Skip to content

feat(admin): Mode B lane readiness card and pilot nav preset - #628

Open
privatejoel wants to merge 1 commit into
mainfrom
feat/lane-readiness
Open

privatejoel wants to merge 1 commit into
mainfrom
feat/lane-readiness

Conversation

@privatejoel

Copy link
Copy Markdown
Collaborator

Summary

Plan C-8 (R-M5 in docs/SO_EXECUTION_COHESION.md). This PR adds a readiness card for the Mode B lane and a pilot nav preset.

The endpoint. GET /api/admin/lane_readiness is admin only. It writes nothing. It returns a list of checks. Each check has a status (ok, warn or missing) and a one-line reason.

  • Flags: so_processing_mode (B is ok, A is warn), terms_check_mode (on or shadow is ok, off is warn), order_handoff_enabled (off is warn, because C-D13 turns it on later).
  • Migrations, each probed by one table and column: 221 (tenant_settings.so_processing_mode), 250 (order_term_checks), 251 (orders.handoff_status), 253 (admin_notifications.recipient_user_id).
  • Cron: the last run of cron/tick and cron/daily from cron_health. The endpoint uses the probeCron reader of /api/health. No row is missing. A stale run or a failed run is warn.
  • Mail provider: the same emailProvider() and emailConfigured() that /api/health reports.
  • Handoff recipients: resolveInternalRecipients on the saved To and CC lists. The check returns counts only, not addresses.
  • ClamAV: CLAMAV_URL set or not (OPS-2).
  • orders.payment_terms (OPS-3): the probe says if the column exists on this database.
  • Use of each lane step in the last 7 days: one head count on audit_events for each of seven actions (create_order, order_reconcile_quotes, order_terms_checked, order_term_decided, approve_order, so_pdf_downloaded, order_sales_order_attached). Zero is warn.

A probe reads missing only for 42703, PGRST204, 42P01 or PGRST205. Any other error reads warn with the error. It never reads ok. Every query on a tenant table filters tenant_id. cron_health has no tenant.

The card. Admin > Sales & quotes > Mode B lane readiness shows the checks in groups. Below them, the pilot nav preset shows what it hides and shows for each role. Nothing changes until an admin clicks "Apply pilot preset". The click sends the map through the existing PATCH /api/admin/nav_settings. The admin can change any role back in Admin > Navigation.

The preset (C-D9 defaults).

  • Sales engineer: My Day, Inbox, Sales Orders, Approvals. "New PO" is the Inbox (intake). "Orders (Register)" is Sales Orders (so), which holds the Register view.
  • The clerk, an operator seat (C-D5): My Day and Sales Orders.
  • Admin: every item. The preset clears any item that was hidden for admin.
  • Other roles do not change.

The phone tabs follow the preset. app.tsx now gives the sidebar and MobileShell the same visibleNav() result, and MobileShell already hides a tab that is not in its nav.

The preset follows the C-D5 and C-D9 defaults. DISC-1 (discovery with the pilot team) has not run yet. Change the preset after DISC-1 if the team works differently.

Small refactors: hasRoleAccess moved from NavVisibilityAdmin.tsx to lib/nav-settings.ts, and the nav filter in app.tsx became visibleNav(). Both keep their behaviour. health.js exports probeCron.

Deliberate shortcuts (each marked in the code):

  • shortcut: 253 is probed before its PR (C-17) merges, so it reads missing until then.
  • shortcut: fixed to the C-D5 and C-D9 defaults, change it after DISC-1 with the pilot team.

Deploy notes

  • No migration.
  • No new environment variable. No new action in SERVER_ACTIONS. The endpoint uses the coarse admin permission.
  • DISC-1 is pending. Do not apply the preset for the pilot until the team agrees to it.
  • After deploy, open the card for the pilot tenant. Read OPS-1 (cron), OPS-2 (ClamAV) and OPS-3 (payment_terms) from it.

Tests

