Repository navigation
test(oauth): assert the callback redirect against the port actually bound, not a fixed 54545 - #8854
Conversation
…ound, not a fixed 54545 The code-login file's own startServer(0) can be handed 54545 by the OS (macOS assigns ephemeral ports in sequence), so the callback flow correctly falls back and the literal port assertion fails (lane=all 43928410201, macos 4/4). Assert that 54545 is tried first, that fallback happens only after that bind failed, and that the redirect names the listening port. Drop the outside re-bind probe of 54545 and match the port in the no-localhost check.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
Fixes the dev-red flake in lane=all run 43928410201, job
macos 4/4(job 133514225751):Cause (from the job log). That batch ran its files one at a time (
1x PARALLEL), so no other file held the port. The test file's own management server is started withstartServer(0), and macOS assigns ephemeral ports in sequence. Across the file it received 54520, 54522, … 54543, and then 54545 for this exact test (🚀 opencodex proxy running on http://localhost:54545just before the failure). With the proxy sitting on the Anthropic callback port,OAuthCallbackFlowdid what it is designed to do: it fell back to a free port (54547) and advertised that port. The product is correct; the test asserted a fixed port it does not own. Any other process that holds 54545 triggers the same failure.Change (test-only).
tests/oauth/oauth-code-login.test.ts:expectLocalhostCallbackRedirecthelper recordsBun.servecalls and asserts what holds whichever port is free: the redirect ishttp://localhost:<port>/callback; the first IPv4 bind attempt is 54545; the advertised port equals the port of the listener that actually bound; and a port other than 54545 is used only after a bind on 54545 threw. Tests 2 and 8 (the two places that compared against the literalhttp://localhost:54545/callback) now use it.EADDRINUSEwhenever anything else held the port. The test's own property, zeroBun.servecalls during a code-mode login, stays and is unchanged.not.toContain("54545")becomes a port match (:54545or%3A54545). A random state, PKCE challenge, flow id or millisecond expiry could otherwise contain those five digits; thelocalhost/127.0.0.1checks above it are unchanged.src/oauthis unchanged; the fallback behaviour is correct.Verification
Red/green on
origin/dev2589be5. A separate process held127.0.0.1:54545(Bun.serve({ port: 54545, reusePort: false })), and each run used/usr/bin/lockf -k /tmp/ocx-test.lock bun test …:Expected "http://localhost:54545/callback",Received "http://localhost:59292/callback"); the other is test 2's probe (Failed to start server. Is port 54545 in use?).oauth-code-login,oauth-callback-server,oauth-manual-codeandoauth-login-cli-errorspass, 86 pass / 0 fail (the preferred-port path).callback-server.tswas temporarily changed to advertisethis.preferredPortafter falling back. Both rewritten tests then fail (Expected: 57200, Received: 54545), so the helper still catches a wrong redirect. The mutation was reverted.bun run typecheck✓,bun run structure:check✓,bun run privacy:scan✓.Not run: the full
bun run testsuite, skipped on a shared host by instruction. Theci:fulllabel sends the full suite to CI. No new test files, so no test-layout registration was needed.Checklist
Summary by CodeRabbit