Skip to content

Make the MCP server tests ignore localhost probes and the filing wait's deadline - #997

Merged
robzolkos merged 3 commits into
mainfrom
fix-mcpserver-filing-flake
Nov 1, 2026
Merged

robzolkos merged 3 commits into
mainfrom
fix-mcpserver-filing-flake

Conversation

@robzolkos

@robzolkos robzolkos commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

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. TestFilingSaysWhetherTryingAgainIsSafe cut 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/mcpserver comes from newUpstream, which answers 404 without reaching the fake when a request lacks the test client's token. newTestAPI takes only what newUpstream returns, so a new test cannot build a client against an unguarded fake.
  • Only the unsettled subtest shortens the filing wait, and its filing starts as processing, 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 (mostly internal/commands) have "unexpected request" handlers too. They did not fail, and I have not checked whether each one judges every request.

Verification

  • TestFakeBasecampAnswersOnlyTheClientUnderTest sends the probe: fails on the first commit, passes after the gate.
  • Polls slowed to 100ms by a temporary patch: failed and unsettled each 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/ci passes.

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 bare GET /, from reaching the fakes.
  • TestFilingSaysWhetherTryingAgainIsSafe no longer cuts the filing wait for all subtests. Only the unsettled subtest shortens it, and its filing now starts as processing, 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.

View guided diff Turn on auto-fix

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.
Copilot AI balanced review requested due to automatic review settings November 1, 2026 18:28
@robzolkos
robzolkos requested a review from a team as a code owner November 1, 2026 18:28
@github-actions github-actions Bot added the tests Tests (unit and e2e) label Nov 1, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

View guided diff | Turn on auto-fix | Re-trigger cubic

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 unsettled and starts that fixture as processing, removing dependence on the first poll.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to 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

@robzolkos
robzolkos merged commit f45d3c8 into main Nov 1, 2026
32 checks passed
@robzolkos
robzolkos deleted the fix-mcpserver-filing-flake branch November 1, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants