# Architecture census The numbers below are what the module tree costs, measured by `tools/arch-census.py`. `tests/architecture.rs` enforces them against `tests/architecture-budget.json`, which may only shrink. Baseline verification, before any of this work: `cargo test --all-targets --features test-support` 273 passed / 0 failed across 36 test binaries; `cargo clippy --all-targets --features test-support -- -D warnings` clean; `cargo build --release` clean. ## 2026-11-20 16:48 totals: 585 pub, 219 dead (73 test-only, 146 named by nobody), 42 pub(crate), 4 glob re-exports, 80 edges, largest file 1501 (src/db/queries.rs) | module | pub | dead | test-only | dead-only | pub(crate) | glob | lines | largest file | |---|---|---|---|---|---|---|---|---| | bin/gpg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/gpg.rs | | bin/makechrootpkg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/makechrootpkg.rs | | bin/makepkg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/makepkg.rs | | bin/mkarchroot | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/mkarchroot.rs | | bin/pacman | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/pacman.rs | | bin/repo-add | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/repo-add.rs | | bin/sandbox-agent | 0 | 0 | 0 | 0 | 0 | 0 | 50 | 50 src/bin/sandbox-agent.rs | | config | 35 | 9 | 5 | 4 | 0 | 0 | 427 | 427 src/config.rs | | db | 226 | 49 | 13 | 36 | 5 | 2 | 3687 | 1501 src/db/queries.rs | | error | 15 | 0 | 0 | 0 | 0 | 0 | 124 | 124 src/error.rs | | fetch | 3 | 1 | 0 | 1 | 0 | 0 | 56 | 56 src/fetch.rs | | git | 19 | 5 | 0 | 5 | 0 | 0 | 280 | 280 src/git.rs | | hash | 8 | 1 | 0 | 1 | 0 | 0 | 61 | 61 src/hash.rs | | http | 68 | 54 | 11 | 43 | 32 | 2 | 1951 | 565 src/http/routes/pages.rs | | lib | 0 | 0 | 0 | 0 | 0 | 0 | 22 | 22 src/lib.rs | | main | 0 | 0 | 0 | 0 | 0 | 0 | 361 | 361 src/main.rs | | ops | 13 | 5 | 3 | 2 | 0 | 0 | 415 | 415 src/ops.rs | | pipeline | 30 | 15 | 6 | 9 | 2 | 0 | 1339 | 481 src/pipeline/steps.rs | | pkginfo | 7 | 3 | 0 | 3 | 0 | 0 | 122 | 122 src/pkginfo.rs | | pkgver | 18 | 9 | 5 | 4 | 0 | 0 | 347 | 347 src/pkgver/mod.rs | | recipe | 11 | 4 | 0 | 4 | 0 | 0 | 467 | 467 src/recipe.rs | | review | 29 | 10 | 4 | 6 | 0 | 0 | 792 | 295 src/review/diff.rs | | sandbox | 35 | 23 | 15 | 8 | 3 | 0 | 1175 | 347 src/sandbox/kata.rs | | shims | 19 | 12 | 4 | 8 | 0 | 0 | 603 | 603 src/shims/mod.rs | | time | 16 | 7 | 3 | 4 | 0 | 0 | 221 | 221 src/time.rs | | urlutil | 2 | 1 | 0 | 1 | 0 | 0 | 56 | 56 src/urlutil.rs | | watch | 31 | 11 | 4 | 7 | 0 | 0 | 969 | 317 src/watch/detect.rs | ``` bin/gpg -> shims bin/makechrootpkg -> shims bin/makepkg -> shims bin/mkarchroot -> shims bin/pacman -> shims bin/repo-add -> shims bin/sandbox-agent -> sandbox config -> error hash db -> config error hash pkgver time fetch -> error hash git -> error http -> config db hash ops pipeline pkgver review time watch main -> config db http ops pipeline pkgver review watch ops -> config db error time watch pipeline -> config db error git hash pkginfo pkgver recipe review sandbox time watch recipe -> db error review -> config db error git hash pkgver recipe time urlutil sandbox -> config error hash time shims -> hash pkginfo pkgver recipe watch -> config db error fetch git hash pkgver recipe review time ``` --- ## 2026-11-20 18:57 — after totals: 505 pub, 105 dead (72 test-only, 33 named by nobody), 109 pub(crate), 0 glob re-exports, 87 edges, largest file 603 (src/shims/mod.rs) | module | pub | dead | test-only | dead-only | pub(crate) | glob | lines | largest file | |---|---|---|---|---|---|---|---|---| | bin/gpg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/gpg.rs | | bin/makechrootpkg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/makechrootpkg.rs | | bin/makepkg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/makepkg.rs | | bin/mkarchroot | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/mkarchroot.rs | | bin/pacman | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/pacman.rs | | bin/repo-add | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/repo-add.rs | | bin/sandbox-agent | 0 | 0 | 0 | 0 | 0 | 0 | 50 | 50 src/bin/sandbox-agent.rs | | config | 31 | 5 | 5 | 0 | 0 | 0 | 427 | 427 src/config.rs | | db | 202 | 21 | 13 | 8 | 10 | 0 | 3742 | 364 src/db/candidates.rs | | error | 21 | 0 | 0 | 0 | 0 | 0 | 430 | 430 src/error.rs | | fetch | 3 | 1 | 0 | 1 | 0 | 0 | 56 | 56 src/fetch.rs | | git | 14 | 0 | 0 | 0 | 0 | 0 | 240 | 240 src/git.rs | | hash | 7 | 0 | 0 | 0 | 0 | 0 | 59 | 59 src/hash.rs | | http | 27 | 13 | 10 | 3 | 67 | 0 | 1922 | 565 src/http/routes/pages.rs | | lib | 0 | 0 | 0 | 0 | 0 | 0 | 23 | 23 src/lib.rs | | main | 0 | 0 | 0 | 0 | 0 | 0 | 314 | 314 src/main.rs | | ops | 13 | 4 | 3 | 1 | 0 | 0 | 415 | 415 src/ops.rs | | pipeline | 21 | 6 | 6 | 0 | 11 | 0 | 1330 | 472 src/pipeline/steps.rs | | pkginfo | 6 | 2 | 0 | 2 | 0 | 0 | 115 | 115 src/pkginfo.rs | | pkgver | 14 | 5 | 5 | 0 | 0 | 0 | 343 | 343 src/pkgver/mod.rs | | recipe | 7 | 0 | 0 | 0 | 0 | 0 | 459 | 459 src/recipe.rs | | review | 24 | 5 | 4 | 1 | 3 | 0 | 859 | 288 src/review/diff.rs | | sandbox | 27 | 15 | 15 | 0 | 11 | 0 | 1178 | 350 src/sandbox/kata.rs | | shims | 19 | 12 | 4 | 8 | 0 | 0 | 603 | 603 src/shims/mod.rs | | time | 14 | 5 | 3 | 2 | 0 | 0 | 206 | 206 src/time.rs | | urlutil | 1 | 0 | 0 | 0 | 0 | 0 | 56 | 56 src/urlutil.rs | | usecase | 30 | 3 | 0 | 3 | 0 | 0 | 402 | 123 src/usecase/reviews.rs | | watch | 24 | 8 | 4 | 4 | 7 | 0 | 1038 | 270 src/watch/detect.rs | ### Before / after | | pub | dead | dead-only (named by nobody) | pub(crate) | globs | largest file | |---|---|---|---|---|---|---| | before | 585 | 219 | 146 | 42 | 4 | 1501 src/db/queries.rs | | after | 505 | 105 | 33 | 109 | 0 | 603 src/shims/mod.rs | The headline is not the pub count, though it fell 585 → 505. It is the **146 items whose name no other module ever wrote, down to 33** — and of those 33, every one is a type returned by a public function, so it is part of an interface without anyone having to spell it. None is an export nobody can reach. The other three numbers are the ones that keep it true: - **globs 4 → 0.** `db/mod.rs` and `http/routes/mod.rs` list what they hand out. The architecture test's glob allowlist is empty and any new glob fails. - **pub(crate) 42 → 109.** This is the count that went *up*, and it is the point. `priv` was removed from the budgeted keys for the same reason it would have been absurd to keep: closing an interface raises it, so a ceiling on it would have been a ceiling on the work. - **largest file 1501 → 603,** and the largest file is now `src/shims/mod.rs` — a test fixture, not production logic. ### Where the layer map ended up ``` error 0 → hash/time/urlutil/pkgver/pkginfo 1 → config/fetch/git 2 → db/sandbox 3 → recipe 4 → review/shims 5 → watch 6 → pipeline 7 → ops 8 → usecase 9 → http 10 → main/lib/bin 11 ``` `usecase` is the one module added. It sits above everything it orchestrates and below both front ends, which is what lets the CLI and the web UI run the same workflow instead of each guessing at it. ### The one budget above its baseline `error.pub` is 21 against a baseline of 15. The six added names are the payload types `Missing`, `Refused`, `Guard`, `WorldGap`, `PoolFull` and `TransientCause`, which the typed-error task required and which must be `pub` because they are constructed in `db`, `pipeline`, `watch` and `sandbox` and matched in `error`. They are interface, not leakage: `error.dead` is 0. `usecase` has no baseline because it did not exist at the start. Its 30 exports are the workflows, and its 3 dead-only items (`Checked`, `GcPlan`, `Prepared`) are again return types, not orphans. Every other budget in `tests/architecture-budget.json` is at or below its task-1 value, and the ratchet test fails on any increase. --- ## Second movement: the test surface The first movement closed interfaces by deleting exports nothing reached. The second closed them by moving tests home, because a test that sits outside a module can only reach what the module exports — so every fixture-free test in `tests/` was quietly holding a door open. | | pub | dead | dead-only | pub(crate) | glob | largest file | |---|---|---|---|---|---|---| | after the first movement | 505 | 105 | 33 | 109 | 0 | 603 src/shims/mod.rs | | after the second | 484 | 84 | 36 | 119 | 0 | 673 src/config.rs | `pub` fell 505 → 484 and test-only items fell 72 → 48. The 48 that remain are not an oversight: `tools/test-surface.md` gives each one a disposition and a reason, and 33 of them are `residue` — items production needs inside their own module *and* a fixture-bound integration test needs from outside, which Rust cannot express as anything other than `pub` because it has no test-conditional visibility. `dead-only` rose 33 → 36, and both increases are consequences of narrowing rather than of anything being forgotten: - **sandbox 0 → 2.** `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. Narrowing them means narrowing that provisioner, which means those tests stop constructing it. - **db 8 → 9.** Five state enums each have a `can_transition`. Three became private when their tests moved into the module; the other two — `ReleaseState` and `SubscriptionState` — are consulted by nothing at all, so the name moved from test-only to dead-only rather than disappearing. Both carry a NOTE saying they are dead tables for machines nothing enforces. `pub(crate)` rose 109 → 119 for the same reason it rose before: closing an interface raises that count, which is why it is reported and not budgeted. The largest file is now `src/config.rs` at 673 lines, up from 603. It grew because eleven config parsing tests moved into it, not because the module grew 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 `tools/test-surface.py` and fails if any test-only item lacks a hand-written disposition reason, or if any disposition count exceeds `tests/architecture-budget.json`. `tools/arch-census.py --write-budget` now preserves the `test_surface` section instead of erasing it: two tools writing one file must not delete each other's axis, or the ratchet quietly stops checking one of them. ## 2026-11-21 14:08 totals: 448 pub, 49 dead (49 test-only, 0 named by nobody), 170 pub(crate), 0 glob re-exports, 87 edges, largest file 699 (src/config.rs) | module | pub | dead | test-only | dead-only | pub(crate) | glob | lines | largest file | |---|---|---|---|---|---|---|---|---| | bin/gpg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/gpg.rs | | bin/makechrootpkg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/makechrootpkg.rs | | bin/makepkg | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/makepkg.rs | | bin/mkarchroot | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/mkarchroot.rs | | bin/pacman | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/pacman.rs | | bin/repo-add | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 4 src/bin/repo-add.rs | | bin/sandbox-agent | 0 | 0 | 0 | 0 | 0 | 0 | 50 | 50 src/bin/sandbox-agent.rs | | config | 29 | 2 | 2 | 0 | 2 | 0 | 699 | 699 src/config.rs | | db | 189 | 11 | 11 | 0 | 19 | 0 | 3888 | 368 src/db/mod.rs | | error | 21 | 0 | 0 | 0 | 0 | 0 | 430 | 430 src/error.rs | | fetch | 1 | 0 | 0 | 0 | 2 | 0 | 57 | 57 src/fetch.rs | | git | 14 | 0 | 0 | 0 | 0 | 0 | 240 | 240 src/git.rs | | hash | 7 | 0 | 0 | 0 | 0 | 0 | 111 | 111 src/hash.rs | | http | 17 | 5 | 5 | 0 | 81 | 0 | 2034 | 565 src/http/routes/pages.rs | | lib | 0 | 0 | 0 | 0 | 0 | 0 | 23 | 23 src/lib.rs | | main | 0 | 0 | 0 | 0 | 0 | 0 | 314 | 314 src/main.rs | | ops | 11 | 3 | 3 | 0 | 5 | 0 | 455 | 455 src/ops.rs | | pipeline | 21 | 6 | 6 | 0 | 16 | 0 | 1411 | 472 src/pipeline/steps.rs | | pkginfo | 6 | 0 | 0 | 0 | 0 | 0 | 117 | 117 src/pkginfo.rs | | pkgver | 7 | 0 | 0 | 0 | 0 | 0 | 559 | 559 src/pkgver/mod.rs | | recipe | 7 | 0 | 0 | 0 | 0 | 0 | 459 | 459 src/recipe.rs | | review | 24 | 4 | 4 | 0 | 4 | 0 | 915 | 301 src/review/diff.rs | | sandbox | 21 | 7 | 7 | 0 | 16 | 0 | 1413 | 508 src/sandbox/kata.rs | | shims | 8 | 4 | 4 | 0 | 13 | 0 | 655 | 655 src/shims/mod.rs | | time | 13 | 3 | 3 | 0 | 0 | 0 | 243 | 243 src/time.rs | | urlutil | 1 | 0 | 0 | 0 | 0 | 0 | 56 | 56 src/urlutil.rs | | usecase | 30 | 0 | 0 | 0 | 0 | 0 | 405 | 124 src/usecase/reviews.rs | | watch | 21 | 4 | 4 | 0 | 12 | 0 | 1115 | 296 src/watch/upstream.rs | ``` bin/gpg -> shims bin/makechrootpkg -> shims bin/makepkg -> shims bin/mkarchroot -> shims bin/pacman -> shims bin/repo-add -> shims bin/sandbox-agent -> sandbox config -> error hash db -> config error hash pkgver time fetch -> error hash git -> error http -> config db hash ops pkgver review time usecase watch main -> config db http ops pipeline pkgver review usecase ops -> config db error time watch pipeline -> config db error git hash pkginfo pkgver recipe review sandbox time watch recipe -> db error review -> config db error git hash pkgver recipe time urlutil sandbox -> config error hash time shims -> hash pkginfo pkgver recipe usecase -> config db error ops pipeline review watch watch -> config db error fetch git hash pkgver recipe review time ```