use super::test_utils::*;
#[test]
fn test_config_file_loading() {
let config_content = r#"
default_max_iterations: 5
auto_worktree: true
verbose: true
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_config_override_with_cli_args() {
let config_content = r#"
default_max_iterations: 5
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test
.arg("run")
.arg(workflow_path.to_str().unwrap())
.arg("-n")
.arg("10") .run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_invalid_config_file() {
let config_content = "invalid yaml : : : this is not valid\n bad indentation without key";
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert!(
output.exit_code == exit_codes::SUCCESS || output.exit_code == exit_codes::CONFIG_ERROR
|| output.exit_code == exit_codes::GENERAL_ERROR
|| output.stderr_contains("config")
|| output.stderr_contains("parse")
|| output.stderr_contains("YAML"),
"Unexpected behavior with invalid config, got exit code {} with stderr: {}",
output.exit_code,
output.stderr
);
}
#[test]
fn test_config_with_environment_variables() {
let test = CliTest::new()
.env("PRODIGY_LOG_LEVEL", "error")
.env("PRODIGY_AUTO_COMMIT", "false");
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert!(
output.exit_code == exit_codes::SUCCESS,
"Expected success but got exit code {}. stdout: {}\nstderr: {}",
output.exit_code,
output.stdout,
output.stderr
);
}
#[test]
fn test_config_file_with_workflow_defaults() {
let config_content = r#"
workflow_defaults:
timeout: 300
retry_attempts: 3
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_config_with_plugin_settings() {
let config_content = r#"
plugins:
enabled: false
auto_load: []
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_config_precedence() {
let config_content = r#"
default_max_iterations: 2
"#;
let test = CliTest::new()
.with_config(config_content)
.env("PRODIGY_MAX_ITERATIONS", "3");
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test
.arg("run")
.arg(workflow_path.to_str().unwrap())
.arg("-n")
.arg("4") .run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_config_with_mapreduce_defaults() {
let config_content = r#"
mapreduce_defaults:
max_parallel: 10
chunk_size: 100
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("mapreduce", &create_mapreduce_workflow("mr"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert!(
output.exit_code == exit_codes::SUCCESS || output.stderr_contains("mapreduce"),
"Expected success or mapreduce in stderr. Got exit code: {}, stdout: {}, stderr: {}",
output.exit_code,
output.stdout,
output.stderr
);
}
#[test]
fn test_config_with_logging_settings() {
let config_content = r#"
logging:
level: debug
format: json
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert!(
output.exit_code == exit_codes::SUCCESS
|| output.stderr_contains("DEBUG")
|| output.stderr_contains("{")
);
}
#[test]
fn test_missing_config_file() {
let test = CliTest::new();
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_config_with_git_settings() {
let config_content = r#"
git:
auto_commit: false
commit_prefix: "prodigy: "
branch_prefix: "prodigy/"
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert_eq!(output.exit_code, exit_codes::SUCCESS);
}
#[test]
fn test_config_with_path_settings() {
let config_content = r#"
paths:
worktree_base: "/tmp/prodigy-worktrees"
event_storage: "/tmp/prodigy-events"
"#;
let test = CliTest::new().with_config(config_content);
let (test, workflow_path) = test.with_workflow("test", &create_test_workflow("test"));
let output = test.arg("run").arg(workflow_path.to_str().unwrap()).run();
assert!(
output.exit_code == exit_codes::SUCCESS
|| output.stderr_contains("permission")
|| output.stderr_contains("path")
);
}