codex-plugin-cc/tests/helpers.mjs
ZETA a1266348d6
fix: make test suite portable across platforms (#56)
* fix: make test suite portable across platforms

Replace hardcoded macOS path with fileURLToPath for cross-platform
compatibility. Add .cmd wrapper creation and platform-aware PATH
separator in test fixtures so the fake codex binary is discoverable
on Windows. Add shell and windowsHide options to the test helper
run() function to match production behavior.

Test results on Windows improve from 12/64 pass to 59/64 pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: skip shell for absolute-path commands to avoid Windows space-in-path breakage

When `process.execPath` resolves to a path with spaces (e.g.,
`C:\Program Files\nodejs\node.exe`), `shell: true` causes cmd.exe
to split the path at the space. Guard with `path.isAbsolute()` so
only bare command names (which need `.cmd` shim resolution) use the
shell.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Dominik Kundel <dkundel@openai.com>
2026-03-31 12:40:08 -07:00

33 lines
1.0 KiB
JavaScript

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-") {
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
}
export function writeExecutable(filePath, source) {
fs.writeFileSync(filePath, source, { encoding: "utf8", mode: 0o755 });
}
export function run(command, args, options = {}) {
return spawnSync(command, args, {
cwd: options.cwd,
env: options.env,
encoding: "utf8",
input: options.input,
shell: process.platform === "win32" && !path.isAbsolute(command),
windowsHide: true
});
}
export function initGitRepo(cwd) {
run("git", ["init", "-b", "main"], { cwd });
run("git", ["config", "user.name", "Codex Plugin Tests"], { cwd });
run("git", ["config", "user.email", "tests@example.com"], { cwd });
run("git", ["config", "commit.gpgsign", "false"], { cwd });
run("git", ["config", "tag.gpgsign", "false"], { cwd });
}