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

Closed opened this
Closed without merging

scout/forge:scout/4130-settings-backups-now-drill-error-and-res → main 3 commits fork 5 threads · 5 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +72 −39
src/web/pages/backups.ts +45 −38
@@ -41,7 +41,7 @@ import { field, readForm, type Form } from "../form.ts";
4141 import { html, when, type Html } from "../html.ts";
4242 import { liveRegionsJs } from "../client.ts";
4343 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";
4545 import { accountSections } from "./origins.ts";
4646
4747 function requireAdmin(ctx: Ctx): Response | undefined {
@@ -95,8 +95,8 @@ function keyNote(
9595 sealed value (secrets, app variables, origin tokens) is lost and must be
9696 set again.
9797 </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
100100 data together, and a restore will bring back repositories and issues but
101101 not sealed values, which must be set again.${last} To carry the key
102102 wrapped, set <code>FORGE_SNAPSHOT_PASSPHRASE</code> and restart — and
@@ -118,32 +118,29 @@ function drillTiming(d: DrillResult): string {
118118 .join(", ")}`;
119119 }
120120
121 /** The last drill in one line, and the button to run another. */
121 /** The last drill in one line. */
122122 function drillLine(ctx: Ctx): Html {
123123 const d = lastDrill(ctx.app.db);
124124 const timing = d === undefined ? "" : drillTiming(d);
125125 const line =
126126 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>`
128128 : 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 —
131131 snapshot <code>${d.snapshotId ?? ""}</code>, key opened —
132132 ${d.counts.users} users, ${d.counts.repositories} repositories, ${d.counts.issues} issues, ${d.counts.pulls} pulls, ${d.counts.apps} apps.${timing
133133 ? html` <span class="backups-timing">${timing}.</span>`
134134 : ""}
135135 </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
138138 <code>${d.snapshotId ?? "none"}</code> failed at
139139 ${d.failedStep ?? "an unknown step"} after ${d.ms} ms${d.reason
140140 ? html`: ${d.reason}`
141141 : ""}.${timing ? html` <span class="backups-timing">${timing}.</span>` : ""}
142142 </p>`;

Failed drill: reason, step and snapshot id are unbroken strings; the old .backups-drill wrapped them. Use <p class="break"> here and on the green and failed-snapshot/listing paragraphs.

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.

147144 }
148145
149146 const SNAPSHOT_FRESH_MS = 26 * 3_600_000;
@@ -192,8 +189,11 @@ export function recoverySentence(r: Recovery): string {
192189 function recoveryLine(r: Recovery): Html {
193190 const sentence = recoverySentence(r);
194191 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>
197197 </p>`;
198198 }
199199
@@ -335,8 +335,7 @@ async function movingPart(
335335 now,
336336 });
337337 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>`
340339 : null;
341340 return html`<div id="backups-live" data-live="backup.*" data-live-src="/settings/backups/live">${recovery}${card(
342341 html`<p>
outdated

A bare <pre> in .code has no padding, background or wrapping, and the scroll area cannot be focused from the keyboard. Use a component that fits a command, or add tabindex="0" and an aria-label.

@@ -358,27 +357,30 @@ bun run src/snapshot/restore.ts ${snapshots[0].name} /path/to/empty/data</pre>`
358357 ${when(
359358 failing,
360359 (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
363362 since ${time(f.since)}: ${f.error}
364363 </p>`,
365364 )}
366365 ${when(
367366 listing,
368367 (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}
371370 </p>`,
372371 )}
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)}`,
381373 {
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>`,
382384 head: html`${icon("download")}
383385 <h2>Where and when</h2>`,
384386 },
@@ -414,17 +416,19 @@ bun run src/snapshot/restore.ts ${snapshots[0].name} /path/to/empty/data</pre>`
414416 </div>
415417 </li>`,
416418 )}
417 </ul>`,
419 </ul>
420 <div class="card-body prose">
421 <p class="muted small">
outdated

The .prose div is a flex item of .card-foot, with padding on top of the foot's own. A long unbreakable command can widen it past 360px. Give it flex:1 1 100%; min-width:0, or put the restore text in the card body.

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>`,
418428 {
419429 pad: false,
420430 head: html`${icon("history")}
421431 <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}`,
428432 },
429433 )
430434 }
@@ -532,8 +536,11 @@ function mirrorCard(ctx: Ctx): Html {
532536 every snapshot is copied there within the hour.</p>`
533537 : state === undefined
534538 ? 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
537544 ${state.reachable ? "reachable" : "unreachable"} (checked
538545 ${time(state.attemptAt)}).
539546 ${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 () =
101101 rmSync(bare, { recursive: true, force: true });
102102 }
103103 });
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", () => {
102102 // The terminal's dashboard prints the forge's needs: the card is there too.
103103 expect(forgeNeeds(app, admin)?.some((l) => l.includes("The last snapshot failed"))).toBe(true);
104104 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"');
106106 expect(page.replace(/\s+/g, " ")).toContain("The last snapshot failed");
107107 expect(page).toContain("no answer in 180 s");
108108

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs