summaryrefslogtreecommitdiffstats
path: root/tools/test-surface.md
blob: 740cf6179bdb6ef1444205e18b9cb02884fc6824 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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) |
| `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 |

### How visibility becomes feature-conditional

For a free function, method, const or static, one body sits behind two
declarations, exactly one of which compiles:

```rust
#[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:

```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;
```

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

| module | item | declared at | test files | in-module call sites | why |
|---|---|---|---|---|---|
| `config` | `TestHooks` | `src/config.rs:157` | `common/mod.rs`, `production_surface.rs` | `src/config.rs:142`, `src/config.rs:199` | 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` | `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: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: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` | `virtualize` | `src/time.rs:129` | `crash.rs`, `dispatch.rs`, `production_surface.rs` | — | already gated behind test-support. |

## Totals

| disposition | count |
|---|---|
| `interface` | 1 |
| `narrowed` | 19 |
| `already-gated` | 17 |
| **total** | **37** |

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.