Skip to content

ci(api): gate the build on HTTP api tests, via a list that may only grow (#914) - #920

Merged
thinkclay merged 2 commits into
mainfrom
fix/ci-api-tests
Sep 26, 2026
Merged

thinkclay merged 2 commits into
mainfrom
fix/ci-api-tests

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #914.

The problem, and why the obvious fix doesn't work

packages/supabase/tests/routers/ holds the HTTP tests against the running api edge function — the only kind that catches "this endpoint answers 403 to everyone" (#900) or "this endpoint 500s on every request" (#901). Nothing ran them. No npm script named the directory; prepush load-probed it with --filter '__prepush_load_probe__', which matches no test, so it checked the files parse and ran zero assertions; api-tests.yml runs a different tree entirely.

Pointing CI at the directory does not work. Measured against origin/main @ e675422de on a fresh local stack:

suite result
functions/api/__tests__/{lib,routes} 344 passed, 72 failed
tests/routers/ 122 passed, 177 failed

Turning either on wholesale leaves the build permanently red — the state #412 already taught us gives no signal at all. I also had the continue-on-error wrong in the issue: it is a deliberate, documented decision, explained in the workflow with its history. I'd filed this without reading far enough down the file, and corrected that on the issue.

A ratchet instead

tests/routers/GATED.txt lists the files CI gates on — 8 files, 58 tests, verified passing individually and together. The step that runs them has no continue-on-error. That is the point.

The list may only grow. A file earns its way in by passing; GATED.txt records what is excluded and why, including the two REST files (office-jobs-rest, office-settings-rest) that fail only with Auth setup is incomplete — blocked behind the cached token fixture that auth.test.ts cannot currently produce (magic-link auth fails locally), which is #478 territory rather than anything wrong with those tests.

prepush runs the same list, but only when a local Supabase answers on :54321. It stays infra-free for anyone without a stack and says so:

🔍 Gated HTTP api tests skipped — no local Supabase on :54321.

Three smaller things in the same area

  • The workflow's paths filter did not include packages/supabase/tests/** — so a PR touching only these tests would not have triggered the workflow that runs them.
  • The two muted steps still described the suite as mid-repair under API tests: cleanupCurrentTestData doesn't delete GoTrue auth users → fixed-email fixtures collide #411, which is closed. Their comments now carry current numbers and name what the remaining failures actually are.
  • tests/README.md gains a table saying which of the three test directories a new api test belongs in. That split was documented nowhere, which is part of how tests/routers/ drifted into being unrun.

Verification — the gate can actually go red

A gate that cannot fail is the thing this issue is about, so both paths were run, not assumed:

scenario result
all 8 listed files ok │ 58 passed │ 0 failed, exit 0
a known-failing file added to the list exit 1
a listed file that doesn't exist exit 1, ::error file=…GATED.txt::Listed file not found: …
prepush, stack up runs the gate, 58 passed
prepush, no stack skips, exit 0, does not block the push

The step's run: block was extracted from the YAML and executed verbatim under bash rather than eyeballed. That caught a real bug: the first version used mapfile, which needs bash 4 — the bash on a contributor's macOS is 3.2, so it would have worked in CI and been unrunnable by hand. It is a portable while read loop now.

What this deliberately does not do

It does not attempt the broad repair of either tree. ~250 tests fail across the two for assertion and fixture drift that predates this change; the auth fixture is the first blocker under a good slice of it. That is its own piece of work, and GATED.txt is the mechanism for landing it incrementally rather than in one heroic PR.

🤖 Generated with Claude Code

thinkclay and others added 2 commits September 26, 2026 17:33
…row (#914)

`packages/supabase/tests/routers/` holds the HTTP tests against the running
`api` edge function — the only kind that catches "this endpoint answers 403 to
everyone" (#900) or "this endpoint 500s on every request" (#901). Nothing ran
them. No npm script named the directory; `prepush` load-probed it with
`--filter '__prepush_load_probe__'`, which matches no test, so it checked the
files parse and ran zero assertions; and `api-tests.yml` runs a different tree.

The obvious fix — point CI at the directory — does not work. Measured against
origin/main @ e675422 on a fresh local stack:

    functions/api/__tests__/{lib,routes}   344 passed,  72 failed
    tests/routers/                         122 passed, 177 failed

Turning either on wholesale leaves the build permanently red, which is the
state #412 already taught us gives no signal at all. That is why the two
existing steps carry `continue-on-error` — a deliberate, documented decision I
misread as carelessness when filing this.

So: a ratchet. `tests/routers/GATED.txt` lists the files CI gates on. Eight
files, 58 tests, verified passing both individually and together. The step that
runs them has no `continue-on-error` — that is the point. The list may only
grow; a file earns its way in by passing, and `GATED.txt` records what is
excluded and why, including the two REST files blocked behind the cached auth
fixture (#478) rather than by anything wrong with them.

`prepush` runs the same list, but only when a local Supabase answers on :54321
— it stays infra-free for anyone without a stack, and says so rather than
failing silently.

Three smaller things in the same area:

  - The workflow's `paths` filter did not include `packages/supabase/tests/**`,
    so a PR touching only these tests would not have triggered the workflow
    that runs them.
  - The two muted steps still described the suite as mid-repair under #411,
    which is closed. Their comments now carry the current numbers and say what
    the remaining failures actually are.
  - `tests/README.md` gains a table saying which of the three test directories
    a new api test belongs in, since that split was documented nowhere.

Verified: the gate fails the build when a listed file fails (exit 1), and when
a listed file is missing (exit 1, with the path named). Both were run, not
assumed — a gate that cannot go red is the thing this issue is about.

Co-Authored-By: Claude Opus 5 <[email protected]>
The gate worked — it ran, it failed the build, which is what it is for. But it
failed for the wrong reason: 47 of 58 died on `supabaseKey is required`.

Two causes, both now fixed, and the second is the one worth keeping:

1. The three test steps passed `SUPABASE_ANON_KEY: ${{ secrets.X }}` with no
   fallback. This repo has no such secret, so they received an EMPTY STRING.
   The "Wait for API" and benchmark steps in the same file already fall back to
   the well-known local demo keys; the test steps now do too.

2. `tests/shared/setup.ts` read them with `??`, which falls back on `undefined`
   but not on `''`. So the empty string beat the committed default and every
   suite died on a message that reads like a broken test rather than an unset
   secret. It takes the first env var that is set to something non-blank now.

Reproduced CI's exact condition locally — `SUPABASE_ANON_KEY=""
SUPABASE_SERVICE_ROLE_KEY="" EXPO_PUBLIC_SUPABASE_ANON_KEY=""` — and ran the
gate's own `run:` block against it: fails without the fix, `58 passed, 0
failed` with it.

Worth noting what this says about the two report-only steps: they have been
running with empty keys too, so a share of their 72 failures is this, not
drift. Their numbers will move once this lands.
@thinkclay

Copy link
Copy Markdown
Contributor Author

CI went red, and it is worth being precise about what that proved.

The gate worked. It ran the 8 listed files, they failed, and it failed the build — no continue-on-error to swallow it. That is the whole point of this PR, demonstrated on its first run.

It failed for the wrong reason, though: 47 of 58 died on supabaseKey is required. Two causes, both fixed in fee9a7a:

  1. The three test steps passed SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY_LOCAL }} with no fallback. This repo has no such secret, so they received an empty string. The "Wait for API" step and the benchmark job in the same file already fall back to the well-known local demo keys — the test steps now do too.

  2. tests/shared/setup.ts read them with ??, which falls back on undefined but not on ''. So the empty string beat the committed default, and every suite died on a message that reads like a broken test rather than an unset secret. It now takes the first env var that is set to something non-blank.

I reproduced CI's exact condition locally rather than inferring it — SUPABASE_ANON_KEY="" SUPABASE_SERVICE_ROLE_KEY="" EXPO_PUBLIC_SUPABASE_ANON_KEY="", running the gate step's own run: block:

WITHOUT the fix:  error: Test failed
WITH the fix:     ok | 58 passed | 0 failed

One consequence worth flagging for review. The two report-only steps have been running with empty keys this whole time. So an unknown share of their "72 failures" is this, not assertion drift — the numbers I quoted in the PR description and in GATED.txt were measured locally, where the keys resolve, and CI's own numbers should improve once this lands. I have deliberately not re-measured and re-worded those comments yet: the honest thing is to let this run and see what CI actually reports, rather than predict it.

If the report-only suites come back substantially greener, that is a good argument for a follow-up that re-measures and moves more files into GATED.txt.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay

Copy link
Copy Markdown
Contributor Author

Green, and the open question from my last comment is answered — I was wrong about it.

I suggested a share of the report-only suites' 72 failures might be the empty-key bug rather than assertion drift. It was not. With the keys resolving:

suite before after
Run Unit Tests (report-only) 344 passed, 72 failed 345 passed, 71 failed
Run Integration Tests (report-only) — 1 passed, 6 failed
Run gated HTTP API tests 11 passed, 47 failed 58 passed, 0 failed ✅

One test. So those 71 are genuine drift, and there is no follow-up re-measurement to do — the numbers recorded in GATED.txt and the PR description stand as written.

There is a useful side effect: CI's 345/71 now matches what I measured locally (344/72, one test apart), which means the two environments agree and the local measurement in GATED.txt is trustworthy for deciding what to add to the list next.

Merging.

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.

The HTTP api tests in tests/routers/ are executed by nothing, and the two suites CI does run cannot fail the build

1 participant