Skip to content

test: gate auth suites, mint without site url - #932

Merged
thinkclay merged 1 commit into
mainfrom
fix/926-auth-gate-onet
Oct 1, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/926-auth-gate-onet

Conversation

@blink-dev

Copy link
Copy Markdown
Collaborator

Part of #926. It fixes findings 2 and 3; checking the function secrets on dev, preview and prod is the one item left.

auth, auth-session-regression, ccpa, onet and resume passed locally and failed 40 of 152 in CI, all on Failed to get or create auth token. The CI log already said why:

Magic link was built on an unsubstituted config placeholder: env%28EXPO_PUBLIC_URL%29/auth/confirm?token_hash=…&type=signup

config.toml sets site_url = "env(EXPO_PUBLIC_URL)". pnpm supa loads it from .env. CI runs plain supabase start without it, so GoTrue built every emailed link on the literal placeholder. The test helpers parsed the link with new URL(), which throws on that, so every sign-up came back null.

The helpers never visit the link; they only need token_hash and type for verifyOtp. So they now read the query string directly, and the site URL stops mattering. That avoids setting a dummy one in CI.

Changes

  • tests/shared/setup.ts: new magicLinkParams(), used by completeMagicLinkAuth. The env( early return is gone; it only existed to explain this failure.
  • tests/routers/auth-session-regression.test.ts: uses magicLinkParams() instead of new URL().
  • functions/api/tests/setup.ts: the same fix inline, so the report-only unit tests stop losing users this way too.
  • tests/routers/onet.test.ts: onet.occupation_data is empty on a fresh stack, because ONET is a download (pnpm supa:seed:onet) and not in seeds/.sql. The suite now inserts three occupations when the table is empty and deletes them afterwards. A stack with the real data is left alone.
  • tests/routers/GATED.txt: adds the five suites. The header no longer recommends db reset.

Verification

  • Took a real magic link and swapped its base for env%28EXPO_PUBLIC_URL%29. The old parsing throws; both new helpers sign the user in.
  • All 19 gated files with tokens.json deleted first: 154 passed, 0 failed. onet.occupation_data is back to 0 rows afterwards.
  • Magic-link sign-in in the browser against pnpm dev:local + pnpm supa:functions: link emailed, confirmed, landed on /onboarding.
  • deno lint, deno fmt --check and deno check pass on the changed files.

In CI, GoTrue still builds its emailed links on the placeholder. Nothing follows them now, but a future test that checks where a link points would hit it.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay
thinkclay merged commit d1e28a0 into main Oct 1, 2026
15 checks passed
@thinkclay
thinkclay deleted the fix/926-auth-gate-onet branch October 1, 2026 19:04

@thinkclay thinkclay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good diagnosis. The CI log did say why, and "the helpers never visit the link; they only need token_hash and type" is the right conclusion — removing the dependency on site_url beats setting a dummy one.

Checked the parser:

const query = magicLink.indexOf('?')
return new URLSearchParams(query === -1 ? '' : magicLink.slice(query + 1))

Correct for what GoTrue emits (…/auth/confirm?token_hash=…&type=signup): first ?, no fragment. Worth knowing it would fold a #fragment into the last param's value if one ever appeared — not a concern for confirm links, and no regression since new URL().searchParams ignored fragments anyway.

Removing the env( guard is the right call even though it deletes a diagnostic. A guard that returns null and aborts every suite is worse than parsing the two things you need. And you flagged the residual — GoTrue still builds links on the placeholder in CI, so a future test asserting where a link points will hit it. That note is doing real work; please keep it there.

One wart on the O*NET fixtures

The setup/teardown pair is a sound Deno pattern (no beforeAll), and gating on count means a stack with real O*NET data is untouched. But the cleanup is reachable only through a test that runs:

if (count) return;        // setup: skip when rows exist
…
if (!seededFixtures) return;   // teardown: skip when we didn't seed

If a run is killed mid-suite — timeout, OOM, Ctrl-C — the three fixture rows survive. The next run then sees count === 3, returns early, leaves seededFixtures false, and never cleans up. The rows persist until a db reset, and every later run quietly tests against them believing they are real data.

Benign, and it self-conceals, which is the part I would note in a comment at least. A cheap hardening would be deleting by onetsoc_code unconditionally in teardown rather than gating on seededFixtures — those three codes are fixtures whether or not this process inserted them. Your call; not blocking.

Approving.

thinkclay added a commit that referenced this pull request Oct 6, 2026
… if it does not (#987) (#995)

The job has reported success while producing nothing since roughly the
Expo 55->56 upgrade. The comment it left on #990 was an empty code
block. Three things had to be wrong for that:

1. No --config, so deno's config discovery walked out of
   packages/supabase into apps/ui-storybook-native/tsconfig.json and
   refused its `"jsx": "react-native"`. continue-on-error swallowed the
   exit code, and the `>` redirect still created an empty
   benchmark-results.txt — so the artifact and the comment were empty
   rather than missing, which is why nobody noticed. Any deno
   invocation from this repo without --config hits it; reproduced with
   a throwaway file in /tmp.

2. functions/api/__tests__/setup.ts:305 read `url.searchParams` after
   #932 replaced `new URL()` with `new URLSearchParams()` named
   `params`. completeMagicLinkAuth's "missing token or type" branch
   would have thrown a ReferenceError instead of logging and returning
   null.

3. It could not finish in the time the job had. Measured: 389s at the
   file's defaults, 180s with fewer requests per iteration — barely
   better, because Deno.bench keeps sampling until it is confident and
   simply took more samples — and 83s once the sample count itself is
   bounded with `n`. All four knobs are env-overridable; CI takes the
   bounded set, local runs keep the larger defaults. timeout-minutes
   10 -> 15, since 83s is on an M4 Pro and the job also pays for
   checkout, install and `supabase start`.

continue-on-error stays on the measurement: a slow benchmark should not
block a PR. But "it ran and was slow" and "it never ran" are different
states and only the first deserves to be quiet, so a new step fails the
job when the results file is empty or missing.

Verified with CI's env against a real stack: exit 0, 83s, 54 lines, all
five summary rows carrying real figures.

Not fixed here, and worth seeing before trusting the output: there are
no tRPC benchmarks at all (all five are REST, so the rest-vs-trpc name
has no other half), the run logs 30 auth 500s from the magic-link
fixture, and the summary's "2.6 s" is one iteration of 20 requests
rather than a per-request time.

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.

2 participants