OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
test(windows): reserve native sandbox setup for hosted or opted-in SDK tests (#2401)
Michael D'Angelo25ce2c80bd5d
diff --git a/sdk/typescript/TESTING.md b/sdk/typescript/TESTING.mdindex 61b30f536..68c2ccaa9 100644--- a/sdk/typescript/TESTING.md+++ b/sdk/typescript/TESTING.md@@ -22,6 +22,17 @@ bun test --timeout 30000 ./tests-ts/worker-progress.test.tsFor an MCP change, follow the [MCP test guide](../../plugins/codex-security/mcp-app/TESTING.md). To see which suites this repository requires for a PR, see [How this repository tests pull requests](../../docs/ci.md).+### Native Windows sandbox tests++Two tests in `tests-ts/config.test.ts` start the real Codex sandbox to check+workspace writes and policy-source reads. Sandbox setup can change machine-wide+Windows state. These tests run by default on GitHub-hosted Windows Actions+runners. To include them in a local or self-hosted PowerShell run, set+`$env:CODEX_SECURITY_TEST_WINDOWS_SANDBOX = '1'` before running Bun. The value+`true` also enables them. Set the variable to `0` or `false` to skip both, even+on a hosted runner. The PowerShell machine-policy test has its own+`CODEX_SECURITY_ALLOW_MACHINE_POLICY_TEST` setting.+## Check the packageRun static checks, the MCP suite and the SDK suite after installing the dependencies and native payload:diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex 2670f2509..2d265c1d5 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -176,6 +176,70 @@ function macOsSandboxUnavailable(): boolean {);}+function shouldScheduleNativeSandboxTests(+ platform: NodeJS.Platform,+ environment: NodeJS.ProcessEnv,+): boolean {+ if (platform !== "win32") return true;+ const setting =+ environment["CODEX_SECURITY_TEST_WINDOWS_SANDBOX"]?.toLowerCase();+ if (setting === "1" || setting === "true") return true;+ if (setting === "0" || setting === "false") return false;+ return (+ environment["GITHUB_ACTIONS"] === "true" &&+ environment["RUNNER_ENVIRONMENT"] === "github-hosted"+ );+}++const skipNativeSandboxTests =+ !shouldScheduleNativeSandboxTests(process.platform, process.env) ||+ macOsSandboxUnavailable();++describe("native sandbox test scheduling", () => {+ const local = { CODEX_SECURITY_ALLOW_MACHINE_POLICY_TEST: "false" };+ const hosted = {+ ...local,+ GITHUB_ACTIONS: "true",+ RUNNER_ENVIRONMENT: "github-hosted",+ };+ const setting = "CODEX_SECURITY_TEST_WINDOWS_SANDBOX";+ const onWindows = (env: NodeJS.ProcessEnv) =>+ shouldScheduleNativeSandboxTests("win32", env);++ test("defaults Windows coverage to GitHub-hosted Actions runners", () => {+ expect(onWindows(local)).toBe(false);+ expect(onWindows(hosted)).toBe(true);+ expect(onWindows({ ...hosted, [setting]: "" })).toBe(true);+ expect(onWindows({ RUNNER_ENVIRONMENT: "github-hosted" })).toBe(false);+ expect(onWindows({ ...hosted, RUNNER_ENVIRONMENT: "self-hosted" })).toBe(+ false,+ );+ });++ test.each(["1", "true", "True"])(+ "opts into local Windows coverage with %s",+ (value) => {+ expect(onWindows({ ...local, [setting]: value })).toBe(true);+ },+ );++ test.each(["0", "false"])(+ "opts out of hosted Windows coverage with %s",+ (value) => {+ expect(onWindows({ ...hosted, [setting]: value })).toBe(false);+ },+ );++ test.each(["darwin", "linux"] as const)(+ "ignores the Windows setting on %s",+ (platform) => {+ expect(+ shouldScheduleNativeSandboxTests(platform, { [setting]: "false" }),+ ).toBe(true);+ },+ );+});+async function sandboxFailureDetails(codexHome: string, details: string) {if (process.platform !== "win32") return details;const directory = join(codexHome, ".sandbox");@@ -1015,7 +1079,7 @@ describe("Codex configuration", () => {expect(result.stdout.length).toBeGreaterThan(0);});- test.skipIf(macOsSandboxUnavailable())(+ test.skipIf(skipNativeSandboxTests)("allows scan helpers to write workspace files without writable credential ancestry",async () => {const { root, codexHome, stateDirectory, workspace, environment } =@@ -1109,7 +1173,7 @@ describe("Codex configuration", () => {},);- test.skipIf(macOsSandboxUnavailable())(+ test.skipIf(skipNativeSandboxTests)("reads policy source without exposing credentials or changing host files",async () => {const { root, codexHome, workspace, stateDirectory, environment } =