diff options
| -rw-r--r-- | src/review/diff.rs | 13 | ||||
| -rw-r--r-- | src/shims/mod.rs | 7 | ||||
| -rw-r--r-- | src/time.rs | 11 | ||||
| -rw-r--r-- | tests/architecture-budget.json | 20 | ||||
| -rw-r--r-- | tools/test-surface.md | 26 |
5 files changed, 50 insertions, 27 deletions
diff --git a/src/review/diff.rs b/src/review/diff.rs index 4a8a3ef..39d9066 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -266,6 +266,19 @@ pub fn diff_digest(ps: &[Panel]) -> String { crate::hash::hex_str(&render_text(ps)) } +/// Render a candidate's diff, store its digest on the row, and return it. +/// +/// Test-tier only, and that is worth stating plainly because the number says +/// something alarming at first glance: zero callers in `src/`, seventeen test +/// files. Intake renders through `review::intake::record`, which is the single +/// entry point the pipeline and both front ends use; this is the older, +/// uncomposed form that says "render and store" in two steps. It stays because +/// a test that wants a digest without running intake wants exactly this, and it +/// is gated rather than moved to `tests/common` because it needs this module's +/// private `panels`/`render_text` and `candidates::set_diff_digest` — widening +/// those to let a test out would undo the narrowing this crate just spent a +/// dozen commits doing. +#[cfg(feature = "test-support")] pub fn render_and_store(db: &Db, cfg: &Config, c: &CandidateRow) -> Result<String> { let base = match c.base_release_id { Some(id) => db::release_by_id(db, id)?, diff --git a/src/shims/mod.rs b/src/shims/mod.rs index debcd19..67c6640 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -141,6 +141,13 @@ pub fn invocations(dir: &Path) -> Vec<serde_json::Value> { } } +/// How many times the shim recorded `tool` being called with `needle` in its +/// arguments. +/// +/// Test-tier only. The shim *writes* the invocation log in production — that is +/// how a fake tool leaves evidence — but nothing in the crate reads it back; +/// only tests ask what a build actually did. +#[cfg(feature = "test-support")] pub fn called_with(dir: &Path, tool: &str, needle: &str) -> usize { invocations(dir) .iter() diff --git a/src/time.rs b/src/time.rs index 5e82f0c..9917f54 100644 --- a/src/time.rs +++ b/src/time.rs @@ -37,6 +37,14 @@ thread_local! { static CLOCK: std::cell::RefCell<Option<String>> = const { std::cell::RefCell::new(None) }; } +/// Freeze the clock for this thread, returning the previous pin if any. +/// +/// Test-tier only, together with `unpin` — the two are one capability and +/// gating half of it would leave a release binary able to freeze time and +/// unable to release it. The census never reported `pin` as test-only because +/// its name match also fires inside `upstream_pins` and `source_digests`; the +/// only callers in the crate are tests. +#[cfg(feature = "test-support")] pub fn pin(ts: &str) -> Option<String> { CLOCK.with(|c| { let mut slot = c.borrow_mut(); @@ -44,6 +52,8 @@ pub fn pin(ts: &str) -> Option<String> { }) } +/// Release a pin set by `pin`. See the note there about why both are gated. +#[cfg(feature = "test-support")] pub fn unpin() { CLOCK.with(|c| *c.borrow_mut() = None); } @@ -212,6 +222,7 @@ mod tests { // clock itself and need nothing else; the third test in that file pins a // lease against a pinned clock, which needs a database, so it stayed. + #[cfg(feature = "test-support")] #[test] fn a_pinned_clock_moves_relative_arithmetic_with_it() { pin("2026-01-01T00:00:00Z"); diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json index fc44d5f..d806fbf 100644 --- a/tests/architecture-budget.json +++ b/tests/architecture-budget.json @@ -235,9 +235,9 @@ "dead": 5, "deadonly": 1, "glob": 0, - "largest": 288, + "largest": 301, "largest_file": "src/review/diff.rs", - "lines": 859, + "lines": 872, "priv": 3, "pub": 24, "test": 4 @@ -257,9 +257,9 @@ "dead": 12, "deadonly": 8, "glob": 0, - "largest": 603, + "largest": 610, "largest_file": "src/shims/mod.rs", - "lines": 603, + "lines": 610, "priv": 0, "pub": 19, "test": 4 @@ -268,9 +268,9 @@ "dead": 5, "deadonly": 2, "glob": 0, - "largest": 231, + "largest": 242, "largest_file": "src/time.rs", - "lines": 231, + "lines": 242, "priv": 0, "pub": 14, "test": 3 @@ -310,12 +310,10 @@ } }, "test_surface": { - "already-gated": 10, - "gate": 3, - "gate_pending": 3, + "already-gated": 13, "residue": 33, "total": 46, - "ungated": 36 + "ungated": 33 }, "totals": { "dead": 84, @@ -324,7 +322,7 @@ "glob": 0, "largest": 673, "largest_file": "src/config.rs", - "lines": 15118, + "lines": 15149, "priv": 119, "pub": 484, "test": 48 diff --git a/tools/test-surface.md b/tools/test-surface.md index cd6851e..9f85c5f 100644 --- a/tools/test-surface.md +++ b/tools/test-surface.md @@ -46,14 +46,6 @@ The `residue` count is ratcheted by `tests/architecture.rs`, so it can only shrink. -## Gate behind `test-support` — 3 items - -| module | item | declared at | test files | why | -|---|---|---|---|---| -| `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. | - ## Residue — `pub` because Rust has no test-conditional visibility — 33 items | module | item | declared at | test files | why | @@ -86,13 +78,13 @@ shrink. | `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. | +| `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 — 10 items +## Already gated — 13 items | module | item | declared at | test files | why | |---|---|---|---|---| @@ -104,19 +96,21 @@ shrink. | `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. | +| `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 | |---|---| -| `gate` | 3 | | `residue` | 33 | -| `already-gated` | 10 | +| `already-gated` | 13 | | **total** | **46** | -Of these, 36 are ungated today. Gating the `gate` rows and narrowing the -`narrow` rows removes 3 items from the release build's public surface; the +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. |
