Skip to content

ci(functions): make the edge-function type check able to fail - #924

Merged
thinkclay merged 1 commit into
mainfrom
fix/api-deno-typecheck
Sep 26, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/api-deno-typecheck

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #921.

deno check on the api function reported 404 errors, and its step in api-tests.yml carried continue-on-error: true from the day it was written — so it had never once been able to fail. Nothing checked the other 25 functions at all.

1. The zod split — 70 errors from one line

functions/api/deno.json resolved zod from deno.land/x while @hono/zod-openapi resolved its own peer (declared "zod": "3.*") from npm, where the workspace is on zod 4. Every z.object() handed to createRoute was built by a different zod than the library's types expected:

Type 'ZodObject<…, ZodTypeDef, …>' is missing the following properties from
type 'ZodType<any, ZodTypeDef, any>': "~standard", "~validate", openapi

"~standard"/"~validate" are zod 4 internals; the five-arg ZodObject is zod 3. Pointing the import map at npm:[email protected] puts both sides on one instance: 70 → 0. The function imports no workspace schemas, so nothing else moves with it.

Not caused by the recent zod bump — I checked, since I merged it: 407 errors at 4.1.13 before #870, 404 at 4.6.5 after. The split is the 3/4 boundary in the import map and predates it.

2. A ratchet, because the other 334 are real

~117 are handlers returning a status the route's responses never declared; ~103 are data-shape mismatches. Each needs a decision about that route's contract — per-route work, not a CI fix. So known-bad is pinned per file and anything worse fails. Per file rather than one total on purpose: a single number lets you add errors to one route while fixing another and still pass.

Verified all three failure paths by planting errors and watching them fail:

planted result
new error in a file not in the baseline NEW packages/…/auth-session/index.ts — 1 error(s) → exit 1
extra error in a baselined file WORSE packages/…/routes/teams.ts — 19, baseline allows 18 → exit 1
a function becoming uncheckable deno could not type-check these functions at all → exit 1

3. It now covers every function, and 12 are held at zero

pnpm test:deno:types used to find every .ts and check them in one go — each file without its function's import map. That is why it reported a different 315, including complaints about scf-schemas importing awesome-phonenumber, which is correct in context. It now points at the new checker.

Checked properly, from each function's own directory, 12 are already clean: auth-logout, auth-refresh, auth-session, auth-token-exchange, background-check-webhook, community-ai-summary, community-moderate, news, news-import, notify-check-receipts, notify-digest-daily, notify-digest-weekly. Their absence from the baseline holds them at zero — including deployed functions (the notify-* pipeline, webhooks-email, job-import) that the old api-only step never looked at.

--node-modules-dir=auto is passed on the command line rather than added to each deno.json: only api sets it, and without it deno aborts at startup on any function using npm: specifiers. Keeping it out of the config leaves what the Supabase runtime reads untouched.

The two bugs that nearly shipped in this script

Worth reading, because both made it silently useless:

