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
3 changes: 2 additions & 1 deletion dist/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/runCodexExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export async function runCodexExec({
env,
stdio: ["pipe", "inherit", "inherit"],
});
child.stdin.on("error", reject);
child.stdin.write(input);
child.stdin.end();

Expand Down
22 changes: 20 additions & 2 deletions test/runCodexExec.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ function runCodexExecWithFakeCodex({
permissionProfile = "",
extraArgs = "",
safetyStrategy = "unsafe",
promptFileContents = null,
fakeCodexExits = false,
} = {}) {
const tempDir = mkdtempSync(path.join(tmpdir(), "codex-action-permissions-"));
const capturePath = path.join(tempDir, "args.json");
const outputPath = path.join(tempDir, "output.txt");
const promptPath = path.join(tempDir, "prompt.md");
const fakeCodexPath = path.join(tempDir, "codex.mjs");
writeFileSync(
fakeCodexPath,
`import { writeFileSync } from "node:fs";
${fakeCodexExits ? "process.exit(7);" : ""}
const args = process.argv.slice(2);
writeFileSync(process.env.CODEX_CAPTURE_ARGS, JSON.stringify(args));
const outputIndex = args.indexOf("--output-last-message");
Expand All @@ -43,6 +47,9 @@ writeFileSync(args[outputIndex + 1], "fake final message\\n");
`,
"utf8"
);
if (promptFileContents != null) {
writeFileSync(promptPath, promptFileContents, "utf8");
}
const posixLauncher = path.join(tempDir, "codex");
writeFileSync(
posixLauncher,
Expand All @@ -62,9 +69,9 @@ writeFileSync(args[outputIndex + 1], "fake final message\\n");
mainPath,
"run-codex-exec",
"--prompt",
"test prompt",
promptFileContents == null ? "test prompt" : "",
"--prompt-file",
"",
promptFileContents == null ? "" : promptPath,
"--codex-home",
"",
"--cd",
Expand Down Expand Up @@ -111,6 +118,17 @@ writeFileSync(args[outputIndex + 1], "fake final message\\n");
return { result, capturedArgs };
}

test("handles a broken Codex stdin pipe without an uncaught error", () => {
const { result } = runCodexExecWithFakeCodex({
promptFileContents: "x".repeat(8 * 1024 * 1024),
fakeCodexExits: true,
});

assert.notEqual(result.status, 0);
assert.doesNotMatch(result.stderr, /Unhandled 'error' event/);
assert.match(result.stderr, /write EPIPE|codex exited with code 7/);
});

test("preserves workspace-write as the default legacy sandbox", () => {
const { result, capturedArgs } = runCodexExecWithFakeCodex();

Expand Down
Loading