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: reuse the asynchronous archive checker across package fixtures (#1936)
Michael D'Angeloa726c1d88acf
diff --git a/sdk/typescript/tests-ts/package-tar-listing.test.ts b/sdk/typescript/tests-ts/package-tar-listing.test.tsindex eb23566a3..2f22f41ad 100644--- a/sdk/typescript/tests-ts/package-tar-listing.test.ts+++ b/sdk/typescript/tests-ts/package-tar-listing.test.ts@@ -248,7 +248,7 @@ function checkPackage(root: string,archivePath: string,contractPath: string,- environment: NodeJS.ProcessEnv,+ environment: NodeJS.ProcessEnv = process.env,): Promise<{ status: number; stderr: string }> {return runPackageCommand(root,@@ -348,7 +348,7 @@ describe("npm package tar listings", () => {test.each([false, true])("rejects invalid package paths before Brotli expansion, complete=%p",- (complete) => {+ async (complete) => {const root = mkdtempSync(join(tmpdir(), "codex-package-path-order-"));try {const archivePath = join(root, "unexpected-brotli.tgz");@@ -365,17 +365,7 @@ describe("npm package tar listings", () => {);const contractPath = join(root, "plugin contract.json");writeFileSync(contractPath, JSON.stringify(pluginContract));- const result = spawnSync(- commandPath("node"),- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- { cwd: root, encoding: "utf8", timeout: 30_000, windowsHide: true },- );+ const result = await checkPackage(root, archivePath, contractPath);expect(result.status).toBe(1);expect(result.stderr).toContain(complete@@ -388,7 +378,7 @@ describe("npm package tar listings", () => {},);- test("escapes terminal controls in unexpected archive path diagnostics", () => {+ test("escapes terminal controls in unexpected archive path diagnostics", async () => {const root = mkdtempSync(join(tmpdir(), "codex-package-terminal-path-"));try {const archivePath = join(root, "unexpected-path.tgz");@@ -405,17 +395,7 @@ describe("npm package tar listings", () => {);const contractPath = join(root, "plugin contract.json");writeFileSync(contractPath, JSON.stringify(pluginContract));- const result = spawnSync(- commandPath("node"),- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- { cwd: root, encoding: "utf8", timeout: 30_000, windowsHide: true },- );+ const result = await checkPackage(root, archivePath, contractPath);expect(result.status).toBe(1);expect(result.stderr).toContain("unexpected file: package/unexpected");expect(result.stderr).not.toMatch(/[\u001b\u0007\u009b]/u);@@ -425,7 +405,7 @@ describe("npm package tar listings", () => {}});- test("accepts equivalent bounded gzip representations", () => {+ test("accepts equivalent bounded gzip representations", async () => {const root = mkdtempSync(join(tmpdir(), "codex-package-gzip-test-"));try {const tarBytes = packageTar({ trailingZeroBytes: 31 * 1024 * 1024 });@@ -472,22 +452,11 @@ describe("npm package tar listings", () => {for (const [representation, contents] of archives) {const archivePath = join(root, `${representation}.tgz`);writeFileSync(archivePath, contents);- const result = spawnSync(- commandPath("node"),- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- {- cwd: root,- encoding: "utf8",- env: environment,- timeout: 30_000,- windowsHide: true,- },+ const result = await checkPackage(+ root,+ archivePath,+ contractPath,+ environment,);expect({representation,@@ -908,7 +877,7 @@ describe("npm package tar listings", () => {}});- test("checks reconstructed sparse binary assets and their discarded metadata", () => {+ test("checks reconstructed sparse binary assets and their discarded metadata", async () => {const root = mkdtempSync(join(tmpdir(), "codex-package-sparse-assets-"));try {const logo = readFileSync(@@ -1263,22 +1232,11 @@ describe("npm package tar listings", () => {);const environment = { ...process.env };delete environment["CODEX_SECURITY_EXPECTED_GIT_HEAD"];- const result = spawnSync(- commandPath("node"),- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- {- cwd: root,- env: environment,- encoding: "utf8",- timeout: 30_000,- windowsHide: true,- },+ const result = await checkPackage(+ root,+ archivePath,+ contractPath,+ environment,);if (scenario.error) {expect({ scenario: scenario.name, status: result.status }).toEqual({@@ -1303,7 +1261,7 @@ describe("npm package tar listings", () => {test.each([0x78, 0x67])("preserves inherited character locale for Unicode pax owners, type=%i",- (type) => {+ async (type) => {const root = mkdtempSync(join(tmpdir(), "codex-package-owner-test-"));try {const archivePath = join(root, "unicode owner.tgz");@@ -1329,22 +1287,11 @@ describe("npm package tar listings", () => {if (process.platform !== "win32")environment["LC_ALL"] =process.platform === "darwin" ? "en_US.UTF-8" : "C.UTF-8";- const result = spawnSync(- commandPath("node"),- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- {- cwd: root,- env: environment,- encoding: "utf8",- timeout: 30_000,- windowsHide: true,- },+ const result = await checkPackage(+ root,+ archivePath,+ contractPath,+ environment,);expect({ status: result.status, stderr: result.stderr }).toEqual({status: 0,@@ -1356,7 +1303,7 @@ describe("npm package tar listings", () => {},);- test("streams each archive without resolving tar from its directory", () => {+ test("streams each archive without resolving tar from its directory", async () => {const root = mkdtempSync(join(tmpdir(), "codex-package-tar-test-"));try {const archiveDirectory = join(@@ -1382,7 +1329,6 @@ describe("npm package tar listings", () => {writeFileSync(archivePath, archiveContents);writeFileSync(contractPath, JSON.stringify(pluginContract));- const nodePath = commandPath("node");const environment: NodeJS.ProcessEnv = { ...process.env };delete environment["CODEX_SECURITY_EXPECTED_GIT_HEAD"];environment["PATH"] = `.${delimiter}${process.env["PATH"] ?? ""}`;@@ -1441,22 +1387,11 @@ process.exit(result.status ?? 1);environment["TAR_PROXY_LOG"] = logPath;}- const result = spawnSync(- nodePath,- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- {- cwd: root,- encoding: "utf8",- env: environment,- timeout: 30_000,- windowsHide: true,- },+ const result = await checkPackage(+ root,+ archivePath,+ contractPath,+ environment,);expect(existsSync(adjacentTarMarker)).toBe(false);expect({ status: result.status, stderr: result.stderr }).toEqual({@@ -1510,22 +1445,11 @@ process.exit(result.status ?? 1);]);environment["TAR_PROXY_FAIL_EXTRACT"] = "true";- const failed = spawnSync(- nodePath,- [- fileURLToPath(- new URL("../scripts/check-package.mjs", import.meta.url),- ),- archivePath,- contractPath,- ],- {- cwd: root,- encoding: "utf8",- env: environment,- timeout: 30_000,- windowsHide: true,- },+ const failed = await checkPackage(+ root,+ archivePath,+ contractPath,+ environment,);expect(failed.status).not.toBe(0);expect(failed.stderr).toContain("synthetic extraction failure");