Skip to content

test(cli): bind daemon fixtures to 127.0.0.1 - #3894

Open
fsafey wants to merge 1 commit into
mvschwarz:mainfrom
fsafey:up/test-listen-loopback
Open

fsafey wants to merge 1 commit into
mvschwarz:mainfrom
fsafey:up/test-listen-loopback

Conversation

@fsafey

@fsafey fsafey commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What a user gets

No product change. The CLI test suite stops flaking when two test files pick the same ephemeral port. Most CLI fixtures started their fake daemon with server.listen(0), a wildcard (::) bind, while the client under test reached it at 127.0.0.1:<port> (the default daemon URL from a state file without host, or an explicit 127.0.0.1 URL). On macOS a wildcard bind does not reserve 127.0.0.1:<port>, so a concurrent listen(0, "127.0.0.1") in another test file can take the same port and answer instead. Observed: status.test.ts > snapshot age under TZ=America/Los_Angeles > reports a snapshot taken two minutes ago as 2m ago timed out at 20000ms with an unhandled DaemonResponseError: The daemon returned an unreadable response (HTTP 404).

This binds those 75 fixtures (54 files under packages/cli/test) to 127.0.0.1, so the kernel refuses a second loopback bind on that port. It is the same fix #3891 made for the pair-client target in hosts-add-pair-routes.test.ts; that file is left to #3891.

How you verified it

