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

Merged opened this

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

Merged

scout/forge:scout/14185-the-drill-card-names-the-hosted-forge-it → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/14185-the-drill-card-names-the-hosted-forge-it was merged into main as 0416458.

Review

Sign in to review this change.
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
3434
3535 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](../RECOVERY.md)).
3636
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:`).
outdated

Missing full stop before "Terminal:"; the two sentences run together.

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.
3939 - 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.
4040
4141 ## Restore one forge
src/snapshot/drill_hosted_words.ts +18 −12
@@ -1,17 +1,22 @@
11 /**
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.
78 */
89
910 import { printable } from "./bucket.ts";
1011 import { formatBytes, type DrillResult } from "./drill.ts";
1112
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 */
1317 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"}`;
1520 }
1621
1722 /**
@@ -20,11 +25,12 @@ export function seconds(ms: number): string {
2025 export function hostedDrillWords(d: Pick<DrillResult, "hosted" | "hostedSkipped">): string | undefined {
2126 const h = d.hosted;
2227 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.`;
2733 }
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.";
2935 return undefined;
3036 }
test/drill-hosted-card.test.ts +15 −8
@@ -32,10 +32,10 @@ const green: DrillResult = {
3232 at: "2026-11-15T08:10:00.000Z", snapshotId: "s", ms: 60_000, counts: { repositories: 1, issues: 0, users: 1, pulls: 0, apps: 0 },
3333 health: "ok", verdict: "green", failedStep: null, phases: [], budgetMs: 600_000, reason: null,
3434 };
35 // 3 MiB = 3 × 1024² bytes; 3240 ms = 3.2 s.
35 // 3 MiB = 3 × 1024² bytes; 3240 ms = 3 seconds, whole.
3636 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.";
3939
4040 beforeAll(async () => {
4141 root = mkdtempSync(join(tmpdir(), "forge-drill-hosted-card-"));
@@ -66,21 +66,21 @@ const cardSays = async (): Promise<string | undefined> => {
6666 return /<span data-drill-hosted>([^<]*)<\/span>/.exec(page)?.[1];
6767 };
6868
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"]);
7171 });
7272
7373 test("the words name the forge, its size and seconds; one forge alone and one repository read as such", () => {
7474 expect(hostedDrillWords(restored)).toBe(LINE);
7575 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.",
7777 );
7878 // A proof kept before the drill timed it says no time rather than a wrong one.
7979 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.",
8181 );
8282 // 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 (");
8484 expect(hostedDrillWords({ hostedSkipped: true })).toBe(SKIP);
8585 expect(hostedDrillWords(green)).toBeUndefined();
8686 });
@@ -100,6 +100,13 @@ test("a drill with no hosted forge says it skipped the step, in one line", async
100100 expect(hostedDrillLines({ app }).join(" ").replace(/\s+/g, " ").trim()).toBe(`Last drill: ${SKIP}`);
101101 });
102102
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 &lt;b&gt;x&amp;y&lt;/b&gt; (1 of 2 hosted forges): 1 KiB, 1 repository, 2 seconds, checks passed.");
108 });
109
103110 test("a drill kept before the hosted step says nothing of it", async () => {
104111 recordDrill(app.db, green);
105112 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", () => {
266266 // Its restore and checks are timed, and the card says them in seconds (#13919).
267267 expect(Number.isSafeInteger(ms) && ms! >= 0).toBe(true);
268268 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\.$/);
270270 // The board says the forge the drill brought back.
271271 const now = at.getTime() + 3_600_000;
272272 const lane = await readLane("primary", store, now);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs