summaryrefslogtreecommitdiffstats
path: root/tests/architecture.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-20 20:47:21 +0000
committeraur-build <aur-build@localhost>2026-11-20 20:47:21 +0000
commit289560d196b65b0b257b59a92c956f088eb29fad (patch)
tree01966faf56a44013c805de2ae08d7ad139939462 /tests/architecture.rs
parent39ae04fcc1e25d6b252a7432dfc8257e41237750 (diff)
downloadaur-build-289560d196b65b0b257b59a92c956f088eb29fad.tar.gz
aur-build-289560d196b65b0b257b59a92c956f088eb29fad.zip
tools: decide the disposition of every test-only pub item
The census could say which `pub` items nothing outside their module names, and which of those a test names. It could not say what to do about them, because the two questions that actually decide it are ones a raw-source name match cannot answer: Does a test *call* it, or merely mention it inside a string? Does production code *inside* the declaring module call it? `tools/test-surface.py` asks both, and `tools/test-surface.md` records the answer for all 61 items. Four dispositions, each with a hand-written reason kept in `tools/test-surface-reasons.json`: gate (9) production never calls it; a test does move-test (9) the test that names it builds no fixture, so it is a unit test in the wrong file narrow (6) no test calls it at all — census false positives, the name appears only inside a string literal residue (34) stays pub, and the honest column `residue` needs saying out loud. Rust has no test-conditional visibility: no attribute makes an item `pub` under one feature and `pub(crate)` under another, and `pub use` cannot re-export a `pub(crate)` item. An item that production needs *inside* its own module and a fixture-bound integration test needs from outside cannot be narrowed without breaking one side or the other. That is not a gap in this analysis; it is a gap in the language, and the way to close those 34 rows is to change the tests — move them into the module, or exercise the behaviour through the module's real entry point — not to invent a visibility that does not exist. So the column is ratcheted rather than wished away. `the_test_surface_is_disposed_of` fails if any row lacks a hand-written reason, and if any count — including `gate_pending`, items decided to be gated but not yet gated — exceeds its budget. It can only shrink. Two census limitations surfaced and are now written down rather than silently trusted: "module" means the top-level directory, so an item used only from a sibling file in the same module reads as dead; and mentions are matched over raw source, so a string counts as a reference. Six items were being counted as test-pinned on the strength of a string alone. No source file is edited here. This is the decision record the next commits apply. Suite: 284 passed, 0 failed. Release build: zero warnings.
Diffstat (limited to 'tests/architecture.rs')
-rw-r--r--tests/architecture.rs108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/architecture.rs b/tests/architecture.rs
index d3a4142..483a293 100644
--- a/tests/architecture.rs
+++ b/tests/architecture.rs
@@ -340,6 +340,25 @@ impl Census {
}
}
+/// A top-level section of the budget file, as `key -> allowed`.
+fn budget_section(section: &str) -> BTreeMap<String, usize> {
+ let path = root().join("tests/architecture-budget.json");
+ let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {}", path.display(), e));
+ let value: serde_json::Value = serde_json::from_str(&text).expect("budget file is json");
+ let mut out = BTreeMap::new();
+ let obj = value
+ .get(section)
+ .unwrap_or_else(|| panic!("budget file has no `{section}` section"))
+ .as_object()
+ .unwrap_or_else(|| panic!("budget `{section}` section is an object"));
+ for (key, val) in obj {
+ if let Some(n) = val.as_u64() {
+ out.insert(key.clone(), n as usize);
+ }
+ }
+ out
+}
+
fn rank_of(module: &str) -> Option<u8> {
RANKS
.iter()
@@ -579,3 +598,92 @@ fn the_census_tool_and_this_test_agree() {
disagreements.join("\n")
);
}
+
+/// Every `pub` item that exists only because a test names it has a recorded
+/// disposition, and the counts may only shrink.
+///
+/// `tools/test-surface.py` asks two questions the census cannot: whether a test
+/// actually *calls* the item or merely mentions it inside a string, and whether
+/// production code inside the declaring module calls it. The answers yield four
+/// dispositions — `gate`, `move-test`, `narrow`, `residue` — and this test holds
+/// the crate to them in three ways:
+///
+/// - every row must carry a hand-written reason from
+/// `tools/test-surface-reasons.json`, so no item is disposed of by a heuristic
+/// nobody read;
+/// - the per-disposition counts, and `gate_pending` — items decided to be gated
+/// but not yet gated — may only shrink against the budget.
+///
+/// `residue` is the honest column: items production needs inside their own module
+/// *and* a fixture-bound integration test needs from outside. Rust has no
+/// test-conditional visibility, so those cannot be narrowed without breaking one
+/// side or the other; ratcheting the count is what keeps the column from growing
+/// while it is worked down by changing tests rather than visibilities.
+#[test]
+fn the_test_surface_is_disposed_of() {
+ if !std::process::Command::new("python3")
+ .arg("--version")
+ .output()
+ .is_ok()
+ {
+ println!("python3 is not on PATH — skipping the test-surface check");
+ return;
+ }
+ let out = std::process::Command::new("python3")
+ .arg("tools/test-surface.py")
+ .arg("--json")
+ .current_dir(root())
+ .output()
+ .expect("run tools/test-surface.py");
+ assert!(
+ out.status.success(),
+ "tools/test-surface.py failed: {}",
+ String::from_utf8_lossy(&out.stderr)
+ );
+ let report: serde_json::Value = serde_json::from_slice(&out.stdout).expect("test-surface json");
+ let rows = report.get("rows").and_then(|r| r.as_array()).expect("rows");
+
+ let mut unreasoned = Vec::new();
+ for row in rows {
+ let name = row.get("name").and_then(|v| v.as_str()).unwrap_or("?");
+ let module = row.get("module").and_then(|v| v.as_str()).unwrap_or("?");
+ let disp = row.get("disp").and_then(|v| v.as_str()).unwrap_or("?");
+ if !row.get("hand_written").and_then(|v| v.as_bool()).unwrap_or(false) {
+ unreasoned.push(format!("{module}.{name} ({disp})"));
+ }
+ }
+ assert!(
+ unreasoned.is_empty(),
+ "{} test-only items have no hand-written disposition reason in \
+ tools/test-surface-reasons.json:\n{}\n\
+ a disposition nobody argued for is not a decision.",
+ unreasoned.len(),
+ unreasoned.join("\n")
+ );
+
+ let budget = budget_section("test_surface");
+ let surface = &budget;
+ let counts = report.get("counts").and_then(|c| c.as_object()).expect("counts");
+ let mut looser = Vec::new();
+ let mut tighter = Vec::new();
+ for (key, ceiling) in surface {
+ let actual = counts.get(key).and_then(|v| v.as_u64()).unwrap_or(0) as usize;
+ if actual > *ceiling {
+ looser.push(format!("{key}: budget {ceiling}, actual {actual}"));
+ } else if actual < *ceiling {
+ tighter.push(format!("{key}: budget {ceiling}, actual {actual}"));
+ }
+ }
+ assert!(
+ looser.is_empty(),
+ "the test surface grew past its budget — a new `pub` item that only tests \
+ name needs a disposition and a lower ceiling elsewhere:\n{}",
+ looser.join("\n")
+ );
+ assert!(
+ tighter.is_empty(),
+ "these test-surface budgets are looser than the code, hiding ground already \
+ won (rewrite with `python3 tools/test-surface.py --write` and re-record):\n{}",
+ tighter.join("\n")
+ );
+}