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

The maintenance board's quiet duties collapse into one line: N duties ran, nothing to report #13353

Merged opened this

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

Merged

scout/forge:scout/13332-the-maintenance-board-s-quiet-duties-col → main 9 commits fork 4 threads · 4 unresolved

  • Merged. scout/13332-the-maintenance-board-s-quiet-duties-col was merged into main as f192a99.

Review

Sign in to review this change.
6 files changed +86 −6
docs/features/maintenance.md +7
@@ -31,6 +31,13 @@ when it last ran (UTC), what it found ("nothing found" when it filed nothing), a
3131 overdue when now is past its last slot plus one day plus 6 hours of grace (a night may run long); one
3232 that never ran says so and gives its slot, and is not overdue.
3333
34 **Quiet duties fold.** A duty that ran on time and found nothing is quiet; `splitDuties` in
35 `src/maintenance/duties.ts` decides it from `NOTHING_FOUND`, the same constant the duty's `found` is built
36 from. On `/maintenance` the quiet ones sit behind one closed fold, "All 3 duties ran, nothing to report" (or
37 "2 other duties ran, ..." when some have rows), and list their names when opened. Never-run, overdue,
38 unfinished and finding duties keep their rows. The terminal's Maintenance screen folds them into one line
39 the same way, naming the duties. Tests: `test/maintenance-calm.test.ts`.
40
3441 **Come back.** On boot `resumeAtBoot` acts only when the host has restarted since the prepare
3542 (`/proc/sys/kernel/random/boot_id` differs from the one stored); a release roll of the process on
3643 the same host boot keeps what the admin prepared. It then lifts the hold, unpauses the crew and
src/maintenance/duties.ts +22 −2
@@ -27,17 +27,20 @@ export interface Duty {
2727 readonly says: string;
2828 }
2929
30 /** What `found` says when a duty filed nothing; the one string every door compares against. */
31 export const NOTHING_FOUND = "nothing found";
32
3033 const when = (ms: number): string => `${new Date(ms).toISOString().slice(0, 16).replace("T", " ")} UTC`;
3134
3235 const oneLine = (s: string): string => {
3336 const t = s.replace(/\s+/g, " ").trim().replace(/\.$/, "");
34 return t === "" || /^(filed|found) nothing$/i.test(t) || /^read \d+ repositor(y|ies); filed nothing$/i.test(t) ? "nothing found" : t.slice(0, 160);
37 return t === "" || /^(filed|found) nothing$/i.test(t) || /^read \d+ repositor(y|ies); filed nothing$/i.test(t) ? NOTHING_FOUND : t.slice(0, 160);
3538 };
3639
3740 export function dutyOf(name: string, slot: Slot, last: Last | undefined, now: number): Duty {
3841 if (last === undefined) {
3942 const at = `${String(slot.hour).padStart(2, "0")}:${String(slot.minute).padStart(2, "0")} UTC`;
40 return { name, lastRun: "never", found: "nothing found", overdue: false, detail: `never run; its slot is ${at} each night`, says: `${name}: never run; its slot is ${at} each night.` };
43 return { name, lastRun: "never", found: NOTHING_FOUND, overdue: false, detail: `never run; its slot is ${at} each night`, says: `${name}: never run; its slot is ${at} each night.` };
4144 }
4245 const overdue = now > last.slot + DAY + GRACE_MS;
4346 const found = last.finishedAt === undefined ? "not finished" : oneLine(last.says);
@@ -56,3 +59,20 @@ export function duties(dataDir: string, now: number = Date.now()): Duty[] {
5659 dutyOf(d.name, d.slot, readLast(dataDir, d.name), now),
5760 );
5861 }
62
63 /**
64 * Duties whose last run found nothing and is on time fold away; never-run, overdue, unfinished and
65 * finding duties keep their rows. One rule for the page and the terminal.
66 */
67 export function splitDuties<T extends Pick<Duty, "found" | "overdue" | "lastRun">>(all: readonly T[]): { quiet: T[]; loud: T[] } {
68 const isQuiet = (d: T): boolean => d.found === NOTHING_FOUND && !d.overdue && d.lastRun !== "never";
69 return { quiet: all.filter(isQuiet), loud: all.filter((d) => !isQuiet(d)) };
70 }
71
72 /**
73 * The one calm sentence for the folded duties: "All 3 duties ran, ..." or "1 other duty ran, ...".
74 */
75 export function quietLine(n: number, noneLoud: boolean): string {
76 const count = `${String(n)} ${n === 1 ? "duty" : "duties"}`;
77 return noneLoud ? `All ${count} ran, nothing to report` : `${String(n)} other ${n === 1 ? "duty" : "duties"} ran, nothing to report`;
78 }
src/tui/screens/maintenance.ts +7 −2
@@ -7,7 +7,7 @@
77 * refused by the service. Enter, Esc or q closes it.
88 */
99
10 import { duties } from "../../maintenance/duties.ts";
10 import { duties, quietLine, splitDuties } from "../../maintenance/duties.ts";
1111 import { ABOUT_TO_STOP_ROWS, prepare, resumeNow, status } from "../../maintenance/service.ts";
1212 import { probeStandby, withStandby, type Standby } from "../../maintenance/standby.ts";
1313 import type { Ctx, Screen } from "../app/app.ts";
@@ -43,7 +43,12 @@ export function maintenanceLines(f: Session, standby?: Standby): string[] {
4343 ...[...last.checks].sort((a, b) => Number(a.ok) - Number(b.ok)).flatMap((c) => wrap(`${c.ok ? "ok " : "FAILED"} ${c.name}: ${c.says}`, INNER)),
4444 ]
4545 : [];
46 const dutyLines = duties(f.app.config.dataDir).flatMap((d) => wrap(d.says, INNER));
46 // Quiet duties fold into one line, as on the page; the rest keep their lines.
47 const { quiet, loud } = splitDuties(duties(f.app.config.dataDir));
48 const dutyLines = [
49 ...loud.flatMap((d) => wrap(d.says, INNER)),
50 ...(quiet.length === 0 ? [] : wrap(`${quietLine(quiet.length, loud.length === 0)}: ${quiet.map((d) => d.name).join(", ")}`, INNER)),
51 ];
4752 return [...wrap(s.says, INNER), "", ...facts, ...checks, "", ...dutyLines];
4853 }
4954
src/web/pages/maintenance.ts +4 −2
@@ -7,7 +7,7 @@
77 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
88 import { dutyStates, switchDuty } from "../../maintain/pause.ts";
99 import { DISMISS_DAYS, REASON_MAX, dismiss, dismissals, dismissalWords } from "../../maintain/dismiss.ts";
10 import { duties } from "../../maintenance/duties.ts";
10 import { duties, quietLine, splitDuties } from "../../maintenance/duties.ts";
1111 import { statusWithStandby } from "../../maintenance/standby.ts";
1212 import { ABOUT_TO_STOP_ROWS, prepare, resumeNow, status } from "../../maintenance/service.ts";
1313 import type { Ctx } from "../../http/context.ts";
@@ -56,6 +56,7 @@ export async function maintenancePage(ctx: Ctx): Promise<Response> {
5656 const rendering = performance.now();
5757 const s = await statusWithStandby(status(ctx.app));
outdated

Principle 8 (plain words) and robustness: quiet is the literal string "nothing found". Share the constant with whatever produces found, or add a boolean to the duty data.

5858 const ran = duties(ctx.app.config.dataDir);
59 const { quiet, loud } = splitDuties(ran);
5960 const dismissed = dismissals(ctx.app.db);
6061 const states = dutyStates(ctx.app.db);
6162 const mergedPending = await mergedBranches(ctx.app, new Date());
@@ -76,7 +77,8 @@ export async function maintenancePage(ctx: Ctx): Promise<Response> {
7677 <div class="form-actions mb"><form method="post" action="/maintenance/resume">${btn("End maintenance now")}</form></div>`}
7778 ${fold("maintenance-duties-fold", "Duties", `${String(ran.length)}${overdue + paused > 0 ? `, ${String(overdue + paused)} need you` : ""}`, overdue + paused > 0,
7879 html`<dl id="maintenance-duties" class="status-rows">
79 ${ran.map((d) => fact(d.name, html`${d.detail}${d.overdue ? html` ${badge("overdue", { tone: "danger" })}` : null}`))}
80 ${loud.map((d) => fact(d.name, html`${d.detail}${d.overdue ? html` ${badge("overdue", { tone: "danger" })}` : null}`))}
81 ${quiet.length === 0 ? null : disclosure(html`<span class="muted">${quietLine(quiet.length, loud.length === 0)}</span>`, html`<dl class="status-rows">${quiet.map((d) => fact(d.name, d.detail))}</dl>`, { id: "maintenance-quiet", extra: "mb" })}
8082 ${states.map((d) => {
8183 const dm = dismissed.get(d.name);
8284 const detail = dm === undefined ? d.detail : dm.active && !d.paused ? `on; ${dismissalWords(dm)}` : `${d.detail}; ${dismissalWords(dm)}`;
src/web/style/components.ts +1
@@ -817,6 +817,7 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
817817 }
818818 .disclosure[open] > summary::before { transform: rotate(90deg); }
819819 .disclosure > summary:hover { color: var(--accent); }
820 .disclosure > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius); }
820821 /* A page's "? Help" (page_help.ts): a 44px target a thumb can hit, and a ring a keyboard can see. */
821822 .disclosure[data-page-help] > summary { width: fit-content; min-width: 44px; }
822823 .disclosure[data-page-help] > summary::before { content: none; }
test/maintenance-calm.test.ts +45
@@ -8,6 +8,9 @@ import { createUser } from "../src/core/users.ts";
88 import { serve, type Servers } from "../src/http/server.ts";
99 import { dutyStates, setPaused } from "../src/maintain/pause.ts";
1010 import { needsYou } from "../src/web/pages/maintenance.ts";
11 import { NOTHING_FOUND, quietLine, splitDuties } from "../src/maintenance/duties.ts";
12 import { maintenanceLines } from "../src/tui/screens/maintenance.ts";
13 import type { Session } from "../src/tui/session.ts";
1114 import { JOBS } from "../src/nightly/jobs.ts";
1215 import { writeLast } from "../src/nightly/stamps.ts";
1316 import { quietLogs } from "./helpers/globals.ts";
@@ -98,3 +101,45 @@ test("maintenance on shows End maintenance now right under the status line", asy
98101 expect(html.indexOf('id="maintenance-duties-fold"')).toBeGreaterThan(end);
99102 expect(html).toContain("maintenance is on");
100103 });
104
105 test("quiet duties fold into one line; duties with findings keep their rows", () => {
106 const d = (name: string, found: string, over = false) => ({ name, found, overdue: over, lastRun: "2026-01-01 00:00 UTC" });
107 const quiet = splitDuties([d("a", NOTHING_FOUND), d("b", NOTHING_FOUND)]);
108 expect(quiet.quiet.length).toBe(2);
109 expect(quiet.loud.length).toBe(0);
110 expect(quietLine(2, true)).toBe("All 2 duties ran, nothing to report");
111 const one = splitDuties([d("a", "nothing found"), d("b", "filed 2 issues")]);
112 expect(one.quiet.map((x) => x.name)).toEqual(["a"]);
113 expect(one.loud.map((x) => x.name)).toEqual(["b"]);
114 expect(quietLine(1, false)).toBe("1 other duty ran, nothing to report");
115 const all = splitDuties([d("a", "filed 1"), d("b", "not finished"), d("c", "nothing found", true)]);
116 expect(all.quiet.length).toBe(0);
117 expect(all.loud.length).toBe(3);
118 });
119
120 const foldOf = (html: string): string => /<details[^>]*id="maintenance-quiet"(?![^>]*\sopen)[^>]*>([\s\S]*?)<\/details>/.exec(html)?.[1] ?? "";
121
122 test("on the page the quiet duties sit inside one closed fold and a finding duty stays outside it", async () => {
123 const now = Date.now();
outdated

This test only checks the fold exists and is closed. Assert the quiet duty name is inside the details and that a finding duty row is outside it. Add a terminal test too.

124 const [quiet, loud] = [JOBS[0]!.name, JOBS[1]!.name];
125 writeLast(dir, quiet, { slot: now, startedAt: now, finishedAt: now + 1000, says: "filed nothing" });
126 writeLast(dir, loud, { slot: now, startedAt: now, finishedAt: now + 1000, says: "filed 2 issues" });
127 const html = await get();
128 const fold = foldOf(html);
129 expect(fold).toContain("1 other duty ran, nothing to report");
130 expect(fold).toContain(`<dt>${quiet}</dt>`);
131 expect(fold).not.toContain(`<dt>${loud}</dt>`);
132 expect(html).toContain(`<dt>${loud}</dt>`);
133 expect(html).toContain("filed 2 issues");
134 });
135
136 test("the terminal folds the quiet duties into one line and keeps the finding duty's own", () => {
137 const now = Date.now();
138 const [quiet, loud] = [JOBS[0]!.name, JOBS[1]!.name];
139 writeLast(dir, quiet, { slot: now, startedAt: now, finishedAt: now + 1000, says: "filed nothing" });
140 writeLast(dir, loud, { slot: now, startedAt: now, finishedAt: now + 1000, says: "filed 2 issues" });
141 const text = maintenanceLines({ app, db: app.db, user: { isAdmin: true, kind: "human" } } as unknown as Session).join(" ");
142 expect(text).toContain("1 other duty ran, nothing to report");
143 expect(text).not.toContain(`${quiet}: last ran`);
144 expect(text).toContain(`${loud}: last ran`);
145 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs