hive-c0re: extract read_from so the prune_unknown test exercises the real wiring
This commit is contained in:
parent
e24259dde1
commit
1d120289d1
1 changed files with 10 additions and 7 deletions
|
|
@ -41,7 +41,11 @@ pub fn tool_groups_path() -> PathBuf {
|
|||
/// honoured — but `read` itself never writes; unknown names stay on disk
|
||||
/// until the next `set_groups` rewrites the file.
|
||||
pub fn read() -> std::io::Result<BTreeMap<String, Vec<String>>> {
|
||||
let mut map = super::read_map(&tool_groups_path())?;
|
||||
read_from(&tool_groups_path())
|
||||
}
|
||||
|
||||
fn read_from(path: &Path) -> std::io::Result<BTreeMap<String, Vec<String>>> {
|
||||
let mut map = super::read_map(path)?;
|
||||
prune_unknown(&mut map);
|
||||
Ok(map)
|
||||
}
|
||||
|
|
@ -214,16 +218,15 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn read_drops_an_unknown_name_still_on_disk_without_rewriting_the_file() {
|
||||
fn read_from_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
|
||||
};
|
||||
// Exercises `read()`'s own wiring, not a hand-rolled equivalent —
|
||||
// deleting the `prune_unknown` call inside `read_from` must fail
|
||||
// this assertion.
|
||||
let map = read_from(&path).expect("read_from");
|
||||
assert_eq!(map["alice"], vec!["messaging".to_owned()]);
|
||||
|
||||
// `read()` itself never writes — the stale name is still on disk.
|
||||
|
|
|
|||
Loading…
Reference in a new issue