test(proxy): catch CancelledError in TestAutoIndexStartupWarning (#264)#269
Merged
test(proxy): catch CancelledError in TestAutoIndexStartupWarning (#264)#269
Conversation
`test_no_warning_when_compression_none` and its sibling `test_warns_compression_without_auto_index` wrap `await mgr.start()` in `try/except Exception` because the test only cares about the *warning* assertion that follows; the `echo` upstream is expected to fail the JSON-RPC handshake. But the MCP SDK's stdio reader can surface that failure as `asyncio.CancelledError` (a `BaseException`, not an `Exception`), so the cancellation leaked past the catch and the test failed under enough total async test mass to push timing across a threshold. Reproducible at ~50% on PR #263 (which added 23 tests, shifting event-loop scheduling); not reproducible in isolation. Widen the catch to `(Exception, asyncio.CancelledError)` with a comment naming the SDK cancellation path so a future reader who sees `except Exception` would have narrowed elsewhere doesn't re-narrow this one. The narrower form is preferred over `BaseException` so `KeyboardInterrupt` still aborts a hung test. No production code touched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per PR review: the second test's "See sibling test" comment rots if the first test is renamed or reordered. Replace with a self-contained one-liner that names the SDK behavior and the safety argument directly. Co-Authored-By: Claude Opus 4.7 (1M context) <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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Closes #264.
Summary
test_no_warning_when_compression_noneandtest_warns_compression_without_auto_indexintests/test_proxy_manager.py::TestAutoIndexStartupWarningswallow the expected connect failure against anechoupstream so they can assert on the warning that fires before the connect loop runs. The catch wasexcept Exception, but the MCP SDK's stdio reader can surface the upstream's premature exit asasyncio.CancelledError(aBaseException, notException), so the cancellation leaked past the catch and the test failed.Catch widened to
(Exception, asyncio.CancelledError)with a comment naming the SDK cancellation path. The narrower form is preferred overexcept BaseExceptionsoKeyboardInterruptstill aborts a hung test.No production code touched.
Why option 1 (broaden the catch) over option 2 (no-op patch the connect)
Issue #264 listed both. Option 1 is two-line; option 2 rewrites the test to skip the real connect entirely. Option 1 wins because:
ProxyManager.start()end-to-end including the connect loop, which is closer to production than a patched no-op.except Exceptionelsewhere has no reason to re-narrow these.start()raises before reaching the connect loop.If the underlying SDK behavior gets cleaned up later (CancelledError → wrapped in a plain Exception), the catch still works.
Verification
uv run pytest -m "not ollama" -q→ 1748 pass, 1 fail (test_no_warning_when_compression_none).uv run pytest -m "not ollama" -q→ 1747 pass, 0 fail.uv run pytest tests/test_proxy_manager.py::TestAutoIndexStartupWarning -v→ 3 pass.uv run ruff check src && uv run ruff format --check src→ clean.🤖 Generated with Claude Code