diff --git a/plugins/codex/scripts/lib/process.mjs b/plugins/codex/scripts/lib/process.mjs index 0948dbd..f3d0d49 100644 --- a/plugins/codex/scripts/lib/process.mjs +++ b/plugins/codex/scripts/lib/process.mjs @@ -2,13 +2,16 @@ import { spawnSync } from "node:child_process"; import process from "node:process"; export function runCommand(command, args = [], options = {}) { - const result = spawnSync(command, args, { + const platform = options.platform ?? process.platform; + const spawnSyncImpl = options.spawnSyncImpl ?? spawnSync; + + const result = spawnSyncImpl(command, args, { cwd: options.cwd, env: options.env, encoding: "utf8", input: options.input, stdio: options.stdio ?? "pipe", - shell: process.platform === "win32", + shell: options.shell ?? platform === "win32", windowsHide: true }); diff --git a/tests/process.test.mjs b/tests/process.test.mjs index 80e0715..ee0ffc9 100644 --- a/tests/process.test.mjs +++ b/tests/process.test.mjs @@ -1,7 +1,52 @@ import test from "node:test"; import assert from "node:assert/strict"; -import { terminateProcessTree } from "../plugins/codex/scripts/lib/process.mjs"; +import { runCommand, terminateProcessTree } from "../plugins/codex/scripts/lib/process.mjs"; + +test("runCommand enables shell on Windows for PATH-resolved commands", () => { + let captured = null; + + const result = runCommand("codex", ["--version"], { + platform: "win32", + spawnSyncImpl(command, args, options) { + captured = { command, args, options }; + return { + status: 0, + signal: null, + stdout: "codex-cli 0.0.0", + stderr: "", + error: null + }; + } + }); + + assert.equal(captured.command, "codex"); + assert.deepEqual(captured.args, ["--version"]); + assert.equal(captured.options.shell, true); + assert.equal(result.status, 0); +}); + +test("runCommand does not force shell on non-Windows platforms", () => { + let captured = null; + + runCommand("codex", ["--version"], { + platform: "linux", + spawnSyncImpl(command, args, options) { + captured = { command, args, options }; + return { + status: 0, + signal: null, + stdout: "codex-cli 0.0.0", + stderr: "", + error: null + }; + } + }); + + assert.equal(captured.command, "codex"); + assert.deepEqual(captured.args, ["--version"]); + assert.equal(captured.options.shell, false); +}); test("terminateProcessTree uses taskkill on Windows", () => { let captured = null;