feat(lens): sum up a finished live run with time taken

doneLine reads like "Reviewed 30 traces in 31s with", measured from when reading started.
This commit is contained in:
Ishaan Jaff 2026-10-03 17:58:16 -07:00
parent b174232308
commit 5724190869
No known key found for this signature in database
2 changed files with 20 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import {
briefReasoning,
checkLabel,
conclusions,
doneLine,
durationLabel,
newestFirst,
nowLine,
@ -370,6 +371,17 @@ describe("honest live list", () => {
expect(inFlight({ status: "running" } as Job)).toEqual([]);
});
it("sums up a finished run from when reading started", () => {
const job = {
reviewed: 30,
created_at: "2026-10-03T16:00:00Z",
finished_at: "2026-10-03T16:00:41Z",
steps: [{ kind: "stage", label: "Reading executions", at: "2026-10-03T16:00:10Z" }],
} as unknown as Job;
expect(doneLine(job)).toBe("Reviewed 30 traces in 31s with");
expect(doneLine({ ...job, reviewed: 1, finished_at: null })).toBe("Reviewed 1 trace with");
});
it("formats review time", () => {
expect(durationLabel(420)).toBe("420ms");
expect(durationLabel(1420)).toBe("1.4s");

View file

@ -1,3 +1,4 @@
import { durationText } from "./format";
import type { Job, Review, ReviewVerdict, Settings } from "./types";
export type Outcome = "issue" | "clear" | "unknown";
@ -239,3 +240,10 @@ export function durationLabel(ms: number): string {
if (ms < 1000) return `${Math.max(0, Math.round(ms))}ms`;
return ms < 60_000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`;
}
export function doneLine(job: Pick<Job, "reviewed" | "created_at" | "finished_at" | "steps">): string {
const end = job.finished_at ? Date.parse(job.finished_at) : Number.NaN;
const seconds = Math.round((end - Date.parse(readingStart(job))) / 1000);
const took = Number.isFinite(seconds) && seconds >= 0 ? ` in ${durationText(seconds)}` : "";
return `Reviewed ${job.reviewed} ${job.reviewed === 1 ? "trace" : "traces"}${took} with`;
}