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(ci): wait for Windows sandbox fixture setup (#1799)
Michael D'Angelof49e018990f0
diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex 63611c437..126f5c7cd 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -1,4 +1,4 @@-import { mkdir, readFile, stat, writeFile } from "node:fs/promises";+import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";import { join, resolve } from "node:path";import { afterEach, describe, expect, test } from "bun:test";import { parse } from "smol-toml";@@ -32,7 +32,15 @@ const { temporaryDirectory, cleanup } = createApiTestFixtures(false,);-afterEach(cleanup);+let sandboxFixtureUsed = false;++afterEach(async () => {+ if (sandboxFixtureUsed) {+ await waitForWindowsSandboxSetup();+ sandboxFixtureUsed = false;+ }+ await cleanup();+});test("inline Codex overrides preserve literal keys and string values", () => {const metadata = {@@ -146,7 +154,63 @@ function macOsSandboxUnavailable(): boolean {);}+async function sandboxFailureDetails(codexHome: string, details: string) {+ if (process.platform !== "win32") return details;+ const directory = join(codexHome, ".sandbox");+ try {+ for (const name of (await readdir(directory)).sort()) {+ if (/^sandbox\.\d{4}-\d{2}-\d{2}\.log$/u.test(name)) {+ details += `\n${name}:\n${await readFile(join(directory, name), "utf8")}`;+ }+ }+ } catch (error) {+ details += `\nCould not read native sandbox logs: ${String(error)}`;+ }+ return details;+}++async function waitForWindowsSandboxSetup() {+ if (process.platform !== "win32") return;++ // Codex applies read ACLs in a background worker shared across Codex homes.+ // Finish that work before deleting its fixture or creating another workspace.+ const result = Bun.spawnSync(+ [+ join(+ process.env["SystemRoot"] ?? "C:\\Windows",+ "System32",+ "WindowsPowerShell",+ "v1.0",+ "powershell.exe",+ ),+ "-NoLogo",+ "-NoProfile",+ "-NonInteractive",+ "-Command",+ `+$ErrorActionPreference = 'Stop'+try {+ $mutex = [System.Threading.Mutex]::OpenExisting('Local\\CodexSandboxReadAcl')+} catch [System.Threading.WaitHandleCannotBeOpenedException] {+ exit 0+}+try {+ if (-not $mutex.WaitOne(30000)) {+ throw 'Codex sandbox read ACL setup did not finish within 30 seconds'+ }+ $mutex.ReleaseMutex()+} finally {+ $mutex.Dispose()+}`,+ ],+ { stdout: "pipe", stderr: "pipe" },+ );+ expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);+}+async function scanSandboxFixture() {+ await waitForWindowsSandboxSetup();+ sandboxFixtureUsed = true;const root = await temporaryDirectory();const stateDirectory = join(root, "state");const codexHome = await prepareCodexSecurityCredentialHome({@@ -583,7 +647,7 @@ describe("Codex configuration", () => {return;}throw new Error(- `The pinned Codex CLI rejected an allowed scan write: ${details}`,+ `The pinned Codex CLI rejected an allowed scan write: ${await sandboxFailureDetails(codexHome, details)}`,);}expect(await readFile(allowed, "utf8")).toBe("probe");@@ -751,7 +815,7 @@ describe("Codex configuration", () => {return;}throw new Error(- `The pinned Codex CLI rejected an allowed policy read: ${details}`,+ `The pinned Codex CLI rejected an allowed policy read: ${await sandboxFailureDetails(codexHome, details)}`,);}expect(new TextDecoder().decode(read.stdout)).toBe("original");