From 13ee9e6398232f96f1cfc898fd19bde8db843fa1 Mon Sep 17 00:00:00 2001 From: Chummy Date: Wed, 18 Feb 2026 21:53:54 +0800 Subject: [PATCH] test: cover deterministic HashMap ordering paths --- src/doctor/mod.rs | 40 ++++++++++++++++++++++++++++++++++++++++ src/identity.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/doctor/mod.rs b/src/doctor/mod.rs index c5367c0..44d3cd4 100644 --- a/src/doctor/mod.rs +++ b/src/doctor/mod.rs @@ -765,4 +765,44 @@ mod tests { .and_then(|name| name.to_str()) .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\"")); + } } diff --git a/src/identity.rs b/src/identity.rs index a614e46..dc56e80 100644 --- a/src/identity.rs +++ b/src/identity.rs @@ -1452,4 +1452,37 @@ mod tests { ); 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); + } }