Wrong ANSI strip. An earlier draft used /\[[0-9;]*m/ — no escape character — so every line kept a leading \x1b, ^TS never matched, and all 26 functions reported zero. A ratchet that always passes. Caught only by planting an error and watching it pass.

A startup abort scored as zero. The same draft counted "deno aborted before checking anything" as "no errors", which reported three functions clean that deno had never looked at. The script now separates no errors from could not be checked, and fails on the latter unless the baseline acknowledges it with a reason. stripe-webhook is the single entry — it pins npm:[email protected], a version that was never published (#923, and not a production issue: deploy-functions.sh does not deploy it).

Verification

The runtime check I am relying on CI for: the zod import-map change is the only runtime-affecting edit here (deno.land/x/[email protected] → npm:[email protected] — same library, same version, different registry). The local edge runtime serves whichever checkout started it, so my local api-test pass may not have exercised this tree. CI's Run API Tests job serves the PR's code over real HTTP, so that is the signal to watch. If it passes, the change is runtime-neutral.

🤖 Generated with Claude Code

`deno check` on the `api` function reported 404 errors and its step in
api-tests.yml carried `continue-on-error: true` from the day it was written,
so it had never once been able to fail. Nothing checked the other 25
functions at all.

## The zod split: 70 errors from one line

`functions/api/deno.json` resolved `zod` from `deno.land/x` while
`@hono/zod-openapi` resolved its own peer — declared `"zod": "3.*"` — from
npm, where the workspace is on zod 4. So every `z.object()` handed to
`createRoute` was built by a different zod than the library's types expected:

    Type 'ZodObject<…, ZodTypeDef, …>' is missing the following properties
    from type 'ZodType<any, ZodTypeDef, any>': "~standard", "~validate", openapi

`"~standard"`/`"~validate"` are zod 4 internals; the five-arg `ZodObject` is
zod 3. Pointing the import map at `npm:[email protected]` puts both sides on one
instance and the family goes 70 -> 0. The function imports no workspace
schemas, so nothing else moves with it.

Not caused by the recent zod bump: 407 errors at 4.1.13 before #870, 404 at
4.6.5 after. The split is the 3/4 boundary in the import map and predates it.

## A ratchet, because the rest are real

The 334 that remain on `api` are ~117 handlers returning a status the route's
`responses` never declared and ~103 data-shape mismatches. Each needs a
decision about that route's contract — per-route work, not a CI fix. So the
known-bad is pinned per file and anything worse fails. Per file rather than
one total: a single number lets you add errors to one route while fixing
another and still pass.

Verified all three failure paths by planting errors: a new file not in the
baseline fails, an existing file gaining one fails, and a function becoming
uncheckable fails.

## It now covers every function, and 12 are held at zero

`pnpm test:deno:types` used to `find` every .ts and check them in one go —
each file WITHOUT its function's import map. That is why it reported a
different 315, including complaints about `scf-schemas` importing
`awesome-phonenumber`, which is correct in context. It pointed at the new
checker.

Checked properly, from each function's own directory, 12 are already clean:
auth-logout, auth-refresh, auth-session, auth-token-exchange,
background-check-webhook, community-ai-summary, community-moderate, news,
news-import, notify-check-receipts, notify-digest-daily, notify-digest-weekly.
Their absence from the baseline holds them at zero. That includes deployed
functions — the notify-* pipeline, webhooks-email, job-import — which the old
api-only step never looked at.

`--node-modules-dir=auto` is passed on the command line rather than added to
each deno.json: only `api` sets it, and without it deno aborts at startup on
any function using npm: specifiers. Keeping it out of the config leaves what
the Supabase runtime reads untouched.

## The bug that nearly shipped in this script

An earlier draft stripped ANSI with `/\[[0-9;]*m/` — no escape character — so
every line kept a leading \x1b, `^TS` never matched, and all 26 functions
reported zero. A ratchet that always passes. Caught by planting an error and
watching it pass.

The same draft scored a startup abort as zero errors, which reported three
functions "clean" that deno had never looked at. The script now separates "no
errors" from "could not be checked" and fails on the latter unless the
baseline acknowledges it with a reason. `stripe-webhook` is the one entry:
it pins `npm:[email protected]`, a version that was never published — #923.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay
thinkclay merged commit 28e1550 into main Sep 26, 2026
14 checks passed
@thinkclay
thinkclay deleted the fix/api-deno-typecheck branch September 26, 2026 22:57
thinkclay added a commit that referenced this pull request Sep 26, 2026
`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]>
thinkclay added a commit that referenced this pull request Sep 26, 2026
…922)

* fix(test): repair the shared api test fixtures, and gate 19 files instead 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]>

* fix(test): mint the auth fixture on demand instead of failing the suite

`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]>

* fix(test): trim the gate to what a clean stack can actually prove

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]>

* ci(api): give the lint job time to run the type-check it was handed

`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]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
thinkclay added a commit that referenced this pull request Sep 27, 2026
#929)

#924 added a ratchet that type-checks all 26 edge functions and claimed 12 of
them were "held at zero". That was only true for PRs that also happened to
touch `functions/api/**`.

The step lived in api-tests.yml, which is path-filtered:

    paths:
      - 'packages/supabase/functions/api/**'
      - 'packages/supabase/migrations/**'
      - ...

So a new type error in notify-publish, trpc or any of the other 24 never ran
the check that was supposed to catch it. #927 demonstrated it: that PR changed
`functions/stripe-webhook/` specifically to make it type-check for the first
time, went green, and the ratchet never fired. I verified it by hand instead,
which is exactly the manual step a gate exists to remove.

Moved to ci.yml, hung off the existing `gate` job with a new `edge_fn` filter
covering `packages/supabase/functions/**`, `packages/supabase/package.json` and
the script itself. ci.yml runs on every PR, so the filter — not the workflow's
trigger — decides.

Kept as its own job rather than folded into an existing one: it needs deno,
which nothing else in ci.yml does, and it should be skippable when no function
changed. No pnpm install — the script imports only node: builtins.

Removed from api-tests.yml along with the Node setup that existed solely for
it. That job goes back to what its name says: linting and formatting the REST
API code.

This is the same class of defect the ratchet was built to fix — a check that
cannot fail on the thing it is meant to guard. It just moved from
`continue-on-error: true` to a path filter.

Co-authored-by: Claude Opus 5 <[email protected]>
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.

ci(api): the api edge function has never type-checked — 404 errors from one zod split, and CI is set to ignore them

1 participant