[MERC-4] 补齐 transport error 即时失效单测与后端死亡恢复 E2E - #4
Merged
Conversation
基于 MERC-3 review 结论补齐测试缺口(MERC-4):
单测(tests/unit/pool/transport-error-invalidation.test.ts):
- 覆盖 transport.on('error') → invalidateConnection 即时失效路径
(修复的卖点,此前完全没有测试覆盖)
- 使用真实 BaseTransport 子类(TestTransport),走真实状态机
handleError → state ERROR + isConnected() 翻转 + emit('error'),
而非 mock isConnected(),可抓到 isConnectionHealthy 不再调用
isConnected() 或 handleError 不再翻 ERROR 的回归
- 验证:connectionFailed 携带连接 id、死连接释放 maxConnections 槽位、
下次 acquire 拿到不同 id 的新连接、幂等不重复失效
E2E(tests/integration/backend-death-recovery.test.ts):
- stdio 后端进程运行中退出(code 0)→ 池失效死连接 → 下次
tools/list 成功并经新连接返回相同 N 个工具(非 TRANSPORT_ERROR)
- 验证单槽池在连接死亡后释放槽位、不再复用死连接
E2E(tests/integration/sse-reconnect-recovery.test.ts):
- SSE 后端重连耗尽 → transport ERROR → 池失效连接 → SSE 恢复可达后
下次 tools/list 经新连接成功;SSE 持续不可达时返回明确降级错误
(连接创建超时),而非吐回死连接的陈旧响应
验证:npm run typecheck/lint/format:check 通过;clean build 后
npm test 全绿(947/947,含 cli-mode 集成测试 9/9)。
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.
背景
基于 MERC-3 review 结论补齐测试缺口(Multica issue: MERC-4)。
Architect 在 MERC-3 review 中确认主根因修复正确、可合并,但「已实现单测 + E2E 验证」只完成了一半:
transport.on('error') → invalidateConnection(修复的「即时失效」卖点)完全没有测试覆盖;现有 pool 用例 mock 了isConnected(),没有验证「真实 transport 进入 ERROR → isConnected() 翻转 → 池失效 → 新建」整链路。本 PR 在 MERC-3 修复(commit
f3f946e,PR #3)之上补齐这些测试。改动
单测:
tests/unit/pool/transport-error-invalidation.test.ts(5 用例)覆盖
transport.on('error') → invalidateConnection即时失效路径。使用真实BaseTransport子类(TestTransport),走真实状态机handleError → state ERROR + isConnected() 翻转 + emit('error'),而非 mockisConnected()—— 可抓到isConnectionHealthy不再调用isConnected()或handleError不再翻 ERROR 的回归。验证:connectionFailed携带连接 id、死连接释放maxConnections槽位、下次acquire拿到不同 id 的新连接、幂等不重复失效。E2E:
tests/integration/backend-death-recovery.test.ts(2 用例,真实 stdio 子进程)stdio 后端进程运行中退出(code 0)→ 池即时失效死连接 → 下次
tools/list成功并经新连接返回相同 N 个工具(非TRANSPORT_ERROR)。验证单槽池在连接死亡后释放槽位、不再复用死连接。E2E:
tests/integration/sse-reconnect-recovery.test.ts(2 用例,真实HttpTransport)SSE 后端重连耗尽 → transport
ERROR→ 池失效连接 → SSE 恢复可达后下次tools/list经新连接成功;SSE 持续不可达时返回明确降级错误(连接创建超时),而非吐回死连接的陈旧响应。HttpTransport与ConnectionPool为真实实例,仅 mockeventsource/node-fetch两个网络原语以确定性驱动 SSE 连通性。新增 mock MCP stdio 后端:
tests/integration/fixtures/mock-stdio-server.js。验证
npm run typecheck/npm run lint/npm run format:check:通过npm test:947/947 通过(含 9 个 cli-mode 集成测试 9/9,build 后全绿)说明
本 PR 在 MERC-3 修复(PR #3,commit
f3f946e)之上追加测试 commit。若 PR #3 先合并入 main,本 PR 的 diff 将自动收敛为仅含新增测试。两 PR 可独立评审、不冲突。Multica: MERC-4