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): keep scrolled history in place at the history cap (#2266)

12f5c7cb7f9d1a
diff --git a/sdk/typescript/src/scan-dashboard.ts b/sdk/typescript/src/scan-dashboard.ts
index abf2186f5..8eaee43cf 100644
--- a/sdk/typescript/src/scan-dashboard.ts
+++ b/sdk/typescript/src/scan-dashboard.ts
@@ -667,15 +667,17 @@ export class ScanDashboard {
} else {
this.#activities[existing] = entry;
}
- if (this.#activities.length > MAX_HISTORY_ENTRIES) {
- this.#activities.splice(0, this.#activities.length - MAX_HISTORY_ENTRIES);
- }
+ // Count the added rows before dropping old entries above the view, so a
+ // scrolled view stays in place once history reaches its cap.
if (this.#scrollOffset !== 0) {
this.#scrollOffset += Math.max(
0,
this.#activityLines(this.#width()).length - previousRows,
);
}
+ if (this.#activities.length > MAX_HISTORY_ENTRIES) {
+ this.#activities.splice(0, this.#activities.length - MAX_HISTORY_ENTRIES);
+ }
this.#scheduleRefresh();
}
diff --git a/sdk/typescript/tests-ts/scan-dashboard.test.ts b/sdk/typescript/tests-ts/scan-dashboard.test.ts
index df0fd1dba..a97e1f11b 100644
--- a/sdk/typescript/tests-ts/scan-dashboard.test.ts
+++ b/sdk/typescript/tests-ts/scan-dashboard.test.ts
@@ -2073,6 +2073,33 @@ describe("live scan dashboard", () => {
dashboard.stop();
});
+ test("keeps scrolled history in place once the oldest activity is dropped", () => {
+ const stderr = capture(true);
+ const input = new DashboardTestInput();
+ const dashboard = createDashboard(
+ { ...stderr.stream, columns: 80, rows: 14 },
+ { input },
+ );
+ const visible = () => lastFrame(stderr).match(/finding-\d+/gu);
+
+ recordActions(dashboard, 2_000);
+ dashboard.start();
+ input.emit("data", "\u001B[A".repeat(6));
+ const before = visible();
+ expect(before).toContain("finding-1994");
+
+ dashboard.record({
+ id: "action-2001",
+ kind: "command",
+ status: "completed",
+ description: "rg -n finding-2001 routes.ts",
+ paths: [],
+ });
+ expect(visible()).toEqual(before);
+ expect(lastFrame(stderr)).toContain("7 lines above live");
+ dashboard.stop();
+ });
+
test("scrolls half a page with Mac-friendly Ctrl+U and Ctrl+D", () => {
const stderr = capture(true);
const input = new DashboardTestInput();