summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-21 09:38:33 +0000
committeraur-build <aur-build@localhost>2026-11-21 09:38:33 +0000
commitd3da3a1882999a80db34089153f9684fd8d7bbee (patch)
tree704d35539e96fc3a92fd89ed560870fef5816d2c /tests
parentae492c87ff66b9f2c8fec25a5ca917c438bf5858 (diff)
downloadaur-build-d3da3a1882999a80db34089153f9684fd8d7bbee.tar.gz
aur-build-d3da3a1882999a80db34089153f9684fd8d7bbee.zip
tools: key items by (module, name), and prove the surface by compiling
The auditor's two counterexamples were both detector bugs, and they were the same class of bug as the ones before: the instrument was reading the source in a way that flattered the number. - Rows are keyed by `(module, name)`. Keyed by bare name, `pipeline::dispatch::Pool::shutdown` merged into the `db::Writer::shutdown` row, which is gated, so an ungated item was reported `already-gated`. - The production-mention index is built from lines with comments and string literals removed. Searching raw text made `review::approve::withdraw` look production-used because the *string* "withdraw" appears in an HTTP route pattern and an audit action; every real caller named `withdraw_package` or `withdraw_release_in`, which are different items. - A `pub` declaration inside a private module is not a public declaration. Without that, the inner-module narrowing made the detector report an `http::new` nobody could name. - For a name declared in several modules — `new`, `open`, `record`, `parse` — a bare mention elsewhere cannot be resolved, so the row is kept and flagged `ambiguous` rather than silently dropped, and `tools/test-surface-ambiguous.json` holds the human verdict. An ambiguous row with no verdict fails the architecture test; "the tool could not tell" is not a disposition. - The count rule was duplicated between `--json` and `--write-budget` and the two drifted the moment a rule was added to one. `tally()` is now the one place. `tools/release-surface-probe.py` replaces inference with compilation for the final claim. It writes a throwaway crate depending on `aur-build` twice, with and without `test-support`, and tries to name every dispositioned item from outside. A path that compiles with the feature proves the path is real; every such path must fail without it. Current result: 28 real external paths, 27 closed in a release build, and the one that stays open is `db::Writer`, which is public because `Db` has a `pub writer: Writer` field and Rust will not type a public field with a private type. That is recorded as `interface` in `tools/test-surface-interface.json` — a disposition that admits reachability and names the signature that forces it — and the probe fails if the file claims an item that is not in fact reachable, so it cannot quietly rot. The tool's own docstring and the generated table claimed "Rust has no test-conditional visibility". That was false and is gone, replaced with the two shapes that do it.
Diffstat (limited to 'tests')
-rw-r--r--tests/architecture-budget.json61
-rw-r--r--tests/architecture.rs62
2 files changed, 93 insertions, 30 deletions
diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json
index 3358039..4046776 100644
--- a/tests/architecture-budget.json
+++ b/tests/architecture-budget.json
@@ -90,14 +90,14 @@
},
"db": {
"dead": 19,
- "deadonly": 9,
+ "deadonly": 8,
"glob": 0,
- "largest": 367,
+ "largest": 368,
"largest_file": "src/db/mod.rs",
- "lines": 3961,
- "priv": 11,
- "pub": 200,
- "test": 10
+ "lines": 3953,
+ "priv": 12,
+ "pub": 198,
+ "test": 11
},
"error": {
"dead": 0,
@@ -114,11 +114,11 @@
"dead": 1,
"deadonly": 1,
"glob": 0,
- "largest": 56,
+ "largest": 57,
"largest_file": "src/fetch.rs",
- "lines": 56,
- "priv": 0,
- "pub": 3,
+ "lines": 57,
+ "priv": 1,
+ "pub": 2,
"test": 0
},
"git": {
@@ -149,9 +149,9 @@
"glob": 0,
"largest": 565,
"largest_file": "src/http/routes/pages.rs",
- "lines": 2010,
- "priv": 74,
- "pub": 22,
+ "lines": 2034,
+ "priv": 78,
+ "pub": 20,
"test": 5
},
"lib": {
@@ -193,7 +193,7 @@
"glob": 0,
"largest": 472,
"largest_file": "src/pipeline/steps.rs",
- "lines": 1400,
+ "lines": 1411,
"priv": 16,
"pub": 21,
"test": 6
@@ -213,11 +213,11 @@
"dead": 0,
"deadonly": 0,
"glob": 0,
- "largest": 545,
+ "largest": 559,
"largest_file": "src/pkgver/mod.rs",
- "lines": 545,
+ "lines": 559,
"priv": 0,
- "pub": 8,
+ "pub": 7,
"test": 0
},
"recipe": {
@@ -237,7 +237,7 @@
"glob": 0,
"largest": 301,
"largest_file": "src/review/diff.rs",
- "lines": 902,
+ "lines": 914,
"priv": 4,
"pub": 24,
"test": 4
@@ -257,11 +257,11 @@
"dead": 12,
"deadonly": 8,
"glob": 0,
- "largest": 646,
+ "largest": 652,
"largest_file": "src/shims/mod.rs",
- "lines": 646,
- "priv": 2,
- "pub": 19,
+ "lines": 652,
+ "priv": 8,
+ "pub": 13,
"test": 4
},
"time": {
@@ -303,7 +303,7 @@
"glob": 0,
"largest": 302,
"largest_file": "src/watch/upstream.rs",
- "lines": 1102,
+ "lines": 1121,
"priv": 10,
"pub": 24,
"test": 4
@@ -311,19 +311,20 @@
},
"test_surface": {
"already-gated": 17,
- "narrowed": 29,
- "total": 46
+ "interface": 1,
+ "narrowed": 19,
+ "total": 37
},
"totals": {
"dead": 84,
- "deadonly": 36,
+ "deadonly": 35,
"edges": 87,
"glob": 0,
"largest": 701,
"largest_file": "src/config.rs",
- "lines": 15655,
- "priv": 138,
- "pub": 484,
- "test": 48
+ "lines": 15734,
+ "priv": 150,
+ "pub": 472,
+ "test": 49
}
}
diff --git a/tests/architecture.rs b/tests/architecture.rs
index 882adee..12de924 100644
--- a/tests/architecture.rs
+++ b/tests/architecture.rs
@@ -682,6 +682,34 @@ fn the_test_surface_is_disposed_of() {
unconfirmed.join("\n")
);
+ // A row is `ambiguous` when the only evidence that production uses the item
+ // is a bare mention of a name the detector cannot resolve — `new`, `open`
+ // and `record` are declared in many modules, and a line saying `Foo::new()`
+ // in http says nothing about `db::open`. The tool genuinely does not know,
+ // so a human has to say which item the mention meant and record the verdict.
+ let mut unadjudicated = Vec::new();
+ for row in rows {
+ if row.get("ambiguous").and_then(|v| v.as_bool()).unwrap_or(false)
+ && !row.get("adjudicated").and_then(|v| v.as_bool()).unwrap_or(false)
+ {
+ unadjudicated.push(format!(
+ "{}:{} at {}",
+ row.get("module").and_then(|v| v.as_str()).unwrap_or("?"),
+ row.get("name").and_then(|v| v.as_str()).unwrap_or("?"),
+ row.get("where").and_then(|v| v.as_str()).unwrap_or("?")
+ ));
+ }
+ }
+ assert!(
+ unadjudicated.is_empty(),
+ "{} items look production-used only because a bare mention of a colliding \n\
+ name could have meant them, and no human has said which item the mention \n\
+ referred to. Read the cited line and record the verdict in \n\
+ tools/test-surface-ambiguous.json:\n{}",
+ unadjudicated.len(),
+ unadjudicated.join("\n")
+ );
+
let budget = budget_section("test_surface");
let surface = &budget;
let counts = report.get("counts").and_then(|c| c.as_object()).expect("counts");
@@ -708,3 +736,37 @@ fn the_test_surface_is_disposed_of() {
tighter.join("\n")
);
}
+
+/// The definitive check, and the slow one: compile a throwaway crate against
+/// `aur-build` twice, once without `test-support` and once with it, and try to
+/// name every dispositioned item from outside.
+///
+/// `tools/test-surface.py` infers the test surface by reading source, and
+/// inference has been wrong before — a name matched inside a string literal
+/// made `review::approve::withdraw` look production-used, and keying rows by
+/// bare name merged `pipeline::dispatch::Pool::shutdown` into the gated
+/// `db::Writer::shutdown` row. This test does not read source. It asks the
+/// compiler what a release build actually lets an outside crate reach.
+///
+/// `#[ignore]`d because it builds the library twice from scratch, roughly
+/// doubling the suite. Run it with `cargo test --test architecture -- --ignored`
+/// or `AUR_PROBE_RELEASE_SURFACE=1 cargo test --test architecture`.
+#[test]
+#[ignore = "builds the library twice; run with --ignored or AUR_PROBE_RELEASE_SURFACE=1"]
+fn the_release_build_exports_nothing_that_only_tests_reach() {
+ let out = std::process::Command::new("python3")
+ .arg("tools/release-surface-probe.py")
+ .current_dir(root())
+ .output()
+ .expect("run tools/release-surface-probe.py");
+ let text = String::from_utf8_lossy(&out.stdout).to_string();
+ assert!(
+ out.status.success(),
+ "a release build still exports something only the test tier needs:\n{text}{}",
+ String::from_utf8_lossy(&out.stderr)
+ );
+ assert!(
+ text.contains("nothing leaked"),
+ "the probe did not report success:\n{text}"
+ );
+}