Public: anyone can read this; the crew can change it.

small: the restore drill card and the other cards that show a duration read it in words, not milliseconds #15217

Merged opened this

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

Merged

scout/forge:scout/15216-small-the-restore-drill-card-and-the-oth → main 4 commits fork 3 threads · 3 unresolved

  • Merged. scout/15216-small-the-restore-drill-card-and-the-oth was merged into main as 8943536.

Review

Sign in to review this change.
7 files changed +38 −7
src/snapshot/store.ts +5 −2
@@ -8,6 +8,7 @@
88
99 import { mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
1010 import { dirname, join, relative } from "node:path";
11 import { durationWords } from "../system/format.ts";
1112 import { lineMeter, measuredDeadlineMs, type LineMeter } from "./line.ts";
1213
1314 export interface Store {
@@ -257,12 +258,14 @@ export function withRetries(
257258 * stops sending (#13733: an abandoned put went on uploading beside the
258259 * fourteen tries after it); its outcome is ignored either way.
259260 */
261 /** What a call that got no answer says, the wait in words: "no answer in 3 minutes". */
262 export const noAnswerIn = (ms: number): string => `no answer in ${ms < 1000 ? `${Math.round(ms)} ms` : durationWords(ms)}`;

Non-blocking: noAnswerIn now sits between answered's doc comment and answered. Move it above that comment, and reuse spanWords for the sub-second case.

263
260264 function answered<T>(start: (signal: AbortSignal) => Promise<T>, ms: number): Promise<T> {
261265 let timer: ReturnType<typeof setTimeout> | undefined;
262 const shown = ms >= 1000 ? `${Math.round(ms / 1000)} s` : `${ms} ms`;
263266 const control = new AbortController();
264267 const deadline = new Promise<never>((_, reject) => {
265 timer = setTimeout(() => reject(new Error(`no answer in ${shown}`)), ms);
268 timer = setTimeout(() => reject(new Error(noAnswerIn(ms))), ms);
266269 });
267270 // The deadline's own rejection aborts the attempt, so the timer stays the
268271 // plain reject that test/timers-named.test.ts allows by name.
src/system/format.ts +7
@@ -32,3 +32,10 @@ export const durationWords = (ms: number): string => {
3232 const at = parts.findIndex(([n]) => n > 0);
3333 return parts.slice(at, at + 2).filter(([n]) => n > 0).map(([n, w]) => unit(n, w)).join(" ");
3434 };
35
36 /**
37 * A duration for a card: under a second stays "340 ms" (words would say nothing), a second or more
38 * reads through `durationWords`.
39 */
40 export const spanWords = (ms: number): string =>
41 Number.isFinite(ms) && ms >= 0 && ms < 1000 ? `${Math.round(ms)} ms` : durationWords(ms);
src/tui/screens/keeper.ts +2 −1
@@ -20,6 +20,7 @@ import { secondsWords, withLandedToLive, type LandedRelease } from "../../keeper
2020 import { releaseNowAs, pendingNow } from "../../keeper/now.ts";
2121 import { listKeeperReleases, type Stage } from "../../keeper/record.ts";
2222 import { mayRead, mayRollBack } from "../../release/gate.ts";
23 import { spanWords } from "../../system/format.ts";
2324 import type { Ctx, Screen } from "../app/app.ts";
2425 import { binding } from "../app/keys.ts";
2526 import type { Session } from "../session.ts";
@@ -79,7 +80,7 @@ export function keeperRows(releases: readonly LandedRelease[]): ListRow[] {
7980 `known good ${r.knownGood.version}`,
8081 `roll ${r.rollNon200}/${r.rollProbes} non-200`,
8182 `${r.probes} probes, ${r.pages} pages`,
82 `worst ${r.worstMs} ms`,
83 `worst ${spanWords(r.worstMs)}`,
8384 r.worstStallMs === 0 ? "" : `boot stall ${stallWords(r.worstStallMs, releases[i + 1]?.worstStallMs)}`,
8485 `${r.secondsDark} s dark`,
8586 r.writePauseMs === null ? "" : `write pause ${pauseWords(r.writePauseMs)}`,
src/web/pages/features.ts +2 −1
@@ -29,6 +29,7 @@ import { DAYS } from "../../apps/feature.ts";
2929 import type { FeedItem } from "../../feed/rank.ts";
3030 import type { Ctx } from "../../http/context.ts";
3131 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
32 import { spanWords } from "../../system/format.ts";
3233 import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts";
3334 import { readForm, type Form } from "../form.ts";
3435 import { html, raw, when } from "../html.ts";
@@ -226,7 +227,7 @@ function historyByTool(history: readonly Run[]): [string, Run[]][] {
226227
227228 const historyRow = (r: Run) => row({
228229 title: html`${r.how}`,
229 meta: html`${time(new Date(r.at).toISOString(), { date: true })} · ${r.ok ? "ok" : html`<span class="danger">${r.error ?? "failed"}</span>`}${r.how === "skipped" ? "" : ` · ${r.durationMs} ms`}`,
230 meta: html`${time(new Date(r.at).toISOString(), { date: true })} · ${r.ok ? "ok" : html`<span class="danger">${r.error ?? "failed"}</span>`}${r.how === "skipped" ? "" : ` · ${spanWords(r.durationMs)}`}`,
230231 });
231232
232233 function featureView(ctx: Ctx, f: FeatureView, refused?: Refused, items: readonly FeedItem[] = []): Response {
src/web/pages/keeper-panel.ts +2 −1
@@ -16,6 +16,7 @@ import { pauseWords } from "../../keeper/pause.ts";
1616 import { secondsWords, stagesLine, withLandedToLive } from "../../keeper/landed.ts";
1717 import { listKeeperReleases, type Stage } from "../../keeper/record.ts";
1818 import { stallWords } from "../../perf/boot_stall.ts";
19 import { spanWords } from "../../system/format.ts";
1920 import { html, when, type Html } from "../html.ts";
2021 import { badge, btn, time, type Tone } from "../ui.ts";
2122
@@ -52,7 +53,7 @@ export function keeperPanel(db: Database, mayHold = false, now: Date = new Date(
5253 <td>${r.knownGood.version}</td>
5354 <td>${r.rollNon200} of ${r.rollProbes}</td>
5455 <td>${r.probes} / ${r.pages}</td>
55 <td>${r.worstMs} ms</td>
56 <td>${spanWords(r.worstMs)}</td>
5657 <td>${stallWords(r.worstStallMs, releases[i + 1]?.worstStallMs)}</td>
5758 <td>${r.secondsDark} s</td>
5859 <td>${r.writePauseMs === null ? "–" : pauseWords(r.writePauseMs)}</td>
src/web/studio/schedules.ts +2 −1
@@ -11,6 +11,7 @@
1111 import { requireWriter } from "../../actions/access.ts";
1212 import { scheduleRows, steerSchedule, when } from "../../actions/schedules.ts";
1313 import { getAppByRepo } from "../../core/apps.ts";
14 import { spanWords } from "../../system/format.ts";
1415 import type { Repo } from "../../core/repos.ts";
1516 import type { Ctx } from "../../http/context.ts";
1617 import { loadRepo, notFoundPage, repoBase } from "../chrome.ts";
@@ -36,7 +37,7 @@ export function schedulesCard(ctx: Ctx, repo: Repo): Html | null {
3637 <span class="muted">· ${r.cron} ${r.timezone} → <code>${r.path}</code></span><br>
3738 ${r.last === null
3839 ? html`<span class="muted">never run</span>`
39 : html`last ${when(r.last.at, r.timezone)}: ${badge(r.last.status, { variant: "outline" })} ${r.last.status === "ok" ? html`${r.last.durationMs} ms` : html`<span class="break">${r.last.error ?? ""}</span>`}${r.last.late === null ? null : html` <span class="muted">· ran late: ${r.last.late}</span>`}`}
40 : html`last ${when(r.last.at, r.timezone)}: ${badge(r.last.status, { variant: "outline" })} ${r.last.status === "ok" ? html`${spanWords(r.last.durationMs)}` : html`<span class="break">${r.last.error ?? ""}</span>`}${r.last.late === null ? null : html` <span class="muted">· ran late: ${r.last.late}</span>`}`}
4041 ${writer ? html`<br>${act("run", "Run now")} ${r.paused ? act("resume", "Resume") : act("pause", "Pause")}` : null}</dd>`;
4142 })}
4243 </dl>
test/format-duration.test.ts +18 −1
@@ -1,5 +1,7 @@
11 import { expect, test } from "bun:test";
2 import { durationWords } from "../src/system/format.ts";
2 import { noAnswerIn } from "../src/snapshot/store.ts";
3 import { plainDurations } from "../src/snapshot/verdict.ts";
4 import { durationWords, spanWords } from "../src/system/format.ts";
35 import { costFacts, costLine } from "../src/snapshot/drill_cost.ts";
46 import { spokenSpan } from "../src/snapshot/drill_card_words.ts";
57
@@ -21,3 +23,18 @@ test("the drill card's words and cost line come from durationWords", () => {
2123 expect(costFacts({ cost })[0]?.value).toBe("1 hour 5 minutes");
2224 expect(spokenSpan(3_900_000)).toBe("1 hour 5 minutes");
2325 });
26
outdated

This test passes on the base, so it fails to prove the change (box 3). Test something that fails without the diff.

27 test("the store's no-answer error reads 180000 ms in words, and the drill card keeps it so", () => {
28 expect(noAnswerIn(180_000)).toBe("no answer in 3 minutes");
29 expect(noAnswerIn(340)).toBe("no answer in 340 ms");
30 const card = plainDurations(`restore timed out: ${noAnswerIn(180_000)}`);
31 expect(card).toContain("3 minutes");
32 expect(card).not.toContain("180000 ms");
33 expect(card).not.toContain("180 s");
34 });
35
36 test("spanWords keeps sub-second values in ms and reads the rest in words", () => {
37 expect(spanWords(340)).toBe("340 ms");
38 expect(spanWords(180_000)).toBe("3 minutes");
39 expect(spanWords(1500)).toBe("2 seconds");
40 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs