Public: anyone can read this; the crew can change it.
The maintenance board shows each worker's last run time and result as one row #13313
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13302-the-maintenance-board-shows-each-worker → main 4 commits fork 2 threads · 2 unresolved
7 files
changed +139
−37
docs/features/maintenance-week.md +23 −7
| @@ -1,9 +1,22 @@ | ||
| 1 | 1 | # Maintenance, last 7 days (#12436) |
| 2 | 2 | |
| 3 | 3 | One line per maintenance worker: how many things it found in the last seven |
| 4 | days, how many it acted on, and when it last ran (even if that was before the | |
| 5 | week). A worker that has never run is still a line, reading "not yet run". A | |
| 6 | run stopped by its budget is not counted as a run. | |
| 4 | days, how many it acted on, when it last ran (even if that was before the | |
| 5 | week), and how that last run went. A worker that has never run is still a line, | |
| 6 | reading "not yet run". A run stopped by its budget is not counted as a run, so | |
| 7 | it never becomes the last result or the duration. | |
| 8 | ||
| 9 | ## The result word | |
| 10 | ||
| 11 | Each line ends with one of three words, and the time the last run took: | |
| 12 | ||
| 13 | - **ok** — the last run finished without an error (`ok in 4.2 s`). | |
| 14 | - **failed** — the last run ended in an error (`failed in 340 ms`). | |
| 15 | - **parked** — the worker's switch is off. Parked wins: it is shown even when | |
| 16 | the last run was ok or failed, and then without a duration. | |
| 17 | ||
| 18 | The duration reads `340 ms`, `4.2 s` or `3 min`. A worker that never ran and is | |
| 19 | not parked has no result and reads "not yet run". | |
| 7 | 20 | |
| 8 | 21 | All three doors are for a forge admin, or an agent granted `telemetry:read`. |
| 9 | 22 | |
| @@ -11,12 +24,14 @@ All three doors are for a forge admin, or an agent granted `telemetry:read`. | ||
| 11 | 24 | |
| 12 | 25 | Under **Maintenance, last 7 days**, one sentence says how many workers found |
| 13 | 26 | something this week. Open it to see each worker's found and acted counts and |
| 14 | its last run. | |
| 27 | its last run, result word and duration. The row carries `data-result` | |
| 28 | (`ok`, `failed`, `parked`) for styling and tests. | |
| 15 | 29 | |
| 16 | 30 | ## In the terminal |
| 17 | 31 | |
| 18 | 32 | Open the palette and choose **Maintenance, last 7 days**. The first line is the |
| 19 | same sentence; below it, a line per worker. `j`/`k` scroll, `esc` closes. | |
| 33 | same sentence; below it, a line per worker, ending in the same result and | |
| 34 | duration. `j`/`k` scroll, `esc` closes. | |
| 20 | 35 | |
| 21 | 36 | ## Over MCP |
| 22 | 37 | |
| @@ -24,8 +39,9 @@ same sentence; below it, a line per worker. `j`/`k` scroll, `esc` closes. | ||
| 24 | 39 | { "name": "system", "arguments": { "kind": "maintenance" } } |
| 25 | 40 | |
| 26 | 41 | |
| 27 | answers `{ workers: [{ name, found, acted, last }] }`, `last` an ISO time or | |
| 28 | null. Anyone without the gate is refused as `forbidden`. | |
| 42 | answers `{ workers: [{ name, found, acted, last, result, ms, says }] }`: | |
| 43 | `last` an ISO time or null, `result` `ok`, `failed`, `parked` or null, `ms` the | |
| 44 | last run's milliseconds or null, and `says` the same words the page shows. Anyone without the gate is refused as `forbidden`. | |
| 29 | 45 | |
| 30 | 46 | ## Keeping it true |
| 31 | 47 |
src/http/mcp/tools/system.ts +2 −2
| @@ -13,7 +13,7 @@ import { footing, riskLines } from "../../../system/footing.ts"; | ||
| 13 | 13 | import { laneWords, readOffsiteLane } from "../../../snapshot/offsite_lane.ts"; |
| 14 | 14 | import { largestDirs } from "../../../system/largest_dirs.ts"; |
| 15 | 15 | import { dbSize } from "../../../system/db_size.ts"; |
| 16 | import { weekRows } from "../../../maintain/week_line.ts"; | |
| 16 | import { resultWords, weekRows } from "../../../maintain/week_line.ts"; | |
| 17 | 17 | import { duties } from "../../../maintain/registry.ts"; |
| 18 | 18 | import { maySwitch, setPlannerSwitch, SWITCH_REFUSED, utcAt, validUntil, type SwitchInput } from "../../../actions/planner_switch.ts"; |
| 19 | 19 | import { pauseSentence, pausedUntil } from "../../../core/planner_pause.ts"; |
| @@ -72,7 +72,7 @@ export const tool: Tool = { | ||
| 72 | 72 | const reader = telemetryReader(ctx.app, user); |
| 73 | 73 | if (!reader) return badBlocked("forbidden", noTelemetryBlocked(ctx.app, user, "Reading this forge's maintenance workers takes the telemetry:read grant.")); |
| 74 | 74 | noteRead(ctx.app, user, reader, "system"); |
| 75 | return good({ workers: weekRows(ctx.app.db, duties.map((d) => d.name)) }); | |
| 75 | return good({ workers: weekRows(ctx.app.db, duties.map((d) => d.name)).map((w) => ({ ...w, says: resultWords(w) })) }); | |
| 76 | 76 | } |
| 77 | 77 | if (args["kind"] === "footing") { |
| 78 | 78 | if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads what it stands on"); |
src/maintain/week_line.ts +37 −5
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | * when it last ran. */ |
| 3 | 3 | |
| 4 | 4 | import type { Database } from "bun:sqlite"; |
| 5 | import { errored } from "./pause.ts"; | |
| 5 | 6 | |
| 6 | 7 | export const WEEK_MS = 7 * 24 * 60 * 60 * 1000; |
| 7 | 8 | |
| @@ -13,14 +14,27 @@ export interface WorkerTally { | ||
| 13 | 14 | readonly acted: number; |
| 14 | 15 | /** The worker's newest real start (ISO), in the window or not; null when it never ran. */ |
| 15 | 16 | readonly last: string | null; |
| 17 | /** The newest real run's outcome and how long it took; null when it never ran. */ | |
| 18 | readonly outcome: string | null; | |
| 19 | readonly ms: number | null; | |
| 16 | 20 | } |
| 17 | 21 | |
| 22 | /** | |
| 23 | * The word a worker's last run gets: parked while its switch is off, failed when it did not come | |
| 24 | * out ok. | |
| 25 | */ | |
| 26 | export type Result = "ok" | "failed" | "parked"; | |
| 27 | ||
| 18 | 28 | export interface WeekRow { |
| 19 | 29 | readonly name: string; |
| 20 | 30 | readonly found: number; |
| 21 | 31 | readonly acted: number; |
| 22 | 32 | /** ISO time of the last run; null reads "not yet run". */ |
| 23 | 33 | readonly last: string | null; |
| 34 | /** The last run's result word; null only for a worker that never ran and is not parked. */ | |
| 35 | readonly result: Result | null; | |
| 36 | /** The last run's duration in milliseconds; null when it never ran. */ | |
| 37 | readonly ms: number | null; | |
| 24 | 38 | } |
| 25 | 39 | |
| 26 | 40 | /** One grouped, index-served statement: every duty's sums, a budget stop not counting as a run. */ |
| @@ -31,24 +45,42 @@ export function tallies(db: Database, now: Date): WorkerTally[] { | ||
| 31 | 45 | `SELECT duty, |
| 32 | 46 | COALESCE(SUM(CASE WHEN started >= ?1 THEN json_array_length(findings) END), 0) AS found, |
| 33 | 47 | COALESCE(SUM(CASE WHEN started >= ?1 THEN json_array_length(actions) END), 0) AS acted, |
| 34 | MAX(started) AS last | |
| 35 | FROM maintenance_run WHERE outcome NOT LIKE 'budget:%' GROUP BY duty`, | |
| 48 | MAX(started) AS last, | |
Two correlated subqueries per duty each re-find the newest run. It is fine at this size, but one lookup of the latest id per duty joined once would be cheaper and keep the grouped statement single-pass. Optional. |
||
| 49 | (SELECT r.outcome FROM maintenance_run r WHERE r.duty = m.duty AND r.outcome NOT LIKE 'budget:%' ORDER BY r.id DESC LIMIT 1) AS outcome, | |
| 50 | (SELECT CAST(ROUND((julianday(r.finished) - julianday(r.started)) * 86400000) AS INTEGER) FROM maintenance_run r | |
| 51 | WHERE r.duty = m.duty AND r.outcome NOT LIKE 'budget:%' ORDER BY r.id DESC LIMIT 1) AS ms | |
| 52 | FROM maintenance_run m WHERE outcome NOT LIKE 'budget:%' GROUP BY duty`, | |
| 36 | 53 | ) |
| 37 | 54 | .all(since) as WorkerTally[]; |
| 38 | 55 | } |
| 39 | 56 | |
| 40 | 57 | /** Pure: a row per named worker, in the given order; a worker with no run is still a row. */ |
| 41 | export function weekLine(workers: readonly string[], tally: readonly WorkerTally[]): WeekRow[] { | |
| 58 | export function weekLine(workers: readonly string[], tally: readonly WorkerTally[], parked: ReadonlySet<string> = new Set()): WeekRow[] { | |
| 42 | 59 | const by = new Map(tally.map((t) => [t.duty, t])); |
| 43 | 60 | return workers.map((name) => { |
| 44 | 61 | const t = by.get(name); |
| 45 | return { name, found: t?.found ?? 0, acted: t?.acted ?? 0, last: t?.last ?? null }; | |
| 62 | const result: Result | null = parked.has(name) ? "parked" : t?.outcome == null ? null : errored(t.outcome) ? "failed" : "ok"; | |
| 63 | return { name, found: t?.found ?? 0, acted: t?.acted ?? 0, last: t?.last ?? null, result, ms: t?.ms ?? null }; | |
| 46 | 64 | }); |
| 47 | 65 | } |
| 48 | 66 | |
| 67 | /** A duration in words that stays short: `340 ms`, `4.2 s`, `3 min`. */ | |
| 68 | export function took(ms: number): string { | |
| 69 | if (ms < 1000) return `${String(Math.max(0, Math.round(ms)))} ms`; | |
| 70 | if (ms < 60_000) return `${(ms / 1000).toFixed(1)} s`; | |
| 71 | return `${String(Math.round(ms / 60_000))} min`; | |
| 72 | } | |
| 73 | ||
| 74 | /** The row's result and duration as every door says it: `ok in 4.2 s`, `parked`, `not yet run`. */ | |
| 75 | export function resultWords(r: WeekRow): string { | |
| 76 | if (r.result === null) return "not yet run"; | |
| 77 | return r.result === "parked" || r.ms === null ? r.result : `${r.result} in ${took(r.ms)}`; | |
| 78 | } | |
| 79 | ||
| 49 | 80 | /** The rows for the forge's own workers. */ |
| 50 | 81 | export function weekRows(db: Database, workers: readonly string[], now = new Date()): WeekRow[] { |
| 51 | return weekLine(workers, tallies(db, now)); | |
| 82 | const parked = new Set((db.query("SELECT duty FROM maintenance_duty_state WHERE paused = 1").all() as { duty: string }[]).map((r) => r.duty)); | |
| 83 | return weekLine(workers, tallies(db, now), parked); | |
| 52 | 84 | } |
| 53 | 85 | |
| 54 | 86 | /** The one sentence on first view: how many workers found something this week. */ |
src/tui/screens/maintenanceweek.ts +3 −3
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | |
| 8 | 8 | import { telemetryReader } from "../../actions/telemetry.ts"; |
| 9 | 9 | import { duties } from "../../maintain/registry.ts"; |
| 10 | import { weekRows, weekWords } from "../../maintain/week_line.ts"; | |
| 10 | import { resultWords, weekRows, weekWords } from "../../maintain/week_line.ts"; | |
| 11 | 11 | import type { Ctx, Screen } from "../app/app.ts"; |
| 12 | 12 | import { binding } from "../app/keys.ts"; |
| 13 | 13 | import type { Session } from "../session.ts"; |
| @@ -28,8 +28,8 @@ export function weekLines(session: Session, now = new Date()): string[] { | ||
| 28 | 28 | "", |
| 29 | 29 | ...rows.map((r) => |
| 30 | 30 | r.last === null |
| 31 | ? `${pad(r.name, width)} not yet run` | |
| 32 | : `${pad(r.name, width)} found ${String(r.found)} · acted ${String(r.acted)} · last ${r.last.slice(0, 16).replace("T", " ")}Z`), | |
| 31 | ? `${pad(r.name, width)} ${resultWords(r)}` | |
| 32 | : `${pad(r.name, width)} found ${String(r.found)} · acted ${String(r.acted)} · last ${r.last.slice(0, 16).replace("T", " ")}Z · ${resultWords(r)}`), | |
| 33 | 33 | ]; |
| 34 | 34 | } |
| 35 | 35 |
src/web/pages/system.ts +41 −14
| @@ -63,7 +63,7 @@ import { shapeWords } from "../../engine/mode.ts"; | ||
| 63 | 63 | import { badge, chartBox, disclosure, meter, pill, row, time } from "../ui.ts"; |
| 64 | 64 | import { LARGEST_DIRS, largestDirs, type LargestDirs } from "../../system/largest_dirs.ts"; |
| 65 | 65 | import { DB_FILE_CAP, DB_GROWTH_MAX, TOP, dbSize, dbSizeNeed, type DbSize } from "../../system/db_size.ts"; |
| 66 | import { weekRows, weekWords, type WeekRow } from "../../maintain/week_line.ts"; | |
| 66 | import { resultWords, weekRows, weekWords, type WeekRow } from "../../maintain/week_line.ts"; | |
| 67 | 67 | import { duties } from "../../maintain/registry.ts"; |
| 68 | 68 | import { childDirOf, listChildren } from "../../actions/spawn.ts"; |
| 69 | 69 | import { childrenUse, mibWords, realSelf, selfUse, shareOf, sizeWords, useWords, type ChildUseRow, type SelfUse } from "../../spawn/usage.ts"; |
| @@ -94,7 +94,10 @@ const meterRow = (name: string, value: number | null, max: number, figure: strin | ||
| 94 | 94 | const figureRow = (name: string, figure: string, data: Record<string, string> = {}): Html => |
| 95 | 95 | row({ title: name, trail: html`<span class="mono">${figure}</span>`, data }); |
| 96 | 96 | |
| 97 | /** The five largest directories under the forge's data (#11800), measured at most once a minute, never waited on. */ | |
| 97 | /** | |
| 98 | * The five largest directories under the forge's data (#11800), measured at most once a minute, | |
| 99 | * never waited on. | |
| 100 | */ | |
| 98 | 101 | export function largestDirsSection(found: LargestDirs | null): Html { |
| 99 | 102 | return html`<section class="settings-block" id="sys-largest"><h2>Largest under the forge's data</h2> |
| 100 | 103 | ${found === null |
| @@ -154,13 +157,15 @@ export function maintenanceSection(rows: readonly WeekRow[]): Html { | ||
| 154 | 157 | row({ |
| 155 | 158 | title: r.name, |
| 156 | 159 | meta: html`${r.last === null ? null : html`found ${String(r.found)} · acted ${String(r.acted)}`}`, |
| 157 | trail: r.last === null ? html`<span class="muted">not yet run</span>` : time(r.last), | |
| 158 | data: { worker: r.name, found: String(r.found), acted: String(r.acted) }, | |
| 160 | trail: r.last === null ? html`<span class="muted">${resultWords(r)}</span>` : html`${time(r.last)} · ${resultWords(r)}`, | |
| 161 | data: { worker: r.name, found: String(r.found), acted: String(r.acted), result: r.result ?? "none" }, | |
| 159 | 162 | }), |
| 160 | 163 | )}</ul>`)}</section>`; |
| 161 | 164 | } |
| 162 | 165 | |
| 163 | /** This forge's own size and use when it is a child in a cell (#10853); nothing on any other forge. */ | |
| 166 | /** | |
| 167 | * This forge's own size and use when it is a child in a cell (#10853); nothing on any other forge. | |
| 168 | */ | |
| 164 | 169 | export function selfSection(self: SelfUse | null): Html { |
| 165 | 170 | if (self === null) return html``; |
| 166 | 171 | const { use, size } = self; |
| @@ -185,7 +190,10 @@ export function engineSection(choice: { mode: string; why: string } | undefined) | ||
| 185 | 190 | })}</ul></section>`; |
| 186 | 191 | } |
| 187 | 192 | |
| 188 | /** What this forge's own size section leaves to the page's `?`: who set the size and what is measured. */ | |
| 193 | /** | |
| 194 | * What this forge's own size section leaves to the page's `?`: who set the size and what is | |
| 195 | * measured. | |
| 196 | */ | |
| 189 | 197 | export const selfHelp = (self: SelfUse | null): Html | null => |
| 190 | 198 | self === null ? null : html`<p id="sys-self-help">Size is set by the forge that made this one. ${self.from === "process" ? "Memory and CPU count this process alone. " : ""}Disk is measured every 30 seconds.</p>`; |
| 191 | 199 | |
| @@ -234,7 +242,10 @@ export function inProcessSection(rows: readonly ChildHour[]): Html { | ||
| 234 | 242 | )}</ul></section>`; |
| 235 | 243 | } |
| 236 | 244 | |
| 237 | /** Processes grouped forge, crew, check, app, host; the client re-sorts them by CPU or memory (`system-live.ts`). */ | |
| 245 | /** | |
| 246 | * Processes grouped forge, crew, check, app, host; the client re-sorts them by CPU or memory | |
| 247 | * (`system-live.ts`). | |
| 248 | */ | |
| 238 | 249 | const KIND_ORDER = ["forge", "crew", "check", "app", "host"] as const; |
| 239 | 250 | function procTable(v: SystemView): Html { |
| 240 | 251 | const groups = KIND_ORDER.flatMap((k) => v.groups.filter((g) => g.kind === k)); |
| @@ -291,7 +302,10 @@ export const pageCaches = (): CacheRow[] => [ | ||
| 291 | 302 | { name: "folders and refs", holds: "folder listings at a commit, ref names (tree_cache.ts)", capBytes: PARTS_BYTES, ...keptPartsStats() }, |
| 292 | 303 | ]; |
| 293 | 304 | |
| 294 | /** `pageCaches`' rows as a table; the hit rate is hits over hits and misses since the process started. */ | |
| 305 | /** | |
| 306 | * `pageCaches`' rows as a table; the hit rate is hits over hits and misses since the process | |
| 307 | * started. | |
| 308 | */ | |
| 295 | 309 | export function cachesSection(rows: readonly CacheRow[]): Html { |
| 296 | 310 | const rate = (r: CacheRow) => (r.hits + r.misses === 0 ? "—" : `${((100 * r.hits) / (r.hits + r.misses)).toFixed(1)}%`); |
| 297 | 311 | return html`<section class="settings-block"><h2>Code page caches, since start</h2> |
| @@ -301,7 +315,10 @@ export function cachesSection(rows: readonly CacheRow[]): Html { | ||
| 301 | 315 | </table></div></section>`; |
| 302 | 316 | } |
| 303 | 317 | |
| 304 | /** Absorbed apps and whether production is serving (#9887); `featureHealth`'s rows. Nothing absorbed, nothing drawn. */ | |
| 318 | /** | |
| 319 | * Absorbed apps and whether production is serving (#9887); `featureHealth`'s rows. Nothing | |
| 320 | * absorbed, nothing drawn. | |
| 321 | */ | |
| 305 | 322 | export function featuresSection(rows: readonly FeatureHealth[]): Html { |
| 306 | 323 | if (rows.length === 0) return html``; |
| 307 | 324 | return html`<section class="settings-block" id="sys-features"><h2>Features from apps</h2> |
| @@ -371,7 +388,8 @@ export function footprintSection(f: Footprint | null): Html { | ||
| 371 | 388 | * last restore drill with where it restored from. `snapshot/offsite_lane.ts`'s reading. |
| 372 | 389 | */ |
| 373 | 390 | export function offsiteSection(l: OffsiteLane): Html { |
| 374 | // A lane that exists and is not level and sealed is red; no lane at all is a setting, said in words (first sight, #11111). | |
| 391 | // A lane that exists and is not level and sealed is red; no lane at all is a setting, said in | |
| 392 | // words (first sight, #11111). | |
| 375 | 393 | const tone = l.health === "ok" || l.health === "none" ? null : badge(l.health, { tone: "danger" }); |
| 376 | 394 | const d = l.drill; |
| 377 | 395 | // First sight (#11111): the heading and one sentence stay; the rows open behind one disclosure. |
| @@ -483,7 +501,10 @@ export function lagSection(rows: readonly LagReading[]): Html { | ||
| 483 | 501 | |
| 484 | 502 | const SLOW_TTL_MS = 5000; |
| 485 | 503 | let slowKept: { db: object; at: number; rows: SlowPage[] } | undefined; |
| 486 | /** `slowPages`, kept a few seconds so a busy /system never repeats the query; changes show on reload. */ | |
| 504 | /** | |
| 505 | * `slowPages`, kept a few seconds so a busy /system never repeats the query; changes show on | |
| 506 | * reload. | |
| 507 | */ | |
| 487 | 508 | function slowPagesCached(db: Parameters<typeof slowPages>[0]): SlowPage[] { |
| 488 | 509 | const now = Date.now(); |
| 489 | 510 | if (slowKept === undefined || slowKept.db !== db || now - slowKept.at > SLOW_TTL_MS) |
| @@ -491,14 +512,19 @@ function slowPagesCached(db: Parameters<typeof slowPages>[0]): SlowPage[] { | ||
| 491 | 512 | return slowKept.rows; |
| 492 | 513 | } |
| 493 | 514 | |
| 494 | /** Real visitors' pages over budget (#10536): one line each, and nothing at all when every page is fast. */ | |
| 515 | /** | |
| 516 | * Real visitors' pages over budget (#10536): one line each, and nothing at all when every page is | |
| 517 | * fast. | |
| 518 | */ | |
| 495 | 519 | export function slowPagesSection(rows: readonly SlowPage[]): Html { |
| 496 | 520 | if (rows.length === 0) return html``; |
| 497 | 521 | return html`<section class="settings-block" id="slow-pages"><h2>Pages over budget, last hour</h2> |
| 498 | 522 | <ul class="list" aria-label="Pages over their budget for real visitors">${rows.map((p) => html`<li data-route="${p.route}" data-phase="${p.phase}">${slowPageLine(p)}</li>`)}</ul></section>`; |
| 499 | 523 | } |
| 500 | 524 | |
| 501 | /** Who read the telemetry routes in the last 10 minutes and how fast (#9069); `readerPaces`' rows. */ | |
| 525 | /** | |
| 526 | * Who read the telemetry routes in the last 10 minutes and how fast (#9069); `readerPaces`' rows. | |
| 527 | */ | |
| 502 | 528 | export function readersSection(rows: readonly ReaderPace[]): Html { |
| 503 | 529 | const secs = (ms: number | null): string => (ms === null ? "—" : `${(ms / 1000).toFixed(1)} s`); |
| 504 | 530 | return html`<section class="settings-block"><h2>Telemetry readers</h2>${ |
| @@ -620,7 +646,8 @@ export async function systemPage(ctx: Ctx): Promise<Response> { | ||
| 620 | 646 | const inProcess = childHours(ctx.app, Date.now(), tally.hour, openChildren(ctx.app).map((c) => c.name)).filter((r) => mine.has(r.name)); |
| 621 | 647 | const nowMono = performance.now(); |
| 622 | 648 | const worst = liveOf(ctx.app).stallBlame.worst(nowMono, HOUR_MS, WORST_STALLS); |
| 623 | // Never waits on the cluster: the last reading, or the declared rows while the first read runs behind. | |
| 649 | // Never waits on the cluster: the last reading, or the declared rows while the first read runs | |
| 650 | // behind. | |
| 624 | 651 | const standsOn = footing.peek() ?? declaredFooting("the cluster is being read; reload in a moment"); |
| 625 | 652 | // Never waits on the walk: the last measurement, a new one started behind it when stale. |
| 626 | 653 | const largestUnder = largestDirs.peek(ctx.app.config.dataDir); |
test/maintain-week-line.test.ts +31 −5
| @@ -6,6 +6,7 @@ const now = new Date("2026-11-14T12:00:00.000Z"); | ||
| 6 | 6 | function db(): Database { |
| 7 | 7 | const d = new Database(":memory:"); |
| 8 | 8 | d.run("CREATE TABLE maintenance_run (id INTEGER PRIMARY KEY AUTOINCREMENT, duty TEXT, started TEXT, finished TEXT, findings TEXT, actions TEXT, probes TEXT, outcome TEXT)"); |
| 9 | d.run("CREATE TABLE maintenance_duty_state (duty TEXT PRIMARY KEY, paused INTEGER)"); | |
| 9 | 10 | return d; |
| 10 | 11 | } |
| 11 | 12 | const add = (d: Database, duty: string, at: number, f: number, a: number, outcome = "ok") => |
| @@ -21,7 +22,7 @@ test("counts at the seven-day edge: exactly seven days is in, a millisecond olde | ||
| 21 | 22 | }); |
| 22 | 23 | |
| 23 | 24 | test("a worker with no run is a row, not hidden", () => { |
| 24 | expect(weekRows(db(), ["idle"], now)).toEqual([{ name: "idle", found: 0, acted: 0, last: null }]); | |
| 25 | expect(weekRows(db(), ["idle"], now)).toEqual([{ name: "idle", found: 0, acted: 0, last: null, result: null, ms: null }]); | |
| 25 | 26 | }); |
| 26 | 27 | |
| 27 | 28 | test("an idle week still shows the last run; two workers are told apart; budget stops do not count", () => { |
| @@ -31,19 +32,44 @@ test("an idle week still shows the last run; two workers are told apart; budget | ||
| 31 | 32 | add(d, "b", now.getTime() - 1000, 1, 0); |
| 32 | 33 | add(d, "b", now.getTime(), 4, 4, "budget:runs"); |
| 33 | 34 | const rows = weekRows(d, ["a", "b"], now); |
| 34 | expect(rows[0]).toEqual({ name: "a", found: 0, acted: 0, last: new Date(old).toISOString() }); | |
| 35 | expect(rows[1]).toEqual({ name: "b", found: 1, acted: 0, last: new Date(now.getTime() - 1000).toISOString() }); | |
| 35 | expect(rows[0]).toEqual({ name: "a", found: 0, acted: 0, last: new Date(old).toISOString(), result: "ok", ms: 0 }); | |
| 36 | expect(rows[1]).toEqual({ name: "b", found: 1, acted: 0, last: new Date(now.getTime() - 1000).toISOString(), result: "ok", ms: 0 }); | |
| 36 | 37 | }); |
| 37 | 38 | |
| 38 | 39 | test("/system draws a never-run worker as 'not yet run'", async () => { |
| 39 | 40 | const { maintenanceSection } = await import("../src/web/pages/system.ts"); |
| 40 | const out = maintenanceSection([{ name: "idle-one", found: 0, acted: 0, last: null }]).text; | |
| 41 | const out = maintenanceSection([{ name: "idle-one", found: 0, acted: 0, last: null, result: null, ms: null }]).text; | |
| 41 | 42 | expect(out).toContain("idle-one"); |
| 42 | 43 | expect(out).toContain("not yet run"); |
| 43 | 44 | }); |
| 44 | 45 | |
| 45 | 46 | test("the one sentence counts the workers that found something", async () => { |
| 46 | 47 | const { weekWords } = await import("../src/maintain/week_line.ts"); |
| 47 | const row = (found: number) => ({ name: "w", found, acted: 0, last: null }); | |
| 48 | const row = (found: number) => ({ name: "w", found, acted: 0, last: null, result: null, ms: null }); | |
| 48 | 49 | expect(weekWords([row(0), row(3), row(1)])).toBe("2 of 3 workers found something this week"); |
| 49 | 50 | }); |
| 51 | ||
| 52 | test("each result word: ok, failed and parked, with the last run's duration; a budget stop is no run", async () => { | |
| 53 | const { resultWords, took } = await import("../src/maintain/week_line.ts"); | |
| 54 | const d = db(); | |
| 55 | const t = now.getTime(); | |
| 56 | const run = (duty: string, ms: number, outcome: string) => | |
| 57 | d.query("INSERT INTO maintenance_run (duty, started, finished, findings, actions, probes, outcome) VALUES (?1,?2,?3,'[]','[]','[]',?4)").run( | |
| 58 | duty, new Date(t - 10_000).toISOString(), new Date(t - 10_000 + ms).toISOString(), outcome); | |
| 59 | run("good", 4200, "ok"); | |
| 60 | run("bad", 340, "error: boom"); | |
| 61 | run("bad2", 340, "ok"); | |
| 62 | run("bad2", 90_000, "timeout"); | |
| 63 | run("held", 100, "ok"); | |
| 64 | run("good", 50, "budget:runs"); | |
| 65 | d.query("INSERT INTO maintenance_duty_state (duty, paused) VALUES ('held', 1)").run(); | |
| 66 | const rows = weekRows(d, ["good", "bad", "bad2", "held", "none"], now); | |
| 67 | expect(rows.map((r) => r.result)).toEqual(["ok", "failed", "failed", "parked", null]); | |
| 68 | expect(rows.map(resultWords)).toEqual(["ok in 4.2 s", "failed in 340 ms", "failed in 2 min", "parked", "not yet run"]); | |
| 69 | expect(took(0)).toBe("0 ms"); | |
| 70 | const { maintenanceSection } = await import("../src/web/pages/system.ts"); | |
| 71 | const out = maintenanceSection(rows).text; | |
| 72 | expect(out).toContain("ok in 4.2 s"); | |
| 73 | expect(out).toContain('data-result="failed"'); | |
| 74 | expect(out).toContain("parked"); | |
| 75 | }); |
test/maintenance-week-doors.test.ts +2 −1
| @@ -67,7 +67,7 @@ test("MCP maintenance answers a row per worker; a non-admin is forbidden; teleme | ||
| 67 | 67 | expect(out.result.isError).not.toBe(true); |
| 68 | 68 | const { workers } = JSON.parse(out.result.content[0].text); |
| 69 | 69 | expect(workers.map((w: any) => w.name)).toEqual(duties.map((d) => d.name)); |
| 70 | expect(workers[0]).toMatchObject({ name: first, found: 2, acted: 1 }); | |
| 70 | expect(workers[0]).toMatchObject({ name: first, found: 2, acted: 1, result: "ok", says: "ok in 0 ms" }); | |
| 71 | 71 | expect(workers[0].last).not.toBeNull(); |
| 72 | 72 | expect(workers[1]).toMatchObject({ found: 0, acted: 0, last: null }); |
| 73 | 73 | |
| @@ -88,6 +88,7 @@ test("the terminal screen says the sentence and lists every worker, for the same | ||
| 88 | 88 | expect(lines[0]).toBe(`1 of ${String(duties.length)} workers found something this week`); |
| 89 | 89 | expect(lines.length).toBe(duties.length + 2); |
| 90 | 90 | expect(lines[2]).toContain("found 2 · acted 1"); |
| 91 | expect(lines[2]).toContain("ok in 0 ms"); | |
| 91 | 92 | expect(lines[3]).toContain("not yet run"); |
| 92 | 93 | expect(weekLines(new Session(app, identity(bob)))).toEqual([]); |
| 93 | 94 | expect(weekLines(new Session(app, identity(undefined)))).toEqual([]); |
new above
offline
Non-blocking: this line runs past the wrapped width; break it after "page shows."