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(windows): use the working interpreter in SDK runtime fixtures (#2513)

Michael D'Angelo05ddd1924221
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index eef10dc88..02d5b409f 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -1,4 +1,5 @@
-import { runNodePython } from "./support/python-probe.js";
+import { execNodePython, runNodePython } from "./support/python-probe.js";
+import { useTestPython } from "./support/python.js";
import { nodeCommand } from "./support/shell.js";
import { scanRegistrationArguments } from "./support/workbench-command.js";
import {
@@ -119,6 +120,11 @@ import { mockFs, restoreFs } from "./support/module-mocks.js";
const { temporaryDirectory, cleanup, temporaryDirectories } =
createApiTestFixtures("codex-security-runtime-");
+const pythonWithLauncher = useTestPython(false);
+const pythonOnPath =
+ process.platform === "win32"
+ ? pythonWithLauncher
+ : () => Bun.which("python3") ?? Bun.which("python");
const testPosix = process.platform === "win32" ? test.skip : test;
const restoreSpawn = (spawn: typeof childProcess.spawn) =>
mock.module("node:child_process", () => ({ ...childProcess, spawn }));
@@ -530,7 +536,7 @@ describe("plugin runtime preparation", () => {
);
test("preserves remediation when the filesystem device changes", async () => {
- const python = Bun.which("python3") ?? Bun.which("python");
+ const python = pythonOnPath();
expect(python).not.toBeNull();
const target = await temporaryDirectory("codex-security-remounted-target-");
const verification = runNodePython(python!, [
@@ -6027,7 +6033,7 @@ describe("runtime directories and plugin Python boundary", () => {
await mkdir(stateDirectory);
await mkdir(scanDirectory, { mode: 0o700 });
- const python = Bun.which("python3") ?? Bun.which("python");
+ const python = pythonOnPath();
expect(python).not.toBeNull();
const fixture = runNodePython(python!, [
"-c",
@@ -6142,7 +6148,7 @@ describe("runtime directories and plugin Python boundary", () => {
] as const)(
"rejects recipe scans when the agent did not create %s",
async (_description, present) => {
- const python = Bun.which("python3") ?? Bun.which("python");
+ const python = pythonOnPath();
expect(python).not.toBeNull();
const requiredDrafts = ["scan-manifest.json", "findings.json"] as const;
const root = await temporaryDirectory("codex-security-missing-drafts-");
@@ -6766,8 +6772,7 @@ describe("runtime directories and plugin Python boundary", () => {
});
test("resolves inherited Python names case-insensitively", async () => {
- const discovered =
- Bun.which("python3") ?? Bun.which("python") ?? Bun.which("py");
+ const discovered = pythonWithLauncher();
expect(discovered).not.toBeNull();
const interpreter = join(
await realpath(dirname(discovered!)),
@@ -7080,7 +7085,7 @@ describe("runtime directories and plugin Python boundary", () => {
test.skipIf(process.platform !== "win32")(
"uses a configured Windows Python path without the executable suffix",
async () => {
- const discovered = Bun.which("python3") ?? Bun.which("python");
+ const discovered = pythonOnPath();
expect(discovered).not.toBeNull();
if (discovered === null) return;
const python = await realpath(discovered);
@@ -7106,9 +7111,18 @@ describe("runtime directories and plugin Python boundary", () => {
async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
- const installedPython = process.env["PYTHON"] ?? Bun.which("python");
- expect(installedPython).not.toBeNull();
- if (installedPython === null) return;
+ let installedPython = process.env["PYTHON"];
+ if (installedPython === undefined) {
+ const command = pythonWithLauncher();
+ expect(command).not.toBeNull();
+ if (command === null) return;
+ // The Windows py launcher and the interpreter's DLLs can live in different directories.
+ installedPython = execNodePython(
+ command,
+ ["-X", "utf8", "-c", "import sys; print(sys.executable)"],
+ process.env,
+ ).trimEnd();
+ }
await mkdir(repository);
const launcher = join(root, "py.exe");
await copyFile(installedPython, launcher);
diff --git a/sdk/typescript/tests-ts/scan-resume.test.ts b/sdk/typescript/tests-ts/scan-resume.test.ts
index c1a873b50..a6f6811e2 100644
--- a/sdk/typescript/tests-ts/scan-resume.test.ts
+++ b/sdk/typescript/tests-ts/scan-resume.test.ts
@@ -32,6 +32,7 @@ import {
readOperationTelemetry,
} from "../src/operation-telemetry.js";
import { capture, dependencies } from "./cli-fixtures.js";
+import { useTestPython } from "./support/python.js";
import { runPython } from "./support/python-probe.js";
import { copyCompletedScanFixture, PLUGIN_ROOT } from "./plugin-root.js";
import { TestClient } from "./support/api-client.js";
@@ -40,6 +41,10 @@ import { createApiTestFixtures } from "./support/temporary-directories.js";
import { fail } from "./support/errors.js";
const { temporaryDirectory, cleanup } = createApiTestFixtures();
+const pythonOnPath =
+ process.platform === "win32"
+ ? useTestPython(false)
+ : () => Bun.which("python3") ?? Bun.which("python");
afterEach(cleanup);
async function interruptedScan(
@@ -134,7 +139,7 @@ async function interruptedScan(
}) + "\n",
);
}
- const python = Bun.which("python3") ?? Bun.which("python");
+ const python = pythonOnPath();
if (python === null) throw new Error("Python is required for this test.");
const environment = {
PATH: process.env["PATH"],
@@ -1252,7 +1257,7 @@ test.each(["chatgpt", "api-key"] as const)(
const promptFile = join(root, "post-scan.md");
const postScanPrompt = "Keep these original post-scan instructions.\n";
await writeFile(promptFile, postScanPrompt);
- const python = Bun.which("python3") ?? Bun.which("python");
+ const python = pythonOnPath();
if (python === null) throw new Error("Python is required for this test.");
const environment = {
PATH: process.env["PATH"],