fix: make Codex hooks transactional

This commit is contained in:
ZacharyZhang-NY committed 2026-07-20 02:07:52 -04:00
1 parent 6a7fdb7595
commit a9adba1fc1
19 files changed
+2525 -1114

No files matched your search

+16 -2
View File
@@ -43,11 +43,11 @@ async function createFixture(status) {
};
}
function runGuard(scriptPath, homeDir) {
function runGuard(scriptPath, homeDir, input = '{}') {
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, [scriptPath], {
env: { ...process.env, HOME: homeDir, USERPROFILE: homeDir },
stdio: ['ignore', 'pipe', 'pipe'],
stdio: ['pipe', 'pipe', 'pipe'],
});
let stdout = '';
let stderr = '';
@@ -55,6 +55,7 @@ function runGuard(scriptPath, homeDir) {
child.stderr.on('data', (chunk) => { stderr += chunk; });
child.once('error', reject);
child.once('close', (code) => resolve({ code, stdout, stderr }));
child.stdin.end(input);
});
}
@@ -101,3 +102,16 @@ test('cached frozen status keeps the blocking exit code', async () => {
await fixture.close();
}
});
test('fail-open guards report malformed hook input', async () => {
const fixture = await createFixture('active');
try {
const result = await runGuard(fixture.scriptPath, fixture.homeDir, '{ malformed');
assert.equal(result.code, 0);
assert.match(result.stderr, /invalid JSON.*fail-open/i);
assert.equal(result.stdout, '');
} finally {
await fixture.close();
}
});