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

fix(ci): stabilize Python discovery and native worker tests (#1793)

Michael D'Angeloc05aaf4e8c2e
diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.ts
index 19232bc42..8a3a13918 100644
--- a/sdk/typescript/src/runtime.ts
+++ b/sdk/typescript/src/runtime.ts
@@ -3490,7 +3490,8 @@ async function usablePython(
{
env: command.environment,
encoding: "utf8",
- timeout: 5_000,
+ // Cold Python startup can exceed five seconds on busy Windows hosts.
+ timeout: 30_000,
windowsHide: true,
signal,
},
diff --git a/sdk/typescript/tests-ts/fixtures/stored-daybreak-workers.mjs b/sdk/typescript/tests-ts/fixtures/stored-daybreak-workers.mjs
index 34c0145b1..36d2fe95b 100644
--- a/sdk/typescript/tests-ts/fixtures/stored-daybreak-workers.mjs
+++ b/sdk/typescript/tests-ts/fixtures/stored-daybreak-workers.mjs
@@ -1,14 +1,20 @@
import childProcess from "node:child_process";
+import { once } from "node:events";
import { mock } from "bun:test";
import { createInterface } from "node:readline";
import { pathToFileURL } from "node:url";
const spawn = childProcess.spawn;
let workerArgs;
+let workerProcess;
// Capture actual worker arguments in this isolated coordinator process.
const recordedSpawn = (command, args, options) => {
- if (args[0] === "exec") workerArgs = args;
- return spawn(command, args, options);
+ const child = spawn(command, args, options);
+ if (args[0] === "exec") {
+ workerArgs = args;
+ workerProcess = child;
+ }
+ return child;
};
for (const name of ["node:child_process", "child_process"])
mock.module(name, () => ({ ...childProcess, spawn: recordedSpawn }));
@@ -45,6 +51,7 @@ try {
const request = JSON.parse(line);
const requestCount = requests.length;
workerArgs = undefined;
+ workerProcess = undefined;
const result = await executor.run({
...request,
promptPath: process.argv[3],
@@ -56,6 +63,10 @@ try {
throw new Error("Native worker arguments were not captured");
if (requests.length === requestCount)
throw new Error("Worker completed without a synthetic Responses request");
+ // Turn completion can precede exec's exit. Release its SQLite handles before
+ // this fixture starts a separate app-server against the same Codex home.
+ if (workerProcess.exitCode === null && workerProcess.signalCode === null)
+ await once(workerProcess, "exit");
const config = await readDeepScanRuntimeConfig({
codexPath: process.env.CODEX_CLI_PATH,
cwd: process.cwd(),
diff --git a/sdk/typescript/tests-ts/repository-findings.test.ts b/sdk/typescript/tests-ts/repository-findings.test.ts
index dbf4219be..4ea2981a7 100644
--- a/sdk/typescript/tests-ts/repository-findings.test.ts
+++ b/sdk/typescript/tests-ts/repository-findings.test.ts
@@ -66,7 +66,9 @@ print(json.dumps(result))
["-I", "-B", "-", join(PLUGIN_ROOT, "scripts")],
process.env,
probe,
- AbortSignal.timeout(10_000),
+ AbortSignal.timeout(
+ Number(process.env["CODEX_SECURITY_TEST_TIMEOUT_MS"] ?? "30000"),
+ ),
);
expect(execution.exitCode, execution.stderr).toBe(0);
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 58dac3346..b8f9b94b2 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -6274,6 +6274,51 @@ describe("runtime directories and plugin Python boundary", () => {
expect(result.stdout.trim()).toBe(python);
});
+ test("accepts Python when a cold interpreter starts after five seconds", () => {
+ const result = spawnSync(
+ process.execPath,
+ [
+ "-e",
+ `
+ import { expect, jest, mock } from "bun:test";
+ import * as childProcess from "node:child_process";
+ import { promisify } from "node:util";
+ const started = Promise.withResolvers();
+ const probe = () => {};
+ probe[promisify.custom] = (_command, _args, options) =>
+ new Promise((resolve, reject) => {
+ const timeout = setTimeout(() => {
+ clearTimeout(ready);
+ reject(new Error("Python startup timed out"));
+ }, options.timeout);
+ const ready = setTimeout(() => {
+ clearTimeout(timeout);
+ resolve({ stdout: "codex-security-python-ok\\n", stderr: "" });
+ }, 6_000);
+ started.resolve();
+ });
+ mock.module("node:child_process", () => ({ ...childProcess, execFile: probe }));
+ const { resolvePluginPython } = await import(process.argv[1]);
+ jest.useFakeTimers();
+ try {
+ const resolving = resolvePluginPython({ configuredPath: process.execPath }).then(
+ (value) => ({ value }),
+ (error) => ({ error }),
+ );
+ await started.promise;
+ jest.advanceTimersByTime(6_000);
+ expect(await resolving).toEqual({ value: process.execPath });
+ } finally {
+ jest.useRealTimers();
+ }
+ `,
+ fileURLToPath(new URL("../src/runtime.ts", import.meta.url)),
+ ],
+ { encoding: "utf8" },
+ );
+ expect(result.status, result.stderr).toBe(0);
+ });
+
testPosix("uses configured, inherited, and managed Python", async () => {
const root = await temporaryDirectory();
const configured = join(root, "configured-python");