test: cover deterministic HashMap ordering paths

This commit is contained in:
Chummy 2026-02-18 21:53:54 +08:00
parent 58bb9fa9a7
commit 13ee9e6398
2 changed files with 73 additions and 0 deletions

View file

@ -765,4 +765,44 @@ mod tests {
.and_then(|name| name.to_str()) .and_then(|name| name.to_str())
.is_some_and(|name| name.starts_with(".zeroclaw_doctor_probe_"))); .is_some_and(|name| name.starts_with(".zeroclaw_doctor_probe_")));
} }
#[test]
fn config_validation_reports_delegate_agents_in_sorted_order() {
let mut config = Config::default();
config.agents.insert(
"zeta".into(),
crate::config::DelegateAgentConfig {
provider: "totally-fake".into(),
model: "model-z".into(),
system_prompt: None,
api_key: None,
temperature: None,
max_depth: 3,
},
);
config.agents.insert(
"alpha".into(),
crate::config::DelegateAgentConfig {
provider: "totally-fake".into(),
model: "model-a".into(),
system_prompt: None,
api_key: None,
temperature: None,
max_depth: 3,
},
);
let mut items = Vec::new();
check_config_semantics(&config, &mut items);
let agent_messages: Vec<_> = items
.iter()
.filter(|item| item.message.starts_with("agent \""))
.map(|item| item.message.as_str())
.collect();
assert_eq!(agent_messages.len(), 2);
assert!(agent_messages[0].contains("agent \"alpha\""));
assert!(agent_messages[1].contains("agent \"zeta\""));
}
} }

View file

@ -1452,4 +1452,37 @@ mod tests {
); );
assert_eq!(identity.psychology.unwrap().mbti.as_deref(), Some("ENTP")); assert_eq!(identity.psychology.unwrap().mbti.as_deref(), Some("ENTP"));
} }
#[test]
fn aieos_to_system_prompt_sorts_hashmap_sections_for_determinism() {
let mut neural_matrix = std::collections::HashMap::new();
neural_matrix.insert("zeta".to_string(), 0.10);
neural_matrix.insert("alpha".to_string(), 0.90);
let mut favorites = std::collections::HashMap::new();
favorites.insert("snack".to_string(), "tea".to_string());
favorites.insert("book".to_string(), "rust".to_string());
let identity = AieosIdentity {
psychology: Some(PsychologySection {
neural_matrix: Some(neural_matrix),
..Default::default()
}),
interests: Some(InterestsSection {
favorites: Some(favorites),
..Default::default()
}),
..Default::default()
};
let prompt = aieos_to_system_prompt(&identity);
let alpha_pos = prompt.find("- alpha: 0.90").unwrap();
let zeta_pos = prompt.find("- zeta: 0.10").unwrap();
assert!(alpha_pos < zeta_pos);
let book_pos = prompt.find("- book: rust").unwrap();
let snack_pos = prompt.find("- snack: tea").unwrap();
assert!(book_pos < snack_pos);
}
} }