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(findings): align severity badges in finding tables (#122)

Michael75d4784af121
diff --git a/sdk/typescript/src/scan-history-renderer.ts b/sdk/typescript/src/scan-history-renderer.ts
index d71f8af3a..e76cacb5c 100644
--- a/sdk/typescript/src/scan-history-renderer.ts
+++ b/sdk/typescript/src/scan-history-renderer.ts
@@ -124,7 +124,8 @@ export function renderScanHistory(
const finding = (entry: JsonObject, includeReason = true): void => {
const severity = findingSeverity(entry);
const title = clean(entry["title"]);
- const badge = paint(severity.padEnd(8), SEVERITY_COLORS[severity] ?? 37);
+ const label = severity === "INFORMATIONAL" ? "INFO" : severity;
+ const badge = paint(label.padEnd(8), SEVERITY_COLORS[severity] ?? 37);
wrap(title, 14, ` ${badge} `);
const before = entry["beforeOccurrenceIds"] as string[] | undefined;
const after = entry["afterOccurrenceIds"] as string[] | undefined;
diff --git a/sdk/typescript/tests-ts/scan-history-renderer.test.ts b/sdk/typescript/tests-ts/scan-history-renderer.test.ts
index 30548dd84..3ef71e9a4 100644
--- a/sdk/typescript/tests-ts/scan-history-renderer.test.ts
+++ b/sdk/typescript/tests-ts/scan-history-renderer.test.ts
@@ -148,25 +148,42 @@ describe("scan history renderer", () => {
] as const)(
"wraps %s titles at terminal columns",
(_name, title, expected) => {
+ const badges = [
+ ["critical", "CRITICAL", 31],
+ ["high", "HIGH", 31],
+ ["medium", "MEDIUM", 33],
+ ["low", "LOW", 36],
+ ["informational", "INFO", 37],
+ ] as const;
for (const color of [false, true]) {
const output = renderScanHistory(
{
repository: "/repo",
- findings: [{ title, severity: "high", path: "source.ts" }],
+ findings: badges.map(([severity]) => ({
+ title,
+ severity,
+ path: `${severity}.ts`,
+ })),
},
"findings",
{ columns: 48, color },
);
const lines = stripVTControlCharacters(output).split("\n");
- const start = lines.findIndex((line) => line.startsWith(" HIGH"));
- const end = lines.indexOf(" source.ts");
- expect(lines.slice(start, end)).toEqual(
- expected.map(
- (line, index) =>
- `${index === 0 ? " HIGH " : " "}${line}`,
- ),
- );
- if (color) expect(output).toContain("\u001B[31mHIGH \u001B[0m");
+ for (const [severity, label, ansiColor] of badges) {
+ const badge = label.padEnd(8);
+ const start = lines.findIndex((line) =>
+ line.startsWith(` ${badge} `),
+ );
+ expect(lines.slice(start, start + expected.length + 1)).toEqual([
+ ...expected.map(
+ (line, index) =>
+ `${index === 0 ? ` ${badge} ` : " "}${line}`,
+ ),
+ ` ${severity}.ts`,
+ ]);
+ if (color)
+ expect(output).toContain(`\u001B[${ansiColor}m${badge}\u001B[0m`);
+ }
}
},
);
@@ -573,20 +590,27 @@ describe("scan history renderer", () => {
targetPath: "/synthetic/repository",
progress: { status: "complete" },
findings: [
- { title: relation.beforeTitle, severity: "high", related: [relation] },
+ {
+ title: relation.beforeTitle,
+ severity: "informational",
+ related: [relation],
+ },
],
};
const compact = renderScanHistory(scan, "show", { color: false });
- expect(compact).toContain("1 related finding, kept separate");
+ expect(compact).toContain(`\n INFO ${relation.beforeTitle}\n`);
+ expect(compact).toContain(
+ "\n ↔ 1 related finding, kept separate",
+ );
expect(compact).not.toContain(relation.reason);
const expanded = renderScanHistory(scan, "show", {
color: false,
showLinkedFindings: true,
});
for (const value of [
- relation.afterTitle,
- relation.scanId.slice(0, 8),
- relation.reason,
+ `\n RELATED SCAN ${relation.scanId.slice(0, 8)}`,
+ `\n ↳ ${relation.afterTitle}`,
+ `\n ${relation.reason}`,
]) {
expect(expanded).toContain(value);
}