Files
baibot-withmcp/src/controller/agent/create/tests.rs
Slavi Pantaleev f7cb38b620 Fix clippy warnings in tests
- Avoid unwrap_or() on a statically-Some value by using the raw token count
- Use an array literal instead of vec! for the non-allocated test cases

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 09:41:00 +03:00

62 lines
1.9 KiB
Rust

#[test]
fn agent_config_parsing_works() {
struct TestCase {
input: String,
expected: Option<serde_yaml_ng::Value>,
}
let provider = crate::agent::AgentProvider::OpenAI;
let sample_config = crate::agent::default_config_for_provider(&provider);
let sample_config_pretty_yaml = serde_yaml_ng::to_string(&sample_config).unwrap();
let test_cases = [
// Invalid input
TestCase {
input: r#"Hello"#.to_owned(),
expected: None,
},
// Plain text
TestCase {
input: sample_config_pretty_yaml.clone(),
expected: Some(sample_config.clone()),
},
// Generic code block
TestCase {
input: format!("```\n{}```", sample_config_pretty_yaml),
expected: Some(sample_config.clone()),
},
// YAML code block (yaml)
TestCase {
input: format!("```yaml\n{}```", sample_config_pretty_yaml),
expected: Some(sample_config.clone()),
},
// YAML code block (yml)
TestCase {
input: format!("```yml\n{}```", sample_config_pretty_yaml),
expected: Some(sample_config.clone()),
},
// JSON code block
TestCase {
input: format!("```json\n{}```", sample_config_pretty_yaml),
expected: None,
},
];
for (i, test_case) in test_cases.iter().enumerate() {
let result = super::parse_from_message_to_yaml_value(&test_case.input);
match result {
Ok(config) => {
assert_eq!(
config,
test_case.expected.clone().unwrap(),
"Test case {} failed",
i
);
}
Err(_) => {
assert_eq!(test_case.expected, None, "Test case {} failed", i);
}
}
}
}