Repository navigation
Fix silently-dropped status_events inserts (#66); partial load-test audit (#61) - #70
Conversation
Audited all 7 scripts/load-*.mjs against the current route/auth model (POST /api/jobs and PATCH /api/jobs/[id]'s #58/#64 technician-ownership checks, requireApiRole's role model, the SMS outbox/lease changes from #51, and TECH_TOKEN_SECRET signing shape from src/lib/techToken.ts) and found no drift: - Neither office-actions script ever passes technician_id on job creation, and the technician_id used for the PATCH assignment step is always looked up scoped to the acting company via getTechnician(), so #58/#64's ownership checks never reject it. - The full status-transition sequence each office script drives (new -> assigned -> en_route -> in_progress -> quote_pending -> completed) is still valid against src/lib/stateMachine.ts. - Seed script emails/passwords (northwind-comfort-live-qa and the load-fleet-hvac-N fleet slugs) still match what the office scripts sign in with. - The tech-action scripts' manual jwt.sign({jobId, action}, ..., {expiresIn: "24h"}) still matches generateTechToken()'s exact shape; repeated 409s/429s against the same seeded job are the intentional repeated-link/rate-limit scenario the issue asked to confirm, not a bug. - All npm run test:load:*/seed:load:* script names in package.json still match docs/LOAD_TESTING.md. One real gap found and fixed: LOAD_OFFICE_CONCURRENCY and LOAD_OFFICE_DURATION_SECONDS are read by load-office-actions.mjs and load-multi-office-actions.mjs but were never documented in docs/LOAD_TESTING.md's env var list. Added them. Verified every script has valid syntax (node --check) and that all of their runtime dependencies (autocannon, jsonwebtoken, @supabase/ssr, @supabase/supabase-js) resolve. Could not complete this issue's acceptance criterion of actually running each script end-to-end against a live dev server -- this sandbox has no access to SwiftDispatch's real Supabase project (confirmed via the connected Supabase MCP tool, which only reaches an unrelated project), the same already-documented limitation blocking #66. No other code changes were needed since the static audit found nothing else stale. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Confirmed directly against the live Supabase project that session-scoped status_events inserts in POST /api/jobs and PATCH /api/jobs/[id] were being silently rejected: the table has only a SELECT RLS policy (no INSERT policy), and neither call site checked the insert's error. Real production impact confirmed: 654 non-demo manual/call-sourced jobs have zero status_events rows, and the only dispatcher-attributed rows that exist all have actor_id: null -- the seed script's service-role insert signature, not a real API request's (which always sets actor_id: profile.id). Fixed both call sites by switching to createSupabaseAdminClient(), matching how intake/tech-action already write status_events, and now logging (rather than ignoring) the insert's error. Added regression tests to both routes' existing test files proving the write happens through the admin client and not the session client -- the session fakes no longer handle the status_events table at all, so a regression back to the session client throws in tests instead of silently "working". Also covers the non-fatal-on-failure behavior and the technician-authored PATCH path. Verified red-before-green: applying only the production fix without updating the test mocks throws "supabaseUrl is required" (the real admin client construction, unmocked), proving the switch is real; after wiring the admin-client mock, all tests pass. docs/AUTHORIZATION.md's previously-"flagged, not fixed" note is now marked resolved with the live-project findings. No backfill for the 654 already-affected jobs is included here -- that's a production data decision, not a code fix, and is left for explicit follow-up if wanted. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
diese-tech
left a comment
There was a problem hiding this comment.
Half-Shell Council Review
April O'Neil
“Okay, headline first: the reporting is honest, which I like. #66 is actually done. #61 is not. The PR itself even says the end-to-end smoke criterion is still unchecked, so we can’t turn around and say this closes #61 without changing the story.”
April’s read: the PR scope is mostly clean, but the issue contract matters. #61 explicitly requires each load script to be run once against a local dev server with seeded QA data. Static inspection and node --check do not satisfy that acceptance criterion.
Donatello
“The status-events fix is the right shape. We are not redesigning RLS, and we are not moving tenant-scoped job mutations onto the service role. We’re using the admin client exactly where the schema already expects it: writing the audit row.”
Donnie’s read: #66 is architecturally sound. POST /api/jobs and PATCH /api/jobs/[id] keep their normal session-scoped job work, but route status_events inserts through createSupabaseAdminClient(), matching the existing intake/tech-action pattern.
Raphael
“Yeah, this is the part I cared about. Before, the insert could die and nobody knew. Now it uses the client that can actually write the row, checks the error, and the tests are rigged so switching it back to the session client blows up. Good. That’s a real regression test.”
Raph’s read: the #66 fix closes the actual correctness hole. Both call sites now inspect/log insert failure, and the session-client test doubles deliberately do not support status_events, so reverting the production code to the old behavior would fail loudly.
Michelangelo
“Tests are doing actual ninja stuff here, not just standing around looking cool. Dispatcher creates a job? Covered. Dispatcher changes status? Covered. Tech changes status? Covered. Audit insert explodes? Job still succeeds. Nice.”
Mikey’s read: #66 behavior coverage is strong and targeted. Exact-head CI is green at 76a814707bf3fc6b82b3df148808fa9c5dc3cf4e.
For #61 though, node --check only proves the scripts can parse. It does not prove login credentials, seed assumptions, env wiring, current route behavior, or response-shape expectations survive first contact with a running app.
Casey Jones
“You wanna know where this breaks in real life? Some load script boots, logs in with a stale account, gets a 401, and never even reaches the part you thought you tested. Syntax ain’t operations.”
Casey’s read: the missing smoke execution is the only remaining ugly operational uncertainty. No need for a destructive break-it run, but each script needs to at least start successfully against local seeded QA data if #61 is going to be closed.
Splinter
“Discipline is knowing when not to widen the blade.”
Splinter’s read: do not expand the implementation. Choose one of two clean paths:
- run each #61 load script once in the local-dev/seeded-QA smoke mode already specified by the issue, record the result, and keep
Closes #61 - or remove the claim that this PR closes #61 and leave that issue open for the final verification step
Shredder
“The PR claims the scripts are current. Prove it where the code cannot lie: execute them.”
Shredder’s challenge: a stale login, env value, seed fixture, or response assumption can all survive static inspection. The missing smoke run is exactly the test that defeats those failure modes.
Leonardo
“#66 passes. #61 is one step short. We don’t call the mission complete while one acceptance box is still knowingly open.”
Disposition: changes requested from the review perspective.
No production-code changes requested. Finish the #61 smoke verification, or stop closing #61 in this PR. Once that is resolved, I do not see another blocker in the current diff.
|
Fair finding — fixed the PR title/body to stop claiming I looked into whether the new live DB access could also unblock #61's smoke-run criterion, and it can't: every load/seed script needs I'm not going to ask for that secret in chat — not something I'd act on safely even if offered. Left it as an explicit open decision for the repo owner in the PR body: either they run the smoke test themselves per the existing #66 stands as fully done per your review — no changes needed there. Generated by Claude Code Generated by Claude Code |
Summary
Closes #66. Does not close #61 — see the review thread; the end-to-end smoke-run acceptance criterion is still open and I don't have the means to complete it from this sandbox (explained below). Originally combined into one PR per instruction to consolidate remaining work; keeping them together since #61's static audit and doc fix are still real, useful progress even though the issue itself stays open.
While auditing #61's load scripts I got access to the real SwiftDispatch Supabase project (
vfpodezcyufjnqkcpzcn) via the connected Supabase MCP tool for the first time this session. That directly unblocked #66, which had been sitting undiagnosable without live DB access.#61 — Load test scripts audit (static pass done; end-to-end run still blocked)
Read all 7
scripts/load-*.mjsplus the seed scripts against the current route/auth model — no drift found (details below) — and fixed one doc gap (LOAD_OFFICE_CONCURRENCY/LOAD_OFFICE_DURATION_SECONDSwere read by two scripts but never documented indocs/LOAD_TESTING.md).Why the smoke run is still blocked, even with live DB access: every load/seed script needs
SUPABASE_SERVICE_ROLE_KEY— either directly (seed-live-qa.mjs,load-office-actions.mjs,load-tech-actions.mjs, and their multi-company variants all callcreateClient(supabaseUrl, serviceRoleKey)), or indirectly through a locally-running Next.js server that itself needs that key to serve/api/intakeand friends. The Supabase MCP tool only exposes the project URL and publishable/anon keys (get_project_url,get_publishable_keys) — it correctly never exposes the service-role secret. So I can query the database directly (which is how I confirmed #66), but I cannot seed QA data, sign in as a QA user, or run a local server against this project without that key.I'm not asking you to paste it into chat — that's not something I'd act on safely even if offered. This is a genuine decision point:
docs/LOAD_TESTING.mdas-is — nothing in this PR changes that path) or in a sandbox you've provisioned with that secret through whatever secret-handling mechanism you'd trust for it.Audit findings (no drift)
technician_idonPOST /api/jobs— assignment happens via a separatePATCHusing a technician already scoped to the acting company, so Add behavior-level regression coverage for untested production mutation seams #58/Audit every mutation route for unvalidated cross-tenant resource references #64's ownership checks never reject it.new → assigned → en_route → in_progress → quote_pending → completed) is still valid againstsrc/lib/stateMachine.ts.load-tech-actions.mjs's hand-rolled JWT signing still matchesgenerateTechToken()'s exact shape.npm run test:load:*/seed:load:*names still matchdocs/LOAD_TESTING.md.#66 — status_events silently dropped for dispatcher/admin-authored jobs (real bug, fixed)
Queried the live project directly to settle this:
status_eventshas exactly one RLS policy —SELECT-only for company members. NoINSERTpolicy exists.authenticateddoes have a table-levelINSERTgrant, which is exactly what makes this fail silently (RLSWITH CHECKrejects the row; there's no permission error to surface) rather than loudly.manual/call-sourced jobs have zerostatus_eventsrows.dispatcher-attributed rows that do exist all haveactor_id: null— that's the seed script's service-role insert signature (scripts/seed-live-qa.mjs), not a real API request, which always setsactor_id: profile.id. So none of the existing dispatcher rows are evidence the session-scoped insert ever worked.Fix: switched both
POST /api/jobsandPATCH /api/jobs/[id]'sstatus_eventsinserts tocreateSupabaseAdminClient(), matching howintake/tech-actionalready write this table, and now log the insert'serrorinstead of ignoring it at both call sites.Verified red-before-green: applying only the production change without updating the test mocks threw
supabaseUrl is required(the real, unmocked admin client), proving the switch actually changed behavior. Added regression tests to both routes' existing test files that prove the write lands via the admin-client mock and not the session-client mock — covering the dispatcher-created-job path, the dispatcher-status-change path, the technician-status-change path, and the non-fatal-on-insert-failure path.Not included: a backfill for the 654 already-affected jobs. That's a production data decision, not a code fix, so I left it for you to decide rather than doing it unilaterally.
docs/AUTHORIZATION.md's previously-"flagged, not fixed" note for this is now marked resolved with the live-project findings.Tests
npx vitest run— 328 passed (5 new regression tests), all others unaffectednpx tsc --noEmit -p tsconfig.json— cleannpm run lint— clean (same 21 pre-existing warnings)npm run build— cleannode --checkon all load/seed scripts — all pass (proves syntax only, not the smoke-run criterion)Acceptance criteria
#61 (partial — issue stays open):
SUPABASE_SERVICE_ROLE_KEY, which the connected Supabase MCP tool correctly does not exposedocs/LOAD_TESTING.mdupdated for the one real drift found#66 (complete):
errornpm run lint,npx tsc --noEmit,npm test,npm run buildall pass🤖 Generated with Claude Code
https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF