Make the MCP server tests ignore localhost probes and the filing wait's deadline
Merged
RO
12h ago+68+68+01234567890123456789-48-48-01234567890123456789
Why
make release-check failed in race-test while v0.22.1 was being cut, on MCP server tests that had not changed since v0.22.0. Two separate causes, both in the tests:
- Another program's requests. moshi-hook, which runs on some developer machines, sends two bare
GET /(no credentials) to every new localhost listener. The fakes here count every request they see, so the probe failed whichever test was listening. Seen in three different tests. - A deadline race.
TestFilingSaysWhetherTryingAgainIsSafecut the filing wait to 300ms for every subtest, and the SDK's first poll fires at 250ms. A poll slower than 50ms, common under the race detector, ended the wait first.
What changed
- Every fake Basecamp in
internal/mcpservercomes fromnewUpstream, which answers 404 without reaching the fake when a request lacks the test client's token.newTestAPItakes only whatnewUpstreamreturns, so a new test cannot build a client against an unguarded fake. - Only the
unsettledsubtest shortens the filing wait, and its filing starts asprocessing, so its result does not depend on whether a poll landed.
Scope
- Covers
internal/mcpserver, the only package that failed. Seven test files in other packages (mostlyinternal/commands) have "unexpected request" handlers too. They did not fail, and I have not checked whether each one judges every request.
Verification
TestFakeBasecampAnswersOnlyTheClientUnderTestsends the probe: fails on the first commit, passes after the gate.- Polls slowed to 100ms by a temporary patch:
failedandunsettledeach failed 5 of 5 before, all subtests passed 5 of 5 after. go test -race -count=20 ./internal/mcpserver/with moshi-hook running: 0 failures (before: failures in each of three batches, 3 of 15 package runs).bin/cipasses.
Summary by cubic
Fixes flaky internal/mcpserver tests that intermittently failed make release-check under the race detector.
- Every fake Basecamp in the package is now built through
newUpstream, which answers 404 to any request lacking the test client's bearer token. This stops other programs probing localhost, like moshi-hook's bareGET /, from reaching the fakes. TestFilingSaysWhetherTryingAgainIsSafeno longer cuts the filing wait for all subtests. Only theunsettledsubtest shortens it, and its filing now starts asprocessing, so its result no longer depends on whether a poll lands before the wait expires.