Skip to content

test(oauth): assert the callback redirect against the port actually bound, not a fixed 54545 - #8854

Merged
lidge-jun merged 1 commit into
devfrom
fix/oauth-code-login-callback-port
Nov 16, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/oauth-code-login-callback-port

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes the dev-red flake in lane=all run 43928410201, job macos 4/4 (job 133514225751):

tests/oauth/oauth-code-login.test.ts:600
(fail) OAuth code-display login > omitting mode keeps the callback response shape and the localhost redirect
Expected: "http://localhost:54545/callback"
Received: "http://localhost:54547/callback"

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 with startServer(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:54545 just before the failure). With the proxy sitting on the Anthropic callback port, OAuthCallbackFlow did 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:

  • A new expectLocalhostCallbackRedirect helper records Bun.serve calls and asserts what holds whichever port is free: the redirect is http://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 literal http://localhost:54545/callback) now use it.
  • Test 2 ("code mode opens no listening socket") loses its outside probe that re-bound 127.0.0.1:54545. The probe threw EADDRINUSE whenever anything else held the port. The test's own property, zero Bun.serve calls during a code-mode login, stays and is unchanged.
  • Test 1's not.toContain("54545") becomes a port match (:54545 or %3A54545). A random state, PKCE challenge, flow id or millisecond expiry could otherwise contain those five digits; the localhost / 127.0.0.1 checks above it are unchanged.

src/oauth is unchanged; the fallback behaviour is correct.

Verification

Red/green on origin/dev 2589be5. A separate process held 127.0.0.1:54545 (Bun.serve({ port: 54545, reusePort: false })), and each run used /usr/bin/lockf -k /tmp/ocx-test.lock bun test …:

  • Before (unchanged test file), port held: 39 pass / 2 fail. One failure is the CI failure (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?).
  • After, port held: 41 pass / 0 fail (the fallback path).
  • After, port free: oauth-code-login, oauth-callback-server, oauth-manual-code and oauth-login-cli-errors pass, 86 pass / 0 fail (the preferred-port path).
  • Mutation check: with port held, callback-server.ts was temporarily changed to advertise this.preferredPort after 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 test suite, skipped on a shared host by instruction. The ci:full label sends the full suite to CI. No new test files, so no test-layout registration was needed.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (none needed: test-only)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (test-only; OAuth product code untouched)

Summary by CodeRabbit

  • Tests
    • Expanded OAuth login coverage to verify callback listener port selection, fallback behavior, and the port reported in redirects. Updated checks for code-mode login and default-mode API behavior. No user-facing behavior changes are included in this update.

…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.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 16, 2026 18:52
@lidge-jun lidge-jun added the ci:full Run the four full Ubuntu test shards on this pull request label Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T18:54:35.129101Z d495988 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The OAuth login tests now inspect Bun.serve calls to verify callback listener selection and redirects. They also verify code mode opens no listener and check for port 54545 only when it appears as a port value.

Changes: OAuth callback login tests

Layer / File(s) Summary
Listener and redirect assertions
tests/oauth/oauth-code-login.test.ts
The tests inspect bind attempts and verify that callback redirects use the port of the selected listener. Code mode still verifies that it makes no Bun.serve calls. The response check rejects 54545 only when it appears as a port value.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Merge Risk: Minimal · up to d4959

This change only updates OAuth login tests so they no longer assume the callback always uses port 54545. It does not change production behavior, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test-only change: the OAuth callback redirect assertion now checks the port actually bound instead of a fixed 54545. The raw summary and objectives confirm this is the main change:…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test-only change: the OAuth callback redirect assertion now checks the port actually bound instead of a fixed 54545. The raw summary and objectives confirm this is the main change: a helper records Bun.serve calls, checks fallback order, and advertises the listening port. The title is specific and accurate, and it does not mention product code, which is unchanged, so it does not overstate the change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2589be5 and d495988.

Files selected for processing: 1

  • tests/oauth/oauth-code-login.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@lidge-jun
lidge-jun merged commit ed308a3 into dev Nov 16, 2026
37 of 39 checks passed
@lidge-jun
lidge-jun deleted the fix/oauth-code-login-callback-port branch November 16, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). ci:full Run the four full Ubuntu test shards on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant