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 #[cfg(test)] mod

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)

  1. What B1 counts. A .rs file under services/*/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)] mod loads, 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.

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

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

  4. Layout. x.rs keeps its file and gains children under x/; a service's mod.rs under api/ gains siblings beside it. That is the layout services/canopy-web/src/api/case_detail.rs has. 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 names case_detail::page::get_case_detail today. No pub use is added only to keep an old path compiling: callers are updated in the same merge request.

  5. 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), then pub(in crate::api), then pub(crate).

  6. 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.rs in the parent. Test function names do not change.

  7. The lock. Each merge request that removes a counted file lowers the lock to the new count.

Every unit's procedure

  1. Record before. The test names cargo nextest list -p <service> prints. For a canopy-web unit, also the output of cargo xtask route-authz audit and web-paths audit, which read canopy-web alone.

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

  3. Move what names a path. Seven of the 24 files are named in compliance/ lists: as an entry's file (prod-ambient-clock-allowlist.toml, prod-utc-today-allowlist.toml, adr-011-literal-allowlist.toml, determination-status-fields.toml, contested-surfaces.toml), as a test_ref of the form file::test_fn (the action catalogues), or in a comment (the scenario inventories, and fixtures/config/default/jurisdiction.toml). Each reference moves with what it names. xtask/src/cmd/route_authz.rs names services/canopy-web/src/api/composition.rs as 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.adoc gives each route's handler as src/api/<file> (<handler>), which no lint checks, and the api/canopy-*.adoc pages, the guides and services.adoc cite route files in prose. Those references move with the handler. ADRs and the pages under plans/ are records of their date and are left as written. The step ends with a search for each old path under compliance/, fixtures/config/, xtask/src/ and docs/modules/ROOT/pages/ outside adrs/ and plans/; the merge request lists what the search still finds and why it is still true.

  4. Prove the move (next section).

  5. 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 use lines, mod declarations, visibility keywords, module doc headers, and lines rustfmt re-wrapped after a change of indent; the last are shown equal with whitespace and trailing commas removed.

Routes, for every service but canopy-web

cargo xtask api-docs --offline passes with no change under docs/modules/ROOT/openapi/. The service's the_served_openapi_spec_is_the_committed_snapshot test compares the document it serves, every route and schema, with the committed snapshot. Sixteen services have that test; canopy-web, which serves pages, does not.

Routes and write admission, for canopy-web

route-authz audit and web-paths audit print the same before and after, apart from the file a handler is reported in. canopy-web's route table, services/canopy-web/src/api/mod.rs, changes only in the paths it names handlers by.

Delegated routes, for every service

cargo xtask delegated-routes passes: it compares canopy_auth::delegated_routes() with its table in the authorization inventory.

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: case_detail/page.rs (1,090), tab.rs (742), hero.rs (724), income_tab.rs (527), cross_program.rs (504); fact_editor/refusal.rs (565)

page/gates.rs, page/reads.rs (the page's reads and section context), page/shell.rs (the four shells and the refusal page); tab/render.rs; hero/chips.rs (program legs and chips); income_tab/rows.rs; cross_program/matrix.rs; refusal/sink.rs (the refused-write record and its sinks). These files are not counted yet, so the lock does not move.

17

U2 (w3)

canopy-tanf: work_requirement_handlers.rs (4,150) and its child full_weeks.rs (543)

under work_requirement_handlers/: activities.rs, work_standard.rs, summary.rs, time_limits.rs, sanctions.rs; the file's fifteen inline test modules each become <name>.rs under the child that holds their code; full_weeks.rs's two become full_weeks/tests.rs and full_weeks/infra_tests.rs

16

U3 (w2)

xtask/src/cmd/quality_budgets.rs, coding-conventions.adoc

run_b1 takes the SourceScope that workspace_test_scope builds, as run_b2 does, and counts by decision 1. The count it reports is 16, the lock: the showing the ruling asks for. If it reports another number, the difference is found and explained before anything merges.

16

U4 (w3)

canopy-web: applications.rs (8,892), tests only

its one inline test module (4,536 lines) moves whole to applications/tests.rs. The file stays over 500 lines, so the lock does not move.

16

U5 (w5)

canopy-web: applications.rs, code

under applications/, with the handler each starts from: process_page.rs (get_process_application), process_view.rs (build_process_view and its reads), process_clocks.rs (filing_clock_views), list.rs (list_applications), decide.rs (approve_application, deny_application), run_determination.rs (run_determination), run_alerts.rs (the run's alerts and banners), intake_page.rs (get_intake_application), intake_rows.rs (section rows and steps), section_save.rs (put_section_proxy, complete_data_collection_proxy). applications/tests.rs is divided among them by decision 6.

15

U6 (w5)

canopy-applications: services/canopy-applications/src/api/mod.rs (4,807)

program_codes.rs, ele_consent.rs, drafts.rs, finalize.rs, filing.rs (create_application and its guards), reads.rs, update.rs (update and withdraw), interview_completion.rs, determination_context.rs

14

U7 (w5)

canopy-appeals: services/canopy-appeals/src/api/mod.rs (4,398)

bindings.rs, windows.rs, filing.rs, reads.rs (lists and hearing views), decision.rs, final_appeal.rs, withdrawal.rs, postponement.rs (postponement, clock check, reconcile)

13

U8 (w5)

canopy-renewals: services/canopy-renewals/src/api/mod.rs (3,889)

certifications.rs, conversion.rs, due.rs (due lists, caseload trend, universe snapshot), interim_contacts.rs (contacts and change reports), nudges.rs, periodic_reports.rs, periodic_report_reopen.rs, redeterminations.rs, scheduler.rs

12

U9 (w5)

canopy-persons: services/canopy-persons/src/api/mod.rs (3,741), services/canopy-persons/src/api/export.rs (812)

persons.rs, households.rs, member_claims.rs, parent_claims.rs, address_claims.rs, financial_claims.rs (income, asset, expense), fact_reads.rs, redaction.rs, finalize_control.rs; export/csv.rs

10

U10 (w3)

canopy-reporting: services/canopy-reporting/src/api/mod.rs (2,077)

overpayments.rs, fns388.rs, qc.rs, tanf_reports.rs, medicaid_reports.rs

9

U11 (w3)

canopy-web: actions.rs (1,963)

under actions/: interim_contact.rs, recert_nudge.rs, change_report.rs, abawd_activity.rs, discrepancy.rs, notice_download.rs, document_review.rs

8

U12 (w3)

canopy-web: cases.rs (1,849), audit_log.rs (1,773)

cases/rows.rs, cases/status.rs; audit_log/export.rs, audit_log/citation.rs

6

U13 (w3)

canopy-web: composition.rs (1,549), dashboard.rs (1,345)

composition/live.rs, composition/role.rs, composition/user.rs; dashboard/hero.rs, dashboard/panels.rs

4

U14 (w2)

canopy-eligibility: services/canopy-eligibility/src/api/handlers.rs (1,741)

handlers/determine.rs, handlers/reads.rs, handlers/alerts.rs

3

U15 (w3)

canopy-security: services/canopy-security/src/api/mod.rs (1,625)

events.rs, signing_keys.rs, alerts.rs, chain.rs, archive.rs, workers.rs

2

U16 (w3)

canopy-enrollment: services/canopy-enrollment/src/api/mod.rs (1,489)

access.rs (the household gate and read audit), enrollments.rs, issuance.rs, household_reads.rs, termination.rs

1

U17 (w2)

canopy-medicaid: services/canopy-medicaid/src/api/handlers.rs (1,036)

handlers/determine.rs, handlers/determinations.rs, handlers/ele.rs. Sets this plan's status to Done.

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, route-authz audit is compared before and after and the car's e2e lane walks the pages.

Test code moved out of a #[cfg(test)] module stops being compiled, so its tests stop running and nothing fails.

silent

The multiset of test function names is compared before and after in every unit.

Test code loses its #[cfg(test)] gate and is compiled into the service.

silent

Every moved test file is declared under #[cfg(test)]. After U3, an ungated test file over 500 lines is counted as production, which fails the budget.

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 (an_allowlisted_site_passes_and_stale_or_miscounted_entries_fail, xtask/src/cmd/test_lanes_lint/ambient_clock.rs; a_vanished_field_entry_is_stale, xtask/src/cmd/determination_status_lint.rs); the entry moves in the same merge request.

A reference no lint is known to check goes stale: a handler's file in the authorization inventory or another docs page, a test_ref in an action catalogue, a file in the literal allowlist or the contested-surfaces list, a comment.

silent

The search that ends step 3 of the procedure, with its result stated in the merge request.

route-authz audit resolves a canopy-web handler through the route table, loses it in a child module, and reports fewer routes.

silent

Its output is compared before and after, so a route that drops out shows. It already follows a nested handler: case_detail::request_verification::request_verification, a POST in the table today.

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, services/canopy-web/src/api/mod.rs, which is 496 lines, past 500.

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 in nav.adoc, before U1. Done, it is docs/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.adoc first 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 --done is 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 no src/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, not cross_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], as work_requirement_handlers/full_weeks.rs does. 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.rs keys 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 in tests/e2e/specs/case-detail-scroll.spec.ts, is corrected in U2.

Edit this page · default