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: split Windows CI and test the installed package (#1102)
mldangelo-oai688e2aee6290
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex 4120d73ce..d202a9a0a 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -324,7 +324,6 @@ jobs:sudo apt-get updatesudo apt-get install --yes ripgrep- name: Test- timeout-minutes: 10working-directory: sdk/typescriptenv:TEMP: ${{ runner.temp }}@@ -600,7 +599,6 @@ jobs:shell: pwshrun: ./sdk/typescript/scripts/prepare-windows-test-root.ps1- name: Test shard ${{ matrix.shard }}- timeout-minutes: 10env:TEMP: ${{ steps.windows-temp.outputs.path }}TMP: ${{ steps.windows-temp.outputs.path }}diff --git a/.github/workflows/test-quality.yml b/.github/workflows/test-quality.ymlindex 97daad9cb..2981492b7 100644--- a/.github/workflows/test-quality.yml+++ b/.github/workflows/test-quality.yml@@ -32,7 +32,7 @@ jobs:if: ${{ !cancelled() && (inputs.native-artifacts-ready || needs.native.result == 'success') }}name: ${{ matrix.os }} / ${{ matrix.mode }}runs-on: ${{ matrix.os }}- timeout-minutes: ${{ matrix.os == 'windows-latest' && (matrix.mode == 'baseline' || matrix.mode == 'isolated') && 45 || 30 }}+ timeout-minutes: ${{ matrix.os == 'windows-latest' && (matrix.mode == 'baseline' && 60 || matrix.mode == 'parallel' && 45) || 30 }}env:CODEX_SECURITY_PROPERTY_SEED: ${{ github.event_name == 'pull_request' && 1 || github.run_number }}strategy:@@ -40,6 +40,9 @@ jobs:matrix:os: [ubuntu-latest, windows-latest]mode: [baseline, isolated, parallel]+ exclude:+ - os: windows-latest+ mode: isolatedinclude:- mode: baselineargs: ""@@ -47,6 +50,27 @@ jobs:args: --isolate- mode: parallelargs: --parallel=2+ - os: windows-latest+ mode: isolated-1+ args: --isolate --shard=1/7+ - os: windows-latest+ mode: isolated-2+ args: --isolate --shard=2/7+ - os: windows-latest+ mode: isolated-3+ args: --isolate --shard=3/7+ - os: windows-latest+ mode: isolated-4+ args: --isolate --shard=4/7+ - os: windows-latest+ mode: isolated-5+ args: --isolate --shard=5/7+ - os: windows-latest+ mode: isolated-6+ args: --isolate --shard=6/7+ - os: windows-latest+ mode: isolated-7+ args: --isolate --shard=7/7- os: windows-latestmode: shard-1args: --shard=1/7@@ -92,7 +116,7 @@ jobs:plugins/codex-security/mcp-app/pnpm-lock.yaml- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2with:- bun-version: "1.3.13"+ bun-version: "1.4.2"- name: Install dependenciesrun: |pnpm --dir sdk/typescript install --frozen-lockfile@@ -104,6 +128,7 @@ jobs:run: ./sdk/typescript/scripts/prepare-windows-test-root.ps1- name: Test runner modeenv:+ CODEX_SECURITY_TEST_TIMEOUT_MS: ${{ runner.os == 'Windows' && '120000' || '30000' }}TEMP: ${{ steps.windows-temp.outputs.path || runner.temp }}TMP: ${{ steps.windows-temp.outputs.path || runner.temp }}TMPDIR: ${{ steps.windows-temp.outputs.path || runner.temp }}@@ -152,7 +177,7 @@ jobs:comparison_status=0for os in ubuntu-latest windows-latest; dofor mode in isolated parallel; do- node sdk/typescript/scripts/compare-test-reports.mjs "reports/runner-$os-baseline.xml" "reports/runner-$os-$mode.xml" >> "$GITHUB_STEP_SUMMARY" || comparison_status=1+ node sdk/typescript/scripts/compare-test-reports.mjs "reports/runner-$os-baseline.xml" "reports/runner-$os-$mode*.xml" >> "$GITHUB_STEP_SUMMARY" || comparison_status=1donedonenode sdk/typescript/scripts/compare-test-reports.mjs reports/runner-windows-latest-baseline.xml 'reports/runner-windows-latest-shard-*.xml' >> "$GITHUB_STEP_SUMMARY" || comparison_status=1diff --git a/sdk/typescript/scripts/check-package.mjs b/sdk/typescript/scripts/check-package.mjsindex 3c520c5e9..629e89096 100644--- a/sdk/typescript/scripts/check-package.mjs+++ b/sdk/typescript/scripts/check-package.mjs@@ -2,7 +2,11 @@ import { spawnSync } from "node:child_process";import { createHash } from "node:crypto";import { readFileSync } from "node:fs";import { fileURLToPath } from "node:url";-import { brotliDecompressSync, gunzipSync } from "node:zlib";+import { gunzipSync } from "node:zlib";+import {+ assertPublicPackageContents,+ MAX_EXPANDED_ASSET_BYTES,+} from "./package-public-content.mjs";import { assertExpectedGitHead } from "./package-provenance.mjs";import { packageSmokeTimeouts } from "./package-smoke-timeouts.mjs";import { regularTarListingLines } from "./package-tar-listing.mjs";@@ -25,7 +29,6 @@ if (archive === undefined || args.length > 2) {);}-const MAX_EXPANDED_ASSET_BYTES = 32 * 1024 * 1024;const archiveBytes = gunzipSync(readFileSync(archive), {maxOutputLength: MAX_EXPANDED_ASSET_BYTES,});@@ -49,9 +52,11 @@ function tar(args, encoding = "buffer") {let offset = 0;const archiveFiles = new Map();+const archiveMetadata = [];for (; offset + 512 <= archiveBytes.byteLength;) {const header = archiveBytes.subarray(offset, offset + 512);if (header.every((byte) => byte === 0)) {+ archiveMetadata.push(header);offset += 512;continue;}@@ -80,6 +85,12 @@ for (; offset + 512 <= archiveBytes.byteLength;) {path,archiveBytes.subarray(contentsStart, contentsStart + size),);+ archiveMetadata.push(+ header,+ archiveBytes.subarray(contentsStart + size, nextOffset),+ );+ } else {+ archiveMetadata.push(archiveBytes.subarray(offset, nextOffset));}offset = nextOffset;}@@ -336,40 +347,6 @@ assertExpectedGitHead(process.env.CODEX_SECURITY_EXPECTED_GIT_HEAD,);-const internalMarker =- /(?:internal\.api\.openai\.org|gateway\.[a-z0-9.-]*internal|\.openai\.org|openai\.firewall\.socket\.dev|socket\x2dfirewall\x2dregistry|openai\.(?:enterprise\.)?slack\.com|app\.slack\.com\/client|(?:app\.notion\.com\/p|notion\.so)\/openai|linear\.app\/openai|(?:github\.com[:/]|api\.github\.com\/repos\/|raw\.githubusercontent\.com\/)openai\/openai(?:\.git)?(?:[^a-z0-9_-]|$)|LicenseRef\x2dProprietary|\/Users\/|\/home\/dev-user|flow\.apps\.openai\.org|(?:^|[^a-z0-9_-])go\/[a-z0-9_-]+)/iu;--const payloads = [archiveBytes.toString("utf8")];-const compressedFiles = [...files].filter((file) => /\.br$/iu.test(file));-const compressedParts = new Map();-for (const file of files) {- const match = /^(.*\.br)\.part-([0-9]+)$/iu.exec(file);- if (match === null) continue;- const [, name, part] = match;- const parts = compressedParts.get(name) ?? [];- parts.push({ file, part: Number(part) });- compressedParts.set(name, parts);-}--function brotliPayload(bytes, file) {- const result = brotliDecompressSync(bytes, {- info: true,- maxOutputLength: MAX_EXPANDED_ASSET_BYTES,- });- if (result.engine.bytesWritten !== bytes.length) {- throw new Error(`npm tarball contains trailing Brotli data: ${file}.`);- }- return result.buffer;-}--for (const file of compressedFiles) {- payloads.push(brotliPayload(archiveFile(file), file).toString("utf8"));-}-for (const parts of compressedParts.values()) {- parts.sort((left, right) => left.part - right.part);- const bytes = Buffer.concat(parts.map(({ file }) => archiveFile(file)));- payloads.push(brotliPayload(bytes, parts[0].file).toString("utf8"));-}for (const file of files) {if (/\.png$/iu.test(file)) {const digest = createHash("sha256").update(archiveFile(file)).digest("hex");@@ -379,11 +356,7 @@ for (const file of files) {}}-for (const contents of payloads) {- if (internalMarker.test(contents)) {- throw new Error("npm tarball contains an internal reference.");- }-}+assertPublicPackageContents(archiveFiles, Buffer.concat(archiveMetadata));if (args.length === 1) {const smoke = spawnSync(diff --git a/sdk/typescript/scripts/package-public-content.mjs b/sdk/typescript/scripts/package-public-content.mjsnew file mode 100644index 000000000..5c65ce6f4--- /dev/null+++ b/sdk/typescript/scripts/package-public-content.mjs@@ -0,0 +1,52 @@+import { brotliDecompressSync } from "node:zlib";++export const MAX_EXPANDED_ASSET_BYTES = 32 * 1024 * 1024;++const internalMarker =+ /(?:internal\.api\.openai\.org|gateway\.[a-z0-9.-]*internal|\.openai\.org|openai\.firewall\.socket\.dev|socket\x2dfirewall\x2dregistry|openai\.(?:enterprise\.)?slack\.com|app\.slack\.com\/client|(?:app\.notion\.com\/p|notion\.so)\/openai|linear\.app\/openai|(?:github\.com[:/]|api\.github\.com\/repos\/|raw\.githubusercontent\.com\/)openai\/openai(?:\.git)?(?:[^a-z0-9_-]|$)|LicenseRef\x2dProprietary|\/Users\/|\/home\/dev-user|flow\.apps\.openai\.org|(?:^|[^a-z0-9_-])go\/[a-z0-9_-]+)/iu;++export function assertPublicPackageContents(+ archiveFiles,+ archiveMetadata = Buffer.alloc(0),+) {+ assertPublicText(archiveMetadata.toString("utf8"));+ const compressedParts = new Map();+ for (const [path, bytes] of archiveFiles) {+ assertPublicText(path);+ const part = /^(.*\.br)\.part-([0-9]+)$/iu.exec(path);+ if (part !== null) {+ const [, name, index] = part;+ const parts = compressedParts.get(name) ?? [];+ parts.push({ path, index: Number(index), bytes });+ compressedParts.set(name, parts);+ } else if (/\.br$/iu.test(path)) {+ assertPublicBrotli(bytes, path);+ } else {+ assertPublicText(bytes.toString("utf8"));+ }+ }+ for (const parts of compressedParts.values()) {+ parts.sort((left, right) => left.index - right.index);+ assertPublicBrotli(+ Buffer.concat(parts.map(({ bytes }) => bytes)),+ parts[0].path,+ );+ }+}++function assertPublicBrotli(bytes, path) {+ const result = brotliDecompressSync(bytes, {+ info: true,+ maxOutputLength: MAX_EXPANDED_ASSET_BYTES,+ });+ if (result.engine.bytesWritten !== bytes.length) {+ throw new Error(`npm tarball contains trailing Brotli data: ${path}.`);+ }+ assertPublicText(result.buffer.toString("utf8"));+}++function assertPublicText(contents) {+ if (internalMarker.test(contents)) {+ throw new Error("npm tarball contains an internal reference.");+ }+}diff --git a/sdk/typescript/scripts/smoke-package.mjs b/sdk/typescript/scripts/smoke-package.mjsindex 22026d83a..b610435b7 100644--- a/sdk/typescript/scripts/smoke-package.mjs+++ b/sdk/typescript/scripts/smoke-package.mjs@@ -487,8 +487,17 @@ try {"npm must create the published codex-security executable shim.",);+ const launchEnvironment = {+ ...process.env,+ NODE_OPTIONS: "--preserve-symlinks-main --no-experimental-detect-module",+ NODE_USE_ENV_PROXY: undefined,+ };function runInstalledCli(argument) {- const options = { cwd: consumer, capture: true };+ const options = {+ cwd: consumer,+ capture: true,+ env: launchEnvironment,+ };if (process.platform === "win32") {return run(process.env.ComSpec ?? "cmd.exe",@@ -503,6 +512,41 @@ try {const version = runInstalledCli("--version");assert.equal(version.trim(), packageManifest.version);+ const preload = join(consumer, "unavailable-cwd.mjs");+ await writeFile(+ preload,+ [+ "const originalCwd = process.cwd;",+ 'Object.defineProperty(process, "cwd", {',+ " value() {",+ ' if (/[\\\\/]dist[\\\\/]cli\\.js:/u.test(new Error().stack ?? "")) {',+ ' throw new Error("working directory is unavailable");',+ " }",+ " return originalCwd.call(process);",+ " },",+ "});\n",+ ].join("\n"),+ );+ const failed = spawnSync(+ process.execPath,+ [+ "--import",+ pathToFileURL(preload).href,+ process.platform === "win32" ? launcher : shim,+ "scan",+ ],+ {+ cwd: consumer,+ env: launchEnvironment,+ encoding: "utf8",+ timeout: PACKAGE_SMOKE_TIMEOUT_MS,+ windowsHide: true,+ },+ );+ assert.equal(failed.status, 2, failed.stderr);+ assert.equal(failed.stdout, "");+ assert.equal(failed.stderr, "working directory is unavailable\n");+const help = runInstalledCli("--help");assert.match(help, /Usage: codex-security\b/u);assert.match(help, /\bpublish\b/u);diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.tsindex e28075492..002fea5a9 100644--- a/sdk/typescript/src/runtime.ts+++ b/sdk/typescript/src/runtime.ts@@ -41,7 +41,6 @@ import {sep,win32,} from "node:path";-import { createInterface } from "node:readline";import { fileURLToPath } from "node:url";import { promisify } from "node:util";import { pipeline } from "node:stream/promises";@@ -739,13 +738,21 @@ export async function streamWindowsCredentialAclDescriptors(await Promise.all([completion,(async () => {- const lines = createInterface({- input: child.stdout,- crlfDelay: Infinity,- });- for await (const descriptor of lines) {- if (descriptor === "") continue;- await inspectDescriptor(descriptor);+ // Consume chunks directly: readline can resume its queued-line+ // iterator after EOF and throw instead of draining the last lines.+ child.stdout.setEncoding("utf8");+ let pending = "";+ for await (const chunk of child.stdout) {+ const lines = (pending + chunk).split(/[\r\n]/u);+ pending = lines.pop()!;+ for (const descriptor of lines) {+ if (descriptor === "") continue;+ await inspectDescriptor(descriptor);+ descriptors += 1;+ }+ }+ if (pending !== "") {+ await inspectDescriptor(pending);descriptors += 1;}})(),diff --git a/sdk/typescript/tests-ts/cli-launcher.test.ts b/sdk/typescript/tests-ts/cli-launcher.test.tsindex 35acc1c53..9cc72797a 100644--- a/sdk/typescript/tests-ts/cli-launcher.test.ts+++ b/sdk/typescript/tests-ts/cli-launcher.test.ts@@ -2,14 +2,12 @@ import {copyFile,mkdir,mkdtemp,- readFile,rm,symlink,writeFile,} from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";-import { pathToFileURL } from "node:url";import { describe, expect, test } from "bun:test";import { VERSION } from "../src/index.js";import { SYNTHETIC_CREDENTIALS } from "./cli-fixtures.js";@@ -92,99 +90,4 @@ describe("CLI launcher", () => {await rm(root, { recursive: true, force: true });}});-- test("builds and runs emitted split TypeScript output from a clean installed npm-style bin when Node preserves main symlinks", async () => {- const root = await mkdtemp(join(tmpdir(), "codex-security-cli-node-bin-"));- try {- const installed = join(root, "node_modules", "@openai", "codex-security");- const dist = join(installed, "dist");- const build = await runCommand(- "node",- [- join(packageRoot, "node_modules", "typescript", "bin", "tsc"),- "--project",- join(packageRoot, "tsconfig.build.json"),- "--outDir",- dist,- ],- { cwd: packageRoot, timeout: 30_000 },- );- expect(build.status).toBe(0);- expect(build.stderr).toBe("");-- expect(await readFile(join(dist, "cli.js"), "utf8")).toContain(- 'from "./api.js"',- );-- const launcher = join(installed, "bin", "codex-security.mjs");- await mkdir(join(installed, "bin"), { recursive: true });- await copyFile(join(packageRoot, "bin", "codex-security.mjs"), launcher);- await copyFile(- join(packageRoot, "package.json"),- join(installed, "package.json"),- );- await symlink(- join(packageRoot, "node_modules"),- join(installed, "node_modules"),- process.platform === "win32" ? "junction" : "dir",- );-- const binDirectory = join(root, "node_modules", ".bin");- await mkdir(binDirectory, { recursive: true });- const bin =- process.platform === "win32"- ? launcher- : join(binDirectory, "codex-security");- if (process.platform !== "win32") {- await symlink(launcher, bin);- }-- const launchEnvironment = {- ...process.env,- NODE_OPTIONS:- "--preserve-symlinks-main --no-experimental-detect-module",- NODE_USE_ENV_PROXY: undefined,- };- const child = await runCommand("node", [bin, "--version"], {- env: launchEnvironment,- timeout: 30_000,- });-- expect(child.status).toBe(0);- expect(child.stderr).toBe("");- expect(child.stdout).toBe(`${VERSION}\n`);-- const preload = join(root, "unavailable-cwd.mjs");- await writeFile(- preload,- [- "const originalCwd = process.cwd;",- 'Object.defineProperty(process, "cwd", {',- " value() {",- ' if (/[\\\\/]dist[\\\\/]cli\\.js:/u.test(new Error().stack ?? "")) {',- ' throw new Error("working directory is unavailable");',- " }",- " return originalCwd.call(process);",- " },",- "});\n",- ].join("\n"),- );- const failed = await runCommand(- "node",- ["--import", pathToFileURL(preload).href, bin, "scan"],- {- env: launchEnvironment,- timeout: 30_000,- },- );-- expect([failed.status, failed.stdout, failed.stderr]).toEqual([- 2,- "",- "working directory is unavailable\n",- ]);- } finally {- await rm(root, { recursive: true, force: true });- }- }, 30_000);});diff --git a/sdk/typescript/tests-ts/cli-publish.test.ts b/sdk/typescript/tests-ts/cli-publish.test.tsindex 1e543da73..530810d3e 100644--- a/sdk/typescript/tests-ts/cli-publish.test.ts+++ b/sdk/typescript/tests-ts/cli-publish.test.ts@@ -1049,7 +1049,7 @@ describe("publish scan", () => {const created = [{...base,- issueIdentifier: "\u001B[31mSEC-400\u001B[0m\n\u009Fsafe",+ issueIdentifier: "\u001B[31mSEC-400\u001B[0m\nsafe\u009F",url: "javascript:alert(1)",},{@@ -1085,7 +1085,7 @@ describe("publish scan", () => {deps,),).toBe(0);- expect(stdout.text()).toContain(" SEC-400\n");+ expect(stdout.text()).toContain(" SEC-400 safe\n");for (const identifier of ["SEC-401", "SEC-402", "SEC-403", "SEC-404"]) {expect(stdout.text()).toContain(` ${identifier}\n`);}diff --git a/sdk/typescript/tests-ts/package-public-content.test.ts b/sdk/typescript/tests-ts/package-public-content.test.tsnew file mode 100644index 000000000..1b534df2d--- /dev/null+++ b/sdk/typescript/tests-ts/package-public-content.test.ts@@ -0,0 +1,96 @@+import { brotliCompressSync, brotliDecompressSync } from "node:zlib";+import { describe, expect, test } from "bun:test";++const { assertPublicPackageContents } = (await import(+ new URL("../scripts/package-public-content.mjs", import.meta.url).href+)) as {+ assertPublicPackageContents: (+ files: Map<string, Buffer>,+ archiveMetadata?: Buffer,+ ) => void;+};++// Synthetic alphanumeric text whose compressed bytes happen to contain " Go/w".+const cleanCompressedPayload = Buffer.from(+ "G/8DAGRwm7EiGn34sGFNRM5DuwB8/2zECGTx7hk1/DY6puqEJWJumAz3HfjBg7bx5FxwfFCafaN2of0Oi2uTSSE+wAYOJS4Ii53urIa5BOIkTbR5t2YJ4/UM6dWzXcEvk92TZNz/Y7hNVxjrsXKemVnN4i1pUOdQiCYQNLU7Dbh77pXyrGIWSl+X+L7DUfFR+4Rz3GF85xCbj1NuwlDfIWj42+ueic5NDX4bPXmp46fE8bTdpAUmMvt48x99pm2wlp+oKNvvcb64GT4i7F9zCJMIdfmc06UCn7Go4jQ1WI2P+e05ZbpsWoTkPXnAFULsyUtefeZ1d5nbvE2CDXV3eF7Hxc2KgtQQv8j/CIEd+9vG3REfGcJVIVMqjo1SKzOfADpWQYh3p18YFMyF6R4qOYzPB+zjBy/ZQiCaNm1LpVYdJ7XL0wXPjAVOzJU4zeSUvNFqQ0TeXFGat6ikPEii43FRFSx3aQi2HnWI3rBd1tts0LlTjIWUq8+agHu/mwmJ+jWxAF74Yvij4++fUTHxm8PvqXOK+3QpR82rAPZ+pyRgKX1Z9k9XHlVwNXzJCd5laKwKOWnAOF6vKnrqhZz4aw1VqEJ+1x/4+AM++Pw58PdlRKBjKoLl7DKgEBCGKsd5FF8XPQz9pC3MWj1UbdVa/jLl5M1iIfl9P44zgKV1TaG1LEjuS09t7e0UFSrgXI0BWvBuyNfEras635PJBiZuI8mX6s5yt5NkocDkATyMNP1BnW+wKyTzduIFbd2yV45t/t6ttd5y5FeAAKnT0Jjsmk3zbYdl12fpKKDUvs363EVzTjWEhNaoTC3ntUZKNlYzX74UMDogR28vd8vvJniJvfamegrjMcf3fviFr9caYVQH+bq/TpxK078VtU0Z5iah0E2+ttjzWXHi//ftzs9e+xArq7zohSgVrMpgsL2kjfl/zaltHiNmTgogtQI6gRiI1ICa3kimcK2a/gj0cTkCVwKywUt6xu1N2x2lPi7dk/pnx8/iSkdyphyFA4OQov+d8maitV0XwU9/NKTW048C",+ "base64",+);++function compressedFiles(bytes: Buffer, split: boolean): Map<string, Buffer> {+ if (!split) return new Map([["package/runtime.mjs.br", bytes]]);+ const middle = Math.floor(bytes.length / 2);+ return new Map([+ ["package/runtime.mjs.br.part-001", bytes.subarray(middle)],+ ["package/runtime.mjs.br.part-000", bytes.subarray(0, middle)],+ ]);+}++describe("npm package public contents", () => {+ test.each([false, true])(+ "accepts clean expanded contents despite compressed marker bytes (split: %p)",+ (split) => {+ expect(cleanCompressedPayload.toString("utf8")).toContain(" Go/w");+ expect(+ brotliDecompressSync(cleanCompressedPayload).toString("utf8"),+ ).toMatch(/^[A-Za-z0-9]+$/u);+ expect(() =>+ assertPublicPackageContents(+ compressedFiles(cleanCompressedPayload, split),+ ),+ ).not.toThrow();+ },+ );++ test.each([false, true])(+ "rejects a marker in expanded contents (split: %p)",+ (split) => {+ const bytes = brotliCompressSync(+ Buffer.from("See go/synthetic-reference."),+ );+ expect(() =>+ assertPublicPackageContents(compressedFiles(bytes, split)),+ ).toThrow("npm tarball contains an internal reference.");+ },+ );++ test.each([false, true])(+ "rejects trailing bytes after a valid Brotli stream (split: %p)",+ (split) => {+ const bytes = Buffer.concat([+ cleanCompressedPayload,+ Buffer.from("extra"),+ ]);+ expect(() =>+ assertPublicPackageContents(compressedFiles(bytes, split)),+ ).toThrow("npm tarball contains trailing Brotli data");+ },+ );++ test("checks tar metadata", () => {+ expect(() =>+ assertPublicPackageContents(new Map(), Buffer.from("go/synthetic-owner")),+ ).toThrow("npm tarball contains an internal reference.");+ });++ test("checks plaintext and public paths", () => {+ expect(() =>+ assertPublicPackageContents(+ new Map([["package/README.md", Buffer.from("Public documentation.")]]),+ ),+ ).not.toThrow();+ expect(() =>+ assertPublicPackageContents(+ new Map([+ ["package/README.md", Buffer.from("See go/synthetic-reference.")],+ ]),+ ),+ ).toThrow("npm tarball contains an internal reference.");+ expect(() =>+ assertPublicPackageContents(+ new Map([+ ["package/go/synthetic-reference.br", cleanCompressedPayload],+ ]),+ ),+ ).toThrow("npm tarball contains an internal reference.");+ });+});diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.tsindex 961fc1a49..21d8039b3 100644--- a/sdk/typescript/tests-ts/runtime.test.ts+++ b/sdk/typescript/tests-ts/runtime.test.ts@@ -1,6 +1,6 @@import { execFile, spawnSync } from "node:child_process";import * as childProcess from "node:child_process";-import { EventEmitter, once } from "node:events";+import { EventEmitter } from "node:events";import { existsSync, renameSync, symlinkSync } from "node:fs";import {chmod,@@ -3430,10 +3430,8 @@ describe("runtime directories and plugin Python boundary", () => {);}),]);- const ended = once(first.stdout, "end");first.stdout.end();first.stderr.end();- await ended;first.exitCode = 2;first.emit("close", 2, null);await nextTurn();@@ -3603,6 +3601,86 @@ describe("runtime directories and plugin Python boundary", () => {expect(observed).toBe(expected);});+ test.each(["queued", "chunked"] as const)(+ "streams %s Windows credential descriptors through EOF",+ async (kind) => {+ if (+ runTestInSubprocess(+ import.meta.path,+ `streams ${kind} Windows credential descriptors through EOF`,+ )+ ) {+ return;+ }+ const child = Object.assign(new EventEmitter(), {+ stdout: new PassThrough(),+ stderr: new PassThrough(),+ exitCode: null as number | null,+ signalCode: null,+ kill: () => true,+ });+ const originalSpawn = childProcess.spawn;+ mock.module("node:child_process", () => ({+ ...childProcess,+ spawn: () => child,+ }));+ const expected =+ kind === "queued"+ ? Array.from({ length: 4096 }, (_, i) => `descriptor-${i}`)+ : ["first", "café", "middle", "last"];+ const entered = Promise.withResolvers<void>();+ const release = Promise.withResolvers<void>();+ const observed: string[] = [];+ const outcome = streamWindowsCredentialAclDescriptors(+ "synthetic-credential-inspector",+ [],+ async (descriptor) => {+ observed.push(descriptor);+ if (observed.length === 1) {+ entered.resolve();+ await release.promise;+ }+ },+ );+ try {+ if (kind === "queued") {+ // End with more queued lines than readline's watermark while the+ // first asynchronous descriptor inspection is still pending.+ child.stdout.end(`${expected.join("\n")}\n`);+ } else {+ child.stdout.write(+ Buffer.concat([Buffer.from("first\r\ncaf"), Buffer.from([0xc3])]),+ );+ }+ await entered.promise;+ if (kind === "chunked") {+ child.stdout.end(+ Buffer.concat([+ Buffer.from([0xa9]),+ Buffer.from("\r\n\r\nmiddle\rlast"),+ ]),+ );+ }+ child.stderr.end();+ child.exitCode = 0;+ child.emit("close", 0, null);+ await nextTurn();+ expect(observed).toEqual([expected[0]!]);+ release.resolve();+ expect(await outcome).toBe(expected.length);+ expect(observed).toEqual(expected);+ } finally {+ release.resolve();+ child.stdout.destroy();+ child.stderr.destroy();+ mock.module("node:child_process", () => ({+ ...childProcess,+ spawn: originalSpawn,+ }));+ }+ },+ );+test("preserves Windows credential ACL subprocess failures while streaming", async () => {await expect(streamWindowsCredentialAclDescriptors(diff --git a/sdk/typescript/tests-ts/scan-dashboard.test.ts b/sdk/typescript/tests-ts/scan-dashboard.test.tsindex a5c093983..e814f773a 100644--- a/sdk/typescript/tests-ts/scan-dashboard.test.ts+++ b/sdk/typescript/tests-ts/scan-dashboard.test.ts@@ -1,5 +1,6 @@import { EventEmitter } from "node:events";import { Writable } from "node:stream";+import { pathToFileURL } from "node:url";import { stripVTControlCharacters } from "node:util";import { describe, expect, test } from "bun:test";import type { ComponentReceipt } from "../src/component-scan.js";@@ -1272,7 +1273,7 @@ describe("live scan dashboard", () => {expect(frame).not.toContain("/private/tmp/");expect(frame.match(/\[09:41:00\]/gu)).toHaveLength(1);expect(stderr.text()).toContain(- `\u001B]8;;file:///private/tmp/codex%20security/scans/promptfoo-cloud/artifacts/02_discovery/raw_candidates_02.jsonl\u0007raw_candidates_02.jsonl\u001B]8;;\u0007`,+ `\u001B]8;;${pathToFileURL(target).href}\u0007raw_candidates_02.jsonl\u001B]8;;\u0007`,);dashboard.stop();});@@ -1340,9 +1341,11 @@ describe("live scan dashboard", () => {expect(frame).not.toContain("`db.raw( input )`");expect(stderr.text()).toContain("\u001B[2mdb.raw( input )\u001B[22m");expect(stderr.text()).toContain(- "\u001B]8;;file:///tmp/report.md\u0007report\u001B]8;;\u0007",+ `\u001B]8;;${pathToFileURL("/tmp/report.md").href}\u0007report\u001B]8;;\u0007`,+ );+ expect(stderr.text()).not.toContain(+ `\u001B]8;;${pathToFileURL("/tmp/example.md").href}`,);- expect(stderr.text()).not.toContain("\u001B]8;;file:///tmp/example.md");dashboard.record({id: "command-inline-code",@@ -1377,10 +1380,8 @@ describe("live scan dashboard", () => {paths: [],});- const frame = lastFrame(stderr);- expect(frame).toContain("See report, unsafe, and control.");expect(stderr.text()).toContain(- "\u001B]8;;https://example.com/report?token=[redacted]\u0007report\u001B]8;;\u0007",+ "See \u001B]8;;https://example.com/report?token=[redacted]\u0007report\u001B]8;;\u0007, unsafe, and control.",);expect(stderr.text()).not.toContain("secret-token");expect(stderr.text()).not.toContain("javascript:");@@ -1395,7 +1396,9 @@ describe("live scan dashboard", () => {paths: [],});expect(lastFrame(stderr)).toContain("printf '[report](/tmp/report.md)'");- expect(stderr.text()).not.toContain("\u001B]8;;file:///tmp/report.md");+ expect(stderr.text()).not.toContain(+ `\u001B]8;;${pathToFileURL("/tmp/report.md").href}`,+ );dashboard.stop();});diff --git a/sdk/typescript/tests-ts/test-reports.test.ts b/sdk/typescript/tests-ts/test-reports.test.tsindex 8fb83daee..c2026b2d5 100644--- a/sdk/typescript/tests-ts/test-reports.test.ts+++ b/sdk/typescript/tests-ts/test-reports.test.ts@@ -122,7 +122,7 @@ describe("JUnit inventory comparison", () => {const expected = [...["ubuntu-latest", "windows-latest"].flatMap((os) =>["isolated", "parallel"].map(- (mode) => `reports/runner-${os}-${mode}.xml`,+ (mode) => `reports/runner-${os}-${mode}*.xml`,),),"reports/runner-windows-latest-shard-*.xml",