test: take a free port instead of binding a hardcoded 9876 - #336
Open
Gunther-Schulz wants to merge 1 commit into
Open
test: take a free port instead of binding a hardcoded 9876#336Gunther-Schulz wants to merge 1 commit into
Gunther-Schulz wants to merge 1 commit into
Conversation
The dispatch back-compat case asserts on ANTHROPIC_BASE_URL, but the wrapper really binds the port it is given, so a hardcoded one fails for anyone whose machine already holds it. Observed with a local QGIS MCP server owning 9876: the whole suite went red on a change that had nothing to do with it, which is the failure mode that trains people to discount a red suite. --proxy-port 0 is not usable here, because the assertion needs the number it passed in. So the case asks the OS for a free port, closes the probe socket and passes that number through. There is a small TOCTOU window between the close and the wrapper's own bind; it is far narrower than a fixed port's collision surface, and unlike the fixed port it fails rarely and randomly rather than permanently on the machines that happen to use 9876. Verified as a controlled pair, both arms from the same command with 9876 deliberately held by another process: before, 42/43 with this case failing on EADDRINUSE; after, 43/43. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RMiYvNxKq6G9gfJMzArm4q
Gunther-Schulz
added a commit
to Gunther-Schulz/claude-code-cache-fix
that referenced
this pull request
Aug 14, 2026
…on because a gate said so PR cnighswonger#337 carries the coalescer itself, opt-in behind its env gate, with the measured population in the body — 144 pairs, 114 streaks, 55 billed twice — and the retry class stated as the design constraint rather than as a caveat, since suppressing those would leave a real request unanswered. The record half did not make the slice, and that was decided by the gates rather than by taste: the cherry-pick conflicted on fork-only paths that do not exist upstream, and slice-preflight then named five static imports in its test reaching the census and harvest stack. Ported anyway it would have widened this PR into the verification stack's topic. The PR body says so, so the omission is a stated boundary rather than something a reviewer discovers. Also filed cnighswonger#336, the one-file fix for upstream's hardcoded test port, proven as a controlled pair with the port deliberately held. Separate PR rather than a rider, because upstream asked for unrelated changes to be lifted out. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RMiYvNxKq6G9gfJMzArm4q
Contributor
|
Reviewed at e0256dc. Verdict: approving. Clean, minimal, well-motivated test-only fix. What I checked:
Applying — Proxy Builder |
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.
test/install-service.test.mjs's dispatch back-compat case binds a hardcoded127.0.0.1:9876. The assertion is aboutANTHROPIC_BASE_URL, but the wrapper really binds the port it is handed, so the case fails for anyone whose machine already holds that one.That is not hypothetical: a local QGIS MCP server owns 9876 here, and the suite went red on a change that had nothing to do with it — blocking a push until the port was freed by hand. A test that fails for reasons outside the diff is the kind that teaches people to discount a red suite.
The fix
--proxy-port 0is not usable here, because the assertion needs the number it passed in. So the case asks the OS for a free port, closes the probe socket, and passes that number through. There is a small TOCTOU window between the close and the wrapper's own bind — far narrower than a fixed port's collision surface, and it fails rarely and randomly rather than permanently on every machine that happens to use 9876.Verification
A controlled pair, both arms from the same command with 9876 deliberately held by another process:
One file, one case, no behaviour change to shipped code.
🤖 Generated with Claude Code
https://claude.ai/code/session_01RMiYvNxKq6G9gfJMzArm4q