From 31a46d0367db087279bb02351692ebcc47aa3ea6 Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 08:50:23 +0100 Subject: [PATCH] [roads] rename.rs: a new id never spells a word the output already holds The R-55 property mapped renamed strings back anywhere in the output, so a group renamed to `in` turned every firewall "direction": "in" into the group's old name and failed about once in four runs (seed 8124609985917702487). The renaming now reserves every string the plans and problems hold; the seed is kept as a fixed test, which fails without the reservation. No change to the compiler. --- crates/roads/tests/rename.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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();