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
fix(cli): align scan schemas and structured output (#2580)
Michael D'Angeloead4c769a1b7
diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.mdindex eaa02717c..d71a9c527 100644--- a/sdk/typescript/docs/cli.md+++ b/sdk/typescript/docs/cli.md@@ -619,8 +619,13 @@ available) or `SCAN_RESUME_UNAVAILABLE` for `scans resume`. Rerunning an importescan uses `SCAN_IMPORT_FAILED` if the import fails. YAML and TOON failures remainon stderr without `--full-output`, or when retained results are unavailable.-Diagnostics stay on stderr. Each command's `--schema --format json` describes-its successful output and failure codes.+Scan argument errors with `--full-output` and JSON or JSONL use an `ok: false`+envelope with `error.code` and `error.message`. Command schema validation errors+with JSON or JSONL retain their field details and name missing or invalid+options by their CLI flags. Diagnostics stay on stderr.+`scan --schema --format json` describes optional caller inputs before defaults+and the fields returned by preflight, completed scans, and execution failures,+including sealed results recovered after an interruption.See [Exports and CI](#exports-and-ci) for exit codes and CI examples.### Follow-up finding validation@@ -2702,7 +2707,10 @@ SDK's local `validate()` and `patch()` methods use the same fallback.for `patch`. Omit it or use `--verification-mode standard` for the default checks.Results include evidence and `fixed`, `still_vulnerable`, or `inconclusive` status.-`--json` returns structured output. Exit codes are `0` when all findings are+Without output options, each finding prints a verdict and its evidence.+Explicit output formats, field selection and token controls operate on the+structured result containing `repository`, optional `scanId`, and `results`.+Exit codes are `0` when all findings arefixed, `1` when any remain vulnerable, and `2` for inconclusive/failed checks.With `--json` or `--format jsonl`, authentication and execution failures return`status: "failed"`, `code: "VERIFICATION_FAILED"`, and `message`. Withdiff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex c5ff49ed4..bd05fd1b1 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -118,7 +118,7 @@ import {formatDeepScanReviews,type DeepScanProgress,} from "./scan-progress.js";-import { isRecord as isJsonObject } from "./record.js";+import { asRecord, isRecord as isJsonObject } from "./record.js";import { suggestOwnersInternal } from "./suggest-owners.js";import { parseImportedFindings } from "./findings-import.js";import { publishScanToCustom } from "./custom-publish.js";@@ -163,6 +163,8 @@ import {verificationBatches,VerificationModeSchema,type FindingPatch,+ FindingPatchSchema,+ FindingVerificationSchema,type FindingVerification,} from "./remediation.js";import {@@ -545,7 +547,14 @@ const ASSESS_PATCH_RISK_OPTION = z.describe("Assess the completed patch and return the risk report.");function optionValue(flag: string) {- return z.string().min(1, `${flag} must not be empty.`);+ return z+ .string({+ error: (issue) =>+ issue.input === undefined+ ? `Missing required option ${flag}.`+ : undefined,+ })+ .min(1, `${flag} must not be empty.`);}function remediationInputOptions(verb: "Patch" | "Verify") {@@ -1242,15 +1251,88 @@ interface ScanOutcome {error?: string;}-function scanOutputSchema(...codes: [string, ...string[]]) {+const jsonDocument = z.record(z.string(), z.unknown());+const scanArtifactFields = {+ manifest: jsonDocument,+ findings: jsonDocument,+ review: jsonDocument,+ scanDir: z.string(),+ reportPath: z.string(),+};+const retainedScanOutput = z.object({+ ...scanArtifactFields,+ mode: z.string(),+});+const completedScanOutput = z.looseObject({+ ...scanArtifactFields,+ artifactsDir: z.string(),+ sarifPath: z.string().nullable(),+ threadId: z.string(),+ turn: jsonDocument,+ cost: jsonDocument.nullable(),+ threatModel: jsonDocument.nullable(),+ threatModelPath: z.string().nullable(),+ repositoryFindings: z.array(jsonDocument).optional(),+ ownerSuggestionsPath: z.string().optional(),+ ownerSuggestionsError: z.string().optional(),+ validation: jsonDocument.optional(),+ warnings: z.array(z.string()).optional(),+ patchSeverity: FailureSeveritySchema.optional(),+ patches: z.array(FindingPatchSchema).optional(),+ pullRequest: jsonDocument.optional(),+});++const scanPreflightOutput = z.looseObject({+ ...DeepScanSettingsSchema.shape,+ dryRun: z.literal(true),+ repository: z.string(),+ target: z.object({+ kind: z.enum(["repository", "paths", "refs", "working_tree"]),+ paths: z.array(z.string()),+ base: z.string().optional(),+ head: z.string().optional(),+ baseRef: z.string().optional(),+ headRef: z.string().optional(),+ }),+ mode: ScanSettingsSchema.shape.mode.unwrap(),+ model: z.string(),+ reasoningEffort: z.string(),+ modelProvider: z.string().optional(),+ outputDir: z.string().nullable(),+ stateDirectory: z.string().optional(),+ archiveDir: z.string().optional(),+ authentication: z.looseObject({+ method: z.string(),+ verified: z.literal(false),+ }),+ maxTimeMinutes: ScanSettingsSchema.shape.maxTimeMinutes,+ maxCostUsd: ScanSettingsSchema.shape.maxCostUsd,+ costLimitNote: z.string().optional(),+ knowledgeBasePaths: ScanSettingsSchema.shape.knowledgeBasePaths,+ scanPromptFile: ScanSettingsSchema.shape.scanPromptFile,+ validationPromptFile: ScanSettingsSchema.shape.validationPromptFile,+ failOnSeverity: FailureSeveritySchema.optional(),+ projectConfig: jsonDocument.optional(),+ deepScanSources: jsonDocument.optional(),+});++function cliFailureSchema(...codes: [string, ...string[]]) {+ return z.object({+ status: z.literal("failed"),+ code: z.literal(codes),+ message: z.string(),+ });+}++function scanOutputSchema(+ ...codes: [string, ...string[]]+): z.ZodType<Record<string, unknown> | undefined> {return z.union([- z.record(z.string(), z.unknown()),- z.object({- status: z.literal("failed"),- code: z.literal(codes),- message: z.string(),- }),+ completedScanOutput,+ retainedScanOutput,+ scanPreflightOutput,+ cliFailureSchema(...codes),]).optional();}@@ -2446,7 +2528,8 @@ export async function main(const message = errorMessage(outcome.error);if (!argv.includes("--full-output")) {const data = { status: "failed", code, message };- if (frameworkFlags.filterOutput) filteredScanFailure = { format, data };+ if (frameworkFlags.filters.length)+ filteredScanFailure = { format, data };return data;}// Incur would wrap returned data in an ok: true envelope.@@ -4262,7 +4345,7 @@ export async function main(if (machineFormat &&(!argv.includes("--full-output") || selection !== undefined) &&- frameworkFlags.filterOutput+ frameworkFlags.filters.length)filteredScanFailure = { format, data: failure };return structured ? failure : undefined;@@ -4426,7 +4509,7 @@ export async function main(environment: dependencies.environment,fetch: dependencies.hostedScannerFetch,};- function setHostedOutputFormat(format?: string) {+ function setTerminalOutputFormat(format?: string) {escapeFrameworkOutput =format === "md" || (format === "toon" && output.isTTY === true);}@@ -4542,7 +4625,7 @@ export async function main(}).optional(),run: ({ args, options, error, format }) => {- setHostedOutputFormat(format);+ setTerminalOutputFormat(format);return collectHostedFindings("Snyk", error, (signal) =>collectSnykIssues({@@ -4607,7 +4690,7 @@ export async function main(}).optional(),run: ({ args, options, error, format }) => {- setHostedOutputFormat(format);+ setTerminalOutputFormat(format);return collectHostedFindings("Semgrep", error, (signal) =>collectSemgrepPlatformFindings({@@ -6642,7 +6725,16 @@ export async function main(description: "Verify a fix described in a file.",},],- output: z.record(z.string(), z.unknown()).optional(),+ output: z+ .union([+ z.object({+ repository: z.string(),+ scanId: z.string().optional(),+ results: z.array(FindingVerificationSchema),+ }),+ cliFailureSchema("VERIFICATION_FAILED"),+ ])+ .optional() as z.ZodType<Record<string, unknown> | undefined>,async run({ format, options, error: incurError }) {let workerDiagnostic: string | undefined;const structured = format === "json" || format === "jsonl";@@ -6809,7 +6901,8 @@ export async function main(}}- if (structured) {+ if (!useDefaultOutput(format)) {+ setTerminalOutputFormat(format);return {repository,...(selected === undefined ? {} : { scanId: selected.scanId }),@@ -7516,18 +7609,10 @@ export async function main(function validateCliArguments(): string | undefined {if (argv.includes("--help") || argv.includes("-h")) return undefined;+ if (frameworkFlags.malformedFilter)+ return "--filter-output requires matching brackets for array slices.";if (command === undefined || !commands.has(command)) return undefined;- const structuredOutput = argv.some(- (value, index) =>- value === "--json" ||- ((value === "--format" ||- value === "--format=json" ||- value === "--format=jsonl") &&- (value.endsWith("=json") ||- value.endsWith("=jsonl") ||- argv[index + 1] === "json" ||- argv[index + 1] === "jsonl")),- );+ const structuredOutput = frameworkFlags.formats.some(isJsonFormat);if (structuredOutput &&["validate", "login", "logout"].includes(command) &&@@ -7561,21 +7646,10 @@ export async function main(}}if (command === "scan" && !argv.includes("--schema")) {- if (- argv.some(- (value) =>- value === "--filter-output" || value.startsWith("--filter-output="),- )- ) {+ if (frameworkFlags.filters.length) {return "--filter-output is not supported for scan results.";}- if (- argv.some(- (value, index) =>- value === "--format=md" ||- (value === "--format" && argv[index + 1] === "md"),- )- ) {+ if (frameworkFlags.formats.includes("md")) {return "Markdown output is not supported for scan results.";}}@@ -7587,33 +7661,22 @@ export async function main(command === "import";const subcommand = nestedCommand ? argv[commandIndex + 1] : undefined;if (- command === "import" &&- subcommand !== "sonar" &&- frameworkFlags.rawCollector+ frameworkFlags.rawStructuredOutput &&+ !(command === "scans" && subcommand === "logs")) {- // Incur's skill-sync notice turns a saved collector array into an object.+ // Saved logs include the framework's CTA after streamed events. Other+ // raw result objects and arrays keep notices in full-output metadata.cliOptions.sync = false;}if (command === "info") {- for (let index = 0; index < argv.length; index += 1) {- const argument = argv[index]!;- if (- argument !== "--filter-output" &&- !argument.startsWith("--filter-output=")- ) {- continue;- }- const selector = argument.includes("=")- ? argument.slice(argument.indexOf("=") + 1)- : argv[index + 1];- if (- selector !== undefined &&- !selector- .split(",")- .every((field) => Object.hasOwn(infoOutput.shape, field))- ) {+ for (const selector of frameworkFlags.filters) {+ if (selector === undefined) continue;+ const valid = selector.split(/,(?!\d+\])/u).every((field) => {+ const match = /^([\w-]+)(?:\.[\w-]+|\[\d+,\d+\])*$/u.exec(field);+ return match !== null && Object.hasOwn(infoOutput.shape, match[1]!);+ });+ if (!valid)return "--filter-output must select an info metadata field.";- }}}const entry = commands.get(command)!;@@ -7699,40 +7762,31 @@ export async function main(return `Unexpected positional argument for ${command}${subcommand === undefined ? "" : ` ${subcommand}`}.${hint}`;}}- const firstImportOption = scanImport ? commandIndex + 2 : argv.length;- const frameworkArgv: string[] = [];- for (let index = 0; index < argv.length; index++) {- const argument = argv[index]!;- const next = argv[index + 1];- const separator = argument.indexOf("=");- if (- index >= firstImportOption &&- argument === "--json" &&- next !== undefined &&- !next.startsWith("--") &&- next !== "-h"- ) {- // Incur reserves bare --json for output, but parses --json=FILE normally.- frameworkArgv.push(`--json=${next}`);- index++;- } else if (- separator >= 0 &&- FRAMEWORK_VALUE_OPTIONS.has(argument.slice(0, separator))- ) {- frameworkArgv.push(- argument.slice(0, separator),- argument.slice(separator + 1),- );- } else {- frameworkArgv.push(argument);- }- }- const frameworkFlags = frameworkOutputFlags(frameworkArgv);- const policyFullOutput =- command === "policy" && argv.includes("--full-output");+ const frameworkFlags = parseFrameworkArguments(+ argv,+ scanImport ? commandIndex + 2 : argv.length,+ );+ const frameworkArgv = frameworkFlags.args;+ const { jsonFormat } = frameworkFlags;+ const policyFullOutput = command === "policy" && frameworkFlags.fullOutput;+ const scanErrorFormat =+ command === "scan" && !scanImport && frameworkFlags.fullOutput+ ? jsonFormat+ : undefined;+ const argumentFailure = (message: string) =>+ Formatter.format(+ {+ ok: false,+ error: { code: "SCAN_FAILED", message },+ meta: { command: "scan" },+ },+ scanErrorFormat,+ ) + "\n";const argumentError = validateCliArguments();if (argumentError !== undefined && !policyFullOutput) {errorOutput.write(`codex-security: ${argumentError}\n`);+ if (scanErrorFormat)+ await writeCliOutput(output, argumentFailure(argumentError));return 2;}const updateController = new AbortController();@@ -7831,6 +7885,9 @@ export async function main(}let notice: UpdateNotice | undefined;+ if (argv.includes("--schema") || argv.includes("--llms-full")) {+ describeCommandInputs(commands);+ }try {await cli.serve(frameworkArgv, {stdout: frameworkCapture.stream.write,@@ -7885,10 +7942,61 @@ export async function main(if (exitCode === 0) exitCode = 2;} else {if (exitCode !== 0) return exitCode;- errorOutput.write(- `codex-security: ${diagnosticLines(await incurErrorMessage(frameworkOutput))}\n`,- );- return 2;+ const envelope = jsonFormat+ ? parseJson(() => frameworkOutput)+ : undefined;+ const record = asRecord(envelope);+ const error =+ record?.["ok"] === false ? asRecord(record["error"]) : record;+ const validationError = error?.["code"] === "VALIDATION_ERROR";+ const structuredFailure = Boolean(scanErrorFormat || validationError);+ let message =+ structuredFailure && typeof error?.["message"] === "string"+ ? error["message"]+ : await incurErrorMessage(frameworkOutput);+ if (validationError && Array.isArray(error["fieldErrors"])) {+ const entry = command ? commands.get(command) : undefined;+ const leaf =+ entry && "_group" in entry+ ? (entry.commands.get(following ?? "") ?? entry.root)+ : entry;+ const options =+ leaf && "options" in leaf ? leaf.options?.shape : undefined;+ const messages = error["fieldErrors"].map((field) => {+ if (!isJsonObject(field) || typeof field["path"] !== "string")+ return message;+ const detail =+ typeof field["message"] === "string" ? field["message"] : message;+ if (options && Object.hasOwn(options, field["path"])) {+ const flag = field["path"].replace(+ /[A-Z]/g,+ (letter) => `-${letter.toLowerCase()}`,+ );+ return field["missing"]+ ? `Missing required option --${flag}.`+ : `Invalid value for --${flag}: ${detail}`;+ }+ return detail;+ });+ message = messages.join("\n");+ error["message"] = message;+ frameworkOutput = Formatter.format(envelope, jsonFormat) + "\n";+ }+ errorOutput.write(`codex-security: ${diagnosticLines(message)}\n`);+ if (!structuredFailure) return 2;+ exitCode = 2;+ // Errors in built-in flags precede Incur's format selection. Its other+ // parse errors already carry the requested envelope or token view.+ if (+ scanErrorFormat &&+ record?.["ok"] !== false &&+ !(+ typeof envelope === "number" &&+ frameworkFlags.tokenArguments.includes("--token-count")+ )+ ) {+ frameworkOutput = argumentFailure(message);+ }}}if (rawExportOutput) return exitCode;@@ -8257,33 +8365,101 @@ async function prepareScanArgumentsFromRecipe(};}-function frameworkOutputFlags(argv: readonly string[]) {- let fullOutput = false;- let rawCollector = false;+/** Incur describes parsed Zod outputs by default. Callers supply the inputs,+ * which may omit fields populated by CLI defaults. Keep the runtime defaults. */+function describeCommandInputs(+ commands: NonNullable<ReturnType<typeof Cli.toCommands.get>>,+): void {+ for (const entry of commands.values()) {+ if ("_group" in entry) describeCommandInputs(entry.commands);+ const command = "_group" in entry ? entry.root : entry;+ if (command && "options" in command && command.options) {+ const input = z.toJSONSchema(command.options, { io: "input" });+ command.options = command.options.meta({+ required: input.required ?? [],+ });+ }+ }+}++function isJsonFormat(format: string | undefined): format is "json" | "jsonl" {+ return format === "json" || format === "jsonl";+}++function parseFrameworkArguments(+ argv: readonly string[],+ firstImportOption: number,+) {+ const args: string[] = [];+ const formats: string[] = [];+ const filters: (string | undefined)[] = [];const tokenArguments: string[] = [];- let filterOutput = false;+ let fullOutput = false;+ let malformedFilter = false;for (let index = 0; index < argv.length; index++) {- const value = argv[index]!;- if (value === "--full-output") fullOutput = true;- if (value === "--json") rawCollector = true;- if (value === "--token-count") tokenArguments.push(value);- if (FRAMEWORK_VALUE_OPTIONS.has(value)) {- const operand = argv[++index];- if (value === "--filter-output") filterOutput = true;+ const argument = argv[index]!;+ const next = argv[index + 1];+ if (+ index >= firstImportOption &&+ argument === "--json" &&+ next !== undefined &&+ !next.startsWith("--") &&+ next !== "-h"+ ) {+ // Incur accepts the import's JSON input in the equals form.+ args.push(`--json=${next}`);+ index++;+ continue;+ }+ const equals = argument.indexOf("=");+ const flag = equals < 0 ? argument : argument.slice(0, equals);+ if (!FRAMEWORK_VALUE_OPTIONS.has(flag)) {+ args.push(argument);+ if (argument === "--json") formats.push("json");+ if (argument === "--full-output") fullOutput = true;+ if (argument === "--token-count") tokenArguments.push(argument);+ continue;+ }+ // Leave a following flag available when the option is missing its operand.+ const operand =+ equals >= 0+ ? argument.slice(equals + 1)+ : next?.startsWith("--")+ ? undefined+ : next;+ if (equals < 0 && operand !== undefined) index++;+ if (flag === "--filter-output") {+ filters.push(operand);+ // Incur cannot advance past an unterminated array slice.if (- (value === "--token-limit" || value === "--token-offset") &&- operand !== undefined- )- tokenArguments.push(value, operand);- if (value === "--format")- rawCollector =- operand === "json" || operand === "jsonl" || operand === "yaml";+ operand !== undefined &&+ !/^(?:[^\[\]]|\[[^\[\]]*\])*$/u.test(operand)+ ) {+ malformedFilter = true;+ continue;+ }}+ args.push(flag);+ if (operand !== undefined) args.push(operand);+ if (flag === "--format" && operand) formats.push(operand);+ if (+ (flag === "--token-limit" || flag === "--token-offset") &&+ operand !== undefined+ )+ tokenArguments.push(flag, operand);}+ const format = formats.at(-1);+ const jsonFormat = isJsonFormat(format) ? format : undefined;return {- rawCollector: rawCollector && !fullOutput,- filterOutput,+ args,+ formats,+ jsonFormat,+ fullOutput,+ malformedFilter,+ filters,tokenArguments,+ rawStructuredOutput:+ !fullOutput && (jsonFormat !== undefined || format === "yaml"),};}diff --git a/sdk/typescript/tests-ts/cli-external-imports.test.ts b/sdk/typescript/tests-ts/cli-external-imports.test.tsindex 10744a0b0..3f77d8492 100644--- a/sdk/typescript/tests-ts/cli-external-imports.test.ts+++ b/sdk/typescript/tests-ts/cli-external-imports.test.ts@@ -65,6 +65,35 @@ test("Semgrep import advertises its saved report format and native finding JSON});});+test("publish validation names the missing CLI options and preserves machine error fields", async () => {+ const args = [+ "publish",+ "findings",+ "report.json",+ "--provider",+ "wiz",+ "--repository",+ ".",+ "--dry-run",+ ];+ for (const flags of [[], ["--json"], ["--format=jsonl", "--full-output"]]) {+ const cli = createCliTest(main);+ expect(await cli.runCli([...args, ...flags], dependencies())).toBe(2);+ expect(cli.stderr.text()).toContain(+ "Missing required option --source-key.",+ );+ if (flags.length === 0) continue;+ const parsed = JSON.parse(cli.stdout.text());+ const error = flags.includes("--full-output") ? parsed.error : parsed;+ expect(error.code).toBe("VALIDATION_ERROR");+ expect(error.message).toContain("Missing required option --to.");+ expect(error.message).toContain("Missing required option --source-key.");+ expect(+ error.fieldErrors.map((field: { path: string }) => field.path),+ ).toEqual(["to", "sourceKey"]);+ }+});+test("a closed diagnostic pipe preserves the Sonar error envelope", async () => {const stdout = capture();const stderr = new Writable({@@ -113,7 +142,8 @@ test("rejects unsupported Sonar full-output formats before collecting findings",expect(collectSonarIssues).not.toHaveBeenCalled();});-const installedSkills = "stale installed skills preserve collector output";+const installedSkills =+ "stale installed skills preserve raw result objects and arrays";test(installedSkills, async () => {if (runTestInSubprocess(import.meta.path, installedSkills)) return;const root = await temporaryDirectory("import-skills-");@@ -149,6 +179,13 @@ test(installedSkills, async () => {const yaml = createCliTest(main);expect(await yaml.runCli([...args, "--format=yaml"], deps)).toBe(0);expect(Bun.YAML.parse(yaml.stdout.text())).toEqual(advisories);+ const scan = createCliTest(main);+ expect(await scan.runCli(["scan", ".", "--dry-run", "--json"], deps)).toBe(+ 0,+ );+ const preflight = JSON.parse(scan.stdout.text());+ expect(preflight.dryRun).toBe(true);+ expect(preflight).not.toHaveProperty("cta");} finally {await removeTemporaryDirectory(root);}diff --git a/sdk/typescript/tests-ts/cli-publish.test.ts b/sdk/typescript/tests-ts/cli-publish.test.tsindex 1a986f4c9..9e227fb24 100644--- a/sdk/typescript/tests-ts/cli-publish.test.ts+++ b/sdk/typescript/tests-ts/cli-publish.test.ts@@ -574,10 +574,36 @@ describe("publish scan to custom", () => {},);+ test("identifies an invalid custom destination URL in JSON", async () => {+ const { stdout, stderr, runCli } = createCliTest(main);+ const deps = dependencies();+ deps.publishScanToCustom = async () => fail("must not publish");+ expect(+ await runCli(+ [+ "publish",+ "scan",+ "completed-scan",+ "--to",+ "custom",+ "--findings-url",+ "not-a-url",+ "--json",+ ],+ deps,+ ),+ ).toBe(2);+ expect(stderr.text()).toContain("--findings-url");+ expect(JSON.parse(stdout.text())).toMatchObject({+ code: "VALIDATION_ERROR",+ message: "Invalid value for --findings-url: Invalid URL",+ fieldErrors: [{ path: "findingsUrl" }],+ });+ });+test.each([[["--to", "custom"], "requires --findings-url"],[["--to", "custom", "--findings-url", "--dry-run"], "--findings-url"],- [["--to", "custom", "--findings-url", "not-a-url"], "URL"],[["--to",diff --git a/sdk/typescript/tests-ts/cli-scan-failures.test.ts b/sdk/typescript/tests-ts/cli-scan-failures.test.tsindex 3ad2e6522..e1b2ee654 100644--- a/sdk/typescript/tests-ts/cli-scan-failures.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-failures.test.ts@@ -1,4 +1,5 @@import { describe, expect, test } from "bun:test";+import Ajv2020 from "ajv/dist/2020.js";import { main } from "../src/cli.js";import { CodexSecurityError } from "../src/index.js";import {@@ -459,3 +460,74 @@ for (const command of ["rerun", "resume"]) {},);}++test("scan discovery accepts caller inputs and validates the reported result variants", async () => {+ const stdout = capture();+ const stderr = capture();+ expect(+ await main(+ ["scan", "--schema", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),+ ).toBe(0);+ const { options, output } = JSON.parse(stdout.text());+ const ajv = new Ajv2020({ strict: false });+ const inputs = ajv.compile(options);+ expect(inputs({ dryRun: true })).toBe(true);+ expect(inputs({ maxCost: "not a number" })).toBe(false);+ const data = ajv.compile(output);+ expect(data({ dryRun: true, ...fakePreflight() })).toBe(true);+ expect(data(JSON.parse(JSON.stringify(fakeResult(["high"]).toJSON())))).toBe(+ true,+ );+ expect(+ data({ status: "failed", code: "SCAN_FAILED", message: "Example" }),+ ).toBe(true);+ const retained = fakeResult(["medium"]);+ expect(+ data({+ mode: retained.mode,+ manifest: retained.manifest,+ findings: retained.findings,+ review: retained.review,+ scanDir: retained.scanDir,+ reportPath: retained.reportPath,+ }),+ ).toBe(true);+ expect(data({})).toBe(false);+ expect(data({ status: "failed", code: 0, message: 42 })).toBe(false);+});++test.each([+ { args: ["--max-cost"] },+ { args: ["--format"] },+ { args: ["--format", "--json"] },+ { args: ["--token-limit", "--json"] },+ { args: ["--max-cost", "invalid"] },+ { args: ["--path", "src", "--diff", "HEAD"] },+ { args: ["--token-limit", "invalid"] },+])(+ "returns a JSON error envelope for invalid scan arguments %j",+ async ({ args }) => {+ for (const flags of [["--format=jsonl"], ["--json"]]) {+ const stdout = capture();+ const stderr = capture();+ expect(+ await main(+ ["scan", ".", "--dry-run", "--full-output", ...flags, ...args],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),+ ).toBe(2);+ const result = JSON.parse(stdout.text());+ expect(stderr.text()).toContain(result.error.message.split("\n")[0]);+ expect(result).toMatchObject({+ ok: false,+ error: { code: expect.any(String), message: expect.any(String) },+ });+ }+ },+);diff --git a/sdk/typescript/tests-ts/cli-verify-fix.test.ts b/sdk/typescript/tests-ts/cli-verify-fix.test.tsindex d662460e8..714121350 100644--- a/sdk/typescript/tests-ts/cli-verify-fix.test.ts+++ b/sdk/typescript/tests-ts/cli-verify-fix.test.ts@@ -736,6 +736,59 @@ describe("read-only finding verification", () => {expect(await batches()).toEqual([[findings[0]!], [findings[1]!]]);});+ test("rejects an unfinished output slice before starting a verification", async () => {+ const cli = createCliTest(main);+ const deps = dependencies({+ onCodex: () => {+ throw new Error("Unexpected verification");+ },+ });+ expect(+ await cli.runCli(+ ["verify-fix", "Example", "--filter-output=results[0"],+ deps,+ ),+ ).toBe(2);+ expect(cli.stderr.text()).toContain(+ "--filter-output requires matching brackets",+ );+ });++ test("formats a verification result before applying output controls", async () => {+ const result = {+ id: "finding-1",+ status: "fixed",+ evidence: "Synthetic evidence.",+ };+ const deps = dependencies({+ onCodex: (_args, output) => {+ output?.stdout.write(JSON.stringify({ results: [result] }));+ return 0;+ },+ });+ const yaml = captureCli(main, "stdout");+ expect(+ await yaml.run(+ [+ "verify-fix",+ "Example",+ "--format=yaml",+ "--filter-output",+ "results",+ ],+ deps,+ ),+ ).toBe(0);+ const { parse } = await import("yaml");+ expect(parse(yaml.text())).toEqual({ results: [result] });++ const tokens = captureCli(main, "stdout");+ expect(+ await tokens.run(["verify-fix", "Example", "--token-count"], deps),+ ).toBe(0);+ expect(tokens.text().trim()).toMatch(/^[1-9][0-9]*$/u);+ });+test("reports inconclusive findings without treating them as fixed", async () => {const stdout = captureCli(main, "stdout");expect(diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.tsindex e2b2dbb72..8af1f4d8c 100644--- a/sdk/typescript/tests-ts/cli.test.ts+++ b/sdk/typescript/tests-ts/cli.test.ts@@ -2291,6 +2291,25 @@ describe("CLI", () => {expect(stderr.text()).toBe("");});+ test("projects nested info settings and other top-level metadata", async () => {+ const { stdout, runCli } = createCliTest(main);+ expect(+ await runCli(+ [+ "info",+ "--json",+ "--filter-output",+ "model,configuration.settings.mode",+ ],+ dependencies(),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual({+ model: DEFAULT_SCAN_MODEL_CONFIGURATION.model,+ configuration: { settings: { mode: "standard" } },+ });+ });+test("rejects scan-only filters before running the info command", async () => {const { stdout, stderr, runCli } = createCliTest(main);