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(dashboard): show saved review progress in the component table (#2111)

wj0b93b9dfa055
diff --git a/sdk/typescript/src/scan-dashboard.ts b/sdk/typescript/src/scan-dashboard.ts
index 72b429925..f49363cf5 100644
--- a/sdk/typescript/src/scan-dashboard.ts
+++ b/sdk/typescript/src/scan-dashboard.ts
@@ -922,16 +922,45 @@ export class ScanDashboard {
this.#components.length - rows,
),
);
+ const visible = this.#components
+ .slice(first, first + rows)
+ .map(({ receipt, dashboard }) => {
+ const count =
+ dashboard.#files === null
+ ? null
+ : scanProgressCount(dashboard.#files);
+ const progress =
+ count === null
+ ? "—"
+ : `${formatCount(count.completed)}/${formatCount(count.total)} ${count.label}`;
+ const status =
+ receipt.status === "started"
+ ? dashboard.#stage
+ : componentStatus(receipt);
+ return { receipt, dashboard, status, progress };
+ });
+ const progressWidth = Math.max(
+ "Progress".length,
+ ...visible.map(({ progress }) => progress.length),
+ );
const costWidth = Math.max(
8,
...this.#components.map(({ dashboard }) =>
dashboard.#cost === null ? 1 : formatScanCost(dashboard.#cost).length,
),
);
- const nameWidth = Math.max(
- 10,
- width - 52 - (this.#showCost ? costWidth + 1 : 0),
+ const nameAndStatusWidth =
+ width - 17 - progressWidth - (this.#showCost ? costWidth + 1 : 0);
+ // When space is tight, share the original 35 status and progress columns
+ // so adding the unit doesn't push the cost amount offscreen.
+ const statusWidth = Math.min(
+ Math.max(
+ "Status".length,
+ ...visible.map(({ status }) => stringWidth(status)),
+ ),
+ Math.max("Status".length, 35 - progressWidth, nameAndStatusWidth - 10),
);
+ const nameWidth = Math.max(10, nameAndStatusWidth - statusWidth);
const cell = (value: string, width: number): string => {
const text = fitLine(value, width);
return text + " ".repeat(width - stringWidth(text));
@@ -940,30 +969,24 @@ export class ScanDashboard {
marker: string,
name: string,
status: string,
- files: string,
+ progress: string,
findings: string,
cost: string,
): string =>
- ` ${marker} ${cell(name, nameWidth)} ${cell(status, 24)} ${files.padStart(11)} ${findings.padStart(8)}${this.#showCost ? ` ${cost.padStart(8)}` : ""}`;
- const table = this.#components
- .slice(first, first + rows)
- .map(({ receipt, dashboard }, index) => {
- const files = dashboard.#files;
- return row(
+ ` ${marker} ${cell(name, nameWidth)} ${cell(status, statusWidth)} ${progress.padStart(progressWidth)} ${findings.padStart(8)}${this.#showCost ? ` ${cost.padStart(8)}` : ""}`;
+ const table = visible.map(
+ ({ receipt, dashboard, status, progress }, index) =>
+ row(
first + index === this.#selectedComponent ? "›" : " ",
receipt.name,
- receipt.status === "started"
- ? dashboard.#stage
- : componentStatus(receipt),
- files === null
- ? "—"
- : `${formatCount(files.filesCompleted)}/${formatCount(files.filesTotal)}`,
+ status,
+ progress,
receipt.findingCount === undefined
? "—"
: formatCount(receipt.findingCount),
dashboard.#cost === null ? "—" : formatScanCost(dashboard.#cost),
- );
- });
+ ),
+ );
if (table.length === 0) table.push(` ${this.#stage}…`);
while (table.length < rows) table.push("");
const count = (status: ComponentReceipt["status"]) =>
@@ -984,7 +1007,7 @@ export class ScanDashboard {
divider,
` ${count("completed")} complete · ${count("started")} running · ${count("pending")} queued · ${count("failed")} failed`,
"",
- row(" ", "Component", "Status", "Files", "Findings", "Cost"),
+ row(" ", "Component", "Status", "Progress", "Findings", "Cost"),
...table,
divider,
` SCOPE ${selected?.paths.join(", ") ?? "waiting for component plan"}`,
diff --git a/sdk/typescript/tests-ts/scan-dashboard.test.ts b/sdk/typescript/tests-ts/scan-dashboard.test.ts
index 750441dfe..4966fdd77 100644
--- a/sdk/typescript/tests-ts/scan-dashboard.test.ts
+++ b/sdk/typescript/tests-ts/scan-dashboard.test.ts
@@ -2735,52 +2735,80 @@ function failingDashboardOutput(output: string[]) {
};
}
-test("aligns component columns by terminal width and retains trailing cost", async () => {
- const stderr = capture(true);
- const dashboard = createDashboard(
- { ...stderr.stream, columns: 160, rows: 24 },
- { presentation: "components", showCost: true },
- );
- const receipts: ComponentReceipt[] = [
- "a".repeat(74),
- "界".repeat(37),
- "e\u0301".repeat(37),
- ].map((name, index) => ({
- id: String(index),
- name,
- paths: ["src"],
- status: "pending",
- outputDir: `/synthetic/results/${index}`,
- }));
- dashboard.start();
- dashboard.setComponents(receipts);
- for (const receipt of receipts)
- dashboard.recordComponentEvent({
- componentId: receipt.id,
- type: "cost",
- value: {
- model: "synthetic-model",
- inputTokens: 1,
- cachedInputTokens: 0,
- cacheWriteInputTokens: 0,
- outputTokens: 1,
- estimatedUsd: 1,
- estimatedUsdRange: { min: 1, max: 1, context: "unknown" },
- },
- });
- await Promise.resolve();
- const frame = stripVTControlCharacters(
- stderr.text().split("\u001B[H").at(-1)!,
- );
- const rows = frame.split("\n").filter((line) => line.includes("Queued"));
- expect(rows).toHaveLength(3);
- for (const row of rows) expect(row).toContain("$1.00");
- expect(
- new Set(rows.map((row) => stringWidth(row.slice(0, row.indexOf("$1.00")))))
- .size,
- ).toBe(1);
- dashboard.stop();
-});
+test.each([80, 160])(
+ "fits component progress at %i columns",
+ async (columns) => {
+ const stderr = capture(true);
+ const dashboard = createDashboard(
+ { ...stderr.stream, columns, rows: 24 },
+ { presentation: "components", showCost: true },
+ );
+ const receipts: ComponentReceipt[] = [
+ "a".repeat(74),
+ "界".repeat(37),
+ "e\u0301".repeat(37),
+ ].map((name, index) => ({
+ id: String(index),
+ name,
+ paths: ["src"],
+ status: "pending",
+ outputDir: `/synthetic/results/${index}`,
+ }));
+ dashboard.start();
+ dashboard.setComponents(receipts);
+ for (const [index, receipt] of receipts.entries()) {
+ if (index < 2) {
+ dashboard.updateComponent({ ...receipt, status: "started" });
+ dashboard.recordComponentEvent({
+ componentId: receipt.id,
+ type: "progress",
+ value: {
+ phase: "attack_path",
+ filesCompleted: 2,
+ filesTotal: 8,
+ ...(index === 1 && {
+ reviewItems: { completed: 1_234, total: 12_345 },
+ }),
+ },
+ });
+ }
+ dashboard.recordComponentEvent({
+ componentId: receipt.id,
+ type: "cost",
+ value: {
+ model: "synthetic-model",
+ inputTokens: 1,
+ cachedInputTokens: 0,
+ cacheWriteInputTokens: 0,
+ outputTokens: 1,
+ estimatedUsd: 1,
+ estimatedUsdRange: { min: 1, max: 12.34, context: "unknown" },
+ },
+ });
+ }
+ await Promise.resolve();
+ const frame = stripVTControlCharacters(
+ stderr.text().split("\u001B[H").at(-1)!,
+ );
+ const lines = frame.split("\n");
+ const header = lines.findIndex((line) =>
+ /Status\s+Progress\s+Findings\s+Cost/u.test(line),
+ );
+ expect(header).toBeGreaterThanOrEqual(0);
+ const rows = lines.slice(header + 1, header + 4);
+ expect(rows).toHaveLength(3);
+ expect(rows[0]).toContain("2/8 files");
+ expect(rows[1]).toContain("1,234/12,345 reviews");
+ expect(rows[2]).toMatch(/Queued\s+—\s+—\s+\$1\.00/u);
+ for (const row of rows) expect(row).toContain("$1.00–$12.34");
+ expect(
+ new Set(
+ rows.map((row) => stringWidth(row.slice(0, row.indexOf("$1.00")))),
+ ).size,
+ ).toBe(1);
+ dashboard.stop();
+ },
+);
test.each([16, 25, 120])(
"preserves markup after clipped prefixes at width %i",