diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/arch-census.md | 32 | ||||
| -rw-r--r-- | tools/test-surface-confirmed.json | 6 | ||||
| -rw-r--r-- | tools/test-surface-reasons.json | 16 | ||||
| -rw-r--r-- | tools/test-surface.md | 116 | ||||
| -rw-r--r-- | tools/test-surface.py | 172 |
5 files changed, 241 insertions, 101 deletions
diff --git a/tools/arch-census.md b/tools/arch-census.md index ce0647c..c80c1ea 100644 --- a/tools/arch-census.md +++ b/tools/arch-census.md @@ -199,6 +199,38 @@ more capable. `largest` is reported and not budgeted for exactly that reason — counting lines across a module and its tests measures the wrong thing, and a ceiling on it would discourage moving tests home, which is the whole movement. +### The detector was wrong, and four items were mis-sorted because of it + +The first version of `tools/test-surface.py` decided "production uses this" by +searching the declaring module's files for the name. That credited four items +with callers they do not have, and each false credit was a different mistake: + +| item | what the detector believed | what is actually there | +|---|---|---| +| `db::cas_accepted_release` | a call at `db/mod.rs:55` | a `pub use` continuation line — a re-export is not a call | +| `shims::invocations` | calls at `mod.rs:112`, `:134` | the string `"invocations.jsonl"`, and a call from `called_with`, which is itself gated | +| `sandbox::LocalAgentProvisioner` | three call sites | its own `struct` and `impl` headers | +| `sandbox::local_addr` | `kata.rs:220`, `mod.rs:120` | `listener.local_addr()` — std's method on a `TcpListener`, in sibling files | + +All four are now gated, and `KataBackend::local_addr` — which had no caller in +`src` or in any test — is deleted. The detector now strips string literals and +comments, skips `use` statements including the continuation lines of a +brace-delimited block, skips an item's own `impl` headers, and does not count a +call made inside a `#[cfg(test)]` module or a `test-support`-gated item. + +The last case is the one a regex cannot resolve: `self.store_dir()` and +`listener.local_addr()` are indistinguishable by name match. Rows whose only +evidence is a call in method position are flagged `⚑` in +`tools/test-surface.md`, and `the_test_surface_is_disposed_of` fails until a +human has read the cited line and listed the row in +`tools/test-surface-confirmed.json`. Four rows are confirmed that way; the fifth +was the dead accessor. + +This matters more than the four items. The residue column is the one number this +report cannot eliminate, so the claim underneath it — *every residue item has a +real production caller* — has to be checkable, not asserted. The table now +prints each item's in-module call sites for exactly that reason. + ### What the ratchet now also holds `tests/architecture.rs` gained `the_test_surface_is_disposed_of`, which runs diff --git a/tools/test-surface-confirmed.json b/tools/test-surface-confirmed.json new file mode 100644 index 0000000..972d6fc --- /dev/null +++ b/tools/test-surface-confirmed.json @@ -0,0 +1,6 @@ +[ + "config.store_dir", + "http.cookie", + "watch.needs_stage_b", + "ops.build_success_rate" +]
\ No newline at end of file diff --git a/tools/test-surface-reasons.json b/tools/test-surface-reasons.json index 3ac9585..b85eeff 100644 --- a/tools/test-surface-reasons.json +++ b/tools/test-surface-reasons.json @@ -1,10 +1,10 @@ { "config.TestHooks": "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": "`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": "the content-addressed store layout is used at config.rs:313 and :355; tests/invariants.rs pins it and needs a fixture.", - "db.MIGRATIONS": "`db::migrate` iterates it at db/mod.rs:135; tests/db.rs asserts the list is ordered and complete.", + "config.store_dir": "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": "`db::migrate` iterates it to apply pending migrations; tests/db.rs asserts the list is ordered and complete.", "db.ReleaseState": "a row type named by twenty sites inside db; tests/pipeline.rs names it while driving a real pipeline.", - "db.cas_accepted_release": "the compare-and-set on the accepted-release pointer; nothing in production performs that CAS today, but it is the primitive `accepted_release_for` is paired with.", + "db.cas_accepted_release": "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 \u2014 a re-export is not a call.", "db.claim": "production leases with `claim_batch`; `claim` is called only by tests, so the release build need not compile it.", "db.set_setting": "a settings writer with no production caller; `setting`/`setting_i64` readers are used, the setter is not.", "db.shutdown": "`Writer::shutdown` is never called by the server; tests use it to quiesce the writer thread.", @@ -36,21 +36,21 @@ "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.", "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": "the kata backend; tests/kata.rs constructs it rather than going through `for_config`'s caller.", - "sandbox.LocalAgentProvisioner": "the local agent provisioner impl; tests/kata.rs drives it.", + "sandbox.KataBackend": "selected by `backend_for` when the config names an agent-sandbox backend; tests/kata.rs drives it directly.", + "sandbox.LocalAgentProvisioner": "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.LoopbackBackend": "the default backend; tests/failure_modes.rs constructs it to inject a fault.", "sandbox.ProvisionRequest": "kata provisioning internals; the test that names them needs no fixture.", "sandbox.Provisioner": "kata provisioning internals; same test.", "sandbox.RemoteBackend": "the remote backend; tests/remote_agent.rs constructs it against a real agent.", - "sandbox.SandboxInfo": "the sandbox descriptor returned by the trait; tests/failure_modes.rs reads its fields.", + "sandbox.SandboxInfo": "the return type of `SandboxBackend::status`; tests/failure_modes.rs reads its fields.", "sandbox.for_config": "kata backend constructor; same test.", - "sandbox.local_addr": "the agent's local address, read by the backend selection at mod.rs:120; tests/remote_agent.rs asserts on it.", + "sandbox.local_addr": "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 \u2014 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.", "sandbox.provision_request": "kata request builder; same test.", "sandbox.reclaim": "kata reclaim path; the TTL test that names it needs no fixture.", "sandbox.sandbox_cr": "kata container-record shape; same test.", "sandbox.shared_for": "kata workspace helper; same test.", "shims.called_with": "reads the shim's invocation log, which only tests inspect.", - "shims.invocations": "reads the shim invocation log; the shim writes it in production (mod.rs:112) but nothing in src reads it back.", + "shims.invocations": "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.manifest": "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": "the shim's `--db` argument validator; production calls it at mod.rs:510, tests check its verdicts.", "time.unpin": "the clock escape hatch; `pin`/`unpin` exist so a test can freeze time. Its only in-module mention is a unit test.", diff --git a/tools/test-surface.md b/tools/test-surface.md index 9f85c5f..4465611 100644 --- a/tools/test-surface.md +++ b/tools/test-surface.md @@ -46,71 +46,71 @@ The `residue` count is ratcheted by `tests/architecture.rs`, so it can only shrink. -## Residue — `pub` because Rust has no test-conditional visibility — 33 items - -| module | item | declared at | test files | why | -|---|---|---|---|---| -| `config` | `store_dir` | `src/config.rs:357` | `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. | -| `db` | `cas_accepted_release` | `src/db/pkgbases.rs:84` | `db.rs` | the compare-and-set on the accepted-release pointer; nothing in production performs that CAS today, but it is the primitive `accepted_release_for` is paired with. | -| `http` | `LogTail` | `src/http/sse.rs:11` | `live.rs` | the SSE tail type; the live test that names it drives a real server. | -| `http` | `Page` | `src/http/render.rs:4` | `common/mod.rs` | the render model, named by twenty sites in http; tests/mod.rs asserts on it directly. | -| `http` | `Panel` | `src/http/render.rs:142` | `versions.rs` | a diff panel in the render model; tests/versions.rs asserts on its body. | -| `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:46` | `common/mod.rs`, `http.rs` | the login route handler; same — its tests are harness-free and move with it. | -| `ops` | `STAGING_GRACE_SECS` | `src/ops.rs:310` | `ops.rs` | 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:46` | `ops.rs` | computed inside the maintenance report at ops.rs:87; tests/ops.rs checks the arithmetic. | -| `ops` | `sweep_staging` | `src/ops.rs:332` | `ops.rs` | called by the maintenance pass at ops.rs:286; tests/ops.rs exercises it directly. | -| `pipeline` | `admissible` | `src/pipeline/dispatch.rs:100` | `dispatch.rs` | the dispatch filter, called at dispatch.rs:86; tests/dispatch.rs pins which builds it admits. | -| `pipeline` | `dispatch_once` | `src/pipeline/dispatch.rs:71` | `dispatch.rs` | 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:113` | `dispatch.rs` | the disk probe the dispatcher consults at dispatch.rs:106. | -| `pipeline` | `index_world` | `src/pipeline/publish.rs:21` | `kata.rs` | 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:189` | `failure_modes.rs`, `kata.rs`, `remote_agent.rs` | the run entry point with an injected sandbox; production uses `run`, tests inject a fake. | -| `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` | `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: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:486` | `shims.rs` | the shim's `--db` argument validator; production calls it at mod.rs:510, tests check its verdicts. | -| `watch` | `StageBSlot` | `src/watch/upstream.rs:118` | `vcs.rs` | the stage-B cache slot shape; tests/vcs.rs asserts on it while driving a real mirror. | -| `watch` | `needs_stage_b` | `src/watch/upstream.rs:20` | `vcs.rs` | the stage-B predicate, consulted by detect.rs:101. | -| `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 — 13 items - -| module | item | declared at | test files | why | -|---|---|---|---|---| -| `config` | `TestHooks` | `src/config.rs:143` | `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. | -| `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. | -| `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. | -| `shims` | `called_with` | `src/shims/mod.rs:151` | `crash.rs`, `dispatch.rs`, `invariants.rs`, `kata.rs` … | reads the shim's invocation log, which only tests inspect. | -| `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` | already gated behind test-support. | -| `time` | `virtualize` | `src/time.rs:129` | `crash.rs`, `dispatch.rs`, `production_surface.rs` | already gated behind test-support. | +## Residue — `pub` because Rust has no test-conditional visibility — 29 items + +| module | item | declared at | test files | in-module call sites | why | +|---|---|---|---|---|---| +| `config` | `store_dir` | `src/config.rs:357` | `architecture.rs`, `invariants.rs` | `src/config.rs:319`, `src/config.rs:361` ⚑ | 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:326` | `db.rs` | `src/db/mod.rs:147` | `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:78` | `pipeline.rs` | `src/db/model/mod.rs:137`, `src/db/model/state.rs:85`, `src/db/model/state.rs:86` +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:11` | `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:4` | `common/mod.rs` | `src/http/render.rs:55`, `src/http/render.rs:62`, `src/http/render.rs:71` +16 | the render model, named by twenty sites in http; tests/mod.rs asserts on it directly. | +| `http` | `Panel` | `src/http/render.rs:142` | `versions.rs` | `src/http/render.rs:115`, `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:36` | `common/mod.rs`, `http.rs` | `src/http/mod.rs:191`, `src/http/routes/mod.rs:38`, `src/http/routes/mod.rs:50` +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:46` | `common/mod.rs`, `http.rs` | `src/http/mod.rs:185` | the login route handler; same — its tests are harness-free and move with it. | +| `ops` | `STAGING_GRACE_SECS` | `src/ops.rs:310` | `ops.rs` | `src/ops.rs:286` | 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:46` | `ops.rs` | `src/ops.rs:87` ⚑ | computed inside the maintenance report at ops.rs:87; tests/ops.rs checks the arithmetic. | +| `ops` | `sweep_staging` | `src/ops.rs:332` | `ops.rs` | `src/ops.rs:286` | called by the maintenance pass at ops.rs:286; tests/ops.rs exercises it directly. | +| `pipeline` | `admissible` | `src/pipeline/dispatch.rs:100` | `dispatch.rs` | `src/pipeline/dispatch.rs:86` | the dispatch filter, called at dispatch.rs:86; tests/dispatch.rs pins which builds it admits. | +| `pipeline` | `dispatch_once` | `src/pipeline/dispatch.rs:71` | `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:113` | `dispatch.rs` | `src/pipeline/dispatch.rs:106` | the disk probe the dispatcher consults at dispatch.rs:106. | +| `pipeline` | `index_world` | `src/pipeline/publish.rs:21` | `kata.rs` | `src/pipeline/mod.rs:255`, `src/pipeline/mod.rs:278`, `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:189` | `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:155` | `approve.rs` | `src/review/approve.rs:151`, `src/review/approve.rs:180`, `src/review/approve.rs:184` +4 | 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` | `src/review/risk.rs:94`, `src/review/risk.rs:189`, `src/review/risk.rs:195` | 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` | `src/sandbox/agent.rs:210`, `src/sandbox/loopback.rs:51`, `src/sandbox/loopback.rs:80` +6 | the sandbox exit record, named across the backends; tests/failure_modes.rs asserts on it. | +| `sandbox` | `KataBackend` | `src/sandbox/kata.rs:179` | `kata.rs` | `src/sandbox/kata.rs:189`, `src/sandbox/kata.rs:200`, `src/sandbox/mod.rs:97` | selected by `backend_for` when the config names an agent-sandbox backend; tests/kata.rs drives it directly. | +| `sandbox` | `LoopbackBackend` | `src/sandbox/loopback.rs:10` | `failure_modes.rs` | `src/sandbox/mod.rs:92` | the default backend; tests/failure_modes.rs constructs it to inject a fault. | +| `sandbox` | `RemoteBackend` | `src/sandbox/remote.rs:12` | `remote_agent.rs` | `src/sandbox/mod.rs:94` | the remote backend; tests/remote_agent.rs constructs it against a real agent. | +| `sandbox` | `SandboxInfo` | `src/sandbox/mod.rs:70` | `failure_modes.rs` | `src/sandbox/kata.rs:319`, `src/sandbox/kata.rs:320`, `src/sandbox/loopback.rs:31` +4 | the return type of `SandboxBackend::status`; tests/failure_modes.rs reads its fields. | +| `shims` | `manifest` | `src/shims/mod.rs:88` | `common/mod.rs`, `invariants.rs`, `pipeline.rs`, `production_surface.rs` … | `src/shims/mod.rs:176` | 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:494` | `shims.rs` | `src/shims/mod.rs:525` | the shim's `--db` argument validator; production calls it at mod.rs:510, tests check its verdicts. | +| `watch` | `StageBSlot` | `src/watch/upstream.rs:118` | `vcs.rs` | `src/watch/upstream.rs:130`, `src/watch/upstream.rs:166` | the stage-B cache slot shape; tests/vcs.rs asserts on it while driving a real mirror. | +| `watch` | `needs_stage_b` | `src/watch/upstream.rs:20` | `vcs.rs` | `src/watch/detect.rs:101` ⚑ | the stage-B predicate, consulted by detect.rs:101. | +| `watch` | `probe` | `src/watch/upstream.rs:25` | `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:17` | `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 + +| module | item | declared at | test files | in-module call sites | why | +|---|---|---|---|---|---| +| `config` | `TestHooks` | `src/config.rs:143` | `common/mod.rs`, `production_surface.rs` | `src/config.rs:128`, `src/config.rs:185` | 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. | +| `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:266` | `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:273` | `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. | +| `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. | +| `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:36` | `architecture.rs`, `remote_agent.rs` | `src/sandbox/kata.rs:232`, `src/sandbox/mod.rs:120` ⚑ | 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:159` | `crash.rs`, `dispatch.rs`, `invariants.rs`, `kata.rs` … | — | reads the shim's invocation log, which only tests inspect. | +| `shims` | `invocations` | `src/shims/mod.rs:141` | `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 | |---|---| -| `residue` | 33 | -| `already-gated` | 13 | +| `residue` | 29 | +| `already-gated` | 17 | | **total** | **46** | -Of these, 33 are ungated today. Gating the `gate` rows and narrowing the +Of these, 29 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 f51c26e..16929bd 100644 --- a/tools/test-surface.py +++ b/tools/test-surface.py @@ -46,6 +46,13 @@ HARNESS = ("Env::new", "env_with_fixture", "Fixture", "tempdir", "Command::new", # evidence the analysis already has. REASONS = json.load(open(os.path.join(ROOT, "tools", "test-surface-reasons.json"))) +# Rows whose only in-module evidence is a call in method position on some +# receiver. A name match cannot tell `self.store_dir()` from +# `listener.local_addr()`; a human has to. Each entry below was read at the +# cited line and confirmed to be a call of the item itself. Anything dotted-only +# and absent from this list fails `tests/architecture.rs`. +CONFIRMED = set(json.load(open(os.path.join(ROOT, "tools", "test-surface-confirmed.json")))) + def rust_files(d): out = [] @@ -66,28 +73,87 @@ def module_of(path): return parts[0].removesuffix(".rs") -def strip_test_modules(path): - """Lines of `path` with `#[cfg(test)] mod ... {}` blocks removed.""" +def line_context(path): + """Per line: (inside_cfg_test_mod, inside_test_support_gate). + + Both are tracked by brace depth from the attribute that opens them, so a + mention inside a `#[cfg(test)] mod tests {}` or a + `#[cfg(feature = "test-support")] fn ... {}` is not evidence that + production code uses the name. Getting this wrong is what once let a + test-only function be classified as production-used because its only + caller was another test-only function. + """ lines = open(path).read().split("\n") - out, i = [], 0 + ctx = [] + depth = 0 + test_mod_depth = None + gate_stack = [] # depths at which a test-support-gated block opened + pending = None # "test" | "gate" | None, from a pending attribute + i = 0 while i < len(lines): - if lines[i].strip() == "#[cfg(test)]": - j = i + 1 - while j < len(lines) and lines[j].strip().startswith("//"): - j += 1 - if j < len(lines) and re.match(r"\s*(?:pub(?:\(crate\))?\s+)?mod\s+\w+", lines[j]): - depth, started, k = 0, False, j - while k < len(lines): - depth += lines[k].count("{") - lines[k].count("}") - if "{" in lines[k]: - started = True - if started and depth <= 0: - break - k += 1 - i = k + 1 - continue - out.append(lines[i]) + line = lines[i] + stripped = line.strip() + if stripped.startswith("#[") and "test-support" in stripped: + pending = "gate" + elif stripped == "#[cfg(test)]": + pending = "test" + + opens = line.count("{") + closes = line.count("}") + is_decl = bool(re.match(r"^\s*(?:pub(?:\(crate\))?\s+)?(?:fn|mod|struct|enum|trait|impl|const|static|type|use)\b", line)) + + # An attribute only attaches to the declaration on the next code line. + if pending and is_decl: + if pending == "test" and re.match(r"^\s*(?:pub(?:\(crate\))?\s+)?mod\b", line): + test_mod_depth = depth + elif pending == "gate": + gate_stack.append(depth) + if pending and (is_decl or not stripped.startswith("#")): + if not is_decl: + pending = None + + ctx.append((test_mod_depth is not None, bool(gate_stack))) + + depth += opens - closes + if test_mod_depth is not None and depth <= test_mod_depth: + test_mod_depth = None + while gate_stack and depth <= gate_stack[-1]: + gate_stack.pop() + if not stripped.startswith("#"): + pending = None i += 1 + return ctx + + +def strip_noise(line): + """Drop comments and string literals, so a mention inside either is not a + call. `\binvocations.jsonl\b` matching a filename is what made a shim + reader look production-used when nothing read it.""" + line = re.sub(r"//[^\"]*$", "", line) + line = re.sub(r'"(?:[^"\\]|\\.)*"', '""', line) + line = re.sub(r"r#\".*?\"#", '""', line) + return line + + +def use_block_lines(path): + """Line numbers that are part of a `use ...;` statement, including the + continuation lines of a brace-delimited `use foo::{\\n ... };` block. A + re-export is not a call: `pub use pkgbases::{ ..., cas_accepted_release, ... };` + once made a function with no production caller look production-used.""" + lines = open(path).read().split("\n") + out = set() + depth = 0 + in_use = False + for i, raw in enumerate(lines): + line = strip_noise(raw) + if not in_use and re.match(r"^\s*(?:pub(?:\(crate\))?\s+)?use\b", line): + in_use = True + if in_use: + out.add(i) + depth += line.count("{") - line.count("}") + if ";" in line and depth <= 0: + in_use = False + depth = 0 return out @@ -173,19 +239,46 @@ def analyse(): 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)) + self_impl = re.compile( + r"^\s*(?:pub(?:\(crate\))?\s+)?impl\s+(?:<[^>]*>\s*)?%s\b" % re.escape(name)) + self_impl_for = re.compile( + r"^\s*(?:pub(?:\(crate\))?\s+)?impl\s+[^{]*\bfor\s+(?:<[^>]*>\s*)?%s\b" % re.escape(name)) for p in files: - for i, line in enumerate(strip_test_modules(p), 1): - if not re.search(r"\b%s\b" % re.escape(name), line): - continue - s = line.strip() - if s.startswith("//") or s.startswith("///"): + ctx = line_context(p) + uses = use_block_lines(p) + for i, raw in enumerate(open(p).read().split("\n")): + if i in uses: + continue # a re-export is not a call + if i < len(ctx) and ctx[i][0]: + continue # inside #[cfg(test)] mod tests + if i < len(ctx) and ctx[i][1]: + continue # inside a test-support-gated item + line = strip_noise(raw) + if not line.strip(): continue + if self_impl.match(raw) or self_impl_for.match(raw): + continue # the item's own impl header if re.match(r"^\s*pub\s+(?:fn|struct|enum|trait|const|static|type)\s+%s\b" - % re.escape(name), line): - continue - if re.match(r"^\s*(?:pub(?:\(crate\))?\s+)?use\s+", line): - continue - internal.append("%s:%d" % (os.path.relpath(p, ROOT), i)) + % re.escape(name), raw): + continue # the item's own declaration + for m in pat.finditer(line): + # A mention in method-call position on some receiver + # (`.name(`) is not evidence that *this* item is used: + # `KataBackend::local_addr` was credited to + # `listener.local_addr()`, a std method on a different + # type. Bare calls and qualified paths are evidence. + before = line[:m.start()].rstrip() + dotted = before.endswith(".") + internal.append(("%s:%d" % (os.path.relpath(p, ROOT), i + 1), dotted)) + + bare = [h for h, dotted in internal if not dotted] + # Every piece of in-module evidence for this item is a call in method + # position on some receiver. That is usually real (`self.store_dir()`, + # `req.cookie("sid")`) but it is the one shape a name match cannot + # resolve, so such rows are named for a human rather than trusted. + dotted_only = bool(internal) and not bare + internal = [h for h, _ in internal] if gated: disp = "already-gated" @@ -202,11 +295,14 @@ def analyse(): module=mod, name=name, where=("%s:%d" % (occ[0][0], occ[0][1])) if occ else "?", gated=gated, string_only=string_only, tests=users, - internal=internal, sites=[list(s) for s in sites], + internal=internal, dotted_only=dotted_only, + confirmed=("%s.%s" % (mod, name)) in CONFIRMED, + sites=[list(s) for s in sites], disp=disp, reason=(REASONS.get("%s.%s" % (mod, name)) - or ("production uses it at %s; the test that names it needs a fixture." - % internal[0] if internal + 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, )) @@ -262,12 +358,18 @@ def render(rows): if not sel: continue A("\n## %s — %d items\n" % (title[d], len(sel))) - A("| module | item | declared at | test files | why |\n|---|---|---|---|---|") + A("| module | item | declared at | test files | in-module call sites | why |\n" + "|---|---|---|---|---|---|") for r in sel: - A("| `%s` | `%s` | `%s` | %s | %s |" % ( + cites = ", ".join("`%s`" % c for c in r["internal"][:3]) or "—" + if len(r["internal"]) > 3: + cites += " +%d" % (len(r["internal"]) - 3) + if r["dotted_only"]: + cites += " ⚑" + A("| `%s` | `%s` | `%s` | %s | %s | %s |" % ( r["module"], r["name"], r["where"], ", ".join("`%s`" % t for t in r["tests"][:4]) + (" …" if len(r["tests"]) > 4 else ""), - r["reason"].replace("|", "\\|"))) + cites, r["reason"].replace("|", "\\|"))) A("\n## Totals\n\n| disposition | count |\n|---|---|") for d in order: if tot[d]: |
