Codex VS Code extension test runner misreports npm run exit code as 1 (Vitest + Node API harness, WSL2)

Open 💬 1 comment Opened Dec 1, 2025 by emwbae

What version of Codex is running?

codex-cli 0.61.1-alpha.1

What subscription do you have?

Pro

Which model were you using?

GPT 5.1, codex, Codex High

What platform is your computer?

_No response_

What issue are you seeing?

Summary

When using the Codex VS Code extension’s internal test runner against a Node/Vitest project in WSL2, Codex consistently reports:

Command: npm run codex:test

Exit code: 1

and only shows the initial RUN v3.2.4 ... line from Vitest,

even though:

Running the same command in the attached WSL terminal passes, prints a full Vitest summary, and exits with code 0.

A custom harness script is used that:

uses Vitest’s official Node API (startVitest),

runs tests once (watch: false),

prints logs to stdout, and

propagates process.exitCode correctly.

It looks like Codex’s internal test runner is either:

misinterpreting the process exit code, or

terminating the process early / truncating logs before Vitest finishes,

in a way that doesn’t happen from the normal WSL terminal.

Environment

All details are generic; repo is private but this should be reproducible with any similar setup.

OS: Windows 11 + WSL2

WSL distro: Ubuntu

Node version (inside WSL): v22.21.1 (but likely reproducible on other recent Node versions)

Package manager: npm

Test runner: Vitest v3.2.4

VS Code: (fill in your version)

Codex / OpenAI VS Code extension: (fill in extension + version)

Project: Node/TypeScript app with Vitest tests (private repo)

VS Code is attached via Remote WSL (status bar shows [WSL: Ubuntu]), and the Codex extension is installed in WSL.

Relevant project wiring (generic)

Root package.json:

{
"scripts": {
"codex:test": "node scripts/codex-test-runner.cjs"
}
}

Test files under test (generic examples):

src/server/featureA/__tests__/featureA.test.ts

src/server/featureB/__tests__/featureB.test.ts

tests/integration/featureC.test.ts

(Actual file names don’t seem to matter; any Vitest tests will do.)

Harness: scripts/codex-test-runner.cjs

const path = require('node:path');

console.log('[CODEX TEST HARNESS] cwd:', process.cwd());
console.log('[CODEX TEST HARNESS] node version:', process.version);
console.log('[CODEX TEST HARNESS] CI:', process.env.CI);
console.log('[CODEX TEST HARNESS] NODE_ENV:', process.env.NODE_ENV);

(async () => {
try {
// Use Vitest's official Node API instead of spawning npx
const { startVitest } = await import('vitest/node');

const filters = [
'src/server/featureA/__tests__/featureA.test.ts',
'src/server/featureB/__tests__/featureB.test.ts',
'tests/integration/featureC.test.ts',
];

console.log('[CODEX TEST HARNESS] starting Vitest with filters:', filters);

// Run Vitest in "test" mode, single run (no watch)
const vitest = await startVitest(
'test',
filters,
{ watch: false }, // CLI-style options
);

// If Vitest couldn't start or failed early, it may return undefined and set exitCode
if (!vitest) {
console.log(
'[CODEX TEST HARNESS] startVitest returned undefined, exitCode:',
process.exitCode,
);
process.exit(process.exitCode ?? 1);
}

const files = vitest.state?.getFiles?.() ?? [];
console.log('[CODEX TEST HARNESS] vitest finished, files run:', files.length);

const exitCode = process.exitCode ?? 0;
console.log('[CODEX TEST HARNESS] exiting with code', exitCode);
process.exit(exitCode);
} catch (err) {
// Log to STDOUT so tools can see errors
console.log(
'[CODEX TEST HARNESS] error while running Vitest via Node API:',
err && err.stack ? err.stack : err,
);
process.exit(1);
}
})();

Notes:

Everything is CommonJS on the harness side.

All diagnostics go to console.log (stdout), not stderr.

No npx is used; we only rely on vitest/node.

Steps to Reproduce

In WSL, open the project in VS Code:

cd /home/dev/project-x
code .

Confirm:

VS Code window shows [WSL: Ubuntu] in the status bar.

Codex / OpenAI extension is installed in WSL.

From the integrated WSL terminal, run:

npm run codex:test

echo "exit code: $?"

Local WSL result (expected):

Harness logs (cwd, node version, etc.).

Vitest runs the filtered tests.

Normal Vitest summary appears, e.g.:

Test Files 2 passed (2)
Tests 22 passed (22)

Then:

[CODEX TEST HARNESS] vitest finished, files run: 2
[CODEX TEST HARNESS] exiting with code 0
exit code: 0

Now trigger the Codex internal test runner for a task (e.g., after Codex edits some code, let it “run tests” automatically). Codex’s tool ends up calling the same script:

Command: npm run codex:test

Inspect the Codex task’s output.

Observed Behavior (Codex)

Codex’s test log shows something like:

Command: npm run codex:test
Exit code: 1
Last ~60 lines of output:

project-x@1.0.0 codex:test node scripts/codex-test-runner.cjs

[CODEX TEST HARNESS] cwd: /home/dev/project-x
[CODEX TEST HARNESS] node version: v22.21.1
[CODEX TEST HARNESS] CI: undefined
[CODEX TEST HARNESS] NODE_ENV: undefined
[CODEX TEST HARNESS] starting Vitest with filters: [
'src/server/featureA/__tests__/featureA.test.ts',
'src/server/featureB/__tests__/featureB.test.ts',
'tests/integration/featureC.test.ts'
]

RUN v3.2.4 /home/dev/project-x
No stack traces or additional Vitest logs appeared—Vitest still exits with no summary in this environment, so you might need to run a different reporter manually to capture the failure details.

What steps can reproduce the bug?

See above.

What is the expected behavior?

This is happening for ALL tests that codex attempts to run in VSCODE.

Additional information

Notes:

The harness clearly starts (we see the [CODEX TEST HARNESS] logs).

The RUN v3.2.4 line appears, but no test summary or harness “finished/exiting” logs appear.

Codex reports exit code 1, even though running the exact same command in the WSL terminal exits 0.

The harness never logs its catch block message (no [... error while running Vitest via Node API ...]), so the process isn’t exiting through the error path in this script. It seems to be terminated externally or its exit code is being altered/overridden in the Codex runner.

Expected Behavior

When Codex runs:

npm run codex:test

in the same WSL project, it should:

Allow node scripts/codex-test-runner.cjs to complete,

Surface all stdout from the harness and from Vitest (including summary and final “exiting with code 0” line),

And report Exit code: 0 when process.exit(0) is called.

In other words, the Codex test environment should behave like running the same command in the integrated WSL terminal.

Why this appears to be a Codex bug (not project config)

Same Node version, same working directory, same script:

Terminal: exit 0 + full Vitest summary.

Codex test runner: exit 1 + truncated output.

Harness doesn’t depend on npx; it imports vitest/node directly.

All errors are written to stdout via console.log, so they should appear in Codex’s log if they exist.

Codex reports exit 1 even when, locally, the script’s final log is [... exiting with code 0] and echo "exit code: $?" prints 0.

From the project side there’s no remaining knob to turn; this looks like a mismatch between:

what the Node process is actually doing, and

what Codex’s internal test runner reports (exit code + captured output).

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