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

A maintenance finding with no action for 14 days closes itself with a note #16007

Merged opened this

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

Merged

scout/forge:scout/15982-a-maintenance-finding-with-no-action-for → main 0 commits fork 4 threads · 4 unresolved

  • Merged. scout/15982-a-maintenance-finding-with-no-action-for was merged into main as 743ac0e.

Review

Sign in to review this change.
11 files changed +252 −15
docs/features/maintenance-autoclose.md added +17
@@ -0,0 +1,17 @@
1 ---
2 topic: When something is wrong
3 row: Findings that close themselves
4 ---
5 # Findings that close themselves (#15982)
6
7 A finding on the maintenance board that stands 14 days with no action closes itself. The row then
8 reads "closed 2026-11-15: no action in 14 days", and the Findings fold counts "N auto-closed".
9 Reopening it starts its 14 days again.
10
11 - **Page**: `/maintenance`, Findings. An auto-closed row has a **Reopen** button (admins).
12 - **Terminal**: the Maintenance screen (`src/tui/screens/maintenance.ts`) lists them under "Closed
13 for want of action"; `o` asks for a number and reopens that one, through the same
14 `reopenFinding` as the page.
15 - **How it runs**: the maintenance tick calls `autoClose` (`src/maintenance/findings.ts`) after
16 the degraded history is recorded; a failure of its own is logged as "findings: auto-close failed".
17 Nothing is deleted: the span is only marked.
src/core/migration-pins/20261123130000-finding-autoclose.pin added +1
@@ -0,0 +1,1 @@
1 f64d7a1bf8bc086349a4fef22c1796311dcdedf70ba55f7c3b23f81780307019
src/core/migrations/20261123130000-finding-autoclose.ts added +8
@@ -0,0 +1,8 @@
1 // A finding nobody acted on for 14 days is closed with a note (#15982, maintenance/findings.ts).
2 // `swept_at` is when the maintenance tick closed it (epoch ms; null while it stands), and
3 // `clock_at` is when its 14 days last began again, set when a person reopens it. The span itself
4 // keeps following the cause, so nothing the vitals say is hidden or lost.
5 export default `
6 ALTER TABLE degraded_span ADD COLUMN swept_at INTEGER;
7 ALTER TABLE degraded_span ADD COLUMN clock_at INTEGER;
8 `;
src/http/server.ts +2 −1
@@ -44,7 +44,7 @@ import { contributePage } from "../web/pages/contribute.ts";
4444 import { pipelinePage } from "../web/pages/pipeline.ts";
4545 import { adminDataPage, appDataCsv, appDataPage, dataPage } from "../web/pages/data.ts";
4646 import { fleetAct, fleetReceipt, fleetUndo } from "../web/pages/fleet-ops.ts";
47 import { maintenanceDuty, maintenanceDismiss, maintenanceQuiet, maintenanceUnquiet, maintenanceJson, maintenancePage, maintenancePrepare, maintenanceResume, staleAction, mergedAction, previewAction } from "../web/pages/maintenance.ts";
47 import { maintenanceDuty, maintenanceDismiss, maintenanceQuiet, maintenanceUnquiet, maintenanceReopen, maintenanceJson, maintenancePage, maintenancePrepare, maintenanceResume, staleAction, mergedAction, previewAction } from "../web/pages/maintenance.ts";
4848 import { maintenanceBudget } from "../web/pages/maintenance_budgets.ts";
4949 import { nightlyOutputPage, resiliencePage } from "../web/pages/resilience.ts";
5050 import { boundedSignal } from "../kernel/fetch_timeout.ts";
@@ -1185,6 +1185,7 @@ export function buildRouter(): Router<Handler> {
11851185 router.add("POST", "/maintenance/dismiss", maintenanceDismiss);
11861186 router.add("POST", "/maintenance/quiet", maintenanceQuiet);
11871187 router.add("POST", "/maintenance/unquiet", maintenanceUnquiet);
1188 router.add("POST", "/maintenance/findings/reopen", maintenanceReopen);
11881189 router.add("POST", "/maintenance/stale/:id/:what", staleAction);
11891190 router.add("POST", "/maintenance/branches/delete", mergedAction);
11901191 router.add("POST", "/maintenance/previews/remove", previewAction);
src/main.ts +7
@@ -109,6 +109,7 @@ import { configProblem, dataDirOf, preflight } from "./kernel/preflight.ts";
109109 import { running } from "./kernel/version.ts";
110110 import { record as recordDegraded } from "./kernel/degraded_history.ts";
111111 import { vitals } from "./kernel/vitals.ts";
112 import { autoClose } from "./maintenance/findings.ts";
112113 import { markReady, readFootprint, keepFootprint } from "./system/footprint.ts";
113114 import { walkSmallForge } from "./release/small_forge.ts";
114115 import { proveRunning } from "./release/prove.ts";
@@ -895,6 +896,12 @@ const tickAsks = async (): Promise<void> => {
895896 } catch (error) {
outdated

The sweep shares the try with the vitals record: a vitals failure skips it, and its own failure logs as 'vitals failed'. Give it its own try/catch.

896897 app.log.warn("degraded history: vitals failed", { error: String(error) });
897898 }
899 // Findings with no action for 14 days close themselves; its failure is its own.
900 try {
901 autoClose(app.db, Date.now());
902 } catch (error) {
903 app.log.warn("findings: auto-close failed", { error: String(error) });
904 }
898905 };
899906 // Followed upstreams are read on a slow tick (`actions/upstream_follow.ts`):
900907 // the tip and how far behind land on the follow row; nothing is opened.
src/maintenance/findings.ts +55 −5
@@ -16,13 +16,22 @@ export interface FindingRow {
1616 readonly days: number;
1717 /** True while the newest span is still open. */
1818 readonly open: boolean;
19 /** When the tick closed it for want of action (epoch ms), or null while it stands. */
20 readonly autoClosedAt: number | null;
1921 }
2022
23 /** Days a finding may stand with no action before the tick closes it. */
24 export const AUTO_CLOSE_DAYS = 14;
25 /** The note an auto-closed finding carries. */
26 export const AUTO_CLOSE_NOTE = `no action in ${String(AUTO_CLOSE_DAYS)} days`;
27
2128 /** Rows a board shows; the rest are counted, not listed. */
2229 export const FINDING_ROWS = 20;
2330
2431 export interface Findings {
2532 readonly rows: FindingRow[];
33 /** Every cause the tick closed for want of action, listed or not. */
34 readonly autoClosed: number;
2635 /** Causes past the cap, not listed. */
2736 readonly more: number;
2837 }
@@ -33,16 +42,17 @@ export interface Findings {
3342 */
3443 export function findingRows(db: Database, cap = FINDING_ROWS): Findings {
3544 const { got, more } = latestSpans(db, cap);
36 return { rows: got.map((r) => ({ cause: r.cause, latest: r.sentence, days: r.days, open: r.closed_at === null })), more };
45 const rows = got.map((r) => ({ cause: r.cause, latest: r.sentence, days: r.days, open: r.closed_at === null, autoClosedAt: r.swept_at }));
46 return { rows, autoClosed: autoClosedCauses(db).length, more };
3747 }
3848
39 interface SpanRow { cause: string; sentence: string; href: string; closed_at: number | null; days: number; total: number }
49 interface SpanRow { cause: string; sentence: string; href: string; closed_at: number | null; swept_at: number | null; days: number; total: number }
4050
4151 /** The one query behind every reading of the findings: the board, the terminal and the JSON. */
4252 function latestSpans(db: Database, cap: number): { got: SpanRow[]; more: number } {
4353 const got = db
4454 .query<SpanRow, [number, number]>(
45 `SELECT s.cause, s.sentence, s.href, s.closed_at, g.days, COUNT(*) OVER () AS total
55 `SELECT s.cause, s.sentence, s.href, s.closed_at, s.swept_at, g.days, COUNT(*) OVER () AS total
4656 FROM degraded_span s
4757 JOIN (SELECT cause, MAX(id) AS last, COUNT(DISTINCT opened_at / ?1) AS days FROM degraded_span GROUP BY cause) g ON s.id = g.last
4858 ORDER BY s.opened_at DESC, s.id DESC LIMIT ?2`,
@@ -51,6 +61,46 @@ function latestSpans(db: Database, cap: number): { got: SpanRow[]; more: number
5161 return { got, more: Math.max(0, (got[0]?.total ?? 0) - got.length) };
5262 }
5363
64 /**
65 * The maintenance tick's sweep: a cause whose newest span is open and has stood `AUTO_CLOSE_DAYS`
66 * since it opened or was last reopened is marked closed. Returns the causes it closed.
67 */
68 export function autoClose(db: Database, now: number): string[] {
69 return db
70 .query<{ cause: string }, [number, number]>(
71 `UPDATE degraded_span SET swept_at = ?1
72 WHERE closed_at IS NULL AND swept_at IS NULL AND COALESCE(clock_at, opened_at) <= ?2
73 RETURNING cause`,
74 )
75 .all(now, now - AUTO_CLOSE_DAYS * DAY_MS)
76 .map((r) => r.cause);
77 }
78
79 /** The causes the tick closed and nobody has reopened, newest first: the terminal numbers them. */
80 export function autoClosedCauses(db: Database): string[] {
81 return db
82 .query<{ cause: string }, []>(
83 `SELECT cause FROM degraded_span WHERE swept_at IS NOT NULL
84 GROUP BY cause ORDER BY MAX(opened_at) DESC, MAX(id) DESC`,

Non-blocking: this groups all spans of a cause, so an old swept span keeps the cause listed after a newer span opened. Join on the newest span (MAX(id)) as latestSpans does.

85 )
86 .all()
87 .map((r) => r.cause);
88 }
89
90 /** Reopen an auto-closed finding: it stands again and its 14 days begin now. */
91 export function reopenFinding(db: Database, cause: string, now: number): boolean {
92 return (
93 db
94 .query<{ id: number }, [string, number]>(
95 "UPDATE degraded_span SET swept_at = NULL, clock_at = ?2 WHERE cause = ?1 AND swept_at IS NOT NULL RETURNING id",
96 )
97 .all(cause, now).length > 0
98 );
99 }
100
101 /** The date an auto-closed finding was closed, "2026-11-20". */
102 export const closedDate = (ms: number): string => new Date(ms).toISOString().slice(0, 10);
103
54104 /** One finding for an agent: what degraded, how bad, in one line, and the one place to act. */
55105 export interface FindingJson {
56106 /** The watcher that raised it: the degraded cause's name. */
@@ -68,7 +118,7 @@ export function findingsJson(db: Database): { findings: FindingJson[] } {
68118 return {
69119 findings: latestSpans(db, FINDING_ROWS).got.map((r) => ({
70120 duty: r.cause,
71 severity: r.closed_at === null ? "degraded" : "cleared",
121 severity: r.closed_at === null && r.swept_at === null ? "degraded" : "cleared",
72122 cause: r.sentence,
73123 action: r.href,
74124 })),
@@ -85,7 +135,7 @@ export function findingLines(db: Database): string[] {
85135 return [
86136 "",
87137 "Findings (what degraded, latest reading):",
88 ...rows.map((r) => `${r.cause}: ${r.latest} (${seenWords(r.days)}${r.open ? "; still open" : ""})`),
138 ...rows.map((r) => `${r.cause}: ${r.latest} (${seenWords(r.days)}${r.autoClosedAt !== null ? `; closed ${closedDate(r.autoClosedAt)}: ${AUTO_CLOSE_NOTE}` : r.open ? "; still open" : ""})`),
89139 ...(more > 0 ? [`And ${String(more)} more, older causes, not listed.`] : []),
90140 ];
91141 }
src/tui/screens/maintenance.ts +12 −2
@@ -8,7 +8,7 @@
88 */
99
1010 import { filedText } from "../../maintenance/filed.ts";
11 import { findingLines } from "../../maintenance/findings.ts";
11 import { autoClosedCauses, findingLines, reopenFinding } from "../../maintenance/findings.ts";
1212 import { LEVEL_WORDS, nextLevel, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts";
1313 import { dutyStates } from "../../maintain/pause.ts";
1414 import { duties, quietLine, splitDuties } from "../../maintenance/duties.ts";
@@ -180,6 +180,14 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
180180 learnLive();
181181 };
182182
183 /**
184 * Reopen the numbered auto-closed finding: the page's button, through the same `reopenFinding`.
185 */
186 const doReopen = (i: number): void => {
187 const cause = autoClosedCauses(f.app.db)[i];
188 say(cause !== undefined && reopenFinding(f.app.db, cause, Date.now()) ? `Reopened ${cause}.` : "That finding is not closed.");
189 };
190
183191 /**
184192 * Ask the stalled pull whether it is still wanted: the page's button, through the same `nudge`.
185193 */
@@ -202,7 +210,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
202210 ? [binding(["p"], "prepare for maintenance")]
203211 : [binding(["c"], "check again, retake the backup"), binding(["e"], "end maintenance")]),
204212 ...(!mayAct() || busy || stalledNow(f.db, new Date()) === undefined ? [] : [binding(["a"], "ask the stalled pull: still wanted?")]),
205 ...(!mayAct() || busy ? [] : [...(live.length > 0 ? [binding(["z"], "quiet a finding for a day")] : []), ...(quieted(f.app.db).length > 0 ? [binding(["b"], "bring a quieted finding back")] : [])]),
213 ...(!mayAct() || busy ? [] : [...(live.length > 0 ? [binding(["z"], "quiet a finding for a day")] : []), ...(quieted(f.app.db).length > 0 ? [binding(["b"], "bring a quieted finding back")] : []), ...(autoClosedCauses(f.app.db).length > 0 ? [binding(["o"], "reopen a finding closed for want of action")] : [])]),
206214 binding(["enter", "esc", "q"], "close"),
207215 ];
208216 },
@@ -214,6 +222,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
214222 ...(level === undefined ? [] : [`Showing: ${LEVEL_WORDS[level]}`, ""]),
215223 ...maintenanceLines(f, standby, level),
216224 // The numbered findings wait on a person, so the calm view leaves them out.
225 ...(level === "needs-you" ? [] : autoClosedCauses(f.app.db).flatMap((c, i) => [...(i === 0 ? ["", "Closed for want of action (o reopens one):"] : []), ...wrap(`${String(i + 1)}. ${c}`, INNER)])),
217226 ...(live.length === 0 || level === "fyi" ? [] : ["", "Findings (z quiets one):", ...live.flatMap((l, i) => wrap(`${String(i + 1)}. ${l.label} (${l.kind})`, INNER))]),
218227 ],
219228 actions: [{ label: "Close" }],
@@ -235,6 +244,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
235244 else if (e.key === "c" && !idle) doPrepare("");
236245 else if (e.key === "e" && !idle) ctx.push(askEnd());
237246 else if (e.key === "z" && live.length > 0) ctx.push(askNumber("Quiet a finding", "Number of the finding, quieted for a day", live.length, (i) => live[i] && doQuiet(live[i]!)));
247 else if (e.key === "o" && autoClosedCauses(f.app.db).length > 0) ctx.push(askNumber("Reopen a finding", "Number under closed for want of action", autoClosedCauses(f.app.db).length, doReopen));
238248 else if (e.key === "b" && quieted(f.app.db).length > 0) ctx.push(askNumber("Bring a finding back", "Number under quieted", quieted(f.app.db).length, doBringBack));
239249 return true;
240250 },
src/web/pages/maintenance.ts +18 −4
@@ -11,7 +11,7 @@ import { dutyStates, switchDuty } from "../../maintain/pause.ts";
1111 import { DISMISS_DAYS, REASON_MAX, dismiss, dismissals, dismissalWords } from "../../maintain/dismiss.ts";
1212 import { duties, quietLine, splitDuties } from "../../maintenance/duties.ts";
1313 import { LEVELS, LEVEL_WORDS, dutiesLevel, levelOf, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts";
14 import { findingRows, findingsJson, seenWords } from "../../maintenance/findings.ts";
14 import { AUTO_CLOSE_NOTE, closedDate, findingRows, findingsJson, reopenFinding, seenWords } from "../../maintenance/findings.ts";
1515 import { NOTHING_FILED, filedPieces } from "../../maintenance/filed.ts";
1616 import { stalledStep } from "../../maintenance/stalled.ts";
1717 import { statusWithStandby } from "../../maintenance/standby.ts";
@@ -53,11 +53,12 @@ const plural = (n: number, one: string, many: string): string => `${String(n)} $
5353 * nothing when none. Open when a cause is still open, which each row says once.
5454 */
5555 function findingsFold(db: Parameters<typeof findingRows>[0]): Html {
56 const { rows, more } = findingRows(db);
56 const { rows, more, autoClosed } = findingRows(db);
5757 if (rows.length === 0) return html``;
58 return fold("maintenance-findings", "Findings", String(rows.length + more), rows.some((r) => r.open),
58 const count = `${String(rows.length + more)}${autoClosed > 0 ? `, ${String(autoClosed)} auto-closed` : ""}`;
59 return fold("maintenance-findings", "Findings", count, rows.some((r) => r.open && r.autoClosedAt === null),
5960 html`<dl id="maintenance-findings-rows" class="status-rows">${rows.map(
60 (r) => statusRow(r.cause, html`<span data-finding="${r.cause}">${r.latest}</span> <span class="muted">${seenWords(r.days)}${r.open ? "; still open" : ""}</span>`),
61 (r) => statusRow(r.cause, html`<span data-finding="${r.cause}">${r.latest}</span> <span class="muted">${seenWords(r.days)}${r.autoClosedAt !== null ? html`; closed ${closedDate(r.autoClosedAt)}: ${AUTO_CLOSE_NOTE}` : r.open ? "; still open" : ""}</span>${r.autoClosedAt !== null ? html` <form method="post" action="/maintenance/findings/reopen" class="inline"><input type="hidden" name="cause" value="${r.cause}">${btn("Reopen", { variant: "ghost", size: "sm" })}</form>` : null}`),
outdated

Principles 1 and 8: 'came back N times' was not asked for and crowds the row. Remove it, or justify it. Also the inline form with class inline is hand-rolled markup, so check it against the named components in docs/DESIGN.md.

6162 )}${more > 0 ? statusRow(`And ${String(more)} more`, html`<span class="muted">older causes, not listed</span>`) : html``}</dl>`);
6263 }
6364
@@ -310,6 +311,19 @@ export async function maintenanceQuiet(ctx: Ctx): Promise<Response> {
310311 return flashTo(ctx, "/maintenance", r.ok ? { message: r.says } : { tone: "danger", message: r.says });
311312 }
312313
314 /**
315 * POST /maintenance/findings/reopen (field cause): an auto-closed finding stands again, one tap.
316 */
317 export async function maintenanceReopen(ctx: Ctx): Promise<Response> {

Both doors: Reopen has no terminal equivalent. Add a src/tui/ screen entry plus docs/features/<name>.md, with a test.

318 const denied = mayQuiet(ctx);
319 if (denied) return denied;
320 const form = await readForm(ctx, "admin");
321 if (form instanceof Response) return form;
322 const cause = formField(form, "cause");
323 const ok = cause.length > 0 && cause.length <= 200 && reopenFinding(ctx.app.db, cause, Date.now());
324 return flashTo(ctx, "/maintenance", ok ? { message: `Reopened ${cause}.` } : { tone: "danger", message: "That finding is not closed." });
325 }
326
313327 /** POST /maintenance/unquiet (fields kind, key): undo a quiet now, receipted. */
314328 export async function maintenanceUnquiet(ctx: Ctx): Promise<Response> {
315329 const denied = mayQuiet(ctx);
test/maintenance-autoclose.test.ts added +86
@@ -0,0 +1,86 @@
1 /**
2 * A finding with no action for 14 days closes itself with a note, and reopens in one tap (#15982).
3 */
4 import { afterAll, beforeAll, expect, test } from "bun:test";
5 import { Database } from "bun:sqlite";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { serve, type Servers } from "../src/http/server.ts";
11 import { AUTO_CLOSE_NOTE, autoClose, closedDate, findingLines, findingRows, reopenFinding } from "../src/maintenance/findings.ts";
12 import { adminCookie } from "./helpers/admin.ts";
13 import { quietLogs } from "./helpers/globals.ts";
14
15 quietLogs();
16 const DAY = 86_400_000;
17 const T0 = Date.parse("2026-11-01T12:00:00.000Z");
18
19 function seed(): Database {
20 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)");
22 return db;
23 }
24 const add = (db: Database, cause: string, at: number, closedAt: number | null = null): void => {
25 db.query("INSERT INTO degraded_span (cause, sentence, href, opened_at, closed_at) VALUES (?1, 'x', '/system', ?2, ?3)").run(cause, at, closedAt);
26 };
27
28 test("day 13 stands, day 14 closes with the note, and the sweep says it once", () => {
29 const db = seed();
30 add(db, "disk-free", T0);
31 expect(autoClose(db, T0 + 13 * DAY)).toEqual([]);
32 expect(findingRows(db).rows[0]!.autoClosedAt).toBeNull();
33 expect(autoClose(db, T0 + 14 * DAY)).toEqual(["disk-free"]);
34 const f = findingRows(db);
35 expect(f.autoClosed).toBe(1);
36 expect(f.rows[0]!.autoClosedAt).toBe(T0 + 14 * DAY);
37 expect(findingLines(db).join("\n")).toContain(`closed 2026-11-15: ${AUTO_CLOSE_NOTE}`);
38 expect(autoClose(db, T0 + 15 * DAY)).toEqual([]);
39 });
40
41 test("a reopened finding stands again and its 14 days begin at the reopening", () => {
42 const db = seed();
43 add(db, "disk-free", T0);
44 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);
47 expect(findingRows(db).autoClosed).toBe(0);
48 expect(autoClose(db, T0 + 29 * DAY)).toEqual([]); // day 13 after reopening
49 expect(autoClose(db, T0 + 30 * DAY)).toEqual(["disk-free"]);
50 });
51
52 test("the summary counts every auto-closed cause, past the listed rows", () => {
53 const db = seed();
54 for (let i = 0; i < 22; i++) add(db, `cause-${String(i)}`, T0 + i);
55 autoClose(db, T0 + 14 * DAY + 100);
56 const f = findingRows(db);
57 expect(f.rows.length).toBe(20);
58 expect(f.autoClosed).toBe(22);
59 });
60
61 let dir = "", app: App, servers: Servers, cookie = "";
62 beforeAll(async () => {
63 dir = await mkdtemp(join(tmpdir(), "forge-autoclose-"));
64 app = createApp({ dataDir: dir, port: 0 });
65 servers = await serve(app);
66 cookie = await adminCookie(app, { username: "boss", email: "[email protected]", password: "a-good-passphrase" });
67 });
68 afterAll(async () => { await servers.stop(); await rm(dir, { recursive: true, force: true }); });
69
70 test("the page shows the closing with its date and a Reopen button; the summary counts it; one tap reopens", async () => {
71 const t = Date.now() - 20 * DAY;
72 add(app.db, "disk-free", t);
73 autoClose(app.db, Date.now());
74 const page = await (await fetch(`${servers.url}/maintenance`, { headers: { cookie } })).text();
75 expect(page).toContain(AUTO_CLOSE_NOTE);
76 expect(page).toContain(closedDate(findingRows(app.db).rows[0]!.autoClosedAt!));
77 expect(page).toContain("1 auto-closed");
78 expect(page).toContain('action="/maintenance/findings/reopen"');
79 const res = await fetch(`${servers.url}/maintenance/findings/reopen`, {
80 method: "POST", redirect: "manual",
81 headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
82 body: new URLSearchParams({ cause: "disk-free" }),
83 });
84 expect(res.status).toBe(303);
85 expect(findingRows(app.db).autoClosed).toBe(0);
86 });
test/maintenance-findings.test.ts +3 −3
@@ -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)");
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)");
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", days: 3, open: true });
29 expect(rows.find((r) => r.cause === "disk-free")).toEqual({ cause: "disk-free", latest: "5 GiB", days: 1, open: false });
28 expect(mem).toEqual({ cause: "memory-growth", latest: "50 MiB", days: 3, open: true, autoClosedAt: null });
29 expect(rows.find((r) => r.cause === "disk-free")).toEqual({ cause: "disk-free", latest: "5 GiB", days: 1, open: false, autoClosedAt: null });
3030 expect(seenWords(3)).toBe("seen 3 days");
3131 expect(seenWords(1)).toBe("seen 1 day");
3232 });
test/tui-maintenance-reopen.test.ts added +43
@@ -0,0 +1,43 @@
1 /**
2 * The terminal's maintenance screen reopens an auto-closed finding with o, as the page's button
3 * does (#15982).
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createUser, type User } from "../src/core/users.ts";
11 import { autoClose, findingRows } from "../src/maintenance/findings.ts";
12 import { openMaintenance } from "./helpers/tui-maintenance.ts";
13 import { quietLogs } from "./helpers/globals.ts";
14 import { settleUntil } from "./helpers/tui.ts";
15
16 quietLogs();
17 let dir = "", app: App, admin: User;
18
19 beforeAll(async () => {
20 dir = await mkdtemp(join(tmpdir(), "forge-tui-reopen-"));
21 app = createApp({ dataDir: dir, port: 0 });
22 const r = await createUser(app.db, { username: "boss", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, isAdmin: true });
23 if (!r.ok) throw new Error("user");
24 admin = r.value;
25 });
26 afterAll(async () => {
27 app.close();
28 await rm(dir, { recursive: true, force: true });
29 });
30
31 test("o lists the auto-closed findings and reopens the chosen one", async () => {
32 const opened = Date.now() - 20 * 86_400_000;
33 app.db.query("INSERT INTO degraded_span (cause, sentence, href, opened_at) VALUES ('disk-free', 'x', '/system', ?1)").run(opened);
34 autoClose(app.db, Date.now());
35 expect(findingRows(app.db).autoClosed).toBe(1);
36 const s = await openMaintenance(app, admin);
37 expect(s.text()).toContain("o reopens one");
38 await s.press("o");
39 await s.press("1");
40 await s.press("\r");
41 await settleUntil(s.tui, "Reopened disk-free.");
42 expect(findingRows(app.db).autoClosed).toBe(0);
43 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs