Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix: keep completed security scan output concise (#81)

ianw-oai603b080fd56a
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 75b25b4c2..aa77aa3ac 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -1027,6 +1027,13 @@ export async function main(
exitCode,
});
}
+ if (
+ !options.dryRun &&
+ format === "toon" &&
+ !argv.some((argument) => SCAN_HISTORY_OUTPUT_OPTION.test(argument))
+ ) {
+ return;
+ }
return outcome.data;
},
})
@@ -1503,14 +1510,21 @@ export async function main(
},
});
- await cli.serve([...argv], {
- stdout: (value) => {
- frameworkOutput += value;
- },
- exit: (code) => {
- frameworkExit = code;
+ await cli.serve(
+ argv.flatMap((argument) =>
+ argument.startsWith("--format=")
+ ? ["--format", argument.slice("--format=".length)]
+ : [argument],
+ ),
+ {
+ stdout: (value) => {
+ frameworkOutput += value;
+ },
+ exit: (code) => {
+ frameworkExit = code;
+ },
},
- });
+ );
if (pendingUpdate !== undefined) {
const notice = await pendingUpdate;
if (notice !== undefined) errorOutput.write(formatUpdateNotice(notice));
@@ -2258,7 +2272,6 @@ async function runScan(
let firstSignalAt = 0;
let progress: Progress | null = null;
let lastWorkerUpdate = "";
- let workerCapacity: { planned: number; started: number } | null = null;
let phase: string | null = null;
const preparationAbortController = new AbortController();
const signalListener = (signal: SignalName) => () => {
@@ -2443,10 +2456,7 @@ async function runScan(
: `dispatch:${status.phase}:${status.planned}:${status.started}`;
if (update === lastWorkerUpdate) return;
lastWorkerUpdate = update;
- if (status.kind === "dispatch") {
- workerCapacity = { planned: status.planned, started: status.started };
- phase = scanPhase(status.phase);
- }
+ if (status.kind === "dispatch") phase = scanPhase(status.phase);
const message = workerStatusMessage(status);
if (message === null || progress === null) return;
progress.stopTimer();
@@ -2536,7 +2546,7 @@ async function runScan(
).length;
const incomplete = result.coverage.completeness !== "complete";
progress?.stage("Scan complete");
- printScanSummary(result, progress, errorOutput, workerCapacity);
+ printScanSummary(result, progress, errorOutput);
if (incomplete) {
errorOutput.write(
threshold === undefined
@@ -2607,7 +2617,6 @@ function printScanSummary(
result: ScanResult,
progress: Progress | null,
errorOutput: Writable,
- workers: { planned: number; started: number } | null,
): void {
const severities = new Map<SeverityLevel, number>();
for (const finding of result.findings.findings) {
@@ -2634,9 +2643,7 @@ function printScanSummary(
completed >= started
? Math.floor((completed - started) / 1_000)
: progress?.elapsedSeconds ?? 0;
- errorOutput.write(
- `codex-security: Elapsed: ${elapsed}s.${workers === null ? "" : ` Workers: ${workers.started}/${workers.planned}.`}\n`,
- );
+ errorOutput.write(`codex-security: Elapsed: ${elapsed}s.\n`);
const tokenSummary = formatTokenUsage(result.turnResult.usage);
if (tokenSummary !== null) {
@@ -2647,12 +2654,11 @@ function printScanSummary(
`codex-security: Estimated cost: ${formatUsd(result.cost.estimatedUsd)} USD.\n`,
);
}
- const scanDir = cliErrorMessage(result.scanDir);
- errorOutput.write(`codex-security: Results: ${scanDir}\n`);
errorOutput.write(
- result.sarifPath === null
- ? `codex-security: Next: codex-security export ${quoteCliPath(scanDir)} --export-format sarif\n`
- : `codex-security: Next: review ${cliErrorMessage(result.reportPath)}\n`,
+ `codex-security: Report: ${cliErrorMessage(result.reportPath)}\n`,
+ );
+ errorOutput.write(
+ `codex-security: Results: ${cliErrorMessage(result.scanDir)}\n`,
);
}
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index 88f6f5f29..1baf3f9db 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -1877,14 +1877,87 @@ describe("CLI", () => {
expect(stderr.text()).not.toContain("SYNTHETIC_DATABASE_SECRET");
});
- test("renders scan output with the Incur default format", async () => {
+ test("prints only the completion summary for default scans", async () => {
const stdout = capture();
const stderr = capture();
+ const result = fakeResult(["high"], "complete", {
+ input_tokens: 1_250,
+ cached_input_tokens: 200,
+ output_tokens: 30,
+ });
+
expect(
- await main(["scan"], stdout.stream, stderr.stream, dependencies()),
+ await main(
+ ["scan"],
+ stdout.stream,
+ stderr.stream,
+ dependencies({ result }),
+ ),
).toBe(0);
- expect(stdout.text()).toContain("scanDir: /tmp/scan");
- expect(stdout.text()).toContain("completeness: complete");
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toContain("Scan complete");
+ expect(stderr.text()).toContain(
+ "Findings: 1 (1 high). Coverage: complete.",
+ );
+ expect(stderr.text()).toContain("Elapsed: 1s.");
+ expect(stderr.text()).toContain(
+ "Tokens: 1,250 input, 200 cached, 30 output.",
+ );
+ expect(stderr.text()).toContain("Estimated cost: $0.00625 USD.");
+ expect(stderr.text()).toContain(`Report: ${result.reportPath}`);
+ expect(stderr.text()).toContain("Results: /tmp/scan");
+ expect(stderr.text()).not.toContain("Next:");
+ });
+
+ test("prints complete scan results only when explicitly requested", async () => {
+ for (const [arguments_, marker] of [
+ [["--json"], '"manifest"'],
+ [["--format", "json"], '"manifest"'],
+ [["--format=json"], '"manifest"'],
+ [["--format", "jsonl"], '"manifest"'],
+ [["--format=jsonl"], '"manifest"'],
+ [["--format", "toon"], "manifest:"],
+ [["--format=toon"], "manifest:"],
+ [["--format", "yaml"], "manifest:"],
+ [["--format=yaml"], "manifest:"],
+ [["--full-output"], "manifest:"],
+ ] as const) {
+ const stdout = capture();
+ expect(
+ await main(
+ ["scan", ...arguments_],
+ stdout.stream,
+ capture().stream,
+ dependencies(),
+ ),
+ ).toBe(0);
+ expect(stdout.text()).toContain(marker);
+ }
+ });
+
+ test("honors explicit scan token output operations", async () => {
+ for (const arguments_ of [
+ ["--token-count"],
+ ["--token-limit", "4"],
+ ["--token-offset", "1"],
+ ["--token-offset", "1", "--token-limit", "4"],
+ ] as const) {
+ const stdout = capture();
+ expect(
+ await main(
+ ["scan", ...arguments_],
+ stdout.stream,
+ capture().stream,
+ dependencies(),
+ ),
+ ).toBe(0);
+ if (arguments_[0] === "--token-count") {
+ expect(stdout.text().trim()).toMatch(/^\d+$/u);
+ expect(Number(stdout.text().trim())).toBeGreaterThan(0);
+ } else {
+ expect(stdout.text()).toContain("[truncated: showing tokens ");
+ }
+ }
});
test("prints scan completion warnings without failing the scan", async () => {
@@ -2057,15 +2130,14 @@ describe("CLI", () => {
expect(stderr.text()).toContain(
"Findings: 4 (1 critical, 2 high, 1 informational). Coverage: complete.",
);
- expect(stderr.text()).toContain("Elapsed: 1s. Workers: 3/6.");
+ expect(stderr.text()).toContain("Elapsed: 1s.");
expect(stderr.text()).toContain(
"Tokens: 1,250 input, 200 cached, 30 output.",
);
expect(stderr.text()).toContain("Estimated cost: $0.00625 USD.");
+ expect(stderr.text()).toContain(`Report: ${result.reportPath}`);
expect(stderr.text()).toContain("Results: /tmp/scan");
- expect(stderr.text()).toContain(
- "Next: codex-security export /tmp/scan --export-format sarif",
- );
+ expect(stderr.text()).not.toContain("Next:");
});
test("reports the running cost against the scan budget", async () => {
@@ -2194,7 +2266,8 @@ describe("CLI", () => {
expect(stderr.text()).toContain(
"Worker delegation unavailable during file review; continuing without delegated workers.",
);
- expect(stdout.text()).toContain("completeness: complete");
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toContain("Findings: 0. Coverage: complete.");
});
test("validates a dry run without starting a scan", async () => {