Public: anyone can read this; the crew can change it.
/maintenance answers one question at first sight (is the forge healthy, and is anything waiting on me) and folds the rest #12717
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12692-maintenance-answers-one-question-at-firs → main 11 commits fork 2 threads · 2 unresolved
7 files
changed +203
−56
docs/features/maintenance.md +9
| @@ -16,6 +16,15 @@ | ||
| 16 | 16 | The page says plainly what stops: releases, new crew runs, then the forge, its |
| 17 | 17 | apps and previews when the host powers off. |
| 18 | 18 | |
| 19 | **The page.** `/maintenance` answers one question first: one status line, "Healthy: nothing needs you" or | |
| 20 | "Needs you" with what waits (maintenance on, a failed return, overdue or paused duties, stale pulls; `needsYou` | |
| 21 | in `src/web/pages/maintenance.ts`). Below it, each part is a `disclosure` with a count in its summary: | |
| 22 | Duties, Budgets, Prepare for a power-off (or Maintenance state while on), Last return. A fold opens by | |
| 23 | itself only when something in it needs a person. Pulls untouched for 14 days are a fold too, open, with their | |
| 24 | count, only when there are some; /system keeps them as a section under its own heading. While maintenance is | |
| 25 | on, "End maintenance now" sits under the status line. The forge's looks picture it as the owner (the slot was | |
| 26 | /repos'). Tests: `test/maintenance-calm.test.ts`, `test/maintain-stale-web.test.ts`. | |
| 27 | ||
| 19 | 28 | **Duties.** `/maintenance`, the terminal's Maintenance screen and the `duties` of MCP `maintenance {action: "status"}` |
| 20 | 29 | list each nightly job and the radar in one line (`src/maintenance/duties.ts`, one function for all three doors): |
| 21 | 30 | when it last ran (UTC), what it found ("nothing found" when it filed nothing), and "overdue". A duty is |
forge.json +2 −2
| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | "api.github.com" |
| 5 | 5 | ], |
| 6 | 6 | "app": { |
| 7 | "looks": ["/", "/front", "/explore", "/board", "/notes", "/feed", "/review", "/releases", "/apps", "/repos", "/map", "/system", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], | |
| 8 | "looksAsOwner": ["/", "/board", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/talk", "/system", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], | |
| 7 | "looks": ["/", "/front", "/explore", "/board", "/notes", "/feed", "/review", "/releases", "/apps", "/map", "/system", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], | |
| 8 | "looksAsOwner": ["/", "/board", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/talk", "/system", "/maintenance", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], | |
| 9 | 9 | "run": "bun run src/main.ts", |
| 10 | 10 | "install": "", |
| 11 | 11 | "health": "/healthz", |
src/web/pages/maintenance.ts +83 −51
| @@ -13,8 +13,9 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 13 | 13 | import { notFoundPage, signInFirst } from "../chrome.ts"; |
| 14 | 14 | import { field as formField, readForm } from "../form.ts"; |
| 15 | 15 | import { html, type Html } from "../html.ts"; |
| 16 | import { icon } from "../icons.ts"; | |
| 16 | 17 | import { flashTo, page } from "../layout.ts"; |
| 17 | import { badge, btn, field } from "../ui.ts"; | |
| 18 | import { badge, btn, disclosure, field } from "../ui.ts"; | |
| 18 | 19 | import { STALE_DAYS, STALE_WORDS, closeStale, nudge, stalePulls } from "../../maintain/stale_pulls.ts"; |
| 19 | 20 | import { budgetOfRow } from "./maintenance_budgets.ts"; |
| 20 | 21 | |
| @@ -27,52 +28,85 @@ function admin(ctx: Ctx): Response | undefined { | ||
| 27 | 28 | /** One fact of the page: what it is and how it stands, as a `dl` row. */ |
| 28 | 29 | const fact = (label: string, value: Html | string): Html => html`<div class="status-row"><dt>${label}</dt><dd>${value}</dd></div>`; |
| 29 | 30 | |
| 31 | /** A folded section: a count in its summary, open only when something in it needs a person. */ | |
| 32 | const fold = (id: string, title: string, count: string, open: boolean, body: Html): Html => | |
| 33 | disclosure(html`${title} <span class="muted">${count}</span>`, body, { id, extra: "mb", open }); | |
| 34 | ||
| 35 | const plural = (n: number, one: string, many: string): string => `${String(n)} ${n === 1 ? one : many}`; | |
| 36 | ||
| 37 | /** What waits on a person, in words; empty when nothing does. Plain data in, plain data out. */ | |
| 38 | export function needsYou(o: { phase: string; healthy?: boolean; overdue: number; paused: number; stale: number }): string[] { | |
| 39 | const out: string[] = []; | |
| 40 | if (o.phase !== "idle") out.push("maintenance is on"); | |
| 41 | if (o.healthy === false) out.push("the last return failed a check"); | |
| 42 | if (o.overdue > 0) out.push(plural(o.overdue, "duty overdue", "duties overdue")); | |
| 43 | if (o.paused > 0) out.push(plural(o.paused, "duty paused", "duties paused")); | |
| 44 | if (o.stale > 0) out.push(plural(o.stale, "stale pull", "stale pulls")); | |
| 45 | return out; | |
| 46 | } | |
| 47 | ||
| 30 | 48 | export async function maintenancePage(ctx: Ctx): Promise<Response> { |
| 31 | 49 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 32 | 50 | const denied = admin(ctx); |
| 33 | 51 | if (denied) return denied; |
| 34 | 52 | const rendering = performance.now(); |
| 35 | 53 | const s = await statusWithStandby(status(ctx.app)); |
| 54 | const ran = duties(ctx.app.config.dataDir); | |
| 55 | const states = dutyStates(ctx.app.db); | |
| 56 | const stalePending = stalePulls(ctx.app.db, new Date()); | |
| 57 | const stale = stalePending.length; | |
| 58 | const overdue = ran.filter((d) => d.overdue).length; | |
| 59 | const paused = states.filter((d) => d.paused).length; | |
| 60 | const waiting = needsYou({ phase: s.phase, ...(s.healthy === undefined ? {} : { healthy: s.healthy }), overdue, paused, stale }); | |
| 61 | const idle = s.phase === "idle"; | |
| 62 | const statusLine = waiting.length === 0 | |
| 63 | ? html`<p id="maintenance-status" class="mb" data-state="healthy">${icon("check")} <strong>Healthy</strong> <span class="muted">Nothing needs you.</span></p>` | |
| 64 | : html`<p id="maintenance-status" class="mb" data-state="needs-you">${icon("alert")} <strong>Needs you</strong> <span class="muted">${waiting.join("; ")}.</span></p>`; | |
| 36 | 65 | const body = html`<div class="page-head"><h1>Maintenance</h1></div> |
| 37 | <p id="maintenance-says">${s.says}</p> | |
| 38 | <dl id="maintenance-duties" class="status-rows"> | |
| 39 | ${duties(ctx.app.config.dataDir).map((d) => fact(d.name, html`${d.detail}${d.overdue ? html` ${badge("overdue", { tone: "danger" })}` : null}`))} | |
| 40 | ${dutyStates(ctx.app.db).map((d) => | |
| 41 | html`${fact(d.name, html`${d.detail} | |
| 42 | <form method="post" action="/maintenance/duties/${d.name}" class="inline"> | |
| 43 | <input type="hidden" name="paused" value="${d.paused ? "no" : "yes"}">${btn(d.paused ? "Resume" : "Pause", { variant: "outline" })} | |
| 44 | </form>`)}${budgetOfRow(ctx.app, d.name)}`, | |
| 45 | )} | |
| 46 | </dl> | |
| 47 | ${stalePullsSection(ctx, ctx.auth.user!.kind !== "agent")} | |
| 48 | ${s.phase === "idle" ? html`<p id="maintenance-standby" class="muted">${s.standby.says}</p>` : null} | |
| 49 | ${s.phase === "idle" | |
| 50 | ? html`<p class="muted">Get the forge ready for a planned power-off. What stops:</p> | |
| 51 | <dl class="status-rows">${ABOUT_TO_STOP_ROWS.map((r) => fact(r.what, r.stops))}</dl> | |
| 52 | <form method="post" action="/maintenance/prepare" class="stack"> | |
| 53 | ${field({ name: "reason", label: "Shown to visitors (optional)", maxlength: 200, autocomplete: "off" })} | |
| 54 | ${field({ name: "confirm", type: "checkbox", value: "yes", required: true, label: "I understand the crew and releases stop now" })} | |
| 55 | <div class="form-actions">${btn("Prepare for maintenance", { variant: "danger" })}</div> | |
| 56 | </form> | |
| 57 | ${s.last | |
| 58 | ? html`<p id="maintenance-last" class="muted">${s.last.says}</p> | |
| 59 | ${s.last.checks | |
| 60 | ? html`<dl id="maintenance-checks" class="status-rows"> | |
| 61 | ${s.last.checks.map((c) => | |
| 62 | fact(c.name, html`${c.ok ? badge("ok", { tone: "success" }) : badge("FAILED", { tone: "danger", icon: "x" })} ${c.says}`), | |
| 63 | )} | |
| 64 | </dl>` | |
| 65 | : html`<ul id="maintenance-checks" class="muted">${s.last.verified.map((v) => html`<li>${v}</li>`)}</ul>`}` | |
| 66 | : null}` | |
| 67 | : html`<dl class="status-rows"> | |
| 66 | ${statusLine} | |
| 67 | ${idle ? null : html`<p id="maintenance-says" class="muted">${s.says}</p> | |
| 68 | <div class="form-actions mb"><form method="post" action="/maintenance/resume">${btn("End maintenance now")}</form></div>`} | |
| 69 | ${fold("maintenance-duties-fold", "Duties", `${String(ran.length)}${overdue + paused > 0 ? `, ${String(overdue + paused)} need you` : ""}`, overdue + paused > 0, | |
| 70 | html`<dl id="maintenance-duties" class="status-rows"> | |
| 71 | ${ran.map((d) => fact(d.name, html`${d.detail}${d.overdue ? html` ${badge("overdue", { tone: "danger" })}` : null}`))} | |
| 72 | ${states.map((d) => | |
| 73 | fact(d.name, html`${d.detail} | |
| 74 | <form method="post" action="/maintenance/duties/${d.name}" class="inline"> | |
| 75 | <input type="hidden" name="paused" value="${d.paused ? "no" : "yes"}">${btn(d.paused ? "Resume" : "Pause", { variant: "outline" })} | |
| 76 | </form>`), | |
| 77 | )} | |
| 78 | </dl>`)} | |
| 79 | ${fold("maintenance-budgets", "Budgets", String(states.length), false, html`<dl class="status-rows">${states.map((d) => budgetOfRow(ctx.app, d.name))}</dl>`)} | |
| 80 | ${stale > 0 | |
| 81 | ? fold("stale-pulls", `Pulls untouched for ${String(STALE_DAYS)} days`, String(stale), true, staleRows(ctx.auth.user!.kind !== "agent", stalePending)) | |
| 82 | : null} | |
| 83 | ${idle | |
| 84 | ? fold("maintenance-prepare", "Prepare for a power-off", `${String(ABOUT_TO_STOP_ROWS.length)} things stop`, false, | |
| 85 | html`<p id="maintenance-standby" class="muted">${s.standby.says}</p> | |
| 86 | <dl class="status-rows">${ABOUT_TO_STOP_ROWS.map((r) => fact(r.what, r.stops))}</dl> | |
| 87 | <form method="post" action="/maintenance/prepare" class="stack"> | |
| 88 | ${field({ name: "reason", label: "Shown to visitors (optional)", maxlength: 200, autocomplete: "off" })} | |
| 89 | ${field({ name: "confirm", type: "checkbox", value: "yes", required: true, label: "I understand the crew and releases stop now" })} | |
| 90 | <div class="form-actions">${btn("Prepare for maintenance", { variant: "danger" })}</div> | |
| 91 | </form>`) | |
| 92 | : fold("maintenance-state", "Maintenance state", `${String(s.working)} still working`, true, | |
| 93 | html`<dl class="status-rows"> | |
| 68 | 94 | ${s.phase === "ready" ? null : fact("Standby", s.standby.says)} |
| 69 | 95 | ${fact("Since", s.since ?? "")} ${s.reason ? fact("Reason", s.reason) : null} |
| 70 | 96 | ${fact("Backup", s.backup?.says ?? "")} ${fact("Still working", String(s.working))} |
| 71 | 97 | </dl> |
| 72 | <div class="form-actions"> | |
| 73 | <form method="post" action="/maintenance/prepare">${btn("Check again and retake the backup", { variant: "outline" })}</form> | |
| 74 | <form method="post" action="/maintenance/resume">${btn("End maintenance now")}</form> | |
| 75 | </div>`}`; | |
| 98 | <div class="form-actions"><form method="post" action="/maintenance/prepare">${btn("Check again and retake the backup", { variant: "outline" })}</form></div>`)} | |
| 99 | ${idle && s.last | |
| 100 | ? fold("maintenance-return", "Last return", s.healthy === false ? "failed" : "ok", s.healthy === false, | |
| 101 | html`<p id="maintenance-last" class="muted">${s.last.says}</p> | |
| 102 | ${s.last.checks | |
| 103 | ? html`<dl id="maintenance-checks" class="status-rows"> | |
| 104 | ${s.last.checks.map((c) => | |
| 105 | fact(c.name, html`${c.ok ? badge("ok", { tone: "success" }) : badge("FAILED", { tone: "danger", icon: "x" })} ${c.says}`), | |
| 106 | )} | |
| 107 | </dl>` | |
| 108 | : html`<ul id="maintenance-checks" class="muted">${s.last.verified.map((v) => html`<li>${v}</li>`)}</ul>`}`) | |
| 109 | : null}`; | |
| 76 | 110 | const response = page({ ctx, title: "Maintenance", body }); |
| 77 | 111 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 78 | 112 | return response; |
| @@ -110,24 +144,22 @@ export async function maintenanceDuty(ctx: Ctx): Promise<Response> { | ||
| 110 | 144 | return flashTo(ctx, "/maintenance", r.ok ? { message: r.says } : { tone: "danger", message: r.says }); |
| 111 | 145 | } |
| 112 | 146 | |
| 113 | /** | |
| 114 | * The section: one row per stale pull with its age; the buttons only for a forge admin who is a | |
| 115 | * person. | |
| 116 | */ | |
| 117 | export function stalePullsSection(ctx: Ctx, withActions: boolean): Html { | |
| 118 | const pulls = stalePulls(ctx.app.db, new Date()); | |
| 147 | /** The stale pulls as rows with their age; the buttons only for a forge admin who is a person. */ | |
| 148 | function staleRows(withActions: boolean, pulls: ReturnType<typeof stalePulls>): Html { | |
| 119 | 149 | const form = (id: string, what: "nudge" | "close", label: string): Html => |
| 120 | 150 | html`<form method="post" action="/maintenance/stale/${id}/${what}" class="inline">${btn(label, { variant: "outline" })}</form>`; |
| 151 | if (pulls.length === 0) return html`<p class="muted">None.</p>`; | |
| 152 | return html`<dl class="status-rows">${pulls.map( | |
| 153 | (p) => html`<div class="status-row" data-pull="${p.repo}#${String(p.number)}"><dt><a href="/${p.repo}/pulls/${String(p.number)}">${p.repo}#${String(p.number)}</a></dt> | |
| 154 | <dd>${p.title} <span class="muted">${String(p.ageDays)} days</span> | |
| 155 | ${withActions ? html`${form(p.id, "nudge", "Ask")}${p.byAgent ? form(p.id, "close", "Close") : null}` : null}</dd></div>`, | |
| 156 | )}</dl>`; | |
| 157 | } | |
| 158 | ||
| 159 | /** The section with its own heading, for /system; /maintenance folds the same rows with a count. */ | |
| 160 | export function stalePullsSection(ctx: Ctx, withActions: boolean): Html { | |
| 121 | 161 | return html`<section class="settings-block" id="stale-pulls"><h2>Pulls untouched for ${String(STALE_DAYS)} days</h2> |
| 122 | ${pulls.length === 0 | |
| 123 | ? html`<p class="muted">None.</p>` | |
| 124 | : html`<dl class="status-rows">${pulls.map( | |
| 125 | (p) => html`<div class="status-row" data-pull="${p.repo}#${String(p.number)}"><dt><a href="/${p.repo}/pulls/${String(p.number)}">${p.repo}#${String(p.number)}</a></dt> | |
| 126 | <dd>${p.title} <span class="muted">${String(p.ageDays)} days</span> | |
| 127 | ${withActions | |
| 128 | ? html`${form(p.id, "nudge", "Ask")}${p.byAgent ? form(p.id, "close", "Close") : null}` | |
| 129 | : null}</dd></div>`, | |
| 130 | )}</dl>`}</section>`; | |
| 162 | ${staleRows(withActions, stalePulls(ctx.app.db, new Date()))}</section>`; | |
| 131 | 163 | } |
| 132 | 164 | |
| 133 | 165 | /** |
src/web/ui.ts +3 −1
| @@ -955,11 +955,13 @@ export interface DisclosureOptions { | ||
| 955 | 955 | extra?: string; |
| 956 | 956 | /** The `<details>`'s id, for a script or a link that finds it. */ |
| 957 | 957 | id?: string; |
| 958 | /** Open on first paint, for a body that holds something waiting on a person. */ | |
| 959 | open?: boolean; | |
| 958 | 960 | } |
| 959 | 961 | |
| 960 | 962 | /** What a person sometimes needs, closed until asked for: a quiet chevron summary over its body. */ |
| 961 | 963 | export function disclosure(summary: Html | string, body: Html | string, o: DisclosureOptions = {}): Html { |
| 962 | return html`<details${o.id ? html` id="${o.id}"` : null} class="disclosure${o.extra ? ` ${o.extra}` : ""}"> | |
| 964 | return html`<details${o.id ? html` id="${o.id}"` : null} class="disclosure${o.extra ? ` ${o.extra}` : ""}"${o.open ? html` open` : null}> | |
| 963 | 965 | <summary${o.small ? html` class="muted small"` : null}${o.label ? html` aria-label="${o.label}"` : null}>${summary}</summary> |
| 964 | 966 | ${body} |
| 965 | 967 | </details>`; |
test/forge-looks.test.ts +2 −2
| @@ -50,7 +50,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 50 | 50 | "/sw.js": "the service worker script", |
| 51 | 51 | "/offline": "the static fallback the service worker keeps for an unreachable forge", |
| 52 | 52 | "/audit.csv": "a CSV download of /audit", |
| 53 | "/maintenance": "no picture: the cap of 24 looks is spent; an admin's page, covered by test/maintenance.test.ts", | |
| 53 | "/repos": "the list of repositories, a table; its slot went to /maintenance, the admin's health page (#12692); covered by its own tests", | |
| 54 | 54 | "/claim": "answers 404 to an admin: it exists only for a link-holder", |
| 55 | 55 | "/welcome": "the account screen of a forge with no admin yet; answers 404 to an admin", |
| 56 | 56 | "/first-admin": "the setup form for a forge with no admin yet", |
| @@ -81,7 +81,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 81 | 81 | "/search": "a search box; its slot went to the preview seed's /next as its owner (#8866)", |
| 82 | 82 | "/contribute": "a static page about how to help; its slot went to the preview seed's /bets as its owner (#8866)", |
| 83 | 83 | "/privacy": "three static lines on what the forge keeps about a visitor (#11265); covered by test/visitors.test.ts", |
| 84 | "/migrate": "an import form, nothing to picture until a job runs; the look slot went to /repos", | |
| 84 | "/migrate": "an import form, nothing to picture until a job runs; its slot went to /repos, and that one to /maintenance (#12692)", | |
| 85 | 85 | }; |
| 86 | 86 | |
| 87 | 87 | let dir: string; |
test/maintain-stale-web.test.ts +4
| @@ -73,6 +73,10 @@ test("the section lists a stale pull escaped, with Ask for the admin only on /ma | ||
| 73 | 73 | const system = await (await fetch(`${servers.url}/system`, { headers: { cookie: adminCookie } })).text(); |
| 74 | 74 | expect(system).toContain("Pulls untouched for 14 days"); |
| 75 | 75 | expect(system).not.toContain("/maintenance/stale/"); |
| 76 | // On /maintenance a fold, open, its count in the summary; /system keeps its own section and h2. | |
| 77 | expect(page).toMatch(/<details id="stale-pulls" class="disclosure[^"]*" open>\s*<summary>Pulls untouched for 14 days <span class="muted">1<\/span><\/summary>/); | |
| 78 | expect(page).not.toContain("<h2>Pulls untouched"); | |
| 79 | expect(system).toContain('<section class="settings-block" id="stale-pulls"><h2>Pulls untouched for 14 days</h2>'); | |
| 76 | 80 | }); |
| 77 | 81 | |
| 78 | 82 | test("the action refuses a non-admin, a cross-origin post and a bad verb; an admin's ask comments once", async () => { |
test/maintenance-calm.test.ts added +100
| @@ -0,0 +1,100 @@ | ||
| 1 | /** /maintenance leads with one status line (healthy or needs you) and folds the rest. */ | |
Add a case for overdue/stale/failed-return opening their folds and one asserting maintenance-on shows the 'End maintenance now' action under the status line; today only paused is covered on the page. |
||
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createUser } from "../src/core/users.ts"; | |
| 8 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 9 | import { dutyStates, setPaused } from "../src/maintain/pause.ts"; | |
| 10 | import { needsYou } from "../src/web/pages/maintenance.ts"; | |
| 11 | import { JOBS } from "../src/nightly/jobs.ts"; | |
| 12 | import { writeLast } from "../src/nightly/stamps.ts"; | |
| 13 | import { quietLogs } from "./helpers/globals.ts"; | |
| 14 | ||
| 15 | quietLogs(); | |
| 16 | let dir = "", app: App, servers: Servers, cookie = ""; | |
| 17 | ||
| 18 | beforeAll(async () => { | |
| 19 | dir = await mkdtemp(join(tmpdir(), "forge-calm-")); | |
| 20 | app = createApp({ dataDir: dir, port: 0 }); | |
| 21 | servers = await serve(app); | |
| 22 | const made = await createUser(app.db, { username: "boss", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, isAdmin: true }); | |
| 23 | if (!made.ok) throw new Error("user"); | |
| 24 | const res = await fetch(`${servers.url}/signin`, { | |
| 25 | method: "POST", redirect: "manual", | |
| 26 | headers: { "content-type": "application/x-www-form-urlencoded", origin: servers.url }, | |
| 27 | body: new URLSearchParams({ username: "boss", password: "a-good-passphrase" }), | |
| 28 | }); | |
| 29 | cookie = (res.headers.get("set-cookie") ?? "").split(";")[0] ?? ""; | |
| 30 | }); | |
| 31 | afterAll(async () => { | |
| 32 | servers.stop(); | |
| 33 | app.close(); | |
| 34 | await rm(dir, { recursive: true, force: true }); | |
| 35 | }); | |
| 36 | const get = async (): Promise<string> => (await fetch(`${servers.url}/maintenance`, { headers: { cookie } })).text(); | |
| 37 | ||
| 38 | test("a quiet forge says healthy and folds everything", async () => { | |
| 39 | const html = await get(); | |
| 40 | expect(html).toContain('data-state="healthy"'); | |
| 41 | expect(html).toContain("Nothing needs you."); | |
| 42 | expect(html).not.toContain('data-state="needs-you"'); | |
| 43 | expect(html).toMatch(/<details[^>]*id="maintenance-prepare"(?![^>]*\sopen)[^>]*>/); | |
| 44 | expect(html).toMatch(/<details[^>]*id="maintenance-budgets"(?![^>]*\sopen)[^>]*>/); | |
| 45 | expect(html).toContain('action="/maintenance/prepare"'); | |
| 46 | }); | |
| 47 | ||
| 48 | test("a paused duty says needs you and opens the duties", async () => { | |
| 49 | setPaused(app.db, dutyStates(app.db)[0]!.name, true, "boss"); | |
| 50 | const html = await get(); | |
| 51 | expect(html).toContain('data-state="needs-you"'); | |
| 52 | expect(html).toContain("1 duty paused"); | |
| 53 | expect(html).toMatch(/<details[^>]*id="maintenance-duties-fold"[^>]*\sopen/); | |
| 54 | }); | |
| 55 | ||
| 56 | test("needsYou names each waiting thing", () => { | |
| 57 | expect(needsYou({ phase: "idle", overdue: 0, paused: 0, stale: 0 })).toEqual([]); | |
| 58 | expect(needsYou({ phase: "ready", healthy: false, overdue: 2, paused: 0, stale: 1 })).toEqual(["maintenance is on", "the last return failed a check", "2 duties overdue", "1 stale pull"]); | |
| 59 | }); | |
| 60 | ||
| 61 | test("every fold's summary carries a count", async () => { | |
| 62 | const html = await get(); | |
| 63 | for (const m of html.matchAll(/<details[^>]*class="disclosure[^>]*>\s*<summary[^>]*>([\s\S]*?)<\/summary>/g)) expect(m[1]).toMatch(/<span class="muted">[^<]+<\/span>/); | |
| 64 | }); | |
| 65 | ||
| 66 | test("no stale pull, no stale section on the page", async () => { | |
| 67 | const html = await get(); | |
| 68 | expect(html).not.toContain('id="stale-pulls"'); | |
| 69 | }); | |
| 70 | ||
| 71 | test("an overdue duty, on the page: named by the status line, and the duties fold opens by itself", async () => { | |
| 72 | setPaused(app.db, dutyStates(app.db)[0]!.name, false, "boss"); | |
| 73 | const before = await get(); | |
| 74 | expect(before).not.toContain("duty overdue"); | |
| 75 | const slot = Date.now() - 3 * 86_400_000; | |
| 76 | writeLast(dir, JOBS[0]!.name, { slot, startedAt: slot, finishedAt: slot + 1000, says: "filed nothing" }); | |
| 77 | const html = await get(); | |
| 78 | expect(html).toContain('data-state="needs-you"'); | |
| 79 | expect(html).toContain("1 duty overdue"); | |
| 80 | expect(html).toMatch(/<details[^>]*id="maintenance-duties-fold"[^>]*\sopen/); | |
| 81 | }); | |
| 82 | ||
| 83 | test("a failed return is named by the status line", () => { | |
| 84 | expect(needsYou({ phase: "idle", healthy: false, overdue: 1, paused: 0, stale: 0 })).toEqual(["the last return failed a check", "1 duty overdue"]); | |
| 85 | }); | |
| 86 | ||
| 87 | test("maintenance on shows End maintenance now right under the status line", async () => { | |
| 88 | await fetch(`${servers.url}/maintenance/prepare`, { | |
| 89 | method: "POST", redirect: "manual", | |
| 90 | headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" }, | |
| 91 | body: new URLSearchParams({ confirm: "yes" }), | |
| 92 | }); | |
| 93 | const html = await get(); | |
| 94 | const at = html.indexOf('id="maintenance-status"'); | |
| 95 | const end = html.indexOf('action="/maintenance/resume"'); | |
| 96 | expect(at).toBeGreaterThan(-1); | |
| 97 | expect(end).toBeGreaterThan(at); | |
| 98 | expect(html.indexOf('id="maintenance-duties-fold"')).toBeGreaterThan(end); | |
| 99 | expect(html).toContain("maintenance is on"); | |
| 100 | }); |
new above
offline
Use the
disclosurehelper from src/web/ui.ts rather than hand-rolled <details>, as DESIGN.md says. Summaries need a count every time: Prepare and Maintenance state pass an empty string. Also skip the fold for Stale pulls when the count is 0 (state the count in the status line instead), and drop the duplicate h2 inside stalePullsSection when it is wrapped (principle 1).