From e24259dde107a86a118273c8e30f0fa305c2e531 Mon Sep 17 00:00:00 2001 From: damocles Date: Thu, 8 Oct 2026 00:32:23 +0200 Subject: [PATCH] hive-c0re: add prune_unknown table tests + read() coverage, mirroring capabilities.rs --- hive-c0re/src/agent_config/tool_groups.rs | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hive-c0re/src/agent_config/tool_groups.rs b/hive-c0re/src/agent_config/tool_groups.rs index ead66c9c..91636d46 100644 --- a/hive-c0re/src/agent_config/tool_groups.rs +++ b/hive-c0re/src/agent_config/tool_groups.rs @@ -188,4 +188,46 @@ mod tests { assert_eq!(map["alice"], vec!["inbox".to_owned()]); assert_eq!(map["ruth"], vec!["messaging".to_owned()]); } + + #[test] + fn prune_unknown_keeps_known_name() { + let mut map = BTreeMap::from([("alice".to_owned(), vec!["messaging".to_owned()])]); + assert!(!prune_unknown(&mut map)); + assert_eq!(map["alice"], vec!["messaging".to_owned()]); + } + + #[test] + fn prune_unknown_drops_unrecognised_name() { + let mut map = BTreeMap::from([("alice".to_owned(), vec!["diagnostics".to_owned()])]); + assert!(prune_unknown(&mut map)); + assert!(!map.contains_key("alice")); + } + + #[test] + fn prune_unknown_keeps_known_and_drops_unknown_in_same_entry() { + let mut map = BTreeMap::from([( + "alice".to_owned(), + vec!["messaging".to_owned(), "scheduling".to_owned()], + )]); + assert!(prune_unknown(&mut map)); + assert_eq!(map["alice"], vec!["messaging".to_owned()]); + } + + #[test] + fn read_drops_an_unknown_name_still_on_disk_without_rewriting_the_file() { + let dir = tempfile::tempdir().expect("tempdir"); + let path = dir.path().join(TOOL_GROUPS_FILE); + std::fs::write(&path, r#"{"alice": ["messaging", "diagnostics"]}"#).expect("seed"); + + let map: BTreeMap> = { + let mut m = crate::agent_config::read_map(&path).expect("read"); + prune_unknown(&mut m); + m + }; + assert_eq!(map["alice"], vec!["messaging".to_owned()]); + + // `read()` itself never writes — the stale name is still on disk. + let on_disk = std::fs::read_to_string(&path).expect("read file"); + assert!(on_disk.contains("diagnostics"), "{on_disk}"); + } }