Skip to content

test(agent-core-v2): build test paths the way a Windows host does - #5488

Merged
RealKai42 merged 1 commit into
mainfrom
test/windows-path-fixtures
Nov 26, 2026
Merged

RealKai42 merged 1 commit into
mainfrom
test/windows-path-fixtures

Conversation

@RealKai42

@RealKai42 RealKai42 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

主 CI 的 Windows 测试(ci.yml 的 test-windows)从 2026-06 起一直是 if: false。最近一次手动触发的 Windows 全量(2026-11-20,运行 44650161040)里,agent-core-v2 有两组测试一共 116 条失败:

  • MCP stdio 相关 37 条:服务起不来,或连接状态是 failed;
  • 项目文件系统 fsService.test.ts 79 条:大多报 path not found,越界限制的用例报「找不到」而不是「越界」。

逐条核实后,这两组都是测试夹具的问题,不是产品在 Windows 上的 bug。这个 PR 修这两组夹具,为重新打开 Windows 测试清掉一部分障碍。

Bug Reproduction Steps

  1. 在 Windows 上跑 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。
  2. 在 Windows 上跑 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:

  1. 这些测试把真实的 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。
  2. test/mcpCore/stubs.ts 用 new URL(...).pathname 取 fixture 路径,在 Windows 上是 /D:/a/...;作为脚本参数按 win32 解析,会变成 D:\D:\a\...。
  3. 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:\...;
    • 在 win32 路径语义下跑真实的 ProjectFsService,符号链接越界、绝对路径、..、盘符相对路径和设备路径都会被拒,工作区内的读取都放行。

这是根本修复:测试改成和它模拟的平台一致,不靠跳过或放宽断言。

Code Changes

 test/mcpCore/stubs.ts
-  fixture = new URL('./fixtures/x.mjs', import.meta.url).pathname
+  fixture = fileURLToPath(new URL('./fixtures/x.mjs', import.meta.url))
+  hostPathClass = process.platform === 'win32' ? 'win32' : 'posix'

 FakeEnvironment paired with a real HostProcessService (5 files)
-  new FakeEnvironment(identity, { capabilities: ['process'] })
+  new FakeEnvironment(identity, { capabilities: ['process'], pathClass: hostPathClass })

 test/mcpCore/client-stdio.test.ts
-  import { join } from 'pathe'
+  import { join } from 'node:path'

 test/project/projectFs/fsService.test.ts
-  import { ... } from 'node:path'
+  import { ... } from 'node:path/posix'
   fakeFs: every path a caller passes in goes through posixPathOf (backslashes → slashes)
   readdir spies: record and compare posixPathOf(path)
  • 只改了 FakeEnvironment 和真实进程服务配在一起的地方;用假 spawn 的用例不需要真实路径,保持原样。不改 FakeEnvironment 的默认值,别的测试依赖它 POSIX 的行为(例如 homeDir 是 /home/fake)。
  • fsService.test.ts 有一处断言原来在 Windows 上形同虚设:expect(reads).not.toContain('/repo/.git')。Windows 上记录下来的是反斜杠路径,就算遍历真的进了 .git,这句也会通过。现在先统一成正斜杠再比较。

Behavior Changes and Affected Users

行为 改动前 改动后 谁依赖旧行为 退路
产品行为 — 不变,只改测试 — —
这 7 个测试文件在 macOS、Linux 上 通过 不变:node:path/posix 与 node:path 相同,hostPathClass 是 posix,没有特殊字符的路径 fileURLToPath 和 pathname 结果相同 — —
这 7 个测试文件在 Windows 上 MCP 37 条、fsService 79 条失败 MCP 的 5 个文件全部通过;fsService 剩 1 条(见下) — —

主 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')。
  • 修复前它就失败,失败的方式和这里修的「假文件系统路径对不上」不同。
  • macOS 上即使把 node:path 换成 win32、把当前目录设成带盘符的路径,也复现不了,所以原因还没查清,这个 PR 不碰它。
验证
  • Windows:在这个分支上手动触发 desktop-ci.yml(Windows 全量),运行 45754920477。
    • 这 7 个文件:
      • client-stdio.test.ts 26/26;
      • connection-manager.test.ts 52/52;
      • agent/mcp/output.test.ts 69/69;
      • projectMcp.test.ts 31/31;
      • initialization.test.ts 2/2;
      • fsService.test.ts 122/123,没过的 1 条见上。
    • 全量的结论仍是 failure:110 个文件、595 条失败,都在别的文件里,和这个 PR 无关。2026-11-20 那次是 107 个文件、557 条,其间 main 加了不少用例。
    • PR 上那个红色的 windows 检查就是这次手动运行,它挂在这个分支的提交上;红是因为上面那些和本 PR 无关的失败。
  • 模拟 Windows 路径(macOS):把 node:path 替换成 node:path/win32 再跑 fsService.test.ts。修复前 123 条里失败 79 条,和 11-20 那次 Windows 运行里这个文件的 79 条失败重合 78 条;修复后 123/123 通过。模拟文件只在本机用过,没有提交。
  • macOS 原生:改动的文件,加上所有引用 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 通过。
  • 没有 changeset:只改测试,按 gen-changesets 的规则免写。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

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.
@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2054e85

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T04:54:17.592712Z 2054e85 PR opened
🔒 Security Review ✅ Completed 2026-11-26T04:57:04.051914Z 2054e85 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@2054e85
npx https://pkg.pr.new/@moonshot-ai/kimi-code@2054e85

commit: 2054e85

@RealKai42
RealKai42 merged commit 69e7ee3 into main Nov 26, 2026
22 of 23 checks passed
@RealKai42
RealKai42 deleted the test/windows-path-fixtures branch November 26, 2026 05:07
RealKai42 added a commit that referenced this pull request Nov 26, 2026
#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant