Repository navigation
test: bind route test servers to the loopback address they request - #247
Merged
Merged
Conversation
Seven test files listened on the wildcard address (app.listen(0) -> ::) but sent requests to 127.0.0.1. On macOS an ephemeral wildcard listen can be handed a port that another Vitest worker already holds on 127.0.0.1, and connections to 127.0.0.1:<port> then reach that other server. Under the full parallel suite this produced 401 instead of 400 in tutor.routes.test.ts (a dev or gateway server answered) and a 30 s timeout in examples.routes.test.ts (a server without HTTP handler answered). Binding to 127.0.0.1 makes the kernel reject that port. Assertions and timeouts are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Stacked on #246 (Sonar fixes, needed to pass the pre-push gate) – merge #246 first; GitHub then retargets this PR to
main.Problem
Two tests failed sporadically only under the full parallel suite:
tutor.routes.test.ts› "rejects a browser revision …": 401 instead of 400examples.routes.test.ts› "passes exact repository …": timeout after 30 sRoot cause (same for both)
The route tests started their server with
app.listen(0)(wildcard::) but sent requests to127.0.0.1. On macOS:listen(0)can be handed a port that another process already holds on127.0.0.1(measured: after a counter wrap,listen(0)returned the held port;lsofshows*:Pand127.0.0.1:Pboth LISTEN).listen(0, "127.0.0.1")and outgoing connects do skip held ports.127.0.0.1:Pgo to the more specific listener, i.e. the other worker's server.Many tests keep servers on
127.0.0.1. If the foreign server enforces the gateway or is the dev server fromdev-entrypoint.test.ts(which forwards the test key to KI:connect →401 CREDENTIAL_INVALID, reproduced exactly), the tutor test gets 401. If it has no HTTP handler (WebSocket-only test servers), the examples request never gets an answer → timeout.Deterministic reproduction of the old failure
A helper process binds every second port from the current counter position on
127.0.0.1(answering 401, or without request handler):expected 401 to be 400Fix
listen(0, "127.0.0.1")in the 7 test files whose clients use127.0.0.1(the two affected ones pluscompiler.routes,routes-core,server-status,test-reset.routes,protocol-version, which had the same latent bug). Assertions, timeouts and test content are unchanged; no retries. Tests that requestlocalhostandaccess-control.test.ts(deliberate loopback variants) keep the wildcard server.Test plan
./run-tests.sh– all tests green (Docker 32/32, E2E 28/28)🤖 Generated with Claude Code