diff --git a/tests/commands.test.mjs b/tests/commands.test.mjs index 809fdff..62bea9b 100644 --- a/tests/commands.test.mjs +++ b/tests/commands.test.mjs @@ -4,7 +4,7 @@ import test from "node:test"; import assert from "node:assert/strict"; import { fileURLToPath } from "node:url"; -const ROOT = path.resolve(fileURLToPath(new URL("..", import.meta.url))); +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const PLUGIN_ROOT = path.join(ROOT, "plugins", "codex"); function read(relativePath) { diff --git a/tests/fake-codex-fixture.mjs b/tests/fake-codex-fixture.mjs index ac7f084..a85fd31 100644 --- a/tests/fake-codex-fixture.mjs +++ b/tests/fake-codex-fixture.mjs @@ -1,4 +1,6 @@ +import fs from "node:fs"; import path from "node:path"; +import process from "node:process"; import { writeExecutable } from "./helpers.mjs"; @@ -507,11 +509,19 @@ rl.on("line", (line) => { }); `; writeExecutable(scriptPath, source); + + // On Windows, npm global binaries are invoked via .cmd wrappers. + // Create a codex.cmd so the fake binary is discoverable by spawn with shell: true. + if (process.platform === "win32") { + const cmdWrapper = `@echo off\r\nnode "%~dp0codex" %*\r\n`; + fs.writeFileSync(path.join(binDir, "codex.cmd"), cmdWrapper, { encoding: "utf8" }); + } } export function buildEnv(binDir) { + const sep = process.platform === "win32" ? ";" : ":"; return { ...process.env, - PATH: `${binDir}:${process.env.PATH}` + PATH: `${binDir}${sep}${process.env.PATH}` }; } diff --git a/tests/helpers.mjs b/tests/helpers.mjs index 799fe3c..945ae0e 100644 --- a/tests/helpers.mjs +++ b/tests/helpers.mjs @@ -1,6 +1,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; +import process from "node:process"; import { spawnSync } from "node:child_process"; export function makeTempDir(prefix = "codex-plugin-test-") { @@ -16,7 +17,9 @@ export function run(command, args, options = {}) { cwd: options.cwd, env: options.env, encoding: "utf8", - input: options.input + input: options.input, + shell: process.platform === "win32" && !path.isAbsolute(command), + windowsHide: true }); } diff --git a/tests/runtime.test.mjs b/tests/runtime.test.mjs index 15f96c5..56ba6c1 100644 --- a/tests/runtime.test.mjs +++ b/tests/runtime.test.mjs @@ -10,7 +10,7 @@ import { initGitRepo, makeTempDir, run } from "./helpers.mjs"; import { loadBrokerSession } from "../plugins/codex/scripts/lib/broker-lifecycle.mjs"; import { resolveStateDir } from "../plugins/codex/scripts/lib/state.mjs"; -const ROOT = path.resolve(fileURLToPath(new URL("..", import.meta.url))); +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const PLUGIN_ROOT = path.join(ROOT, "plugins", "codex"); const SCRIPT = path.join(PLUGIN_ROOT, "scripts", "codex-companion.mjs"); const STOP_HOOK = path.join(PLUGIN_ROOT, "scripts", "stop-review-gate-hook.mjs");