From b6cf29b9a006d7cbcb4c6794b1635256ce2f1f2a Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 08:41:10 +0100 Subject: [PATCH] [roads] QA F-07: a missing roads/ folder is store.roads, and roads/ is never followed through a link A store folder without roads/ compiled to plans with no access and no problem, kill switches included. It is now an error naming roads. A roads/ that is a file or a symbolic link is refused the same way (the builder's self-review #8): entries inside were already refused, the folder itself was followed. --- crates/roads/src/rules.rs | 2 ++ crates/roads/src/store.rs | 31 ++++++++++++++++++++++++++++++- crates/roads/tests/qa_findings.rs | 1 - crates/roads/tests/validation.rs | 19 +++++++++++++++++++ docs/FORMATS.md | 5 ++++- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/crates/roads/src/rules.rs b/crates/roads/src/rules.rs index c62123a..f0ff5dc 100644 --- a/crates/roads/src/rules.rs +++ b/crates/roads/src/rules.rs @@ -8,6 +8,7 @@ pub const FILE_SIZE: &str = "file.size"; pub const FILE_ENCODING: &str = "file.encoding"; pub const FILE_HEADER: &str = "file.header"; pub const FILE_COUNT: &str = "file.count"; +pub const STORE_ROADS: &str = "store.roads"; pub const YAML_REFUSED: &str = "yaml.refused"; pub const YAML_SYNTAX: &str = "yaml.syntax"; pub const KEY_UNKNOWN: &str = "key.unknown"; @@ -72,6 +73,7 @@ pub const ALL: &[&str] = &[ FILE_ENCODING, FILE_HEADER, FILE_COUNT, + STORE_ROADS, YAML_REFUSED, YAML_SYNTAX, KEY_UNKNOWN, diff --git a/crates/roads/src/store.rs b/crates/roads/src/store.rs index 8ab3ba7..66e5ade 100644 --- a/crates/roads/src/store.rs +++ b/crates/roads/src/store.rs @@ -104,7 +104,36 @@ impl Store { let mut files = Vec::new(); let mut problems = Vec::new(); let roads = root.join(ROADS_DIR); - if roads.is_dir() { + // A missing roads/ folder means no road grants anything, kill switches included: say so (QA F-07). The + // folder itself is never followed through a symbolic link, like the entries inside it. + let readable = match std::fs::symlink_metadata(&roads) { + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + problems.push(Problem::error( + ROADS_DIR, + None, + r::STORE_ROADS, + "missing: there is no roads/ folder, so no road grants anything and no kill switch is on", + )); + false + } + Err(e) => return Err(e), + Ok(m) if !m.file_type().is_dir() => { + let what = if m.file_type().is_symlink() { + "a symbolic link" + } else { + "not a folder" + }; + problems.push(Problem::error( + ROADS_DIR, + None, + r::STORE_ROADS, + format!("{what}; roads/ must be a real folder, so no road was read"), + )); + false + } + Ok(_) => true, + }; + if readable { for entry in std::fs::read_dir(&roads)? { let entry = entry?; let name = entry.file_name().to_string_lossy().into_owned(); diff --git a/crates/roads/tests/qa_findings.rs b/crates/roads/tests/qa_findings.rs index 2242dfd..c7169bb 100644 --- a/crates/roads/tests/qa_findings.rs +++ b/crates/roads/tests/qa_findings.rs @@ -200,7 +200,6 @@ fn f06_a_road_across_address_families_is_reported() { /// F-07. A store folder without `roads/` compiles to plans with no access and no problem at all, so pointing /// `--store` one folder too high revokes everything, kill switches included, without a word. #[test] -#[ignore = "QA F-07 (minor): a missing roads/ folder is not reported"] fn f07_a_missing_roads_folder_is_reported() { let dir = tempfile::tempdir().unwrap(); std::fs::copy( diff --git a/crates/roads/tests/validation.rs b/crates/roads/tests/validation.rs index 1de5b7d..07355e8 100644 --- a/crates/roads/tests/validation.rs +++ b/crates/roads/tests/validation.rs @@ -207,6 +207,25 @@ fn generated(baseline: &[u8]) -> BTreeSet { .any(|p| p.path == "directory.json" && p.code == rules::SNAPSHOT_JSON) ); assert!(c.plans.is_empty()); + // store.roads: a store folder without roads/, and one whose roads/ is a file (QA F-07). + for make_roads in [false, true] { + let tmp = tempfile::tempdir().unwrap(); + for f in ["directory.json", "devices.json"] { + std::fs::copy(common::home_dir().join(f), tmp.path().join(f)).unwrap(); + } + if make_roads { + std::fs::write(tmp.path().join("roads"), "not a folder").unwrap(); + } + let s = Store::load_dir(tmp.path()).unwrap(); + assert!( + s.problems + .iter() + .any(|p| p.path == "roads" && p.code == rules::STORE_ROADS && p.is_error()), + "{:?}", + s.problems + ); + } + hit.insert(rules::STORE_ROADS.into()); hit } diff --git a/docs/FORMATS.md b/docs/FORMATS.md index c447b0e..898ac6c 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -14,7 +14,10 @@ versioned; a change that an older build would misread bumps the version. `roads/` holds only regular files named `-.md`. Anything else in it — a folder, a symbolic link, a file with another name — is an error (`file.kind`), so the folder can never hold something the compiler does -not read. Files are read in byte order of their names. At most 10,000 road files. +not read. Files are read in byte order of their names. At most 10,000 road files. A store without a `roads/` +folder, or whose `roads/` is a file or a symbolic link, is `store.roads`: nothing is read, nothing is granted, +and it is said out loud, because pointing `--store` one folder too high would otherwise revoke everything, +kill switches included, without a word (QA F-07). ## Road files