Skip to content

test(vitest): unblock subprocess MCP tests on Node >= 25 dev machines (#478)#479

Merged
colbymchenry merged 1 commit into
colbymchenry:mainfrom
eddieran:fix/tests-pass-on-node-25-plus
May 27, 2026
Merged

test(vitest): unblock subprocess MCP tests on Node >= 25 dev machines (#478)#479
colbymchenry merged 1 commit into
colbymchenry:mainfrom
eddieran:fix/tests-pass-on-node-25-plus

Conversation

@eddieran

Copy link
Copy Markdown
Contributor

Summary

Closes #478.

On a developer machine running Node.js 25+, npm test against main reports 13 failures across 4 files (mcp-daemon, mcp-initialize, mcp-ppid-watchdog, mcp-roots). Every failure is a subprocess test: each one spawns dist/bin/codegraph.js serve --mcp with process.execPath and waits for a JSON-RPC response. On Node ≥25 the spawned child hits the CLI's hard-block (src/bin/codegraph.ts:65) and exits before responding, so waitForMessage times out.

The CLI's block exists to keep end users off Node 25's V8 turboshaft WASM JIT Zone bug (#81). Test scenarios don't actually exercise that path — they spin up short-lived servers, exchange a few JSON-RPC frames, and tear down — so the right thing is to opt the test runner's spawned children out of the block, while leaving the runtime guard intact for everyone else.

Change

One added field in vitest.config.ts:

env: { CODEGRAPH_ALLOW_UNSAFE_NODE: '1' },

Vitest puts this into process.env for the test process. Every affected test either (a) spawns without env (default = inherit process.env) or (b) spawns with env: { ...process.env, ... }, so the variable flows into the child unchanged. No test file or production source is modified.

Validation

On Node 26.0.0 (this dev box), before:

Test Files  4 failed | 44 passed (48)
     Tests  13 failed | 1019 passed | 2 skipped (1034)

After:

Test Files  48 passed (48)
     Tests  1032 passed | 2 skipped (1034)

The runtime guard is still enforced when codegraph is invoked directly — node dist/bin/codegraph.js status on Node 26 still prints the banner and exits with code 1.

Notes for review

  • CI on Node 22/23 is unaffected — the guard doesn't fire there, so the variable is a no-op.
  • The node-version-check.test.ts unit tests (which assert the banner content) are unrelated and continue to pass — they call the banner builders directly, not via spawn.
  • CLAUDE.md's "Known pre-existing Windows failures" note explains the Windows failure mode for mcp-initialize.test.ts / mcp-roots.test.ts (EPERM in afterEach). The macOS/Linux Node ≥25 failure mode is different (timeouts on the parent side, child exits 1 on startup), and is now addressed by this PR — happy to add a follow-up doc tweak to CLAUDE.md if useful.

Test plan

  • npm test green on Node 26.0.0
  • node dist/bin/codegraph.js status still prints the unsupported-version banner and exits 1 on Node 26.0.0 (guard intact for end users)
  • CI green on Node 22/23 (no behavior change expected)

…colbymchenry#478)

Vitest already inherits process.env into every spawned `codegraph serve --mcp`
child, but on Node >= 25 the CLI's hard-block (src/bin/codegraph.ts) kills the
child before it can respond. Set CODEGRAPH_ALLOW_UNSAFE_NODE=1 via test.env so
the test suite is green regardless of the contributor's Node version; the
runtime guard itself is unchanged for end users.

@colbymchenry colbymchenry left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice work — diagnosis is precise (the process.execPath spawn pattern + the >=25 hard-block) and the fix is the right pinch point: vitest's test.env propagates into every spawned child, both the ones that default-inherit process.env and the ones that spread {...process.env, ...}, so a single line in the config covers all four files. Runtime guard stays intact for end users (verified node dist/bin/codegraph.js status still banners + exits 1 on a simulated >=25 box).

Validated locally end-to-end by temporarily lowering the bin's nodeMajor >= 25 to >= 22 on a Node 22 dev box, reproducing the exact Timed out. Messages so far: [] symptom from #478, then confirming the env addition flips all 5 probed tests green. Reverted the probe; no regression with the gate at 25. Thanks for the clean writeup and the n=0 → n=13 numbers!

@colbymchenry colbymchenry merged commit 02935d7 into colbymchenry:main May 27, 2026
jorgerobles pushed a commit to jorgerobles/codegraph that referenced this pull request Jun 1, 2026
…colbymchenry#478) (colbymchenry#479)

Vitest already inherits process.env into every spawned `codegraph serve --mcp`
child, but on Node >= 25 the CLI's hard-block (src/bin/codegraph.ts) kills the
child before it can respond. Set CODEGRAPH_ALLOW_UNSAFE_NODE=1 via test.env so
the test suite is green regardless of the contributor's Node version; the
runtime guard itself is unchanged for end users.
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.

MCP integration tests fail on Node ≥25 dev machines (spawned servers blocked by version check)

2 participants