diff options
| author | aur-build <aur-build@localhost> | 2026-11-21 13:28:55 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-21 13:28:55 +0000 |
| commit | 48fecfe03be4f214eaf4f9c49cb3c27496bb74ba (patch) | |
| tree | 432f6e32351df60d36a115561c1bf8b8013c5430 /tests/architecture.rs | |
| parent | a200edaac2056dd9c85d6bddff3ca181f0cc277e (diff) | |
| download | aur-build-48fecfe03be4f214eaf4f9c49cb3c27496bb74ba.tar.gz aur-build-48fecfe03be4f214eaf4f9c49cb3c27496bb74ba.zip | |
src: narrow what only its own module reads, and delete what nothing reads at all
The census's 35 `deadonly` items were a lead, not a verdict, and the compiler
answered it: 17 of them are read only inside their own module and were declared
`pub` for no reason, so they are `pub(crate)` now — `db::OpenReview` and its two
queries, `ReviewSubject` and its query, `fetch::Body`, `http`'s `form_get`,
`query_get` and `Page::flash`, `ops::EvictPlan`, `usecase`'s `StageB`… — and two
are read by nobody: `ReleaseState::can_transition` and
`SubscriptionState::can_transition`, both already annotated "nothing consults
this table today", which is the definition of dead rather than the argument for
keeping.
Narrowing them is what made the compiler look harder, and it found three more:
`ReviewSubject::pkgbase` was selected out of the database and never read,
`StageB::cached` was written in three places and never read, and
`StageB::version` was never called. All gone, the SELECT column with them.
The other 18 cannot be narrowed and now say so, once at the declaration and once
in the budget file: a row type the `aur-build` binary binds without naming
(`PackageRow`, `Checked`, `GcPlan`, `Prepared`), a type behind a `pub` fn a test
calls (`Unbuilt`, `BulkItem`, `StageA`, `CheckReport`, `PkgInfo`, `Installed`,
`Subscription`, `Manifest`), a trait a public test provisioner implements
(`Provisioner`, `ProvisionRequest`), and three that a release build never even
compiles because their module is `test-support`-gated (`shims::*`, `VirtualClock`).
`deadonly` therefore means *dead and unargued* now: an allowlisted item leaves the
dead columns, which is the only way the number can be held at zero forever.
448 pub, 49 dead, 0 unargued; 284 tests pass, one ignored, none lost.
Diffstat (limited to 'tests/architecture.rs')
| -rw-r--r-- | tests/architecture.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/architecture.rs b/tests/architecture.rs index 12de924..6f68f2b 100644 --- a/tests/architecture.rs +++ b/tests/architecture.rs @@ -241,6 +241,7 @@ impl Census { .collect(); let mut modules: BTreeMap<String, Module> = BTreeMap::new(); + let allowlist = allowed_pub_items(); for (path, text) in &texts { let module = modules.entry(module_of(path)).or_default(); module.lines += text.lines().count(); @@ -278,6 +279,12 @@ impl Census { } let used_by_tests = test_texts.iter().any(|t| mentions(t, name)); for module in declaring { + // An item the budget file argues for is a decision, not a hole, + // so it leaves the dead columns entirely. `deadonly` then means + // *dead and unargued* — the one number that can stay at zero. + if allowlist.contains(&format!("{module}.{name}")) { + continue; + } let module = modules.get_mut(module).unwrap(); module.dead += 1; if used_by_tests { @@ -340,6 +347,27 @@ impl Census { } } +/// The `dead_code.allowlist` keys — `module.item` for every item that stays +/// `pub` by decision, with its reason next to it in the same file. +fn allowed_pub_items() -> BTreeSet<String> { + 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"); + value + .get("dead_code") + .and_then(|d| d.get("allowlist")) + .and_then(|a| a.as_object()) + .map(|a| { + a.keys() + .map(|k| { + assert!(!k.trim().is_empty(), "an allowlist key cannot be blank"); + k.clone() + }) + .collect() + }) + .unwrap_or_default() +} + /// 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"); |
