Skip to content

Commit 1655338

Browse files
committed
test: persist fake app-server lifecycle markers synchronously
1 parent 28ed9de commit 1655338

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

tests/codex-app-server.test.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ test('uses codex app-server and a 15 second deadline by default', async () => {
4040
assert.equal(CODEX_APP_SERVER_DEFAULT_TIMEOUT_MS, 15_000);
4141
});
4242

43+
test('fake app-server persists lifecycle markers synchronously before exiting', async () => {
44+
const source = await readFile(fake, 'utf8');
45+
assert.match(source, /appendFileSync/);
46+
assert.match(source, /recordLifecycle/);
47+
});
48+
4349
test('terminates the child on success, JSON-RPC error, malformed output, oversized line and timeout', async (t) => {
4450
/** @type {Array<[Record<string,string>,Record<string,number>,string|null]>} */ const cases = [
4551
[{}, {}, null],

tests/fixtures/fake-codex-app-server.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
// @ts-nocheck
3+
import { appendFileSync } from 'node:fs';
34
import { appendFile } from 'node:fs/promises';
45
import process from 'node:process';
56
import readline from 'node:readline';
@@ -9,6 +10,9 @@ const input = readline.createInterface({ input: process.stdin, crlfDelay: Infini
910
async function record(value) {
1011
if (process.env.FAKE_CODEX_RECORD) await appendFile(process.env.FAKE_CODEX_RECORD, `${JSON.stringify(value)}\n`);
1112
}
13+
function recordLifecycle(signal) {
14+
if (process.env.FAKE_CODEX_RECORD) appendFileSync(process.env.FAKE_CODEX_RECORD, `${JSON.stringify({ lifecycle: signal })}\n`);
15+
}
1216

1317
let outputQueue = Promise.resolve();
1418
function write(value) {
@@ -32,8 +36,8 @@ if (process.env.FAKE_CODEX_STDERR_BYTES) {
3236
process.stderr.write(text.repeat(Math.ceil(Number(process.env.FAKE_CODEX_STDERR_BYTES) / text.length)));
3337
}
3438

35-
for (const signal of ['SIGTERM', 'SIGINT']) process.on(signal, async () => {
36-
await record({ lifecycle: signal });
39+
for (const signal of ['SIGTERM', 'SIGINT']) process.on(signal, () => {
40+
recordLifecycle(signal);
3741
process.exit(0);
3842
});
3943
process.on('exit', () => { if (process.env.FAKE_CODEX_EXIT_MARKER) process.stderr.write(process.env.FAKE_CODEX_EXIT_MARKER); });

0 commit comments

Comments
 (0)