summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/architecture-budget.json61
-rw-r--r--tests/architecture.rs62
-rw-r--r--tools/release-surface-probe.py149
-rw-r--r--tools/test-surface-ambiguous.json3
-rw-r--r--tools/test-surface-interface.json3
-rw-r--r--tools/test-surface-reasons.json2
-rw-r--r--tools/test-surface.md99
-rw-r--r--tools/test-surface.py211
8 files changed, 473 insertions, 117 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}"
+ );
+}
diff --git a/tools/release-surface-probe.py b/tools/release-surface-probe.py
new file mode 100644
index 0000000..2f6830b
--- /dev/null
+++ b/tools/release-surface-probe.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python3
+"""Prove what the release build actually exports, by compiling against it.
+
+`tools/test-surface.py` reads the source and *infers* which `pub` items exist
+only for tests. Inference can be wrong — it already was, twice: a detector that
+matched names inside string literals called `review::approve::withdraw`
+production-used, and a detector keyed by bare name merged
+`pipeline::dispatch::Pool::shutdown` into the gated `db::Writer::shutdown` row.
+
+This tool does not infer. It writes a throwaway crate that depends on
+`aur-build` twice over — once without `test-support`, once with — and tries to
+name every dispositioned item from outside. An item is honest only if:
+
+ * at least one candidate path compiles **with** the feature, which proves the
+ path is real and the item is genuinely reachable to the test tier, and
+ * every path that compiles with the feature fails **without** it, which proves
+ a release build does not export it.
+
+A path that compiles in both builds is a leak and this tool exits non-zero.
+
+An item with no nameable path at all is not a pass and not a failure: a method
+(`Config::store_dir`) or a const inside a private submodule cannot be named by a
+`use` line whatever its visibility. Those are reported separately with the
+source line that states their visibility, for a human to read.
+
+Usage:
+ python3 tools/release-surface-probe.py # report
+ python3 tools/release-surface-probe.py --quiet # exit code only
+"""
+import argparse
+import json
+import os
+import re
+import shutil
+import subprocess
+import sys
+
+ROOT = os.path.dirname(os.path.abspath(__file__)) + "/.."
+CACHE = os.path.join(ROOT, "target", "release-surface-probe")
+
+
+def table():
+ out = subprocess.run([sys.executable, os.path.join(ROOT, "tools", "test-surface.py"),
+ "--json"], capture_output=True, text=True, cwd=ROOT)
+ if out.returncode != 0:
+ sys.exit("tools/test-surface.py failed: " + out.stderr)
+ return json.loads(out.stdout)["rows"]
+
+
+def candidates(row):
+ """Paths an outside crate could try for this item.
+
+ The declaring file's module path, and the top-level module the census groups
+ it under, because most items are re-exported up to the module door. Neither
+ reaches a method or an item inside a nested private module; those are
+ reported as not nameable rather than guessed at.
+ """
+ f = row["where"].rsplit(":", 1)[0]
+ mod = f[len("src/"):-len(".rs")]
+ if mod.endswith("/mod"):
+ mod = mod[: -len("/mod")]
+ top = mod.split("/")[0]
+ paths = {"aur_build::%s::%s" % (mod.replace("/", "::"), row["name"]),
+ "aur_build::%s::%s" % (top, row["name"])}
+ return sorted(paths)
+
+
+def build(feature):
+ """Compile one probe binary per candidate path; return the set that failed."""
+ d = os.path.join(CACHE, "with" if feature else "no")
+ shutil.rmtree(d, ignore_errors=True)
+ os.makedirs(os.path.join(d, "src", "bin"))
+ with open(os.path.join(d, "Cargo.toml"), "w") as h:
+ h.write('[package]\nname="surface-probe"\nversion="0.0.0"\nedition="2021"\n\n'
+ '[dependencies]\naur-build = { path = "%s"%s }\n'
+ % (os.path.abspath(os.path.join(ROOT, ".")),
+ ', features = ["test-support"]' if feature else ""))
+ with open(os.path.join(d, "src", "main.rs"), "w") as h:
+ h.write("fn main() {}\n")
+
+ units = {}
+ rows = table()
+ for i, row in enumerate(rows):
+ for j, path in enumerate(candidates(row)):
+ name = "x%02d_%d" % (i, j)
+ units[name] = (row["module"], row["name"], path, row["disp"])
+ with open(os.path.join(d, "src", "bin", name + ".rs"), "w") as h:
+ h.write("#![allow(unused_imports, dead_code)]\nuse %s;\nfn main() {}\n" % path)
+
+ r = subprocess.run(["cargo", "build", "--bins", "--keep-going", "--message-format=short",
+ "--target-dir", os.path.join(CACHE, "tgt-" + ("with" if feature else "no"))],
+ cwd=d, capture_output=True, text=True)
+ if "error: could not compile `surface-probe`" not in r.stdout + r.stderr and not units:
+ sys.exit("probe build produced no output; cargo is not working")
+ failed = set(re.findall(r"\b(x\d+_\d+)\.rs", r.stdout + r.stderr))
+ return units, failed
+
+
+def main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument("--quiet", action="store_true", help="print nothing unless something leaked")
+ args = ap.parse_args()
+
+ units_with, failed_with = build(True)
+ _, failed_without = build(False)
+
+ real = set(units_with) - failed_with # paths that really exist
+ # An `interface` item is reachable in a release build on purpose: a public
+ # signature requires it and no test asked for it. The probe's job is to
+ # confirm the reachability is the declared kind, not to pretend it is gone.
+ declared = {u for u in real if units_with[u][3] == "interface"}
+ leaked = sorted(real - failed_without - declared) # ...and a release build still exports
+ unexpected = sorted(declared - real) # declared public, but not reachable
+ nameable = {}
+ for u in real:
+ mod, name, path, disp = units_with[u]
+ nameable.setdefault((mod, name), []).append(path)
+ silent = sorted({(units_with[u][0], units_with[u][1]) for u in failed_with} - set(nameable))
+
+ if not args.quiet:
+ print("candidate paths probed: %d" % len(units_with))
+ print("real external paths: %d (compile with test-support)" % len(real))
+ print("of those, unreachable in a release build: %d" % len([u for u in real if u in failed_without]))
+ print("declared public interface (reachable on purpose): %d" % len(declared))
+ print("items with a nameable path: %d" % len(nameable))
+ print("items no `use` line can name (methods, private submodules): %d" % len(silent))
+ for mod, name in silent:
+ print(" %s.%s" % (mod, name))
+ print()
+
+ if unexpected:
+ print("DECLARED PUBLIC BUT NOT REACHABLE — the interface file is stale:")
+ for u in unexpected:
+ print(" %s.%s %s" % (units_with[u][0], units_with[u][1], units_with[u][2]))
+ return 1
+
+ if leaked:
+ print("LEAKED INTO THE RELEASE BUILD — these paths compile with and without the feature:")
+ for u in leaked:
+ mod, name, path, disp = units_with[u]
+ print(" %-14s %-22s %s (disposition: %s)" % (mod, name, path, disp))
+ return 1
+ if not args.quiet:
+ print("nothing leaked: every path that reaches the test tier is closed in a release build")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/test-surface-ambiguous.json b/tools/test-surface-ambiguous.json
new file mode 100644
index 0000000..c3fd7e2
--- /dev/null
+++ b/tools/test-surface-ambiguous.json
@@ -0,0 +1,3 @@
+{
+ "pipeline.shutdown": "Two items share the name `shutdown`: `db::Writer::shutdown` and `pipeline::dispatch::Pool::shutdown`. Read dispatch.rs:61 — the pool's is now gated, and the only src/ call site of `.shutdown()` outside `pipeline` is the writer's. The collision is real; the verdict is that neither needs more than its current gate."
+}
diff --git a/tools/test-surface-interface.json b/tools/test-surface-interface.json
new file mode 100644
index 0000000..067a1a1
--- /dev/null
+++ b/tools/test-surface-interface.json
@@ -0,0 +1,3 @@
+{
+ "db.Writer": "`Db` has a `pub writer: Writer` field and pipeline, ops, review, watch and usecase all call `db.writer.tx(..)`. A field cannot be `pub` with a `pub(crate)` type — the compiler rejects it — so `Writer` is public because the public interface of `Db` requires it, not because a test asked. `tools/release-surface-probe.py` confirms it is reachable in a release build; that reachability is load-bearing, not residue."
+}
diff --git a/tools/test-surface-reasons.json b/tools/test-surface-reasons.json
index 8e4d320..f4d40dd 100644
--- a/tools/test-surface-reasons.json
+++ b/tools/test-surface-reasons.json
@@ -35,9 +35,11 @@
"pipeline.free_disk_mb": "the disk probe the dispatcher consults at dispatch.rs:106.",
"pipeline.index_world": "the world-index step, used by the pipeline at mod.rs:255 and steps.rs:92; tests/kata.rs checks what landed in the index.",
"pipeline.run_with": "the run entry point with an injected sandbox; production uses `run`, tests inject a fake.",
+ "pipeline.shutdown": "`Pool::shutdown` stops and joins the dispatcher threads. Production runs the pool until the process exits and never asks it to stop; tests/dispatch.rs and tests/crash.rs need the join so they can assert on the pool's effects after it is gone. Gated, not narrowed: no production build should carry a stop path nothing invokes.",
"review.BulkRefusal": "the bulk-refusal payload, built and matched across approve.rs; tests/approve.rs asserts on it.",
"review.LOW": "the risk floor, compared at risk.rs:94,189,195; tests/notices.rs pins where the floor bites.",
"review.render_and_store": "intake renders through `review::intake::record`; this wrapper has zero callers in src and 17 in tests. Gated, not relocated: it needs the module-private diff renderer.",
+ "review.withdraw": "Single-release withdraw. The CLI and the web UI both go through `usecase::withdraw_package` -> `pipeline::publish::withdraw_package`; nothing invokes this. tests/pipeline.rs pins its invariants (a second withdraw is refused, an unknown release is refused), so it is gated rather than deleted: the test is the cover for the operation production has not grown yet.",
"sandbox.Exit": "the sandbox exit record, named across the backends; tests/failure_modes.rs asserts on it.",
"sandbox.K8sSandboxProvisioner": "the kata provisioner impl; tests/kata.rs drives it directly.",
"sandbox.KataBackend": "selected by `backend_for` when the config names an agent-sandbox backend; tests/kata.rs drives it directly.",
diff --git a/tools/test-surface.md b/tools/test-surface.md
index 05e554f..740cf61 100644
--- a/tools/test-surface.md
+++ b/tools/test-surface.md
@@ -26,58 +26,72 @@ under `tests/` does. That definition is coarse in two ways that matter here:
| `gate` | add `#[cfg(feature = "test-support")]` | production never calls it; a test does |
| `move-test` | move the test into the module, then make the item private | the test that names it builds no fixture, so it is a unit test in the wrong file |
| `narrow` | `pub(crate)` or private | no test calls it at all (string-only mention) |
-| `residue` | stays `pub`, documented, counted | production needs it *inside* its module **and** a fixture-bound integration test needs it from outside |
+| `interface` | stays `pub`, and the probe proves it is reachable | a public signature requires it; no test asked for it |
+| `residue` | **a failure** | ungated, and nothing has argued why it should be |
-### Why `residue` exists at all
+### How visibility becomes feature-conditional
-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* an integration test needs from outside cannot be narrowed
-without breaking one or the other.
+For a free function, method, const or static, one body sits behind two
+declarations, exactly one of which compiles:
-The way to shrink that column is not a visibility change. It is to make the
-integration tests stop reaching in — by moving them into the module, or by
-exercising the behaviour through the module's real entry point. That is a
-test-design change with a real cost per row, recorded here rather than
-attempted blind.
+```rust
+#[cfg(feature = "test-support")] pub fn probe(..) -> .. { probe_impl(..) }
+#[cfg(not(feature = "test-support"))] pub(crate) fn probe(..) -> .. { probe_impl(..) }
+fn probe_impl(..) -> .. { .. }
+```
-The `residue` count is ratcheted by `tests/architecture.rs`, so it can only
-shrink.
+For a type, the real definition lives in a private module and a gated
+`pub use` is the only path to it:
+```rust
+mod kata_backend { pub struct KataBackend { .. } }
+#[cfg(feature = "test-support")] pub use kata_backend::KataBackend;
+#[cfg(not(feature = "test-support"))] pub(crate) use kata_backend::KataBackend;
+```
-## Feature-conditional visibility — production uses it, only from inside its module — 29 items
+A `pub` item in a private module has no nameable path from outside, yet is
+visible enough to appear in a public trait signature — which is how the
+return type of `Sandbox::run` narrows when a plain `pub(crate) struct`
+would be a private-in-public error.
+
+`residue` is not a verdict, it is an unargued row. The column is shrunk by
+applying one of the two shapes above, by moving the test into the module,
+or by deleting the item.
+
+Whether this table tells the truth is not checked by reading it.
+`tools/release-surface-probe.py` compiles a throwaway crate against the
+library twice, with and without `test-support`, and fails if any path that
+reaches the test tier also reaches a release build.
+
+
+## Public because a public signature requires it; no test asked for it — 1 items
+
+| module | item | declared at | test files | in-module call sites | why |
+|---|---|---|---|---|---|
+| `db` | `Writer` | `src/db/mod.rs:191` | `architecture.rs` | `src/db/audit.rs:10`, `src/db/audit.rs:74`, `src/db/mod.rs:329` +15 | `Db` has a `pub writer: Writer` field and pipeline, ops, review, watch and usecase all call `db.writer.tx(..)`. A field cannot be `pub` with a `pub(crate)` type — the compiler rejects it — so `Writer` is public because the public interface of `Db` requires it, not because a test asked. `tools/release-surface-probe.py` confirms it is reachable in a release build; that reachability is load-bearing, not residue. |
+
+## Feature-conditional visibility — production uses it, only from inside its module — 19 items
| module | item | declared at | test files | in-module call sites | why |
|---|---|---|---|---|---|
+| `config` | `shared_workspace` | `src/config.rs:98` | `config.rs`, `kata.rs`, `remote_agent.rs` | `src/config.rs:19`, `src/config.rs:30`, `src/config.rs:40` +8 | `Config::validate` calls it at config.rs:226; tests/kata.rs and tests/remote_agent.rs call it too and both need a fixture. |
| `config` | `store_dir` | `src/config.rs:376` | `architecture.rs`, `invariants.rs` | `src/config.rs:333`, `src/config.rs:389` ⚑ | the content-addressed store layout is resolved by this module for the cache and blob paths; tests/invariants.rs pins where a blob lands and needs a fixture. |
| `db` | `MIGRATIONS` | `src/db/migrations.rs:343` | `db.rs` | `src/db/mod.rs:157` | `db::migrate` iterates it to apply pending migrations; tests/db.rs asserts the list is ordered and complete. |
-| `db` | `ReleaseState` | `src/db/model/state.rs:85` | `pipeline.rs` | `src/db/model/mod.rs:137`, `src/db/model/state.rs:104`, `src/db/model/state.rs:105` +11 | a row type named by twenty sites inside db; tests/pipeline.rs names it while driving a real pipeline. |
-| `http` | `LogTail` | `src/http/sse.rs:18` | `live.rs` | `src/http/routes/pages.rs:510` | the SSE tail type; the live test that names it drives a real server. |
-| `http` | `Page` | `src/http/render.rs:9` | `common/mod.rs` | `src/http/render.rs:72`, `src/http/render.rs:79`, `src/http/render.rs:88` +16 | the render model, named by twenty sites in http; tests/mod.rs asserts on it directly. |
-| `http` | `Panel` | `src/http/render.rs:164` | `versions.rs` | `src/http/render.rs:132`, `src/http/routes/pages.rs:116`, `src/http/routes/pages.rs:149` +1 | a diff panel in the render model; tests/versions.rs asserts on its body. |
-| `http` | `cookie` | `src/http/mod.rs:41` | `common/mod.rs`, `http.rs` | `src/http/mod.rs:205`, `src/http/routes/mod.rs:38`, `src/http/routes/mod.rs:64` +2 ⚑ | the auth cookie helper; the tests that use it build no fixture, so they move into the module and it narrows. |
-| `http` | `login` | `src/http/routes/mod.rs:51` | `common/mod.rs`, `http.rs` | `src/http/mod.rs:199` | the login route handler; same — its tests are harness-free and move with it. |
+| `http` | `cookie` | `src/http/mod.rs:42` | `common/mod.rs`, `http.rs` | `src/http/mod.rs:223`, `src/http/routes/mod.rs:38`, `src/http/routes/mod.rs:64` +2 ⚑ | the auth cookie helper; the tests that use it build no fixture, so they move into the module and it narrows. |
+| `http` | `login` | `src/http/routes/mod.rs:51` | `common/mod.rs`, `http.rs` | `src/http/mod.rs:217` | the login route handler; same — its tests are harness-free and move with it. |
| `ops` | `STAGING_GRACE_SECS` | `src/ops.rs:333` | `ops.rs` | `src/ops.rs:300` | the grace period the staging sweep applies at ops.rs:286; tests/ops.rs pins the value it must be. |
| `ops` | `build_success_rate` | `src/ops.rs:51` | `ops.rs` | `src/ops.rs:101` ⚑ | computed inside the maintenance report at ops.rs:87; tests/ops.rs checks the arithmetic. |
| `ops` | `sweep_staging` | `src/ops.rs:363` | `ops.rs` | `src/ops.rs:300` | called by the maintenance pass at ops.rs:286; tests/ops.rs exercises it directly. |
-| `pipeline` | `admissible` | `src/pipeline/dispatch.rs:119` | `dispatch.rs` | `src/pipeline/dispatch.rs:100` | the dispatch filter, called at dispatch.rs:86; tests/dispatch.rs pins which builds it admits. |
-| `pipeline` | `dispatch_once` | `src/pipeline/dispatch.rs:76` | `dispatch.rs` | `src/pipeline/dispatch.rs:60` | one tick of the dispatcher, called by the scheduler loop at dispatch.rs:60; tests/dispatch.rs drives single ticks. |
-| `pipeline` | `free_disk_mb` | `src/pipeline/dispatch.rs:146` | `dispatch.rs` | `src/pipeline/dispatch.rs:134` | the disk probe the dispatcher consults at dispatch.rs:106. |
+| `pipeline` | `admissible` | `src/pipeline/dispatch.rs:130` | `dispatch.rs` | `src/pipeline/dispatch.rs:111` | the dispatch filter, called at dispatch.rs:86; tests/dispatch.rs pins which builds it admits. |
+| `pipeline` | `dispatch_once` | `src/pipeline/dispatch.rs:87` | `dispatch.rs` | `src/pipeline/dispatch.rs:71` | one tick of the dispatcher, called by the scheduler loop at dispatch.rs:60; tests/dispatch.rs drives single ticks. |
+| `pipeline` | `free_disk_mb` | `src/pipeline/dispatch.rs:157` | `dispatch.rs` | `src/pipeline/dispatch.rs:145` | the disk probe the dispatcher consults at dispatch.rs:106. |
| `pipeline` | `index_world` | `src/pipeline/publish.rs:26` | `kata.rs` | `src/pipeline/mod.rs:269`, `src/pipeline/mod.rs:292`, `src/pipeline/steps.rs:92` | the world-index step, used by the pipeline at mod.rs:255 and steps.rs:92; tests/kata.rs checks what landed in the index. |
| `pipeline` | `run_with` | `src/pipeline/mod.rs:194` | `failure_modes.rs`, `kata.rs`, `remote_agent.rs` | `src/pipeline/mod.rs:186` | the run entry point with an injected sandbox; production uses `run`, tests inject a fake. |
-| `review` | `BulkRefusal` | `src/review/approve.rs:162` | `approve.rs` | `src/review/approve.rs:151`, `src/review/approve.rs:199`, `src/review/approve.rs:203` +4 | the bulk-refusal payload, built and matched across approve.rs; tests/approve.rs asserts on it. |
| `review` | `LOW` | `src/review/risk.rs:13` | `notices.rs` | `src/review/risk.rs:105`, `src/review/risk.rs:200`, `src/review/risk.rs:206` | the risk floor, compared at risk.rs:94,189,195; tests/notices.rs pins where the floor bites. |
-| `sandbox` | `Exit` | `src/sandbox/mod.rs:44` | `failure_modes.rs` | `src/sandbox/agent.rs:210`, `src/sandbox/loopback.rs:72`, `src/sandbox/loopback.rs:101` +6 | the sandbox exit record, named across the backends; tests/failure_modes.rs asserts on it. |
-| `sandbox` | `KataBackend` | `src/sandbox/kata.rs:185` | `kata.rs` | `src/sandbox/kata.rs:195`, `src/sandbox/kata.rs:206`, `src/sandbox/mod.rs:121` | selected by `backend_for` when the config names an agent-sandbox backend; tests/kata.rs drives it directly. |
-| `sandbox` | `LoopbackBackend` | `src/sandbox/loopback.rs:19` | `failure_modes.rs` | `src/sandbox/mod.rs:116` | the default backend; tests/failure_modes.rs constructs it to inject a fault. |
-| `sandbox` | `RemoteBackend` | `src/sandbox/remote.rs:21` | `remote_agent.rs` | `src/sandbox/mod.rs:118` | the remote backend; tests/remote_agent.rs constructs it against a real agent. |
-| `sandbox` | `SandboxInfo` | `src/sandbox/mod.rs:82` | `failure_modes.rs` | `src/sandbox/kata.rs:305`, `src/sandbox/kata.rs:306`, `src/sandbox/loopback.rs:52` +4 | the return type of `SandboxBackend::status`; tests/failure_modes.rs reads its fields. |
-| `shims` | `manifest` | `src/shims/mod.rs:93` | `common/mod.rs`, `invariants.rs`, `pipeline.rs`, `production_surface.rs` … | `src/shims/mod.rs:190` | the shim manifest, read by `run` at mod.rs:161; seven test files read it to assert what a build did. |
-| `shims` | `valid_db_arg` | `src/shims/mod.rs:513` | `shims.rs` | `src/shims/mod.rs:553` | the shim's `--db` argument validator; production calls it at mod.rs:510, tests check its verdicts. |
-| `watch` | `StageBSlot` | `src/watch/upstream.rs:153` | `vcs.rs` | `src/watch/upstream.rs:165`, `src/watch/upstream.rs:213` | the stage-B cache slot shape; tests/vcs.rs asserts on it while driving a real mirror. |
+| `shims` | `manifest` | `src/shims/mod.rs:93` | `common/mod.rs`, `invariants.rs`, `pipeline.rs`, `production_surface.rs` … | `src/shims/mod.rs:191` | the shim manifest, read by `run` at mod.rs:161; seven test files read it to assert what a build did. |
+| `shims` | `valid_db_arg` | `src/shims/mod.rs:518` | `shims.rs` | `src/shims/mod.rs:558` | the shim's `--db` argument validator; production calls it at mod.rs:510, tests check its verdicts. |
| `watch` | `needs_stage_b` | `src/watch/upstream.rs:25` | `vcs.rs` | `src/watch/detect.rs:101` ⚑ | the stage-B predicate, consulted by detect.rs:101. |
-| `watch` | `probe` | `src/watch/upstream.rs:44` | `ops.rs`, `vcs.rs` | `src/watch/detect.rs:95` | the upstream probe, called by detect.rs:95; tests/ops.rs and tests/vcs.rs both need a fixture. |
+| `watch` | `probe` | `src/watch/upstream.rs:44` | `architecture.rs`, `ops.rs`, `vcs.rs` | `src/watch/detect.rs:95` | the upstream probe, called by detect.rs:95; tests/ops.rs and tests/vcs.rs both need a fixture. |
| `watch` | `sync_mirror` | `src/watch/mirror.rs:22` | `detect.rs` | `src/watch/detect.rs:40` | the mirror sync, called by detect.rs:40; tests/detect.rs drives a real sync. |
## Already gated — 17 items
@@ -88,29 +102,30 @@ shrink.
| `db` | `cas_accepted_release` | `src/db/pkgbases.rs:94` | `db.rs` | — | production performs this CAS inside a transaction via `cas_accepted_release_in` (publish.rs:208); the standalone form has no caller in the crate. The census credited it with a production caller at the `pub use` continuation line in db/mod.rs — a re-export is not a call. |
| `db` | `claim` | `src/db/builds/mod.rs:138` | `common/mod.rs`, `state_machine.rs`, `time.rs` | — | production leases with `claim_batch`; `claim` is called only by tests, so the release build need not compile it. |
| `db` | `set_setting` | `src/db/settings.rs:44` | `db.rs` | — | a settings writer with no production caller; `setting`/`setting_i64` readers are used, the setter is not. |
-| `db` | `shutdown` | `src/db/mod.rs:276` | `common/mod.rs`, `crash.rs`, `dispatch.rs` | — | `Writer::shutdown` is never called by the server; tests use it to quiesce the writer thread. |
| `db` | `snapshot_by_commit` | `src/db/snapshots.rs:55` | `detect.rs` | — | a snapshot lookup nothing in production performs. |
-| `db` | `tx_for_tests` | `src/db/mod.rs:283` | `approve.rs`, `common/mod.rs`, `db.rs`, `invariants.rs` … | — | already gated behind test-support — the pattern the rest of this table asks for. |
+| `db` | `tx_for_tests` | `src/db/mod.rs:284` | `approve.rs`, `common/mod.rs`, `db.rs`, `invariants.rs` … | — | already gated behind test-support — the pattern the rest of this table asks for. |
| `db` | `unapproved_index_entries` | `src/db/invariants.rs:15` | `db.rs`, `detect.rs`, `notices.rs`, `shims.rs` | — | an invariant query nothing runs; it needs `pub(crate)` diff internals to be useful, so it is gated rather than relocated. |
| `db` | `world_members` | `src/db/world.rs:32` | `db.rs` | — | a world-snapshot reader nothing calls; `put_world_snapshot` is the half production uses. |
+| `pipeline` | `shutdown` | `src/pipeline/dispatch.rs:61` | `architecture.rs`, `common/mod.rs`, `crash.rs`, `dispatch.rs` | — | `Pool::shutdown` stops and joins the dispatcher threads. Production runs the pool until the process exits and never asks it to stop; tests/dispatch.rs and tests/crash.rs need the join so they can assert on the pool's effects after it is gone. Gated, not narrowed: no production build should carry a stop path nothing invokes. |
| `review` | `render_and_store` | `src/review/diff.rs:282` | `approve.rs`, `common/mod.rs`, `crash.rs`, `dispatch.rs` … | — | intake renders through `review::intake::record`; this wrapper has zero callers in src and 17 in tests. Gated, not relocated: it needs the module-private diff renderer. |
+| `review` | `withdraw` | `src/review/approve.rs:234` | `architecture.rs`, `pipeline.rs`, `production_surface.rs` | — | Single-release withdraw. The CLI and the web UI both go through `usecase::withdraw_package` -> `pipeline::publish::withdraw_package`; nothing invokes this. tests/pipeline.rs pins its invariants (a second withdraw is refused, an unknown release is refused), so it is gated rather than deleted: the test is the cover for the operation production has not grown yet. |
| `sandbox` | `LocalAgentProvisioner` | `src/sandbox/kata.rs:134` | `kata.rs` | — | production selects `K8sSandboxProvisioner` (kata.rs:193); nothing in the crate constructs this type. It exists so tests can drive the real agent protocol against the shim binary without a cluster, so it is gated rather than deleted. The census credited its own `impl` headers as callers. |
| `sandbox` | `local_addr` | `src/sandbox/remote.rs:57` | `architecture.rs`, `remote_agent.rs` | `src/sandbox/kata.rs:238`, `src/sandbox/mod.rs:144` ⚑ | DELETED from kata.rs and gated on remote.rs. `KataBackend::local_addr` had zero callers anywhere and is gone; `RemoteBackend::local_addr` is called only by tests/remote_agent.rs, so it is gated. Both were credited with production callers at `listener.local_addr()`, which is std's method on a TcpListener in a sibling file — the census treats all of src/sandbox as one module and a name match cannot tell a receiver's type. This row is why `dotted_only` confirmation exists. |
-| `shims` | `called_with` | `src/shims/mod.rs:173` | `crash.rs`, `dispatch.rs`, `invariants.rs`, `kata.rs` … | — | reads the shim's invocation log, which only tests inspect. |
-| `shims` | `invocations` | `src/shims/mod.rs:155` | `shims.rs` | — | the shim appends to invocations.jsonl in production but nothing reads it back; the two credited sites name the *filename* in a string, and the only reader, `called_with`, is itself gated. Gated with it. |
+| `shims` | `called_with` | `src/shims/mod.rs:174` | `crash.rs`, `dispatch.rs`, `invariants.rs`, `kata.rs` … | — | reads the shim's invocation log, which only tests inspect. |
+| `shims` | `invocations` | `src/shims/mod.rs:156` | `shims.rs` | — | the shim appends to invocations.jsonl in production but nothing reads it back; the two credited sites name the *filename* in a string, and the only reader, `called_with`, is itself gated. Gated with it. |
| `time` | `unpin` | `src/time.rs:57` | `time.rs` | — | the clock escape hatch; `pin`/`unpin` exist so a test can freeze time. Its only in-module mention is a unit test. |
-| `time` | `virtual_sleep` | `src/time.rs:178` | `production_surface.rs` | `src/time.rs:90`, `src/time.rs:106` | already gated behind test-support. |
| `time` | `virtualize` | `src/time.rs:129` | `crash.rs`, `dispatch.rs`, `production_surface.rs` | — | already gated behind test-support. |
## Totals
| disposition | count |
|---|---|
-| `narrowed` | 29 |
+| `interface` | 1 |
+| `narrowed` | 19 |
| `already-gated` | 17 |
-| **total** | **46** |
+| **total** | **37** |
-Of these, 0 are ungated today. Gating the `gate` rows and narrowing the
+Of these, 1 are ungated today. Gating the `gate` rows and narrowing the
`narrow` rows removes 0 items from the release build's public surface; the
`move-test` rows remove 0 more and take their tests home with them.
diff --git a/tools/test-surface.py b/tools/test-surface.py
index 6121889..b8e856b 100644
--- a/tools/test-surface.py
+++ b/tools/test-surface.py
@@ -17,12 +17,32 @@ Those two questions yield the four dispositions written to
`tools/test-surface.md`. Run with `--json` for the machine-readable form, whose
`residue` count `tests/architecture.rs` ratchets.
-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 therefore cannot be narrowed
-without breaking one or the other. Those rows are `residue`, and the only way to
-shrink them is to change the tests, not the visibility.
+Two shapes make visibility feature-conditional, and the table records which one
+an item uses. For a free function, method, const or static, one body sits behind
+two declarations:
+
+ #[cfg(feature = "test-support")] pub fn probe(..) -> .. { probe_impl(..) }
+ #[cfg(not(feature = "test-support"))] pub(crate) fn probe(..) -> .. { probe_impl(..) }
+ fn probe_impl(..) -> .. { .. }
+
+For a type, the real definition lives in a private module and a gated `pub use`
+is the only path to it:
+
+ mod kata_backend { pub struct KataBackend { .. } }
+ #[cfg(feature = "test-support")] pub use kata_backend::KataBackend;
+ #[cfg(not(feature = "test-support"))] pub(crate) use kata_backend::KataBackend;
+
+A `pub` item in a private module has no nameable path from outside, yet is
+visible enough to appear in a public trait signature — which is why the return
+type of `Sandbox::run` narrows this way when a plain `pub(crate) struct` would
+be a private-in-public error.
+
+`residue` is therefore a failure, not a verdict: it means an item is still
+ungated and nothing has argued it should be. The only honest dispositions are
+the ones that close the release build, plus `interface` for the rare item a
+public signature forces open. Whether the table is telling the truth is checked
+by compiling against the library, not by reading it — see
+`tools/release-surface-probe.py`.
"""
import argparse, collections, json, os, re, sys
@@ -53,6 +73,19 @@ REASONS = json.load(open(os.path.join(ROOT, "tools", "test-surface-reasons.json"
# and absent from this list fails `tests/architecture.rs`.
CONFIRMED = set(json.load(open(os.path.join(ROOT, "tools", "test-surface-confirmed.json"))))
+# Rows whose production-use verdict rests on a bare mention of a name the
+# detector cannot resolve to one item. Each entry is a human verdict on the
+# cited line; a row that is ambiguous and absent here fails the architecture
+# test, because "the tool could not tell" is not a disposition.
+AMBIGUOUS = json.load(open(os.path.join(ROOT, "tools", "test-surface-ambiguous.json")))
+
+# Items that stay `pub` in a release build because a public signature requires
+# them, not because a test asked. Each entry states the signature. This is the
+# one disposition that admits reachability, so it is declared by hand and the
+# probe verifies it: `db::Writer` is public because `Db.writer` is a `pub` field
+# and Rust will not type a public field with a private type.
+INTERFACE = json.load(open(os.path.join(ROOT, "tools", "test-surface-interface.json")))
+
def rust_files(d):
out = []
@@ -248,24 +281,83 @@ def integration_tests(path):
return out
+def enclosing_mods_are_private(lines, idx):
+ """True when every module enclosing `lines[idx]` is a private `mod`.
+
+ A `pub` item inside a private module has no nameable path from outside the
+ parent, so it is not a public declaration. This is the second half of the
+ inner-module narrowing; without it the detector reads `pub fn new` inside
+ `mod log_tail` and reports an `http::new` that nothing can reach.
+ """
+ depth, enclosed = 0, []
+ for k in range(idx - 1, -1, -1):
+ depth += lines[k].count("{") - lines[k].count("}")
+ if depth > 0:
+ m = re.match(r"^\s*(pub(?:\(crate\))?\s+)?mod\s+\w+", lines[k])
+ if m:
+ enclosed.append(m.group(1))
+ depth -= 1
+ return bool(enclosed) and not any(enclosed)
+
+
def analyse():
src = {p: open(p).read() for p in rust_files(SRC)}
tests = {p: open(p).read() for p in rust_files(TESTS)}
+
+ # Rows are keyed by (module, name), not by bare name. `pipeline::dispatch::
+ # Pool::shutdown` and `db::Writer::shutdown` are two items; keyed by name
+ # alone they merged into one row, and because the `db` one is gated the
+ # ungated one was reported `already-gated`.
names = collections.defaultdict(list)
for path, text in src.items():
- for line in text.splitlines():
+ lines = text.splitlines()
+ for line_no, line in enumerate(lines):
if COMMENT.match(line):
continue
m = PUB_RE.match(line)
- if m:
- names[m.group(1)].append(path)
+ if m and not enclosing_mods_are_private(lines, line_no):
+ names[(module_of(path), m.group(1))].append(path)
+
+ # A production mention, counted per line with comments and string literals
+ # removed. Searching raw text is what made `review::approve::withdraw` look
+ # production-used: the only src/ hits for the bare word outside `review`
+ # were the route pattern "packages/{name}/withdraw" and an audit action
+ # string, and every real caller named `withdraw_package` or
+ # `withdraw_release_in`, which are different items.
+ stripped = {p: "\n".join("" if COMMENT.match(l) else strip_noise(l)
+ for l in t.splitlines())
+ for p, t in src.items()}
+
+ # A bare mention in another module cannot be resolved to one item when the
+ # same name is declared in several modules — `new`, `parse` and `open` are
+ # declared all over the crate, and a line saying `Foo::new()` in `http` says
+ # nothing about `db::open`. For a colliding name a mention counts only if
+ # the line actually routes through the declaring module: a qualified path
+ # (`db::open`, `crate::db::open`) or a `use` that imports from it. A
+ # colliding name with unqualified mentions is kept and flagged, because the
+ # honest answer is "a line-based tool cannot tell" and a human should.
+ collisions = {name for (mod, name) in names if
+ len({m for (m, n) in names if n == name}) > 1}
+
+ def mentioned(line, mod, name):
+ if not re.search(r"\b%s\b" % re.escape(name), line):
+ return None # not a mention at all
+ if name not in collisions:
+ return True # only one item could mean this
+ top = mod.split(os.sep)[0]
+ if re.search(r"\b%s\s*::[^;]*\b%s\b" % (re.escape(top), re.escape(name)), line):
+ return True # qualified path through the module
+ if re.match(r"^\s*(pub\s+)?use\b", line) and re.search(r"\b%s\s*::" % re.escape(top), line):
+ return True # an import from the module
+ return False # colliding and unqualified: unknown
rows = []
- for name, paths in sorted(names.items()):
- declaring = {module_of(p) for p in paths}
- if any(module_of(p) not in declaring and re.search(r"\b%s\b" % re.escape(name), t)
- for p, t in src.items()):
- continue
+ for (mod, name), paths in sorted(names.items()):
+ hits = [v for p, text in stripped.items() if module_of(p) != mod
+ for v in [mentioned(text, mod, name)] if v is not None]
+ if any(hits):
+ continue # production uses it outside the module
+ ambiguous_collision = any(v is False for v in hits)
users = sorted(os.path.relpath(f, TESTS) for f, t in tests.items()
if re.search(r"\b%s\b" % re.escape(name), t))
if not users:
@@ -290,7 +382,6 @@ def analyse():
sites.append((f, tname, any(k in body for k in HARNESS)))
internal = []
- mod = module_of(paths[0])
base = os.path.join(SRC, mod)
files = rust_files(base) if os.path.isdir(base) else [os.path.join(SRC, mod + ".rs")]
pat = re.compile(r"\b%s\b" % re.escape(name))
@@ -344,7 +435,9 @@ def analyse():
for t in (open(pp).read() for pp in paths)
)
- if gated and narrowed:
+ if ("%s.%s" % (mod, name)) in INTERFACE:
+ disp = "interface"
+ elif gated and narrowed:
disp = "narrowed"
elif gated:
disp = "already-gated"
@@ -358,30 +451,35 @@ def analyse():
disp = "residue"
rows.append(dict(
- module=mod, name=name,
+ module=mod, name=name, ambiguous=ambiguous_collision,
where=("%s:%d" % (occ[0][0], occ[0][1])) if occ else "?",
gated=gated, narrowed=narrowed, string_only=string_only, tests=users,
internal=internal, dotted_only=dotted_only,
confirmed=("%s.%s" % (mod, name)) in CONFIRMED,
+ adjudicated=("%s.%s" % (mod, name)) in AMBIGUOUS,
+ justified=("%s.%s" % (mod, name)) in INTERFACE,
sites=[list(s) for s in sites],
disp=disp,
reason=(REASONS.get("%s.%s" % (mod, name))
+ or INTERFACE.get("%s.%s" % (mod, name))
or ("production uses it at %s (%d sites in-module); the test that "
"names it needs a fixture."
% ("`, `".join(internal[:3]), len(internal)) if internal
else "nothing in src calls it; a test does.")),
- hand_written=("%s.%s" % (mod, name)) in REASONS,
+ hand_written=("%s.%s" % (mod, name)) in REASONS
+ or ("%s.%s" % (mod, name)) in INTERFACE,
))
return rows
def render(rows):
- order = ["gate", "move-test", "narrow", "residue", "narrowed", "already-gated"]
+ order = ["gate", "move-test", "narrow", "residue", "interface", "narrowed", "already-gated"]
title = {"gate": "Gate behind `test-support`",
"move-test": "Move the test into the module, then narrow",
"narrow": "Narrow — no test actually calls it",
- "residue": "Residue — `pub` because Rust has no test-conditional visibility",
+ "residue": "Residue — ungated and unargued; a failure, not a verdict",
"already-gated": "Already gated",
+ "interface": "Public because a public signature requires it; no test asked for it",
"narrowed": "Feature-conditional visibility — production uses it, only from inside its module"}
out = [open(DOC).read().split("## gate-marker")[0]] if False else []
L = []
@@ -406,19 +504,34 @@ def render(rows):
A("| `gate` | add `#[cfg(feature = \"test-support\")]` | production never calls it; a test does |")
A("| `move-test` | move the test into the module, then make the item private | the test that names it builds no fixture, so it is a unit test in the wrong file |")
A("| `narrow` | `pub(crate)` or private | no test calls it at all (string-only mention) |")
- A("| `residue` | stays `pub`, documented, counted | production needs it *inside* its module **and** a fixture-bound integration test needs it from outside |\n")
- A("### Why `residue` exists at all\n")
- A("Rust has no test-conditional visibility. No attribute makes an item `pub`\n"
- "under one feature and `pub(crate)` under another, and `pub use` cannot\n"
- "re-export a `pub(crate)` item. An item that production needs inside its own\n"
- "module *and* an integration test needs from outside cannot be narrowed\n"
- "without breaking one or the other.\n")
- A("The way to shrink that column is not a visibility change. It is to make the\n"
- "integration tests stop reaching in — by moving them into the module, or by\n"
- "exercising the behaviour through the module's real entry point. That is a\n"
- "test-design change with a real cost per row, recorded here rather than\n"
- "attempted blind.\n")
- A("The `residue` count is ratcheted by `tests/architecture.rs`, so it can only\nshrink.\n")
+ A("| `interface` | stays `pub`, and the probe proves it is reachable | a public signature requires it; no test asked for it |")
+ A("| `residue` | **a failure** | ungated, and nothing has argued why it should be |\n")
+ A("### How visibility becomes feature-conditional\n")
+ A("For a free function, method, const or static, one body sits behind two\n"
+ "declarations, exactly one of which compiles:\n")
+ A("```rust\n"
+ "#[cfg(feature = \"test-support\")] pub fn probe(..) -> .. { probe_impl(..) }\n"
+ "#[cfg(not(feature = \"test-support\"))] pub(crate) fn probe(..) -> .. { probe_impl(..) }\n"
+ "fn probe_impl(..) -> .. { .. }\n"
+ "```\n")
+ A("For a type, the real definition lives in a private module and a gated\n"
+ "`pub use` is the only path to it:\n")
+ A("```rust\n"
+ "mod kata_backend { pub struct KataBackend { .. } }\n"
+ "#[cfg(feature = \"test-support\")] pub use kata_backend::KataBackend;\n"
+ "#[cfg(not(feature = \"test-support\"))] pub(crate) use kata_backend::KataBackend;\n"
+ "```\n")
+ A("A `pub` item in a private module has no nameable path from outside, yet is\n"
+ "visible enough to appear in a public trait signature — which is how the\n"
+ "return type of `Sandbox::run` narrows when a plain `pub(crate) struct`\n"
+ "would be a private-in-public error.\n")
+ A("`residue` is not a verdict, it is an unargued row. The column is shrunk by\n"
+ "applying one of the two shapes above, by moving the test into the module,\n"
+ "or by deleting the item.\n")
+ A("Whether this table tells the truth is not checked by reading it.\n"
+ "`tools/release-surface-probe.py` compiles a throwaway crate against the\n"
+ "library twice, with and without `test-support`, and fails if any path that\n"
+ "reaches the test tier also reaches a release build.\n")
tot = collections.Counter(r["disp"] for r in rows)
for d in order:
sel = sorted([r for r in rows if r["disp"] == d], key=lambda r: (r["module"], r["name"]))
@@ -449,6 +562,22 @@ def render(rows):
return "\n".join(L) + "\n"
+def tally(rows):
+ """The one definition of the test-surface counts.
+
+ Two copies of this rule drifted the first time the `interface` exclusion was
+ added to only one of them, and the budget then recorded as ungated an item
+ the report called justified.
+ """
+ counts = collections.Counter(r["disp"] for r in rows)
+ counts["gate_pending"] = sum(1 for r in rows if r["disp"] == "gate" and not r["gated"])
+ counts["ungated"] = sum(1 for r in rows
+ if not r["gated"] and r["disp"] != "interface")
+ counts["total"] = len(rows)
+ counts["release_exposed"] = counts["ungated"]
+ return counts
+
+
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("--json", action="store_true")
@@ -458,25 +587,17 @@ if __name__ == "__main__":
a = ap.parse_args()
rows = analyse()
if a.json:
- counts = collections.Counter(r["disp"] for r in rows)
- counts["gate_pending"] = sum(1 for r in rows if r["disp"] == "gate" and not r["gated"])
- counts["ungated"] = sum(1 for r in rows if not r["gated"])
- counts["total"] = len(rows)
- counts["release_exposed"] = sum(1 for r in rows if not r["gated"])
- print(json.dumps({"rows": rows, "counts": counts}, indent=1))
+ print(json.dumps({"rows": rows, "counts": tally(rows)}, indent=1))
elif a.write_budget:
- rows = analyse()
- counts = collections.Counter(r["disp"] for r in rows)
- counts["gate_pending"] = sum(1 for r in rows if r["disp"] == "gate" and not r["gated"])
- counts["ungated"] = sum(1 for r in rows if not r["gated"])
- counts["total"] = len(rows)
+ counts = tally(rows)
path = a.write_budget
if not os.path.isabs(path):
path = os.path.join(ROOT, path)
budget = json.load(open(path))
budget["test_surface"] = {k: counts[k] for k in
("gate", "gate_pending", "move-test", "narrow",
- "residue", "narrowed", "already-gated", "total", "ungated")
+ "residue", "interface", "narrowed", "already-gated",
+ "total", "ungated")
if counts[k]}
with open(path, "w") as handle:
json.dump(budget, handle, indent=2, sort_keys=True)