Files
shimmy/tests/workflow_tests.rs
Michael A. Kuykendall 02276d75f9 Merge fix/issue-128-backend-already-initialized: Backend singleton + clippy fixes
- Resolves Issue #128: BackendAlreadyInitialized error
- OnceLock singleton pattern for LlamaBackend
- Fixed 60+ clippy errors across codebase:
  * Boolean logic bugs in GPU detection tests
  * Obsolete API usage in benchmarks (Registry rewrite)
  * Dead code warnings in test helpers
  * Needless borrows (54 instances)
  * Unnecessary literal unwrap patterns
  * Field reassignment after default
  * expect_fun_call patterns
  * empty_line_after_doc_comments
  * single_match patterns
  * needless_range_loop
- All tests passing with -D warnings (strict mode)

Signed-off-by: Michael A. Kuykendall <michaelallenkuykendall@gmail.com>
2025-10-21 15:25:40 -05:00

118 lines
4.5 KiB
Rust

// PUNCH-generated tests for workflow module
use shimmy::tools::ToolRegistry;
use shimmy::workflow::{WorkflowEngine, WorkflowStep, WorkflowStepType};
use std::collections::HashMap;
#[cfg(test)]
mod tests {
use super::*;
// Rule: rust_result_err - Functions returning Result need Err case tests
#[test]
fn execute_workflow_error_case() {
// Test error case handling with invalid workflow
let engine = WorkflowEngine::new(ToolRegistry::new());
let request = shimmy::workflow::WorkflowRequest {
workflow: shimmy::workflow::Workflow {
id: "test".to_string(),
name: "test".to_string(),
description: "test".to_string(),
steps: vec![], // Empty workflow should cause error
inputs: HashMap::new(),
outputs: vec!["nonexistent".to_string()], // Reference non-existent step
},
context: HashMap::new(),
};
let rt = tokio::runtime::Runtime::new().unwrap();
let result = rt.block_on(engine.execute_workflow(request));
// Empty workflow might succeed but requesting output from non-existent step should fail
if let Ok(workflow_result) = result {
assert!(
!workflow_result.success,
"Workflow should fail with non-existent output step"
);
}
}
// Rule: rust_result_err - Functions returning Result need Err case tests
#[test]
fn calculate_execution_order_error_case() {
let engine = WorkflowEngine::new(ToolRegistry::new());
// Test circular dependencies - same as in the main module tests
let steps = vec![
WorkflowStep {
id: "step1".to_string(),
step_type: WorkflowStepType::DataTransform {
operation: "extract".to_string(),
expression: "test".to_string(),
},
depends_on: vec!["step2".to_string()],
parameters: serde_json::Value::Null,
},
WorkflowStep {
id: "step2".to_string(),
step_type: WorkflowStepType::DataTransform {
operation: "extract".to_string(),
expression: "test".to_string(),
},
depends_on: vec!["step1".to_string()],
parameters: serde_json::Value::Null,
},
];
let result = engine.calculate_execution_order(&steps);
assert!(
result.is_err(),
"Function should return Err for circular dependencies"
);
}
// Rule: rust_result_err - Functions returning Result need Err case tests
#[test]
fn substitute_variables_error_case() {
let engine = WorkflowEngine::new(ToolRegistry::new());
// Test with undefined variables - current implementation doesn't actually error on this
// but we can test the behavior
let template = "Hello {{undefined_var}}";
let variables = HashMap::new();
let result = engine.substitute_variables(template, &variables);
// Current implementation just leaves undefined variables as-is
assert!(
result.is_ok(),
"Current implementation handles undefined variables gracefully"
);
let output = result.unwrap();
assert!(
output.contains("{{undefined_var}}"),
"Undefined variables should remain in output"
);
}
// Rule: rust_empty_str - Functions accepting &str need empty string tests
#[test]
fn substitute_variables_empty_template() {
let engine = WorkflowEngine::new(ToolRegistry::new());
let variables = HashMap::new();
let result = engine.substitute_variables("", &variables);
match result {
Ok(output) => assert_eq!(output, "", "Empty template should return empty string"),
Err(_) => panic!("Empty template should not fail"),
}
}
#[test]
fn substitute_variables_no_variables() {
let engine = WorkflowEngine::new(ToolRegistry::new());
let variables = HashMap::new();
let template = "Hello World";
let result = engine.substitute_variables(template, &variables);
match result {
Ok(output) => assert_eq!(
output, "Hello World",
"Template without variables should pass through"
),
Err(_) => panic!("Template without variables should not fail"),
}
}
}