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(cli): distinguish file inventory from review progress (#1960)

Michael D'Angelo76a58ac7d937
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 6059f4438..5ac6869d9 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -9426,11 +9426,7 @@ async function executeScan(
`Reviews: ${deepProgress.completed} completed, ${deepProgress.active} active, cap ${deepProgress.maximum}`,
);
} else if (fileProgress !== null) {
- const count = scanProgressCount(fileProgress);
- if (count.total > 0)
- details.push(
- `${count.label === "reviews" ? "Reviews" : "Files"}: ${count.completed.toLocaleString("en-US")}/${count.total.toLocaleString("en-US")}`,
- );
+ details.push(formatScanProgressCount(fileProgress, "status"));
}
const tokens =
runningCost !== null
@@ -9701,10 +9697,8 @@ async function executeScan(
}
if (progress === null) return;
progress.stopTimer();
- const count = scanProgressCount(update);
- progress.stage(
- `Scan phase: ${phase}${count.total === 0 ? "" : ` (${count.completed.toLocaleString("en-US")}/${count.total.toLocaleString("en-US")} ${count.label})`}.`,
- );
+ const count = formatScanProgressCount(update, "phase");
+ progress.stage(`Scan phase: ${phase} (${count}).`);
progress.startTimer(runningMessage());
},
onDeepProgress: (update) => {
@@ -10703,6 +10697,23 @@ function printScanSummary(
}
}
+function formatScanProgressCount(
+ progress: ScanProgress,
+ style: "phase" | "status",
+): string {
+ const { label, completed, total } = scanProgressCount(progress);
+ const totalText = total.toLocaleString("en-US");
+ if (label === "files" && completed === 0) {
+ return style === "phase"
+ ? `${totalText} ${total === 1 ? "file" : "files"} inventoried`
+ : `File inventory: ${totalText}`;
+ }
+ const ratio = `${completed.toLocaleString("en-US")}/${totalText}`;
+ return style === "phase"
+ ? `${ratio} ${label}`
+ : `${label === "reviews" ? "Reviews" : "Files"}: ${ratio}`;
+}
+
function componentScanEventLine(
componentName: string,
event: ComponentScanEvent,
@@ -10716,8 +10727,8 @@ function componentScanEventLine(
}
if (event.type === "progress") {
const progress = event.value;
- const count = scanProgressCount(progress);
- return `codex-security: ${componentName} ${scanPhase(progress.phase)} | ${count.label === "reviews" ? "Reviews" : "Files"}: ${count.completed.toLocaleString("en-US")}/${count.total.toLocaleString("en-US")}\n`;
+ const count = formatScanProgressCount(progress, "status");
+ return `codex-security: ${componentName} ${scanPhase(progress.phase)} | ${count}\n`;
}
if (event.type === "usage") {
const tokens = formatTokenUsage(event.value);
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index 825c8cf82..9acd9fbee 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -2511,6 +2511,7 @@ describe("CLI", () => {
expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());
expect(stderr.text()).toContain("Preparing scan");
expect(stderr.text()).toContain("Running scan");
+ expect(stderr.text()).not.toContain("File inventory:");
expect(stderr.text()).not.toContain("\u001B");
expect(stderr.text()).not.toContain("\r");
expect(setIntervalMock).toHaveBeenCalledTimes(0);
@@ -2561,7 +2562,7 @@ describe("CLI", () => {
phase: "validation",
filesCompleted: 0,
filesTotal: 8,
- reviewItems: { completed: 11, total: 13 },
+ reviewItems: { completed: 0, total: 13 },
},
{
phase: "validation",
@@ -2572,15 +2573,20 @@ describe("CLI", () => {
],
});
deps.setInterval = mock(fakeInterval);
- expect(await runCli(["scan", ".", "--headless"], deps)).toBe(0);
+ expect(
+ await runCli(["scan", ".", "--headless", "--diff", "HEAD^"], deps),
+ ).toBe(0);
+ expect(stderr.text()).toContain(
+ "Running scan: preflight (committed changes) | File inventory: 8",
+ );
expect(stderr.text()).toContain(
- "Scan phase: validating findings (11/13 reviews).",
+ "Scan phase: validating findings (0/13 reviews).",
);
expect(stderr.text()).toContain(
"Scan phase: validating findings (13/13 reviews).",
);
expect(stderr.text()).toContain(
- "Running scan: validating findings | Reviews: 13/13",
+ "Running scan: validating findings (committed changes) | Reviews: 13/13",
);
expect(stderr.text()).not.toContain("Files: 13/13");
});
@@ -5227,7 +5233,12 @@ describe("CLI", () => {
expect(stderr.text()).toContain(
"Tokens: unavailable uncached input, 200 cache reads, unavailable cache writes, 30 output, 1,280 total. Estimated cost: $0.00488–$0.01156 (standard, context unknown, cache writes unknown).",
);
- expect(stderr.text()).toContain("Scan phase: reviewing files (0/8 files).");
+ expect(stderr.text()).toContain(
+ "Scan phase: reviewing files (8 files inventoried).",
+ );
+ expect(stderr.text()).toContain(
+ "Running scan: reviewing files | File inventory: 8",
+ );
expect(stderr.text()).toContain("Scan phase: reviewing files (3/8 files).");
expect(stderr.text()).toContain(
"Running scan: reviewing files | Workers: 4/6 | Files: 3/8 | Tokens: unavailable uncached input, 200 cache reads, unavailable cache writes, 30 output, 1,280 total | Cost: $0.00488–$0.01156",
diff --git a/sdk/typescript/tests-ts/component-scan.test.ts b/sdk/typescript/tests-ts/component-scan.test.ts
index ae44f296b..1dda7a3ac 100644
--- a/sdk/typescript/tests-ts/component-scan.test.ts
+++ b/sdk/typescript/tests-ts/component-scan.test.ts
@@ -619,6 +619,13 @@ test.each([
.text()
.includes("apps/api | ChatGPT allowance not reported"),
).toBe(presentation === "headless");
+ for (const filesTotal of [0, 2]) {
+ options.onProgress?.({
+ phase: "preflight",
+ filesCompleted: 0,
+ filesTotal,
+ });
+ }
options.onProgress?.({
phase: "validation",
filesCompleted: 2,
@@ -667,6 +674,8 @@ test.each([
);
} else expect(stderr.text()).toContain("apps/api completed");
if (presentation !== "dashboard") {
+ expect(stderr.text()).toContain("apps/api preflight | File inventory: 0");
+ expect(stderr.text()).toContain("apps/api preflight | File inventory: 2");
expect(stderr.text()).toContain(
"apps/api validating findings | Files: 2/2",
);