use shimmy::tools::ToolRegistry;
use shimmy::workflow::{WorkflowEngine, WorkflowStep, WorkflowStepType};
use std::collections::HashMap;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn execute_workflow_error_case() {
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![], inputs: HashMap::new(),
outputs: vec!["nonexistent".to_string()], },
context: HashMap::new(),
};
let rt = tokio::runtime::Runtime::new().unwrap();
let result = rt.block_on(engine.execute_workflow(request));
if result.is_ok() {
let workflow_result = result.unwrap();
assert!(
!workflow_result.success,
"Workflow should fail with non-existent output step"
);
}
}
#[test]
fn calculate_execution_order_error_case() {
let engine = WorkflowEngine::new(ToolRegistry::new());
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"
);
}
#[test]
fn substitute_variables_error_case() {
let engine = WorkflowEngine::new(ToolRegistry::new());
let template = "Hello {{undefined_var}}";
let variables = HashMap::new();
let result = engine.substitute_variables(template, &variables);
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"
);
}
#[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"),
}
}
}