hive-c0re: add prune_unknown table tests + read() coverage, mirroring capabilities.rs
This commit is contained in:
parent
06951ddc30
commit
e24259dde1
1 changed files with 42 additions and 0 deletions
|
|
@ -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<String, Vec<String>> = {
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue