Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plugins/codex/scripts/lib/process.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { spawnSync } from "node:child_process";
import process from "node:process";

// Git metadata can exceed Node's 1 MiB spawnSync default. Keep a generous explicit bound.
const DEFAULT_MAX_BUFFER = 256 * 1024 * 1024;

export function runCommand(command, args = [], options = {}) {
const result = spawnSync(command, args, {
cwd: options.cwd,
env: options.env,
encoding: "utf8",
input: options.input,
maxBuffer: options.maxBuffer,
maxBuffer: options.maxBuffer ?? DEFAULT_MAX_BUFFER,
stdio: options.stdio ?? "pipe",
shell: options.shell ?? (process.platform === "win32" ? (process.env.SHELL || true) : false),
windowsHide: true
Expand Down
24 changes: 23 additions & 1 deletion tests/process.test.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
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 allows output larger than Node's default maxBuffer", () => {
const outputBytes = 2 * 1024 * 1024;
const result = runCommand(process.execPath, [
"-e",
`process.stdout.write("x".repeat(${outputBytes}))`
]);

assert.equal(result.error, null);
assert.equal(result.status, 0);
assert.equal(Buffer.byteLength(result.stdout), outputBytes);
});

test("runCommand preserves an explicit maxBuffer override", () => {
const result = runCommand(
process.execPath,
["-e", `process.stdout.write("x".repeat(${2 * 1024}))`],
{ maxBuffer: 1024 }
);

assert.equal(result.error?.code, "ENOBUFS");
});

test("terminateProcessTree uses taskkill on Windows", () => {
let captured = null;
Expand Down