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): isolate Windows launcher paths and verify hook arguments (#2387)

Michael D'Angelo5abe5f2a23b2
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index f1799aa36..b0a325afe 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -1350,12 +1350,33 @@ describe("CLI", () => {
code: "ENOENT",
});
expect(trustedHook).not.toMatch(/^exec\s+npx(?:\s|$)/m);
- expect(trustedHook).toContain(await realpath(process.execPath));
- expect(trustedHook).toContain(
+ // Let Git invoke the declared /bin/sh, including its bundled shell on Windows.
+ const displayArgs = trustedHook.replace(/^exec /m, "printf '%s\\0' ");
+ expect(displayArgs).not.toBe(trustedHook);
+ const decoded = await runCommand(
+ "git",
+ [
+ "-C",
+ root,
+ "-c",
+ "alias.report-hook-argv=!/bin/sh -s",
+ "report-hook-argv",
+ ],
+ { input: displayArgs, windowsHide: true },
+ );
+ expect(decoded.status, decoded.stderr).toBe(0);
+ expect(decoded.stdout.split("\0")).toEqual([
+ await realpath(process.execPath),
await realpath(
fileURLToPath(new URL("../src/cli.ts", import.meta.url)),
),
- );
+ "scan",
+ ".",
+ "--working-tree",
+ "--fail-on-severity",
+ "medium",
+ "",
+ ]);
} finally {
await rm(root, { recursive: true, force: true });
}
diff --git a/sdk/typescript/tests-ts/mcp-launcher.test.ts b/sdk/typescript/tests-ts/mcp-launcher.test.ts
index 156a8bc1e..9368b39d1 100644
--- a/sdk/typescript/tests-ts/mcp-launcher.test.ts
+++ b/sdk/typescript/tests-ts/mcp-launcher.test.ts
@@ -26,6 +26,13 @@ test.skipIf(process.platform !== "win32")(
);
try {
const caller = join(root, "caller");
+ const launcherEnv = {
+ SystemRoot: process.env["SystemRoot"],
+ HOME: root,
+ USERPROFILE: root,
+ LOCALAPPDATA: root,
+ XDG_CACHE_HOME: root,
+ };
const runtime = join(root, "Node runtime");
const scripts = join(root, "plugin", "scripts");
const server = join(root, "plugin", "mcp", "server.mjs");
@@ -67,7 +74,7 @@ test.skipIf(process.platform !== "win32")(
{
cwd: caller,
env: {
- SystemRoot: process.env["SystemRoot"],
+ ...launcherEnv,
PATH: path,
PATHEXT: ".CMD;.EXE;.BAT;.COM",
},
@@ -95,7 +102,7 @@ test.skipIf(process.platform !== "win32")(
{
cwd: caller,
env: {
- SystemRoot: process.env["SystemRoot"],
+ ...launcherEnv,
PATH: ";.;relative-bin;",
},
encoding: "utf8",