Skip to content

test(agent-core-v2): make the test suite pass on Windows#2035

Open
Yorha9e wants to merge 9 commits into
MoonshotAI:mainfrom
Yorha9e:fix/windows-test-compat
Open

test(agent-core-v2): make the test suite pass on Windows#2035
Yorha9e wants to merge 9 commits into
MoonshotAI:mainfrom
Yorha9e:fix/windows-test-compat

Conversation

@Yorha9e

@Yorha9e Yorha9e commented Jul 22, 2026

Copy link
Copy Markdown

Problem

The agent-core-v2 test suite currently fails 98 tests across 23 files on Windows (Node 24, Windows 11) while passing on POSIX. All failures are platform assumptions in test code — no product bugs were found. This PR makes the suite fully green on Windows without weakening a single assertion, and keeps every test passing unchanged on POSIX.

This is also a first step toward re-enabling the test-windows CI job disabled in #1144 (for the agent-core-v2 package; other packages may still have Windows failures to address separately).

Root causes and fixes (one commit per family)

  1. Hook test commands are not shell-portable — hook tests spawn commands via spawn(shell: true), which is cmd.exe on Windows. POSIX constructs (echo ... >&2; exit 2) and node -e "<script>" with JSON.stringify quoting both break: cmd.exe toggles quoting at every " (it does not understand \"), shredding scripts that contain double quotes. → New test/harness/nodeScriptCommand.ts writes the script to a temp .cjs file and invokes node on it — no shell quoting on either platform.

  2. fsService fake-fs path mismatch — stubs keyed paths with POSIX literals / node:path join while session services resolve with node:path (drive letters on Windows) and normalize with pathe. → Unify the test file on pathe and normalize fake-fs lookup keys.

  3. MCP stdio fake servers fail to start — fixture paths were built with URL.pathname, which yields /D:/... on Windows. → fileURLToPath (platform-aware, identical on POSIX).

  4. Plugin tests shell out to the zip CLI — Info-ZIP does not exist on Windows. → New test/harness/zipArchive.ts builds the same archive layout with yazl (already a dependency).

  5. Hard-coded POSIX path expectations (sessionLifecycle, workspaceCommand) — expected values like /tmp/extra resolve to D:\tmp\extra on Windows. → Derive expectations with resolve/normalize from the same literals; byte-identical values on POSIX.

  6. Remaining files — pathe-align path expectations with implementation output (agentRoots, skillRoots, skillCatalog, glob, toolResultTruncation); probe symlink capability at runtime and skip when unavailable (hostFsService, profile/context, workspaceRegistry, sessionExport) via new test/harness/symlinkSupport.ts — on Developer-Mode Windows and POSIX these tests still run in full; skip the POSIX mkdir mode-bit assertion on Windows (persist), matching an existing fileStorageService precedent; route the fullCompaction hook command through nodeScriptCommand.

Scope

  • Test code onlypackages/agent-core-v2/test/, plus two new harness helpers. Zero changes under src/.
  • No assertion was weakened: skips are capability probes (symlink privilege, POSIX mode bits) that still execute fully where the capability exists; everything else derives expectations per platform with identical values on POSIX.

Verification

  • Windows 11, Node v24.18.0: pnpm -C packages/agent-core-v2 typecheck clean; pnpm vitest run3864 passed | 14 skipped (capability probes) | 0 failed (previously 98 failed).
  • POSIX: unchanged by construction (pathe normalize is a no-op on POSIX paths; fileURLToPath/resolve produce identical values; capability probes only skip when the capability is genuinely absent). CI will confirm.

Checklist

  • I have read the CONTRIBUTING document.
  • Changeset included (@moonshot-ai/agent-core-v2 patch).
  • Tests pass locally (see Verification).

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1abb298

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/agent-core-v2 Patch

Not sure what this means? Click here to learn what changesets are.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a39bb8b47

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


import { ZipFile } from 'yazl';

/** Zip every file under `sourceRoot` (recursively) and return the archive bytes. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Move helper comments into the file header

This per-function JSDoc sits outside the top-of-file helper header. In packages/agent-core-v2, local convention keeps comments solely in the file header and forbids comments beside functions/statements, so this explanation should be folded into the opening block instead of attached to the function.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

@Yorha9e

Yorha9e commented Jul 22, 2026

Copy link
Copy Markdown
Author

Good catch — folded all helper documentation into the top-of-file comment blocks and dropped the inline comments across the new harness helpers and touched test files (4f21469). Also swept the rest of the PR for the same convention violation; nothing else remains.

yorha9e added 9 commits July 22, 2026 21:22
Hook test commands were executed through spawn(shell: true), which on
Windows means cmd.exe. Two POSIX assumptions broke them there:

- 'echo ... >&2; exit 2' style commands: cmd.exe has no ';' separator.
- 'node -e "<script>"' with JSON.stringify quoting: cmd.exe toggles
  quoting at every '"' (it does not understand \"), shredding scripts
  containing double quotes into multiple arguments.

Introduce test/harness/nodeScriptCommand: write the script to a temp
.cjs file and invoke node on it — no shell quoting on either platform.
Also switch a tool-result path assertion to pathe join, matching the
implementation's forward-slash rendering.
The test stubs and in-memory fake fs keyed paths with POSIX literals
and node:path join, while session services resolve with node:path
(drive-letter absolute on Windows) and normalize with pathe. Unify the
test file on pathe and normalize fake-fs lookup keys; assertions
unchanged.
URL.pathname yields a leading-slash form (/D:/...) on Windows, so every
stdio fake server spawned by the MCP tests failed to start. fileURLToPath
is platform-aware and identical on POSIX.
…zip CLI

The plugin tests invoked the external Info-ZIP binary, which does not
exist on Windows. Add test/harness/zipArchive.ts (yazl, already a repo
dependency) producing the same archive layout.
Session services resolve configured dirs with node:path (drive letters
on Windows) while the local-config backend normalizes with pathe. Derive
seed keys and expected values from the same POSIX literals via
resolve/normalize helpers instead of hard-coded POSIX paths.
…link capability

sessionLifecycle additional-dir expectations now derive from
node:path resolve (identical values on POSIX). The two profile symlink
tests skip via a runtime EPERM probe when the platform cannot create
symlinks (unprivileged Windows), keeping full coverage elsewhere.
- pathe-align path expectations with implementation output (agentRoots,
  skillRoots, skillCatalog, glob, toolResultTruncation)
- probe symlink capability and skip when unavailable (hostFsService,
  workspaceRegistry, sessionExport) via test/harness/symlinkSupport.ts
- skip the POSIX mkdir mode-bit assertion on Windows (persist), matching
  an existing fileStorageService precedent
- route the fullCompaction hook command through nodeScriptCommand so the
  hook script survives cmd.exe (fullCompaction)
Fold helper documentation into top-of-file comment blocks and drop
inline comments in test files, per packages/agent-core-v2/AGENTS.md
comment conventions (review feedback).
@Yorha9e
Yorha9e force-pushed the fix/windows-test-compat branch from 9548d6b to 1abb298 Compare July 22, 2026 13:24
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