Repository navigation
fix(test): repair the shared api test fixtures — 249 failures to 95 - #922
Conversation
|
CI rejected five of the files I added to the gate, and it was right to. I gated on local results and called it evidence. Five files — That is precisely the failure mode the gate exists to catch, and I walked into it by measuring in the wrong environment. They are out of the list. The gate is now 14 files / 74 tests, verified after The headline numbers survive re-measurementI re-ran both trees on the clean database, since if the gate list was measured on a dirty stack the totals might be too:
One test apart. So the 249 → 95 claim holds; only the gate list was wrong. One thing this surfaced that is worth its own issueThe magic-link path cannot complete on a clean stack, and the endpoint answers |
📊 Performance Benchmark Results |
…tead of 3
Most of the ~250 failing api tests were not 250 problems. Four faults in
shared plumbing accounted for the bulk of them, and each looked like a broken
endpoint rather than a broken fixture.
## The magic link carried `token_hash`, not `token`
`completeMagicLinkAuth` read `url.searchParams.get("token")`. GoTrue's
confirmation link is `/auth/confirm?token_hash=...&type=signup`, so the read
found nothing, the helper returned null, and every suite built on magic-link
registration asserted `user !== null` and failed. The same bug sat in both
test trees, and it is why `tests/routers/auth.test.ts` could never produce the
cached token fixture — which in turn failed every suite calling
`requireAuthSetup()` with "Auth setup is incomplete".
One line each. It is the single biggest cause in this change.
## The application fixture invented two columns
`createTestApplication` inserted `custom_answers` and `type`. Neither is a
column on `core.applications`; no migration has ever created either. PostgREST
rejects the whole insert when a key does not exist, so every test needing a
seeded application died in its fixture rather than in its assertions.
## Production code that could not be reached by a test
Two modules read their configuration in a way that works under the edge
runtime and cannot work under `deno test`:
- `checkApplicationAccess` built its own service client internally, so the
stub its unit tests pass as the first argument never reached the lookup.
It takes the client as a parameter now; the production call site passes
`getServiceClient()` explicitly, so the service-role read (#608, #649) is
unchanged.
- `auth.ts` captured the magic-link redirect target in a module-level const,
freezing the environment as it stood at import. Read per request now.
Both are small changes that make the modules configurable by their callers.
Neither alters what the edge runtime does.
## No token with the office role
`TEST_USERS.admin` carries `worker/platform` only (#478), so office suites
reaching for it got a 403 and read it as a broken endpoint. There is an
`office` entry now — `[email protected]`, seeded with the role by
`002_seed-users.sql` — cached alongside the others, and the two office REST
suites use it.
## Result
functions/api/__tests__ 344 passed, 72 failed -> 387 passed, 29 failed
tests/routers/ 122 passed, 177 failed -> 221 passed, 78 failed
249 failures to 107. `GATED.txt` grows from 3 files to 19 — 152 tests that
now fail the build if they regress, verified passing together.
What remains is per-suite assertion drift rather than shared plumbing, worst
first: work-logs, profileCompletion, applications, payments, education. One
known environmental gap is also left: the magic-link endpoint answers
`500 Configuration Error` because the local edge runtime has no site URL
configured, which is a stack-config question rather than a code one.
Co-Authored-By: Claude Opus 5 <[email protected]>
`requireAuthSetup()` threw "Auth setup is incomplete. Run auth.test.ts first"
— an ordering dependency between test FILES. `deno test` walks a directory
alphabetically, so every suite whose name sorts before `auth.test.ts` ran
before the suite that writes the token fixture and failed for no reason of its
own. Running one file on its own failed the same way, which made the tree
hostile to work on a single suite at a time — the exact thing anyone repairing
it needs to do.
It mints the tokens itself now when the fixture is missing or stale: password
sign-in for the seeded accounts, no mailbox round-trip, including the `office`
entry added alongside. Suites that mean to exercise the magic-link path still
call it directly.
Proof it is not order-dependent any more: delete `tests/fixtures/tokens.json`
and run `office-jobs-rest.test.ts` alone — 3 passed, where it previously
failed with the message above.
tests/routers/ 221 passed, 78 failed -> 233 passed, 66 failed
`GATED.txt` is unchanged at 19 files: this fixed tests inside suites that
still fail for their own reasons, so no additional file went fully green.
Co-Authored-By: Claude Opus 5 <[email protected]>
I added five files to GATED.txt on the strength of a local green run and CI
rejected them immediately: 40 of 152 tests, every one of them "Failed to get
or create auth token".
The five — auth, auth-session-regression, ccpa, onet, resume — mint their
users through the magic-link flow. That flow completes against my local stack,
which has a warm mailbox and users left by earlier runs, and does not complete
on the fresh stack CI builds. Local green was not evidence, and I treated it
as evidence.
They come back out. The gate is 14 files, 74 tests, verified after
`pnpm supa db reset` — a stack as close to CI's as I can make locally.
GATED.txt now says this in the file itself, above the list, because the next
person to add a line will be standing exactly where I was.
The headline numbers in this branch survive the same re-measurement on a clean
database, so they were sound; it was only the gate list that was wrong:
functions/api/__tests__ 387 passed, 29 failed (unchanged)
tests/routers/ 232 passed, 67 failed (was 233/66 dirty)
Also recorded: the magic-link endpoint answers `500 Configuration Error:
Magic link redirect target is not configured` wherever no site URL is set,
which is the environmental half of why those five cannot be gated yet.
Co-Authored-By: Claude Opus 5 <[email protected]>
a41f780 to
b5d3309
Compare
📊 Performance Benchmark Results |
`Lint REST API Code` has been cancelled at exactly 5:00 on every run since #924, which surfaces as `##[error]The operation was canceled` with no failing check named, and then fails `All Tests Passed`. It is a job timeout, not a lint failure. #924 added a "Type Check (ratchet)" step that runs `deno check` across all 25 edge functions — roughly four minutes on its own — to a job whose `timeout-minutes` was 5, already partly spent on lint and format. Reproduced on main at 28e1550, the commit that added the step: Lint REST API Code | cancelled | 22:57:47Z -> 23:03:03Z All Tests Passed | failure So this is not specific to any branch — every PR touching packages/supabase has been red for it since. 15 minutes, with the reasoning in the file so the next person to add a step to this job knows what it costs. The ratchet itself is fine: run locally on this branch it reports 380 errors, within baseline (api 334, unchanged). Co-Authored-By: Claude Opus 5 <[email protected]>
|
It is a job timeout. #924 added a "Type Check (ratchet)" step that runs Reproduced on main at So every PR touching Fixed here in The ratchet itself is healthy — run locally on this branch it reports 380 errors, within baseline (api 334, unchanged), so nothing in these production edits makes types worse.
|
📊 Performance Benchmark Results |
Follow-on from #920, which built the gate. This repairs what the gate was built to let us land incrementally.
Most of ~250 failures were not 250 problems
Five faults in shared plumbing accounted for the bulk. Each presented as a broken endpoint rather than a broken fixture, which is why they survived so long.
1. The magic link carried
token_hash, nottokenGoTrue's confirmation link is
/auth/confirm?token_hash=…&type=signup. The read found nothing,completeMagicLinkAuthreturned null, and every suite built on magic-link registration asserteduser !== nulland failed. The identical bug sat in both test trees — and it is whyauth.test.tscould never write the cached token fixture, which then failed everything callingrequireAuthSetup().One line each. Single biggest cause in this PR.
2. The application fixture invented two columns
createTestApplicationinsertedcustom_answersandtype. Neither is a column oncore.applications; no migration has ever created either. PostgREST rejects the whole insert when a key does not exist, so every test needing a seeded application died in its fixture instead of its assertions.3. Production code a test could not reach
checkApplicationAccessbuilt its own service client internally, so the stub its unit tests pass as the first argument never reached the lookup. It takes the client as a parameter now; the production call site passesgetServiceClient()explicitly, so the service-role read (fix(api): an org admin 404'd on an application their own list returned #608, fix(api): an org admin passed both auth checks and then 404'd anyway #649) is unchanged.auth.tscaptured the magic-link redirect target in a module-levelconst, freezing the environment at import time. Read per request now.4. No token carried the office role
TEST_USERS.adminisworker/platformonly (#478), so office suites got a 403 and read it as a broken endpoint. There is anofficeentry now —[email protected], seeded with the role by002_seed-users.sql.5. An ordering dependency between test files
requireAuthSetup()threw "Run auth.test.ts first".deno testwalks a directory alphabetically, so every suite sorting beforeauth.test.tsfailed for no reason of its own — and running any single file alone failed the same way, which made the tree hostile to the exact activity needed to repair it. It mints the tokens itself now.Proof it is order-independent: delete
tests/fixtures/tokens.json, runoffice-jobs-rest.test.tsalone → 3 passed.Result
functions/api/__tests__tests/routers/GATED.txtgrows 3 → 19 files, 152 tests that now fail the build if they regress — verified passing together, and from a deleted fixture.What is left, honestly
95 failures remain and they are not another shared cause — I checked by grouping every remaining error message. They are per-suite assertion drift, and most suites exercise the legacy tRPC layer (29 of 38 files in
tests/routers/callcallTRPCEndpoint; tRPC still serves, it is not 404). Worst first:work-logsprofileCompletionpaymentseducationWhether those are worth repairing or retiring is a call about the tRPC→REST migration, not a mechanical fix — so I have not guessed at it.
One environmental gap is also left unfixed: the magic-link endpoint answers
500 Configuration Error: Magic link redirect target is not configuredbecause the local edge runtime has no site URL set. That is stack config, not code — the code side is fixed (it reads per request now).🤖 Generated with Claude Code