Public: anyone can read this; the crew can change it.
The drill card names the hosted forge it restored, its size and its restore time in seconds, or says there is none #14196
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14185-the-drill-card-names-the-hosted-forge-it → main 2 commits fork 1 thread · 1 unresolved
4 files
changed +36
−23
docs/features/hosted-backup.md +2 −2
| @@ -34,8 +34,8 @@ A hosted forge's directory is the forge's own to write, and its host reads it fo | ||
| 34 | 34 | |
| 35 | 35 | Each restore drill, after the host itself, restores one hosted forge alone from the same snapshot (the next one each day and each week, `src/snapshot/drill_hosted.ts`) and proves it opens: its ledger reads and names it, its database passes SQLite's integrity check, and every repository its copy holds comes back and passes `git fsck`. The verdict says which forge ("…passed, with hosted forge glint (1 of 17)"). One that does not come back fails the drill at the step `forge`, by name ([](../RECOVERY.md)). |
| 36 | 36 | |
| 37 | - Web: `/settings/backups`, press Run a drill; when it ends, the last-drill line says "Hosted forge NAME (SIZE, 1 of N) restored alone in 3.2 s: its database passed the integrity check and its K repositories git fsck." Terminal: the Resilience screen's "Last drill:" line under the verdict says the same, and so does the recovery issue's comment (`- hosted:`). | |
| 38 | - A forge that hosts none, or whose snapshot left every hosted forge out, says in one line that the hosted restore was skipped; the drill stays green. | |
| 37 | - Web: `/settings/backups`, press Run a drill; when it ends, the last-drill line says "Restored NAME (1 of N hosted forges): SIZE, K repositories, S seconds, checks passed." in whole seconds. Terminal: the Resilience screen's "Last drill:" line under the verdict says the same, and so does the recovery issue's comment (`- hosted:`). | |
| 38 | - A forge that hosts none, or whose snapshot left every hosted forge out, says "No hosted forges to drill." in one line; the drill stays green. | |
| 39 | 39 | - Red at `forge`: the reason names the forge and what did not hold (a missing chunk, the integrity check, a repository's `git fsck`, its ledger); it is paged once like every red drill. |
| 40 | 40 | |
| 41 | 41 | ## Restore one forge |
src/snapshot/drill_hosted_words.ts +18 −12
| @@ -1,17 +1,22 @@ | ||
| 1 | 1 | /** |
| 2 | * What the last restore drill says of its hosted step (#13919), one line, in the same words on the | |
| 3 | * Backups card, the Resilience screen and the recovery issue's comment: the forge it restored | |
| 4 | * alone, its size and its restore time in seconds; or that it was skipped for want of one. A drill | |
| 5 | * that failed there is red at the step `forge` and its reason names the forge; this says nothing | |
| 6 | * more of it. Control characters in a kept name print as `?`; each surface still escapes the line. | |
| 2 | * What the last restore drill says of its hosted step (#13919, #14185), one line, in the same | |
| 3 | * words on the Backups card, the Resilience screen and the recovery issue's comment: the forge it | |
| 4 | * restored alone, which of how many, its size, its repositories and its restore time in whole | |
| 5 | * seconds; or that there was none to drill. A drill that failed there is red at the step `forge` | |
| 6 | * and its reason names the forge; this says nothing more of it. Control characters in a kept name | |
| 7 | * print as `?`; each surface still escapes the line. | |
| 7 | 8 | */ |
| 8 | 9 | |
| 9 | 10 | import { printable } from "./bucket.ts"; |
| 10 | 11 | import { formatBytes, type DrillResult } from "./drill.ts"; |
| 11 | 12 | |
| 12 | /** Milliseconds as seconds with one decimal: 3240 → "3.2 s". */ | |
| 13 | /** | |
| 14 | * Milliseconds as whole seconds, never negative: 3240 → "3 seconds", 900 → "1 second". A proof | |
| 15 | * that took any time reads at least "1 second", never "0 seconds". | |
| 16 | */ | |
| 13 | 17 | export function seconds(ms: number): string { |
| 14 | return `${(Math.max(0, ms) / 1000).toFixed(1)} s`; | |
| 18 | const s = ms > 0 ? Math.max(1, Math.round(ms / 1000)) : 0; | |
| 19 | return `${s} ${s === 1 ? "second" : "seconds"}`; | |
| 15 | 20 | } |
| 16 | 21 | |
| 17 | 22 | /** |
| @@ -20,11 +25,12 @@ export function seconds(ms: number): string { | ||
| 20 | 25 | export function hostedDrillWords(d: Pick<DrillResult, "hosted" | "hostedSkipped">): string | undefined { |
| 21 | 26 | const h = d.hosted; |
| 22 | 27 | if (h !== undefined) { |
| 23 | const took = h.ms === undefined ? "" : ` in ${seconds(h.ms)}`; | |
| 24 | const of = h.of > 1 ? `, 1 of ${h.of}` : ""; | |
| 25 | const repos = h.repos === 1 ? "its 1 repository" : `its ${h.repos} repositories`; | |
| 26 | return `Hosted forge ${printable(h.name)} (${formatBytes(h.bytes)}${of}) restored alone${took}: its database passed the integrity check and ${repos} git fsck.`; | |
| 28 | const of = `1 of ${h.of} hosted ${h.of === 1 ? "forge" : "forges"}`; | |
| 29 | const repos = `${h.repos} ${h.repos === 1 ? "repository" : "repositories"}`; | |
| 30 | // A proof kept before the drill timed it says no time rather than a wrong one. | |
| 31 | const took = h.ms === undefined ? "" : `, ${seconds(h.ms)}`; | |
| 32 | return `Restored ${printable(h.name)} (${of}): ${formatBytes(h.bytes)}, ${repos}${took}, checks passed.`; | |
| 27 | 33 | } |
| 28 | if (d.hostedSkipped === true) return "No hosted forge was whole in the snapshot, so the hosted restore was skipped."; | |
| 34 | if (d.hostedSkipped === true) return "No hosted forges to drill."; | |
| 29 | 35 | return undefined; |
| 30 | 36 | } |
test/drill-hosted-card.test.ts +15 −8
| @@ -32,10 +32,10 @@ const green: DrillResult = { | ||
| 32 | 32 | at: "2026-11-15T08:10:00.000Z", snapshotId: "s", ms: 60_000, counts: { repositories: 1, issues: 0, users: 1, pulls: 0, apps: 0 }, |
| 33 | 33 | health: "ok", verdict: "green", failedStep: null, phases: [], budgetMs: 600_000, reason: null, |
| 34 | 34 | }; |
| 35 | // 3 MiB = 3 × 1024² bytes; 3240 ms = 3.2 s. | |
| 35 | // 3 MiB = 3 × 1024² bytes; 3240 ms = 3 seconds, whole. | |
| 36 | 36 | const restored: DrillResult = { ...green, hosted: { name: "glint", of: 4, repos: 2, bytes: 3 * 1024 ** 2, ms: 3_240 } }; |
| 37 | const LINE = "Hosted forge glint (3 MiB, 1 of 4) restored alone in 3.2 s: its database passed the integrity check and its 2 repositories git fsck."; | |
| 38 | const SKIP = "No hosted forge was whole in the snapshot, so the hosted restore was skipped."; | |
| 37 | const LINE = "Restored glint (1 of 4 hosted forges): 3 MiB, 2 repositories, 3 seconds, checks passed."; | |
| 38 | const SKIP = "No hosted forges to drill."; | |
| 39 | 39 | |
| 40 | 40 | beforeAll(async () => { |
| 41 | 41 | root = mkdtempSync(join(tmpdir(), "forge-drill-hosted-card-")); |
| @@ -66,21 +66,21 @@ const cardSays = async (): Promise<string | undefined> => { | ||
| 66 | 66 | return /<span data-drill-hosted>([^<]*)<\/span>/.exec(page)?.[1]; |
| 67 | 67 | }; |
| 68 | 68 | |
| 69 | test("seconds have one decimal and never go negative", () => { | |
| 70 | expect([seconds(3_240), seconds(0), seconds(59_960), seconds(-5)]).toEqual(["3.2 s", "0.0 s", "60.0 s", "0.0 s"]); | |
| 69 | test("seconds are whole, never raw ms, and never go negative", () => { | |
| 70 | expect([seconds(3_240), seconds(900), seconds(400), seconds(0), seconds(59_960), seconds(-5)]).toEqual(["3 seconds", "1 second", "1 second", "0 seconds", "60 seconds", "0 seconds"]); | |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | 73 | test("the words name the forge, its size and seconds; one forge alone and one repository read as such", () => { |
| 74 | 74 | expect(hostedDrillWords(restored)).toBe(LINE); |
| 75 | 75 | expect(hostedDrillWords({ hosted: { name: "solo", of: 1, repos: 1, bytes: 512, ms: 900 } })).toBe( |
| 76 | "Hosted forge solo (512 B) restored alone in 0.9 s: its database passed the integrity check and its 1 repository git fsck.", | |
| 76 | "Restored solo (1 of 1 hosted forge): 512 B, 1 repository, 1 second, checks passed.", | |
| 77 | 77 | ); |
| 78 | 78 | // A proof kept before the drill timed it says no time rather than a wrong one. |
| 79 | 79 | expect(hostedDrillWords({ hosted: { name: "old", of: 1, repos: 0, bytes: 2048 } })).toBe( |
| 80 | "Hosted forge old (2 KiB) restored alone: its database passed the integrity check and its 0 repositories git fsck.", | |
| 80 | "Restored old (1 of 1 hosted forge): 2 KiB, 0 repositories, checks passed.", | |
| 81 | 81 | ); |
| 82 | 82 | // A control character in a kept name cannot move the terminal's cursor. |
| 83 | expect(hostedDrillWords({ hosted: { name: "a\u001b[2Jb", of: 1, repos: 0, bytes: 0, ms: 0 } })).toStartWith("Hosted forge a?[2Jb ("); | |
| 83 | expect(hostedDrillWords({ hosted: { name: "a\u001b[2Jb", of: 1, repos: 0, bytes: 0, ms: 0 } })).toStartWith("Restored a?[2Jb ("); | |
| 84 | 84 | expect(hostedDrillWords({ hostedSkipped: true })).toBe(SKIP); |
| 85 | 85 | expect(hostedDrillWords(green)).toBeUndefined(); |
| 86 | 86 | }); |
| @@ -100,6 +100,13 @@ test("a drill with no hosted forge says it skipped the step, in one line", async | ||
| 100 | 100 | expect(hostedDrillLines({ app }).join(" ").replace(/\s+/g, " ").trim()).toBe(`Last drill: ${SKIP}`); |
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | test("a forge name is escaped on the card", async () => { | |
| 104 | recordDrill(app.db, { ...green, hosted: { name: "<b>x&y</b>", of: 2, repos: 1, bytes: 1024, ms: 2_000 } }); | |
| 105 | const page = await (await fetch(`${servers.url}/settings/backups`, { headers: { cookie } })).text(); | |
| 106 | expect(page).not.toContain("<b>x&y</b>"); | |
| 107 | expect(await cardSays()).toBe("Restored <b>x&y</b> (1 of 2 hosted forges): 1 KiB, 1 repository, 2 seconds, checks passed."); | |
| 108 | }); | |
| 109 | ||
| 103 | 110 | test("a drill kept before the hosted step says nothing of it", async () => { |
| 104 | 111 | recordDrill(app.db, green); |
| 105 | 112 | expect(await cardSays()).toBeUndefined(); |
test/snapshot-hosted-chunks.test.ts +1 −1
| @@ -266,7 +266,7 @@ describe("two nights of a host with hosted forges", () => { | ||
| 266 | 266 | // Its restore and checks are timed, and the card says them in seconds (#13919). |
| 267 | 267 | expect(Number.isSafeInteger(ms) && ms! >= 0).toBe(true); |
| 268 | 268 | expect(result.hostedSkipped).toBeUndefined(); |
| 269 | expect(hostedDrillWords(result)).toMatch(/^Hosted forge alpha \(\d+(\.\d)? (B|KiB|MiB)\) restored alone in \d+\.\d s: its database passed the integrity check and its 1 repository git fsck\.$/); | |
| 269 | expect(hostedDrillWords(result)).toMatch(/^Restored alpha \(1 of 1 hosted forge\): \d+(\.\d)? (B|KiB|MiB), 1 repository, \d+ seconds?, checks passed\.$/); | |
| 270 | 270 | // The board says the forge the drill brought back. |
| 271 | 271 | const now = at.getTime() + 3_600_000; |
| 272 | 272 | const lane = await readLane("primary", store, now); |
new above
offline
Missing full stop before "Terminal:"; the two sentences run together.