Public: anyone can read this; the crew can change it.

A maintenance finding shows who last touched it #17015

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/16187-a-maintenance-finding-shows-who-last-tou → main 0 commits fork 7 threads · 7 unresolved

  • Merged. scout/16187-a-maintenance-finding-shows-who-last-tou was merged into main as 4380ea9.

Review

Sign in to review this change.
13 files changed +169 −37
docs/features/maintenance-findings.md +5
@@ -12,6 +12,11 @@ held (#14577), so a cause that lasted a month is one line, not thirty.
1212 still kept: a cause that cleared and opened again keeps the age of its first kept span, beside
1313 "; still open", which ends the row while the newest span is open. The fold opens when any row
1414 is open.
15 - **Who last touched it (#16187).** Each row ends with "last touched by ada 2 h ago", or
16 "untouched" while nobody has acted. Reopening an auto-closed finding records the person; the
17 tick's own close records "maintenance tick". Two columns on `degraded_span`
18 (`touched_by`, `touched_at`); there is no dismiss action yet, so those two are the actions
19 that exist.
1520 - **Bounded.** The 20 newest causes, listed oldest first so the longest-standing leads, then "And
1621 N more". One grouped read of `degraded_span` (`src/maintenance/findings.ts`), whose closed spans
1722 are pruned, so the first paint costs one statement.
src/core/account_purge.ts +4
@@ -59,6 +59,7 @@ export const COVERED: Readonly<Record<string, Coverage>> = {
5959 "config_change.by": FORMER,
6060 "crew_device.added_by": FORMER,
6161 "crew_device.granted_by": FORMER,
outdated

The column is written with a username, not a user id, so FORMER will not scrub it. Store the id or cover it as a username column, and add a purge test. Also keep the alphabetical order.

62 "degraded_span.touched_by": { do: "none", why: "a username, not an id: `purgeAccount` rewrites it to the placeholder's name" },
6263 "repo_review.by": FORMER,
6364 "review_request.requested_by": FORMER,
6465 "review_request.reviewer_id": FORMER,
@@ -367,6 +368,9 @@ export function purgeAccount(db: Database, userId: string, now: Date): PurgeOutc
367368 `${JSON.stringify(name).slice(0, -1)}/`, `${JSON.stringify(FORMER_NAME).slice(0, -1)}/`,
368369 JSON.stringify(userId), JSON.stringify(FORMER_ID),
369370 ).changes;
371 // `degraded_span.touched_by` holds a username (or the tick's name): the finding keeps the
372 // touch, as the placeholder's.
373 if (name !== "") kept += db.query("UPDATE degraded_span SET touched_by = ?2 WHERE touched_by = ?1").run(name, FORMER_NAME).changes;
370374 // `entitlement.payer` is an address, not an id: an ended plan forgets who paid.
371375 const email = db.query<{ email: string }, [string]>("SELECT email FROM user WHERE id = ?1").get(userId)?.email ?? "";
372376 if (email !== "") kept += db.query("UPDATE entitlement SET payer = '' WHERE payer = ?1 COLLATE NOCASE").run(email).changes;
src/core/migration-pins/20261201130000-finding-touched.pin added +1
@@ -0,0 +1,1 @@
1 461643df3330f0bdad0c36fa5105221fd0b93c831dfab8b2e7011621e84546f6
src/core/migrations/20261201130000-finding-touched.ts added +6
@@ -0,0 +1,6 @@
1 // A finding names who last acted on it (#16187, maintenance/findings.ts): a person who reopened
2 // it, or the maintenance tick that closed it. Null while nobody has.
3 export default `
4 ALTER TABLE degraded_span ADD COLUMN touched_by TEXT;
5 ALTER TABLE degraded_span ADD COLUMN touched_at INTEGER;
6 `;
src/generated/migrations.ts +4 −2
@@ -445,7 +445,8 @@ import m440 from "../core/migrations/20261201000000-games.ts";
445445 import m441 from "../core/migrations/20261201090000-app-vital-member.ts";
446446 import m442 from "../core/migrations/20261201120000-first-change-forge.ts";
447447 import m443 from "../core/migrations/20261201121000-repo-check-slots.ts";
448 import m444 from "../core/migrations/20261201130000-game-box-boot.ts";
448 import m444 from "../core/migrations/20261201130000-finding-touched.ts";
449 import m445 from "../core/migrations/20261201130000-game-box-boot.ts";
449450
450451 /** Each migration file's name and its default export, in name order. */
451452 export const MIGRATION_MODULES: readonly (readonly [string, unknown])[] = [
@@ -893,5 +894,6 @@ export const MIGRATION_MODULES: readonly (readonly [string, unknown])[] = [
893894 ["20261201090000-app-vital-member.ts", m441],
894895 ["20261201120000-first-change-forge.ts", m442],
895896 ["20261201121000-repo-check-slots.ts", m443],
896 ["20261201130000-game-box-boot.ts", m444],
897 ["20261201130000-finding-touched.ts", m444],
898 ["20261201130000-game-box-boot.ts", m445],
897899 ];
src/maintenance/findings.ts +46 −18
@@ -21,8 +21,14 @@ export interface FindingRow {
2121 readonly openedAt: number;
2222 /** When the tick closed it for want of action (epoch ms), or null while it stands. */
2323 readonly autoClosedAt: number | null;
24 /** Who last acted on it (a person, or the tick that closed it) and when; null when nobody has. */
25 readonly touchedBy: string | null;
26 readonly touchedAt: number | null;
2427 }
2528
29 /** The name the tick's own sweep is recorded under. */
30 export const TICK_ACTOR = "maintenance tick";
31
2632 /** Days a finding may stand with no action before the tick closes it. */
2733 export const AUTO_CLOSE_DAYS = 14;
2834 /** The note an auto-closed finding carries. */
@@ -46,29 +52,40 @@ export interface Findings {
4652 */
4753 export function findingRows(db: Database, cap = FINDING_ROWS): Findings {
4854 const { got, more } = latestSpans(db, cap);
49 const rows = oldestFirst(got).map((r) => ({ cause: r.cause, latest: r.sentence, open: r.closed_at === null, openedAt: r.first, autoClosedAt: r.swept_at }));
55 const rows = oldestFirst(got).map((r) => ({ cause: r.cause, latest: r.sentence, open: r.closed_at === null, openedAt: r.first, autoClosedAt: r.swept_at, touchedBy: r.touched_by, touchedAt: r.touched_at }));
5056 return { rows, autoClosed: autoClosedCauses(db).length, more };
5157 }
5258
53 interface SpanRow { cause: string; sentence: string; href: string; closed_at: number | null; swept_at: number | null; first: number; total: number }
59 interface SpanRow { cause: string; sentence: string; href: string; closed_at: number | null; swept_at: number | null; touched_by: string | null; touched_at: number | null; first: number; total: number }
5460
5561 /** Oldest first-seen leads; ties keep the query's order. */
5662 const oldestFirst = (rows: SpanRow[]): SpanRow[] => [...rows].sort((a, b) => a.first - b.first);
5763
64 /** "3 d ago", "just now": how long before `now` a moment was. */
65 function agoWords(at: number, now: number): string {
66 const ms = Math.max(0, now - at);
67 if (ms < 60_000) return "just now";
68 if (ms < 3_600_000) return `${String(Math.floor(ms / 60_000))} m ago`;
69 if (ms < DAY_MS) return `${String(Math.floor(ms / 3_600_000))} h ago`;
70 return `${String(Math.floor(ms / DAY_MS))} d ago`;
71 }
72
5873 /** "opened 3 d ago": the age of a finding against the clock the caller passes in. */
59 export function openedWords(openedAt: number, now: number): string {
60 const ms = Math.max(0, now - openedAt);
61 if (ms < 60_000) return "opened just now";
62 if (ms < 3_600_000) return `opened ${String(Math.floor(ms / 60_000))} m ago`;
63 if (ms < DAY_MS) return `opened ${String(Math.floor(ms / 3_600_000))} h ago`;
64 return `opened ${String(Math.floor(ms / DAY_MS))} d ago`;
74 export const openedWords = (openedAt: number, now: number): string => `opened ${agoWords(openedAt, now)}`;
75
76 /** "last touched by ada 2 d ago", or "untouched" while nobody has acted on it. */
outdated

Building the sentence by calling openedWords and stripping "opened " with replace couples this to that function's wording. If its phrasing changes, this silently prints the wrong words. Split out an agoWords(ms, now) that both functions call.

77 export function touchedWords(by: string | null, at: number | null, now: number): string {
78 if (by === null || at === null) return "untouched";
79 return `last touched by ${by} ${agoWords(at, now)}`;
6580 }
6681
6782 /** The one query behind every reading of the findings: the board, the terminal and the JSON. */
6883 function latestSpans(db: Database, cap: number): { got: SpanRow[]; more: number } {
6984 const got = db
7085 .query<SpanRow, [number]>(
71 `SELECT s.cause, s.sentence, s.href, s.closed_at, s.swept_at, g.first, COUNT(*) OVER () AS total
86 `SELECT s.cause, s.sentence, s.href, s.closed_at, s.swept_at, g.first,
87 (SELECT t.touched_by FROM degraded_span t WHERE t.cause = s.cause AND t.touched_at IS NOT NULL ORDER BY t.touched_at DESC, t.id DESC LIMIT 1) AS touched_by,
88 (SELECT MAX(t.touched_at) FROM degraded_span t WHERE t.cause = s.cause) AS touched_at, COUNT(*) OVER () AS total
7289 FROM degraded_span s
7390 JOIN (SELECT cause, MAX(id) AS last, MIN(opened_at) AS first FROM degraded_span GROUP BY cause) g ON s.id = g.last
7491 ORDER BY s.opened_at DESC, s.id DESC LIMIT ?1`,
@@ -83,12 +100,12 @@ function latestSpans(db: Database, cap: number): { got: SpanRow[]; more: number
83100 */
84101 export function autoClose(db: Database, now: number): string[] {
85102 return db
86 .query<{ cause: string }, [number, number]>(
87 `UPDATE degraded_span SET swept_at = ?1
103 .query<{ cause: string }, [number, number, string]>(
outdated

The tick's recording as TICK_ACTOR is untested. The new test seeds it by raw SQL, so it would pass without this change.

104 `UPDATE degraded_span SET swept_at = ?1, touched_by = ?3, touched_at = ?1
88105 WHERE closed_at IS NULL AND swept_at IS NULL AND COALESCE(clock_at, opened_at) <= ?2
89106 RETURNING cause`,
90107 )
91 .all(now, now - AUTO_CLOSE_DAYS * DAY_MS)
108 .all(now, now - AUTO_CLOSE_DAYS * DAY_MS, TICK_ACTOR)
92109 .map((r) => r.cause);
93110 }
94111
@@ -104,13 +121,14 @@ export function autoClosedCauses(db: Database): string[] {
104121 }
105122
106123 /** Reopen an auto-closed finding: it stands again and its 14 days begin now. */
107 export function reopenFinding(db: Database, cause: string, now: number): boolean {
124 export function reopenFinding(db: Database, cause: string, now: number, actor: string): boolean {
125 if (actor.trim() === "") return false;
108126 return (
109127 db
110 .query<{ id: number }, [string, number]>(
111 "UPDATE degraded_span SET swept_at = NULL, clock_at = ?2 WHERE cause = ?1 AND swept_at IS NOT NULL RETURNING id",
128 .query<{ id: number }, [string, number, string]>(
129 "UPDATE degraded_span SET swept_at = NULL, clock_at = ?2, touched_by = ?3, touched_at = ?2 WHERE cause = ?1 AND swept_at IS NOT NULL RETURNING id",
112130 )
113 .all(cause, now).length > 0
131 .all(cause, now, actor).length > 0
114132 );
115133 }
116134
@@ -129,6 +147,10 @@ export interface FindingJson {
129147 readonly action: string;
130148 /** ISO time the cause was first seen. */
131149 readonly openedAt: string;
150 /** Who last acted on it, or null when nobody has. */
151 readonly touchedBy: string | null;
152 /** ISO time of that action, or null. */
153 readonly touchedAt: string | null;
132154 }
133155
134156 /** The same rows as `findingRows`, as the plain data `/maintenance.json` answers. */
@@ -140,13 +162,19 @@ export function findingsJson(db: Database): { findings: FindingJson[] } {
140162 cause: r.sentence,
141163 action: r.href,
142164 openedAt: new Date(r.first).toISOString(),
165 touchedBy: r.touched_by,
166 touchedAt: r.touched_at === null ? null : new Date(r.touched_at).toISOString(),
143167 })),
144168 };
145169 }
146170
147 /** The words a row ends on, board and terminal alike: its age, then "still open" while it is. */
171 /**
172 * The words a row ends on, board and terminal alike: its age, then "still open" while it is, then
outdated

Principle 1: for an auto-closed row the tick's touch repeats the "closed ..." clause. Leave it off when the toucher is the tick.

173 * who last touched it, or "untouched". When the tick closed this row, its "closed" clause already
outdated

The touch is dropped whenever touchedBy === TICK_ACTOR, not only when the row is auto-closed. The touched subquery reads across all spans of a cause: if the tick swept an older span and a newer span of that cause is now open, autoClosedAt is null and the row ends with "still open" and says nothing about who touched it. That misses box 1 ("last actor's name and when, or untouched"), and principle 1 only argues against saying the same thing twice. Fix: omit the touched clause only when r.autoClosedAt !== null && r.touchedBy === TICK_ACTOR; otherwise print touchedWords, so the tick shows as "last touched by maintenance tick 3 d ago". Add a test with a swept older span and an open newer span.

174 * says the touch, so it is not said twice; a tick touch on an older span still shows.
175 */
148176 export const rowWords = (r: FindingRow, now: number): string =>
149 `${openedWords(r.openedAt, now)}${r.autoClosedAt !== null ? `; closed ${closedDate(r.autoClosedAt)}: ${AUTO_CLOSE_NOTE}` : r.open ? "; still open" : ""}`;
177 `${openedWords(r.openedAt, now)}${r.autoClosedAt !== null ? `; closed ${closedDate(r.autoClosedAt)}: ${AUTO_CLOSE_NOTE}` : r.open ? "; still open" : ""}${r.autoClosedAt !== null && r.touchedBy === TICK_ACTOR ? "" : `; ${touchedWords(r.touchedBy, r.touchedAt, now)}`}`;
150178
151179 /** The same rows as terminal lines, led by a blank line; nothing when none. */
152180 export function findingLines(db: Database, now: number = Date.now()): string[] {
src/tui/screens/maintenance.ts +1 −1
@@ -199,7 +199,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
199199 */
200200 const doReopen = (i: number): void => {
201201 const cause = autoClosedCauses(f.app.db)[i];
outdated

The new "Sign in to reopen a finding." branch has no test. It is a behaviour this pull adds, so it needs one that would fail without it, or the branch should be removed if it truly cannot be reached.

202 say(cause !== undefined && reopenFinding(f.app.db, cause, Date.now()) ? `Reopened ${cause}.` : "That finding is not closed.");
202 say(cause !== undefined && reopenFinding(f.app.db, cause, Date.now(), f.user?.username ?? "") ? `Reopened ${cause}.` : "That finding is not closed.");

An empty actor is recorded when f.user is absent. Refuse the reopen instead, and test it.

203203 };
204204
205205 /**
src/web/pages/maintenance.ts +1 −1
@@ -335,7 +335,7 @@ export async function maintenanceReopen(ctx: Ctx): Promise<Response> {
335335 const form = await readForm(ctx, "admin");
336336 if (form instanceof Response) return form;
337337 const cause = formField(form, "cause");
338 const ok = cause.length > 0 && cause.length <= 200 && reopenFinding(ctx.app.db, cause, Date.now());
338 const ok = cause.length > 0 && cause.length <= 200 && reopenFinding(ctx.app.db, cause, Date.now(), ctx.auth.user!.username);
339339 return flashTo(ctx, "/maintenance", ok ? { message: `Reopened ${cause}.` } : { tone: "danger", message: "That finding is not closed." });
340340 }
341341
test/account-purge.test.ts +13
@@ -217,6 +217,19 @@ describe("what stays names nobody", () => {
217217 });
218218 });
219219
220 describe("a finding's toucher", () => {
221 test("a purged person's name on a maintenance finding becomes the placeholder's; the tick's stays", async () => {
222 const dana = await make("dana");
223 app.db.run("INSERT INTO degraded_span (cause, sentence, href, opened_at, touched_by, touched_at) VALUES ('a', 'x', '/system', 1, 'dana', 5), ('b', 'x', '/system', 1, 'maintenance tick', 5), ('c', 'x', '/system', 1, 'danae', 5)");
224 expect(requestClose(app.db, dana.id, T0)).toBe(true);
225 await purgeDue(app, at(7));
226 const by = (c: string) => app.db.query<{ t: string }, [string]>("SELECT touched_by AS t FROM degraded_span WHERE cause = ?1").get(c)!.t;
227 expect(by("a")).toBe(FORMER_NAME);
228 expect(by("b")).toBe("maintenance tick");
229 expect(by("c")).toBe("danae");
230 });
231 });
232
220233 describe("every column that names a user is covered", () => {
221234 test("by its cascade or by a row of COVERED", () => {
222235 // A new table that holds a user id with no ON DELETE CASCADE / SET NULL
test/maintenance-autoclose.test.ts +61 −4
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
88 import { join } from "node:path";
99 import { createApp, type App } from "../src/app.ts";
1010 import { serve, type Servers } from "../src/http/server.ts";
11 import { AUTO_CLOSE_NOTE, autoClose, closedDate, findingLines, findingRows, reopenFinding } from "../src/maintenance/findings.ts";
11 import { AUTO_CLOSE_NOTE, TICK_ACTOR, autoClose, closedDate, findingLines, findingRows, reopenFinding, rowWords } from "../src/maintenance/findings.ts";
1212 import { adminCookie } from "./helpers/admin.ts";
1313 import { quietLogs } from "./helpers/globals.ts";
1414
@@ -18,7 +18,7 @@ const T0 = Date.parse("2026-11-01T12:00:00.000Z");
1818
1919 function seed(): Database {
2020 const db = new Database(":memory:");
21 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER)");
21 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER, touched_by TEXT, touched_at INTEGER)");
2222 return db;
2323 }
2424 const add = (db: Database, cause: string, at: number, closedAt: number | null = null): void => {
@@ -42,8 +42,8 @@ test("a reopened finding stands again and its 14 days begin at the reopening", (
4242 const db = seed();
4343 add(db, "disk-free", T0);
4444 autoClose(db, T0 + 14 * DAY);
45 expect(reopenFinding(db, "disk-free", T0 + 16 * DAY)).toBe(true);
46 expect(reopenFinding(db, "disk-free", T0 + 16 * DAY)).toBe(false);
45 expect(reopenFinding(db, "disk-free", T0 + 16 * DAY, "ada")).toBe(true);
46 expect(reopenFinding(db, "disk-free", T0 + 16 * DAY, "ada")).toBe(false);
4747 expect(findingRows(db).autoClosed).toBe(0);
4848 expect(autoClose(db, T0 + 29 * DAY)).toEqual([]); // day 13 after reopening
4949 expect(autoClose(db, T0 + 30 * DAY)).toEqual(["disk-free"]);
@@ -84,3 +84,60 @@ test("the page shows the closing with its date and a Reopen button; the summary
8484 expect(res.status).toBe(303);
8585 expect(findingRows(app.db).autoClosed).toBe(0);
8686 });
87
88 test("the sweep records the tick as the toucher, at the sweep's time, and the row does not say it twice", () => {
89 const db = seed();
90 add(db, "disk-free", T0);
91 autoClose(db, T0 + 14 * DAY);
92 const r = findingRows(db).rows[0]!;
93 expect(r.touchedBy).toBe(TICK_ACTOR);
94 expect(r.touchedAt).toBe(T0 + 14 * DAY);
95 expect(rowWords(r, T0 + 15 * DAY)).not.toContain("last touched");
96 expect(rowWords(r, T0 + 15 * DAY)).toContain("closed 2026-11-15");
97 });
98
99 test("a tick touch on a swept older span still shows when a newer span of the cause stands open", () => {
100 const db = seed();
101 add(db, "disk-free", T0);
102 autoClose(db, T0 + 14 * DAY);
103 add(db, "disk-free", T0 + 16 * DAY);
104 const r = findingRows(db).rows[0]!;
105 expect(r.autoClosedAt).toBeNull();
106 expect(r.open).toBe(true);
107 expect(rowWords(r, T0 + 17 * DAY)).toBe(`opened 17 d ago; still open; last touched by ${TICK_ACTOR} 3 d ago`);
108 });
109
110 test("a person's touch reads its age in the same words as the opening: just now, m, h, d", () => {
111 const db = seed();
112 add(db, "disk-free", T0);
113 autoClose(db, T0 + 14 * DAY);
114 reopenFinding(db, "disk-free", T0 + 15 * DAY, "ada");
115 const r = findingRows(db).rows[0]!;
116 expect(rowWords(r, T0 + 15 * DAY)).toContain("; last touched by ada just now");
117 expect(rowWords(r, T0 + 15 * DAY + 5 * 60_000)).toContain("; last touched by ada 5 m ago");
118 expect(rowWords(r, T0 + 15 * DAY + 3 * 3_600_000)).toContain("; last touched by ada 3 h ago");
119 expect(rowWords(r, T0 + 17 * DAY)).toContain("; last touched by ada 2 d ago");
120 });
121
122 test("a reopening with no one to name is refused and leaves the finding closed", () => {
123 const db = seed();
124 add(db, "disk-free", T0);
125 autoClose(db, T0 + 14 * DAY);
126 expect(reopenFinding(db, "disk-free", T0 + 15 * DAY, "")).toBe(false);
127 expect(reopenFinding(db, "disk-free", T0 + 15 * DAY, " ")).toBe(false);
128 expect(findingRows(db).autoClosed).toBe(1);
129 });
130
131 test("the page's Reopen records the signed-in username as the toucher", async () => {
132 add(app.db, "load-high", Date.now() - 20 * DAY);
133 autoClose(app.db, Date.now());
134 const res = await fetch(`${servers.url}/maintenance/findings/reopen`, {
135 method: "POST", redirect: "manual",
136 headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
137 body: new URLSearchParams({ cause: "load-high" }),
138 });
139 expect(res.status).toBe(303);
140 const row = findingRows(app.db).rows.find((x) => x.cause === "load-high")!;
141 expect(row.touchedBy).toBe("boss");
142 expect(row.touchedAt).not.toBeNull();
143 });
test/maintenance-finding-age.test.ts +21 −5
@@ -2,14 +2,14 @@
22 import { expect, test } from "bun:test";
33 import { Database } from "bun:sqlite";
44 import { findingsFold } from "../src/web/pages/maintenance.ts";
5 import { findingLines, findingRows, findingsJson, openedWords } from "../src/maintenance/findings.ts";
5 import { findingLines, findingRows, findingsJson, openedWords, reopenFinding } from "../src/maintenance/findings.ts";
66
77 const DAY = 86_400_000;
88 const NOW = Date.parse("2026-11-23T12:00:00.000Z");
99
1010 function seed(): Database {
1111 const db = new Database(":memory:");
12 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER)");
12 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER, touched_by TEXT, touched_at INTEGER)");
1313 const ins = db.query("INSERT INTO degraded_span (cause, sentence, href, opened_at, closed_at) VALUES (?1, 'x', '/system', ?2, NULL)");
1414 ins.run("newer", NOW - 2 * 3_600_000);
1515 ins.run("oldest", NOW - 3 * DAY);
@@ -27,7 +27,7 @@ test("ages read in minutes, hours and days against the clock given", () => {
2727 test("findings list oldest first, in the rows, the terminal and the JSON", () => {
2828 const db = seed();
2929 expect(findingRows(db).rows.map((r) => r.cause)).toEqual(["oldest", "middle", "newer"]);
30 expect(findingLines(db, NOW)[2]).toBe("oldest: x (opened 3 d ago; still open)");
30 expect(findingLines(db, NOW)[2]).toBe("oldest: x (opened 3 d ago; still open; untouched)");
3131 const json = findingsJson(db).findings;
3232 expect(json.map((f) => f.duty)).toEqual(["oldest", "middle", "newer"]);
3333 expect(json[0]?.openedAt).toBe(new Date(NOW - 3 * DAY).toISOString());
@@ -45,12 +45,28 @@ test("the board's Findings fold says the age in each row, oldest first, against
4545
4646 test("a cause that cleared and opened again keeps the age of its first kept span", () => {
4747 const db = new Database(":memory:");
48 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER)");
48 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER, touched_by TEXT, touched_at INTEGER)");
4949 const ins = db.query("INSERT INTO degraded_span (cause, sentence, href, opened_at, closed_at) VALUES ('disk', ?1, '/system', ?2, ?3)");
5050 ins.run("first", NOW - 5 * DAY, NOW - 4 * DAY);
5151 ins.run("again", NOW - 3_600_000, null);
5252 const [row] = findingRows(db).rows;
5353 expect(row?.openedAt).toBe(NOW - 5 * DAY);
54 expect(findingLines(db, NOW)[2]).toBe("disk: again (opened 5 d ago; still open)");
54 expect(findingLines(db, NOW)[2]).toBe("disk: again (opened 5 d ago; still open; untouched)");
5555 expect(findingsJson(db).findings[0]?.openedAt).toBe(new Date(NOW - 5 * DAY).toISOString());
5656 });
57
58 test("a row names who last touched it and when, or says untouched (#16187)", () => {
59 const db = seed();
60 db.run("UPDATE degraded_span SET swept_at = ?1, touched_by = 'maintenance tick', touched_at = ?1 WHERE cause = 'oldest'", [NOW - DAY]);
61 expect(reopenFinding(db, "oldest", NOW - 2 * 3_600_000, "ada")).toBe(true);
62 const rows = findingRows(db).rows;
63 expect(rows.find((r) => r.cause === "oldest")?.touchedBy).toBe("ada");
64 expect(rows.find((r) => r.cause === "middle")?.touchedBy).toBeNull();
65 const lines = findingLines(db, NOW);
66 expect(lines.find((l) => l.startsWith("oldest:"))).toContain("last touched by ada 2 h ago");
67 expect(lines.find((l) => l.startsWith("middle:"))).toContain("untouched");
68 expect(String(findingsFold(db, NOW))).toContain("last touched by ada 2 h ago");
69 const json = findingsJson(db).findings;
70 expect(json.find((f) => f.duty === "oldest")).toMatchObject({ touchedBy: "ada", touchedAt: new Date(NOW - 2 * 3_600_000).toISOString() });
71 expect(json.find((f) => f.duty === "middle")).toMatchObject({ touchedBy: null, touchedAt: null });
72 });
test/maintenance-findings.test.ts +4 −4
@@ -8,7 +8,7 @@ const T0 = Date.parse("2026-11-01T12:00:00.000Z");
88
99 function seed(): Database {
1010 const db = new Database(":memory:");
11 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER)");
11 db.run("CREATE TABLE degraded_span (id INTEGER PRIMARY KEY AUTOINCREMENT, cause TEXT NOT NULL, sentence TEXT NOT NULL, href TEXT NOT NULL, opened_at INTEGER NOT NULL, closed_at INTEGER, swept_at INTEGER, clock_at INTEGER, touched_by TEXT, touched_at INTEGER)");
1212 return db;
1313 }
1414 const add = (db: Database, cause: string, sentence: string, at: number, closed: boolean): void => {
@@ -25,8 +25,8 @@ test("three days of one finding are one row with the latest reading; another fin
2525 const { rows } = findingRows(db);
2626 expect(rows.length).toBe(2);
2727 const mem = rows.find((r) => r.cause === "memory-growth")!;
28 expect(mem).toEqual({ cause: "memory-growth", latest: "50 MiB", open: true, openedAt: T0, autoClosedAt: null });
29 expect(rows.find((r) => r.cause === "disk-free")).toEqual({ cause: "disk-free", latest: "5 GiB", open: false, openedAt: T0 + DAY, autoClosedAt: null });
28 expect(mem).toEqual({ cause: "memory-growth", latest: "50 MiB", open: true, openedAt: T0, autoClosedAt: null, touchedBy: null, touchedAt: null });
29 expect(rows.find((r) => r.cause === "disk-free")).toEqual({ cause: "disk-free", latest: "5 GiB", open: false, openedAt: T0 + DAY, autoClosedAt: null, touchedBy: null, touchedAt: null });
3030 });
3131
3232 test("rows are capped and the rest counted; the terminal says the same", () => {
@@ -42,5 +42,5 @@ test("rows are capped and the rest counted; the terminal says the same", () => {
4242 test("an open cause says so once, in its row", () => {
4343 const db = seed();
4444 add(db, "disk-free", "1 GiB", T0, false);
45 expect(findingLines(db, T0)).toContain("disk-free: 1 GiB (opened just now; still open)");
45 expect(findingLines(db, T0)).toContain("disk-free: 1 GiB (opened just now; still open; untouched)");
4646 });
test/maintenance-json.test.ts +2 −2
@@ -36,8 +36,8 @@ afterAll(async () => {
3636
3737 test("the JSON carries the findings the page lists, from the same module", async () => {
3838 const want = [
39 { duty: "disk-free", severity: "degraded", cause: "5 GiB left", action: "/system", openedAt: new Date(1_000).toISOString() },
40 { duty: "memory-growth", severity: "cleared", cause: "40 MiB", action: "/resilience", openedAt: new Date(2_000).toISOString() },
39 { duty: "disk-free", severity: "degraded", cause: "5 GiB left", action: "/system", openedAt: new Date(1_000).toISOString(), touchedBy: null, touchedAt: null },
40 { duty: "memory-growth", severity: "cleared", cause: "40 MiB", action: "/resilience", openedAt: new Date(2_000).toISOString(), touchedBy: null, touchedAt: null },
4141 ];
4242 for (const res of [
4343 await fetch(`${servers.url}/maintenance.json`, { headers: { cookie } }),

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs