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: sort interactive findings by severity (#2135)

Suhail Patele6f10084a617
diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.md
index ac7cde584..0c40b04cd 100644
--- a/sdk/typescript/docs/cli.md
+++ b/sdk/typescript/docs/cli.md
@@ -2819,7 +2819,9 @@ patch-risk assessment still uses its read-only sandbox.
`scan --patch` runs after a complete scan. `--patch-severity` defaults to `low`;
`high` selects high and critical findings. Interactive users can select findings
-and add instructions. Patch results are `verified`, `no_change`, `blocked`, or
+and add instructions. The interactive finding browser lists critical, high,
+medium, then low findings, preserving scan order within each severity.
+Patch results are `verified`, `no_change`, `blocked`, or
`failed`. Verified/already-fixed findings no longer fail the severity threshold.
### Create or resume a draft pull request
diff --git a/sdk/typescript/src/patch-tui.tsx b/sdk/typescript/src/patch-tui.tsx
index 6d95ab3a5..42d55058f 100644
--- a/sdk/typescript/src/patch-tui.tsx
+++ b/sdk/typescript/src/patch-tui.tsx
@@ -4,6 +4,7 @@ import { stripVTControlCharacters } from "node:util";
import { Box, Text, render, useApp, useInput, useStdout } from "ink";
import { useMemo, useRef, useState } from "react";
import type { Finding, FindingCodeEvidence } from "./models.js";
+import { SCAN_SEVERITIES } from "./scan-settings.js";
const SEVERITY_COLORS = {
critical: "redBright",
@@ -362,12 +363,21 @@ function FindingDetailLine({
export function PatchTui({
repository,
- findings,
+ findings: inputFindings,
onComplete,
color = process.env["NO_COLOR"] === undefined,
}: PatchTuiProps): React.JSX.Element {
const { exit } = useApp();
const { stdout } = useStdout();
+ const findings = useMemo(
+ () =>
+ [...inputFindings].sort(
+ (left, right) =>
+ SCAN_SEVERITIES.indexOf(left.severity.level) -
+ SCAN_SEVERITIES.indexOf(right.severity.level),
+ ),
+ [inputFindings],
+ );
const [pane, setPane] = useState<"findings" | "details">("findings");
const [focused, setFocused] = useState(0);
const focusedFinding = useRef(focused);
diff --git a/sdk/typescript/tests-ts/patch-tui.test.ts b/sdk/typescript/tests-ts/patch-tui.test.ts
index f10898d9a..33ebd44fe 100644
--- a/sdk/typescript/tests-ts/patch-tui.test.ts
+++ b/sdk/typescript/tests-ts/patch-tui.test.ts
@@ -100,6 +100,55 @@ async function press(
}
describe("interactive patch finding browser", () => {
+ test("orders findings by severity while keeping navigation and selection aligned", async () => {
+ const inputFindings = findings([
+ "low",
+ "high",
+ "medium",
+ "critical",
+ "high",
+ ]);
+ const originalOrder = inputFindings.map(({ occurrenceId }) => occurrenceId);
+ const selected: (PatchSelection | null)[] = [];
+ const app = render(
+ createElement(PatchTui, {
+ repository: "/work/example",
+ findings: inputFindings,
+ color: false,
+ onComplete: (value) => selected.push(value),
+ }),
+ );
+
+ const displayedFindings = (app.lastFrame() ?? "")
+ .split("\n")
+ .flatMap(
+ (line) =>
+ line.match(/(?:CRITICAL|HIGH|MEDIUM|LOW) Finding \d+/gu) ?? [],
+ );
+ expect(displayedFindings).toEqual([
+ "CRITICAL Finding 4",
+ "HIGH Finding 2",
+ "HIGH Finding 5",
+ "MEDIUM Finding 3",
+ "LOW Finding 1",
+ ]);
+ expect(app.lastFrame()).toContain("input reaches finding 4.");
+
+ await press(app, "n");
+ await press(app, " ");
+ await press(app, "j");
+ expect(app.lastFrame()).toContain("input reaches finding 2.");
+ await press(app, " ");
+ await press(app, "\r");
+
+ expect(selected).toEqual([
+ { severity: "high", occurrenceIds: ["occ_4", "occ_2"] },
+ ]);
+ expect(inputFindings.map(({ occurrenceId }) => occurrenceId)).toEqual(
+ originalOrder,
+ );
+ });
+
test("shows complete finding details and scrolls through source evidence", async () => {
const app = render(
createElement(PatchTui, {