Public: anyone can read this; the crew can change it.
/settings/backups' now, drill, error and restore parts draw §5's card, row, badge and btn, and .backups-drill, .backups-error, .backups-now, .backups-restore leave the markup #4158
scout/forge:scout/4130-settings-backups-now-drill-error-and-res → main 3 commits fork 5 threads · 5 unresolved
src/web/pages/backups.ts +45 −38
| @@ -41,7 +41,7 @@ import { field, readForm, type Form } from "../form.ts"; | ||
| 41 | 41 | import { html, when, type Html } from "../html.ts"; |
| 42 | 42 | import { liveRegionsJs } from "../client.ts"; |
| 43 | 43 | import { flashTo, fragment, page, redirect } from "../layout.ts"; |
| 44 | import { btn, card, empty, fileSize, icon, row, time } from "../ui.ts"; | |
| 44 | import { badge, btn, card, empty, fileSize, icon, row, time } from "../ui.ts"; | |
| 45 | 45 | import { accountSections } from "./origins.ts"; |
| 46 | 46 | |
| 47 | 47 | function requireAdmin(ctx: Ctx): Response | undefined { |
| @@ -95,8 +95,8 @@ function keyNote( | ||
| 95 | 95 | sealed value (secrets, app variables, origin tokens) is lost and must be |
| 96 | 96 | set again. |
| 97 | 97 | </p>` |
| 98 | : html`<p class="backups-error"> | |
| 99 | ${icon("alert")} Snapshots carry no key: the bucket never holds key and | |
| 98 | : html`<p> | |
| 99 | ${badge("No key", { tone: "danger", icon: "alert" })} Snapshots carry no key: the bucket never holds key and | |
| 100 | 100 | data together, and a restore will bring back repositories and issues but |
| 101 | 101 | not sealed values, which must be set again.${last} To carry the key |
| 102 | 102 | wrapped, set <code>FORGE_SNAPSHOT_PASSPHRASE</code> and restart — and |
| @@ -118,32 +118,29 @@ function drillTiming(d: DrillResult): string { | ||
| 118 | 118 | .join(", ")}`; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | /** The last drill in one line, and the button to run another. */ | |
| 121 | /** The last drill in one line. */ | |
| 122 | 122 | function drillLine(ctx: Ctx): Html { |
| 123 | 123 | const d = lastDrill(ctx.app.db); |
| 124 | 124 | const timing = d === undefined ? "" : drillTiming(d); |
| 125 | 125 | const line = |
| 126 | 126 | d === undefined |
| 127 | ? html`<p class="backups-drill">No restore drill has run yet.</p>` | |
| 127 | ? html`<p>No restore drill has run yet.</p>` | |
| 128 | 128 | : d.verdict === "green" |
| 129 | ? html`<p class="backups-drill"> | |
| 130 | ${icon("check")} Last drill: ${time(d.at)}, ${d.ms} ms, all counts matched — | |
| 129 | ? html`<p> | |
| 130 | ${badge("Green", { tone: "success", icon: "check" })} Last drill: ${time(d.at)}, ${d.ms} ms, all counts matched — | |
| 131 | 131 | snapshot <code>${d.snapshotId ?? ""}</code>, key opened — |
| 132 | 132 | ${d.counts.users} users, ${d.counts.repositories} repositories, ${d.counts.issues} issues, ${d.counts.pulls} pulls, ${d.counts.apps} apps.${timing |
| 133 | 133 | ? html` <span class="backups-timing">${timing}.</span>` |
| 134 | 134 | : ""} |
| 135 | 135 | </p>` |
| 136 | : html`<p class="backups-error backups-drill"> | |
| 137 | ${icon("alert")} Last drill ${time(d.at)}: snapshot | |
| 136 | : html`<p> | |
| 137 | ${badge("Failed", { tone: "danger", icon: "alert" })} Last drill ${time(d.at)}: snapshot | |
| 138 | 138 | <code>${d.snapshotId ?? "none"}</code> failed at |
| 139 | 139 | ${d.failedStep ?? "an unknown step"} after ${d.ms} ms${d.reason |
| 140 | 140 | ? html`: ${d.reason}` |
| 141 | 141 | : ""}.${timing ? html` <span class="backups-timing">${timing}.</span>` : ""} |
| 142 | 142 | </p>`; |
| 143 | return html`${line} | |
| 144 | <form method="post" action="/settings/backups/drill" class="backups-now"> | |
| 145 | ${btn("Run a drill", { type: "submit", icon: "clock" })} | |
| 146 | </form>`; | |
| 143 | return line; | |
outdated
This form lost its 12px top margin, so the button now sits against the line above it. Put the spacing in a named component. |
||
| 147 | 144 | } |
| 148 | 145 | |
| 149 | 146 | const SNAPSHOT_FRESH_MS = 26 * 3_600_000; |
| @@ -192,8 +189,11 @@ export function recoverySentence(r: Recovery): string { | ||
| 192 | 189 | function recoveryLine(r: Recovery): Html { |
| 193 | 190 | const sentence = recoverySentence(r); |
| 194 | 191 | const ok = sentence === "Recoverable now"; |
| 195 | return html`<p class="backups-recovery${ok ? "" : " backups-error"}" role="status"> | |
| 196 | ${icon(ok ? "check" : "alert")} <strong>${sentence}</strong> | |
| 192 | return html`<p class="backups-recovery" role="status"> | |
| 193 | ${badge(ok ? "Ready" : "At risk", { | |
outdated
An empty badge draws a bare icon pill. Give it a word ('Ready' or 'At risk') so the tone is not carried by colour and icon alone. |
||
| 194 | tone: ok ? "success" : "danger", | |
| 195 | icon: ok ? "check" : "alert", | |
| 196 | })} <strong>${sentence}</strong> | |
| 197 | 197 | </p>`; |
| 198 | 198 | } |
| 199 | 199 | |
| @@ -335,8 +335,7 @@ async function movingPart( | ||
| 335 | 335 | now, |
| 336 | 336 | }); |
| 337 | 337 | const restore = snapshots[0] |
| 338 | ? html`<pre class="backups-restore"> | |
| 339 | bun run src/snapshot/restore.ts ${snapshots[0].name} /path/to/empty/data</pre>` | |
| 338 | ? html`<pre tabindex="0" aria-label="Restore command"><code>bun run src/snapshot/restore.ts ${snapshots[0].name} /path/to/empty/data</code></pre>` | |
| 340 | 339 | : null; |
| 341 | 340 | return html`<div id="backups-live" data-live="backup.*" data-live-src="/settings/backups/live">${recovery}${card( |
| 342 | 341 | html`<p> |
outdated
A bare |
||
| @@ -358,27 +357,30 @@ bun run src/snapshot/restore.ts ${snapshots[0].name} /path/to/empty/data</pre>` | ||
| 358 | 357 | ${when( |
| 359 | 358 | failing, |
| 360 | 359 | (f) => |
| 361 | html`<p class="backups-error" role="alert"> | |
| 362 | ${icon("alert")} The last snapshot failed ${time(f.at)}, failing | |
| 360 | html`<p role="alert"> | |
| 361 | ${badge("Failed", { tone: "danger", icon: "alert" })} The last snapshot failed ${time(f.at)}, failing | |
| 363 | 362 | since ${time(f.since)}: ${f.error} |
| 364 | 363 | </p>`, |
| 365 | 364 | )} |
| 366 | 365 | ${when( |
| 367 | 366 | listing, |
| 368 | 367 | (error) => |
| 369 | html`<p class="backups-error"> | |
| 370 | ${icon("alert")} The store could not be listed just now: ${error} | |
| 368 | html`<p> | |
| 369 | ${badge("Unlisted", { tone: "danger", icon: "alert" })} The store could not be listed just now: ${error} | |
| 371 | 370 | </p>`, |
| 372 | 371 | )} |
| 373 | ${drillLine(ctx)} | |
| 374 | <form method="post" action="/settings/backups/now" class="backups-now"> | |
| 375 | ${btn("Snapshot now", { | |
| 376 | type: "submit", | |
| 377 | variant: "primary", | |
| 378 | icon: "download", | |
| 379 | })} | |
| 380 | </form>`, | |
| 372 | ${drillLine(ctx)}`, | |
| 381 | 373 | { |
| 374 | foot: html`<form method="post" action="/settings/backups/now"> | |
| 375 | ${btn("Snapshot now", { | |
| 376 | type: "submit", | |
| 377 | variant: "primary", | |
| 378 | icon: "download", | |
| 379 | })} | |
| 380 | </form> | |
| 381 | <form method="post" action="/settings/backups/drill"> | |
| 382 | ${btn("Run a drill", { type: "submit", icon: "clock" })} | |
| 383 | </form>`, | |
| 382 | 384 | head: html`${icon("download")} |
| 383 | 385 | <h2>Where and when</h2>`, |
| 384 | 386 | }, |
| @@ -414,17 +416,19 @@ bun run src/snapshot/restore.ts ${snapshots[0].name} /path/to/empty/data</pre>` | ||
| 414 | 416 | </div> |
| 415 | 417 | </li>`, |
| 416 | 418 | )} |
| 417 | </ul>`, | |
| 419 | </ul> | |
| 420 | <div class="card-body prose"> | |
| 421 | <p class="muted small"> | |
outdated
The |
||
| 422 | To restore, stop a forge, point it at an empty data directory, | |
| 423 | and run this with the same S3_* variables or | |
| 424 | FORGE_SNAPSHOT_DIR: | |
| 425 | </p> | |
| 426 | ${restore} | |
| 427 | </div>`, | |
| 418 | 428 | { |
| 419 | 429 | pad: false, |
| 420 | 430 | head: html`${icon("history")} |
| 421 | 431 | <h2>Snapshots</h2>`, |
| 422 | foot: html`<span class="muted small" | |
| 423 | >To restore, stop a forge, point it at an empty data | |
| 424 | directory, and run this with the same S3_* variables or | |
| 425 | FORGE_SNAPSHOT_DIR:</span | |
| 426 | > | |
| 427 | ${restore}`, | |
| 428 | 432 | }, |
| 429 | 433 | ) |
| 430 | 434 | } |
| @@ -532,8 +536,11 @@ function mirrorCard(ctx: Ctx): Html { | ||
| 532 | 536 | every snapshot is copied there within the hour.</p>` |
| 533 | 537 | : state === undefined |
| 534 | 538 | ? html`<p>Mirroring to <code>${svc!.mirror!.where}</code>; the first pass has not run yet.</p>` |
| 535 | : html`<p class="${need ? "backups-error" : ""}"> | |
| 536 | ${icon(need ? "alert" : "check")} <code>${state.where}</code> is | |
| 539 | : html`<p> | |
| 540 | ${badge(need ? "Behind" : "Level", { | |
| 541 | tone: need ? "danger" : "success", | |
| 542 | icon: need ? "alert" : "check", | |
| 543 | })} <code>${state.where}</code> is | |
| 537 | 544 | ${state.reachable ? "reachable" : "unreachable"} (checked |
| 538 | 545 | ${time(state.attemptAt)}). |
| 539 | 546 | ${state.newest |
test/backups-timing.test.ts +26
| @@ -101,3 +101,29 @@ test("with no snapshot store the page names only the reads it makes", async () = | ||
| 101 | 101 | rmSync(bare, { recursive: true, force: true }); |
| 102 | 102 | } |
| 103 | 103 | }); |
| 104 | ||
| 105 | test("the page draws its now, drill, error and restore parts from the shared components", async () => { | |
| 106 | await svc.now(); | |
| 107 | const page = await (await fetch(`${servers.url}/settings/backups`, { headers: { cookie } })).text(); | |
| 108 | for (const old of ["backups-drill", "backups-error", "backups-now", "backups-restore"]) | |
| 109 | expect(page).not.toContain(old); | |
| 110 | const flat = page.replace(/\s+/g, " "); | |
| 111 | expect(flat).toContain("No restore drill has run yet."); | |
| 112 | expect(flat).toContain("bun run src/snapshot/restore.ts"); | |
| 113 | expect(page).toContain('<pre tabindex="0" aria-label="Restore command">'); | |
| 114 | // The restore box is in the card body, not a bare child of the flex foot. | |
| 115 | expect(flat).toMatch(/class="card-body prose">\s*<p class="muted small">\s*To restore/); | |
| 116 | expect(flat).not.toMatch(/card-foot">\s*<div class="prose"/); | |
| 117 | expect(page).toContain('data-variant="danger"'); | |
| 118 | for (const [action, label] of [ | |
| 119 | ["/settings/backups/now", "Snapshot now"], | |
| 120 | ["/settings/backups/drill", "Run a drill"], | |
| 121 | ] as const) { | |
| 122 | const form = new RegExp(`<form method="post" action="${action}">[\\s\\S]*?</form>`).exec(page)?.[0]; | |
| 123 | expect(form).toBeDefined(); | |
| 124 | expect(form).toContain('class="btn"'); | |
| 125 | expect(form).toContain(label); | |
| 126 | } | |
| 127 | // The buttons live in the card's foot, which owns their spacing. | |
| 128 | expect(flat).toMatch(/card-foot">\s*<form method="post" action="\/settings\/backups\/now">/); | |
| 129 | }); |
test/snapshot-outcome.test.ts +1 −1
| @@ -102,7 +102,7 @@ describe("a nightly that fails", () => { | ||
| 102 | 102 | // The terminal's dashboard prints the forge's needs: the card is there too. |
| 103 | 103 | expect(forgeNeeds(app, admin)?.some((l) => l.includes("The last snapshot failed"))).toBe(true); |
| 104 | 104 | const page = await (await fetch(`${servers.url}/settings/backups`, { headers: { cookie } })).text(); |
| 105 | expect(page).toContain("backups-error"); | |
| 105 | expect(page).toContain('data-variant="danger"'); | |
| 106 | 106 | expect(page.replace(/\s+/g, " ")).toContain("The last snapshot failed"); |
| 107 | 107 | expect(page).toContain("no answer in 180 s"); |
| 108 | 108 |
Failed drill: reason, step and snapshot id are unbroken strings; the old
.backups-drillwrapped them. Use<p class="break">here and on the green and failed-snapshot/listing paragraphs.