On this branch's commit, macOS, Node 22:

  • Deterministic repro: a vitest setup file (not committed) that, after every listen(0...), binds a second server on 127.0.0.1:<same port> answering 404, and holds the original listen callback until that bind succeeds or fails.
    • Before (base status.test.ts), -t "snapshot age": all three reports a snapshot taken two minutes ago as 2m ago cases fail with the same DaemonResponseError (HTTP 404). The second bind succeeded against :: every time.
    • After: status.test.ts 28/28 pass. All 15 second binds are refused with EADDRINUSE.
  • Completeness: I ran the same setup over all 133 CLI test files that call .listen( or serve(. The second bind succeeded in only two places, both left unchanged: client.test.ts, whose client uses localhost, and host-ipv6-status.test.ts, which binds ::1. The 11 tests that failed in that run all need the built CLI (dist/), which I did not build.
  • The 54 changed files without the setup: 54 files passed, 1232 tests passed, 1 skipped.
  • Not run: npm run build, the full npm test, npm run lint.

Anything you were unsure about

  • preflight.test.ts and one case in up.test.ts use listen(0) as a port-in-use blocker. The preflight probe connects to 127.0.0.1, so I bound those blockers to the address they are probed on.
  • I left client.test.ts and the daemon's tcp-readiness-native.test.ts alone. The first uses localhost; the second binds the host under test explicitly.
  • Product servers already bind an explicit host, so nothing outside test/ changes.

If this is security-related

Not security-related.

  • One concern per PR; no version bump; no CHANGELOG.md edit
  • Tests added or updated where the change is testable
  • I listed the checks I ran, their results, and any checks I could not run

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Updated CLI test servers to listen explicitly on the local loopback address rather than relying on the default network binding. This keeps test traffic local and makes server binding consistent across the test suite. No CLI behavior or user-facing features changed.

CLI test fixtures started their fake daemon with listen(0), a wildcard
("::") bind, while the client under test reached it at 127.0.0.1:<port>
(the daemon URL default, or an explicit 127.0.0.1 URL). On macOS a
wildcard bind does not reserve 127.0.0.1:<port>, so a concurrent
127.0.0.1:0 listener in another test file can bind the same port number
and answer instead. status.test.ts then timed out on "reports a snapshot
taken two minutes ago as 2m ago" with an unhandled DaemonResponseError
(HTTP 404).

Bind those 75 fixtures (54 files) to 127.0.0.1 so the kernel refuses a
second loopback bind. client.test.ts keeps its wildcard bind: its client
uses localhost, not 127.0.0.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

CLI test HTTP servers and mock daemons now bind explicitly to 127.0.0.1 instead of using the default host. Test assertions and application behavior are otherwise unchanged.

Changes: CLI test server bindings

Layer / File(s) Summary
Bind CLI test servers to loopback
packages/cli/test/*
Test HTTP servers and mock daemons now specify 127.0.0.1 in their listen calls. Existing test assertions remain unchanged.

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

Change: Other

Suggested reviewers: mvschwarz, nikhi00718

Merge Risk: Minimal · up to 60ad1

This change only makes CLI test servers bind to the IPv4 loopback address so concurrent listeners stop interfering with them. It does not change product behavior. No concrete risk remains, and it is ready to merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Only #3891 is directly linked and active (open). Its coding requirement is in packages/daemon/test/hosts-add-pair-routes.test.ts: bind the fake pair-client target to 127.0.0.1 and assert the POST /pai… Confirm the state of the pair-client block at the reviewed head (the listen call near the pair-start tests, and the status assertions in the three cases). Then either (a) confirm that #3891 is already merged or handled in a separate change …
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test(cli): bind daemon fixtures to 127.0.0.1" matches the main change. The PR changes the fake-daemon and test HTTP server fixtures under packages/cli/test to bind to 127.0.0.1 instead of t…
Out of Scope Changes check Passed The whole-PR summary shows only test-file changes under packages/cli/test (54 files, 75 fixtures). Each changed line moves a fake-daemon listen call from the wildcard default host to 127.0.0.1. This m…
Full details: Title check

Explanation

The title "test(cli): bind daemon fixtures to 127.0.0.1" matches the main change. The PR changes the fake-daemon and test HTTP server fixtures under packages/cli/test to bind to 127.0.0.1 instead of the wildcard address. It is short, specific, and follows a conventional commit style. It does not mention the macOS port-collision motivation, which is acceptable because the title need not cover every detail.

Full details: Out of Scope Changes check

Explanation

The whole-PR summary shows only test-file changes under packages/cli/test (54 files, 75 fixtures). Each changed line moves a fake-daemon listen call from the wildcard default host to 127.0.0.1. This matches the PR objective: stop cross-file port collisions on macOS. The same root cause is described in #3891. The PR states that product code is unchanged. No changed file appears unrelated to the stated objective. The changes are not from a linked issue requirement, but they are test-only hardening of the mechanism #3891 describes, and the PR scopes them explicitly. I did not diff each file, so the per-line assessment relies on the summary.

Full details: Linked Issues check

Explanation

Only #3891 is directly linked and active (open). Its coding requirement is in packages/daemon/test/hosts-add-pair-routes.test.ts: bind the fake pair-client target to 127.0.0.1 and assert the POST /pair status in three cases before using pairId. The PR summary and PR description state that this PR does not change that file and leave it to #3891. The whole-PR summary lists only packages/cli/test files, so the PR does not implement #3891. I read the head and base versions of the file, but the output was truncated at 16000 bytes before the pair-client block. I could not confirm whether the head file still uses a wildcard listen(0) or already contains the fix. The CLI fixture changes do not satisfy #3891's requirement.

Resolution

Confirm the state of the pair-client block at the reviewed head (the listen call near the pair-start tests, and the status assertions in the three cases). Then either (a) confirm that #3891 is already merged or handled in a separate change and remove it from this PR's linked targets, or (b) apply the #3891 change to hosts-add-pair-routes.test.ts in this PR. Re-run this assessment after that.

Finishing Touches

Generate unit tests (beta)

  • 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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a6d120cc-895b-4019-927a-ff93b5da624b
Commits

Reviewing files that changed from the base of the PR and between bfd90b9 and 60ad112.

Files selected for processing: 54

  • packages/cli/test/add.test.ts
  • packages/cli/test/adopt.test.ts
  • packages/cli/test/agent-image.test.ts
  • packages/cli/test/agent.test.ts
  • packages/cli/test/archive.test.ts
  • packages/cli/test/ask-seat.test.ts
  • packages/cli/test/ask-session.test.ts
  • packages/cli/test/ask.test.ts
  • packages/cli/test/attach.test.ts
  • packages/cli/test/bootstrap.test.ts
  • packages/cli/test/broadcast.test.ts
  • packages/cli/test/bundle.test.ts
  • packages/cli/test/capture.test.ts
  • packages/cli/test/chatroom.test.ts
  • packages/cli/test/context.test.ts
  • packages/cli/test/discover.test.ts
  • packages/cli/test/down.test.ts
  • packages/cli/test/env.test.ts
  • packages/cli/test/expand.test.ts
  • packages/cli/test/export-import.test.ts
  • packages/cli/test/fetch-guard.test.ts
  • packages/cli/test/fork.test.ts
  • packages/cli/test/health.test.ts
  • packages/cli/test/import-running-name-render.test.ts
  • packages/cli/test/kernel-ready-deadline.test.ts
  • packages/cli/test/lifecycle.test.ts
  • packages/cli/test/package.test.ts
  • packages/cli/test/preflight.test.ts
  • packages/cli/test/provider.test.ts
  • packages/cli/test/ps-archived-count.test.ts
  • packages/cli/test/ps-compact.test.ts
  • packages/cli/test/ps-connected-assistants.test.ts
  • packages/cli/test/ps-current-rig.test.ts
  • packages/cli/test/ps-pl012-context-usage.test.ts
  • packages/cli/test/ps-pl019-active.test.ts
  • packages/cli/test/ps-unknown-rig.test.ts
  • packages/cli/test/ps.test.ts
  • packages/cli/test/reconcile-session.test.ts
  • packages/cli/test/requirements.test.ts
  • packages/cli/test/restore.test.ts
  • packages/cli/test/rig.test.ts
  • packages/cli/test/send.test.ts
  • packages/cli/test/snapshot-restore.test.ts
  • packages/cli/test/specs.test.ts
  • packages/cli/test/start.test.ts
  • packages/cli/test/status.test.ts
  • packages/cli/test/transcript.test.ts
  • packages/cli/test/up-restore-decision.test.ts
  • packages/cli/test/up-running-name-render.test.ts
  • packages/cli/test/up.test.ts
  • packages/cli/test/usage.test.ts
  • packages/cli/test/whoami-bounded-peers.test.ts
  • packages/cli/test/whoami-host-hint.test.ts
  • packages/cli/test/whoami.test.ts

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

@mvschwarz

Copy link
Copy Markdown
Owner

Thanks, @fsafey, for #3894, which applies the same 127.0.0.1 binding as #3891 to the CLI test fixtures, so two test files can't end up answering on the same port. It's in review, and we'll follow up here.

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