Repository navigation
fix(mobile): contract test sends fetch as the native app does (no Sec-Fetch-*) - #144
Merged
Merged
Conversation
Node's fetch (undici) adds Sec-Fetch-Mode: cors, which the API gate (apiOnly) treats as a browser and 404s, so setup timed out on /healthz. contract/nativeFetch.ts sends over node:http with only the caller's headers, as React Native does; the server's browser check is unchanged. better-auth 1.7 restores the cached session in the first get-session's init instead of at client creation: the cold-launch test now holds the network back and proves the keychain fills the session atom first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jayleaton
force-pushed
the
fix/contract-native-fetch
branch
from
October 31, 2026 16:43
62a0845 to
061622f
Compare
Owner
Author
|
Authorized by JJ, merged by Claude (Opus 5.5, CI speed agent) with --admin after make ci-local attested 061622f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Same change as jayleaton/sparkrack#36 (merged there). Stacked on #143, which brings better-auth 1.7.
pnpm test:contractcouldn't run. Its setup timed out on/healthzbecause Node'sfetch(undici) adds browser Fetch Metadata to every request (Sec-Fetch-Mode: cors). The server's API gate (apiOnly,apps/web/internal/server/middleware.go) treats that as a browser and returns 404, as designed. React Native's fetch (NSURLSession / OkHttp) sends no such headers, so the harness was not testing the API the way the app reaches it. As a result, the better-auth 1.7 change in #143 (getCookie()became async) had never been checked against a real server.Fix
nativeFetchcovers what the clients use: method, headers, a buffered body, an AbortSignal, andredirect(follows by default; manual and error are supported). DuplicateSet-Cookieheaders are kept.The first real run also caught a better-auth 1.7 change. The cold-launch test expected the session atom to be filled from the keychain when the client is created. In 1.7, expoClient restores that cache inside the first
get-sessionrequest'sinit, before the request is sent. Both versions set onlydataand leaveisPendingalone, and the app's screens wait onisPending, so what users see on launch is the same. The test now holds the client's network requests back. It asserts that the atom is filled from the keychain while nothing has been sent (sent === 0), then releases them and checks thatget-sessionconfirms it (sent === 1). better-auth 1.7 capturesfetchwhen the client is created, which is why the hold is installed before the relaunch.Evidence
Error: contract setup: timed out waiting for the Go server /healthz.Test Files 1 passed (1) · Tests 11 passed (11)against a real Go server and Postgres 18. Every/api/auth/*and/api/core/v1/*request was traced going throughnativeFetch./healthzapiFetchwithoutawait authClient.getCookie()/users/me,PATCH, sessionstsc,expo lint(0 warnings) andpnpm test(18 tests) pass.make check-fastpasses.Merge Danger
Door: two-way.
Blast Radius: test-only. This touches the mobile contract harness, one test and the README. No app code and no server code change.
Local verification
Head
061622f624732d26123c2489c4298b95e9b5845d· tree7bba64b01882· passedAttested by
JJ EatononMacBook-Pro-3.localRan: On this exact tree (7bba64b) in a 4 vCPU Davit box, after the rebase onto main: apps/mobile-app pnpm install --frozen-lockfile, pnpm typecheck, pnpm lint, pnpm test (18/18), pnpm test:contract (11/11 against a real Go server + Postgres); make secret-scan (local). Only apps/mobile-app/contract changes; the Go tree is main's, which passed make ci as #142's head.
🤖 Generated with Claude Code