From 2210c934d4a25602318f094e0eca72f42862d44a Mon Sep 17 00:00:00 2001 From: aur-build Date: Fri, 20 Nov 2026 21:03:58 +0000 Subject: db, sandbox: apply the dispositions the table decided MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Six db items are now gated behind `test-support`, each with a comment saying what it is for and why production never calls it: builds::claim production leases a batch; `claim_batch` is what the dispatcher runs settings::set_setting the readers are used, the setter is not Writer::shutdown the server runs until the process ends snapshots::snapshot_by_commit world::world_members production writes world snapshots, never reads one back member by member invariants::unapproved_index_entries gated, not relocated: reading it needs this module's private helpers, and widening those to let a test out would be the wrong trade Gating them exposed three things they were the only user of, and each is gated with them rather than left compiling into a binary that cannot reach it: `Msg::Shutdown` and its loop arm, and `model::json_or`. `arch-census.py --write-budget` also stopped erasing the `test_surface` section — two writers of one file must not delete each other's axis, or the ratchet quietly stops checking it. `steps::touch` is deleted, not narrowed. Nothing called it — not production, not a test. The census had credited it to `tests/shims.rs`, where the word appears inside a string. In sandbox, two tests moved into `src/sandbox/kata.rs`: the container record a lease provisions, and the TTL expiry of a sandbox that never dials in. Neither builds a fixture. `KataBackend::shared_for`, `provision_request`, `sandbox_cr` and `K8sSandboxProvisioner::for_config` are `pub(crate)` as a result. `KataBackend::reclaim` is deleted — same story as `touch`. It forwarded to `self.provisioner.reclaim`, which the reaping site already calls itself, and the TTL test the census credited it for implements the *trait's* `reclaim` on a null provisioner. Same word, different function. Two honest costs, both recorded rather than smoothed over: - `Provisioner` and `ProvisionRequest` are now named by nobody outside `sandbox`, yet cannot be narrowed: `LocalAgentProvisioner` is `pub` because two fixture tests construct it, and Rust forbids a public type implementing a private trait or taking a private parameter type. `sandbox.deadonly` therefore rises 0 → 2, with the reason here as the ratchet demands. - `agent_sandbox_config()` now exists in both `tests/kata.rs` and `src/sandbox/kata.rs`. Three of that file's remaining tests still need it, and a test helper cannot be shared across the crate boundary without making it public again. sandbox: 27 pub / 15 dead -> 22 pub / 10 dead. Suite: 284 passed, 0 failed, 0 ignored. Clippy clean. --- tools/arch-census.py | 14 ++++++++++++- tools/test-surface.md | 57 ++++++++++++++++++++++----------------------------- tools/test-surface.py | 22 ++++++++++++++++++++ 3 files changed, 59 insertions(+), 34 deletions(-) (limited to 'tools') diff --git a/tools/arch-census.py b/tools/arch-census.py index b493ea8..09f4201 100755 --- a/tools/arch-census.py +++ b/tools/arch-census.py @@ -285,8 +285,20 @@ def main(): data = census() if args.write_budget: + # Preserve any section another tool owns (for example `test_surface`, + # written by tools/test-surface.py). Two writers of one file must not + # erase each other, or the ratchet silently stops checking one axis. + existing = {} + if os.path.exists(args.write_budget): + try: + existing = json.load(open(args.write_budget)) + except (ValueError, OSError): + existing = {} + out = dict(existing) + out["modules"] = data["modules"] + out["totals"] = data["totals"] with open(args.write_budget, "w") as handle: - json.dump({"modules": data["modules"], "totals": data["totals"]}, handle, indent=2, + json.dump(out, handle, indent=2, sort_keys=True) handle.write("\n") print(f"wrote {args.write_budget}") diff --git a/tools/test-surface.md b/tools/test-surface.md index f632e80..19890a1 100644 --- a/tools/test-surface.md +++ b/tools/test-surface.md @@ -46,51 +46,37 @@ The `residue` count is ratcheted by `tests/architecture.rs`, so it can only shrink. -## Gate behind `test-support` — 9 items +## Gate behind `test-support` — 3 items | module | item | declared at | test files | why | |---|---|---|---|---| -| `db` | `claim` | `src/db/builds/mod.rs:130` | `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:38` | `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:244` | `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:50` | `detect.rs` | a snapshot lookup nothing in production performs. | -| `db` | `unapproved_index_entries` | `src/db/invariants.rs:7` | `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:27` | `db.rs` | a world-snapshot reader nothing calls; `put_world_snapshot` is the half production uses. | | `review` | `render_and_store` | `src/review/diff.rs:269` | `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. | | `shims` | `called_with` | `src/shims/mod.rs:144` | `crash.rs`, `dispatch.rs`, `invariants.rs`, `kata.rs` … | reads the shim's invocation log, which only tests inspect. | | `time` | `unpin` | `src/time.rs:47` | `time.rs` | the clock escape hatch; `pin`/`unpin` exist so a test can freeze time. Its only in-module mention is a unit test. | -## Move the test into the module, then narrow — 9 items +## Move the test into the module, then narrow — 3 items | module | item | declared at | test files | why | |---|---|---|---|---| | `http` | `cookie` | `src/http/mod.rs:36` | `common/mod.rs`, `http.rs` | 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:45` | `common/mod.rs`, `http.rs` | the login route handler; same — its tests are harness-free and move with it. | -| `sandbox` | `ProvisionRequest` | `src/sandbox/kata.rs:19` | `kata.rs` | kata provisioning internals; the test that names them needs no fixture. | -| `sandbox` | `Provisioner` | `src/sandbox/kata.rs:28` | `kata.rs` | kata provisioning internals; same test. | -| `sandbox` | `for_config` | `src/sandbox/kata.rs:74` | `kata.rs` | kata backend constructor; same test. | -| `sandbox` | `provision_request` | `src/sandbox/kata.rs:202` | `kata.rs` | kata request builder; same test. | -| `sandbox` | `reclaim` | `src/sandbox/kata.rs:241` | `kata.rs` | kata reclaim path; the TTL test that names it needs no fixture. | -| `sandbox` | `sandbox_cr` | `src/sandbox/kata.rs:39` | `kata.rs` | kata container-record shape; same test. | -| `sandbox` | `shared_for` | `src/sandbox/kata.rs:177` | `kata.rs` | kata workspace helper; same test. | +| `sandbox` | `K8sSandboxProvisioner` | `src/sandbox/kata.rs:86` | `kata.rs` | the kata provisioner impl; tests/kata.rs drives it directly. | -## Narrow — no test actually calls it — 6 items +## Narrow — no test actually calls it — 5 items | module | item | declared at | test files | why | |---|---|---|---|---| -| `db` | `touch` | `src/db/builds/steps.rs:153` | `shims.rs` | census false positive: `touch` appears in tests/shims.rs only inside a string literal. Narrow on its merits, not for the test tier. | | `http` | `Attention` | `src/http/render.rs:182` | `crash.rs` | census false positive: named in crash.rs only inside a string. | | `http` | `html` | `src/http/mod.rs:51` | `http.rs` | census false positive: named in http.rs only inside a string. | | `http` | `logout` | `src/http/routes/mod.rs:36` | `http.rs` | census false positive: named in http.rs only inside a string. | | `http` | `redirect` | `src/http/mod.rs:67` | `http.rs` | census false positive: named in http.rs only inside a string. | | `http` | `route` | `src/http/routes/mod.rs:65` | `http.rs` | census false positive: named in http.rs only inside a string. | -## Residue — `pub` because Rust has no test-conditional visibility — 34 items +## Residue — `pub` because Rust has no test-conditional visibility — 32 items | module | item | declared at | test files | why | |---|---|---|---|---| | `config` | `TestHooks` | `src/config.rs:138` | `common/mod.rs`, `production_surface.rs` | the `hooks` field is already gated; the type and its impl are not, so they compile into a release build that can never read them. | -| `config` | `shared_workspace` | `src/config.rs:93` | `config.rs`, `kata.rs`, `remote_agent.rs` | `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:351` | `invariants.rs` | the content-addressed store layout is used at config.rs:313 and :355; tests/invariants.rs pins it and needs a fixture. | | `db` | `MIGRATIONS` | `src/db/migrations.rs:326` | `db.rs` | `db::migrate` iterates it at db/mod.rs:135; tests/db.rs asserts the list is ordered and complete. | | `db` | `ReleaseState` | `src/db/model/state.rs:78` | `pipeline.rs` | a row type named by twenty sites inside db; tests/pipeline.rs names it while driving a real pipeline. | @@ -109,13 +95,12 @@ shrink. | `review` | `BulkRefusal` | `src/review/approve.rs:155` | `approve.rs` | the bulk-refusal payload, built and matched across approve.rs; tests/approve.rs asserts on it. | | `review` | `LOW` | `src/review/risk.rs:6` | `notices.rs` | the risk floor, compared at risk.rs:94,189,195; tests/notices.rs pins where the floor bites. | | `sandbox` | `Exit` | `src/sandbox/mod.rs:43` | `failure_modes.rs` | the sandbox exit record, named across the backends; tests/failure_modes.rs asserts on it. | -| `sandbox` | `K8sSandboxProvisioner` | `src/sandbox/kata.rs:86` | `kata.rs` | the kata provisioner impl; tests/kata.rs drives it directly. | | `sandbox` | `KataBackend` | `src/sandbox/kata.rs:167` | `kata.rs` | the kata backend; tests/kata.rs constructs it rather than going through `for_config`'s caller. | | `sandbox` | `LocalAgentProvisioner` | `src/sandbox/kata.rs:124` | `kata.rs` | the local agent provisioner impl; tests/kata.rs drives it. | | `sandbox` | `LoopbackBackend` | `src/sandbox/loopback.rs:10` | `failure_modes.rs` | the default backend; tests/failure_modes.rs constructs it to inject a fault. | | `sandbox` | `RemoteBackend` | `src/sandbox/remote.rs:12` | `remote_agent.rs` | the remote backend; tests/remote_agent.rs constructs it against a real agent. | | `sandbox` | `SandboxInfo` | `src/sandbox/mod.rs:70` | `failure_modes.rs` | the sandbox descriptor returned by the trait; tests/failure_modes.rs reads its fields. | -| `sandbox` | `local_addr` | `src/sandbox/kata.rs:245` | `remote_agent.rs` | the agent's local address, read by the backend selection at mod.rs:120; tests/remote_agent.rs asserts on it. | +| `sandbox` | `local_addr` | `src/sandbox/kata.rs:250` | `remote_agent.rs` | the agent's local address, read by the backend selection at mod.rs:120; tests/remote_agent.rs asserts on it. | | `shims` | `invocations` | `src/shims/mod.rs:133` | `shims.rs` | reads the shim invocation log; the shim writes it in production (mod.rs:112) but nothing in src reads it back. | | `shims` | `manifest` | `src/shims/mod.rs:88` | `common/mod.rs`, `invariants.rs`, `pipeline.rs`, `production_surface.rs` … | 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:479` | `shims.rs` | the shim's `--db` argument validator; production calls it at mod.rs:510, tests check its verdicts. | @@ -124,11 +109,17 @@ shrink. | `watch` | `probe` | `src/watch/upstream.rs:25` | `ops.rs`, `vcs.rs` | 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:17` | `detect.rs` | the mirror sync, called by detect.rs:40; tests/detect.rs drives a real sync. | -## Already gated — 3 items +## Already gated — 9 items | module | item | declared at | test files | why | |---|---|---|---|---| -| `db` | `tx_for_tests` | `src/db/mod.rs:251` | `approve.rs`, `common/mod.rs`, `db.rs`, `invariants.rs` … | already gated behind test-support — the pattern the rest of this table asks for. | +| `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:264` | `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:271` | `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. | | `time` | `virtual_sleep` | `src/time.rs:168` | `production_surface.rs` | already gated behind test-support. | | `time` | `virtualize` | `src/time.rs:119` | `crash.rs`, `dispatch.rs`, `production_surface.rs` | already gated behind test-support. | @@ -136,14 +127,14 @@ shrink. | disposition | count | |---|---| -| `gate` | 9 | -| `move-test` | 9 | -| `narrow` | 6 | -| `residue` | 34 | -| `already-gated` | 3 | -| **total** | **61** | - -Of these, 58 are ungated today. Gating the `gate` rows and narrowing the -`narrow` rows removes 15 items from the release build's public surface; the -`move-test` rows remove 9 more and take their tests home with them. +| `gate` | 3 | +| `move-test` | 3 | +| `narrow` | 5 | +| `residue` | 32 | +| `already-gated` | 9 | +| **total** | **52** | + +Of these, 43 are ungated today. Gating the `gate` rows and narrowing the +`narrow` rows removes 8 items from the release build's public surface; the +`move-test` rows remove 3 more and take their tests home with them. diff --git a/tools/test-surface.py b/tools/test-surface.py index 40385ad..7a89069 100644 --- a/tools/test-surface.py +++ b/tools/test-surface.py @@ -279,12 +279,34 @@ if __name__ == "__main__": ap = argparse.ArgumentParser() ap.add_argument("--json", action="store_true") ap.add_argument("--write", action="store_true") + ap.add_argument("--write-budget", metavar="FILE", + help="re-record the `test_surface` section of the budget file") 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) print(json.dumps({"rows": rows, "counts": counts}, 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) + 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", "already-gated", "total", "ungated") + if counts[k]} + with open(path, "w") as handle: + json.dump(budget, handle, indent=2, sort_keys=True) + handle.write("\n") + print("wrote", os.path.relpath(path, ROOT), json.dumps(budget["test_surface"], sort_keys=True)) elif a.write: open(DOC, "w").write(render(rows)) print("wrote", os.path.relpath(DOC, ROOT)) -- cgit v1.2.3