tests: test_mcp_client.py has order-dependent flakiness and a stale VCR cassette after the mcp 2.0 upgrade
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- testing-qa
调研方向
Start by running python -m pytest tests/test_mcp_client.py -q -p no:randomly to reproduce the stale-cassette failure in test_call_http_mcp_tool, then look at tests/_vcr/test_mcp_client/test_call_http_mcp_tool.yaml. The flakiness lives in the http_mcp_server fixture near line 28 of tests/test_mcp_client.py: port reuse, missing process.wait() after kill, and the TCP-only readiness probe. Done means the cassette test passes, which needs a re-recording that requires API access, and the file passes repeatedly with pytest-randomly enabled. Coordinate with #457 first, since it changes the same cassette.
由索引模型根据 Issue 内容生成。
描述
While auditing MCP support, I found that tests/test_mcp_client.py fails frequently on main (tested at 1a8e07d1, macOS, Python 3.13, mcp 2.0.0). There are two distinct problems.
1. Deterministic: stale cassette for test_call_http_mcp_tool
test_call_http_mcp_tool fails in every run:
vcr.stubs.httpx_stubs.py: CannotOverwriteExistingCassetteException
No match for the request (POST https://api.openai.com/v1/responses) ...
Matchers failed: body
which surfaces as openai.APIConnectionError when there is no network/API key.
Root cause: the cassette (tests/_vcr/test_mcp_client/test_call_http_mcp_tool.yaml, recorded 2026-05-06) pins the MCP client traffic too, and it was recorded against an mcp 1.x client — the recorded first request is initialize with "clientInfo": {"name": "mcp", "version": "0.1.0"}. The installed mcp 2.0.0 SDK sends a different body, so the body matcher never matches.
Fix: re-record the cassette. Note that #457 will require re-recording it anyway (its mcp.Client(mode="auto") sends server/discover before/instead of initialize), so it may be most efficient to re-record as part of landing that PR.
2. Order-dependent flakiness in the HTTP server fixture
With pytest-randomly active (the default here), full-file runs fail roughly 50% of the time (3/4 runs on main in my testing). With -p no:randomly, only the stale-cassette test above fails. Failure signatures observed:
test_register_multiple_mcp_servers—KeyError: 'add'(HTTP server's tools missing fromchat._tools)test_register_http_mcp_server—RuntimeErrorTestMCPErrorHandling::test_register_overlapping_tool_names_error
Likely causes in the http_mcp_server fixture (tests/test_mcp_client.py:28):
- Fixed port 8081 reused across tests, and
process.kill()with noprocess.wait()— the next test can start its server while the previous one is still dying: the new bind can fail, or the readiness probe/registration can hit the previous server mid-shutdown (explaining empty tool lists and connection errors). - Readiness probe only checks TCP connectability (
GET /— a 404 counts as "ready"), not that the/mcpapp is actually serving. stdout=subprocess.PIPEis never drained — a server that logs enough (uvicorn INFO logs) can block on a full pipe buffer.- The
process.returncode is not Nonecheck immediately afterPopenis a no-op (the process hasn't been polled yet).
Suggested fixes:
- Bind an ephemeral free port per test (e.g. port 0, or allocate then pass via
MCP_PORT) instead of a shared fixed port. process.wait()afterkill()(or useterminate()+wait(timeout=)thenkill()).- Probe the MCP endpoint itself (or wait for the uvicorn startup log line).
- Send server output to
DEVNULL, or drain the pipes.
Reproduction
# flaky failures (~50% of runs)
for i in 1 2 3 4; do python -m pytest tests/test_mcp_client.py -q 2>&1 | tail -1; done
# deterministic cassette failure
python -m pytest tests/test_mcp_client.py -q -p no:randomly
- 主要语言
- Python
- 星标
- 179
- 派生
- 32
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 10
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
posit-dev/chatlas 的其他 Issue
-
A streaming text delta that repeats everything streamed so far is missing from the recorded turn可能已有人在做 @cpsievert 于 81 天前认领。 未关闭ai-triage:done Priority: Medium
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
ai-triage:needs-review documentation
难度 2/5 1-2 天 新手友好度 76/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 1 天内回复
-
ai-triage:done Priority: Low
难度 3/5 1-2 天 新手友好度 55/100
维护者通常 1 天内回复
-
ai-triage:done Priority: Medium
难度 5/5 一周以上 新手友好度 35/100
posit-dev/chatlas#432 · 2 条评论 ·
维护者通常 1 天内回复
查看 posit-dev/chatlas 的全部 Issue
相似的 Issue
-
bot-triaged module: decompositions module: edge cases module: int overflow module: primTorch oncall: pt2 triage review
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
country:US rating:6 request-theme type:TV SHOW
难度 1/5 1 小时以内 新手友好度 65/100
LizardByte/ThemerrDB#10501 · 1 条评论 ·
-
triage/confirmed
难度 2/5 1-3 小时 新手友好度 77/100
agentscope-ai/agentscope#4563 ·
维护者通常 2 天内回复
-
comp/desktop desktop/chat P3 type/bug
难度 2/5 1-3 小时 新手友好度 77/100
NousResearch/hermes-agent#164451 ·
维护者通常 1 天内回复
-
external integration integration-submission
难度 2/5 1-3 小时 新手友好度 68/100
langchain-ai/docs#8426 ·
维护者通常 1 天内回复