summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-21 14:21:43 +0000
committeraur-build <aur-build@localhost>2026-11-21 14:21:43 +0000
commit92742f0e5d336547d8d72464e2df0ff1c4f2d337 (patch)
tree096cf9e7ed6c6845812b29a2951d0fd495d799f0 /tests
parent141a14112554707e04bc2dd33f0c8071c1d74441 (diff)
downloadaur-build-92742f0e5d336547d8d72464e2df0ff1c4f2d337.tar.gz
aur-build-92742f0e5d336547d8d72464e2df0ff1c4f2d337.zip
tests,tools: hold the dead-code zero in the ratchet, and prove the checks bite
`dead_code.deadonly` is 0 for all 28 modules and the allowlist names the 18 items that stay `pub` by decision, so the remaining question is whether the ratchet can be broken quietly. Three tests close that. `the_dead_code_budget_matches_the_code` refuses a budget that contradicts itself: `modules.<m>.deadonly` is what `interfaces_stay_within_budget` reads and `dead_code.deadonly.<m>` is what `tools/arch-census.py --budget` reads, and both must equal the census — an edit to one alone is how a widening enters unnoticed. `the_dead_code_allowlist_names_real_items` refuses an entry whose item the module no longer declares, which is the permission that lets a deleted item return. `the_budget_writers_preserve_each_other` runs both writers against a copy of the file and fails if either erases the section it does not own, or rewrites the hand-written allowlist — the failure mode two tools sharing one file were always going to have. Each was checked by breaking it on purpose: a raised budget, a stale allowlist key, and a writer that drops the allowlist all fail loudly and pass again when reverted. README now says `--list-dead` exists and that a kept item is allowed by name in the budget file, because a ratchet nobody can inspect is not a ratchet.
Diffstat (limited to 'tests')
-rw-r--r--tests/architecture.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/architecture.rs b/tests/architecture.rs
index 696bac1..b8de0ce 100644
--- a/tests/architecture.rs
+++ b/tests/architecture.rs
@@ -972,3 +972,94 @@ fn every_fixture_is_referenced() {
either drive one or delete the directory.",
);
}
+
+/// The two places the budget states how many unargued dead items a module may
+/// have must say the same thing.
+///
+/// `modules.<m>.deadonly` is the ratchet `interfaces_stay_within_budget` reads;
+/// `dead_code.deadonly.<m>` is the one `tools/arch-census.py --budget` reads.
+/// They are written by the same invocation and disagree only if someone edited
+/// one by hand, which is exactly the moment a ratchet stops meaning anything.
+/// Both are zero, and zero is the point: an item that is dead, exported and
+/// unargued is not a budget question, it is a failure.
+#[test]
+fn the_dead_code_budget_matches_the_code() {
+ let path = root().join("tests/architecture-budget.json");
+ let value: serde_json::Value =
+ serde_json::from_str(&std::fs::read_to_string(&path).expect("read budget")).expect("budget is json");
+ let modules = value.get("modules").and_then(|m| m.as_object()).expect("modules");
+ let dead_code = value
+ .get("dead_code")
+ .and_then(|d| d.get("deadonly"))
+ .and_then(|d| d.as_object())
+ .expect("dead_code.deadonly");
+ let census = Census::take();
+
+ let mut mismatch = Vec::new();
+ for (module, row) in modules {
+ let interface = row.get("deadonly").and_then(|v| v.as_u64()).unwrap_or(u64::MAX);
+ let dead = dead_code.get(module).and_then(|v| v.as_u64());
+ let actual = census
+ .modules
+ .get(module)
+ .map(|m| m.dead_only as u64)
+ .unwrap_or(u64::MAX);
+ if dead != Some(interface) || interface != actual {
+ mismatch.push(format!(
+ "{module}: dead_code.deadonly {:?}, modules.deadonly {interface}, actual {actual}",
+ dead
+ ));
+ }
+ }
+ for module in dead_code.keys() {
+ if !modules.contains_key(module) {
+ mismatch.push(format!("{module}: in dead_code.deadonly, absent from modules"));
+ }
+ }
+ mismatch.sort();
+ assert!(
+ mismatch.is_empty(),
+ "the budget contradicts itself about how many unargued dead items a module has:\n{}",
+ mismatch.join("\n")
+ );
+}
+
+/// Two tools write one file, so neither may erase what the other owns.
+///
+/// `tools/arch-census.py` writes the module numbers and the accepted dead-code
+/// counts; `tools/test-surface.py` writes the test-surface counts; a human owns
+/// the allowlist. A rewrite that drops a section does not fail anything until
+/// the ratchet quietly stops checking that axis, so this runs both writers
+/// against a copy and fails if either section disappears.
+#[test]
+fn the_budget_writers_preserve_each_other() {
+ let source = std::fs::read_to_string(root().join("tests/architecture-budget.json")).expect("read budget");
+ let before: serde_json::Value = serde_json::from_str(&source).expect("budget is json");
+ let tmp = std::env::temp_dir().join(format!("aur-budget-preserve-{}.json", std::process::id()));
+ std::fs::write(&tmp, &source).expect("write temp budget");
+
+ for tool in ["tools/arch-census.py", "tools/test-surface.py"] {
+ let out = std::process::Command::new("python3")
+ .arg(tool)
+ .arg("--write-budget")
+ .arg(&tmp)
+ .current_dir(root())
+ .output()
+ .unwrap_or_else(|e| panic!("run {tool}: {e}"));
+ assert!(out.status.success(), "{tool} failed: {}", String::from_utf8_lossy(&out.stderr));
+ let after: serde_json::Value =
+ serde_json::from_str(&std::fs::read_to_string(&tmp).expect("read temp budget"))
+ .expect("written budget is json");
+ for section in ["test_surface", "dead_code"] {
+ assert!(
+ after.get(section).is_some(),
+ "{tool} erased the `{section}` section it does not own"
+ );
+ }
+ assert_eq!(
+ after["dead_code"]["allowlist"], before["dead_code"]["allowlist"],
+ "{tool} rewrote the hand-written allowlist"
+ );
+ }
+ std::fs::remove_file(&tmp).ok();
+}