summaryrefslogtreecommitdiffstats
path: root/tools/test-surface.md
blob: 9f85c5f18bed0271d9837f1bde742c6290295723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# The test surface: every `pub` item that exists because a test names it

Regenerate with `python3 tools/test-surface.py --write`. The reasons in the
`why` column live in `tools/test-surface-reasons.json` and are reviewed by
hand; everything else is derived from the source.

## What counts

The census (`tools/arch-census.py`) calls a `pub` item **dead** when no file
*outside its own top-level module* names it, and **test-only** when a file
under `tests/` does. That definition is coarse in two ways that matter here:

- *Module is the top-level directory.* An item in `src/db/candidates.rs` used
  only from `src/db/builds/mod.rs` counts as dead, because both are in `db`.
  Many rows below are therefore not "used only by tests" — they are used only
  inside their own module, and a test happens to be the only outside reader.

- *Mentions are matched over raw source, including string literals.* Some
  items are named by a test only inside a string. Nothing in the test tier
  depends on them; they are census false positives.

## The four dispositions

| disposition | meaning | applies when |
|---|---|---|
| `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 |

### Why `residue` exists at all

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.

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.

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. |

## Totals

| disposition | count |
|---|---|
| `residue` | 33 |
| `already-gated` | 13 |
| **total** | **46** |

Of these, 33 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.