fix(audit): fold a job's successful runs whatever ran between them

The owner read a fold that broke at every other job as the same row five
times. A job's successful runs now fold into one row at the newest run's
place across other jobs and admin actions; only that job's own failed or
skipped run breaks the fold (it stays its own row, and older successes
start a new fold below it).
This commit is contained in:
2026-10-01 23:05:38 +02:00
parent 87d71e3762
commit 25905aa786
3 changed files with 50 additions and 22 deletions
+19 -7
View File
@@ -1,5 +1,6 @@
// E31: the audit log's first screen was one job's "done" ten times over. Back-to-back successful runs
// of one job fold into one row; a failure, a skip, another job or an admin's own action breaks the run.
// E31: the audit log's first screen was one job's "done" ten times over. A job's successful runs fold
// into one row whatever ran between them (the owner: a fold broken by every other job read as the same
// row five times); only that job's own failure or skip breaks it.
import { describe, expect, it } from "vitest";
import type { AuditRow } from "./api";
import { foldJobRuns } from "./auditGroups";
@@ -22,7 +23,7 @@ const shape = (rows: ReturnType<typeof foldJobRuns>) =>
rows.map((r) => `${r.target_id}:${String(r.after?.status)}×${r.runs?.length ?? 1}`);
describe("folding the job runs", () => {
it("folds back-to-back successful runs of one job, newest first", () => {
it("folds a job's successful runs into one row, newest first", () => {
const rows = [run("enrich"), run("enrich"), run("enrich"), run("people")];
const out = foldJobRuns(rows);
expect(shape(out)).toEqual(["enrich:ok×3", "people:ok×1"]);
@@ -44,11 +45,22 @@ describe("folding the job runs", () => {
]);
});
it("keeps an admin's own action between two runs, and the runs apart", () => {
expect(shape(foldJobRuns([run("enrich"), admin(), run("enrich")]))).toEqual([
"enrich:ok×1",
"x:ok×1",
it("folds across other jobs and an admin's own action, each at its own place", () => {
const rows = [run("enrich"), run("plex"), run("enrich"), admin(), run("shorts"), run("enrich")];
rows.push(run("plex"));
const out = foldJobRuns(rows);
expect(shape(out)).toEqual(["enrich:ok×3", "plex:ok×2", "x:ok×1", "shorts:ok×1"]);
expect(out[0]!.runs!.map((r) => r.id)).toEqual([rows[0]!.id, rows[2]!.id, rows[5]!.id]);
});
it("starts a new fold below the job's own failure, which another job's does not", () => {
const rows = [run("enrich"), run("enrich", "error"), run("enrich"), run("rss", "error")];
rows.push(run("enrich"));
expect(shape(foldJobRuns(rows))).toEqual([
"enrich:ok×1",
"enrich:error×1",
"enrich:ok×2",
"rss:error×1",
]);
});