New tests:

  • src/v3-app/api-lane-readiness.test.js (29 tests, through the real router and the real auth.js): a ready lane is all ok; usage counts only this tenant and only the last 7 days; the endpoint writes nothing and filters every tenant-table query by the caller's tenant; sales_manager, sales_engineer, operator and viewer get 403 before any read; no tenant gets 400; PATCH gets 405; each probe reads missing for its missing-schema code (eight cases); an unrelated probe error reads warn; flags off read warn; cron missing, stale, failed and unreadable; no mail provider; no To list, no To that resolves, some entries that resolve to nobody, no addresses in the response, no members of another tenant; no CLAMAV_URL; an unused step.
  • src/v3-app/lib/nav-visibility.pilot-preset.test.ts (8 tests): what each pilot role sees after the preset, admin gets every item back, other roles keep their entries, the preview before anything applies, idempotence, and the server's normalizeMap accepts the map unchanged.
  • src/v3-app/components/mobile-shell.pilot-tabs.test.tsx (4 tests): the phone tabs and the More drawer follow the preset.
  • src/v3-app/components/LaneReadinessCard.test.tsx (3 tests): the checks render; the preview shows and nothing saves before the click; the click saves the preset map and updates the live nav.

Mutation check. Each rule was broken, a test failed, and the rule was restored. All 23 mutations were killed:

# Mutation Failed
M1 Admin gate becomes read 4
M2 42P01 is not a missing table 1
M3 The probe drops its tenant_id filter 1
M4 Usage drops the 7-day window 2
M5 Usage drops its tenant_id filter 2
M6 ClamAV always ok 1
M7 Mail provider always ok 1
M8 "No To resolves" is not missing 1
M9 A stale cron run reads ok 1
M10 An absent cron row reads ok 1
M11 Terms shadow reads warn 1
M12 Any probe error reads missing 1
M13 The payment_terms probe is skipped 2
M14 The recipients check returns addresses 2
M15 The engineer loses Approvals 3
M16 The clerk keeps the Inbox 3
M17 Admin loses every item 1
M18 The preset drops other roles' entries 1
M19 visibleNav ignores the setting 4
M20 The preview lists nothing to show 2
M21 The card applies the preset on load 2
M22 The card skips the live nav update 1
M23 The phone tabs ignore the nav 1

Gates:

  • npm run check: pass.
  • npm run lint: 0 errors. No warnings in the changed files.
  • npm run build: pass. Build outputs deleted.
  • npm run verify: pass. It rewrote docs/RBAC_AUDIT.md and docs/WRITE_PATH_AUDIT.md with drift that is not from this change. This PR keeps only the new row for src/api/admin/lane_readiness.js in docs/RBAC_AUDIT.md.
  • npm run eval:golden: pass.
  • NODE_OPTIONS=--no-experimental-webstorage npx vitest run --maxWorkers=2: 630 files, 7411 tests, all pass.

Not covered

  • The handoff send step has no use count. C-18 builds the send and its audit action.
  • The card does not check which tick handlers succeed (OPS-1 asks for the stale-worker list too). It shows only cron/tick and cron/daily.
  • The card does not count queued mail older than 7 days (OPS-1).
  • The preset keys only the base roles that the server's nav_settings accepts. Design and support roles do not change.
  • I did not test the card in a browser.

🤖 Generated with Claude Code

Plan C-8 (R-M5). Add GET /api/admin/lane_readiness. It is admin only
and writes nothing. It returns one check for each item, with ok, warn or
missing and a one-line reason:

- The flags so_processing_mode, terms_check_mode and
  order_handoff_enabled.
- Migrations 221, 250, 251 and 253, each probed by one table and column.
- The last run of cron/tick and cron/daily, from the probeCron reader of
  /api/health.
- The mail provider, the handoff recipients (counts only), CLAMAV_URL and
  the orders.payment_terms column (OPS-3).
- Use of seven lane steps in the last 7 days, from audit_events.

A probe reads missing only for 42703, PGRST204, 42P01 or PGRST205. Any
other error reads warn. Every query on a tenant table filters tenant_id.

Add a card on Admin > Sales & quotes. It shows the checks and the pilot
nav preset (C-D9 defaults). The card shows what the preset hides and
shows. It applies the preset only when an admin clicks, through the
existing nav_settings write. The sidebar and the phone tabs now read the
same visibleNav() result, so the phone tabs follow the preset.

The preset follows the C-D5 and C-D9 defaults. DISC-1 has not run yet.

No migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
anvil Ready Ready Preview Oct 20, 2026 4:41am UTC

This branch was successfully deployed

1 active deployment
Preview — 1edbbd6d Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant