Repository navigation
test(agent-core-v2): build test paths the way a Windows host does - #5488
Conversation
On Windows, the MCP stdio tests paired a real HostProcessService with a FakeEnvironment that defaults to posix paths, so the client resolved the host cwd with path.posix and spawned into a nonexistent directory. Their fixture paths came from URL.pathname, which gives /D:/... on Windows, and an expected cwd was joined with pathe, which writes forward slashes. The project fs tests keyed their fake file system with the platform path.join while the service under test and the fake itself use posix paths, so every lookup missed on Windows. Give the stdio fixtures the host path class, build fixture paths with fileURLToPath, join real paths with node:path, and keep the fake file system on posix paths, folding backslashes that callers such as walkDirectoryTree pass in.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
#5474 landed on main as one squashed commit, so the prompt cache files this branch carried from it now come from main as merged, including the review fixes made after this branch forked. Two main changes met the MCP migration: - #5486 made the crash-after-connect fixture exit when the test creates a signal file instead of after a fixed delay. The fixture is gone, so the testkit's exitAfterConnect now takes whenFile in place of afterMs, crashAfterConnectServer passes it on, and both crash cases keep the signal they create once they have seen the connected state. - #5488 added hostPathClass to the MCP stubs for Windows path classes. The stubs keep it beside the testkit-based servers.
Requirement or Bug
主 CI 的 Windows 测试(
ci.yml的test-windows)从 2026-06 起一直是if: false。最近一次手动触发的 Windows 全量(2026-11-20,运行 44650161040)里,agent-core-v2 有两组测试一共 116 条失败:failed;fsService.test.ts79 条:大多报path not found,越界限制的用例报「找不到」而不是「越界」。逐条核实后,这两组都是测试夹具的问题,不是产品在 Windows 上的 bug。这个 PR 修这两组夹具,为重新打开 Windows 测试清掉一部分障碍。
Bug Reproduction Steps
packages/agent-core-v2/test/mcpCore/client-stdio.test.ts,起进程的用例报HostProcessError: Failed to spawn "...node.exe": cwd /a/kimi-code/kimi-code/D:\a\kimi-code\kimi-code does not exist or is not a directory。packages/agent-core-v2/test/project/projectFs/fsService.test.ts,read、stat这类普通用例报path not found: src/a.ts。Root Cause
MCP stdio 测试(
mcpCore/client-stdio、connection-manager、agent/mcp/output、project/projectMcp的两个文件)有三处只认 POSIX:HostProcessService、宿主的process.cwd()和FakeEnvironment配在一起,而FakeEnvironment不指定pathClass时默认是posix。StdioMcpClient用环境的 path 解析工作目录,在 Windows 上path.posix.resolve('D:\\a\\kimi-code\\kimi-code')得到/a/kimi-code/kimi-code/D:\a\kimi-code\kimi-code,进程起不来,连接管理器把服务记成failed。test/mcpCore/stubs.ts用new URL(...).pathname取 fixture 路径,在 Windows 上是/D:/a/...;作为脚本参数按 win32 解析,会变成D:\D:\a\...。client-stdio.test.ts用pathe的join拼期望的工作目录,得到的是正斜杠,和按 win32 解析出来的反斜杠对不上。项目文件系统测试:假文件系统模拟的是 POSIX 的
/repo,环境也是posix。但它建索引时用的是平台自带的node:path(在 Windows 上是反斜杠),自己的逻辑又写死用/切路径。产品按/repo/src/a.ts去查,在 Windows 上一个都对不上。另外,产品里的walkDirectoryTree用平台 path 拼目录,会把反斜杠路径传给假文件系统。产品侧没有问题:
LocalEnvironment按宿主选 path 模块,Windows 上是win32(src/_base/execEnv/environmentProbe.ts:76)。StdioMcpClient配win32环境,默认工作目录和相对工作目录都解析成正确的D:\...;ProjectFsService,符号链接越界、绝对路径、..、盘符相对路径和设备路径都会被拒,工作区内的读取都放行。这是根本修复:测试改成和它模拟的平台一致,不靠跳过或放宽断言。
Code Changes
FakeEnvironment和真实进程服务配在一起的地方;用假spawn的用例不需要真实路径,保持原样。不改FakeEnvironment的默认值,别的测试依赖它 POSIX 的行为(例如homeDir是/home/fake)。fsService.test.ts有一处断言原来在 Windows 上形同虚设:expect(reads).not.toContain('/repo/.git')。Windows 上记录下来的是反斜杠路径,就算遍历真的进了.git,这句也会通过。现在先统一成正斜杠再比较。Behavior Changes and Affected Users
node:path/posix与node:path相同,hostPathClass是posix,没有特殊字符的路径fileURLToPath和pathname结果相同主 CI 的
test-windows仍然关着,这个 PR 不打开它。没有修的那 1 条:
fsService.test.ts的parses multi-root rg output joined with the windows path separator。win32,工作区却是没有盘符的/repo和/extra,在 Windows 上suggest返回空列表(expected [] to include 'src/a.ts')。node:path换成win32、把当前目录设成带盘符的路径,也复现不了,所以原因还没查清,这个 PR 不碰它。验证
desktop-ci.yml(Windows 全量),运行 45754920477。client-stdio.test.ts26/26;connection-manager.test.ts52/52;agent/mcp/output.test.ts69/69;projectMcp.test.ts31/31;initialization.test.ts2/2;fsService.test.ts122/123,没过的 1 条见上。windows检查就是这次手动运行,它挂在这个分支的提交上;红是因为上面那些和本 PR 无关的失败。node:path替换成node:path/win32再跑fsService.test.ts。修复前 123 条里失败 79 条,和 11-20 那次 Windows 运行里这个文件的 79 条失败重合 78 条;修复后 123/123 通过。模拟文件只在本机用过,没有提交。test/mcpCore/stubs.ts的测试,共 18 个文件 537 条全过;改动的文件打乱顺序连跑 5 遍,每遍 426/426。pnpm lint以 0 退出;pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit(覆盖test)通过;pnpm run check:duplication通过。gen-changesets的规则免写。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.