Repository navigation
Description
Parent discovery
Tracked under #53 — Discovery: Half-Shell codebase audit and technical-debt dependency map. Scopes the repo owner's "every mutation and role permissions testing" item, deliberately narrowed to avoid duplicating #58/#60/#62.
Why this is its own issue, not duplicate work
docs/AUTHORIZATION.md already documents a full role × route permission matrix (written in #49). By the time #58, #60, and #62 land, essentially every mutation route will have its own route.test.ts proving at least one allow case and one deny case for the roles that test file's author chose to check. That's real coverage, but it's not the same guarantee as "the documented matrix is mechanically verified" — nothing today would catch:
- a route's
requireApiRole([...])call changing (a role added or removed) withoutdocs/AUTHORIZATION.md's table being updated to match, or vice versa - a route-test file that only ever checked one deny case (e.g. "technician denied") silently missing another role that should also be denied (e.g. a
dispatcher-only route never getting atechnician-denied test, only anadmin-denied one)
A per-route route.test.ts proves "this specific request shape behaves as this test author expected." A matrix consistency check proves "the code's actual allowed-role list for every route equals what's documented," which is the thing that actually stays true automatically as the codebase grows — the point of a systematic, not incidental, permission audit.
Scope
- A single new test file (e.g.
src/lib/__tests__/authorizationMatrix.test.ts) that:- Statically parses (or imports and introspects, whichever is more reliable without executing route side effects) every
requireApiRole([...])call site undersrc/app/api/**/route.ts, extracting the route path, HTTP method, and its declared allowed-roles array. - Cross-checks that extracted list against a hand-maintained table mirroring
docs/AUTHORIZATION.md's matrix (kept in the test file itself, or a small fixture next to it). - Fails loudly, naming the specific route, if code and doc disagree in either direction (code allows a role the doc doesn't list, or vice versa) — this is the actual "systematic" guarantee: a future PR that changes a role list without updating the doc (or forgets to update the code to match an intentional doc change) breaks CI instead of drifting silently.
- Statically parses (or imports and introspects, whichever is more reliable without executing route side effects) every
- A coverage audit, not new route tests: cross-reference the matrix against every route's
route.test.ts(once Add behavior-level regression coverage for untested production mutation seams #58/Harden payment provider tests, especially the live Square integration #60/Add behavior-level test coverage for the remaining admin CRUD routes #62 have landed) and confirm each documented role/route cell has at least one allow-or-deny assertion somewhere. Where a gap remains, add the missing case to that route's existing test file rather than building a parallel matrix-execution test suite — avoids two competing sources of behavioral truth for the same routes.
Sequencing
This issue makes the most sense after #62 lands (fewer gaps to find in step 2), but step 1 (the static consistency check) can start independently any time — it only needs the routes to exist, not their tests.
Acceptance criteria
- A new test proves every route's actual
requireApiRole([...])allowed-roles list matchesdocs/AUTHORIZATION.md's documented matrix, and fails with a clear message naming the mismatched route if they ever diverge. - Every cell in the documented matrix has at least one allow-or-deny test somewhere in the existing per-route test files (gaps filled in those files, not duplicated elsewhere).
-
npm run lint,npx tsc --noEmit,npm test,npm run buildall pass. - No production code changes unless the consistency check itself surfaces a real doc/code mismatch — if it does, fix whichever side is wrong (code or doc) and say which, with reasoning, same as every other finding this session.
Out of scope
- Per-route behavior tests themselves (Add behavior-level regression coverage for untested production mutation seams #58, Harden payment provider tests, especially the live Square integration #60, Add behavior-level test coverage for the remaining admin CRUD routes #62 already own that).
- Role-aware RLS (documented in
docs/AUTHORIZATION.mdas an intentionally deferred future hardening step, not required here). - Page-level authorization (
requireProfileWithRole,requireAdminProfile, etc.) — API routes only, matching this session's established scope.
Activity
Merge pull request #69 from diese-tech/claude/authorization-matrix-63