Plan: every route module at or under 500 lines (#3406)
Status: Done (2026-12-04) — all 17 units landed through the merge train and budget B1 is 0; what the work found and left open is listed on #3406
Closes: #3406 (by the last unit, U17)
Issues: #3406 (parent) · U1 #3648 · U2 #3649 · U3 #3650 · U4 #3651 · U5 #3652 · U6 #3653 · U7 #3654 · U8 #3655 · U9 #3656 · U10 #3657 · U11 #3658 · U12 #3659 · U13 #3660 · U14 #3661 · U15 #3662 · U16 #3663 · U17 #3664
Branches: refactor/b1-{unit}, for example refactor/b1-web-case-detail
This is a Design + Scope plan. GitLab owns tracking, each unit issue carries the implementer brief, and the plan freezes when U1 starts.
Problem
Budget B1 counts route modules over 500 lines (run_b1, xtask/src/cmd/quality_budgets.rs). It matches services//src/api/.rs, one directory deep, so a route module in a subdirectory is not counted. The lock is 17.
Measured on main at 29e7bebb1, 2026-12-03, by line count:
Files under services/*/src/api/ over 500 lines |
Files | Counted today |
|---|---|---|
At the module's root, production code |
17 |
yes |
Nested, production code |
7 |
no |
Nested, test-only: loaded through a |
28 |
no |
The 17 root files hold about 31,000 lines outside their inline test modules and about 16,000 inside them. Each of the 17 is still over 500 lines with its inline tests taken out, so each needs its code split, not only its tests moved.
The maintainer ruled on #3406 against raising the lock to admit a wider count: modules are split until the wider count is at or under the lock, the counter is widened in a merge request that shows that, and the splitting goes on to zero.
Decisions (approving this plan confirms them)
-
What B1 counts. A
.rsfile underservices/*/src/api/, at any depth, that is over 500 lines and is not test-only. Test-only is what xtask's shared resolver says (SourceScope::is_test_file,xtask/src/test_scope.rs): a file a[cfg(test)] modloads, a file that gates itself with![cfg(test)], and the files those load. B2, B5 and B8 already skip test code by that resolver, so the four budgets share one meaning of test code. A counted file's lines are counted whole, its inline test modules included, as today. Two consequences: the 28 nested test files are not counted and are not split under this plan; and a root-level test file over 500 lines, which today's rule would count, is not counted either. There is no such file today, so every file counted today stays counted. -
Order. The seven nested production files first (U1, U2), so that the wider count equals the lock and the counter is widened (U3) before any large split. Then the root files, largest first, one service per merge request.
-
Moves only. A unit moves code between files. It changes no route, no handler or type name, no logic and no test assertion; Proving a move, below, is how each unit shows that. A defect seen in moved code gets its own issue.
-
Layout.
x.rskeeps its file and gains children underx/; a service'smod.rsunderapi/gains siblings beside it. That is the layoutservices/canopy-web/src/api/case_detail.rshas. A child is named for the route group it holds. The route table (routes()and the functions it calls) stays in the parent, and names a handler by its child's path, as canopy-web's table namescase_detail::page::get_case_detailtoday. Nopub useis added only to keep an old path compiling: callers are updated in the same merge request. -
Visibility. A moved item keeps its visibility. Where the move puts one of its callers outside its new module, it is widened by the least that compiles:
pub(super), thenpub(in crate::api), thenpub(crate). -
Tests travel with their code. An inline
[cfg(test)] mod tests { … }becomes a file declared[cfg(test)] mod tests;; where a file holds several inline test modules, each keeps its name as<name>.rs. A test goes into the test file of the child whose private items it uses. A test that uses several children, or only the router, stays in the parent's test file. A helper several test files share goes to a#[cfg(test)]test_support.rsin the parent. Test function names do not change. -
The lock. Each merge request that removes a counted file lowers the lock to the new count.
Every unit's procedure
-
Record before. The test names
cargo nextest list -p <service>prints. For a canopy-web unit, also the output ofcargo xtask route-authz auditandweb-paths audit, which read canopy-web alone. -
Move tests out, then split the code by route group. A child holds the handlers of one route group and the private helpers only those handlers call. A helper two groups share stays in the parent. Every resulting production file is at or under 500 lines; a group that does not fit is cut again at its next seam, and both halves are named for what they hold.
-
Move what names a path. Seven of the 24 files are named in
compliance/lists: as an entry'sfile(prod-ambient-clock-allowlist.toml,prod-utc-today-allowlist.toml,adr-011-literal-allowlist.toml,determination-status-fields.toml,contested-surfaces.toml), as atest_refof the formfile::test_fn(the action catalogues), or in a comment (the scenario inventories, andfixtures/config/default/jurisdiction.toml). Each reference moves with what it names.xtask/src/cmd/route_authz.rsnamesservices/canopy-web/src/api/composition.rsas a route-table file (COMPOSITION_ROUTER); that stays true because the route table stays in the parent. Rustdoc links to moved items are updated. The docs name handlers by file too:docs/modules/ROOT/pages/authorization-inventory.adocgives each route's handler assrc/api/<file> (<handler>), which no lint checks, and theapi/canopy-*.adocpages, the guides andservices.adoccite route files in prose. Those references move with the handler. ADRs and the pages underplans/are records of their date and are left as written. The step ends with a search for each old path undercompliance/,fixtures/config/,xtask/src/anddocs/modules/ROOT/pages/outsideadrs/andplans/; the merge request lists what the search still finds and why it is still true. -
Prove the move (next section).
-
Deliver. Lower the lock with its note, add the CHANGELOG entry, run the lints, push, open the merge request against the unit's issue.
Proving a move
| What | How |
|---|---|
The code is the same code |
A throwaway script reads the merge request's diff and compares its removed lines with its added lines as two multisets, leading whitespace stripped. What is left over is listed in the merge request. It may hold |
Routes, for every service but canopy-web |
|
Routes and write admission, for canopy-web |
|
Delegated routes, for every service |
|
The tests |
The multiset of test function names is identical before and after, and the unit lane passes; the merge request states both counts. |
Everything else |
The merge train's car: integration, fault, e2e. |
Units
Weights: 2 small · 3 medium · 5 large. One unit is one issue and one merge request, in this order. "B1" is the lock after the unit. Every child named is a new file.
| Unit | Files (lines) | Children, each named for its route group | B1 |
|---|---|---|---|
U1 (w3) |
canopy-web, nested: |
|
17 |
U2 (w3) |
canopy-tanf: |
under |
16 |
U3 (w2) |
|
|
16 |
U4 (w3) |
canopy-web: |
its one inline test module (4,536 lines) moves whole to |
16 |
U5 (w5) |
canopy-web: |
under |
15 |
U6 (w5) |
canopy-applications: |
|
14 |
U7 (w5) |
canopy-appeals: |
|
13 |
U8 (w5) |
canopy-renewals: |
|
12 |
U9 (w5) |
canopy-persons: |
|
10 |
U10 (w3) |
canopy-reporting: |
|
9 |
U11 (w3) |
canopy-web: |
under |
8 |
U12 (w3) |
canopy-web: |
|
6 |
U13 (w3) |
canopy-web: |
|
4 |
U14 (w2) |
canopy-eligibility: |
|
3 |
U15 (w3) |
canopy-security: |
|
2 |
U16 (w3) |
canopy-enrollment: |
|
1 |
U17 (w2) |
canopy-medicaid: |
|
0 |
The children are the target. Where the code shows a better seam than the one named, the unit takes it and its merge request says so; that is not an erratum. If moves alone do not bring a file to 500 lines, the unit stops and says so on its issue.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
A handler is moved without its admission check, or a route loses its handler. |
fail-open |
Moves only (decision 3): an admission check is a line of its handler and moves with it, which the line comparison shows. A lost route fails the OpenAPI snapshot test in the sixteen services that have one; in canopy-web, |
Test code moved out of a |
silent |
The multiset of test function names is compared before and after in every unit. |
Test code loses its |
silent |
Every moved test file is declared under |
An entry in the clock, date or status-field list goes on naming the old file. |
fail-closed |
Those lints refuse an entry that resolves to no site ( |
A reference no lint is known to check goes stale: a handler's file in the authorization inventory or another docs page, a |
silent |
The search that ends step 3 of the procedure, with its result stated in the merge request. |
|
silent |
Its output is compared before and after, so a route that drops out shows. It already follows a nested handler: |
Visibility is widened further than the move needs. |
silent |
Decision 5. The leftover lines of the multiset comparison list every visibility change, for the reviewer. |
The widened counter takes a production file for a test file and under-counts. |
silent |
U3's tests, below, and U3's count must equal this plan's hand count of 16. The resolver is the one B2, B5 and B8 use; a file that does not parse, or whose declaration it does not see, is treated as production. |
A longer handler path re-wraps canopy-web's route table, |
fail-closed |
It is a counted file: the budget fails, and the unit then moves one route group's table into that group's parent. |
A split conflicts with other work on the same large file. |
fail-closed |
The merge train refuses a conflict. Each unit is pushed as soon as it is proved. |
A rustdoc link to a moved item breaks. |
fail-closed |
The docs job denies broken intra-doc links. |
Tests
-
Regression, the case that would have caught it (U3). Today's counter misses an oversized nested route file. New tests on fixture trees, beside
b1_counts_files_over_threshold, which stays:b1_counts_a_nested_production_file_over_the_threshold;b1_does_not_count_a_test_module_file_at_any_depth, with one file at the root and one nested, each loaded by a#[cfg(test)] mod;b1_counts_a_production_file_whole_with_its_inline_tests, where 400 production lines and 200 inline test lines count as one file over. -
Contract. No wire changes. The snapshot tests named under Proving a move hold that in every unit outside canopy-web.
-
Concurrency. None: no unit changes behaviour.
-
Every unit. No test is added, removed or reworded; the name comparison shows it.
Delivery
-
This plan is committed under
docs/modules/ROOT/pages/plans/with its line innav.adoc, before U1. Done, it isdocs/modules/ROOT/pages/plans/archive/route-modules-under-500-lines.adoc. -
Canonical page:
docs/modules/ROOT/pages/coding-conventions.adoc, the quality-budgets table. U3 rewrites the B1 row to decision 1 and states the layout, visibility and test rules (decisions 4 to 6) beside it. -
Other pages: each move unit updates the docs references step 3 names,
authorization-inventory.adocfirst among them. -
CHANGELOG: each unit adds an entry under
== Unreleased,=== Changed. -
Close: U17 closes #3406 and sets this plan's status to Done;
cargo xtask plan-lint --doneis run on it.
Out of scope
-
Nested test files over 500 lines (28 today). Decision 1 leaves them uncounted.
-
Functions over 100 lines. Budget B2 is already 0 for production code.
-
Any change to what a handler does, including defects seen on the way; each gets its own issue.
-
Route code outside
services/*/src/api/. canopy-portal has nosrc/api/; B1 does not count its pages today, and this plan does not add them.
Errata
-
Erratum (2026-12-03), U1: Proving a move lists what the line comparison may leave over. There is one more kind: a path lengthened by the move. A
super::path in moved code or in a rustdoc link names one level more, a link to an item its old file imported names it in full, and a caller names a moved item by its new module (decision 4). Both are listed in the merge request with the rest. -
Erratum (2026-12-03), U1: the sixth child is
cross_program/subject.rs, notcross_program/matrix.rs. The per-member outcome and its rows move; the household-level outcome stays in the parent beside the two tests that call it, so no test moves. -
Erratum (2026-12-03), U2: a moved route keeps its OpenAPI tag by naming it. utoipa takes a route's tag from its module's path, so a handler moved into a child would be published under a new tag; the snapshot test fails on that. The unit adds
tag = "<the tag it had>"to the handler's#[utoipa::path], aswork_requirement_handlers/full_weeks.rsdoes. Those lines are one more kind of leftover, and every later unit that moves a documented handler adds them. -
Erratum (2026-12-03), U2: where a unit turns inline test modules into files, rustfmt re-wraps their lines at the new indent, and the leftover is too long to read. The line comparison is then made in two steps: the original files against the split's output before rustfmt, and that output after rustfmt against the committed files.
-
Erratum (2026-12-03), U2: the search for an old path covers every tracked file, not the four directories Every unit's procedure names.
crates/canopy-test-lib/tests/qc_write_gate_sweep_test.rskeys a waiver on a handler's path as the route table writes it, and doc comments in canopy-auth and canopy-test-lib name handler files. That test is in the integration lane, so the push does not run it: each unit runs it before the push, and shows that it reads the same gates for every write route before and after the move. One mention U1 missed, a comment intests/e2e/specs/case-detail-scroll.spec.ts, is corrected in U2.