Repository navigation
Make the MCP server tests ignore localhost probes and the filing wait's deadline - #997
Merged
Merged
Conversation
moshi-hook, running on a developer's machine, sends two bare GET / to every new localhost listener. The fakes in these tests took any request for one from the client under test, so the probe failed whichever test was listening: an unexpected GET /, a reached flag set, a POST-only handler handed a GET. Every fake now comes from newUpstream, and newTestAPI takes only what it returns. TestFakeBasecampAnswersOnlyTheClientUnderTest sends the probe and fails until the fake ignores it.
newUpstream answers 404, without reaching the fake, to any request that lacks the test client's bearer token. moshi-hook's GET / sends none, and neither would any other program probing localhost.
The test cut the filing wait to 300ms for every subtest, and the SDK's first poll fires at 250ms. A poll slower than 50ms, which the race detector makes common, ended the wait first: "failed" read as unsettled, and "unsettled" reported the start's pending instead of processing. A 100ms poll failed both every time. Only "unsettled" needs the wait to run out, so only it shortens the wait, and its filing starts as processing, so the status it reports does not depend on whether a poll landed.
Contributor
There was a problem hiding this comment.
🟢 Approved
There are no active review issues for the test-only changes aimed at stabilizing the CLI’s MCP server tests.
No open issues 🎉
What changed in this PR
This PR stabilizes the CLI’s MCP server tests against unrelated localhost probes and filing-poll timing under the race detector. Changes are limited to tests.
Changes:
- Centralizes fake upstream creation with a bearer-token gate and automatic cleanup.
- Adds a regression test confirming unauthenticated probes never reach fake handlers.
- Limits the shortened filing timeout to
unsettledand starts that fixture asprocessing, removing dependence on the first poll.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
internal/mcpserver/server_test.go |
Adds guarded upstream helpers and probe regression coverage; migrates server tests. |
internal/mcpserver/filing_test.go |
Uses guarded upstreams and removes the filing deadline race. |
internal/mcpserver/feed_test.go |
Migrates feed test fakes to guarded upstreams. |
internal/mcpserver/composite_test.go |
Migrates composite test fakes to guarded upstreams. |
Review effort: Balanced
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.
Why
make release-checkfailed 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: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.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
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.unsettledsubtest shortens the filing wait, and its filing starts asprocessing, so its result does not depend on whether a poll landed.Scope
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.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/mcpservertests that intermittently failedmake release-checkunder the race detector.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.Written for commit 726861e. Summary will update on new commits.