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(sdk): remove duplicate fixtures and process runs (#2045)
Michael D'Angelo424693807a19
diff --git a/sdk/typescript/tests-ts/action-release-workflow.test.ts b/sdk/typescript/tests-ts/action-release-workflow.test.tsindex a2b83450a..ce19a98fc 100644--- a/sdk/typescript/tests-ts/action-release-workflow.test.ts+++ b/sdk/typescript/tests-ts/action-release-workflow.test.ts@@ -3,14 +3,13 @@ import { execFileSync } from "node:child_process";import {copyFileSync,mkdirSync,- mkdtempSync,readFileSync,readdirSync,- rmSync,writeFileSync,} from "node:fs";import { tmpdir } from "node:os";import { basename, dirname, join } from "node:path";+import { createTemporaryDirectoriesSync } from "./support/temporary-directories.js";import { runWorkflowScript } from "./support/workflow-script.js";type Step = {@@ -60,20 +59,15 @@ const detectContainer = script("release", "Detect container release source");const complete = script("complete", "Require completed release channels");const summarize = script("complete", "Summarize release channels");const publish = script("action", "Publish immutable Action tag and metadata");-const directories: string[] = [];+const directories = createTemporaryDirectoriesSync();const version = "99.1.2";const packageName = "@openai/codex-security";const integrity = "sha512-synthetic-verified-integrity";-afterEach(() => {- for (const directory of directories.splice(0)) {- rmSync(directory, { recursive: true, force: true });- }-});+afterEach(directories.cleanup);function fixture(includeAction = true) {- const directory = mkdtempSync(join(tmpdir(), "action release workflow "));- directories.push(directory);+ const directory = directories.create("action release workflow ");const repository = join(directory, "release-source");const output = join(directory, "outputs");const npmMarker = join(directory, "npm-ran");@@ -399,8 +393,7 @@ test.each([0, 42])(expect(validate.if).toBeUndefined();expect(upload.if).toBeUndefined();- const directory = mkdtempSync(join(tmpdir(), "action runtime firewall "));- directories.push(directory);+ const directory = directories.create("action runtime firewall ");const runner = join(directory, "runner");const existingCache = join(runner, "existing-cache");mkdirSync(existingCache, { recursive: true });@@ -548,8 +541,11 @@ const changedDistributions: Array<{},];-for (const job of ["action-verify", "action"]) {- test(`${job} reuses the exact CLI release before installing dependencies`, () => {+const releaseJobs = ["action-verify", "action"];++test.each(releaseJobs)(+ "%s reuses the exact CLI release before installing dependencies",+ (job) => {const release = fixture();const distribution = release.distribution();const result = release.run(reuseAndInstall(job));@@ -557,23 +553,26 @@ for (const job of ["action-verify", "action"]) {expect(result.output).toBe("existing=true\n");expect(readFileSync(release.npmMarker, "utf8")).toContain("npm\n");expect(release.git("rev-parse", "HEAD")).toBe(distribution);- });+ },+);- test.each(changedDistributions)(- `${job} rejects changed $name before installing dependencies`,- ({ path, update, error }) => {- const release = fixture();- release.distribution(() =>- release.updateJson(`github-action/${path}`, update),- );+test.each(changedDistributions)(+ "both jobs reject changed $name before installing dependencies",+ ({ path, update, error }) => {+ const release = fixture();+ release.distribution(() =>+ release.updateJson(`github-action/${path}`, update),+ );+ for (const job of releaseJobs) {+ release.git("checkout", "--detach", release.source);const result = release.run(reuseAndInstall(job));- expect(result.status).not.toBe(0);- expect(result.stderr).toContain(error);- expect(result.output).toBe("");- expect(readFileSync(release.npmMarker, "utf8")).toBe("");- },- );-}+ expect(result.status, job).not.toBe(0);+ expect(result.stderr, job).toContain(error);+ expect(result.output, job).toBe("");+ expect(readFileSync(release.npmMarker, "utf8"), job).toBe("");+ }+ },+);test("leaves the CLI source ready for first Action publication", () => {const release = fixture();@@ -761,19 +760,21 @@ test("recovers an existing Action tag by creating its companion release with botconst result = publication.run();expect(result.status, result.stderr).toBe(0);expect(publication.commands()).toEqual(["view", "create"]);- expect(publication.state()).toMatchObject({+ const published = publication.state();+ expect(published).toMatchObject({isDraft: false,assets: actionAssets,});- expect(publication.state().notes).toContain(+ expect(published.notes).toContain("https://github.com/example/security-tool/releases/tag/npm-v99.1.2",);- expect(publication.state().notes).toContain(+ expect(published.notes).toContain(`uses: example/security-tool@${publication.distribution}`,);const retry = publication.run();expect(retry.status, retry.stderr).toBe(0);+ expect(publication.state()).toEqual(published);expect(publication.commands()).toEqual(["view","create",@@ -813,17 +814,6 @@ test.each(draftAssetSets)(},);-test("reuses identical published Action metadata without changing the immutable release", () => {- const publication = publicationFixture({- isDraft: false,- assets: actionAssets,- });- const result = publication.run();- expect(result.status, result.stderr).toBe(0);- expect(publication.commands()).toEqual(["view", "download", "download"]);- expect(publication.state()).toEqual({ isDraft: false, assets: actionAssets });-});-test.each([false, true].flatMap((isDraft) =>Object.keys(actionAssets).map((asset) => ({ isDraft, asset })),@@ -869,26 +859,52 @@ test.each(Object.keys(actionAssets))(},);-test.each([- ["success", "success", "success", "true", true],- ["success", "success", "skipped", "", true],- ["failure", "skipped", "skipped", "", false],- ["success", "failure", "skipped", "true", false],- ["success", "success", "failure", "true", false],- ["success", "success", "skipped", "true", false],- ["success", "cancelled", "skipped", "", false],-] as const)(- "requires completed release channels: release=%s install=%s action=%s present=%s",- (releaseResult, installResult, actionResult, hasAction, succeeds) => {- const release = fixture();- const result = release.run(complete, {- RELEASE_RESULT: releaseResult,- INSTALL_RESULT: installResult,- ACTION_RESULT: actionResult,- HAS_ACTION: hasAction,- CONTAINER_RESULT: "success",- HAS_CONTAINER: "true",- });+const successfulChannels = {+ RELEASE_RESULT: "success",+ INSTALL_RESULT: "success",+ ACTION_RESULT: "success",+ HAS_ACTION: "true",+ CONTAINER_RESULT: "success",+ HAS_CONTAINER: "true",+};++const failedRelease = {+ RELEASE_RESULT: "failure",+ INSTALL_RESULT: "skipped",+ ACTION_RESULT: "skipped",+ HAS_ACTION: "",+};++const channelCases: Array<[Record<string, string>, boolean]> = [+ [{}, true],+ [{ RELEASE_RESULT: "failure" }, false],+ [failedRelease, false],+ [{ ...failedRelease, CONTAINER_RESULT: "skipped", HAS_CONTAINER: "" }, false],+ [{ INSTALL_RESULT: "failure" }, false],+ [{ INSTALL_RESULT: "failure", ACTION_RESULT: "skipped" }, false],+ [{ INSTALL_RESULT: "cancelled" }, false],+ [+ { INSTALL_RESULT: "cancelled", ACTION_RESULT: "skipped", HAS_ACTION: "" },+ false,+ ],+ [{ ACTION_RESULT: "failure" }, false],+ [{ ACTION_RESULT: "skipped" }, false],+ [{ ACTION_RESULT: "skipped", HAS_ACTION: "" }, true],+ [{ CONTAINER_RESULT: "failure" }, false],+ [{ CONTAINER_RESULT: "cancelled" }, false],+ [{ CONTAINER_RESULT: "skipped" }, false],+ [{ CONTAINER_RESULT: "skipped", HAS_CONTAINER: "" }, true],+];++test.each(channelCases)(+ "checks release channel requirements with %j",+ (overrides, succeeds) => {+ const result = runWorkflowScript(+ tmpdir(),+ complete,+ { ...successfulChannels, ...overrides },+ ["-e", "-o", "pipefail"],+ );expect(result.status === 0).toBe(succeeds);},);@@ -928,44 +944,24 @@ test.each([},);-test.each([- ["success", "true", true],- ["failure", "true", false],- ["cancelled", "true", false],- ["skipped", "true", false],- ["skipped", "", true],-] as const)(- "requires container publication when present: result=%s present=%s",- (containerResult, hasContainer, succeeds) => {- const release = fixture();- const result = release.run(complete, {- RELEASE_RESULT: "success",- INSTALL_RESULT: "success",- ACTION_RESULT: "success",- HAS_ACTION: "true",- CONTAINER_RESULT: containerResult,- HAS_CONTAINER: hasContainer,- });- expect(result.status === 0).toBe(succeeds);- },-);-test.each(["success", "failure", "cancelled", "skipped"])("reports the coordinated container result: %s",(containerResult) => {- const release = fixture();- const summary = join(release.directory, "summary.md");- const result = release.run(summarize, {- GITHUB_STEP_SUMMARY: summary.replaceAll("\\", "/"),- GITHUB_SERVER_URL: "https://github.com",- GITHUB_REPOSITORY: "example/project",- RELEASE_RESULT: "success",- INSTALL_RESULT: "success",- ACTION_RESULT: "success",- HAS_ACTION: "true",- CONTAINER_RESULT: containerResult,- HAS_CONTAINER: "true",- });+ const directory = directories.create("release summary ");+ const summary = join(directory, "summary.md");+ const result = runWorkflowScript(+ directory,+ summarize,+ {+ ...successfulChannels,+ RELEASE_VERSION: version,+ GITHUB_STEP_SUMMARY: summary.replaceAll("\\", "/"),+ GITHUB_SERVER_URL: "https://github.com",+ GITHUB_REPOSITORY: "example/project",+ CONTAINER_RESULT: containerResult,+ },+ ["-e", "-o", "pipefail"],+ );expect(result.status, result.stderr).toBe(0);const rows = readFileSync(summary, "utf8").split("\n")diff --git a/sdk/typescript/tests-ts/api-audit-admission.test.ts b/sdk/typescript/tests-ts/api-audit-admission.test.tsindex 04b6fadf9..62398fd44 100644--- a/sdk/typescript/tests-ts/api-audit-admission.test.ts+++ b/sdk/typescript/tests-ts/api-audit-admission.test.ts@@ -307,39 +307,27 @@ for (const scenario of cases) {});}-test("Standard admission preserves existing canonical scan IDs", async () => {+test("Standard admission accepts the existing scan ID and preserves BOM-prefixed canonical files", async () => {const root = await temporaryDirectory();const repository = join(root, "repository");await mkdir(repository);const scanDir = await copyCompletedScan(root);- const manifest = JSON.parse(- await readFile(join(scanDir, "scan-manifest.json"), "utf8"),- );+ const files = [];+ for (const name of ["scan-manifest.json", "findings.json", "coverage.json"]) {+ const file = join(scanDir, name);+ const original = await readFile(file);+ if (name === "scan-manifest.json")+ expect(JSON.parse(original.toString()).scan.id).toBe("scan_example_001");+ const bytes = Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), original]);+ await writeFile(file, bytes);+ files.push({ file, bytes });+ }const standard = await observeStandardAdmission(repository, scanDir);- expect(manifest.scan.id).toBe("scan_example_001");expect(standard.error).toBe(standard.finalization);expect(standard.finalizations).toBe(1);-});--test.each(["scan-manifest.json", "findings.json", "coverage.json"])(- "Standard admission preserves BOM-prefixed %s bytes",- async (name) => {- const root = await temporaryDirectory();- const repository = join(root, "repository");- await mkdir(repository);- const scanDir = await copyCompletedScan(root);- const file = join(scanDir, name);- const bytes = Buffer.concat([- Buffer.from([0xef, 0xbb, 0xbf]),- await readFile(file),- ]);- await writeFile(file, bytes);- const standard = await observeStandardAdmission(repository, scanDir);- expect(standard.error).toBe(standard.finalization);- expect(standard.finalizations).toBe(1);+ for (const { file, bytes } of files)expect(await readFile(file)).toEqual(bytes);- },-);+});test("sealed legacy evidence stays readable during canonical admission", async () => {const scanDir = await copyCompletedScan(await temporaryDirectory());diff --git a/sdk/typescript/tests-ts/api-events.test.ts b/sdk/typescript/tests-ts/api-events.test.tsindex 368da5c46..4590eb994 100644--- a/sdk/typescript/tests-ts/api-events.test.ts+++ b/sdk/typescript/tests-ts/api-events.test.ts@@ -14,10 +14,8 @@ import {ContractValidationError,IncompleteScanError,ScanInterruptedError,- type ScanAuthentication,type ScanActivity,type ScanProgress,- type ScanReconnectDetails,type ScanTrustedAccessStatus,type ScanWorkerStatus,} from "../src/index.js";@@ -73,20 +71,24 @@ async function* tacEvents(};}-function runTacEvents(+async function runTacEvents(scanDir: string,items: readonly McpToolCallItem[],- onWarning: (warning: string) => void,- onObserverError?: (observer: ScanObserverName, error: unknown) => void,- onTrustedAccessStatus?: (status: ScanTrustedAccessStatus) => void,- authentication?: ScanAuthentication,-): ReturnType<typeof runEvents> {- return runEvents(scanDir, completedEvents("thread-1", tacEvents(items)), {- authentication,- onObserverError,- onTrustedAccessStatus,- onWarning,- });+ options: Parameters<typeof runEvents>[2] = {},+) {+ const warnings: string[] = [];+ const statuses: ScanTrustedAccessStatus[] = [];+ const result = await runEvents(+ scanDir,+ completedEvents("thread-1", tacEvents(items)),+ {+ onWarning: (warning) => warnings.push(warning),+ onTrustedAccessStatus: (status) => statuses.push(status),+ ...options,+ },+ );+ expect(result.turnResult.status).toBe("completed");+ return { warnings, statuses };}describe("one-shot scan events", () => {@@ -157,136 +159,77 @@ describe("one-shot scan events", () => {);});- test("reports granted trusted cyber access once without a warning", async () => {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];- const statuses: ScanTrustedAccessStatus[] = [];- const item = tacToolCall("granted");-- const result = await runTacEvents(- scanDir,- [item, item],- (warning) => warnings.push(warning),- undefined,- (status) => statuses.push(status),- );-- expect(result.turnResult.status).toBe("completed");- expect(warnings).toEqual([]);- expect(statuses).toEqual(["granted"]);- });-- test("warns once and continues when trusted cyber access is not granted", async () => {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings = mock((_warning: string) => {});- const item = tacToolCall("not_granted");-- const result = await runTacEvents(scanDir, [item, item], warnings);-- expect(result.turnResult.status).toBe("completed");- expect(warnings).toHaveBeenCalledTimes(1);- expect(warnings.mock.calls[0]?.[0]).toBe(- "Some cybersecurity requests or findings may be refused because your account does not have Trusted Access for Cyber. Apply at https://chatgpt.com/cyber.",- );- });-- test("warns once and continues when trusted cyber access is unknown", async () => {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];-- const result = await runTacEvents(- scanDir,- [tacToolCall("unknown")],- (warning) => warnings.push(warning),- );-- expect(result.turnResult.status).toBe("completed");- expect(warnings).toHaveLength(1);- expect(warnings[0]).toBe(- "Some cybersecurity requests or findings may be refused because your Trusted Access for Cyber status could not be verified. Check your access or apply at https://chatgpt.com/cyber.",- );- });-- test("directs API-key scans to the organizational trusted cyber application", async () => {- for (const [authentication, status, expected] of [+ test.each([+ ["granted", []],+ [+ "not_granted",[- {- method: "api_key",- source: "OPENAI_API_KEY",- verified: false,- },- "not_granted",- "Some cybersecurity requests or findings may be refused because your API organization does not have Trusted Access for Cyber. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",+ "Some cybersecurity requests or findings may be refused because your account does not have Trusted Access for Cyber. Apply at https://chatgpt.com/cyber.",],+ ],+ [+ "unknown",[- {- method: "api_key",- source: "CODEX_API_KEY",- verified: false,- },- "unknown",- "Some cybersecurity requests or findings may be refused because Trusted Access for Cyber for your API organization could not be verified. Check your organization's access or apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",+ "Some cybersecurity requests or findings may be refused because your Trusted Access for Cyber status could not be verified. Check your access or apply at https://chatgpt.com/cyber.",],+ ],+ ] as const)(+ "reports %s trusted cyber access once",+ async (status, warnings) => {+ const scanDir = await copyCompletedScan(await temporaryDirectory());+ const item = tacToolCall(status);+ expect(await runTacEvents(scanDir, [item, item])).toEqual({+ warnings: [...warnings],+ statuses: [status],+ });+ },+ );++ test("directs API-key scans to the organizational trusted cyber application", async () => {+ const scanDir = await copyCompletedScan(await temporaryDirectory());+ const expected = {+ not_granted:+ "Some cybersecurity requests or findings may be refused because your API organization does not have Trusted Access for Cyber. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",+ unknown:+ "Some cybersecurity requests or findings may be refused because Trusted Access for Cyber for your API organization could not be verified. Check your organization's access or apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",+ };+ const stored = {+ method: "stored_credentials",+ credentialType: "api_key",+ verified: false,+ } as const;+ for (const [authentication, status] of [[- {- method: "stored_credentials",- credentialType: "api_key",- verified: false,- },+ { method: "api_key", source: "OPENAI_API_KEY", verified: false },"not_granted",- "Some cybersecurity requests or findings may be refused because your API organization does not have Trusted Access for Cyber. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",],[- {- method: "stored_credentials",- credentialType: "api_key",- verified: false,- },+ { method: "api_key", source: "CODEX_API_KEY", verified: false },"unknown",- "Some cybersecurity requests or findings may be refused because Trusted Access for Cyber for your API organization could not be verified. Check your organization's access or apply at https://openai.com/form/enterprise-trusted-access-for-cyber/.",],+ [stored, "not_granted"],+ [stored, "unknown"],] as const) {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];-- const result = await runTacEvents(- scanDir,- [tacToolCall(status)],- (warning) => warnings.push(warning),- undefined,- undefined,+ const { warnings } = await runTacEvents(scanDir, [tacToolCall(status)], {authentication,- );-- expect(result.turnResult.status).toBe("completed");- expect(warnings).toEqual([expected]);- expect(warnings[0]).not.toContain("chatgpt.com/cyber");+ });+ expect(warnings).toEqual([expected[status]]);}});test("does not apply ChatGPT account advisories to Bedrock scans", async () => {+ const scanDir = await copyCompletedScan(await temporaryDirectory());for (const authentication of [{ method: "aws_credentials", source: "AWS_PROFILE", verified: false },{ method: "command", verified: false },] as const) {for (const status of ["granted", "not_granted", "unknown"] as const) {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];- const statuses: ScanTrustedAccessStatus[] = [];- const result = await runEvents(- scanDir,- completedEvents("thread-1", tacEvents([tacToolCall(status)])),- {+ expect(+ await runTacEvents(scanDir, [tacToolCall(status)], {authentication,modelProvider: "amazon-bedrock",- onWarning: (warning) => warnings.push(warning),- onTrustedAccessStatus: (value) => statuses.push(value),- },- );-- expect(result.turnResult.status).toBe("completed");- expect(warnings).toEqual([]);- expect(statuses).toEqual([]);+ }),+ ).toEqual({ warnings: [], statuses: [] });}}});@@ -318,25 +261,20 @@ describe("one-shot scan events", () => {});test("does not mistake external-provider keys for OpenAI API organizations", async () => {+ const scanDir = await copyCompletedScan(await temporaryDirectory());for (const source of ["OPENROUTER_API_KEY","FIREWORKS_API_KEY","CHEAPER_INFERENCE_API_KEY",] as const) {for (const status of ["not_granted", "unknown"] as const) {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];-- const result = await runTacEvents(+ const { warnings } = await runTacEvents(scanDir,[tacToolCall(status)],- (warning) => warnings.push(warning),- undefined,- undefined,- { method: "api_key", source, verified: false },+ {+ authentication: { method: "api_key", source, verified: false },+ },);-- expect(result.turnResult.status).toBe("completed");expect(warnings).toHaveLength(1);expect(warnings[0]).toContain("https://chatgpt.com/cyber");expect(warnings[0]).not.toContain("API organization");@@ -349,27 +287,20 @@ describe("one-shot scan events", () => {test("treats failed trusted cyber access checks as an advisory without exposing provider errors", async () => {const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];-- const result = await runTacEvents(- scanDir,- [- tacToolCall("unknown", {- status: "failed",- result: undefined,- error: { message: "SYNTHETIC_PRIVATE_PROVIDER_ERROR" },- }),- ],- (warning) => warnings.push(warning),- );-- expect(result.turnResult.status).toBe("completed");+ const { warnings } = await runTacEvents(scanDir, [+ tacToolCall("unknown", {+ status: "failed",+ result: undefined,+ error: { message: "SYNTHETIC_PRIVATE_PROVIDER_ERROR" },+ }),+ ]);expect(warnings).toHaveLength(1);expect(warnings[0]).toContain("https://chatgpt.com/cyber");expect(warnings[0]).not.toContain("SYNTHETIC_PRIVATE_PROVIDER_ERROR");});test("treats malformed or stale trusted cyber access results as unverified", async () => {+ const scanDir = await copyCompletedScan(await temporaryDirectory());for (const structuredContent of [null,{ schemaVersion: 1, status: "granted", grants: [] },@@ -413,20 +344,11 @@ describe("one-shot scan events", () => {stale: false,},]) {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];-- const result = await runTacEvents(- scanDir,- [- tacToolCall("granted", {- result: { content: [], structured_content: structuredContent },- }),- ],- (warning) => warnings.push(warning),- );-- expect(result.turnResult.status).toBe("completed");+ const { warnings } = await runTacEvents(scanDir, [+ tacToolCall("granted", {+ result: { content: [], structured_content: structuredContent },+ }),+ ]);expect(warnings).toHaveLength(1);expect(warnings[0]).toContain("could not be verified");}@@ -434,20 +356,13 @@ describe("one-shot scan events", () => {test("does not trust similarly named tools from other MCP servers", async () => {const scanDir = await copyCompletedScan(await temporaryDirectory());- const warnings: string[] = [];-- const result = await runTacEvents(- scanDir,- [- tacToolCall("not_granted", { server: "untrusted_server" }),- tacToolCall("not_granted", { tool: "unrelated_tool" }),- tacToolCall("granted"),- ],- (warning) => warnings.push(warning),- );-- expect(result.turnResult.status).toBe("completed");+ const { warnings, statuses } = await runTacEvents(scanDir, [+ tacToolCall("not_granted", { server: "untrusted_server" }),+ tacToolCall("not_granted", { tool: "unrelated_tool" }),+ tacToolCall("granted"),+ ]);expect(warnings).toEqual([]);+ expect(statuses).toEqual(["granted"]);});test("captures warning observers before payload evaluation and isolates failures", async () => {@@ -512,15 +427,10 @@ describe("one-shot scan events", () => {const scanDir = await copyCompletedScan(await temporaryDirectory());const observerErrors: Array<[ScanObserverName, string]> = [];- const result = await runTacEvents(- scanDir,- [tacToolCall("granted")],- () => {},- collectObserverErrors(observerErrors),- throwing("TAC status observer failed"),- );-- expect(result.turnResult.status).toBe("completed");+ await runTacEvents(scanDir, [tacToolCall("granted")], {+ onObserverError: collectObserverErrors(observerErrors),+ onTrustedAccessStatus: throwing("TAC status observer failed"),+ });expect(observerErrors).toEqual([["onTrustedAccessStatus", "TAC status observer failed"],]);@@ -798,78 +708,28 @@ describe("one-shot scan events", () => {}});- test("extracts bounded rate-limit context from reconnect notifications", async () => {- const scanDir = await copyCompletedScan(await temporaryDirectory());- const reconnects: Array<{- attempt: number;- maxAttempts: number;- details?: ScanReconnectDetails;- }> = [];-- async function* events(): AsyncGenerator<ThreadEvent> {- yield {- type: "error",- message:- "Reconnecting... 2/5 (Rate limit reached for org-private. Please try again in 1.2s.)",- };- yield {- type: "error",- message:- "Reconnecting... 3/5 (Rate limit reached. Please try again in 999999s.)",- };- yield { type: "error", message: "Reconnecting... 4/5" };- yield* completedEvents();- }-- await runEvents(scanDir, events(), {- onReconnect: (attempt, maxAttempts, details) => {- reconnects.push({- attempt,- maxAttempts,- ...(details ? { details } : {}),- });- },- });-- expect(reconnects).toEqual([- {- attempt: 2,- maxAttempts: 5,- details: { reason: "rate_limit", retryAfterSeconds: 1.2 },- },- { attempt: 3, maxAttempts: 5, details: { reason: "rate_limit" } },- { attempt: 4, maxAttempts: 5 },- ]);- expect(JSON.stringify(reconnects)).not.toContain("org-private");- });-- test("classifies retryable reconnect causes without exposing provider details", async () => {+ test("classifies reconnect causes and bounds the reported retry delay", async () => {const scanDir = await copyCompletedScan(await temporaryDirectory());- const reconnects: ScanReconnectDetails[] = [];-+ const onReconnect = mock();async function* events(): AsyncGenerator<ThreadEvent> {- yield {- type: "error",- message: "Reconnecting... 1/5 (ECONNRESET org-private)",- };- yield {- type: "error",- message: "Reconnecting... 2/5 (429 rate limit reached org-private)",- };+ for (const message of [+ "Reconnecting... 1/5 (ECONNRESET org-private)",+ "Reconnecting... 2/5 (Rate limit reached for org-private. Please try again in 1.2s.)",+ "Reconnecting... 3/5 (Rate limit reached. Please try again in 999999s.)",+ "Reconnecting... 4/5",+ "Reconnecting... 5/5 (429 rate limit reached org-private)",+ ])+ yield { type: "error", message };yield* completedEvents();}-- await runEvents(scanDir, events(), {- onReconnect: (_a, _m, detail) => {- if (detail !== undefined) reconnects.push(detail);- },- });-- expect(reconnects).toEqual([- { reason: "network" },- { reason: "rate_limit" },+ await runEvents(scanDir, events(), { onReconnect });+ expect(onReconnect.mock.calls).toEqual([+ [1, 5, { reason: "network" }],+ [2, 5, { reason: "rate_limit", retryAfterSeconds: 1.2 }],+ [3, 5, { reason: "rate_limit" }],+ [4, 5, undefined],+ [5, 5, { reason: "rate_limit" }],]);- expect(JSON.stringify(reconnects)).not.toContain("org-private");});test("fails immediately on definitive authentication and authorization errors", async () => {diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex b4c541273..485a3dca0 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -1915,14 +1915,8 @@ describe("CodexSecurity orchestration", () => {test.each(["revision", "registration", "cancellation", "mock"] as const)("keeps existing output when %s prevents scan registration",async (failurePoint) => {- const root = await temporaryDirectory();- const repository = join(root, "repository");- const codexHome = join(root, "codex-home");- const output = join(root, "scan");- await mkdir(repository);- await mkdir(codexHome);- await mkdir(output, { mode: 0o700 });- await writeFile(join(output, "previous.txt"), "previous scan\n");+ const { root, repository, codexHome, scanDir } = await scanDirectories();+ await writeFile(join(scanDir, "previous.txt"), "previous scan\n");const cancellation = new AbortController();const client = new TestClient({ pluginPath: PLUGIN_ROOT },@@ -1944,13 +1938,13 @@ describe("CodexSecurity orchestration", () => {try {await expect(client.run(repository, {- outputDir: output,+ outputDir: scanDir,archiveExisting: true,signal: cancellation.signal,mock: failurePoint === "mock",}),).rejects.toThrow();- expect(await readFile(join(output, "previous.txt"), "utf8")).toBe(+ expect(await readFile(join(scanDir, "previous.txt"), "utf8")).toBe("previous scan\n",);expect(@@ -1967,14 +1961,8 @@ describe("CodexSecurity orchestration", () => {test.each([false, true])("archives accepted output before starting, cancellation=%p",async (cancelRegistration) => {- const root = await temporaryDirectory();- const repository = join(root, "repository");- const codexHome = join(root, "codex-home");- const output = join(root, "scan");- await mkdir(repository);- await mkdir(codexHome);- await mkdir(output, { mode: 0o700 });- await writeFile(join(output, "previous.txt"), "previous scan\n");+ const { root, repository, codexHome, scanDir } = await scanDirectories();+ await writeFile(join(scanDir, "previous.txt"), "previous scan\n");const cancellation = new AbortController();const notifications: string[] = [];let archived: string | undefined;@@ -2014,7 +2002,7 @@ describe("CodexSecurity orchestration", () => {await expect(client.run(repository, {- outputDir: output,+ outputDir: scanDir,archiveExisting: true,signal: cancellation.signal,onOutputDirReady: () => {@@ -2034,13 +2022,13 @@ describe("CodexSecurity orchestration", () => {expect(observerErrors).toEqual([["onOutputArchived", "archive observer exploded"],]);- expect(archived?.startsWith(`${output}.previous-`)).toBe(true);+ expect(archived?.startsWith(`${scanDir}.previous-`)).toBe(true);expect(registration).toContain("--archive-existing");expect(registration).not.toContain("--archived-scan-dir");expect(await readFile(join(archived!, "previous.txt"), "utf8")).toBe("previous scan\n",);- await expect(stat(output)).resolves.toBeDefined();+ await expect(stat(scanDir)).resolves.toBeDefined();await client.close();},);@@ -2058,9 +2046,7 @@ describe("CodexSecurity orchestration", () => {)("cancels archived registration at $boundary via $cancel, mode=$mode",async ({ boundary, cancel, mode }) => {- const { root, repository, codexHome } = await runtimeDirectories();- const output = join(root, "scan");- await mkdir(output, { mode: 0o700 });+ const { root, repository, codexHome, scanDir } = await scanDirectories();const python = pythonExecutable()!;const environment = {PATH: process.env["PATH"],@@ -2085,7 +2071,7 @@ describe("CodexSecurity orchestration", () => {"--repository",repository,"--scan-dir",- output,+ scanDir,"--recipe-json",JSON.stringify({repository,@@ -2102,7 +2088,7 @@ describe("CodexSecurity orchestration", () => {"--message","synthetic stopped scan",]);- await writeFile(join(output, "previous.txt"), "previous scan\n");+ await writeFile(join(scanDir, "previous.txt"), "previous scan\n");}const connections = new Set<Socket>();let cleaningUp = false;@@ -2117,43 +2103,51 @@ describe("CodexSecurity orchestration", () => {if (address === null || typeof address === "string")throw new Error("Missing fixture port");const pluginRoot = join(root, "controlled-plugin");- await cp(PLUGIN_ROOT, pluginRoot, { recursive: true });+ for (const file of [+ ".codex-plugin/plugin.json",+ "skills/security-scan/SKILL.md",+ "schemas/findings.schema.json",+ ]) {+ await cp(join(PLUGIN_ROOT, file), join(pluginRoot, file));+ }+ await mkdir(join(pluginRoot, "scripts"), { recursive: true });+ const afterRename = boundary === "commit" || boundary === "rollback";+ const hook = afterRename+ ? "insert_running_scan"+ : "directory_snapshot_regular_file_count";+ const framedArgument = "--fixture-message=出力\0literal\nsecond line";await writeFile(join(pluginRoot, "scripts", "workbench_db.py"),- [- "import io, runpy, socket, sys",- "from pathlib import Path",- `workbench = runpy.run_path(${JSON.stringify(join(PLUGIN_ROOT, "scripts", "workbench_db.py"))})`,- "namespace = workbench['main'].__globals__",- "def pause():",- ` with socket.create_connection(('127.0.0.1', ${address.port})) as connection:`,- " connection.sendall(b'ready')",- " if connection.recv(1) == b'p':",- " connection.sendall(b'alive')",- " connection.recv(1)",- "def main(**kwargs):",- " sys.stdout.reconfigure(newline='\\r\\n')",- " if sys.argv[1:2] == ['register-cli-scan'] and '--help' not in sys.argv:",- ...(mode === "real"- ? [- ` sys.argv.remove(${JSON.stringify("--fixture-message=出力\0literal\nsecond line")})`,- ]- : []),- " payload = sys.stdin.buffer.read()",- ` Path(${JSON.stringify(join(root, "registration-input.json"))}).write_bytes(payload)`,- ' sys.stdin = io.TextIOWrapper(io.BytesIO(payload), encoding="utf-8")',- ` original = namespace[${JSON.stringify(boundary === "commit" || boundary === "rollback" ? "insert_running_scan" : "directory_snapshot_regular_file_count")}]`,- " def paused(*args, **options):",- " pause()",- ...(boundary === "rollback"- ? [- " raise RuntimeError('synthetic registration failure after rename')",- ]- : [" return original(*args, **options)"]),- ` namespace[${JSON.stringify(boundary === "commit" || boundary === "rollback" ? "insert_running_scan" : "directory_snapshot_regular_file_count")}] = paused`,- " workbench['main'](**kwargs)",- "if __name__ == '__main__': main()",- ].join("\n"),+ `import io, runpy, socket, sys+from pathlib import Path++workbench = runpy.run_path(${JSON.stringify(join(PLUGIN_ROOT, "scripts", "workbench_db.py"))})+namespace = workbench["main"].__globals__+original = namespace["${hook}"]++def paused(*args, **options):+ with socket.create_connection(("127.0.0.1", ${address.port})) as connection:+ connection.sendall(b"ready")+ if connection.recv(1) == b"p":+ connection.sendall(b"alive")+ connection.recv(1)+ if ${JSON.stringify(boundary)} == "rollback":+ raise RuntimeError("synthetic registration failure after rename")+ return original(*args, **options)++def main(**kwargs):+ sys.stdout.reconfigure(newline="\\r\\n")+ if sys.argv[1:2] == ["register-cli-scan"] and "--help" not in sys.argv:+ sys.argv.remove(${JSON.stringify(framedArgument)})+ payload = sys.stdin.buffer.read()+ Path(${JSON.stringify(join(root, "registration-input.json"))}).write_bytes(payload)+ sys.stdin = io.TextIOWrapper(io.BytesIO(payload), encoding="utf-8")+ namespace["${hook}"] = paused+ workbench["main"](**kwargs)++if __name__ == "__main__":+ main()+`,);let submitted: string | undefined;const registration: typeof runWorkbench = async (@@ -2161,15 +2155,12 @@ describe("CodexSecurity orchestration", () => {args,input,) => {- if (args[0] === "register-cli-scan") {- submitted = `\n${JSON.stringify(JSON.parse(input!), null, 2)}\r\n`;- input = submitted;- // The custom wrapper accepts this text argument before calling the- // real workbench, exercising framed argv at each archive boundary.- if (mode === "real")- args = [...args, "--fixture-message=出力\0literal\nsecond line"];- }- return runWorkbench(options, args, input);+ if (args[0] !== "register-cli-scan")+ return runWorkbench(options, args, input);+ submitted = `\n${JSON.stringify(JSON.parse(input!), null, 2)}\r\n`;+ // The custom wrapper accepts this text argument before calling the+ // real workbench, exercising framed argv at each archive boundary.+ return runWorkbench(options, [...args, framedArgument], submitted);};const controller = new AbortController();const client = new TestClient(@@ -2195,7 +2186,7 @@ describe("CodexSecurity orchestration", () => {const deadline = guard.signal;const connected = once(server, "connection", { signal: deadline });const options = {- outputDir: output,+ outputDir: scanDir,archiveExisting: true,signal: controller.signal,};@@ -2256,7 +2247,7 @@ describe("CodexSecurity orchestration", () => {});if (cancel === "close") closing = client.close();else controller.abort();- if (boundary === "commit" || boundary === "rollback") {+ if (afterRename) {// This child has already renamed the directory. A request/response// proves it remains alive after cancellation until we let it settle.const alive = once(socket, "data", { signal: deadline });@@ -2280,7 +2271,7 @@ describe("CodexSecurity orchestration", () => {);if (previousId !== undefined) {const previous = scans.find((scan) => scan.scanId === previousId)!;- expect(previous.scanDir === output).toBe(boundary !== "commit");+ expect(previous.scanDir === scanDir).toBe(boundary !== "commit");expect(await readFile(join(previous.scanDir, "previous.txt"), "utf8"),).toBe("previous scan\n");@@ -7119,109 +7110,6 @@ describe("CodexSecurity orchestration", () => {}});- test("keeps requested source paths without ranking or ignored directory files", async () => {- const root = await temporaryDirectory();- const repository = join(root, "repository");- const source = join(repository, "src");- const ignored = join(source, "node_modules");- const vendored = join(source, "vendor");- const scopes = join(root, "scopes.json");- const output = join(root, "scoped-source-input.jsonl");- await mkdir(join(source, "tests"), { recursive: true });- await mkdir(join(source, "examples"));- await mkdir(ignored);- await mkdir(vendored);- execFileSync("git", ["init", "-q"], { cwd: repository });- execFileSync("git", ["config", "--local", "core.autocrlf", "false"], {- cwd: repository,- });- await Promise.all([- writeFile(- join(repository, ".gitignore"),- "node_modules/\n.env\nvendor/\n",- ),- writeFile(join(source, "handler.ts"), "export {};\n"),- writeFile(join(source, "Dockerfile"), "FROM scratch\n"),- writeFile(join(source, "tests", "handler.test.ts"), "export {};\n"),- writeFile(join(source, "examples", "demo.ts"), "export {};\n"),- writeFile(join(source, ".env"), "SECRET=private\n"),- writeFile(- join(source, "logo.png"),- Buffer.from([0x89, 0x50, 0x4e, 0x47]),- ),- writeFile(join(ignored, "dependency.ts"), "export {};\n"),- writeFile(join(vendored, "dependency.ts"), "export {};\n"),- ]);- execFileSync(- "git",- ["add", "--force", "src/vendor/dependency.ts", "src/logo.png"],- { cwd: repository },- );-- const enumerate = async (requested: string[]) => {- await writeFile(scopes, JSON.stringify(requested));- execFileSync(- nodeCommand().command,- [- join(PLUGIN_ROOT, "mcp", "helpers.mjs"),- "make-repo-scope-input",- "--repo",- repository,- "--scopes-file",- scopes,- "--out",- output,- ],- { stdio: "pipe" },- );- return (await readFile(output, "utf8"))- .trimEnd()- .split("\n")- .map((row) => (JSON.parse(row) as { path: string }).path);- };-- expect(await enumerate(["src"])).toEqual([- "src/Dockerfile",- "src/examples/demo.ts",- "src/handler.ts",- "src/logo.png",- "src/tests/handler.test.ts",- "src/vendor/dependency.ts",- ]);- expect(await enumerate(["src", "src/.env"])).toEqual([- "src/.env",- "src/Dockerfile",- "src/examples/demo.ts",- "src/handler.ts",- "src/logo.png",- "src/tests/handler.test.ts",- "src/vendor/dependency.ts",- ]);- expect(await enumerate(["src/vendor", "src/logo.png"])).toEqual([- "src/logo.png",- "src/vendor/dependency.ts",- ]);- await expect(enumerate(["../scopes.json"])).rejects.toThrow();- if (process.platform !== "win32") {- await symlink(join(source, "handler.ts"), join(source, "alias.ts"));- await symlink(source, join(repository, "alias"));- await expect(enumerate(["src/alias.ts"])).rejects.toThrow(- /symbolic links/,- );- await expect(enumerate(["alias/handler.ts"])).rejects.toThrow(- /symbolic links/,- );- await expect(enumerate(["alias/../src/handler.ts"])).rejects.toThrow(- /symbolic links/,- );- } else {- await symlink(source, join(repository, "junction"), "junction");- await expect(enumerate(["junction/handler.ts"])).rejects.toThrow(- /symbolic links/,- );- }- });-test("removes scoped target files after a scan settles", async () => {const { root, repository, codexHome, scanDir } = await scanDirectories();await writeFile(join(repository, "target.ts"), "export {};\n");diff --git a/sdk/typescript/tests-ts/attack-path-tool-name.test.ts b/sdk/typescript/tests-ts/attack-path-tool-name.test.tsdeleted file mode 100644index 796c25eb6..000000000--- a/sdk/typescript/tests-ts/attack-path-tool-name.test.ts+++ /dev/null@@ -1,49 +0,0 @@-import { parseJsonLines } from "./support/json.js";-import { mkdtempSync, rmSync } from "node:fs";-import { tmpdir } from "node:os";-import { join } from "node:path";-import { expect, test } from "bun:test";-import { PLUGIN_ROOT } from "./plugin-root.js";-import { runCommand } from "./support/shell.js";--test("keeps model-visible attack-path tool names within the Codex limit", async () => {- const node = Bun.which("node");- expect(node).not.toBeNull();- const state = mkdtempSync(join(tmpdir(), "codex-security-mcp-tools-"));-- try {- const { status, stdout, stderr } = await runCommand(- node!,- [join(PLUGIN_ROOT, "mcp", "server.mjs")],- {- env: { ...process.env, CODEX_SECURITY_STATE_DIR: state },- input: [- '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"codex-security-test","version":"1.0.0"}}}',- '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}',- '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}',- "",- ].join("\n"),- timeout: 30_000,- },- );- expect(status, stderr).toBe(0);-- const tools = parseJsonLines(stdout).find((response) => response.id === 2)- .result.tools as {- name: string;- _meta?: { ui?: { visibility?: string[] } };- }[];-- expect(tools.map((tool) => tool.name)).toContain(- "record_candidate_attack_paths",- );- for (const tool of tools) {- if (tool._meta?.ui?.visibility?.includes("model") === false) continue;- expect(`mcp__codex_security__${tool.name}`.length).toBeLessThanOrEqual(- 64,- );- }- } finally {- rmSync(state, { recursive: true, force: true });- }-});diff --git a/sdk/typescript/tests-ts/classify-scan-severity.test.ts b/sdk/typescript/tests-ts/classify-scan-severity.test.tsindex abe7c5b35..53f1582ce 100644--- a/sdk/typescript/tests-ts/classify-scan-severity.test.ts+++ b/sdk/typescript/tests-ts/classify-scan-severity.test.ts@@ -151,7 +151,7 @@ function classifier(finding: Finding, excluded = false) {}));}-async function query(environment: NodeJS.ProcessEnv, sql: string) {+function query(environment: NodeJS.ProcessEnv, sql: string) {using database = new Database(join(environment["CODEX_SECURITY_STATE_DIR"]!, "workbench.sqlite3"),);@@ -159,36 +159,17 @@ async function query(environment: NodeJS.ProcessEnv, sql: string) {return database.query<Record<string, unknown>, []>(sql).all();}-test("classification and saved assessments run with Node and no Python", async () => {+test("classifies and reads a saved scan with an embedded NUL in its ID without Python", async () => {const { environment, root, scanDirectory, scanId, findings } =- await fixture();+ await fixture("imported\0scan");const withoutPython = {...environment,PATH: dirname(Bun.which("node")!),PYTHON: join(root, "missing-python"),};- const { scanId: _scanId, ...classification } =- await classifyScanDirectorySeverity(scanDirectory, {- environment: withoutPython,- codex: recordingClassifier().codex,- });- expect(- await readScanSeverityClassification(- scanDirectory,- scanId,- findings,- undefined,- withoutPython,- ),- ).toEqual(classification);-});--test("saved assessments retain embedded NULs in imported scan IDs", async () => {- const { environment, scanDirectory, scanId, findings } =- await fixture("imported\0scan");const { scanId: classifiedScanId, ...classification } =await classifyScanDirectorySeverity(scanDirectory, {- environment,+ environment: withoutPython,codex: recordingClassifier().codex,});expect(classifiedScanId).toBe(scanId);@@ -198,7 +179,7 @@ test("saved assessments retain embedded NULs in imported scan IDs", async () =>scanId,findings,undefined,- environment,+ withoutPython,),).toEqual(classification);});@@ -400,12 +381,9 @@ test("checkpoints each finding, resumes missing work, and reprocesses only the sclassifyScanDirectorySeverity(scanDirectory, options),).rejects.toThrow("Interrupted model call");expect(- (- await query(- environment,- "SELECT finding_id FROM scan_severity_assessments",- )- ).map((row) => row["finding_id"]),+ query(environment, "SELECT finding_id FROM scan_severity_assessments").map(+ (row) => row["finding_id"],+ ),).toEqual([findings[0]!.findingId]);await expect(prepareScanPublication(scanDirectory, { ...destination, environment }),@@ -425,7 +403,7 @@ test("checkpoints each finding, resumes missing work, and reprocesses only the senvironment,),).toEqual(assessment);- const rows = await query(+ const rows = query(environment,"SELECT * FROM scan_severity_assessments ORDER BY finding_id",);@@ -435,7 +413,7 @@ test("checkpoints each finding, resumes missing work, and reprocesses only the s).toEqual(complete.assessments);expect(calls).toEqual([]);expect(- await query(+ query(environment,"SELECT * FROM scan_severity_assessments ORDER BY finding_id",),@@ -450,7 +428,7 @@ test("checkpoints each finding, resumes missing work, and reprocesses only the sconst revised = await classifyScanDirectorySeverity(scanDirectory, selected);expect(calls).toEqual(Array(3).fill(findings[0]!.findingId));expect(revised.assessments[0]!.decision).toBe("excluded");- const revisedRows = await query(+ const revisedRows = query(environment,"SELECT * FROM scan_severity_assessments ORDER BY finding_id",);@@ -479,7 +457,7 @@ test("checkpoints each finding, resumes missing work, and reprocesses only the sclassifyScanDirectorySeverity(scanDirectory, selected),).rejects.toThrow("Interrupted model call");expect(- await query(+ query(environment,"SELECT * FROM scan_severity_assessments ORDER BY finding_id",),@@ -562,20 +540,14 @@ test("migration leaves unindexed legacy assessments incomplete until reclassifiefirst.scanDirectory,{ environment, codex: recordingClassifier().codex },);- await query(environment, "DROP TABLE scan_severity_assessments");+ query(environment, "DROP TABLE scan_severity_assessments");for (const table of ["finding_severity_assessments","scan_severity_classifications",]) {- await query(- environment,- `ALTER TABLE ${table} DROP COLUMN classification_runs`,- );+ query(environment, `ALTER TABLE ${table} DROP COLUMN classification_runs`);}- await query(- environment,- "DELETE FROM schema_migrations WHERE version IN (43, 52)",- );+ query(environment, "DELETE FROM schema_migrations WHERE version IN (43, 52)");expect(await readScanSeverityClassification(first.scanDirectory,@@ -586,7 +558,7 @@ test("migration leaves unindexed legacy assessments incomplete until reclassifie),).toEqual({ ...classification, classificationRuns: undefined });expect(- await query(+ query(environment,"SELECT version FROM schema_migrations WHERE version = 43",),@@ -613,7 +585,7 @@ test("migration leaves unindexed legacy assessments incomplete until reclassifie).assessments,).toEqual(classification.assessments);expect(- await query(+ query(environment,"SELECT version FROM schema_migrations WHERE version = 43",),@@ -626,7 +598,7 @@ test("changed rubric, context, or evidence invalidates matching checkpoints", asconst { codex, calls } = recordingClassifier();const options = { environment, rubricPath, codex };await classifyScanDirectorySeverity(scanDirectory, options);- const originalFindings = await query(+ const originalFindings = query(environment,"SELECT * FROM findings ORDER BY id",);@@ -666,9 +638,9 @@ test("changed rubric, context, or evidence invalidates matching checkpoints", ascalls.length = 0;await classifyScanDirectorySeverity(scanDirectory, withContext);expect(calls).toEqual(Array(3).fill(findings[0]!.findingId));- expect(- await query(environment, "SELECT * FROM findings ORDER BY id"),- ).toEqual(originalFindings);+ expect(query(environment, "SELECT * FROM findings ORDER BY id")).toEqual(+ originalFindings,+ );});test("classification refuses to store workflow state inside sealed scan artifacts", async () => {@@ -986,14 +958,11 @@ test("migrates existing databases without changing findings and reads older statenvironment,codex: recordingClassifier().codex,});- const original = await query(- environment,- "SELECT * FROM findings ORDER BY id",- );- await query(environment, "DROP TABLE scan_severity_assessments");- await query(environment, "DROP TABLE finding_severity_assessments");- await query(environment, "DROP TABLE scan_severity_classifications");- await query(+ const original = query(environment, "SELECT * FROM findings ORDER BY id");+ query(environment, "DROP TABLE scan_severity_assessments");+ query(environment, "DROP TABLE finding_severity_assessments");+ query(environment, "DROP TABLE scan_severity_classifications");+ query(environment,"DELETE FROM schema_migrations WHERE version IN (41, 43, 52)",);@@ -1006,7 +975,7 @@ test("migrates existing databases without changing findings and reads older stat).issues,).toHaveLength(2);expect(- await query(+ query(environment,"SELECT version FROM schema_migrations WHERE version = 41",),@@ -1016,14 +985,14 @@ test("migrates existing databases without changing findings and reads older statcodex: recordingClassifier().codex,});expect(- await query(+ query(environment,"SELECT version FROM schema_migrations WHERE version = 41",),).toEqual([{ version: 41 }]);- expect(- await query(environment, "SELECT * FROM findings ORDER BY id"),- ).toEqual(original);+ expect(query(environment, "SELECT * FROM findings ORDER BY id")).toEqual(+ original,+ );});test("classifying another scan preserves both recurring-finding assessments", async () => {@@ -1085,12 +1054,12 @@ test("default rubric replaces legacy inherited assessments and respects custom p"scan_severity_assessments","finding_severity_assessments",]) {- await query(+ query(environment,`UPDATE ${table} SET rubric_sha256 = NULL, source = 'existing-severity', level = 'high', rubric_label = NULL, confidence = NULL`,);}- await query(+ query(environment,"UPDATE scan_severity_classifications SET rubric_sha256 = NULL",);@@ -1164,7 +1133,7 @@ test("saved assessments bind their run count and invalidate changed or unrecorde"scan_severity_assessments","finding_severity_assessments",]) {- await query(environment, `UPDATE ${table} SET classification_runs = NULL`);+ query(environment, `UPDATE ${table} SET classification_runs = NULL`);}expect((@@ -1181,7 +1150,7 @@ test("saved assessments bind their run count and invalidate changed or unrecordeawait classifyScanDirectorySeverity(scanDirectory, { environment, codex });expect(calls).toHaveLength(6);expect(- await query(+ query(environment,`SELECT classification_runs FROM scan_severity_classifications WHERE scan_id = '${scanId}'`,),diff --git a/sdk/typescript/tests-ts/cli-authentication.test.ts b/sdk/typescript/tests-ts/cli-authentication.test.tsindex 612176e53..ab5def889 100644--- a/sdk/typescript/tests-ts/cli-authentication.test.ts+++ b/sdk/typescript/tests-ts/cli-authentication.test.ts@@ -1347,46 +1347,44 @@ describe("skill authentication", () => {},);- for (const nullAuth of [false, true]) {- test.each(["validate", "patch", "verify-fix"] as const)(- `%s forwards a provider's OpenAI-named key (null auth: ${nullAuth})`,- async (command) => {- const stdout = capture();- const stderr = capture();- const status = await runCodexSkillCommand(- [- "-e",- 'console.log(JSON.stringify({type:"item.completed",item:{type:"agent_message",text:JSON.stringify({key:process.env.OPENAI_API_KEY})}}))',- ],- {- command,- auth: "api-key",- modelProvider: "gateway",- codexOverrides: {- model_provider: "gateway",- model_providers: {- gateway: {- env_key: "OPENAI_API_KEY",- ...(nullAuth ? { auth: null } : {}),- },+ test.each([false, true])(+ "forwards a provider's OpenAI-named key to the child (null auth: %p)",+ async (nullAuth) => {+ const stdout = capture();+ const stderr = capture();+ const status = await runCodexSkillCommand(+ [+ "-e",+ 'console.log(JSON.stringify({type:"item.completed",item:{type:"agent_message",text:JSON.stringify({key:process.env.OPENAI_API_KEY})}}))',+ ],+ {+ command: "validate",+ auth: "api-key",+ modelProvider: "gateway",+ codexOverrides: {+ model_provider: "gateway",+ model_providers: {+ gateway: {+ env_key: "OPENAI_API_KEY",+ ...(nullAuth ? { auth: null } : {}),},},- stdout: stdout.stream,- stderr: stderr.stream,},- { command: process.execPath },- {- CODEX_HOME: join(stateDirectory, "ambient"),- OPENAI_API_KEY: "SYNTHETIC_PROVIDER_KEY",- },- );- expect(status, stderr.text()).toBe(0);- expect(JSON.parse(stdout.text())).toEqual({- key: "SYNTHETIC_PROVIDER_KEY",- });- },- );- }+ stdout: stdout.stream,+ stderr: stderr.stream,+ },+ { command: process.execPath },+ {+ CODEX_HOME: join(stateDirectory, "ambient"),+ OPENAI_API_KEY: "SYNTHETIC_PROVIDER_KEY",+ },+ );+ expect(status, stderr.text()).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual({+ key: "SYNTHETIC_PROVIDER_KEY",+ });+ },+ );test("rejects a missing custom provider API key before launch", async () => {const result = await runProviderSkill(stateDirectory, {@@ -1832,44 +1830,41 @@ describe("skill authentication", () => {},);- test.each(["validate", "patch", "verify-fix"] as const)(- "%s reads the login credential home",- async (command) => {- const environment = {- CODEX_HOME: join(stateDirectory, "ambient"),- CODEX_SECURITY_STATE_DIR: stateDirectory,- };- const credentialHome = await createCredentialHome();- await writeFile(- join(credentialHome, "auth.json"),- JSON.stringify({- auth_mode: "apikey",- OPENAI_API_KEY: "SYNTHETIC_STORED_KEY",- }),- { mode: 0o600 },- );- const stdout = capture();- const stderr = capture();- const script = `console.log(JSON.stringify({type:"item.completed",item:{type:"agent_message",text:JSON.stringify({home:process.env.CODEX_HOME,state:process.env.CODEX_SECURITY_STATE_DIR})}}))`;- expect(- await runCodexSkillCommand(- ["-e", script],- {- command,- auth: "auto",- stdout: stdout.stream,- stderr: stderr.stream,- },- { command: process.execPath },- environment,- ),- ).toBe(0);- expect(JSON.parse(stdout.text())).toEqual({- home: credentialHome,- state: stateDirectory,- });- },- );+ test("uses the login credential home for a skill launched with stored authentication", async () => {+ const environment = {+ CODEX_HOME: join(stateDirectory, "ambient"),+ CODEX_SECURITY_STATE_DIR: stateDirectory,+ };+ const credentialHome = await createCredentialHome();+ await writeFile(+ join(credentialHome, "auth.json"),+ JSON.stringify({+ auth_mode: "apikey",+ OPENAI_API_KEY: "SYNTHETIC_STORED_KEY",+ }),+ { mode: 0o600 },+ );+ const stdout = capture();+ const stderr = capture();+ const script = `console.log(JSON.stringify({type:"item.completed",item:{type:"agent_message",text:JSON.stringify({home:process.env.CODEX_HOME,state:process.env.CODEX_SECURITY_STATE_DIR})}}))`;+ expect(+ await runCodexSkillCommand(+ ["-e", script],+ {+ command: "validate",+ auth: "auto",+ stdout: stdout.stream,+ stderr: stderr.stream,+ },+ { command: process.execPath },+ environment,+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual({+ home: credentialHome,+ state: stateDirectory,+ });+ });test.each(["validate", "patch", "verify-fix"])("%s rejects missing explicit API-key authentication before launch",diff --git a/sdk/typescript/tests-ts/cli-export.test.ts b/sdk/typescript/tests-ts/cli-export.test.tsindex 8f9c2e804..5cc603379 100644--- a/sdk/typescript/tests-ts/cli-export.test.ts+++ b/sdk/typescript/tests-ts/cli-export.test.ts@@ -261,8 +261,8 @@ describe("CLI", () => {await chmod(join(scanDir, "exports"), 0o500);}- for (const selector of [["--scan", scanId.slice(0, 8)], []]) {- const result = await runCommand(+ const exportModel = (...selector: string[]) =>+ runCommand(process.execPath,[join(import.meta.dir, "../src/cli.ts"),@@ -277,6 +277,9 @@ describe("CLI", () => {],{ cwd: repository, env: environment, timeout: 30_000 },);+ const selectors = [[], ["--scan", scanId.slice(0, 8)]];+ for (const selector of selectors) {+ const result = await exportModel(...selector);expect(result.stderr).toBe("");expect(result.status).toBe(0);expect(result.stdout).toStartWith(content);@@ -314,22 +317,8 @@ describe("CLI", () => {const changed = JSON.parse(await readFile(manifestPath, "utf8"));changed.scan.threatModel.content = "# Changed after completion\n";await writeFile(manifestPath, JSON.stringify(changed));- for (const selector of [["--scan", scanId.slice(0, 8)], []]) {- const rejected = await runCommand(- process.execPath,- [- join(import.meta.dir, "../src/cli.ts"),- "export",- ...selector,- "--artifact",- "threat-model",- "--output",- "-",- "--python",- python,- ],- { cwd: repository, env: environment, timeout: 30_000 },- );+ for (const selector of selectors) {+ const rejected = await exportModel(...selector);expect(rejected.status).toBe(2);expect(rejected.stdout).toBe("");expect(rejected.stderr).toContain("manifest changed after completion");@@ -1085,34 +1074,15 @@ describe("CLI", () => {}});- test("reports strict export failures without a stack trace", async () => {+ test("preserves strict export diagnostics without a stack trace", async () => {const { stdout, stderr, runCli } = createCliTest(main);-- const deps = dependencies();- deps.exportFindings = async () => {- throw new CodexSecurityError(- "manifest.scan: SARIF projection requires a sealed scan",- );- };- expect(await runCli(["export", "scan", "--output", "-"], deps)).toBe(2);- expect(stdout.text()).toBe("");- expect(stderr.text()).toBe(- "codex-security: manifest.scan: SARIF projection requires a sealed scan\n",- );- });-- test("preserves caught export failures", async () => {- const { stdout, stderr, runCli } = createCliTest(main);-+ const diagnostic = `manifest.scan: SARIF projection requires a sealed scan ${SYNTHETIC_CREDENTIALS}`;const deps = dependencies();deps.exportFindings = async () => {- throw new CodexSecurityError(`export failed ${SYNTHETIC_CREDENTIALS}`);+ throw new CodexSecurityError(diagnostic);};-expect(await runCli(["export", "scan", "--output", "-"], deps)).toBe(2);expect(stdout.text()).toBe("");- expect(stderr.text()).toBe(- `codex-security: export failed ${SYNTHETIC_CREDENTIALS}\n`,- );+ expect(stderr.text()).toBe(`codex-security: ${diagnostic}\n`);});});diff --git a/sdk/typescript/tests-ts/cli-feedback.test.ts b/sdk/typescript/tests-ts/cli-feedback.test.tsindex a5bfd908a..099dcdeaf 100644--- a/sdk/typescript/tests-ts/cli-feedback.test.ts+++ b/sdk/typescript/tests-ts/cli-feedback.test.ts@@ -1,13 +1,16 @@-import { PLUGIN_ROOT } from "./plugin-root.js";-import { spawnSync } from "node:child_process";+import { Database } from "bun:sqlite";import { mkdir, rm } from "node:fs/promises";import { join } from "node:path";import { expect, mock, test } from "bun:test";import { main } from "../src/cli.js";import type { JsonObject } from "../src/config.js";-import { resolvePluginPython, runWorkbench } from "../src/runtime.js";-import { dependencies, FakeSignals } from "./cli-fixtures.js";+import { resolvePluginPython } from "../src/runtime.js";import { temporaryDirectory } from "./support/temporary-directories.js";+import {+ scanRegistrationArguments,+ workbenchCommand,+} from "./support/workbench-command.js";+import { dependencies, FakeSignals } from "./cli-fixtures.js";import { rejecting, throwing } from "./support/errors.js";import { createCliTest } from "./support/cli-run.js";@@ -20,94 +23,62 @@ async function run(args: string[], deps = dependencies()) {test("feedback selects the newest saved scan when starts differ by a microsecond", async () => {const root = await temporaryDirectory("feedback-history-", true);+ const repository = join(root, "repository");+ const state = join(root, "state");try {- const python = await resolvePluginPython();- const repository = join(root, "repository");- const environment = {- PATH: process.env["PATH"],- CODEX_SECURITY_STATE_DIR: join(root, "state"),- };- const workbench = (args: readonly string[]) =>- runWorkbench({ python, pluginRoot: PLUGIN_ROOT, environment }, args);- const scans: { scanId: string; status: string; startedAt: string }[] = [];- for (const [index, status] of ["running", "failed", "running"].entries()) {- const target = index === 2 ? join(root, "other-repository") : repository;- const scanDir = join(root, `scan-${index}`);+ const workbench = workbenchCommand(await resolvePluginPython(), state);+ const ids: string[] = [];+ for (const [target, startedAt, status] of [+ [repository, "2026-01-01T00:00:00Z", "running"],+ [repository, "2026-01-01T00:00:00.000001Z", "failed"],+ [join(root, "other"), "2026-01-02T00:00:00Z", "running"],+ ] as const) {+ const directory = join(root, `scan-${ids.length}`);await mkdir(target, { recursive: true });- await mkdir(scanDir, { mode: 0o700 });- const registered = await workbench([- "register-cli-scan",- "--repository",- target,- "--scan-dir",- scanDir,- "--recipe-json",- JSON.stringify({- config: {},- mode: "standard",- repository: target,- target: { kind: "repository", paths: [] },- }),- ]);- scans.push({- scanId: registered["scanId"] as string,+ await mkdir(directory, { mode: 0o700 });+ const scan = await workbench(+ scanRegistrationArguments(target, directory),+ );+ const id = scan["scanId"] as string;+ ids.push(id);+ using db = new Database(join(state, "workbench.sqlite3"));+ db.query("UPDATE scans SET started_at = ?, status = ? WHERE id = ?").run(+ startedAt,status,- startedAt: [- "2026-01-01T00:00:00Z",- "2026-01-01T00:00:00.000001Z",- "2026-01-02T00:00:00Z",- ][index]!,- });+ id,+ );}- const seeded = spawnSync(- python,- [- "-c",- `import json, sqlite3, sys-with sqlite3.connect(sys.argv[1]) as connection:- for scan in json.loads(sys.argv[2]):- connection.execute("UPDATE scans SET started_at = ?, status = ? WHERE id = ?", (scan["startedAt"], scan["status"], scan["scanId"]))`,- join(environment.CODEX_SECURITY_STATE_DIR, "workbench.sqlite3"),- JSON.stringify(scans),- ],- { encoding: "utf8" },- );- expect(seeded.stderr).toBe("");- expect(seeded.status).toBe(0);- const history = await workbench(["list-scans", "--repository", repository]);- expect(- (history["scans"] as JsonObject[]).map((scan) => scan["scanId"]),- ).toEqual([scans[0]!.scanId, scans[1]!.scanId]);const deps = dependencies({currentDirectory: repository,- environment,- onWorkbench: workbench,+ onWorkbench: async (args) => {+ const result = await workbench(args);+ if (args[0] === "list-scans") {+ expect(+ (result["scans"] as JsonObject[]).map((scan) => scan["scanId"]),+ ).toEqual(ids.slice(0, 2));+ }+ return result;+ },+ });+ deps.sendFeedback = async ({ scan, includeLogs }) => ({+ feedbackId: "feedback-1",+ scanId: scan!.scanId,+ includedLogs: includeLogs,});- deps.sendFeedback = async ({ scan }) => {- expect(scan?.scanId).toBe(scans[1]!.scanId);- return {- feedbackId: "feedback-1",- scanId: scan!.scanId,- includedLogs: true,- };- };const result = await run(["--reason", "Scan stopped", "--include-logs", "--json"],deps,);- expect(result.code).toBe(0);+ expect(result.code, result.stderr).toBe(0);expect(result.stderr).toBe("");- expect(JSON.parse(result.stdout).scanId).toBe(scans[1]!.scanId);+ expect(JSON.parse(result.stdout).scanId).toBe(ids[1]);} finally {await rm(root, { recursive: true, force: true });}});test.each([- ["2026-10-08T01:00:00Z", "2026-10-08T01:00:00.100000Z", 1],- ["2026-10-08T01:00:00.000001Z", "2026-10-08T01:00:00.000002Z", 1],["2026-10-08T01:00:00.1234567Z", "2026-10-08T01:00:00.1234568Z", 1],- ["2026-10-08T03:00:00.123400+02:00", "2026-10-08T01:00:00.123401Z", 1],["1969-12-31T23:59:59.000001Z", "1969-12-31T23:59:59.000002Z", 1],["2026-10-08T01:00:00.000000Z", "2026-10-08T01:00:00Z", 0],["2026-10-08T01:00:00.1000000Z", "2026-10-08T03:00:00.1+02:00", 0],@@ -145,8 +116,10 @@ test.each([expect(result.code).toBe(0);expect(result.stderr).toBe("");expect(JSON.parse(result.stdout).scanId).toBe(expected.scanId);- expect(calls.map((args) => args[0])).toEqual(["list-scans", "get-scan"]);- expect(calls[1]).toEqual(["get-scan", "--scan-id", expected.scanId]);+ expect(calls).toEqual([+ ["list-scans", "--repository", deps.currentDirectory()],+ ["get-scan", "--scan-id", expected.scanId],+ ]);},);diff --git a/sdk/typescript/tests-ts/cli-help.test.ts b/sdk/typescript/tests-ts/cli-help.test.tsindex 4ee0c3d99..12b96cbb9 100644--- a/sdk/typescript/tests-ts/cli-help.test.ts+++ b/sdk/typescript/tests-ts/cli-help.test.ts@@ -1,8 +1,8 @@import { describe, expect, test } from "bun:test";import { main } from "../src/cli.js";+import { DEFAULT_CODEX_CONFIG, scanModelConfiguration } from "../src/config.js";import { DEFAULT_DEEP_SCAN_SETTINGS } from "../src/deep-scan-defaults.js";import { capture, dependencies } from "./cli-fixtures.js";-import { captureCli } from "./support/cli-run.js";async function help(args: readonly string[], columns?: number) {const stdout = capture(true);@@ -58,13 +58,11 @@ describe("CLI help", () => {if (command !== "scan") {expect(option(text, "--verification-mode")).toContain("static");expect(option(text, "--verification-mode")).toContain("standard");- const schema = captureCli(main, "stdout");- expect(- await schema.run([command, "--schema", "--json"], dependencies()),- ).toBe(0);- expect(- JSON.parse(schema.text()).options.properties.verificationMode.enum,- ).toEqual(["static", "standard"]);+ const schema = JSON.parse(await help([command, "--schema", "--json"]));+ expect(schema.options.properties.verificationMode.enum).toEqual([+ "static",+ "standard",+ ]);}},);@@ -95,6 +93,7 @@ describe("CLI help", () => {test("shows semantic values, repeatable inputs, choices, and scan defaults", async () => {const text = await help(["scan", "--help"]);+ expect(text).toContain("Usage: codex-security scan [repository]");expect(text).not.toMatch(/<(?:array|string|number)>/u);expect(option(text, "--path")).toContain("<path>");expect(option(text, "--path")).toMatch(/repeat/iu);@@ -108,24 +107,40 @@ describe("CLI help", () => {expect(option(text, "--mode")).toContain("standard");expect(option(text, "--mode")).toContain("deep");expect(option(text, "--provider")).toContain("amazon-bedrock");+ for (const label of [+ "--model <model>",+ "--provider <provider>",+ "--effort <effort>",+ "--max-time-hours <hours>",+ "--max-time <minutes>",+ ])+ expect(text).toContain(label);+ const { model, reasoningEffort } =+ scanModelConfiguration(DEFAULT_CODEX_CONFIG);+ expect(text).toContain(model);+ expect(text).toContain(reasoningEffort);+ expect(text).toContain('model_reasoning_effort="high"');+ expect(text).toContain("CODEX_SECURITY_STATE_DIR");+ expect(text).not.toContain("openai:gpt");+ expect(text).toContain("--path src --path tests");+ expect(text).not.toContain("codex-security scan . --path src,tests");+ expect(text).toMatch(+ /^ codex-security scan \. --working-tree(?:\s+#.*)?$/mu,+ );for (const [flag, value] of [["--workers", DEFAULT_DEEP_SCAN_SETTINGS.workers],["--subagents", DEFAULT_DEEP_SCAN_SETTINGS.subagents],["--stop-after-no-new", DEFAULT_DEEP_SCAN_SETTINGS.stopAfterNoNew],["--max-discovery-runs", DEFAULT_DEEP_SCAN_SETTINGS.maxDiscoveryRuns],] as const) {+ expect(option(text, flag)).toContain("<count>");expect(option(text, flag)).toMatch(new RegExp(`default: ${value}\\b`, "iu"),);}});- test("uses repeatable flags and bare booleans in copyable examples", async () => {- const scan = await help(["scan", "--help"]);- expect(scan).toContain("--path src --path tests");- expect(scan).toMatch(- /^ codex-security scan \. --working-tree(?:\s+#.*)?$/mu,- );+ test("uses bare booleans in copyable publish examples", async () => {const publish = await help(["publish", "scan", "--help"]);expect(publish).not.toMatch(/--dry-run true\b/u);expect(publish).toMatch(@@ -153,11 +168,8 @@ describe("CLI help", () => {const text = await help([command, "--help"]);expect(option(text, "--format")).not.toMatch(/\bjsonl?\b/u);expect(option(text, "--json")).toBe("");- const schema = captureCli(main, "stdout");- expect(- await schema.run([command, "--schema", "--json"], dependencies()),- ).toBe(0);- expect(JSON.parse(schema.text())).toEqual(expect.any(Object));+ const schema = JSON.parse(await help([command, "--schema", "--json"]));+ expect(schema).toEqual(expect.any(Object));},);@@ -172,7 +184,13 @@ describe("CLI help", () => {test("documents raw export formats without promising output transforms", async () => {const text = await help(["export", "--help"]);+ expect(text).toContain("Usage: codex-security export [scan-dir]");+ expect(text).toContain("--artifact <artifact>");+ expect(text).toContain("--scan <scan-id>");+ expect(text).toContain("--source-root <path>");+ expect(text).toContain("threatmodel.md");expect(option(text, "--export-format")).toContain("<format>");+ expect(option(text, "--export-format")).toContain("sarif");for (const flag of ["--format","--json",@@ -258,13 +276,19 @@ describe("CLI help", () => {test.each([60, 80])("wraps descriptions at %i columns without breaking examples",async (columns) => {- for (const command of [- [],- ["scan"],- ["login"],- ["publish", "scan"],- ["scan", "import"],- ]) {+ for (const [command, examples] of [+ [[], []],+ [["scan"], [/^ codex-security scan \.(?:\s+#.*)?$/mu]],+ [+ ["login"],+ [+ /^ ssh -L 1455:localhost:1455 user@remote$/mu,+ /^ codex-security login$/mu,+ ],+ ],+ [["publish", "scan"], []],+ [["scan", "import"], []],+ ] as const) {const text = await help([...command, "--help"], columns);expect(text).not.toMatch(/\u001b\[/u);for (const line of text.split("\n")) {@@ -280,12 +304,8 @@ describe("CLI help", () => {Math.max(columns, indent + longestToken),);}+ for (const example of examples) expect(text).toMatch(example);}- const text = await help(["scan", "--help"], columns);- expect(text).toMatch(/^ codex-security scan \.(?:\s+#.*)?$/mu);- const login = await help(["login", "--help"], columns);- expect(login).toMatch(/^ ssh -L 1455:localhost:1455 user@remote$/mu);- expect(login).toMatch(/^ codex-security login$/mu);},);});diff --git a/sdk/typescript/tests-ts/cli-policy.test.ts b/sdk/typescript/tests-ts/cli-policy.test.tsindex a99c9da2c..24172d812 100644--- a/sdk/typescript/tests-ts/cli-policy.test.ts+++ b/sdk/typescript/tests-ts/cli-policy.test.ts@@ -457,23 +457,6 @@ describe("policy CLI", () => {expect(await readFile(draft.draftPath, "utf8")).toBe(POLICY);});- test.each(["json", "md", "toon"])(- "does not run a diff preview for %s output",- async (format) => {- const f = await fixture();- const stdout = captureCli(main, "stdout");- let previews = 0;- expect(- await stdout.run(- ["policy", "--format", format],- policyDependencies(f, { onPreview: () => previews++ }),- ),- ).toBe(0);- expect(previews).toBe(0);- expect(stdout.text().length).toBeGreaterThan(0);- },- );-test("asks owner questions and previews the exact draft without writing source", async () => {const f = await fixture();const stderr = capture(true);@@ -678,7 +661,8 @@ describe("policy CLI", () => {path: scope,run: async (stage) => stageResult(stage, content, note),});- const deps = policyDependencies(f, { draft });+ const onPreview = mock();+ const deps = policyDependencies(f, { draft, onPreview });const create = deps.createPolicySecurity;deps.createPolicySecurity = (config) => {const security = create(config);@@ -706,6 +690,7 @@ describe("policy CLI", () => {const markdown = captureCli(main, "stdout");expect(await markdown.run(["policy", "--format", "md"], deps)).toBe(0);expect(markdown.text()).toBe(content);+ expect(onPreview).not.toHaveBeenCalled();});test("marks failed generation and cancellation envelopes as errors", async () => {diff --git a/sdk/typescript/tests-ts/cli-project-config.test.ts b/sdk/typescript/tests-ts/cli-project-config.test.tsindex 800715c97..3fa014281 100644--- a/sdk/typescript/tests-ts/cli-project-config.test.ts+++ b/sdk/typescript/tests-ts/cli-project-config.test.ts@@ -1,5 +1,4 @@import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";-import { execFileSync } from "node:child_process";import { join } from "node:path";import { pathToFileURL } from "node:url";import { afterEach, expect, test, mock } from "bun:test";@@ -19,6 +18,7 @@ import {} from "../src/config.js";import type { ProjectConfigInput } from "../src/project-config-schema.js";import { readProjectConfig } from "../src/project-config.js";+import { git } from "./git-fixture.js";import { dependencies, fakeResult, fakeSecurity } from "./cli-fixtures.js";import { createApiTestFixtures } from "./support/temporary-directories.js";import { copyCompletedScanFixture } from "./plugin-root.js";@@ -62,26 +62,16 @@ async function bulkInventory(input: Awaited<ReturnType<typeof fixture>>,rowModes: readonly string[],) {- execFileSync("git", ["init", "-q", input.repository]);- execFileSync("git", [- "-C",+ git(input.repository, "init", "-q");+ git(input.repository,- "-c",- "user.name=Test",- "-c",- "[email protected]",- "-c",- "commit.gpgsign=false","commit",+ "--no-gpg-sign","--allow-empty","-qm","fixture",- ]);- const revision = execFileSync(- "git",- ["-C", input.repository, "rev-parse", "HEAD"],- { encoding: "utf8" },- ).trim();+ );+ const revision = git(input.repository, "rev-parse", "HEAD");const csv = join(input.root, "repositories.csv");await writeFile(csv,@@ -505,30 +495,11 @@ test("bulk scans apply config and linked operator prompts, preserve CSV scope ovjoin(input.repository, "lib", "index.ts"),"export const value = 2;\n",);- for (const args of [- ["init", "-q", input.repository],- ["-C", input.repository, "config", "--local", "core.autocrlf", "false"],- ["-C", input.repository, "add", "."],- [- "-C",- input.repository,- "-c",- "user.name=Test",- "-c",- "[email protected]",- "-c",- "commit.gpgsign=false",- "commit",- "-qm",- "fixture",- ],- ])- execFileSync("git", args);- const revision = execFileSync(- "git",- ["-C", input.repository, "rev-parse", "HEAD"],- { encoding: "utf8" },- ).trim();+ git(input.repository, "init", "-q");+ git(input.repository, "config", "--local", "core.autocrlf", "false");+ git(input.repository, "add", ".");+ git(input.repository, "commit", "--no-gpg-sign", "-qm", "fixture");+ const revision = git(input.repository, "rev-parse", "HEAD");const csv = join(input.root, "repositories.csv");await writeFile(csv,diff --git a/sdk/typescript/tests-ts/cli-scan-failures.test.ts b/sdk/typescript/tests-ts/cli-scan-failures.test.tsindex ba66831e8..3ad2e6522 100644--- a/sdk/typescript/tests-ts/cli-scan-failures.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-failures.test.ts@@ -3,6 +3,7 @@ import { main } from "../src/cli.js";import { CodexSecurityError } from "../src/index.js";import {FakeSignals,+ SYNTHETIC_CREDENTIALS,capture,dependencies,fakePreflight,@@ -64,116 +65,104 @@ function expectFailure(}}-for (const formatArgs of [- ["--json"],- ["--format", "json"],- ["--format", "jsonl"],-]) {- for (const fullOutput of [false, true]) {- describe(`scan failures with ${formatArgs.join(" ")}${fullOutput ? " --full-output" : ""}`, () => {- const flags = [...formatArgs, ...(fullOutput ? ["--full-output"] : [])];+for (const flags of [["--json"], ["--format", "jsonl", "--full-output"]]) {+ describe(`scan failures with ${flags.join(" ")}`, () => {+ const fullOutput = flags.includes("--full-output");- test.each(commands)(- "formats %s execution failures consistently",- async (_name, command) => {- const stdout = capture();- const stderr = capture();- const message =- "network failure ECONNRESET Bearer SYNTHETIC_TOKEN_123";- expect(- await main(- [...command, ...flags],- stdout.stream,- stderr.stream,- failingScan(message),- ),- ).toBe(2);- expectFailure(stdout.text(), fullOutput, "SCAN_FAILED", message);- expect(stderr.text()).toContain(`${message}\n`);- },- );-- test.each([- ["rerun", "SCAN_REPLAY_UNAVAILABLE"],- ["resume", "SCAN_RESUME_UNAVAILABLE"],- ])("preserves %s preparation failure codes", async (command, code) => {+ test.each(commands)(+ "formats %s execution failures consistently",+ async (_name, command) => {const stdout = capture();const stderr = capture();- const message = "This scan does not have a saved launch recipe.";- const deps = scanDependencies();- deps.runWorkbench = async () => ({- scanId: "saved-scan",- scanDir: "/tmp/saved-scan",- });+ const message = `network failure ECONNRESET ${SYNTHETIC_CREDENTIALS}`;expect(await main(- ["scans", command, "saved-scan", ...flags],+ [...command, ...flags],stdout.stream,stderr.stream,- deps,+ failingScan(message),),).toBe(2);- expectFailure(stdout.text(), fullOutput, code, message);- expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ expectFailure(stdout.text(), fullOutput, "SCAN_FAILED", message);+ expect(stderr.text()).toContain(`${message}\n`);+ },+ );++ test.each([+ ["rerun", "SCAN_REPLAY_UNAVAILABLE"],+ ["resume", "SCAN_RESUME_UNAVAILABLE"],+ ])("preserves %s preparation failure codes", async (command, code) => {+ const stdout = capture();+ const stderr = capture();+ const message = "This scan does not have a saved launch recipe.";+ const deps = scanDependencies();+ deps.runWorkbench = async () => ({+ scanId: "saved-scan",+ scanDir: "/tmp/saved-scan",});+ expect(+ await main(+ ["scans", command, "saved-scan", ...flags],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ expectFailure(stdout.text(), fullOutput, code, message);+ expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ });++ test("reports unavailable latest scans with the replay failure code", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = scanDependencies();+ deps.runWorkbench = async () => ({ scans: [] });+ expect(+ await main(+ ["scans", "rerun", ...flags],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ const message = "No completed scans found for the current repository.";+ expectFailure(+ stdout.text(),+ fullOutput,+ "SCAN_REPLAY_UNAVAILABLE",+ message,+ );+ expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ });- test("reports unavailable latest scans with the replay failure code", async () => {+ test.each(["csv", "json"])(+ "formats rerun failures independently of the %s import format",+ async (format) => {const stdout = capture();const stderr = capture();+ const message = "The saved import source is unavailable.";const deps = scanDependencies();- deps.runWorkbench = async () => ({ scans: [] });+ deps.runWorkbench = async () => ({+ recipe: {+ import: { sourcePath: `/tmp/findings.${format}`, format },+ },+ });+ deps.importScan = async () => {+ throw new CodexSecurityError(message);+ };expect(await main(- ["scans", "rerun", ...flags],+ ["scans", "rerun", "saved-scan", ...flags],stdout.stream,stderr.stream,deps,),).toBe(2);- const message = "No completed scans found for the current repository.";- expectFailure(- stdout.text(),- fullOutput,- "SCAN_REPLAY_UNAVAILABLE",- message,- );+ expectFailure(stdout.text(), fullOutput, "SCAN_IMPORT_FAILED", message);expect(stderr.text()).toBe(`codex-security: ${message}\n`);- });-- test.each(["csv", "json"])(- "formats rerun failures independently of the %s import format",- async (format) => {- const stdout = capture();- const stderr = capture();- const message = "The saved import source is unavailable.";- const deps = scanDependencies();- deps.runWorkbench = async () => ({- recipe: {- import: { sourcePath: `/tmp/findings.${format}`, format },- },- });- deps.importScan = async () => {- throw new CodexSecurityError(message);- };- expect(- await main(- ["scans", "rerun", "saved-scan", ...flags],- stdout.stream,- stderr.stream,- deps,- ),- ).toBe(2);- expectFailure(- stdout.text(),- fullOutput,- "SCAN_IMPORT_FAILED",- message,- );- expect(stderr.text()).toBe(`codex-security: ${message}\n`);- },- );- });- }+ },+ );+ });}test.each(commands)(diff --git a/sdk/typescript/tests-ts/cli-scan-navigation.test.ts b/sdk/typescript/tests-ts/cli-scan-navigation.test.tsindex 672652cd7..4ce28c20b 100644--- a/sdk/typescript/tests-ts/cli-scan-navigation.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-navigation.test.ts@@ -17,17 +17,13 @@ describe("scan navigation", () => {test.each(["show", "logs"])("%s keeps saved output when optional navigation fails",async (command) => {- for (const failure of ["sync", "EPIPE", "ENOSPC"]) {- const result = await runCommand(process.execPath, [- join(import.meta.dir, "fixtures", "scan-navigation-output.mts"),- command,- failure,- ]);- expect(result.status, result.stderr).toBe(0);- expect(JSON.parse(result.stdout)).toMatchObject({ status: 0 });- expect(JSON.parse(result.stdout).output).toContain(completedId);- expect(result.stderr).toBe("");- }+ const result = await runCommand(process.execPath, [+ join(import.meta.dir, "fixtures", "scan-navigation-output.mts"),+ command,+ ]);+ expect(result.status, result.stderr).toBe(0);+ expect(result.stdout).toBe("sync\nEPIPE\nENOSPC\n");+ expect(result.stderr).toBe("");},);diff --git a/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts b/sdk/typescript/tests-ts/cli-scan-patch-settings.test.tsindex b9e3beabf..032eebd97 100644--- a/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts@@ -356,17 +356,6 @@ describe("inline patch service tier", () => {},);- test("preserves the scan native default over an ambient fast tier", async () => {- const child = await patchSettings([], {- homeConfig: 'service_tier = "fast"\n',- });- expect(child.argv).toContain('service_tier="default"');- expect(child.homeTier).toBe('"fast"');- expect(child.loginType).toBe("apiKey");- expect(child.approvalPolicy).toBe("never");- expect(child.sandbox).toBe("workspace-write");- });-test("keeps overlapping scan tiers and Daybreak settings isolated", async () => {let arrivals = 0;const { promise: ready, resolve: release } = Promise.withResolvers<void>();@@ -389,6 +378,11 @@ describe("inline patch service tier", () => {]);expect(children[0]!.argv).toContain('service_tier="fast"');expect(children[1]!.argv).toContain('service_tier="default"');+ expect(children[1]).toMatchObject({+ loginType: "apiKey",+ approvalPolicy: "never",+ sandbox: "workspace-write",+ });expect(children[0]!.argv).toContain("daybreak=true");expect(children[1]!.argv).toContain("daybreak=false");expect(children.map((child) => child.cyberAccessProgram)).toEqual([diff --git a/sdk/typescript/tests-ts/cli-scan-prompts.test.ts b/sdk/typescript/tests-ts/cli-scan-prompts.test.tsindex 9db116952..3b8e6cef2 100644--- a/sdk/typescript/tests-ts/cli-scan-prompts.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-prompts.test.ts@@ -1,9 +1,9 @@-import { spawnSync } from "node:child_process";import { mkdir, realpath, rm, symlink, writeFile } from "node:fs/promises";import { join } from "node:path";import { describe, expect, test, mock } from "bun:test";import { main } from "../src/cli.js";import { dependencies } from "./cli-fixtures.js";+import { git } from "./git-fixture.js";import { temporaryDirectory } from "./support/temporary-directories.js";import { runCapturedCli, captureCli } from "./support/cli-run.js";@@ -74,11 +74,12 @@ describe("CLI scan prompts", () => {process.platform === "win32" ? "junction" : "dir",);- for (const [option, property] of [- ["--scan-prompt-file", "scanPrompt"],- ["--validation-prompt-file", "validationPrompt"],- ["--post-scan-prompt-file", "postScanPrompt"],- ] as const) {+ const promptFlags = [+ "--scan-prompt-file",+ "--validation-prompt-file",+ "--post-scan-prompt-file",+ ];+ for (const option of promptFlags) {for (const [directory, target, input] of [[repository, ".", "linked-prompt.md"],[repository, ".", join("linked-directory", "external-prompt.md")],@@ -113,27 +114,34 @@ describe("CLI scan prompts", () => {expect(stderr.text()).not.toContain("SYNTHETIC_EXTERNAL_PROMPT");expect(onTurn).not.toHaveBeenCalled();}+ }- for (const [directory, target] of [- [repository, "."],- [physicalRepository, repositoryAlias],- [repositoryAlias, physicalRepository],- ] as const) {- let selected: unknown;- expect(- await runCapturedCli(- main,- ["scan", target, option, external, "--json"],- dependencies({- currentDirectory: directory,- onTurn: (_repository, value) => (selected = value),- }),- ),- ).toBe(0);- expect(selected).toMatchObject({- [property]: "SYNTHETIC_EXTERNAL_PROMPT\n",- });- }+ for (const [directory, target] of [+ [repository, "."],+ [physicalRepository, repositoryAlias],+ [repositoryAlias, physicalRepository],+ ] as const) {+ let selected: unknown;+ expect(+ await runCapturedCli(+ main,+ [+ "scan",+ target,+ ...promptFlags.flatMap((flag) => [flag, external]),+ "--json",+ ],+ dependencies({+ currentDirectory: directory,+ onTurn: (_repository, value) => (selected = value),+ }),+ ),+ ).toBe(0);+ expect(selected).toMatchObject({+ scanPrompt: "SYNTHETIC_EXTERNAL_PROMPT\n",+ validationPrompt: "SYNTHETIC_EXTERNAL_PROMPT\n",+ postScanPrompt: "SYNTHETIC_EXTERNAL_PROMPT\n",+ });}} finally {await rm(root, { recursive: true, force: true });@@ -144,30 +152,17 @@ describe("CLI scan prompts", () => {const root = await temporaryDirectory("codex-security-cli-prompts-");try {const repository = join(root, "repository");- for (const args of [- ["init", "-q", repository],- [- "-C",- repository,- "-c",- "[email protected]",- "-c",- "user.name=Test",- "-c",- "commit.gpgsign=false",- "commit",- "--allow-empty",- "-qm",- "initial",- ],- ]) {- expect(spawnSync("git", args, { encoding: "utf8" }).status).toBe(0);- }- const revision = spawnSync(- "git",- ["-C", repository, "rev-parse", "HEAD"],- { encoding: "utf8" },- ).stdout.trim();+ await mkdir(repository);+ git(repository, "init", "-q");+ git(+ repository,+ "commit",+ "--no-gpg-sign",+ "--allow-empty",+ "-qm",+ "initial",+ );+ const revision = git(repository, "rev-parse", "HEAD");await Promise.all([writeFile(join(root, "repositories.csv"),diff --git a/sdk/typescript/tests-ts/cli-scan-validation.test.ts b/sdk/typescript/tests-ts/cli-scan-validation.test.tsindex 9bea0bef5..02f26f180 100644--- a/sdk/typescript/tests-ts/cli-scan-validation.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-validation.test.ts@@ -35,16 +35,12 @@ import { throwing } from "./support/errors.js";import { temporaryDirectory } from "./support/temporary-directories.js";import { runTestInSubprocess } from "./support/test-subprocess.js";import { execNodePython } from "./support/python-probe.js";+import { scanRegistrationArguments } from "./support/workbench-command.js";describe("CLI scan validation preflight", () => {- test.each([- ["other head", false],- ["local changes", false],- ["other head", true],- ["local changes", true],- ] as const)(- "rejects committed diffs with %s before scanning (workflow: %p)",- async (checkout, workflow) => {+ test.each(["other head", "local changes"] as const)(+ "rejects committed diffs with %s before scanning with or without a workflow",+ async (checkout) => {const root = await temporaryDirectory("scan-validation-preflight-");try {const repository = join(root, "repository");@@ -65,33 +61,35 @@ describe("CLI scan validation preflight", () => {}const prepareRuntime = mock(throwing("Unexpected runtime setup"));const createCodex = mock(throwing("Unexpected model invocation"));- const { stdout, stderr, runCli } = createCliTest(main);- expect(- await runCli(- [- "scan",- repository,- "--diff",- base,- "--head",- head,- "--validate",- ...(workflow ? ["--workflow-id", "diff-validation"] : []),- "--json",- ],- {- ...dependencies({ currentDirectory: root }),- createSecurity: (config) =>- new TestClient(config, { prepareRuntime, createCodex }),- },- ),- ).toBe(2);- expect(JSON.parse(stdout.text())).toMatchObject({ status: "failed" });- expect(stderr.text()).toContain(- checkout === "other head"- ? "checkout to match the requested head revision"- : "clean repository checkout",- );+ for (const workflow of [false, true]) {+ const { stdout, stderr, runCli } = createCliTest(main);+ expect(+ await runCli(+ [+ "scan",+ repository,+ "--diff",+ base,+ "--head",+ head,+ "--validate",+ ...(workflow ? ["--workflow-id", "diff-validation"] : []),+ "--json",+ ],+ {+ ...dependencies({ currentDirectory: root }),+ createSecurity: (config) =>+ new TestClient(config, { prepareRuntime, createCodex }),+ },+ ),+ ).toBe(2);+ expect(JSON.parse(stdout.text())).toMatchObject({ status: "failed" });+ expect(stderr.text()).toContain(+ checkout === "other head"+ ? "checkout to match the requested head revision"+ : "clean repository checkout",+ );+ }expect(prepareRuntime).not.toHaveBeenCalled();expect(createCodex).not.toHaveBeenCalled();} finally {@@ -123,20 +121,10 @@ test.each([false, true])(protectedRoot: repository,});const workbench = { python, pluginRoot: PLUGIN_ROOT, environment };- const registered = await runWorkbench(workbench, [- "register-cli-scan",- "--repository",- repository,- "--scan-dir",- scanDir,- "--recipe-json",- JSON.stringify({- repository,- mode: "standard",- target: { kind: "repository", paths: [] },- config: {},- }),- ]);+ const registered = await runWorkbench(+ workbench,+ scanRegistrationArguments(repository, scanDir),+ );const base = fakeResult(["high"]);base.manifest.scan.id = String(registered["scanId"]);const result = new ScanResult({@@ -487,20 +475,7 @@ test("empty scan validation preserves configured Python and Git ignore rules", aawait symlink(repositoryGit, join(hostBin, `git${suffix}`), "file");const registered = await runWorkbench({ python, pluginRoot: PLUGIN_ROOT, environment: process.env },- [- "register-cli-scan",- "--repository",- repository,- "--scan-dir",- scanDir,- "--recipe-json",- JSON.stringify({- repository,- mode: "standard",- target: { kind: "repository", paths: [] },- config: {},- }),- ],+ scanRegistrationArguments(repository, scanDir),);const result = fakeResult();result.manifest.scan.id = String(registered["scanId"]);@@ -623,20 +598,10 @@ test("empty scan validation preserves knowledge-base Git exclusions", async () =selectedGit,),};- const registered = await runWorkbench(workbenchOptions, [- "register-cli-scan",- "--repository",- repository,- "--scan-dir",- scanDir,- "--recipe-json",- JSON.stringify({- repository,- mode: "standard",- target: { kind: "repository", paths: [] },- config: {},- }),- ]);+ const registered = await runWorkbench(+ workbenchOptions,+ scanRegistrationArguments(repository, scanDir),+ );expect(registered["targetRevision"]).toBe(trustedFallback ? revision : "unversioned",);diff --git a/sdk/typescript/tests-ts/cli-skill-chatgpt-provider-auth.test.ts b/sdk/typescript/tests-ts/cli-skill-chatgpt-provider-auth.test.tsindex e97265e8b..8df88c654 100644--- a/sdk/typescript/tests-ts/cli-skill-chatgpt-provider-auth.test.ts+++ b/sdk/typescript/tests-ts/cli-skill-chatgpt-provider-auth.test.ts@@ -68,25 +68,22 @@ function providerSettings(};}-// Exercise every configuration combination without repeatedly preparing a-// credential home and launching the same subprocess protocol.describe("skill authentication configuration", () => {test.each(- commandSources.flatMap(([command, source]) =>+ (["override", "ambient", "profile"] as const).flatMap((source) =>[true, false, undefined].flatMap((requiresOpenAiAuth) =>(["env_key", "bearer"] as const).map(- (credential) =>- [command, source, requiresOpenAiAuth, credential] as const,+ (credential) => [source, requiresOpenAiAuth, credential] as const,),),),)(- "%s removes the custom provider key and %s config for explicit ChatGPT auth (requires OpenAI: %p, credential: %s)",- (command, source, requiresOpenAiAuth, credential) => {+ "explicit ChatGPT auth removes the custom provider key from %s config (requires OpenAI: %p, credential: %s)",+ (source, requiresOpenAiAuth, credential) => {const { providerConfig, environment, overrides, ambientConfig } =providerSettings(source, requiresOpenAiAuth, credential);const options = {- command,+ command: "patch" as const,auth: "chatgpt" as const,codexOverrides: parseToml(overrides.join("\n")) as JsonObject,};diff --git a/sdk/typescript/tests-ts/cli-skills.test.ts b/sdk/typescript/tests-ts/cli-skills.test.tsindex 10ed52aac..365b04011 100644--- a/sdk/typescript/tests-ts/cli-skills.test.ts+++ b/sdk/typescript/tests-ts/cli-skills.test.ts@@ -1327,7 +1327,7 @@ describe("CLI skill commands", () => {}});- test("streams oversized skill prompts to a real child process", async () => {+ test("streams an oversized UTF-8 prompt through a real child and returns its full response", async () => {const input = "é日本語".repeat(256 * 1024 + 1);const stdout = capture();const stderr = capture();@@ -1469,21 +1469,6 @@ process.stdout.write(JSON.stringify({await expect(readSkillCommandOutput(oversizedResponse())).resolves.toEqual({message: largeResponse,});-- const stdout = capture();- const stderr = capture();- await expect(- runCodexSkillCommand(- [- "-e",- 'process.stdout.write(JSON.stringify({type:"item.completed",item:{type:"agent_message",text:"x".repeat(1024*1024+1)}})+"\\n")',- ],- { command: "validate", stdout: stdout.stream, stderr: stderr.stream },- { command: process.execPath },- ),- ).resolves.toBe(0);- expect(stdout.text()).toBe(`${"x".repeat(1024 * 1024 + 1)}\n`);- expect(stderr.text()).toBe("");});test("preserves skill failures and adds authentication advice without replacing details", () => {diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.tsindex 0daca1efd..ff54ec8fd 100644--- a/sdk/typescript/tests-ts/cli.test.ts+++ b/sdk/typescript/tests-ts/cli.test.ts@@ -63,7 +63,6 @@ import {dependencies,fakePreflight,fakeResult,- mustNotInitializeCodex,fakeSecurity,failingSecurity,fakeInterval,@@ -82,6 +81,17 @@ function scanDependencies(run: Parameters<typeof fakeSecurity>[0]) {return { ...dependencies(), createSecurity: () => fakeSecurity(run) };}+async function cliSchema(...command: string[]): Promise<unknown> {+ const stdout = captureCli(main, "stdout");+ expect(+ await stdout.run(+ [...command, "--schema", "--format", "json"],+ dependencies(),+ ),+ ).toBe(0);+ return JSON.parse(stdout.text());+}+const profileScenarios = [{overrides: [@@ -534,25 +544,17 @@ describe("CLI", () => {},);- test.each(- ["failure", "failure with cleanup failure", "SIGINT", "SIGTERM"].flatMap(- (signal) =>- (- [- ["json", false],- ["json", true],- ["jsonl", true],- ] as const- ).map(- ([format, fullOutput]) =>- [signal, format, fullOutput ? "full" : "plain"] as const,- ),- ),- )(- "retains completed assessments and stops patching after validation %s (%s, %s)",- async (signal, format, outputMode) => {+ test.each([+ ["failure", "json", false],+ ["failure", "json", true],+ ["failure with cleanup failure", "jsonl", true],+ ["SIGINT", "json", false],+ ["SIGINT", "json", true],+ ["SIGTERM", "jsonl", true],+ ] as const)(+ "retains assessments and stops patching after validation %s (%s, full output: %p)",+ async (signal, format, fullOutput) => {const validationFailed = signal.startsWith("failure");- const fullOutput = outputMode === "full";const root = await mkdtemp(join(tmpdir(), "scan-validation-partial-"));const repository = join(root, "repository");const scanDir = join(root, "scan");@@ -766,7 +768,7 @@ describe("CLI", () => {const stderr = capture();expect(await main([], root.stream, stderr.stream, dependencies())).toBe(0);expect(root.text()).toContain("Usage: codex-security <command>");- expect(root.text()).toContain("Aliases: cs");+ expect(root.text()).toContain("Integrations:");expect(root.text()).toContain("bulk-scan");expect(root.text()).toContain("install-hook");expect(root.text()).not.toContain("multiscan");@@ -775,14 +777,7 @@ describe("CLI", () => {expect(root.text()).toContain("--llms-full");expect(stderr.text()).toBe("");- const schema = captureCli(main, "stdout");- expect(- await schema.run(- ["scan", "--schema", "--format", "json"],- dependencies(),- ),- ).toBe(0);- const scanSchema = JSON.parse(schema.text()) as {+ const scanSchema = (await cliSchema("scan")) as {args: Record<string, unknown>;options: Record<string, unknown>;output?: {@@ -843,38 +838,17 @@ describe("CLI", () => {additionalProperties: false,});- const rerunSchema = captureCli(main, "stdout");- expect(- await rerunSchema.run(- ["scans", "rerun", "--schema", "--format", "json"],- dependencies(),- ),- ).toBe(0);- expect(JSON.parse(rerunSchema.text())).toMatchObject({+ expect(await cliSchema("scans", "rerun")).toMatchObject({args: { properties: { scanId: { type: "string" } } },options: { properties: { verbose: { type: "boolean" } } },});- const matchSchema = captureCli(main, "stdout");- expect(- await matchSchema.run(- ["scans", "match", "--schema", "--format", "json"],- dependencies(),- ),- ).toBe(0);- expect(JSON.parse(matchSchema.text())).toMatchObject({+ expect(await cliSchema("scans", "match")).toMatchObject({args: { properties: { beforeId: { type: "string" } } },options: { properties: { all: { type: "boolean" } } },});- const falsePositiveSchema = captureCli(main, "stdout");- expect(- await falsePositiveSchema.run(- ["findings", "false-positive", "--schema", "--format", "json"],- dependencies(),- ),- ).toBe(0);- expect(JSON.parse(falsePositiveSchema.text())).toMatchObject({+ expect(await cliSchema("findings", "false-positive")).toMatchObject({args: {properties: {occurrenceId: { type: "string", minLength: 1, maxLength: 256 },@@ -890,33 +864,25 @@ describe("CLI", () => {const manifest = captureCli(main, "stdout");expect(await manifest.run(["--llms"], dependencies())).toBe(0);- expect(manifest.text()).toContain("codex-security scan [repository]");- expect(manifest.text()).toContain(- "codex-security install-hook [repository]",- );- expect(manifest.text()).toContain("codex-security bulk-scan [input]");- expect(manifest.text()).toContain("codex-security export [scanDir]");- expect(manifest.text()).toContain(- "codex-security import github <repository>",- );- expect(manifest.text()).toContain("codex-security validate <findings...>");- expect(manifest.text()).toContain(- "codex-security verify-fix [findings...]",- );- expect(manifest.text()).toContain("codex-security patch [issues...]");- expect(manifest.text()).toContain(- "codex-security findings false-positive <occurrenceId>",- );- expect(manifest.text()).toContain("codex-security scans list [repository]");- expect(manifest.text()).toContain("codex-security scans show [scanId]");- expect(manifest.text()).toContain("codex-security scans rerun [scanId]");- expect(manifest.text()).toContain(- "codex-security scans match [beforeId] [afterId]",- );- expect(manifest.text()).toContain(- "codex-security scans compare [beforeId] [afterId]",- );- expect(manifest.text()).toContain("codex-security info");+ for (const usage of [+ "scan [repository]",+ "install-hook [repository]",+ "bulk-scan [input]",+ "export [scanDir]",+ "import github <repository>",+ "validate <findings...>",+ "verify-fix [findings...]",+ "patch [issues...]",+ "findings false-positive <occurrenceId>",+ "scans list [repository]",+ "scans show [scanId]",+ "scans rerun [scanId]",+ "scans match [beforeId] [afterId]",+ "scans compare [beforeId] [afterId]",+ "info",+ ]) {+ expect(manifest.text()).toContain(`codex-security ${usage}`);+ }const completions = captureCli(main, "stdout");expect(await completions.run(["completions", "bash"], dependencies())).toBe(@@ -966,17 +932,9 @@ describe("CLI", () => {for (const command of commands) {const help = captureCli(main, "stdout");- const schema = captureCli(main, "stdout");expect(await help.run([...command, "--help"], dependencies())).toBe(0);expect(help.text()).not.toMatch(/--[a-z][a-z0-9-]*[A-Z][A-Za-z0-9-]*/u);- expect(- await schema.run(- [...command, "--schema", "--format", "json"],- dependencies(),- ),- ).toBe(0);-- const definitions = JSON.parse(schema.text()) as {+ const definitions = (await cliSchema(...command)) as {args?: {properties?: Record<string, { description?: string }>;};@@ -1876,15 +1834,6 @@ describe("CLI", () => {]);});- test("reports when the current repository has no saved scans", async () => {- const stderr = captureCli(main, "stderr");-- expect(await stderr.run(["scans", "show"], dependencies())).toBe(2);- expect(stderr.text()).toContain(- "No completed scans found for the current repository.",- );- });-test.each([false, true])("does not emit an ok: true envelope for a failed structured history command with full output %p",async (fullOutput) => {@@ -3003,137 +2952,47 @@ describe("CLI", () => {});test("rejects structured modes before starting interactive Codex commands", async () => {- for (const [command, arguments_] of [- ["validate", ["finding"]],- ["login", []],- ["login", ["status"]],- ["logout", []],+ for (const [command, ...args] of [+ ["validate", "finding", "--json"],+ ["login", "--format", "json"],+ ["login", "status", "--format=jsonl"],+ ["logout", "--format", "jsonl"],+ ["logout", "--format=json"],] as const) {- for (const format of [- ["--json"],- ["--format", "json"],- ["--format=json"],- ["--format", "jsonl"],- ["--format=jsonl"],- ] as const) {- const onCodex = mock<() => number>().mockReturnValue(0);- const { stdout, stderr, runCli } = createCliTest(main, {- stderr: true,- });-- expect(- await runCli(- [command, ...arguments_, ...format],- dependencies({- onCodex,- }),- ),- ).toBe(2);- expect(onCodex).not.toHaveBeenCalled();- expect(stdout.text()).toBe("");- expect(stderr.text()).toContain(- `${command} does not support noninteractive JSON output; run it without --json, --format json, or --format jsonl.`,- );- }+ const onCodex = mock(() => 0);+ const { stdout, stderr, runCli } = createCliTest(main, { stderr: true });+ expect(await runCli([command, ...args], dependencies({ onCodex }))).toBe(+ 2,+ );+ expect(onCodex).not.toHaveBeenCalled();+ expect(stdout.text()).toBe("");+ expect(stderr.text()).toContain(+ `${command} does not support noninteractive JSON output; run it without --json, --format json, or --format jsonl.`,+ );}});test("rejects CSV stdout when JSON output is requested", async () => {- for (const exportFormat of [- ["--export-format", "csv"],- ["--export-format=csv"],- ["--exportFormat", "csv"],- ["--exportFormat=csv"],+ for (const flags of [+ ["--export-format", "csv", "--output", "-", "--json"],+ ["--export-format=csv", "--output=-", "--format", "json"],+ ["--exportFormat", "csv", "--output", "-", "--format=jsonl"],+ ["--exportFormat=csv", "--output=-", "--format", "jsonl"],]) {- for (const format of [- ["--json"],- ["--format", "json"],- ["--format=json"],- ["--format", "jsonl"],- ["--format=jsonl"],- ]) {- const exportFindings = mock(resolving(new Uint8Array()));- const { stdout, stderr, runCli } = createCliTest(main);- const deps = dependencies();- deps.exportFindings = exportFindings;-- expect(- await runCli(- ["export", "scan", ...exportFormat, "--output", "-", ...format],- deps,- ),- ).toBe(2);- expect(exportFindings).not.toHaveBeenCalled();- expect(stdout.text()).toBe("");- expect(stderr.text()).toContain(- "CSV stdout cannot be combined with JSON output",- );- }- }- });-- test("prints export help without initializing Codex", async () => {- const { stdout, stderr, runCli } = createCliTest(main);-- const deps = dependencies();- deps.createSecurity = mustNotInitializeCodex;- expect(await runCli(["export", "--help"], deps)).toBe(0);- expect(stdout.text()).toContain("Usage: codex-security export [scan-dir]");- expect(stdout.text()).toContain("--artifact <artifact>");- expect(stdout.text()).toContain("--scan <scan-id>");- expect(stdout.text()).toContain("--export-format <format>");- expect(stdout.text()).toContain("threatmodel.md");- expect(stdout.text()).toContain("--source-root <path>");- expect(stdout.text()).toContain("sarif");- expect(stdout.text()).not.toContain("--format {sarif}");- expect(stderr.text()).toBe("");- });-- test("uses Incur version and command help", async () => {- const version = capture();- const stderr = capture();- expect(- await main(["--version"], version.stream, stderr.stream, dependencies()),- ).toBe(0);- expect(version.text()).toBe(`${VERSION}\n`);- expect(stderr.text()).toBe("");-- const help = capture();- expect(- await main(- ["scan", "--help"],- help.stream,- stderr.stream,- dependencies(),- ),- ).toBe(0);- const text = help.text().replace(/\s+/gu, " ");- expect(text).toContain("Usage: codex-security scan [repository]");- for (const option of [- "--verbose",- "--path <path>",- "--max-cost <usd>",- "--show-cost",- "--workers <count>",- "--subagents <count>",- "--stop-after-no-new <count>",- "--max-discovery-runs <count>",- "--max-time-hours <hours>",- "--max-time <minutes>",- "--headless",- "--model <model>",- "--provider <provider>",- "--effort <effort>",- ]) {- expect(text).toContain(option);+ const exportFindings = mock(resolving(new Uint8Array()));+ const { stdout, stderr, runCli } = createCliTest(main);+ expect(+ await runCli(["export", "scan", ...flags], {+ ...dependencies(),+ exportFindings,+ }),+ ).toBe(2);+ expect(exportFindings).not.toHaveBeenCalled();+ expect(stdout.text()).toBe("");+ expect(stderr.text()).toContain(+ "CSV stdout cannot be combined with JSON output",+ );}- expect(text).toContain(DEFAULT_SCAN_MODEL_CONFIGURATION.model);- expect(text).toContain(DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort);- expect(text).toContain('model_reasoning_effort="high"');- expect(text).toContain("CODEX_SECURITY_STATE_DIR");- expect(text).not.toContain("openai:gpt");- expect(text).not.toContain("codex-security scan . --path src,tests");- expect(stderr.text()).toBe("");});test("documents existing model and reasoning options in bulk-scan help", async () => {@@ -3654,7 +3513,6 @@ describe("CLI", () => {],[["scan", "repo-a", "repo-b", "--dry-run"], "Unexpected positional"],[["findings", "false-positive"], "occurrenceId"],- [["findings", "false-positive", "occurrence-1"], "reason"],[["findings", "false-positive", "occurrence-1", "occurrence-2"],"Unexpected positional",@@ -4633,25 +4491,6 @@ describe("CLI", () => {expect(stderr.text()).toContain(message);});- test("preserves diagnostic text in full-output scan failures", async () => {- const { stdout, stderr, runCli } = createCliTest(main);-- const deps = dependencies();- deps.createSecurity = () =>- failingSecurity(`network failure ECONNRESET ${SYNTHETIC_CREDENTIALS}`);-- expect(await runCli(["scan", ".", "--json", "--full-output"], deps)).toBe(- 2,- );- expect(JSON.parse(stdout.text()).error).toEqual({- code: "SCAN_FAILED",- message: `network failure ECONNRESET ${SYNTHETIC_CREDENTIALS}`,- });- expect(stderr.text()).toContain(- `network failure ECONNRESET ${SYNTHETIC_CREDENTIALS}`,- );- });-test("surfaces underlying scanner errors instead of inventing a model outage", async () => {for (const message of ["Could not save the Codex Security scan: UNIQUE constraint failed: scans.scan_dir",diff --git a/sdk/typescript/tests-ts/contract.property.test.ts b/sdk/typescript/tests-ts/contract.property.test.tsindex f344f8831..1e73c72d3 100644--- a/sdk/typescript/tests-ts/contract.property.test.ts+++ b/sdk/typescript/tests-ts/contract.property.test.ts@@ -57,52 +57,4 @@ describe("canonical scan contract", () => {},);});-- test("rejects non-relative artifact paths before accepting a seal", async () => {- const scanDir = await copyExample();- const manifestPath = join(scanDir, "scan-manifest.json");- const manifest = await readJson<ScanManifest>(manifestPath);- const prefixes = ["../", "/", "C:/", "artifacts/../", "artifacts\\"];- await mkdir(join(scanDir, "artifacts"), { recursive: true });- await fc.assert(- fc.asyncProperty(- fc.stringMatching(/^[a-z]{1,16}$/u),- fc.constantFrom(...prefixes),- async (name, prefix) => {- const filename = `artifact-${name}`;- const bytes = Buffer.from(name);- const artifact = {- path: `artifacts/${filename}`,- sha256: sha256(bytes),- mediaType: "application/octet-stream",- };- const scan = {- ...manifest.scan,- artifacts: [...manifest.scan.artifacts, artifact],- };- await writeFile(join(scanDir, "artifacts", filename), bytes);- await writeJson(manifestPath, { ...manifest, scan });- await loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });-- artifact.path = `${prefix}${filename}`;- await writeJson(manifestPath, { ...manifest, scan });- const rejected = loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });- await expect(rejected).rejects.toBeInstanceOf(- ContractValidationError,- );- await expect(rejected).rejects.toThrow(- /safe scan-relative POSIX path|schema validation failed \(pattern/u,- );- },- ),- {- ...propertyOptions,- numRuns: Number(process.env["CODEX_SECURITY_PROPERTY_RUNS"] ?? "20"),- examples: [- ...prefixes.map((prefix): [string, string] => ["synthetic", prefix]),- ["con", "C:/"],- ],- },- );- });});diff --git a/sdk/typescript/tests-ts/contract.test.ts b/sdk/typescript/tests-ts/contract.test.tsindex ffae199a0..6893f2e3c 100644--- a/sdk/typescript/tests-ts/contract.test.ts+++ b/sdk/typescript/tests-ts/contract.test.ts@@ -67,36 +67,35 @@ function expectation(}describe("canonical scan contract", () => {- test.each(["report.md", "report.html", "exports/results.sarif"])(- "re-finalizing an imported bundle preserves sealed %s",- async (projection) => {- const scanDir = await copyExample();- const destination = join(scanDir, projection);- const content = "Synthetic externally sealed projection.\n";- await mkdir(dirname(destination), { recursive: true });- await writeFile(destination, content);- const manifestPath = join(scanDir, "scan-manifest.json");- const manifest = await readJson(manifestPath);+ test("re-finalizing an imported bundle preserves its sealed projections", async () => {+ const scanDir = await copyExample();+ const manifestPath = join(scanDir, "scan-manifest.json");+ const manifest = await readJson(manifestPath);+ const projections = ["report.md", "report.html", "exports/results.sarif"];+ for (const path of projections) {+ await mkdir(dirname(join(scanDir, path)), { recursive: true });+ await writeFile(join(scanDir, path), path);manifest["scan"].artifacts.push({- path: projection,- sha256: sha256(content),+ path,+ sha256: sha256(path),mediaType: "text/plain",});- await writeJson(manifestPath, manifest);- await loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });- const result = runPython(- process.env["PYTHON"] ?? Bun.which("python3") ?? "python",- [- join(PLUGIN_ROOT, "scripts", "finalize_scan_contract.py"),- "--scan-dir",- scanDir,- ],- );- expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);- expect(await readFile(destination, "utf8")).toBe(content);- await loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });- },- );+ }+ await writeJson(manifestPath, manifest);+ await loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });+ const result = runPython(+ process.env["PYTHON"] ?? Bun.which("python3") ?? "python",+ [+ join(PLUGIN_ROOT, "scripts", "finalize_scan_contract.py"),+ "--scan-dir",+ scanDir,+ ],+ );+ expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);+ for (const path of projections)+ expect(await readFile(join(scanDir, path), "utf8")).toBe(path);+ await loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });+ });test.each(["duplicate finding",@@ -900,45 +899,35 @@ describe("canonical scan contract", () => {});test("rejects unsafe Windows and traversal artifact paths", async () => {+ const scanDir = await copyExample();+ const path = join(scanDir, "scan-manifest.json");+ const manifest = await readJson(path);+ const invalidArtifact = {+ path: "",+ sha256: "0".repeat(64),+ mediaType: "text/plain",+ };+ manifest["scan"]["artifacts"].push(invalidArtifact);for (const unsafe of [+ "/escape","D:/escape","../escape",+ "artifacts/../escape","artifacts\\escape","artifacts/report?.json",- ]) {- const scanDir = await copyExample();- const path = join(scanDir, "scan-manifest.json");- const manifest = await readJson(path);- manifest["scan"]["artifacts"].push({- path: unsafe,- sha256: "0".repeat(64),- mediaType: "text/plain",- });- await writeJson(path, manifest);- await expect(- loadContract(scanDir, { pluginRoot: PLUGIN_ROOT }),- ).rejects.toThrow(ContractValidationError);- }-- for (const unsafe of ["artifacts/report.json.","artifacts/report.json ","artifacts/CON.txt"," ","\u00a0",]) {- const scanDir = await copyExample();- const path = join(scanDir, "scan-manifest.json");- const manifest = await readJson(path);- manifest["scan"]["artifacts"].push({- path: unsafe,- sha256: "0".repeat(64),- mediaType: "text/plain",- });+ invalidArtifact.path = unsafe;await writeJson(path, manifest);- await expect(- loadContract(scanDir, { pluginRoot: PLUGIN_ROOT }),- ).rejects.toThrow("safe scan-relative POSIX path");+ const rejected = loadContract(scanDir, { pluginRoot: PLUGIN_ROOT });+ await expect(rejected).rejects.toBeInstanceOf(ContractValidationError);+ await expect(rejected).rejects.toThrow(+ /safe scan-relative POSIX path|schema validation failed \(pattern/u,+ );}});diff --git a/sdk/typescript/tests-ts/deep-scan-workbench.test.ts b/sdk/typescript/tests-ts/deep-scan-workbench.test.tsindex d38ac725f..effcda5e5 100644--- a/sdk/typescript/tests-ts/deep-scan-workbench.test.ts+++ b/sdk/typescript/tests-ts/deep-scan-workbench.test.ts@@ -74,40 +74,7 @@ function runOwnershipProbe(probe: OwnershipProbe): Record<string, unknown> {>;}-test("copies a Deep Scan publication when the filesystem rejects hardlinks", async () => {- const root = await temporaryDirectories.create(- "codex-security-deep-publication-",- );- const source = join(root, "source.jsonl");- const destination = join(root, "destination.jsonl");- await writeFile(source, '{"finding":"synthetic"}\n');- const python =- process.env["PYTHON"] ?? Bun.which("python3") ?? Bun.which("python");- expect(python).not.toBeNull();-- const result = runPython(python!, [- "-c",- [- "import errno, sys",- "from pathlib import Path",- "sys.path.insert(0, sys.argv[1])",- "import deep_scan_workbench as deep_scan",- "def reject_hardlink(source, destination):",- " raise OSError(errno.ENOTSUP, 'hardlinks are unavailable')",- "deep_scan.os.link = reject_hardlink",- "deep_scan.create_publication_copy(Path(sys.argv[2]), Path(sys.argv[3]))",- ].join("\n"),- join(PLUGIN_ROOT, "scripts"),- source,- destination,- ]);-- expect(new TextDecoder().decode(result.stderr)).toBe("");- expect(result.exitCode).toBe(0);- expect(await readFile(destination, "utf8")).toBe('{"finding":"synthetic"}\n');-});--test("recovers an interrupted copied Deep Scan publication", async () => {+test("recovers an interrupted publication when the filesystem rejects hardlinks", async () => {const root = await temporaryDirectories.create("codex-security-deep-copy-recovery-",);@@ -118,7 +85,7 @@ test("recovers an interrupted copied Deep Scan publication", async () => {const result = runPython(python!, ["-c",[- "import json, shutil, sqlite3, sys",+ "import errno, json, sqlite3, sys","from pathlib import Path","sys.path.insert(0, sys.argv[1])","import deep_scan_workbench as deep_scan",@@ -130,9 +97,14 @@ test("recovers an interrupted copied Deep Scan publication", async () => {"ledger.parent.mkdir(parents=True)","snapshot.parent.mkdir(parents=True)","ledger.write_text('old ledger\\n', encoding='utf-8')",- "shutil.copy2(ledger, backup)",+ "def reject_hardlink(source, destination):",+ " raise OSError(errno.ENOTSUP, 'hardlinks are unavailable')",+ "deep_scan.os.link = reject_hardlink",+ "deep_scan.create_publication_copy(ledger, backup)","snapshot.write_text('new ledger\\n', encoding='utf-8')",- "shutil.copy2(snapshot, ledger)",+ "ledger.unlink()",+ "deep_scan.create_publication_copy(snapshot, ledger)",+ "assert ledger.read_bytes() == snapshot.read_bytes()","connection = sqlite3.connect(':memory:')","connection.row_factory = sqlite3.Row","connection.execute('CREATE TABLE scans (id TEXT PRIMARY KEY, scan_dir TEXT)')",@@ -362,106 +334,50 @@ describe("deep scan workbench ownership", () => {);});- test.each([- [undefined, 96],- [0.5, 0.5],- [96, 96],- ] as const)(- "resolves the configured discovery deadline %p as %p hours",- async (configuredHours, expectedHours) => {- const root = await temporaryDirectories.create(- "codex-security-deep-deadline-config-",- );- const codexHome = join(root, "codex-home");- const configDirectory = join(codexHome, "codex-security");- await mkdir(configDirectory, { recursive: true });- await writeFile(- join(configDirectory, "config.toml"),- `[deep_scan]\n${configuredHours === undefined ? "" : `max_time_hours = ${configuredHours}\n`}`,- );-- const python = Bun.which("python3") ?? Bun.which("python");- expect(python).not.toBeNull();- const result = runPython(- python!,- [- join(PLUGIN_ROOT, "scripts", "deep_scan_config.py"),- "--available-parallelism",- "8",- ],- { env: { ...process.env, CODEX_HOME: codexHome } },- );- expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);- expect(JSON.parse(new TextDecoder().decode(result.stdout))).toMatchObject(- {- maxTimeHours: expectedHours,- },- );- },- );-- test("loads an explicitly isolated Deep Scan configuration", async () => {+ test("the bundled config command reads an isolated config and reports invalid deadlines", async () => {const root = await temporaryDirectories.create(- "codex-security-deep-isolated-config-",+ "codex-security-deep-config-",);const codexHome = join(root, "codex-home");const sharedConfig = join(codexHome, "codex-security", "config.toml");const isolatedConfig = join(root, "isolated-deep-scan.toml");await mkdir(dirname(sharedConfig), { recursive: true });await writeFile(sharedConfig, "[deep_scan]\nworkers = 2\n");- await writeFile(isolatedConfig, "[deep_scan]\nworkers = 7\n");- const python = Bun.which("python3") ?? Bun.which("python");- expect(python).not.toBeNull();-- const result = runPython(- python!,- [- join(PLUGIN_ROOT, "scripts", "deep_scan_config.py"),- "--available-parallelism",- "8",- ],- {- env: {- ...process.env,- CODEX_HOME: codexHome,- CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH: isolatedConfig,- },- },- );-- expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);- expect(JSON.parse(new TextDecoder().decode(result.stdout))).toMatchObject({- workers: 7,- });- });-- test("rejects invalid discovery deadlines before returning scan configuration", async () => {- const root = await temporaryDirectories.create(- "codex-security-deep-invalid-deadline-",+ await writeFile(+ isolatedConfig,+ "[deep_scan]\nworkers = 7\nmax_time_hours = 0.5\n",);- const codexHome = join(root, "codex-home");- const configDirectory = join(codexHome, "codex-security");- const configPath = join(configDirectory, "config.toml");- await mkdir(configDirectory, { recursive: true });const python = Bun.which("python3") ?? Bun.which("python");expect(python).not.toBeNull();-- for (const hours of ["0", "-0.5", "true", '"2"', "nan", "inf", "96.5"]) {- await writeFile(configPath, `[deep_scan]\nmax_time_hours = ${hours}\n`);- const result = runPython(+ const readConfig = () =>+ runPython(python!,[join(PLUGIN_ROOT, "scripts", "deep_scan_config.py"),"--available-parallelism","8",],- { env: { ...process.env, CODEX_HOME: codexHome } },- );- expect(result.exitCode).not.toBe(0);- expect(new TextDecoder().decode(result.stderr)).toContain(- "deep_scan.max_time_hours must be a positive finite number no greater than 96",+ {+ env: {+ ...process.env,+ CODEX_HOME: codexHome,+ CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH: isolatedConfig,+ },+ },);- }+ const result = readConfig();+ expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);+ expect(JSON.parse(new TextDecoder().decode(result.stdout))).toMatchObject({+ workers: 7,+ maxTimeHours: 0.5,+ });++ await writeFile(isolatedConfig, "[deep_scan]\nmax_time_hours = 96.5\n");+ const invalid = readConfig();+ expect(invalid.exitCode).not.toBe(0);+ expect(new TextDecoder().decode(invalid.stderr)).toContain(+ "deep_scan.max_time_hours must be a positive finite number no greater than 96",+ );});test.each([diff --git a/sdk/typescript/tests-ts/endor-findings-local.test.ts b/sdk/typescript/tests-ts/endor-findings-local.test.tsindex 63b3b89d5..e94cd1435 100644--- a/sdk/typescript/tests-ts/endor-findings-local.test.ts+++ b/sdk/typescript/tests-ts/endor-findings-local.test.ts@@ -6,120 +6,6 @@ import { listLocalExternalFindings } from "../src/external-findings-local.js";import { localFindingsFixture } from "./external-findings-local-helpers.js";import { endorFinding, endorSarif } from "./support/endor-import-fixtures.js";-test.each(["native JSON", "SARIF"] as const)(- "Endor %s findings persist locally and update the same source identity",- async (format) => {- const fixture = await localFindingsFixture();- try {- const input = format === "native JSON" ? endorFinding() : endorSarif();- const path = join(fixture.root, "endor.json");- const options = {- repository: fixture.repository,- provider: "endor" as const,- sourceKey: "endor-project-example",- };- const dependencies = { environment: fixture.environment };- await writeFile(path, JSON.stringify(input));-- const prepared = await prepareLocalExternalImport(- path,- options,- dependencies,- );- expect(prepared.preview.excluded).toEqual([]);- expect(prepared.preview.findings).toHaveLength(1);- expect(await listLocalExternalFindings(options, dependencies)).toEqual(- [],- );- expect((await prepared.import()).counts).toEqual({- created: 1,- updated: 0,- unchanged: 0,- });-- const [stored] = await listLocalExternalFindings(options, dependencies);- expect(stored).toMatchObject({- repository: fixture.repository,- provider: "endor",- sourceKey: options.sourceKey,- sourceFindingId: "finding-example-1",- version: 1,- });- expect(stored!.evidence).toEqual(prepared.preview.findings[0]!.evidence);- expect(stored!.assessment).toEqual({ state: "not_assessed" });- expect(stored!.evidence).not.toHaveProperty("confidence");- expect(stored!.evidence.locations).toEqual(- "spec" in input- ? [- { path: "package.json", line: null },- { path: "package-lock.json", line: null },- ]- : [{ path: "package.json", line: null }],- );- if ("spec" in input) {- expect(stored!.evidence.source_data).toEqual(input);- expect(stored!.evidence.packages![0]!.fixed_versions).toEqual([]);- } else {- expect(stored!.evidence.severity).toBe("unknown");- expect(stored!.evidence.source_data).toMatchObject({- result: input.runs[0]!.results[0],- rule: input.runs[0]!.tool.driver.rules[0],- });- }-- const repeated = await prepareLocalExternalImport(- path,- options,- dependencies,- );- expect((await repeated.import()).counts).toEqual({- created: 0,- updated: 0,- unchanged: 1,- });- expect(await listLocalExternalFindings(options, dependencies)).toEqual([- stored!,- ]);-- if ("spec" in input) {- input.spec.dismiss = true;- input.spec.target_dependency_version = "1.1.0";- } else {- input.runs[0]!.results[0]!.message.text = "Updated source explanation";- input.runs[0]!.results[0]!.properties.tags = [];- }- await writeFile(path, JSON.stringify(input));- const changed = await prepareLocalExternalImport(- path,- options,- dependencies,- );- expect((await changed.import()).counts).toEqual({- created: 0,- updated: 1,- unchanged: 0,- });- const updated = await listLocalExternalFindings(options, dependencies);- expect(updated).toHaveLength(1);- expect(updated[0]).toMatchObject({- id: stored!.id,- sourceFindingId: stored!.sourceFindingId,- createdAt: stored!.createdAt,- version: 2,- });- expect(updated[0]!.assessment).toEqual({ state: "not_assessed" });- expect(updated[0]!.evidence).toEqual(- changed.preview.findings[0]!.evidence,- );- expect(updated[0]!.evidence.source_data).not.toEqual(- stored!.evidence.source_data,- );- } finally {- await fixture.dispose();- }- },-);-test("switching Endor JSON and SARIF replaces the same local source snapshot without merging evidence", async () => {const fixture = await localFindingsFixture();try {@@ -159,6 +45,13 @@ test("switching Endor JSON and SARIF replaces the same local source snapshot witconst original = await importAndRead({ list: { objects: [native] } });expect(original.counts).toEqual({ created: 1, updated: 0, unchanged: 0 });+ expect(original.record).toMatchObject({+ repository: fixture.repository,+ provider: "endor",+ sourceKey: options.sourceKey,+ sourceFindingId: native.uuid,+ version: 1,+ });expect(original.record.evidence).toMatchObject({severity: "critical",code_revision: native.spec.source_code_version.sha,@@ -171,6 +64,10 @@ test("switching Endor JSON and SARIF replaces the same local source snapshot witinstalled_version: "1.0.0",});+ expect(await importAndRead(native)).toEqual({+ record: original.record,+ counts: { created: 0, updated: 0, unchanged: 1 },+ });const replaced = await importAndRead(sarif);expect(replaced.counts).toEqual({ created: 0, updated: 1, unchanged: 0 });expect(replaced.record).toMatchObject({@@ -187,8 +84,13 @@ test("switching Endor JSON and SARIF replaces the same local source snapshot witexpect(replaced.record.evidence.source_data).not.toHaveProperty("spec");expect(replaced.record.evidence.source_data).toMatchObject({result: sarif.runs[0]!.results[0],+ rule: sarif.runs[0]!.tool.driver.rules[0],});+ expect(await importAndRead(sarif)).toEqual({+ record: replaced.record,+ counts: { created: 0, updated: 0, unchanged: 1 },+ });const restored = await importAndRead(native);expect(restored.counts).toEqual({ created: 0, updated: 1, unchanged: 0 });expect(restored.record).toMatchObject({@@ -224,6 +126,7 @@ test("sparse Endor findings remain unassessed without invented locations or remeoptions,dependencies,);+ expect(await listLocalExternalFindings(options, dependencies)).toEqual([]);expect((await prepared.import()).counts.created).toBe(1);const records = await listLocalExternalFindings(options, dependencies);expect(records).toHaveLength(1);diff --git a/sdk/typescript/tests-ts/findings-import-literal-fields.test.ts b/sdk/typescript/tests-ts/findings-import-literal-fields.test.tsindex df34b3d7b..c38967ca3 100644--- a/sdk/typescript/tests-ts/findings-import-literal-fields.test.ts+++ b/sdk/typescript/tests-ts/findings-import-literal-fields.test.ts@@ -31,6 +31,18 @@ function csvSource(fields: Record<string, string> = {}): string {);}+test.each(+ (["title", "summary", "remediation"] as const).flatMap((field) =>+ [" \t\r\n", "\u0085", "\u001c\u001d\u001e\u001f"].map(+ (value) => [field, value] as const,+ ),+ ),+)("rejects canonical whitespace in CSV %s %j", async (field, value) => {+ await expect(+ parseImportedFindings(csvSource({ [field]: value }), "csv", PLUGIN_ROOT),+ ).rejects.toThrow(`requires ${field}`);+});+test.each([" ", " ", "\u00A0", "\u2003", "\u2028", "\u2029", "\uFEFF"])("preserves the literal CSV path %j",async (path) => {diff --git a/sdk/typescript/tests-ts/findings-import.test.ts b/sdk/typescript/tests-ts/findings-import.test.tsindex af2ed576c..4d0fc6058 100644--- a/sdk/typescript/tests-ts/findings-import.test.ts+++ b/sdk/typescript/tests-ts/findings-import.test.ts@@ -27,6 +27,10 @@ async function sourceDocument(): Promise<FindingsDocument> {);}+function occurrenceId(index: number): string {+ return "occ_" + index.toString(16).padStart(24, "0");+}+function exportCsv(findings: Finding[], coverage = {}): string {return execFileSync(PYTHON,@@ -121,50 +125,29 @@ describe("findings import formats", () => {"-wide","@wide",];- for (const value of values) {- const source = {- ...finding!,- title: value,- summary: value,- remediation: value,- locations: [- {- path: value.replace(/[\u0000-\u001F]/gu, "") + ".ts",- startLine: 1,- },- ],- };- const [imported] = await parseImportedFindings(- exportCsv([source]),- "csv",- PLUGIN_ROOT,- );- expect(imported).toMatchObject({- title: source.title,- summary: source.summary,- remediation: source.remediation,- locations: source.locations,- });- }- });-- test.each(- (["title", "summary", "remediation"] as const).flatMap((field) =>- [" \t\r\n", "\u0085", "\u001c\u001d\u001e\u001f"].map(- (value) => [field, value] as const,- ),- ),- )("rejects canonical whitespace in CSV %s %j", async (field, value) => {- const {- findings: [finding],- } = await sourceDocument();- await expect(- parseImportedFindings(- exportCsv([{ ...finding!, [field]: value }]),- "csv",- PLUGIN_ROOT,- ),- ).rejects.toThrow(`requires ${field}`);+ const rows = values.map((value, index) => ({+ ...finding!,+ occurrenceId: occurrenceId(index),+ title: value,+ summary: value,+ remediation: value,+ locations: [+ { path: value.replace(/[\u0000-\u001F]/gu, "") + ".ts", startLine: 1 },+ ],+ }));+ const imported = await parseImportedFindings(+ exportCsv(rows),+ "csv",+ PLUGIN_ROOT,+ );+ expect(imported).toMatchObject(+ rows.map(({ title, summary, remediation, locations }) => ({+ title,+ summary,+ remediation,+ locations,+ })),+ );});test("retains a literal apostrophe before a non-whitespace byte order mark", async () => {@@ -182,24 +165,22 @@ describe("findings import formats", () => {const {findings: [finding],} = await sourceDocument();- for (const path of [" ", "\u00A0", "\u2028", "\u2029", "\uFEFF"]) {- const [imported] = await parseImportedFindings(- exportCsv(- [- {- ...finding!,- locations: [{ path, startLine: 1, endLine: 1 }],- extensions: { candidateId: "\uFEFF" },- },- ],- { mode: "deep_repository" },- ),- "csv",- PLUGIN_ROOT,- );- expect(imported!.locations).toEqual([{ path, startLine: 1, endLine: 1 }]);- expect(imported!.extensions?.["candidateId"]).toBe("\uFEFF");- }+ const rows = [" ", "\u00A0", "\u2028", "\u2029", "\uFEFF"].map(+ (path, index) => ({+ ...finding!,+ occurrenceId: occurrenceId(index),+ locations: [{ path, startLine: 1, endLine: 1 }],+ extensions: { candidateId: "\uFEFF" },+ }),+ );+ const imported = await parseImportedFindings(+ exportCsv(rows, { mode: "deep_repository" }),+ "csv",+ PLUGIN_ROOT,+ );+ expect(imported).toMatchObject(+ rows.map(({ locations, extensions }) => ({ locations, extensions })),+ );});test("accepts full findings documents and findings-service payloads", async () => {diff --git a/sdk/typescript/tests-ts/fixtures/scan-navigation-output.mts b/sdk/typescript/tests-ts/fixtures/scan-navigation-output.mtsindex 15ab1bb9d..3ef39d4b6 100644--- a/sdk/typescript/tests-ts/fixtures/scan-navigation-output.mts+++ b/sdk/typescript/tests-ts/fixtures/scan-navigation-output.mts@@ -8,7 +8,6 @@ import { writeJsonLines } from "../support/json.js";import { temporaryDirectory } from "../support/temporary-directories.js";const command = process.argv[2]!;-const failure = process.argv[3]!;const root = await temporaryDirectory("scan-navigation-output-");try {process.env["XDG_DATA_HOME"] = root;@@ -27,44 +26,46 @@ try {progress: { status: "complete" },findings: [],};- const stdout = capture();- const error = Object.assign(new Error("Diagnostic output failed"), {- code: failure,- });- let writes = 0;- const stderr =- failure === "sync"- ? {- write(): boolean {- writes += 1;- throw error;- },- }- : new Writable({- autoDestroy: false,- write(_chunk, _encoding, callback) {- writes += 1;- setImmediate(() => callback(error));- },- });- const status = await main(- ["scans", command, scan.scanId],- stdout.stream,- stderr,- dependencies({- environment: { CODEX_HOME: home, CODEX_SECURITY_STATE_DIR: root },- onWorkbench: () => ({ scan }),- }),- );- await new Promise<void>((resolve) => setImmediate(resolve));- assert.equal(status, 0);- assert.ok(writes > 0);- assert.ok(stdout.text().includes(scan.scanId));- if (stderr instanceof Writable) {- assert.equal(stderr.errored, error);- assert.equal(stderr.listenerCount("error"), 0);+ for (const failure of ["sync", "EPIPE", "ENOSPC"]) {+ const stdout = capture();+ const error = Object.assign(new Error("Diagnostic output failed"), {+ code: failure,+ });+ let writes = 0;+ const stderr =+ failure === "sync"+ ? {+ write(): boolean {+ writes += 1;+ throw error;+ },+ }+ : new Writable({+ autoDestroy: false,+ write(_chunk, _encoding, callback) {+ writes += 1;+ setImmediate(() => callback(error));+ },+ });+ const status = await main(+ ["scans", command, scan.scanId],+ stdout.stream,+ stderr,+ dependencies({+ environment: { CODEX_HOME: home, CODEX_SECURITY_STATE_DIR: root },+ onWorkbench: () => ({ scan }),+ }),+ );+ await new Promise<void>((resolve) => setImmediate(resolve));+ assert.equal(status, 0, `${command} on ${failure}`);+ assert.ok(writes > 0);+ assert.ok(stdout.text().includes(scan.scanId));+ if (stderr instanceof Writable) {+ assert.equal(stderr.errored, error);+ assert.equal(stderr.listenerCount("error"), 0);+ }+ process.stdout.write(`${failure}\n`);}- process.stdout.write(JSON.stringify({ status, output: stdout.text() }));} finally {await rm(root, { recursive: true, force: true });}diff --git a/sdk/typescript/tests-ts/import-scan.test.ts b/sdk/typescript/tests-ts/import-scan.test.tsindex d52a15efe..8101a3c0b 100644--- a/sdk/typescript/tests-ts/import-scan.test.ts+++ b/sdk/typescript/tests-ts/import-scan.test.ts@@ -1,3 +1,4 @@+import { Database } from "bun:sqlite";import { execFileSync } from "node:child_process";import {mkdir,@@ -22,7 +23,6 @@ import type { FindingsDocument } from "../src/models.js";import { ScanResult } from "../src/result.js";import { runWorkbench } from "../src/runtime.js";import { PLUGIN_ROOT } from "./plugin-root.js";-import { runCommand } from "./support/shell.js";import { runTestInSubprocess } from "./support/test-subprocess.js";import { createApiTestFixtures } from "./support/temporary-directories.js";import { rejecting } from "./support/errors.js";@@ -55,10 +55,10 @@ const csvColumns = ["end_line",];-function csvSource(): string {- const rows = sourceOccurrenceIds.map((occurrenceId, index) => [- occurrenceId,- `csf_00000000000000000000000${index + 1}`,+function csvSource(paths = ["src/extract.ts", "src/extract.ts"]): string {+ const rows = paths.map((path, index) => [+ `occ_${String(index + 1).padStart(24, "0")}`,+ `csf_${String(index + 1).padStart(24, "0")}`,"Reported archive extraction issue",description,"high",@@ -67,7 +67,7 @@ function csvSource(): string {"","","Validate archive entry destinations.",- "src/extract.ts",+ path,"41","44",]);@@ -127,7 +127,6 @@ async function fixture(format: "csv" | "json" = "csv") {// Import persistence uses real Python; runtime tests cover interpreter discovery.resolvePluginPython: async () => python!,},- python: python!,source,options,workbenchOptions: { python: python!, pluginRoot: PLUGIN_ROOT, environment },@@ -140,31 +139,27 @@ function completed(result: Awaited<ReturnType<typeof importScan>>): ScanResult {return result;}-async function storedScans(context: Awaited<ReturnType<typeof fixture>>) {- const result = await runCommand(- context.python,- [- "-c",- [- "import json, sqlite3, sys",- "connection = sqlite3.connect(sys.argv[1])",- "connection.row_factory = sqlite3.Row",- 'rows = connection.execute("SELECT id, status, target_path, scan_dir, (SELECT COUNT(*) FROM finding_occurrences WHERE scan_id = scans.id) AS occurrence_count FROM scans ORDER BY created_at, id")',- 'print(json.dumps([dict(row, summaries=[summary for (summary,) in connection.execute("SELECT summary FROM finding_occurrences WHERE scan_id = ?", (row["id"],))]) for row in rows]))',- ].join("\n"),- join(context.stateDirectory, "workbench.sqlite3"),- ],- { timeout: 30_000 },+function storedScans(context: Awaited<ReturnType<typeof fixture>>) {+ using database = new Database(+ join(context.stateDirectory, "workbench.sqlite3"),+ { readwrite: true, create: false },);- expect(result.status, result.stderr).toBe(0);- return JSON.parse(result.stdout) as Array<{- id: string;- status: string;- target_path: string;- scan_dir: string;- occurrence_count: number;- summaries: string[];- }>;+ database.exec("PRAGMA query_only = ON");+ const scans = database+ .query<+ { id: string; status: string; target_path: string; scan_dir: string },+ []+ >(+ "SELECT id, status, target_path, scan_dir FROM scans ORDER BY created_at, id",+ )+ .all();+ const occurrences = database.query<{ summary: string }, [string]>(+ "SELECT summary FROM finding_occurrences WHERE scan_id = ?",+ );+ return scans.map((scan) => {+ const summaries = occurrences.all(scan.id).map((row) => row.summary);+ return { ...scan, occurrence_count: summaries.length, summaries };+ });}test.each(["completed", "failed", "interrupted", "preview"] as const)(@@ -241,7 +236,7 @@ test.each(["completed", "failed", "interrupted", "preview"] as const)(code: "ENOENT",});} else {- const scans = await storedScans(context);+ const scans = storedScans(context);expect(scans).toHaveLength(1);expect(scans[0]!.status).toBe(outcome === "completed" ? "complete" : "failed",@@ -361,7 +356,7 @@ test.each(["csv", "json"] as const)(expect(await readFile(context.options.sourcePath, "utf8")).toBe(context.source,);- const [stored] = await storedScans(context);+ const [stored] = storedScans(context);expect(stored).toMatchObject({id: result.manifest.scan.id,status: "complete",@@ -411,48 +406,60 @@ test("CSV import seals and reloads non-whitespace byte order marks in required texpect(await readFile(context.options.sourcePath, "utf8")).toBe(source);});-test.each(["\u00A0", "\u2028", "\u2029", "src/a\u2028b.py", "src/a\u2029b.py"])(- "CSV import retains literal fields without replaying source decisions for %j",- async (path) => {- const context = await fixture();- const source =- "\uFEFF" +- context.source- .replaceAll('"title"', '"candidate_id","title"')- .replaceAll(- '"Reported archive extraction issue"',- '"\uFEFF","Reported archive extraction issue"',- )- .replaceAll('"open","",""', '"closed","false_positive"," \uFEFF "')- .replaceAll('"src/extract.ts"', `"${path}"`);- await writeFile(context.options.sourcePath, source);- const result = completed(- await importScan(context.options, context.dependencies),- );- const loaded = await loadContract(result.scanDir, {- pluginRoot: PLUGIN_ROOT,+test("CSV import retains literal fields without replaying source decisions", async () => {+ const paths = [+ "\u00A0",+ "\u2028",+ "\u2029",+ "src/a\u2028b.py",+ "src/a\u2029b.py",+ ];+ const context = await fixture();+ const source =+ "\uFEFF" ++ csvSource(paths)+ .replaceAll('"title"', '"candidate_id","title"')+ .replaceAll(+ '"Reported archive extraction issue"',+ '"\uFEFF","Reported archive extraction issue"',+ )+ .replaceAll('"open","",""', '"closed","false_positive"," \uFEFF "');+ await writeFile(context.options.sourcePath, source);+ const result = completed(+ await importScan(context.options, context.dependencies),+ );+ const loaded = await loadContract(result.scanDir, {+ pluginRoot: PLUGIN_ROOT,+ });+ expect(+ loaded.findings.findings+ .map((finding) => finding.locations[0]!.path)+ .sort(),+ ).toEqual(paths.sort());+ for (const finding of loaded.findings.findings) {+ expect(finding.extensions?.["candidateId"]).toBe("\uFEFF");+ expect(finding.validation).toMatchObject({+ method: "Source-reported CSV import metadata",+ status: "closed",+ summary: expect.stringContaining(+ "Source close reason: false_positive\nSource note: \uFEFF ",+ ),});- for (const finding of loaded.findings.findings) {- expect(finding.locations[0]!.path).toBe(path);- expect(finding.extensions?.["candidateId"]).toBe("\uFEFF");- expect(finding.validation).toMatchObject({- method: "Source-reported CSV import metadata",- status: "closed",- summary: expect.stringContaining(- "Source close reason: false_positive\nSource note: \uFEFF ",- ),- });- }- const decisions = await runCommand(context.python, [- "-c",- "import sqlite3, sys; c = sqlite3.connect(sys.argv[1]); print(c.execute('SELECT COUNT(*) FROM finding_decisions').fetchone()[0], c.execute('SELECT COUNT(*) FROM finding_triage').fetchone()[0])",- join(context.stateDirectory, "workbench.sqlite3"),- ]);- expect(decisions.status, decisions.stderr).toBe(0);- expect(decisions.stdout.trim()).toBe("0 0");- expect(await readFile(context.options.sourcePath, "utf8")).toBe(source);- },-);+ }+ using database = new Database(+ join(context.stateDirectory, "workbench.sqlite3"),+ { readwrite: true, create: false },+ );+ database.exec("PRAGMA query_only = ON");+ expect(+ database+ .query(+ "SELECT (SELECT COUNT(*) FROM finding_decisions) AS decisions, (SELECT COUNT(*) FROM finding_triage) AS triage",+ )+ .get(),+ ).toEqual({ decisions: 0, triage: 0 });+ expect(await readFile(context.options.sourcePath, "utf8")).toBe(source);+});test.each(["csv", "json"] as const)("empty %s imports preserve source integrity without claiming an analyzed surface",@@ -482,7 +489,7 @@ test.each(["csv", "json"] as const)().toHaveLength(1);const retainedSource = join(result.scanDir, sourceRef);expect(await readFile(retainedSource, "utf8")).toBe(source);- expect((await storedScans(context))[0]).toMatchObject({+ expect(storedScans(context)[0]).toMatchObject({status: "complete",occurrence_count: 0,});@@ -695,9 +702,9 @@ test("reimporting the retained source preserves finding identities with new scan(finding) => !previousOccurrences.has(finding.occurrenceId),),).toBe(true);- expect(- (await storedScans(context)).map((scan) => scan.occurrence_count),- ).toEqual([2, 2]);+ expect(storedScans(context).map((scan) => scan.occurrence_count)).toEqual([+ 2, 2,+ ]);});const evidence = {@@ -820,7 +827,7 @@ test("imports archive prior output without replacing its saved findings", asynccontext.dependencies,),);- const scans = await storedScans(context);+ const scans = storedScans(context);expect(scans).toHaveLength(2);const archived = scans.find((scan) => scan.id === first.manifest.scan.id)!;expect(archived.scan_dir).not.toBe(second.scanDir);@@ -930,16 +937,10 @@ test.each(["active scan", "missing parent"])(const first = completed(await importScan(options, context.dependencies));const manifest = await readFile(first.manifestPath, "utf8");if (reason === "active scan") {- const update = await runCommand(- context.python,- [- "-c",- "import sqlite3,sys; c=sqlite3.connect(sys.argv[1]); c.execute(\"UPDATE scans SET status='running'\"); c.commit()",- join(context.stateDirectory, "workbench.sqlite3"),- ],- { timeout: 30_000 },+ using database = new Database(+ join(context.stateDirectory, "workbench.sqlite3"),);- expect(update.status, update.stderr).toBe(0);+ database.run("UPDATE scans SET status='running'");}await expect(importScan(@@ -956,8 +957,7 @@ test.each(["active scan", "missing parent"])(reason === "active scan" ? "running scan" : "scan not found",);expect(await readFile(first.manifestPath, "utf8")).toBe(manifest);- expect(await storedScans(context)).toHaveLength(1);- expect((await storedScans(context))[0]?.scan_dir).toBe(first.scanDir);+ expect(storedScans(context)).toMatchObject([{ scan_dir: first.scanDir }]);},);@@ -985,7 +985,7 @@ test("registration preserves archived output when its response is lost after com{ ...context.dependencies, runWorkbench: loseRegistrationReply },),).rejects.toThrow("Synthetic response lost after commit");- const scans = await storedScans(context);+ const scans = storedScans(context);expect(scans).toHaveLength(2);const archived = scans.find((scan) => scan.id === first.manifest.scan.id)!;expect(archived.scan_dir).not.toBe(first.scanDir);@@ -1022,7 +1022,7 @@ test.each(["failure", "abort"] as const)(if (mode === "abort")await expect(operation).rejects.toBeInstanceOf(ScanInterruptedError);else await expect(operation).rejects.toThrow(failureMessage);- const scans = await storedScans(context);+ const scans = storedScans(context);expect(scans).toHaveLength(1);expect(scans[0]!.status).toBe("failed");if (mode === "failure") {diff --git a/sdk/typescript/tests-ts/inventory-input.test.ts b/sdk/typescript/tests-ts/inventory-input.test.tsindex 23808db2e..f7e7a7ef6 100644--- a/sdk/typescript/tests-ts/inventory-input.test.ts+++ b/sdk/typescript/tests-ts/inventory-input.test.ts@@ -95,9 +95,9 @@ process.exitCode = result.status;expect(result.status, result.stderr).toBe(0);return readFileSync(out, "utf8");};- const scopeArgs = (scope = ".") => {+ const scopeArgs = (scope = ".", ...others: string[]) => {const file = join(root, "requested-scopes.json");- writeFileSync(file, JSON.stringify([scope]));+ writeFileSync(file, JSON.stringify([scope, ...others]));return ["--scopes-file", file];};const rows = (command = "make-repo-scope-input", args?: string[]) =>@@ -674,86 +674,97 @@ for (const scope of [".", "src", "./src", "src/résumé.py"]) {test("make-repo-scope-input retains explicit and ignored tracked files without widening directory scope", () => {const f = fixture();f.write("src/source.py");- f.write("src/entrypoint", "run\n");- f.write("outside.py");- f.write(".gitignore", "src/ignored*\n");+ f.write("src/Dockerfile");+ f.write("src/examples/demo.ts");+ f.write("src/tests/handler.test.ts");+ f.write("src/entrypoint");f.write("src/ignored-tracked.py");f.write("src/ignored-untracked.py");+ f.write("src/.env");+ f.write("src/node_modules/dependency.ts");+ f.write("src/vendor/tracked.py");+ f.write("src/vendor/untracked.py");+ f.write("outside.py");+ f.write(".gitignore", ".env\nnode_modules/\nvendor/\nsrc/ignored*\n");f.write("src/binary", Buffer.from([0]));f.write("direct.bin", Buffer.from([0]));- git(f.repo, "add", "--force", "src/ignored-tracked.py");- const scopes = join(f.root, "scopes.json");- writeFileSync(scopes, JSON.stringify(["src", "direct.bin", "src/source.py"]));- const rows = f.rows("make-repo-scope-input", ["--scopes-file", scopes]);- expect(rows.map((row) => row.path)).toEqual([- "direct.bin",+ f.write("src/logo.png", Buffer.from([0x89, 0x50, 0x4e, 0x47]));+ git(+ f.repo,+ "add",+ "--force",+ "src/vendor/tracked.py",+ "src/ignored-tracked.py",+ "src/logo.png",+ );+ const paths = (scope: string, ...others: string[]) =>+ f+ .rows("make-repo-scope-input", f.scopeArgs(scope, ...others))+ .map((row) => row.path);+ const directory = [+ "src/Dockerfile","src/binary","src/entrypoint",+ "src/examples/demo.ts","src/ignored-tracked.py",+ "src/logo.png","src/source.py",+ "src/tests/handler.test.ts",+ "src/vendor/tracked.py",+ ];+ expect(paths("src", "direct.bin", "src/source.py")).toEqual([+ "direct.bin",+ ...directory,+ ]);+ expect(paths("src", "src/.env")).toEqual(["src/.env", ...directory]);+ expect(paths("src/vendor", "src/logo.png")).toEqual([+ "src/logo.png",+ "src/vendor/tracked.py",]);});-for (const encoding of ["utf8", "utf16le", "utf16be"] as const) {- for (const mode of ["revisions", "local-patch"]) {- test(`${mode} previews decode ${encoding} and detect binary bytes beyond the prefix`, () => {- const f = fixture();- f.write("existing.py");- const base = f.commit();- const source = " value = 'café 😀 literal' \n\n return value \n";- const bytes =- encoding === "utf8"- ? Buffer.from(source)- : Buffer.concat([- Buffer.from([0xff, 0xfe]),- Buffer.from(source, "utf16le"),- ]);- if (encoding === "utf16be") bytes.swap16();- f.write("text", bytes);- const lateBinary =- encoding === "utf8"- ? Buffer.concat([Buffer.alloc(96 * 1024, 120), Buffer.from([0])])- : Buffer.concat([- Buffer.from([0xff, 0xfe]),- Buffer.from("x".repeat(96 * 1024) + "\0", "utf16le"),- ]);- if (encoding === "utf16be") lateBinary.swap16();- f.write("encoded-binary", lateBinary);+for (const mode of ["revisions", "local-patch"]) {+ test(`${mode} previews decode UTF-8 and UTF-16 and exclude binary files`, () => {+ const f = fixture();+ f.write("existing.py");+ const base = f.commit();+ const source = " value = 'café 😀 literal' \n\n return value \n";+ const binary = "x".repeat(96 * 1024) + "\0";+ for (const [name, text] of [+ ["text", source],+ ["binary", binary],+ ] as const) {+ f.write(`${name}-utf8`, text);+ const utf16 = Buffer.from("\ufeff" + text, "utf16le");+ f.write(`${name}-utf16le`, utf16);+ f.write(`${name}-utf16be`, utf16.swap16());+ }+ for (const bom of [+ [0xff, 0xfe],+ [0xfe, 0xff],+ ]) {f.write(- "late-binary",- Buffer.concat([Buffer.alloc(96 * 1024, 120), Buffer.from([0])]),+ `late-bom-${bom[0]}`,+ Buffer.concat([+ Buffer.alloc(64 * 1024, 120),+ Buffer.from([...bom, 104, 0, 105, 0]),+ ]),);- for (const bom of [- [0xff, 0xfe],- [0xfe, 0xff],- ])- f.write(- `late-bom-${bom[0]}`,- Buffer.concat([- Buffer.alloc(64 * 1024, 120),- Buffer.from([...bom, 104, 0, 105, 0]),- ]),- );- if (mode === "revisions") f.commit();- const rows = f.rows("make-diff-rank-input", [- "--base",- base,- "--mode",- mode,- ]);- expect(rows.find((row) => row.path === "text")?.preview).toBe(+ }+ if (mode === "revisions") f.commit();+ const rows = f.rows("make-diff-rank-input", [+ "--base",+ base,+ "--mode",+ mode,+ ]);+ expect(rows.map(({ path, preview }) => [path, preview])).toEqual(+ ["text-utf16be", "text-utf16le", "text-utf8"].map((path) => [+ path,source.slice(0, -1),- );- expect(- rows.some(- (row) =>- row.path === "late-binary" ||- row.path === "encoded-binary" ||- row.path.startsWith("late-bom-"),- ),- ).toBe(false);- });- }+ ]),+ );+ });}for (const budget of [0, -1, 2, 30, 220, 1024]) {@@ -1263,18 +1274,26 @@ test("inventory excludes nested Git metadata and handles long destination names"}});-test("scope inventory rejects symbolic-link components before lexical parent traversal", () => {+test("scope inventory rejects escaping paths and symbolic links before lexical traversal", () => {const f = fixture();- f.write("src/source");+ const source = f.write("src/source");+ const escaped = f.run(+ "make-repo-scope-input",+ f.scopeArgs("../requested-scopes.json"),+ );+ expect(escaped.status).toBe(1);symlinkSync(join(f.repo, "src"), join(f.repo, "alias"), "junction");- const scopes = join(f.root, "scopes.json");- for (const scope of [+ const scopes = ["alias/source","alias/../src/source",`${f.root}${sep}.${sep}repository${sep}alias${sep}..${sep}src${sep}source`,- ]) {- writeFileSync(scopes, JSON.stringify([scope]));- const result = f.run("make-repo-scope-input", ["--scopes-file", scopes]);+ ];+ if (process.platform !== "win32") {+ symlinkSync(source, join(f.repo, "src", "alias"));+ scopes.push("src/alias");+ }+ for (const scope of scopes) {+ const result = f.run("make-repo-scope-input", f.scopeArgs(scope));expect(result.status).toBe(1);expect(result.stderr).toContain("symbolic links");}diff --git a/sdk/typescript/tests-ts/linear-comment-pagination.test.ts b/sdk/typescript/tests-ts/linear-comment-pagination.test.tsdeleted file mode 100644index 014bbf41c..000000000--- a/sdk/typescript/tests-ts/linear-comment-pagination.test.ts+++ /dev/null@@ -1,40 +0,0 @@-import { expect, test } from "bun:test";-import { importLinearIssues, type LinearClientFactory } from "../src/linear.js";-import { paginated } from "./support/linear-pagination.js";--test.each([- [0, []],- [1, []],- [51, ["50"]],- [101, ["50", "100"]],-] as const)(- "imports %i issue comments exactly once",- async (count, expectedCursors) => {- const comments = Array.from({ length: count }, (_, index) => ({- body: `Synthetic comment ${index + 1}`,- url: `https://linear.app/example/issue/DEMO-1#comment-${index + 1}`,- }));- const { connection, cursors } = paginated(comments);-- const imported = await importLinearIssues({- issues: ["DEMO-1"],- environment: { CODEX_SECURITY_LINEAR_API_KEY: "synthetic-key" },- linearClient: () =>- ({- issue: async () => ({- identifier: "DEMO-1",- title: "Synthetic issue",- description: "Synthetic evidence.",- url: "https://linear.app/example/issue/DEMO-1",- comments: async () => connection,- }),- }) as unknown as ReturnType<LinearClientFactory>,- });-- expect(imported).toHaveLength(1);- const importedComments: string[] =- imported[0]!.text.match(/Synthetic comment \d+/gu) ?? [];- expect(importedComments).toEqual(comments.map(({ body }) => body));- expect(cursors).toEqual([...expectedCursors]);- },-);diff --git a/sdk/typescript/tests-ts/linear-pagination.test.ts b/sdk/typescript/tests-ts/linear-pagination.test.tsindex c44a3af1f..ba0f78b2e 100644--- a/sdk/typescript/tests-ts/linear-pagination.test.ts+++ b/sdk/typescript/tests-ts/linear-pagination.test.ts@@ -1,38 +1,64 @@import { expect, test } from "bun:test";import { importLinearIssues, type LinearClientFactory } from "../src/linear.js";-import { paginated } from "./support/linear-pagination.js";+import { emptyPage, paginated } from "./support/linear-pagination.js";++test("imports all project issues once across three SDK pages", async () => {+ const issues = Array.from({ length: 101 }, (_, index) => ({+ identifier: `DEMO-${index + 1}`,+ title: `Synthetic issue ${index + 1}`,+ description: "Synthetic evidence.",+ url: `https://linear.app/example/issue/DEMO-${index + 1}`,+ comments: emptyPage,+ }));+ const { connection, cursors } = paginated(issues);+ const imported = await importLinearIssues({+ issues: [],+ project: "Example project",+ environment: { CODEX_SECURITY_LINEAR_API_KEY: "synthetic-key" },+ linearClient: () =>+ ({+ projects: async () => ({+ nodes: [{ issues: async () => connection }],+ }),+ }) as unknown as ReturnType<LinearClientFactory>,+ });+ expect(imported.map(({ id }) => id)).toEqual(+ issues.map(({ identifier }) => identifier),+ );+ expect(cursors).toEqual(["50", "100"]);+});test.each([[1, []],- [51, ["50"]],[101, ["50", "100"]],] as const)(- "imports %i project issues exactly once",+ "imports %i issue comments exactly once",async (count, expectedCursors) => {- const issues = Array.from({ length: count }, (_, index) => ({- identifier: `DEMO-${index + 1}`,- title: `Synthetic issue ${index + 1}`,- description: "Synthetic evidence.",- url: `https://linear.app/example/issue/DEMO-${index + 1}`,- comments: async () => paginated([]).connection,+ const comments = Array.from({ length: count }, (_, index) => ({+ body: `Synthetic comment ${index + 1}`,+ url: `https://linear.app/example/issue/DEMO-1#comment-${index + 1}`,}));- const { connection, cursors } = paginated(issues);+ const { connection, cursors } = paginated(comments);const imported = await importLinearIssues({- issues: [],- project: "Example project",+ issues: ["DEMO-1"],environment: { CODEX_SECURITY_LINEAR_API_KEY: "synthetic-key" },linearClient: () =>({- projects: async () => ({- nodes: [{ issues: async () => connection }],+ issue: async () => ({+ identifier: "DEMO-1",+ title: "Synthetic issue",+ description: "Synthetic evidence.",+ url: "https://linear.app/example/issue/DEMO-1",+ comments: async () => connection,}),}) as unknown as ReturnType<LinearClientFactory>,});- expect(imported.map(({ id }) => id)).toEqual(- issues.map(({ identifier }) => identifier),- );+ expect(imported).toHaveLength(1);+ const importedComments: string[] =+ imported[0]!.text.match(/Synthetic comment \d+/gu) ?? [];+ expect(importedComments).toEqual(comments.map(({ body }) => body));expect(cursors).toEqual([...expectedCursors]);},);diff --git a/sdk/typescript/tests-ts/package-tar-listing.test.ts b/sdk/typescript/tests-ts/package-tar-listing.test.tsindex 5ed1e745b..3bd2f4fb9 100644--- a/sdk/typescript/tests-ts/package-tar-listing.test.ts+++ b/sdk/typescript/tests-ts/package-tar-listing.test.ts@@ -429,31 +429,27 @@ describe("npm package tar listings", () => {["level-0", gzipSync(tarBytes, { level: 0 })],["sparse-0.0", gzipSync(packageTar({ readmeSparse: "0.0" }))],["sparse-1.0", gzipSync(packageTar({ readmeSparse: "1.0" }))],- ["gnu-long-name", gzipSync(packageTar({ readmeLongName: true }))],- ["npm-size-field", gzipSync(packageTar({ sizeTerminator: " \0" }))],- ["nul-regular-file", gzipSync(packageTar({ type: 0 }))],[- "future-timestamps",+ "gnu-long-name",gzipSync(- packageTar({ mtime: Math.floor(Date.now() / 1000) + 365 * 86400 }),- ),- ],- ["unreadable-readme", gzipSync(packageTar({ readmeMode: 0 }))],- [- "read-only-nested-directories",- gzipSync(- packageTar({ compatibleLayout: true, directoryMode: 0o555 }),+ packageTar({+ readmeLongName: true,+ readmeMode: 0,+ mtime: Math.floor(Date.now() / 1000) + 365 * 86400,+ sizeTerminator: " \0",+ type: 0,+ }),),],- ["posix-size-field", gzipSync(packageTar({ sizeTerminator: "\0" }))],- [- "compatible-tar-layout",- gzipSync(packageTar({ compatibleLayout: true })),- ],["read-only-directories",gzipSync(- packageTar({ compatibleLayout: true, rootDirectoryMode: 0o555 }),+ packageTar({+ compatibleLayout: true,+ rootDirectoryMode: 0o555,+ directoryMode: 0o555,+ sizeTerminator: "\0",+ }),),],] as const;diff --git a/sdk/typescript/tests-ts/publication-integration.test.ts b/sdk/typescript/tests-ts/publication-integration.test.tsindex e6082c63e..1e929ea86 100644--- a/sdk/typescript/tests-ts/publication-integration.test.ts+++ b/sdk/typescript/tests-ts/publication-integration.test.ts@@ -7,6 +7,7 @@ import {import { setFindingIdentity, sha256 } from "./support/finding-identity.js";import { parseJsonLines, jsonLines } from "./support/json.js";import { nodeCommand } from "./support/shell.js";+import { Database } from "bun:sqlite";import { execFileSync } from "node:child_process";import {appendFile,@@ -265,20 +266,16 @@ function killTestProcess(pid: number): void {}function storedPublications(fixture: PublicationFixture): StoredPublication[] {- const script = [- "import json, sqlite3, sys",- "connection = sqlite3.connect(sys.argv[1])",- "connection.row_factory = sqlite3.Row",- `rows = connection.execute("SELECT scan_id, finding_id, occurrence_id, json_extract(destination_key, '$[0]') AS destination_type, json_extract(destination_key, '$[1]') AS team_id, json_extract(destination_key, '$[2]') AS project_id, external_id, external_url FROM finding_issue_receipts ORDER BY id").fetchall()`,- "print(json.dumps([dict(row) for row in rows]))",- ].join("\n");- return JSON.parse(- execNodePython(- fixture.python,- ["-c", script, join(fixture.stateDirectory, "workbench.sqlite3")],- fixture.environment,- ),- ) as StoredPublication[];+ using database = new Database(+ join(fixture.stateDirectory, "workbench.sqlite3"),+ { readwrite: true, create: false },+ );+ database.exec("PRAGMA query_only = ON");+ return database+ .query<StoredPublication, []>(+ "SELECT scan_id, finding_id, occurrence_id, json_extract(destination_key, '$[0]') AS destination_type, json_extract(destination_key, '$[1]') AS team_id, json_extract(destination_key, '$[2]') AS project_id, external_id, external_url FROM finding_issue_receipts ORDER BY id",+ )+ .all();}function receiptPath(fixture: PublicationFixture): string {diff --git a/sdk/typescript/tests-ts/publication.test.ts b/sdk/typescript/tests-ts/publication.test.tsindex 1b5366b09..852e480c4 100644--- a/sdk/typescript/tests-ts/publication.test.ts+++ b/sdk/typescript/tests-ts/publication.test.ts@@ -856,13 +856,7 @@ describe("scan publication preparation", () => {expect(description).not.toContain("/blob/");});- test.each([- "../outside.py",- "src/../outside.py",- "/outside.py",- "src\\outside.py",- "C:/outside.py",- ])("rejects publication with an unsafe evidence path %s", async (path) => {+ test("rejects publication with a traversal in an evidence path", async () => {const scanDirectory = await copyExample();const findingsPath = join(scanDirectory, "findings.json");const findings = await readJson<FindingsDocument>(findingsPath);@@ -870,7 +864,7 @@ describe("scan publication preparation", () => {{id: "unsafe-path",label: "Unsafe path",- path,+ path: "src/../outside.py",startLine: 41,code: "preserved_snippet()",explanation:diff --git a/sdk/typescript/tests-ts/publish.test.ts b/sdk/typescript/tests-ts/publish.test.tsindex ad0f2aebd..c2b4f7574 100644--- a/sdk/typescript/tests-ts/publish.test.ts+++ b/sdk/typescript/tests-ts/publish.test.ts@@ -415,6 +415,7 @@ function linearApiClient(interface PublicationPromptData {scanId: string;+ destination: PreparedScanPublication["destination"];handoffFile: string;publicationFile: string;batches: Array<@@ -1397,17 +1398,19 @@ describe("connected Linear publication", () => {const stored = JSON.parse(await readFile(data.publicationFile, "utf8"),) as {- destination: Record<string, unknown>;+ destination: PreparedScanPublication["destination"];batches: Array<Array<{ arguments: Record<string, unknown> }>>;};- expect(stored.destination).toEqual({- type: "linear",- teamId: "team-example",- });- expect(stored.destination).not.toHaveProperty("projectId");- for (const issue of stored.batches.flat()) {- expect(issue.arguments).not.toHaveProperty("project");- }+ expect(data.destination).toEqual(publication.destination);+ expect(stored.destination).toEqual(publication.destination);+ expect(stored.batches.flat().map((issue) => issue.arguments)).toEqual(+ publication.issues.map(({ title, description, priority }) => ({+ team: OPTIONS.teamId,+ title,+ description,+ priority,+ })),+ );await writeHandoff(input, [handoffRecord(publication, publication.issues[0]!, {@@ -1606,67 +1609,6 @@ describe("connected Linear publication", () => {expect(receiptScanId).toBe("scan-example");});- test("publishes directly to a Linear team without project lookups or arguments", async () => {- const publication: PreparedScanPublication = {- ...preparedPublication(),- destination: { type: "linear", teamId: OPTIONS.teamId },- };- let input: string | undefined;- let issueArguments: Record<string, unknown> | undefined;-- const result = await publishScanInternal(- publication.scanDirectory,- { destination: "linear", teamId: OPTIONS.teamId },- dependencies(publication, {- runCodex: async (_command, _arguments, prompt) => {- input = prompt;- const stored = JSON.parse(- await readFile(publicationData(prompt).publicationFile, "utf8"),- ) as {- batches: Array<Array<{ arguments: Record<string, unknown> }>>;- };- issueArguments = stored.batches[0]?.[0]?.arguments;- const event = JSON.parse(issueEvent(publication.issues[0]!)) as {- item: { arguments: Record<string, unknown> };- };- delete event.item.arguments["project"];- return {- exitCode: 0,- stdout: JSON.stringify(event),- stderr: "",- };- },- }),- );-- expect(input).toContain("linear_get_team with the supplied team");- expect(input).not.toContain("linear_get_project");- expect(input).not.toContain("resolved project");- expect(input).toContain("Create issues only in the exact supplied team.");- const encoded = input!- .split("BEGIN UNTRUSTED PUBLICATION DATA\n")[1]!- .split("\nEND UNTRUSTED PUBLICATION DATA")[0]!;- const data = JSON.parse(encoded) as {- destination: Record<string, unknown>;- };- expect(data.destination).toEqual({- type: "linear",- teamId: "team-example",- });- expect(issueArguments).toEqual({- team: "team-example",- title: publication.issues[0]!.title,- description: publication.issues[0]!.description,- priority: 2,- });- expect(issueArguments).not.toHaveProperty("project");- expect(result.destination).toEqual({- type: "linear",- teamId: "team-example",- });- expect(result.counts).toEqual({ findings: 1, created: 1, failed: 0 });- });-test("preserves complete finding descriptions without exposing them to model transcription", async () => {const publication = preparedPublication(2);publication.issues[0]!.description = [diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex 716390ae0..d13c59c79 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -685,6 +685,17 @@ describe("reviewed release note helpers", () => {);});+ test("rejects Unicode whitespace-only reviewed summaries", () => {+ for (const space of ["\u00a0", "\u2007", "\u202f", "\ufeff"]) {+ expect(() =>+ parseReviewedReleaseNotes(+ "1.2.3",+ `<!-- release-version: 1.2.3 -->\n${space}`,+ ),+ ).toThrow("include a reviewed summary");+ }+ });+test("rejects NUL bytes before shell composition", async () => {const workspace = directories.create("release-notes-nul-");const taggedNotes = join(workspace, "tagged-notes.md");@@ -1754,36 +1765,12 @@ describe("GitHub release workflow safeguards", () => {status: 1,message: "Release notes must start with <!-- release-version: 0.1.6 -->",},- {- scenario: "an empty reviewed summary",- summary: "<!-- release-version: 0.1.6 -->\n ",- status: 1,- message: "Release notes must start with <!-- release-version: 0.1.6 -->",- },{scenario: "a U+00A0-only reviewed summary",summary: "<!-- release-version: 0.1.6 -->\n\u00a0",status: 1,message: "Release notes must start with <!-- release-version: 0.1.6 -->",},- {- scenario: "a U+2007-only reviewed summary",- summary: "<!-- release-version: 0.1.6 -->\n\u2007",- status: 1,- message: "Release notes must start with <!-- release-version: 0.1.6 -->",- },- {- scenario: "a U+202F-only reviewed summary",- summary: "<!-- release-version: 0.1.6 -->\n\u202f",- status: 1,- message: "Release notes must start with <!-- release-version: 0.1.6 -->",- },- {- scenario: "a U+FEFF-only reviewed summary",- summary: "<!-- release-version: 0.1.6 -->\n\ufeff",- status: 1,- message: "Release notes must start with <!-- release-version: 0.1.6 -->",- },{scenario: "a matching reviewed summary",summary: "<!-- release-version: 0.1.6 -->\nReviewed summary",diff --git a/sdk/typescript/tests-ts/release-cut-workflow.test.ts b/sdk/typescript/tests-ts/release-cut-workflow.test.tsdeleted file mode 100644index ab91a5ff2..000000000--- a/sdk/typescript/tests-ts/release-cut-workflow.test.ts+++ /dev/null@@ -1,36 +0,0 @@-import { readFileSync } from "node:fs";-import { expect, test } from "bun:test";--test("checks out the same revision used to cut tags after main CI or a manual dispatch", () => {- const workflow = Bun.YAML.parse(- readFileSync(- new URL(- "../../../.github/workflows/node-release-cut.yml",- import.meta.url,- ),- "utf8",- ),- ) as {- on: Record<string, unknown>;- jobs: {- cut: {- env: { RELEASE_SHA: string };- steps: { uses?: string; with?: { ref?: string } }[];- };- };- };- expect(workflow.on).toEqual({- workflow_run: {- workflows: ["node-ci"],- types: ["completed"],- branches: ["main"],- },- workflow_dispatch: null,- });- const { env, steps } = workflow.jobs.cut;- const verifiedSha = "${{ github.event.workflow_run.head_sha || github.sha }}";- expect(env.RELEASE_SHA).toBe(verifiedSha);- expect(- steps.find(({ uses }) => uses?.startsWith("actions/checkout@"))?.with?.ref,- ).toBe(verifiedSha);-});diff --git a/sdk/typescript/tests-ts/release-pr.test.ts b/sdk/typescript/tests-ts/release-pr.test.tsindex adb742ae6..18b97e418 100644--- a/sdk/typescript/tests-ts/release-pr.test.ts+++ b/sdk/typescript/tests-ts/release-pr.test.ts@@ -930,12 +930,13 @@ describe("GitHub request transport", () => {expect(fixture.github.writes).toHaveLength(0);const first = await run();fixture.merge("fix: later fix");+ let humanSha = "";fixture.github.beforeRefWrite = () => {const notes = fixture.repo.readFile(fixture.head(first.plan.branch)!,notesPath,)!;- fixture.commit(+ humanSha = fixture.commit(first.plan.branch,{[notesPath]: notes.replace(@@ -954,11 +955,9 @@ describe("GitHub request transport", () => {"Human-reviewed release note",);expect(updated.reviewRequested).toBe(true);- fixture.git(- "merge-base",- "--is-ancestor",- first.headSha!,- updated.headSha!,+ fixture.git("merge-base", "--is-ancestor", humanSha, updated.headSha!);+ expect(fixture.github.comments.get(updated.pull!)!.at(-1)!.body).toContain(+ "later fix",);});@@ -1577,6 +1576,7 @@ describe("rolling release reconciliation", () => {).toBe("chore(release): 0.2.0");expect(second.plan.branch).toBe(first.plan.branch);expect(pull.body).toBe(humanBody);+ expect(pull.draft).toBe(false);expect(fixture.repo.readFile(second.headSha!, "sdk/typescript/src/example.ts"),).toContain("next");@@ -1863,35 +1863,6 @@ describe("rolling release reconciliation", () => {expect(fixture.github.comments.get(first.pull!)).toHaveLength(3);});- test("retries a concurrent human commit without dropping its notes or history", async () => {- const { fixture, first } = await Fixture.withInitialPull();- fixture.merge("fix: later fix");- let humanSha = "";- fixture.github.beforeRefWrite = () => {- const notes = fixture.repo.readFile(- fixture.head(first.plan.branch)!,- notesPath,- )!;- humanSha = fixture.commit(- first.plan.branch,- {- [notesPath]: notes.replace(- "initial feature",- "Human migration details",- ),- },- "docs: review release notes",- );- };- const result = await fixture.run();- expect(result.plan.humanOwned).toEqual(["highlights"]);- expect(result.plan.files[notesPath]).toContain("Human migration details");- fixture.git("merge-base", "--is-ancestor", humanSha, result.headSha!);- expect(fixture.github.comments.get(result.pull!)!.at(-1)!.body).toContain(- "later fix",- );- });-test("recomputes when main moves during the update", async () => {const fixture = new Fixture();fixture.merge("feat: initial feature");@@ -2286,25 +2257,15 @@ describe("release proposal pauses", () => {).toHaveLength(1);});- test.each([false, true])(- "updates an existing proposal with draft=%p",- async (draft) => {- const { fixture, first, pull } = await Fixture.withInitialPull();- pull.draft = draft;- pull.body += "\nMaintainer review notes.\n";- const reviewedBody = pull.body;- const reviewedHead = fixture.head(first.plan.branch);- fixture.merge("feat!: later breaking change");- const updated = await fixture.run();- expect(updated.action).toBe("updated");- expect(updated.pull).toBe(first.pull);- expect(updated.plan.version).toBe("0.2.0");- expect(fixture.head(first.plan.branch)).not.toBe(reviewedHead);- expect(pull.title).toBe(updated.plan.title);- expect(pull.body).toBe(reviewedBody);- expect(pull.draft).toBe(draft);- },- );+ test("keeps an existing release proposal in draft when updating it", async () => {+ const { fixture, first, pull } = await Fixture.withInitialPull();+ pull.draft = true;+ fixture.merge("feat!: later breaking change");+ const updated = await fixture.run();+ expect(updated.action).toBe("updated");+ expect(updated.pull).toBe(first.pull);+ expect(pull.draft).toBe(true);+ });test("does not advance a proposal closed during preparation", async () => {const { fixture, first, pull } = await Fixture.withInitialPull();diff --git a/sdk/typescript/tests-ts/release-progress-workflow.test.ts b/sdk/typescript/tests-ts/release-progress-workflow.test.tsindex e46785c11..6bd7b630d 100644--- a/sdk/typescript/tests-ts/release-progress-workflow.test.ts+++ b/sdk/typescript/tests-ts/release-progress-workflow.test.ts@@ -96,14 +96,29 @@ test("main CI completions report independently of cutting a release", () => {"utf8",),) as {- on: { workflow_run: unknown };- jobs: { progress: { if: string; uses: string }; cut: unknown };+ on: Record<string, unknown>;+ jobs: {+ progress: { if: string; uses: string };+ cut: {+ env: { RELEASE_SHA: string };+ steps: { uses?: string; with?: { ref?: string } }[];+ };+ };};- expect(cut.on.workflow_run).toEqual({- workflows: ["node-ci"],- types: ["completed"],- branches: ["main"],+ expect(cut.on).toEqual({+ workflow_run: {+ workflows: ["node-ci"],+ types: ["completed"],+ branches: ["main"],+ },+ workflow_dispatch: null,});+ const verifiedSha = "${{ github.event.workflow_run.head_sha || github.sha }}";+ expect(cut.jobs.cut.env.RELEASE_SHA).toBe(verifiedSha);+ expect(+ cut.jobs.cut.steps.find(({ uses }) => uses?.startsWith("actions/checkout@"))+ ?.with?.ref,+ ).toBe(verifiedSha);expect(cut.jobs.progress.uses).toBe("./.github/workflows/release-progress.yml",);diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.tsindex 1d9f35902..2dcc0cdd9 100644--- a/sdk/typescript/tests-ts/runtime.test.ts+++ b/sdk/typescript/tests-ts/runtime.test.ts@@ -99,7 +99,7 @@ import {streamWindowsCredentialAclDescriptors,} from "../src/runtime.js";import { inspectTrustedExecutable } from "../src/trusted-executable.js";-import { loadBundledRuntime, PLUGIN_ROOT } from "./plugin-root.js";+import { PLUGIN_ROOT } from "./plugin-root.js";import { runTestInSubprocess } from "./support/test-subprocess.js";import {lowerUuid7Turn,@@ -241,6 +241,7 @@ interface McpServerResponse {capabilities?: Record<string, unknown>;tools?: Array<{name: string;+ _meta?: { ui?: { visibility?: string[] } };inputSchema: {properties: { userContext?: { maxLength?: number } };};@@ -292,53 +293,6 @@ describe("plugin runtime preparation", () => {).toBe(true);});- test("forwards configured provider credentials through the MCP worker environment", async () => {- const providerKeys = [- "OPENAI_API_KEY",- "OPENROUTER_API_KEY",- "FIREWORKS_API_KEY",- "CHEAPER_INFERENCE_API_KEY",- "AWS_BEARER_TOKEN_BEDROCK",- "AWS_ACCESS_KEY_ID",- "AWS_SECRET_ACCESS_KEY",- "AWS_SESSION_TOKEN",- "AWS_PROFILE",- "AWS_REGION",- "AWS_DEFAULT_REGION",- "AWS_CONFIG_FILE",- "AWS_SHARED_CREDENTIALS_FILE",- "AWS_ROLE_ARN",- "AWS_ROLE_SESSION_NAME",- "AWS_WEB_IDENTITY_TOKEN_FILE",- "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",- "AWS_CONTAINER_CREDENTIALS_FULL_URI",- "AWS_CONTAINER_AUTHORIZATION_TOKEN",- "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",- ];- const configuration = JSON.parse(- await readFile(join(PLUGIN_ROOT, ".mcp.json"), "utf8"),- ) as {- mcpServers: Record<string, { env_vars: string[] }>;- };- const parentEnvironment = Object.fromEntries(- providerKeys.map((name) => [name, `synthetic-${name.toLowerCase()}`]),- );- const allowed = new Set(- configuration.mcpServers["codex-security"]!.env_vars,- );- const mcpEnvironment = Object.fromEntries(- Object.entries(parentEnvironment).filter(([name]) => allowed.has(name)),- );- const worker = spawnSync(- process.execPath,- ["-e", "process.stdout.write(JSON.stringify(process.env))"],- { encoding: "utf8", env: mcpEnvironment },- );-- expect(worker.status).toBe(0);- expect(JSON.parse(worker.stdout)).toMatchObject(parentEnvironment);- });-test("rejects control characters in bundled artifact paths and candidate IDs", async () => {const schema = JSON.parse(await readFile(@@ -361,44 +315,6 @@ describe("plugin runtime preparation", () => {}});- test("derives distinct finding identities from canonical candidate IDs", async () => {- const runtime = await loadBundledRuntime();- const source =- /function buildFindings\(findings, mode\) \{[\s\S]*?\n\}/u.exec(- runtime,- )?.[0];- const candidateSource =- /function findingIdentityCandidate\(finding\) \{[\s\S]*?\n\}/u.exec(- runtime,- )?.[0];- const identitySource =- /function scanFindingIdentity\(finding\) \{[\s\S]*?\n\}/u.exec(- runtime,- )?.[0];- expect(source).toBeDefined();- expect(candidateSource).toBeDefined();- expect(identitySource).toBeDefined();- const buildFindings = new Function(- "semanticIdentifier",- `${candidateSource}\n${identitySource}\n${source}\nreturn buildFindings;`,- )((value: string, fallback: string) => value || fallback) as (- findings: Array<{- title: string;- extensions: { candidateId: string };- }>,- ) => Array<{ identity: { anchor: string } }>;-- const findings = buildFindings([- { title: "Same finding", extensions: { candidateId: "candidate-a" } },- { title: "Same finding", extensions: { candidateId: "candidate-b" } },- ]);-- expect(findings.map((finding) => finding.identity.anchor)).toEqual([- "candidate-a",- "candidate-b",- ]);- });-test("generates canonical scoped security inventory paths", async () => {if (Bun.which("rg") === null) {return;@@ -425,24 +341,29 @@ describe("plugin runtime preparation", () => {const output = join(root, "inventory.txt");const repeatedOutput = join(root, "inventory-repeated.txt");- const generatorArguments = (destination: string) =>- [- join(PLUGIN_ROOT, "mcp", "helpers.mjs"),- "generate-in-scope-files",- "--repo",- repository,- "--scope",- ".",- "--out",- destination,- ] as const;+ if (process.platform !== "win32") {+ await writeFile(+ join(repository, String.raw`literal\backslash.txt`),+ "backslash\n",+ );+ await writeFile(join(repository, "literal:colon.txt"), "colon\n");+ }++ const node = nodeCommand().command;for (const destination of [output, repeatedOutput]) {const inventory = spawnSync(- nodeCommand().command,- generatorArguments(destination),- {- encoding: "utf8",- },+ node,+ [+ join(PLUGIN_ROOT, "mcp", "helpers.mjs"),+ "generate-in-scope-files",+ "--repo",+ repository,+ "--scope",+ ".",+ "--out",+ destination,+ ],+ { encoding: "utf8" },);expect(inventory.status, inventory.stderr).toBe(0);}@@ -463,25 +384,8 @@ describe("plugin runtime preparation", () => {}}if (process.platform !== "win32") {- await writeFile(- join(repository, String.raw`literal\backslash.txt`),- "backslash\n",- );- await writeFile(join(repository, "literal:colon.txt"), "colon\n");- const posixOutput = join(root, "inventory-posix-filenames.txt");- const inventory = spawnSync(- nodeCommand().command,- generatorArguments(posixOutput),- {- encoding: "utf8",- },- );- expect(inventory.status, inventory.stderr).toBe(0);- const posixRows = (await readFile(posixOutput, "utf8"))- .trimEnd()- .split(/\r?\n/u);- expect(posixRows).toContain(String.raw`./literal\backslash.txt`);- expect(posixRows).toContain("./literal:colon.txt");+ expect(rows).toContain(String.raw`./literal\backslash.txt`);+ expect(rows).toContain("./literal:colon.txt");}});@@ -566,39 +470,7 @@ describe("plugin runtime preparation", () => {expect(verification.status, verification.stderr).toBe(0);});- test("allows the workbench to derive missing deferred scan identifiers", async () => {- const schema = JSON.parse(- await readFile(- join(PLUGIN_ROOT, "schemas", "tools", "scan-draft.schema.json"),- "utf8",- ),- ) as {- $defs: {- coverage: {- properties: { deferred: { items: { required: string[] } } };- };- };- };-- expect(schema.$defs.coverage.properties.deferred.items.required).toEqual([- "reason",- ]);- });-- test("accepts preserved context before starting a headless scan", async () => {- const responses = await inspectMcpServer();- const tool = responses- .find((response) => response.id === 2)- ?.result.tools?.find(- (candidate) => candidate.name === "start_codex_security_standard_scan",- );- const userContext = "Assess the HTTP boundary. ".repeat(320);-- expect(userContext.length).toBeGreaterThan(2400);- expect(tool?.inputSchema.properties.userContext?.maxLength).toBeUndefined();- });-- test("keeps native scan tools without the obsolete setup widget", async () => {+ test("exposes native scan tools and unbounded scan context without the obsolete widget", async () => {const contract = JSON.parse(await readFile(new URL(@@ -615,10 +487,21 @@ describe("plugin runtime preparation", () => {expect(responses.find((response) => response.id === 1)?.result.capabilities,).not.toHaveProperty("resources");- const names = new Set(- responses- .find((response) => response.id === 2)- ?.result.tools?.map((tool) => tool.name),+ const tools = responses.find((response) => response.id === 2)!.result+ .tools!;+ const names = new Set(tools.map((tool) => tool.name));+ for (const tool of tools) {+ if (tool._meta?.ui?.visibility?.includes("model") === false) continue;+ expect(`mcp__codex_security__${tool.name}`.length).toBeLessThanOrEqual(+ 64,+ );+ }+ const standardScan = tools.find(+ (tool) => tool.name === "start_codex_security_standard_scan",+ )!;+ expect(standardScan.inputSchema.properties.userContext).toBeDefined();+ expect(standardScan.inputSchema.properties.userContext).not.toHaveProperty(+ "maxLength",);for (const name of ["open_codex_security_workspace",@@ -1749,6 +1632,7 @@ for await (const line of createInterface({ input: process.stdin })) {await expect(extractPluginZip(path, join(root, "extract")),).rejects.toThrow(PluginBootstrapError);+ expect(await readdir(root)).toEqual([`${name}.zip`]);}});@@ -6808,18 +6692,4 @@ describe("runtime directories and plugin Python boundary", () => {await expect(resolving).rejects.toMatchObject({ name: "AbortError" });},);-- test("does not leave extraction staging directories after failure", async () => {- const root = await temporaryDirectory();- const archive = join(root, "bad.zip");- await writeFile(archive, zipSync({ "../escape": strToU8("bad") }));- await expect(- extractPluginZip(archive, join(root, "extract")),- ).rejects.toThrow();- expect(- (await readdir(root)).some((name) =>- name.startsWith(".codex-security-plugin-"),- ),- ).toBe(false);- });});diff --git a/sdk/typescript/tests-ts/saved-scan-bootstrap.test.ts b/sdk/typescript/tests-ts/saved-scan-bootstrap.test.tsindex 840351795..67038085b 100644--- a/sdk/typescript/tests-ts/saved-scan-bootstrap.test.ts+++ b/sdk/typescript/tests-ts/saved-scan-bootstrap.test.ts@@ -23,6 +23,7 @@ import type { Finding } from "../src/models.js";import type { JsonObject } from "../src/config.js";import type { CodexReview } from "../src/deduplication/codex-review.js";import { screeningPairSlot } from "../src/deduplication/deduplication-reviewer.js";+import { git } from "./git-fixture.js";import { copyCompletedScanFixture, PLUGIN_ROOT } from "./plugin-root.js";import { createApiTestFixtures } from "./support/temporary-directories.js";import { rejecting } from "./support/errors.js";@@ -34,7 +35,15 @@ const { temporaryDirectory, cleanup } = createApiTestFixtures();afterEach(cleanup);-async function workspace(git = false) {+function writePythonProbe(path: string) {+ return writeFile(+ path,+ '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',+ { mode: 0o700 },+ );+}++async function workspace(versioned = false) {const root = await temporaryDirectory();const repository = join(root, "repository");await mkdir(join(repository, "src"), { recursive: true });@@ -42,28 +51,11 @@ async function workspace(git = false) {join(repository, "src", "extract.py"),"# Synthetic fixture\n",);- if (git) {- execFileSync("git", ["init", "-q", repository]);- execFileSync("git", [- "-C",- repository,- "config",- "--local",- "core.autocrlf",- "false",- ]);- execFileSync("git", ["-C", repository, "add", "."]);- execFileSync("git", [- "-C",- repository,- "-c",- "user.name=Synthetic Fixture",- "-c",- "[email protected]",- "commit",- "-qm",- "Synthetic fixture",- ]);+ if (versioned) {+ git(repository, "init", "-q");+ git(repository, "config", "--local", "core.autocrlf", "false");+ git(repository, "add", ".");+ git(repository, "commit", "-qm", "Synthetic fixture");}const environment = {PATH: process.env["PATH"],@@ -75,31 +67,39 @@ async function workspace(git = false) {return { root, repository, environment, python };}-async function fixture(git = false, separateSetupCommands = false) {- const base = await workspace(git);+async function registerScan(+ f: Awaited<ReturnType<typeof workspace>>,+ scanDir: string,+) {+ await mkdir(scanDir, { mode: 0o700 });+ const registered = await runWorkbench(+ { environment: f.environment, python: f.python, pluginRoot: PLUGIN_ROOT },+ scanRegistrationArguments(f.repository, scanDir),+ );+ return registered["scanId"] as string;+}++async function fixture(versioned = false, separateSetupCommands = false) {+ const base = await workspace(versioned);const { root, repository, environment, python } = base;const options = { environment, python, pluginRoot: PLUGIN_ROOT };const registrationArguments = (scanDir: string) =>scanRegistrationArguments(repository, scanDir);- async function scan(name: string, registered?: JsonObject) {+ async function scan(name: string, registration?: JsonObject) {const scanDir = join(root, name);- if (registered === undefined) {- await mkdir(scanDir, { mode: 0o700 });- registered = await runWorkbench(options, registrationArguments(scanDir));- }- const scanId = registered["scanId"] as string;+ const scanId = registration+ ? (registration["scanId"] as string)+ : await registerScan(base, scanDir);await copyCompletedScanFixture(scanDir);const manifest = JSON.parse(await readFile(join(scanDir, "scan-manifest.json"), "utf8"),);manifest.scan.id = scanId;- manifest.scan.target.kind = git ? "git_revision" : "directory_snapshot";- if (git)- manifest.scan.target.revision = execFileSync(- "git",- ["-C", repository, "rev-parse", "HEAD"],- { encoding: "utf8" },- ).trim();+ manifest.scan.target.kind = versioned+ ? "git_revision"+ : "directory_snapshot";+ if (versioned)+ manifest.scan.target.revision = git(repository, "rev-parse", "HEAD");delete manifest.scan.sealedAt;delete manifest.scan.artifacts;await writeFile(@@ -214,23 +214,9 @@ test("historical reviews carry the saved occurrence revision instead of the currjoin(f.repository, "src", "extract.py"),"# Changed synthetic source\n",);- execFileSync("git", ["-C", f.repository, "add", "."]);- execFileSync("git", [- "-C",- f.repository,- "-c",- "user.name=Synthetic Fixture",- "-c",- "[email protected]",- "commit",- "-qm",- "Changed synthetic source",- ]);- expect(- execFileSync("git", ["-C", f.repository, "rev-parse", "HEAD"], {- encoding: "utf8",- }).trim(),- ).not.toBe(revision);+ git(f.repository, "add", ".");+ git(f.repository, "commit", "-qm", "Changed synthetic source");+ expect(git(f.repository, "rev-parse", "HEAD")).not.toBe(revision);let calls = 0;await deduplicateScanInternal(f.first.scanId,@@ -285,11 +271,7 @@ for (const source of ["PYTHON", "PATH", "linked PYTHON"] as const) {await deduplicateScanInternal(f.first.scanId, options, dependencies);const executable = join(f.repository, "python3");const marker = join(f.root, "probed");- await writeFile(- executable,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(executable, 0o700);+ await writePythonProbe(executable);const linked = join(f.root, "linked-python");if (source === "linked PYTHON") await symlink(executable, linked);const environment = {@@ -595,11 +577,7 @@ test.skipIf(process.platform === "win32")();const executable = join(f.repository, "python3");const marker = join(f.root, "probed");- await writeFile(- executable,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(executable, 0o700);+ await writePythonProbe(executable);const options = {environment: {...f.environment,@@ -700,11 +678,7 @@ test.skipIf(process.platform === "win32")(await mkdir(join(caller, ".git"));const python = join(caller, "python3");const marker = join(f.root, "caller-probed");- await writeFile(- python,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(python, 0o700);+ await writePythonProbe(python);const source = new URL("../src/runtime.ts", import.meta.url).href;const script = `const { resolvePluginPython } = await import(${JSON.stringify(source)});@@ -735,11 +709,7 @@ test.skipIf(process.platform === "win32")();const python = join(f.repository, "python3");const marker = join(f.root, "cli-probed");- await writeFile(- python,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(python, 0o700);+ await writePythonProbe(python);const source = new URL("../src/cli.ts", import.meta.url).href;for (const args of [["dedupe", "--scan", f.first.scanId],@@ -801,11 +771,11 @@ for (const entry of [test.skipIf(process.platform === "win32")(`non-Git caller PATH is protected before Python probes through ${entry}`,async () => {- const saved =- entry === "bootstrap" || entry === "helper"- ? await fixture()+ const f = await workspace();+ const scanId =+ entry === "helper" || entry === "bootstrap"+ ? await registerScan(f, join(f.root, "scan")): undefined;- const f = saved ?? (await workspace());const caller = join(f.root, "non-git-caller");const callerBin = join(caller, "bin");const trustedBin = join(f.root, "trusted-bin");@@ -818,11 +788,7 @@ for (const entry of [const marker = join(f.root, "untrusted-python-probed");for (const path of [caller, callerBin]) {const python = join(path, "python3");- await writeFile(- python,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(python, 0o700);+ await writePythonProbe(python);await symlink(python, join(path, ".python"));}await symlink(join(callerBin, "python3"), join(linkedBin, "python3"));@@ -836,7 +802,7 @@ for (const entry of [import assert from "node:assert/strict";import { realpath } from "node:fs/promises";const { resolvePluginPython, runWorkbench } = await import(${JSON.stringify(runtime)});- const scanId = ${JSON.stringify(saved?.first.scanId)};+ const scanId = ${JSON.stringify(scanId)};const options = { environment: process.env, protectedRoot: ${JSON.stringify(f.repository)}, pluginRoot: ${JSON.stringify(PLUGIN_ROOT)} };if (${JSON.stringify(entry)} === "bootstrap") {const { savedScanWorkbench } = await import(${JSON.stringify(bootstrap)});@@ -879,11 +845,7 @@ test.skipIf(process.platform === "win32")(await mkdir(join(f.repository, ".git"));const python = join(f.repository, "python3");const marker = join(f.root, "enclosing-checkout-probed");- await writeFile(- python,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(python, 0o700);+ await writePythonProbe(python);await expect(resolvePluginPython({environment: {@@ -898,60 +860,50 @@ test.skipIf(process.platform === "win32")(},);-for (const selector of ["latest", "workflow"] as const) {- test(`bootstrap ${selector} ignores unrelated history enclosing trusted Python`, async () => {- const f = await fixture(true);- const workflowId = "scoped-bootstrap";- await deduplicateScanInternal(- f.first.scanId,- { workflowId, embedding: f.embedding },- { environment: f.environment, reviewer: f.reviewer },- );- const db = new Database(- join(f.environment.CODEX_SECURITY_STATE_DIR, "workbench.sqlite3"),- );- try {- db.query("INSERT INTO security_targets VALUES (?, ?, ?, ?, ?)").run(- "unrelated-target",- dirname(f.python),- "Unrelated synthetic target",- "2026-01-01T00:00:00Z",- "2026-01-01T00:00:00Z",- );- db.query(- "UPDATE scans SET target_path = ?, target_id = ? WHERE id = ?",- ).run(dirname(f.python), "unrelated-target", f.second.scanId);- } finally {- db.close();- }- const workbench = await savedScanWorkbench(- selector === "latest" ? "latest" : { workflowId },- {- environment: { ...f.environment, PYTHON: f.python },- pluginRoot: PLUGIN_ROOT,- currentDirectory: f.repository,- },+test("latest and workflow selectors ignore unrelated history enclosing trusted Python", async () => {+ const f = await fixture(true);+ const workflowId = "scoped-bootstrap";+ await deduplicateScanInternal(+ f.first.scanId,+ { workflowId, embedding: f.embedding },+ { environment: f.environment, reviewer: f.reviewer },+ );+ const db = new Database(+ join(f.environment.CODEX_SECURITY_STATE_DIR, "workbench.sqlite3"),+ );+ try {+ db.query("INSERT INTO security_targets VALUES (?, ?, ?, ?, ?)").run(+ "unrelated-target",+ dirname(f.python),+ "Unrelated synthetic target",+ "2026-01-01T00:00:00Z",+ "2026-01-01T00:00:00Z",);- if (selector === "latest") {- expect(- (- await resolveCompletedScan("latest", {- currentDirectory: () => f.repository,- runWorkbench: workbench,- })- ).scanId,- ).toBe(f.first.scanId);- } else {- const result = await workbench(- ["finding-workflow"],- JSON.stringify({ id: workflowId, action: "get" }),- );- expect((result["workflow"] as { scanId: string }).scanId).toBe(- f.first.scanId,- );- }+ db.query(+ "UPDATE scans SET target_path = ?, target_id = ? WHERE id = ?",+ ).run(dirname(f.python), "unrelated-target", f.second.scanId);+ } finally {+ db.close();+ }+ const options = {+ environment: { ...f.environment, PYTHON: f.python },+ pluginRoot: PLUGIN_ROOT,+ currentDirectory: f.repository,+ };+ const latest = await resolveCompletedScan("latest", {+ currentDirectory: () => f.repository,+ runWorkbench: await savedScanWorkbench("latest", options),});-}+ expect(latest.scanId).toBe(f.first.scanId);+ const workbench = await savedScanWorkbench({ workflowId }, options);+ const result = await workbench(+ ["finding-workflow"],+ JSON.stringify({ id: workflowId, action: "get" }),+ );+ expect((result["workflow"] as { scanId: string }).scanId).toBe(+ f.first.scanId,+ );+});test.skipIf(process.platform === "win32" || process.getuid?.() === 0)("workflow bootstrap ignores inaccessible unrelated history",@@ -1073,11 +1025,7 @@ test.skipIf(process.platform === "win32")(}const executable = join(f.repository, "python3");const marker = join(f.root, "legacy-probed");- await writeFile(- executable,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- );- await chmod(executable, 0o700);+ await writePythonProbe(executable);const workbench = await savedScanWorkbench({ workflowId: "legacy-workflow" },{@@ -1167,7 +1115,7 @@ connection.close()});}-test("latest considers scan and progress updates, start times, and scan IDs", async () => {+test("latest orders uncanceled scans by update, start time, and ID", async () => {const older = "2026-08-01T03:00:00.000001+02:00";const newer = "2026-08-01T01:00:00.000002Z";const f = await fixture();@@ -1222,8 +1170,14 @@ test("latest considers scan and progress updates, start times, and scan IDs", asolderScan.scanId,);expect(await latest()).toBe(olderScan.scanId);+ db.query(+ "UPDATE scans SET canceled_at = '2099-01-02T00:00:00Z' WHERE id = ?",+ ).run(olderScan.scanId);+ expect(await latest()).toBe(newerScan.scanId);// Equal updates fall back to the scans' chronological start times.- db.query("UPDATE scans SET updated_at = '2099-01-01T00:00:00Z'").run();+ db.query(+ "UPDATE scans SET canceled_at = NULL, updated_at = '2099-01-01T00:00:00Z'",+ ).run();db.query("UPDATE scan_progress SET updated_at = '2099-01-01T00:00:00Z'",).run();@@ -1243,38 +1197,6 @@ test("latest considers scan and progress updates, start times, and scan IDs", as}});-test("latest follows progress timestamps and excludes canceled scans", async () => {- const f = await fixture();- const db = new Database(- join(f.environment.CODEX_SECURITY_STATE_DIR, "workbench.sqlite3"),- );- try {- db.query(- "UPDATE scan_progress SET updated_at = '2099-01-01T00:00:00Z' WHERE scan_id = ?",- ).run(f.first.scanId);- async function latest() {- const workbench = await savedScanWorkbench("latest", {- environment: { ...f.environment, PYTHON: f.python },- pluginRoot: PLUGIN_ROOT,- currentDirectory: f.repository,- });- return (- await resolveCompletedScan("latest", {- currentDirectory: () => f.repository,- runWorkbench: workbench,- })- ).scanId;- }- expect(await latest()).toBe(f.first.scanId);- db.query(- "UPDATE scans SET canceled_at = '2099-01-02T00:00:00Z' WHERE id = ?",- ).run(f.first.scanId);- expect(await latest()).toBe(f.second.scanId);- } finally {- db.close();- }-});-for (const kind of ["non-Git", "symlinked"] as const) {test.skipIf(process.platform === "win32")(`latest never executes Git from a saved ${kind} target`,@@ -1339,16 +1261,13 @@ for (const kind of ["non-Git", "symlinked"] as const) {test.skipIf(process.platform === "win32")("bootstrap protects a target committed only to the live WAL",async () => {- const f = await fixture();+ const f = await workspace();+ const scanId = await registerScan(f, join(f.root, "scan"));const target = join(f.root, "wal-target");await mkdir(target);const executable = join(target, "python3");const marker = join(f.root, "wal-target-probed");- await writeFile(- executable,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- { mode: 0o700 },- );+ await writePythonProbe(executable);const db = new Database(join(f.environment.CODEX_SECURITY_STATE_DIR, "workbench.sqlite3"),);@@ -1356,9 +1275,9 @@ test.skipIf(process.platform === "win32")(db.exec("PRAGMA wal_autocheckpoint = 0");db.query("UPDATE scans SET target_path = ? WHERE id = ?").run(target,- f.first.scanId,+ scanId,);- const workbench = await savedScanWorkbench(f.first.scanId, {+ const workbench = await savedScanWorkbench(scanId, {environment: {...f.environment,PYTHON: executable,@@ -1368,7 +1287,7 @@ test.skipIf(process.platform === "win32")(currentDirectory: f.root,});await expect(- workbench(["get-scan", "--scan-id", f.first.scanId]),+ workbench(["get-scan", "--scan-id", scanId]),).rejects.toThrow("PYTHON interpreter is unavailable or unusable");expect(existsSync(marker)).toBe(false);} finally {@@ -1378,7 +1297,8 @@ test.skipIf(process.platform === "win32")();test("saved-scan bootstrap waits for a concurrent database writer", async () => {- const f = await fixture();+ const f = await workspace();+ const scanId = await registerScan(f, join(f.root, "scan"));const writer = spawn(process.execPath,[@@ -1404,13 +1324,13 @@ test("saved-scan bootstrap waits for a concurrent database writer", async () =>throw new Error("Writer exited before acquiring its lock");}),]);- const workbench = await savedScanWorkbench(f.first.scanId, {+ const workbench = await savedScanWorkbench(scanId, {environment: f.environment,currentDirectory: f.repository,pluginRoot: PLUGIN_ROOT,});- const result = await workbench(["get-scan", "--scan-id", f.first.scanId]);- expect((result["scan"] as { scanId: string }).scanId).toBe(f.first.scanId);+ const result = await workbench(["get-scan", "--scan-id", scanId]);+ expect((result["scan"] as { scanId: string }).scanId).toBe(scanId);expect((await closed)[0]).toBe(0);} finally {writer.kill();@@ -1433,11 +1353,7 @@ for (const kind of ["missing", "symlinked"] as const) {}const python = join(f.repository, "python3");const marker = join(f.root, "missing-target-probed");- await writeFile(- python,- '#!/bin/sh\nprintf probed > "$TEST_PYTHON_PROBE"\nprintf "codex-security-python-ok\\n"\n',- { mode: 0o700 },- );+ await writePythonProbe(python);const db = new Database(join(f.environment.CODEX_SECURITY_STATE_DIR, "workbench.sqlite3"),);diff --git a/sdk/typescript/tests-ts/scan-directory-identity.test.ts b/sdk/typescript/tests-ts/scan-directory-identity.test.tsindex 3fc882ad3..e8b968d86 100644--- a/sdk/typescript/tests-ts/scan-directory-identity.test.ts+++ b/sdk/typescript/tests-ts/scan-directory-identity.test.ts@@ -34,8 +34,13 @@ const identities = [["unchanged", 2n ** 60n, 2n ** 60n],] as const;-for (const scenario of scenarios) {- for (const [kind, originalId, replacementId] of identities) {+for (const [kind, originalId, replacementId] of identities) {+ // Without a swap, the hooks all read the same root or parent directory.+ const cases =+ kind === "unchanged"+ ? (["initial-root", "parent-retains-leaf"] as const)+ : scenarios;+ for (const scenario of cases) {const title = `checked scan directory ${scenario} preserves ${kind} identities`;test(title, async () => {if (runTestInSubprocess(import.meta.path, title)) return;diff --git a/sdk/typescript/tests-ts/scan-recovery.test.ts b/sdk/typescript/tests-ts/scan-recovery.test.tsindex b23ee0e8d..2210f2f92 100644--- a/sdk/typescript/tests-ts/scan-recovery.test.ts+++ b/sdk/typescript/tests-ts/scan-recovery.test.ts@@ -306,11 +306,21 @@ describe("scan publication and artifact recovery", () => {},);- test("registers a Unicode scan recipe delivered through stdin", async () => {+ test("registers a Unicode stdin recipe with the authoritative directory contract", async () => {const fixture = await startDraftScan("directory", true);expect(fixture.registration).toMatchObject({scanDir: fixture.scanDir,targetRevision: "unversioned",+ contract: {+ target: {+ allowedKinds: ["directory_snapshot"],+ displayName: "répository-日本語",+ targetId: fixture.registration["targetId"],+ requiredSnapshotDigest: expect.stringMatching(+ /^codex-security-snapshot\/v1:sha256:[a-f0-9]{64}$/,+ ),+ },+ },});const saved = await workbench(fixture, ["get-scan-recipe",@@ -373,29 +383,6 @@ describe("scan publication and artifact recovery", () => {});}, 30_000);- test("returns the authoritative directory snapshot contract at registration", async () => {- const fixture = await startDraftScan();- const registration = fixture.registration;- const contract = registration["contract"] as {- target: {- allowedKinds: string[];- displayName: string;- targetId: string;- requiredSnapshotDigest?: string;- };- };-- expect(registration["targetRevision"]).toBe("unversioned");- expect(contract.target).toMatchObject({- allowedKinds: ["directory_snapshot"],- displayName: "repository",- targetId: registration["targetId"],- requiredSnapshotDigest: expect.stringMatching(- /^codex-security-snapshot\/v1:sha256:[a-f0-9]{64}$/,- ),- });- });-test("builds each ordinary scan context once without losing selected findings", async () => {const fixture = await startDraftScan();const findingsPath = join(fixture.scanDir, "findings.json");@@ -519,29 +506,6 @@ describe("scan publication and artifact recovery", () => {}});- test("seals a prepared scan without publishing it before acceptance", async () => {- const fixture = await startDraftScan();-- const prepared = await workbench(fixture, [- "prepare-scan-completion",- "--scan-id",- fixture.scanId,- ]);-- expect((prepared["scan"] as ScanSummary).progress.status).toBe("running");- const manifest = await readJson<{- scan: { sealedAt: string; completedAt: string };- }>(join(fixture.scanDir, "scan-manifest.json"));- expect(manifest.scan.sealedAt).toBe(manifest.scan.completedAt);- const running = await workbench(fixture, [- "get-scan",- "--scan-id",- fixture.scanId,- ]);- expect((running["scan"] as ScanSummary).progress.status).toBe("running");- expect((await completeScan(fixture)).progress.status).toBe("complete");- });-test.each([["unavailable", undefined],[@@ -698,7 +662,7 @@ describe("scan publication and artifact recovery", () => {});});- test("preserves missing-writeup warnings across prepared scan completion", async () => {+ test("keeps a prepared scan running and preserves its missing-writeup warning on completion", async () => {const fixture = await startDraftScan();const path = join(fixture.scanDir, "findings.json");const document = await readJson<FindingsDocument>(path);@@ -720,6 +684,17 @@ describe("scan publication and artifact recovery", () => {const preparedFindings = (await readJson<FindingsDocument>(path)).findings;expect(preparedFindings).toHaveLength(1);expect(preparedFindings[0]).not.toHaveProperty("writeup");+ const manifest = await readJson<{+ scan: { sealedAt: string; completedAt: string };+ }>(join(fixture.scanDir, "scan-manifest.json"));+ expect(manifest.scan.sealedAt).toBeTruthy();+ expect(manifest.scan.sealedAt).toBe(manifest.scan.completedAt);+ const running = await workbench(fixture, [+ "get-scan",+ "--scan-id",+ fixture.scanId,+ ]);+ expect((running["scan"] as ScanSummary).progress.status).toBe("running");const completion = await workbench(fixture, ["complete-scan","--scan-id",@@ -876,18 +851,6 @@ describe("scan publication and artifact recovery", () => {},);- test("refuses to repair scan-wide coverage contract violations", async () => {- const fixture = await startDraftScan();- const path = join(fixture.scanDir, "coverage.json");- const document = await readJson<CoverageDocument>(path);- document.inventoryStrategy = "";- await writeJson(path, document);- const original = await readFile(path, "utf8");-- await expect(completeScan(fixture)).rejects.toThrow("inventoryStrategy");- expect(await readFile(path, "utf8")).toBe(original);- });-test.each(["complete-scan", "prepare-scan-completion"] as const)("keeps a repairable %s contract failure resumable",async (command) => {@@ -897,10 +860,12 @@ describe("scan publication and artifact recovery", () => {const validInventoryStrategy = document.inventoryStrategy;document.inventoryStrategy = "";await writeJson(path, document);+ const original = await readFile(path);await expect(workbench(fixture, [command, "--scan-id", fixture.scanId]),).rejects.toThrow("inventoryStrategy");+ expect(await readFile(path)).toEqual(original);const pending = await workbench(fixture, ["get-scan","--scan-id",diff --git a/sdk/typescript/tests-ts/security-policy-helper.test.ts b/sdk/typescript/tests-ts/security-policy-helper.test.tsindex 4a08dbc5d..03045021e 100644--- a/sdk/typescript/tests-ts/security-policy-helper.test.ts+++ b/sdk/typescript/tests-ts/security-policy-helper.test.ts@@ -934,34 +934,28 @@ binding.readdir = function (...args) {}});- test.each(["regular", "linked"])(- "resolves complete root and nested %s policies larger than 1 MiB",- (kind) => {- const { root } = fixture();- const rootContent = `${"root policy é\n".repeat(100_000)}root policy end\n`;- const nestedContent = `${"nested policy 文\n".repeat(100_000)}nested policy end\n`;- for (const [path, content, target] of [- ["SECURITY.md", rootContent, "policies/root.md"],- ["component/SECURITY.md", nestedContent, "policies/component.md"],- ] as const) {- expect(Buffer.byteLength(content, "utf8")).toBeGreaterThan(1024 * 1024);- write(root, kind === "linked" ? target : path, content);- if (kind === "linked") {- mkdirSync(dirname(join(root, path)), { recursive: true });- symlinkSync(join(root, target), join(root, path), "file");- }- }- const rootResult = resolve(root, ".");- expect(rootResult.status, rootResult.stderr).toBe(0);- expectGuidance(rootResult.stdout, [["SECURITY.md", rootContent]]);- const nestedResult = resolve(root, "component");- expect(nestedResult.status, nestedResult.stderr).toBe(0);- expectGuidance(nestedResult.stdout, [- ["SECURITY.md", rootContent],- ["component/SECURITY.md", nestedContent],- ]);- },- );+ test("resolves complete root and linked nested policies larger than 1 MiB", () => {+ const { root } = fixture();+ const rootContent = `${"root policy é\n".repeat(100_000)}root policy end\n`;+ const nestedContent = `${"nested policy 文\n".repeat(100_000)}nested policy end\n`;+ expect(Buffer.byteLength(rootContent)).toBeGreaterThan(1024 * 1024);+ expect(Buffer.byteLength(nestedContent)).toBeGreaterThan(1024 * 1024);+ write(root, "SECURITY.md", rootContent);+ write(root, "policies/component.md", nestedContent);+ mkdirSync(join(root, "component"));+ symlinkSync(+ join(root, "policies/component.md"),+ join(root, "component/SECURITY.md"),+ "file",+ );++ const result = resolve(root, "component");+ expect(result.status, result.stderr).toBe(0);+ expectGuidance(result.stdout, [+ ["SECURITY.md", rootContent],+ ["component/SECURITY.md", nestedContent],+ ]);+ });test("preserves required and mutually exclusive helper arguments", () => {const { root } = fixture();diff --git a/sdk/typescript/tests-ts/semgrep-findings-local.test.ts b/sdk/typescript/tests-ts/semgrep-findings-local.test.tsindex 0fdc36501..e26ef29c3 100644--- a/sdk/typescript/tests-ts/semgrep-findings-local.test.ts+++ b/sdk/typescript/tests-ts/semgrep-findings-local.test.ts@@ -1,4 +1,4 @@-import { access, readFile, writeFile } from "node:fs/promises";+import { access, readFile, rm, writeFile } from "node:fs/promises";import { gzipSync } from "node:zlib";import { join } from "node:path";import { expect, test } from "bun:test";@@ -16,18 +16,26 @@ import {semgrepJson,semgrepSarif,} from "./support/semgrep-import-fixtures.js";+import { temporaryDirectory } from "./support/temporary-directories.js";const repositoryUrl = "https://github.com/example/project";const formats = ["JSON", "SARIF"] as const;function report(format: (typeof formats)[number],- message = "Synthetic finding",- sparse = false,+ {+ line = 3,+ fingerprint = "synthetic-fingerprint",+ message = "Synthetic finding",+ sparse = false,+ } = {},) {if (format === "JSON") {const input = semgrepJson();const result = input.results[0]!;+ result.start.line = line;+ result.end.line = line;+ result.extra.fingerprint = fingerprint;result.extra.message = message;if (sparse) {result.path = "../outside.ts";@@ -39,6 +47,10 @@ function report(const input = semgrepSarif();const run = input.runs[0]!;const result = run.results[0]!;+ const region = result.locations[0]!.physicalLocation.region;+ region.startLine = line;+ region.endLine = line;+ result.fingerprints["matchBasedId/v1"] = fingerprint;result.message.text = message;if (sparse) {result.locations[0]!.physicalLocation.artifactLocation.uri =@@ -48,37 +60,11 @@ function report(return input;}-function reportAtLine(- format: (typeof formats)[number],- line: number,- fingerprint: string,-) {- if (format === "JSON") {- const input = semgrepJson();- const result = input.results[0]!;- result.start.line = line;- result.end.line = line;- result.extra.fingerprint = fingerprint;- return input;- }- const input = semgrepSarif();- const result = input.runs[0]!.results[0]!;- const region = result.locations[0]!.physicalLocation.region;- region.startLine = line;- region.endLine = line;- result.fingerprints["matchBasedId/v1"] = fingerprint;- return input;-}-test("Semgrep file reader rejects malformed SARIF repository provenance", async () => {- const fixture = await localFindingsFixture();+ const directory = await temporaryDirectory("semgrep-reader-");try {- const file = join(fixture.root, "semgrep.sarif");- const input = semgrepSarif();- input.runs = input.runs.map((run) => ({- ...run,- versionControlProvenance: [{ repositoryUri: 'http://""?\nX' }],- }));+ const file = join(directory, "semgrep.sarif");+ const input = sarifWithRepositories(['http://""?\nX']);await writeFile(file, JSON.stringify(input));await expect(readSemgrepFindings(file, { sourceRepositoryUrl: repositoryUrl }),@@ -86,7 +72,7 @@ test("Semgrep file reader rejects malformed SARIF repository provenance", async"SARIF source repository does not match the declared source repository URL.",);} finally {- await fixture.dispose();+ await rm(directory, { recursive: true, force: true });}});@@ -107,16 +93,22 @@ for (const suppliedFingerprint of [true, false]) {const fingerprint = suppliedFingerprint? "synthetic-fingerprint": "requires login";- async function importLine(line: number) {+ async function prepareLine(line: number, message?: string) {await writeFile(file,- JSON.stringify(reportAtLine(format, line, fingerprint)),+ JSON.stringify(report(format, { line, fingerprint, message })),);- return (- await prepareLocalExternalImport(file, options, dependencies)- ).import();+ return prepareLocalExternalImport(file, options, dependencies);}- expect((await importLine(3)).counts).toEqual({++ const prepared = await prepareLine(3);+ expect(prepared.preview.findings).toHaveLength(1);+ expect(prepared.preview.excluded).toEqual([]);+ expect(prepared.preview.source).toEqual({+ provider: "semgrep",+ source_key: options.sourceKey,+ });+ expect((await prepared.import()).counts).toEqual({created: 1,updated: 0,unchanged: 0,@@ -125,7 +117,23 @@ for (const suppliedFingerprint of [true, false]) {options,dependencies,);- expect((await importLine(9)).counts).toEqual(+ expect(original).toMatchObject({+ provider: "semgrep",+ sourceKey: options.sourceKey,+ sourceFindingId: prepared.preview.findings[0]!.source_finding_id,+ assessment: { state: "not_assessed" },+ version: 1,+ });+ expect(original!.evidence).toEqual(+ prepared.preview.findings[0]!.evidence,+ );+ expect(original!.evidence).not.toHaveProperty("confidence");+ expect(original!.evidence.locations).toEqual([+ { path: "src/example.ts", line: 3 },+ ]);++ const next = await prepareLine(9);+ expect((await next.import()).counts).toEqual(suppliedFingerprint? { created: 0, updated: 1, unchanged: 0 }: { created: 1, updated: 0, unchanged: 0 },@@ -160,7 +168,12 @@ for (const suppliedFingerprint of [true, false]) {expect(moved!.sourceFindingId).not.toBe(original!.sourceFindingId);expect(moved!.version).toBe(1);}- expect((await importLine(9)).counts).toEqual({+ const repeated = await prepareLocalExternalImport(+ file,+ options,+ dependencies,+ );+ expect((await repeated.import()).counts).toEqual({created: 0,updated: 0,unchanged: 1,@@ -168,6 +181,33 @@ for (const suppliedFingerprint of [true, false]) {expect(await listLocalExternalFindings(options, dependencies)).toEqual(records,);++ if (suppliedFingerprint) {+ const edited = await prepareLine(9, "Updated scanner evidence");+ expect((await edited.import()).counts).toEqual({+ created: 0,+ updated: 1,+ unchanged: 0,+ });+ const updated = await listLocalExternalFindings(+ options,+ dependencies,+ );+ expect(updated).toHaveLength(1);+ expect(updated[0]).toMatchObject({+ id: original!.id,+ sourceFindingId: original!.sourceFindingId,+ createdAt: original!.createdAt,+ assessment: { state: "not_assessed" },+ version: 3,+ });+ expect(updated[0]!.evidence).toEqual(+ edited.preview.findings[0]!.evidence,+ );+ expect(updated[0]!.evidence.description).toBe(+ "Updated scanner evidence",+ );+ }} finally {await fixture.dispose();}@@ -176,99 +216,15 @@ for (const suppliedFingerprint of [true, false]) {}test.each(formats)(- "Semgrep %s imports into SQLite and updates the same source finding",+ "Semgrep %s preserves sparse evidence without inventing a repository location or assessment",async (format) => {const fixture = await localFindingsFixture({ remote: repositoryUrl });try {const file = join(fixture.root, "semgrep.json");- const options = {- repository: fixture.repository,- provider: "semgrep" as const,- sourceKey: "example-project:main",- sourceRepositoryUrl: repositoryUrl,- };- const dependencies = { environment: fixture.environment };- await writeFile(file, JSON.stringify(report(format)));- const prepared = await prepareLocalExternalImport(- file,- options,- dependencies,- );- expect(prepared.preview.findings).toHaveLength(1);- expect(prepared.preview.excluded).toEqual([]);- expect(prepared.preview.source).toEqual({- provider: "semgrep",- source_key: options.sourceKey,- });- const imported = await prepared.import();- expect(imported.counts).toEqual({ created: 1, updated: 0, unchanged: 0 });-- const [stored] = await listLocalExternalFindings(options, dependencies);- expect(stored).toMatchObject({- provider: "semgrep",- sourceKey: options.sourceKey,- sourceFindingId: prepared.preview.findings[0]!.source_finding_id,- evidence: prepared.preview.findings[0]!.evidence,- assessment: { state: "not_assessed" },- version: 1,- });- expect(stored!.evidence.locations).toEqual([- { path: "src/example.ts", line: 3 },- ]);- expect(stored!.evidence).not.toHaveProperty("confidence");-- const repeated = await prepareLocalExternalImport(- file,- options,- dependencies,- );- expect((await repeated.import()).counts).toEqual({- created: 0,- updated: 0,- unchanged: 1,- });- expect(await listLocalExternalFindings(options, dependencies)).toEqual([- stored!,- ]);-await writeFile(file,- JSON.stringify(report(format, "Updated scanner evidence")),- );- const changed = await prepareLocalExternalImport(- file,- options,- dependencies,+ JSON.stringify(report(format, { message: "", sparse: true })),);- expect((await changed.import()).counts).toEqual({- created: 0,- updated: 1,- unchanged: 0,- });- const records = await listLocalExternalFindings(options, dependencies);- expect(records).toHaveLength(1);- expect(records[0]).toMatchObject({- id: stored!.id,- sourceFindingId: stored!.sourceFindingId,- evidence: changed.preview.findings[0]!.evidence,- assessment: { state: "not_assessed" },- version: 2,- createdAt: stored!.createdAt,- });- expect(records[0]!.evidence.description).toBe("Updated scanner evidence");- } finally {- await fixture.dispose();- }- },-);--test.each(formats)(- "Semgrep %s preserves sparse evidence without inventing a repository location or assessment",- async (format) => {- const fixture = await localFindingsFixture({ remote: repositoryUrl });- try {- const file = join(fixture.root, "semgrep.json");- await writeFile(file, JSON.stringify(report(format, "", true)));const options = {repository: fixture.repository,provider: "semgrep" as const,diff --git a/sdk/typescript/tests-ts/skeleton.test.ts b/sdk/typescript/tests-ts/skeleton.test.tsindex 87d18a631..cf4196716 100644--- a/sdk/typescript/tests-ts/skeleton.test.ts+++ b/sdk/typescript/tests-ts/skeleton.test.ts@@ -8,21 +8,9 @@ import {type AttackPathReachability,CodexSecurity,CodexSecurityError,- VERSION,} from "../src/index.js";-import { main } from "../src/cli.js";-import { capture } from "./cli-fixtures.js";import { bashCommand, runCommand } from "./support/shell.js";-const { selectChecks } = (await import(- new URL("../../../.github/scripts/select-ci-checks.mjs", import.meta.url).href-)) as {- selectChecks(- paths: string[],- options: { event: string; baseChanged?: boolean },- ): Record<"compatibility-matrix" | "python-matrix", string>;-};-interface WorkflowStep {name?: string;id?: string;@@ -102,7 +90,6 @@ describe("TypeScript package skeleton", () => {test("runs Bun once per OS and checks every supported Node runtime with the installed package", async () => {const { jobs } = await workflow("node-ci.yml");- const selected = selectChecks([], { event: "push" });expect(jobs["test"]?.strategy?.matrix).toEqual({os: ["ubuntu-latest", "macos-latest"],shard: [1, 2, 3, 4, 5, 6],@@ -110,15 +97,6 @@ describe("TypeScript package skeleton", () => {expect(jobs["compatibility"]?.strategy?.matrix).toBe("${{ fromJSON(needs.classify-changes.outputs.compatibility-matrix) }}",);- expect(JSON.parse(selected["compatibility-matrix"]).include).toEqual([- ...["22.13.0", "24.0.0", "24", "26.0.0", "26"].map((node) => ({- os: "ubuntu-latest",- node,- })),- { os: "macos-latest", node: "22.13.0" },- { os: "windows-latest", node: "22.13.0" },- { os: "windows-latest", node: "24" },- ]);expect(jobs["windows-test"]?.strategy?.matrix).toEqual({shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],});@@ -255,27 +233,9 @@ describe("TypeScript package skeleton", () => {test("covers the Python runtime floor and native platform paths", async () => {const { jobs } = await workflow("node-ci.yml");const job = jobs["plugin-source"]!;- const selected = selectChecks([], { event: "push" });expect(job.strategy?.matrix).toBe("${{ fromJSON(needs.classify-changes.outputs.python-matrix) }}",);- expect(JSON.parse(selected["python-matrix"]).include).toEqual([- ...["3.10", "3.12", "3.14"].map((python) => ({- os: "ubuntu-latest",- python,- markers: "",- })),- {- os: "macos-latest",- python: "3.12",- markers: "cross_platform or native_macos",- },- {- os: "windows-latest",- python: "3.12",- markers: "cross_platform or native_windows",- },- ]);const testStep = job.steps!.find(({ name }) => name === "Test Python source contracts",)!;@@ -625,27 +585,4 @@ describe("TypeScript package skeleton", () => {expect(new CodexSecurityError("failure").name).toBe("CodexSecurityError");await client.close();});-- test("provides executable help and version behavior", async () => {- const stdout = capture(null);- const stderr = capture(null);- expect(await main([], stdout.stream, stderr.stream)).toBe(0);- expect(stdout.text()).toContain("Usage: codex-security <command>");- expect(stdout.text()).toContain("Integrations:");- expect(stderr.text()).toBe("");-- const versionOutput = capture(null);- expect(await main(["--version"], versionOutput.stream, stderr.stream)).toBe(- 0,- );- expect(versionOutput.text()).toBe(`${VERSION}\n`);-- const scanHelpOutput = capture(null);- expect(- await main(["scan", "--help"], scanHelpOutput.stream, stderr.stream),- ).toBe(0);- expect(scanHelpOutput.text()).toContain(- "Usage: codex-security scan [repository]",- );- });});diff --git a/sdk/typescript/tests-ts/suggest-owners.test.ts b/sdk/typescript/tests-ts/suggest-owners.test.tsindex 601efb0d1..9f91d15d2 100644--- a/sdk/typescript/tests-ts/suggest-owners.test.ts+++ b/sdk/typescript/tests-ts/suggest-owners.test.ts@@ -1,7 +1,7 @@import { modelResponseText } from "./support/model-response-text.js";import { execFile as execFileCallback } from "node:child_process";import { cp, mkdir, readFile, rm, symlink, writeFile } from "node:fs/promises";-import { delimiter, dirname, join, relative } from "node:path";+import { delimiter, join, relative } from "node:path";import { promisify } from "node:util";import type { ThreadOptions, TurnOptions } from "@openai/codex-sdk";import { afterEach, expect, test } from "bun:test";@@ -721,7 +721,7 @@ test("prioritizes the first committed declared owner without a model call", asynawait mkdir(join(repo.path, "docs"));await writeFile(join(repo.path, ".github", "CODEOWNERS"),- "* @default\n/handler.ts @example/maintainers @reviewer [email protected]\n",+ "* @default\n/hand*.ts @example/maintainers @reviewer [email protected]\n",);await writeFile(join(repo.path, "CODEOWNERS"), "* @wrong-root\n");await writeFile(join(repo.path, "docs", "CODEOWNERS"), "* @wrong-docs\n");@@ -751,7 +751,7 @@ test("prioritizes the first committed declared owner without a model call", asyncommit: revision,startLine: 2,endLine: 2,- rule: "/handler.ts @example/maintainers @reviewer [email protected]",+ rule: "/hand*.ts @example/maintainers @reviewer [email protected]",matchedPath: "handler.ts",},],@@ -759,54 +759,6 @@ test("prioritizes the first committed declared owner without a model call", asynexpect(report.results[0]!.evidence).toHaveLength(1);});-test.each([- ["src/main.ts", "/src/ @alex_corp", "alex_corp", 2],- [- "src/main.ts",- "/src/ @example/maintainers @alex_corp",- "example/maintainers",- 2,- ],- ["lib/main.rb", "***/*.rb @ruby-team", "default", 1],- ["app/[id]/page.ts", "/app/\\[id\\]/page.ts @routes-team", "routes-team", 2],- ["services/api.ts", "/service* @service-team", "service-team", 2],- ["api1/main.ts", "/api? @api-team", "api-team", 2],- ["docs/start.md", "docs/* @docs-team", "docs-team", 2],- ["docs/nested/start.md", "docs/* @docs-team", "default", 1],- ["src/handler.ts", "/src/**/handler.ts @src-team", "src-team", 2],- ["src/deep/handler.ts", "/src/**/handler.ts @src-team", "src-team", 2],-] as const)(- "selects the committed owner for %s using %s",- async (path, rule, handle, line) => {- const repo = await repository();- await mkdir(join(repo.path, dirname(path)), { recursive: true });- await writeFile(join(repo.path, path), "// Ownership fixture\n");- await writeFile(join(repo.path, "CODEOWNERS"), `* @default\n${rule}\n`);- await repo.git("add", ".");- await repo.git("commit", "-qm", "Declare owners");- const { codex, calls } = fakeCodex();- const report = await suggestOwners(- repo.path,- [{ ...finding, locations: [{ path }] }],- { codex },- );- expect(report.results[0]).toMatchObject({- status: "identified",- owner: { handle },- evidence: [- {- kind: "codeowners",- startLine: line,- matchedPath: path,- commit: report.revision,- rule: line === 1 ? "* @default" : rule,- },- ],- });- expect(calls).toHaveLength(0);- },-);-test("loads CODEOWNERS once per invocation while matching each finding separately", async () => {const repo = await repository();await writeFile(join(repo.path, "other.ts"), "// Another owned file\n");