diff --git a/crates/roads/tests/rename.rs b/crates/roads/tests/rename.rs index c6a456d..1025011 100644 --- a/crates/roads/tests/rename.rs +++ b/crates/roads/tests/rename.rs @@ -149,6 +149,31 @@ impl Renaming { for (o, _) in &olds { taken.insert(o.clone()); } + // `back` maps strings anywhere in the output, so a new id must never spell a word the output already + // holds for another reason: a group renamed to `in` turned every firewall `"direction": "in"` into + // the group's old name (seed 8124609985917702487). Reserve every string the plans and problems hold. + fn strings(v: &Value, out: &mut BTreeSet) { + match v { + Value::String(s) => { + out.insert(s.clone()); + } + Value::Array(a) => a.iter().for_each(|x| strings(x, out)), + Value::Object(m) => m.iter().for_each(|(k, x)| { + out.insert(k.clone()); + strings(x, out); + }), + _ => {} + } + } + let c = compile( + &Store::from_parts(&parts.roads, Some(&parts.directory), Some(&parts.devices)), + now(), + ); + strings( + &serde_json::to_value(c.plans.values().collect::>()).unwrap(), + &mut taken, + ); + strings(&serde_json::to_value(&c.problems).unwrap(), &mut taken); let mut to_new = BTreeMap::new(); for (old, kind) in olds { let new = loop { @@ -385,6 +410,13 @@ fn the_extra_roads_reach_the_order_sensitive_paths() { ); } +/// A seed that once renamed the household group to `in`, a word the plans already hold (a firewall +/// direction). The renaming must avoid it, not the comparison. +#[test] +fn a_new_id_never_spells_a_word_of_the_output() { + check_isomorphic(8124609985917702487).unwrap(); +} + #[test] fn the_identity_renaming_changes_nothing() { let parts = base_parts();