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
11 changes: 10 additions & 1 deletion plugins/codex/scripts/stop-review-gate-hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ function runStopReview(cwd, input = {}) {
}

function main() {
const input = readHookInput();
let input;
try {
input = readHookInput();
} catch {
emitDecision({
decision: "block",
reason: "The stop review gate could not read or parse hook input; refusing to fail open."
});
return;
}
const cwd = input.cwd || process.env.CLAUDE_PROJECT_DIR || process.cwd();
const workspaceRoot = resolveWorkspaceRoot(cwd);
const config = getConfig(workspaceRoot);
Expand Down
13 changes: 13 additions & 0 deletions tests/runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,19 @@ test("stop hook runs a stop-time review task and blocks on findings when the rev
assert.match(status.stdout, /Codex Stop Gate Review/);
});

test("stop hook blocks when hook input is malformed JSON", () => {
const blocked = run(process.execPath, [STOP_HOOK], {
cwd: ROOT,
input: "{not-json"
});

assert.equal(blocked.status, 0, blocked.stderr);
assert.deepEqual(JSON.parse(blocked.stdout), {
decision: "block",
reason: "The stop review gate could not read or parse hook input; refusing to fail open."
});
});

test("stop hook logs running tasks to stderr without blocking when the review gate is disabled", () => {
const repo = makeTempDir();
initGitRepo(repo);
Expand Down