use aca::integration::AgentConfig;
use std::path::Path;
#[test]
fn test_default_config_generation() {
let config = AgentConfig::default();
let toml_str = config
.to_toml_string()
.expect("Should be able to generate TOML from default config");
assert!(!toml_str.is_empty(), "Generated TOML should not be empty");
assert!(toml_str.len() > 100, "Generated TOML should be substantial");
assert!(
toml_str.contains("workspace_path"),
"Should contain workspace_path"
);
assert!(
toml_str.contains("[session_config]"),
"Should contain session_config section"
);
assert!(
toml_str.contains("[task_config]"),
"Should contain task_config section"
);
assert!(
toml_str.contains("[claude_config"),
"Should contain claude_config sections"
);
let parsed_config =
AgentConfig::from_toml_str(&toml_str).expect("Generated TOML should be parseable");
assert_eq!(config.workspace_path, parsed_config.workspace_path);
assert_eq!(
config.setup_commands.len(),
parsed_config.setup_commands.len()
);
}
#[test]
fn test_config_template_generation() {
let config = AgentConfig::default();
let toml_str = config.to_toml_string().expect("Should generate TOML");
let required_sections = [
"workspace_path",
"[session_config]",
"auto_save_interval_minutes",
"auto_checkpoint_interval_minutes",
"[task_config]",
"auto_retry_failed_tasks",
"max_concurrent_tasks",
"[claude_config.session_config]",
"[claude_config.rate_limits]",
"[claude_config.context_config]",
"[claude_config.usage_tracking]",
"[claude_config.error_config]",
];
for section in &required_sections {
assert!(
toml_str.contains(section),
"Generated TOML should contain section: {}",
section
);
}
}
#[test]
fn test_config_generation_with_setup_commands() {
use aca::task::SetupCommand;
let config = AgentConfig {
setup_commands: vec![
SetupCommand::new("test_command", "echo")
.with_args(vec!["Hello".to_string(), "World".to_string()]),
],
..Default::default()
};
let toml_str = config
.to_toml_string()
.expect("Should generate TOML with setup commands");
assert!(
toml_str.contains("[[setup_commands]]"),
"Should contain setup_commands array"
);
assert!(
toml_str.contains("test_command"),
"Should contain command name"
);
assert!(toml_str.contains("echo"), "Should contain command");
let parsed_config =
AgentConfig::from_toml_str(&toml_str).expect("Should parse TOML with setup commands");
assert_eq!(
config.setup_commands.len(),
parsed_config.setup_commands.len()
);
assert_eq!(
config.setup_commands[0].name,
parsed_config.setup_commands[0].name
);
assert_eq!(
config.setup_commands[0].command,
parsed_config.setup_commands[0].command
);
}
#[test]
fn test_config_generation_consistency() {
let config1 = AgentConfig::default();
let config2 = AgentConfig::default();
let toml1 = config1.to_toml_string().expect("Should generate TOML");
let toml2 = config2.to_toml_string().expect("Should generate TOML");
assert_eq!(
toml1, toml2,
"Default configs should generate identical TOML"
);
}
#[test]
fn test_config_workspace_path_validation() {
let config = AgentConfig::default();
let toml_str = config.to_toml_string().expect("Should generate TOML");
assert!(
toml_str.contains("workspace_path"),
"Should contain workspace_path field"
);
let parsed_config = AgentConfig::from_toml_str(&toml_str).expect("Should parse TOML");
assert!(
!parsed_config.workspace_path.as_os_str().is_empty(),
"Workspace path should not be empty"
);
assert!(
Path::new(&parsed_config.workspace_path).is_absolute()
|| parsed_config.workspace_path.is_relative(),
"Workspace path should be a valid path"
);
}