Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(sdk): close native provider probes before fixture cleanup (#2491)

Michael D'Angelo45afec5a64a5
diff --git a/sdk/typescript/tests-ts/api-provider-isolation.test.ts b/sdk/typescript/tests-ts/api-provider-isolation.test.ts
index ca099c8e5..861b31aa4 100644
--- a/sdk/typescript/tests-ts/api-provider-isolation.test.ts
+++ b/sdk/typescript/tests-ts/api-provider-isolation.test.ts
@@ -63,10 +63,12 @@ async function nativeRequest(
// Keep the child deadline inside the CI runner's per-test budget.
const probeTimeoutMs = nativeTestTimeoutMs / 2;
let timedOut = false;
+ let reply;
const timer = setTimeout(() => {
timedOut = true;
// A descendant may retain stdout, so EOF cannot be the signal to stop reading.
lines.close();
+ child.kill("SIGKILL");
}, probeTimeoutMs);
const send = (message: unknown) =>
child.stdin.write(JSON.stringify(message) + "\n");
@@ -86,21 +88,33 @@ async function nativeRequest(
send({ method: "initialized", params: {} });
send({ id: 2, method, params });
}
- if (response.id === 2) return response.result;
+ if (response.id === 2) {
+ reply = response;
+ break;
+ }
}
- const reason = timedOut
- ? `timed out after ${probeTimeoutMs}ms`
- : "closed before replying";
- throw new Error(`Native ${method} probe ${reason}: ${stderr}`);
} finally {
- clearTimeout(timer);
lines.close();
+ // EOF lets the app-server shut down its workers before fixture cleanup.
+ child.stdin.end();
// Bun on Windows can keep these pipes open after the app-server process exits.
child.stdout.destroy();
child.stderr.destroy();
- child.kill();
- await closed;
+ try {
+ await closed;
+ } finally {
+ clearTimeout(timer);
+ }
+ }
+ if (timedOut) {
+ const phase = reply ? "shutdown" : "response";
+ throw new Error(
+ `Native ${method} probe timed out after ${probeTimeoutMs}ms waiting for ${phase}: ${stderr}`,
+ );
}
+ if (!reply)
+ throw new Error(`Native ${method} probe closed before replying: ${stderr}`);
+ return reply.result;
}
async function readProviderProfile(home: string, name: string) {