Public: anyone can read this; the crew can change it.
The weekly restore drill card says what failed in plain words #15081
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15066-the-weekly-restore-drill-card-says-what → main 5 commits fork 3 threads · 3 unresolved
14 files
changed +256
−50
src/snapshot/drill.ts +20 −6
| @@ -82,14 +82,28 @@ export function formatBytes(bytes: number): string { | ||
| 82 | 82 | return `${Math.round(v * 10) / 10} ${units[i]}`; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | /** A span for people: "6 min 12 s", "58 s", "340 ms". */ | |
| 86 | export function formatSpan(ms: number): string { | |
| 87 | if (!Number.isFinite(ms) || ms < 0) return "0 ms"; | |
| 88 | if (ms < 1_000) return `${Math.round(ms)} ms`; | |
| 85 | /** Units in a span's short form ("6 min 12 s") and long form ("6 minutes 12 seconds"). */ | |
| 86 | const SPAN_UNITS = { | |
| 87 | short: { min: () => "min", s: () => "s" }, | |
| 88 | long: { min: (n: number) => (n === 1 ? "minute" : "minutes"), s: (n: number) => (n === 1 ? "second" : "seconds") }, | |
| 89 | } as const; | |
| 90 | ||
| 91 | /** | |
| 92 | * A span for people. Short: "6 min 12 s", "58 s", "340 ms". Long, for sentences (#15066): "6 | |
| 93 | * minutes 12 seconds", "58 seconds", and "less than a second" under one (zero too), so it reads | |
| 94 | * after "took" or "after" and never says ms. | |
| 95 | */ | |
| 96 | export function formatSpan(ms: number, form: "short" | "long" = "short"): string { | |
| 97 | const ok = Number.isFinite(ms) && ms >= 0; | |
| 98 | if (!ok || ms < 1_000) { | |
| 99 | if (form === "long") return "less than a second"; | |
| 100 | return ok ? `${Math.round(ms)} ms` : "0 ms"; | |
| 101 | } | |
| 102 | const u = SPAN_UNITS[form]; | |
| 89 | 103 | const s = Math.round(ms / 1_000); |
| 90 | if (s < 60) return `${s} s`; | |
| 104 | if (s < 60) return `${s} ${u.s(s)}`; | |
| 91 | 105 | const m = Math.floor(s / 60); |
| 92 | return s % 60 === 0 ? `${m} min` : `${m} min ${s % 60} s`; | |
| 106 | return s % 60 === 0 ? `${m} ${u.min(m)}` : `${m} ${u.min(m)} ${s % 60} ${u.s(s % 60)}`; | |
| 93 | 107 | } |
| 94 | 108 | |
| 95 | 109 | /** What people call each phase; the manifest read counts as download. */ |
src/snapshot/drill_card_words.ts added +76
| @@ -0,0 +1,76 @@ | ||
| 1 | /** | |
| 2 | * What the Backups card says of the last restore drill (#15066), in plain words: how long it took | |
| 3 | * in minutes and seconds, never raw milliseconds; and, when it went red, what failed. A drill that | |
| 4 | * ran out of time reads "the restore took longer than 10 minutes, while restoring the snapshot" | |
| 5 | * — naming the step that was running — not "restore timed out: no answer within its 600000 ms". | |
| 6 | * Plain data in, strings out; the page escapes them. | |
| 7 | */ | |
| 8 | ||
| 9 | import { formatSpan, timeByPart, type DrillResult, type DrillStep } from "./drill.ts"; | |
| 10 | import { plainDurations } from "./verdict.ts"; | |
| 11 | ||
| 12 | /** A span in the card's words: "6 minutes 12 seconds", "less than a second". */ | |
| 13 | export const spokenSpan = (ms: number): string => formatSpan(ms, "long"); | |
| 14 | ||
| 15 | /** What the drill was doing during each step, as the card says it. */ | |
| 16 | const DOING: Record<DrillStep, string> = { | |
| 17 | fetch: "listing the snapshots in the store", | |
| 18 | restore: "restoring the snapshot", | |
| 19 | open: "opening the restored database", | |
| 20 | count: "counting what came back", | |
| 21 | unseal: "opening the sealed key", | |
| 22 | health: "starting the restored forge", | |
| 23 | forge: "restoring a hosted forge", | |
| 24 | }; | |
| 25 | ||
| 26 | /** The step's words; an unknown step (a row kept by an older build) says so rather than nothing. */ | |
| 27 | export function stepDoing(step: string | null): string { | |
| 28 | return step !== null && Object.hasOwn(DOING, step) ? DOING[step as DrillStep] : "an unknown step"; | |
| 29 | } | |
| 30 | ||
| 31 | /** True when the drill went red because it ran out of its time, not because a step said no. */ | |
| 32 | export function timedOut(d: Pick<DrillResult, "verdict" | "reason">): boolean { | |
| 33 | return d.verdict === "red" && d.reason !== null && /\btimed out\b/.test(d.reason); | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Where a timed-out restore had got to, from its reason, one flat clause: "bundles, 37 of 212 | |
| 38 | * cloned, 1.8 GiB fetched" (the reason's own parentheses become a comma, so the card's never nest). | |
| 39 | */ | |
| 40 | function whereItWas(d: Pick<DrillResult, "failedStep" | "reason">): string | undefined { | |
| 41 | const r = d.reason ?? ""; | |
| 42 | if (d.failedStep === "restore") { | |
| 43 | const at = /^restore timed out in (.+) after its /.exec(r)?.[1]; | |
| 44 | return at?.replace(/\s*\(([^()]*)\)\s*$/, ", $1"); | |
| 45 | } | |
| 46 | if (d.failedStep === "forge") return /^(hosted forge [^:]+):/.exec(r)?.[1]; | |
| 47 | return undefined; | |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * A red drill's failure, one clause: "the restore took longer than 10 minutes, while restoring the | |
outdated
The progress text comes out as "bundles (37 of 212 ...)", which the caller then wraps in another pair of parentheses. Return it with a comma or dash separator. |
||
| 52 | * snapshot — bundles, 37 of 212 cloned" for a timeout; "opening the sealed key failed after 3 | |
| 53 | * seconds: <reason>" otherwise. | |
| 54 | */ | |
| 55 | export function drillFailure(d: Pick<DrillResult, "verdict" | "reason" | "failedStep" | "ms" | "budgetMs">): string { | |
| 56 | const doing = stepDoing(d.failedStep); | |
| 57 | if (timedOut(d)) { | |
| 58 | const limit = d.budgetMs > 0 ? spokenSpan(d.budgetMs) : spokenSpan(d.ms); | |
| 59 | const where = whereItWas(d); | |
| 60 | return `the restore took longer than ${limit}, while ${doing}${where === undefined ? "" : ` — ${where}`}`; | |
| 61 | } | |
| 62 | return `${doing} failed after ${spokenSpan(d.ms)}${d.reason ? `: ${plainDurations(d.reason)}` : ""}`; | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * "6 minutes 12 seconds of its 14 minutes: clone 4 minutes, download 58 seconds"; just the first | |
| 67 | * part when no phase was kept; empty for an older drill that kept no budget. | |
outdated
"failed after under a second" and "failed after no time" are ungrammatical (principle 8). Reword the span for this position. |
||
| 68 | */ | |
| 69 | export function drillTiming(d: Pick<DrillResult, "ms" | "budgetMs" | "phases">): string { | |
| 70 | if (d.budgetMs <= 0) return ""; | |
| 71 | const spent = `${spokenSpan(d.ms)} of its ${spokenSpan(d.budgetMs)}`; | |
| 72 | if (d.phases.length === 0) return spent; | |
| 73 | return `${spent}: ${timeByPart(d.phases) | |
| 74 | .map((p) => `${p.part} ${spokenSpan(p.ms)}`) | |
| 75 | .join(", ")}`; | |
| 76 | } |
src/snapshot/drill_cost.ts +4 −3
| @@ -16,12 +16,13 @@ export const LIMIT_RULE = "60% of the machine's memory, kept between 3 and 16 Gi | ||
| 16 | 16 | const share = (peak: number, limit: number): number => (limit > 0 ? Math.ceil((peak / limit) * 100) : 0); |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | * "took 1 min 2 s, peak 412 MiB of its 3 GiB limit (14%)"; for a drill that kept no cost, says so. | |
| 19 | * "took 1 minute 2 seconds, peak 412 MiB of its 3 GiB limit (14%)"; for a drill that kept no cost, | |
| 20 | * says so. | |
| 20 | 21 | */ |
| 21 | 22 | export function costLine(d: Pick<DrillResult, "cost">): string { |
| 22 | 23 | const c = d.cost; |
| 23 | 24 | if (c === undefined) return "elapsed time and peak memory not recorded for this drill"; |
| 24 | return `took ${formatSpan(c.elapsedMs)}, peak ${formatBytes(c.peakBytes)} of its ${formatBytes(c.limitBytes)} limit (${share(c.peakBytes, c.limitBytes)}%)`; | |
| 25 | return `took ${formatSpan(c.elapsedMs, "long")}, peak ${formatBytes(c.peakBytes)} of its ${formatBytes(c.limitBytes)} limit (${share(c.peakBytes, c.limitBytes)}%)`; | |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | /** One fact of the drill's cost: its label and its value, as a `dl` row says it. */ |
| @@ -38,7 +39,7 @@ export function costFacts(d: Pick<DrillResult, "cost">): CostFact[] { | ||
| 38 | 39 | const c = d.cost; |
| 39 | 40 | if (c === undefined) return [{ label: "Drill cost", value: "elapsed time and peak memory not recorded for this drill" }]; |
| 40 | 41 | return [ |
| 41 | { label: "Took", value: formatSpan(c.elapsedMs) }, | |
| 42 | { label: "Took", value: formatSpan(c.elapsedMs, "long") }, | |
| 42 | 43 | { label: "Peak memory", value: `${formatBytes(c.peakBytes)}, ${share(c.peakBytes, c.limitBytes)}% of the limit` }, |
| 43 | 44 | { label: "Limit", value: `${formatBytes(c.limitBytes)}: ${LIMIT_RULE}` }, |
| 44 | 45 | ]; |
src/snapshot/verdict.ts +1 −1
| @@ -42,7 +42,7 @@ export function lastVerdict(dataDir: string): DrillResult | undefined { | ||
| 42 | 42 | export function plainDurations(text: string): string { |
| 43 | 43 | return text.replace(/\b(no answer in|timed out in|after) (\d+(?:\.\d+)?) (ms|s)\b/g, (_, lead: string, n: string, unit: string) => { |
| 44 | 44 | const ms = Number(n) * (unit === "s" ? 1000 : 1); |
| 45 | if (ms < 1000) return `${lead} under a second`; | |
| 45 | if (ms < 1000) return `${lead} less than a second`; | |
| 46 | 46 | if (ms < 90_000) return `${lead} about ${Math.round(ms / 1000)} seconds`; |
| 47 | 47 | const min = Math.round(ms / 60_000); |
| 48 | 48 | return `${lead} about ${min} minute${min === 1 ? "" : "s"}`; |
src/web/pages/backups.ts +5 −20
| @@ -28,7 +28,8 @@ import { kitPassphrase as passphrase, saveReadKey, takeKit } from "../../actions | ||
| 28 | 28 | import { SEALED_READ } from "../../snapshot/destination.ts"; |
| 29 | 29 | import { kitWords, lastDownload, lastOutside, makeKit } from "../../snapshot/kit.ts"; |
| 30 | 30 | import { keyOf, progressFacts } from "../../snapshot/snapshot.ts"; |
| 31 | import { formatBytes, formatMinutes, formatSpan, timeByPart, type DrillResult } from "../../snapshot/drill.ts"; | |
| 31 | import { formatBytes } from "../../snapshot/drill.ts"; | |
| 32 | import { drillFailure, drillTiming, spokenSpan } from "../../snapshot/drill_card_words.ts"; | |
| 32 | 33 | import { costFacts } from "../../snapshot/drill_cost.ts"; |
| 33 | 34 | import { lastDrill } from "../../snapshot/drills.ts"; |
| 34 | 35 | import { backupVerdict } from "../../snapshot/bucket.ts"; |
| @@ -113,20 +114,6 @@ function keyNote( | ||
| 113 | 114 | </p>`; |
| 114 | 115 | } |
| 115 | 116 | |
| 116 | /** | |
| 117 | * "6 min 12 s of its 14 min budget: clone 4 min, download 58 s, ...", or | |
| 118 | * "6 min 12 s of its 14 min budget" when no phase was kept; empty for an | |
| 119 | * older drill that kept no budget. | |
| 120 | */ | |
| 121 | function drillTiming(d: DrillResult): string { | |
| 122 | if (d.budgetMs <= 0) return ""; | |
| 123 | const spent = `${formatSpan(d.ms)} of its ${formatMinutes(d.budgetMs)} budget`; | |
| 124 | if (d.phases.length === 0) return spent; | |
| 125 | return `${spent}: ${timeByPart(d.phases) | |
| 126 | .map((p) => `${p.part} ${formatSpan(p.ms)}`) | |
| 127 | .join(", ")}`; | |
| 128 | } | |
| 129 | ||
| 130 | 117 | /** The last drill in one line, and the button to run another. */ |
| 131 | 118 | function drillLine(ctx: Ctx): Html { |
| 132 | 119 | const d = lastDrill(ctx.app.db); |
| @@ -144,7 +131,7 @@ function drillLine(ctx: Ctx): Html { | ||
| 144 | 131 | ? html`<p class="break">No restore drill has run yet.</p>` |
| 145 | 132 | : d.verdict === "green" |
| 146 | 133 | ? html`<p class="break"> |
| 147 | ${badge("Ready", { tone: "success", icon: "check" })} Last drill: ${time(d.at)}, ${d.ms} ms, all counts matched — | |
| 134 | ${badge("Ready", { tone: "success", icon: "check" })} Last drill: ${time(d.at)}, took ${spokenSpan(d.ms)}, all counts matched — | |
| 148 | 135 | snapshot <code>${d.snapshotId ?? ""}</code>, key opened — |
| 149 | 136 | ${d.counts.users} users, ${d.counts.repositories} repositories, ${d.counts.issues} issues, ${d.counts.pulls} pulls, ${d.counts.apps} apps.${hosted}${timing |
| 150 | 137 | ? html` <span class="muted small">${timing}.</span>` |
| @@ -152,10 +139,8 @@ function drillLine(ctx: Ctx): Html { | ||
| 152 | 139 | </p>` |
| 153 | 140 | : html`<p class="break"> |
| 154 | 141 | ${badge("At risk", { tone: "danger", icon: "alert" })} Last drill ${time(d.at)}: snapshot |
| 155 | <code>${d.snapshotId ?? "none"}</code> failed at | |
| 156 | ${d.failedStep ?? "an unknown step"} after ${d.ms} ms${d.reason | |
| 157 | ? html`: ${d.reason}` | |
| 158 | : ""}.${timing ? html` <span class="muted small">${timing}.</span>` : ""} | |
| 142 | <code>${d.snapshotId ?? "none"}</code> failed: | |
| 143 | ${drillFailure(d)}.${timing ? html` <span class="muted small">${timing}.</span>` : ""} | |
| 159 | 144 | </p>`; |
| 160 | 145 | const running = snapshotsOf(ctx.app)?.drillState(); |
| 161 | 146 | const says = drillStatus(ctx.app); |
test/backups-drill-cost.test.ts +1 −1
| @@ -64,7 +64,7 @@ test("a measured drill: took, peak with its share, and the limit with its rule, | ||
| 64 | 64 | const { rows, page } = await costShown(); |
| 65 | 65 | // 412 / 3072 = 13.4%, rounded up to 14%; the apostrophe is escaped on the way out. |
| 66 | 66 | expect(rows).toEqual([ |
| 67 | "Took: 1 min 2 s", | |
| 67 | "Took: 1 minute 2 seconds", | |
| 68 | 68 | "Peak memory: 412 MiB, 14% of the limit", |
| 69 | 69 | "Limit: 3 GiB: 60% of the machine's memory, kept between 3 and 16 GiB, or FORGE_DRILL_MEMORY_MIB", |
| 70 | 70 | ]); |
test/backups-drill-words.test.ts added +130
| @@ -0,0 +1,130 @@ | ||
| 1 | /** | |
| 2 | * The Backups card says the last restore drill in plain words (#15066): durations in minutes and | |
| 3 | * seconds, a timeout as "the restore took longer than 10 minutes" naming the step that was | |
| 4 | * running, and no raw millisecond value anywhere in the card, for a pass, a timeout and a failure. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createUser } from "../src/core/users.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import type { DrillResult } from "../src/snapshot/drill.ts"; | |
| 14 | import { costFacts, costLine } from "../src/snapshot/drill_cost.ts"; | |
| 15 | import { drillFailure, spokenSpan, stepDoing } from "../src/snapshot/drill_card_words.ts"; | |
| 16 | import { recordDrill } from "../src/snapshot/drills.ts"; | |
| 17 | import { startSnapshots, type SnapshotsHandle } from "../src/snapshot/service.ts"; | |
| 18 | import { dirStore } from "../src/snapshot/store.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | let root = ""; | |
| 24 | let app: App; | |
| 25 | let servers: Servers; | |
| 26 | let svc: SnapshotsHandle; | |
| 27 | let cookie = ""; | |
| 28 | ||
| 29 | const counts = { repositories: 3, issues: 4, users: 2, pulls: 1, apps: 0 }; | |
| 30 | const pass: DrillResult = { | |
| 31 | at: "2026-11-15T08:10:00.000Z", snapshotId: "snap-pass", ms: 372_400, counts, health: "ok", verdict: "green", | |
| 32 | failedStep: null, phases: [{ phase: "bundles", ms: 241_000 }, { phase: "files", ms: 58_300 }, { phase: "key", ms: 12 }], budgetMs: 840_000, reason: null, | |
| 33 | }; | |
| 34 | const timeout: DrillResult = { | |
| 35 | ...pass, snapshotId: "snap-slow", ms: 600_213, health: "unreached", verdict: "red", failedStep: "restore", budgetMs: 600_000, | |
| 36 | reason: "restore timed out in bundles (37 of 212 cloned, 1.8 GiB fetched) after its 10 min budget", | |
| 37 | }; | |
| 38 | const failure: DrillResult = { | |
| 39 | ...pass, snapshotId: "snap-bad", ms: 3_240, health: "unreached", verdict: "red", failedStep: "unseal", phases: [], budgetMs: 600_000, | |
| 40 | reason: "the passphrase does not open the wrapped key", | |
| 41 | }; | |
| 42 | ||
| 43 | beforeAll(async () => { | |
| 44 | root = mkdtempSync(join(tmpdir(), "forge-drill-card-words-")); | |
| 45 | app = createApp({ dataDir: root, port: 0 }); | |
| 46 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 47 | if (!u.ok) throw new Error(u.error); | |
| 48 | svc = startSnapshots(app, dirStore(join(root, "store")), { version: "t", nightly: false }); | |
| 49 | servers = await serve(app); | |
| 50 | const r = await fetch(`${servers.url}/signin`, { | |
| 51 | method: "POST", | |
| 52 | headers: { origin: servers.url }, | |
| 53 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 54 | redirect: "manual", | |
| 55 | }); | |
| 56 | cookie = (r.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 57 | }); | |
| 58 | ||
| 59 | afterAll(async () => { | |
| 60 | servers.stop(); | |
| 61 | await svc.stop(); | |
| 62 | app.close(); | |
| 63 | rmSync(root, { recursive: true, force: true }); | |
| 64 | }); | |
| 65 | ||
| 66 | /** The card's verdict paragraph, tags dropped and whitespace folded. */ | |
| 67 | const card = async (d: DrillResult): Promise<string> => { | |
| 68 | recordDrill(app.db, d); | |
| 69 | const page = await (await fetch(`${servers.url}/settings/backups`, { headers: { cookie } })).text(); | |
| 70 | const at = page.indexOf(d.snapshotId!); | |
| 71 | expect(at).toBeGreaterThan(-1); | |
| 72 | const p = page.slice(page.lastIndexOf("<p", at), page.indexOf("</p>", at)); | |
| 73 | return p.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim(); | |
| 74 | }; | |
| 75 | ||
| 76 | const NO_RAW_MS = /\d\s*ms\b/; | |
| 77 | ||
| 78 | test("spans read in minutes and seconds, never ms", () => { | |
| 79 | expect([spokenSpan(600_000), spokenSpan(372_400), spokenSpan(58_300), spokenSpan(1_000), spokenSpan(12), spokenSpan(0)]).toEqual([ | |
| 80 | "10 minutes", "6 minutes 12 seconds", "58 seconds", "1 second", "less than a second", "less than a second", | |
| 81 | ]); | |
| 82 | expect(stepDoing("nonsense")).toBe("an unknown step"); | |
| 83 | }); | |
| 84 | ||
| 85 | test("a pass says how long it took and each part, in minutes and seconds", async () => { | |
| 86 | const said = await card(pass); | |
| 87 | expect(said).toContain("took 6 minutes 12 seconds, all counts matched"); | |
| 88 | expect(said).toContain("6 minutes 12 seconds of its 14 minutes: clone 4 minutes 1 second, download 58 seconds, key less than a second."); | |
| 89 | expect(said).not.toMatch(NO_RAW_MS); | |
| 90 | }); | |
| 91 | ||
| 92 | test("a timeout says the restore took longer than its budget and names the step running", async () => { | |
| 93 | const said = await card(timeout); | |
| 94 | expect(said).toContain( | |
| 95 | "failed: the restore took longer than 10 minutes, while restoring the snapshot — bundles, 37 of 212 cloned, 1.8 GiB fetched.", | |
| 96 | ); | |
| 97 | expect(said).not.toContain("600213"); | |
| 98 | expect(said).not.toMatch(NO_RAW_MS); | |
| 99 | }); | |
| 100 | ||
| 101 | test("a failure names the step in words, its time, and the reason", async () => { | |
| 102 | const said = await card(failure); | |
| 103 | expect(said).toContain("failed: opening the sealed key failed after 3 seconds: the passphrase does not open the wrapped key."); | |
| 104 | expect(said).not.toMatch(NO_RAW_MS); | |
| 105 | }); | |
| 106 | ||
| 107 | test("a timeout in a later step names that step and the hosted forge it was proving", () => { | |
| 108 | expect(drillFailure({ ...timeout, failedStep: "health", reason: "health timed out: no answer within its 10 min budget" })).toBe( | |
| 109 | "the restore took longer than 10 minutes, while starting the restored forge", | |
| 110 | ); | |
| 111 | expect(drillFailure({ ...timeout, failedStep: "forge", reason: "hosted forge glint: timed out: no answer within its 10 min budget" })).toBe( | |
| 112 | "the restore took longer than 10 minutes, while restoring a hosted forge — hosted forge glint", | |
| 113 | ); | |
| 114 | // A reason that carries its own milliseconds is said in words too. | |
| 115 | expect(drillFailure({ ...failure, reason: "the store gave up after 340 ms" })).toBe( | |
| 116 | "opening the sealed key failed after 3 seconds: the store gave up after less than a second", | |
| 117 | ); | |
| 118 | }); | |
| 119 | ||
| 120 | test("a failure with no measurable time reads after 'after', not 'no time'", () => { | |
| 121 | expect(drillFailure({ ...failure, ms: 0, reason: null })).toBe("opening the sealed key failed after less than a second"); | |
| 122 | expect(drillFailure({ ...failure, ms: 340, reason: null })).toBe("opening the sealed key failed after less than a second"); | |
| 123 | }); | |
| 124 | ||
| 125 | test("the drill's cost says its time in the card's words, never ms", () => { | |
| 126 | const cost = { elapsedMs: 400, peakBytes: 1024 ** 2, limitBytes: 3 * 1024 ** 3 }; | |
| 127 | expect(costFacts({ cost })[0]).toEqual({ label: "Took", value: "less than a second" }); | |
| 128 | expect(costLine({ cost })).toStartWith("took less than a second, peak"); | |
| 129 | expect(costFacts({ cost: { ...cost, elapsedMs: 372_000 } })[0]!.value).toBe("6 minutes 12 seconds"); | |
| 130 | }); |
test/drill-card-words.test.ts +1 −1
| @@ -29,7 +29,7 @@ test("the card says minutes, the snapshot's age and the next step", () => { | ||
| 29 | 29 | }); |
| 30 | 30 | |
| 31 | 31 | test("plainDurations rounds sub-second, seconds and minutes", () => { |
| 32 | expect(plainDurations("no answer in 340 ms")).toBe("no answer in under a second"); | |
| 32 | expect(plainDurations("no answer in 340 ms")).toBe("no answer in less than a second"); | |
| 33 | 33 | expect(plainDurations("no answer in 45 s")).toBe("no answer in about 45 seconds"); |
| 34 | 34 | expect(plainDurations("no answer in 180 s")).toBe("no answer in about 3 minutes"); |
| 35 | 35 | expect(plainDurations("table sizes 5 s and 7 ms")).toBe("table sizes 5 s and 7 ms"); |
test/drill-job.test.ts +2 −2
| @@ -160,10 +160,10 @@ test("the cost line says elapsed, peak, the limit and its share; the facts say t | ||
| 160 | 160 | const MiB = 1024 ** 2; |
| 161 | 161 | const d = { cost: { elapsedMs: 62_000, peakBytes: 412 * MiB, limitBytes: 3072 * MiB } }; |
| 162 | 162 | // 412 MiB of 3 GiB = 13.41%, rounded up to 14%. |
| 163 | expect(costLine(d)).toBe("took 1 min 2 s, peak 412 MiB of its 3 GiB limit (14%)"); | |
| 163 | expect(costLine(d)).toBe("took 1 minute 2 seconds, peak 412 MiB of its 3 GiB limit (14%)"); | |
| 164 | 164 | expect(costLine({})).toBe("elapsed time and peak memory not recorded for this drill"); |
| 165 | 165 | expect(costFacts(d)).toEqual([ |
| 166 | { label: "Took", value: "1 min 2 s" }, | |
| 166 | { label: "Took", value: "1 minute 2 seconds" }, | |
| 167 | 167 | { label: "Peak memory", value: "412 MiB, 14% of the limit" }, |
| 168 | 168 | { label: "Limit", value: `3 GiB: ${LIMIT_RULE}` }, |
| 169 | 169 | ]); |
test/mcp-restore-drill.test.ts +1 −1
| @@ -121,7 +121,7 @@ describe("MCP restore_drill", () => { | ||
| 121 | 121 | }); |
| 122 | 122 | test("status prints the drill's elapsed time and peak memory in one line beside its limit (#13253)", async () => { |
| 123 | 123 | const { verdict } = await drillAndRead(token("alice")); |
| 124 | expect(verdict.cost).toBe("took 1 min 2 s, peak 412 MiB of its 3 GiB limit (14%)"); | |
| 124 | expect(verdict.cost).toBe("took 1 minute 2 seconds, peak 412 MiB of its 3 GiB limit (14%)"); | |
| 125 | 125 | expect([verdict.elapsedMs, verdict.peakMiB, verdict.limitMiB]).toEqual([62_000, 412, 3072]); |
| 126 | 126 | }); |
| 127 | 127 | test("a second ask while one runs says so and does not start another", async () => { |
test/snapshot-drill-page.test.ts +6 −6
| @@ -106,18 +106,19 @@ describe("the drill on the Backups page", () => { | ||
| 106 | 106 | const html = await page(cookie); |
| 107 | 107 | expect(html).toContain("snap-stub-1"); |
| 108 | 108 | expect(html).toContain("0 users, 7 repositories, 42 issues, 0 pulls, 0 apps"); |
| 109 | expect(html).toContain("1234 ms"); | |
| 109 | expect(html).toContain("took 1 second,"); | |
| 110 | expect(html).not.toContain("1234 ms"); | |
| 110 | 111 | expect(app.db.query("SELECT count(*) AS n FROM drill").get()).toEqual({ n: 1 }); |
| 111 | 112 | }); |
| 112 | 113 | |
| 113 | test("a red drill's reason shows verbatim, escaped", async () => { | |
| 114 | test("a red drill's reason shows, escaped", async () => { | |
| 114 | 115 | const cookie = await login("alice", "a-good-passphrase"); |
| 115 | 116 | verdict = "red"; |
| 116 | redReason = "restore timed out in bundles (37 of 212 cloned, 1.8 GiB fetched) after its 14 min budget <b>x</b>"; | |
| 117 | redReason = "a sealed value does not open <b>x</b>"; | |
| 117 | 118 | await post(cookie); |
| 118 | 119 | const html = await page(cookie); |
| 119 | 120 | redReason = "a sealed value does not open"; |
| 120 | expect(html).toContain("restore timed out in bundles (37 of 212 cloned, 1.8 GiB fetched) after its 14 min budget <b>x</b>"); | |
| 121 | expect(html).toContain("opening the sealed key failed after 1 second: a sealed value does not open <b>x</b>"); | |
| 121 | 122 | expect(html).not.toContain("<b>x</b>"); |
| 122 | 123 | }); |
| 123 | 124 | |
| @@ -126,8 +127,7 @@ describe("the drill on the Backups page", () => { | ||
| 126 | 127 | verdict = "red"; |
| 127 | 128 | await post(cookie); |
| 128 | 129 | const html = await page(cookie); |
| 129 | expect(html).toContain("failed at"); | |
| 130 | expect(html).toContain("unseal"); | |
| 130 | expect(html).toContain("opening the sealed key failed"); | |
| 131 | 131 | expect(app.db.query("SELECT count(*) AS n FROM drill").get()).toEqual({ n: 3 }); |
| 132 | 132 | }); |
| 133 | 133 |
test/snapshot-drill-phases.test.ts +7 −7
| @@ -177,7 +177,7 @@ describe("the Backups page line", () => { | ||
| 177 | 177 | reason: null, |
| 178 | 178 | ...over, |
| 179 | 179 | }); |
| 180 | const LINE = "6 min 12 s of its 14 min budget: clone 4 min 50 s, download 58 s, decompress 20 s, start and migrate 3 s, open 2 s, key 1 s"; | |
| 180 | const LINE = "6 minutes 12 seconds of its 14 minutes: clone 4 minutes 50 seconds, download 58 seconds, decompress 20 seconds, start and migrate 3 seconds, open 2 seconds, key 1 second"; | |
| 181 | 181 | const backups = async (): Promise<string> => { |
| 182 | 182 | const r = await fetch(`${servers.url}/signin`, { |
| 183 | 183 | method: "POST", |
| @@ -208,20 +208,20 @@ describe("the Backups page line", () => { | ||
| 208 | 208 | verdict: "red", |
| 209 | 209 | health: "unreached", |
| 210 | 210 | failedStep: "restore", |
| 211 | reason: "restore timed out in bundles <b>x</b>", | |
| 211 | reason: "restore timed out in bundles <b>x</b> after its 14 min budget", | |
| 212 | 212 | }), |
| 213 | 213 | ); |
| 214 | 214 | const html = await backups(); |
| 215 | expect(html).toContain("failed at"); | |
| 216 | expect(html).toContain("restore timed out in bundles <b>x</b>"); | |
| 215 | expect(html).toContain("the restore took longer than 14 minutes, while restoring the snapshot — bundles <b>x</b>"); | |
| 216 | expect(html).not.toContain("<b>x</b>"); | |
| 217 | 217 | expect(html).toContain(LINE); |
| 218 | 218 | }); |
| 219 | 219 | |
| 220 | 220 | test("a drill that kept a budget but no phases still says the budget in minutes", async () => { |
| 221 | 221 | recordDrill(app.db, kept({ phases: [], ms: 75_000, budgetMs: 1_000_000 })); |
| 222 | 222 | const html = await backups(); |
| 223 | expect(html).toContain("1 min 15 s of its 16.7 min budget."); | |
| 224 | expect(html).not.toContain("budget:"); | |
| 223 | expect(html).toContain("1 minute 15 seconds of its 16 minutes 40 seconds."); | |
| 224 | expect(html).not.toContain("seconds:"); | |
| 225 | 225 | }); |
| 226 | 226 | |
| 227 | 227 | test("a drill with no phases shows no timing", async () => { |
| @@ -237,7 +237,7 @@ describe("the Backups page line", () => { | ||
| 237 | 237 | ); |
| 238 | 238 | const html = await backups(); |
| 239 | 239 | expect(html).toContain("snap-1"); |
| 240 | expect(html).not.toContain("budget:"); | |
| 240 | expect(html).not.toContain("seconds:"); | |
| 241 | 241 | expect(html).not.toContain("backups-timing"); |
| 242 | 242 | } |
| 243 | 243 | }); |
test/tui-drill.test.ts +1 −1
| @@ -138,7 +138,7 @@ test("the verdict says the drill process's cost beside its limit (#13253)", asyn | ||
| 138 | 138 | await h.press("d"); |
| 139 | 139 | await h.press("left"); |
| 140 | 140 | const text = await h.pressUntil("enter", "peak 412 MiB"); |
| 141 | expect(text).toContain("The drill restored green. Its process took 1 min 2 s, peak 412 MiB of its 3 GiB limit (14%)."); | |
| 141 | expect(text).toContain("The drill restored green. Its process took 1 minute 2 seconds, peak 412 MiB of its 3 GiB limit (14%)."); | |
| 142 | 142 | h.app.stop(); |
| 143 | 143 | }); |
| 144 | 144 |
test/tui-resilience-drill.test.ts +1 −1
| @@ -139,7 +139,7 @@ describe("a restore drill from the terminal's Resilience dialog", () => { | ||
| 139 | 139 | await h.waitFor("peak 412 MiB"); |
| 140 | 140 | // The dialog wraps the line; its words, border and padding removed, read as one. |
| 141 | 141 | const said = h.text().replace(/[│╭╮╰╯─]/g, " ").replace(/\s+/g, " "); |
| 142 | expect(said).toContain("The drill restored green. Its process took 1 min 2 s, peak 412 MiB of its 3 GiB limit (14%)."); | |
| 142 | expect(said).toContain("The drill restored green. Its process took 1 minute 2 seconds, peak 412 MiB of its 3 GiB limit (14%)."); | |
| 143 | 143 | verdict = GREEN; |
| 144 | 144 | h.stop(); |
| 145 | 145 | }); |
new above
offline
Near-duplicate of formatSpan in drill.ts. Principle 8: "no time" and "under a second" read badly after "after". Merge into one helper and fix the zero and sub-second words.