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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15216-small-the-restore-drill-card-and-the-oth → main 4 commits fork 3 threads · 3 unresolved
7 files
changed +38
−7
src/snapshot/store.ts +5 −2
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | import { mkdirSync, readdirSync, rmSync, statSync } from "node:fs"; |
| 10 | 10 | import { dirname, join, relative } from "node:path"; |
| 11 | import { durationWords } from "../system/format.ts"; | |
| 11 | 12 | import { lineMeter, measuredDeadlineMs, type LineMeter } from "./line.ts"; |
| 12 | 13 | |
| 13 | 14 | export interface Store { |
| @@ -257,12 +258,14 @@ export function withRetries( | ||
| 257 | 258 | * stops sending (#13733: an abandoned put went on uploading beside the |
| 258 | 259 | * fourteen tries after it); its outcome is ignored either way. |
| 259 | 260 | */ |
| 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)}`; | |
| 263 | ||
| 260 | 264 | function answered<T>(start: (signal: AbortSignal) => Promise<T>, ms: number): Promise<T> { |
| 261 | 265 | let timer: ReturnType<typeof setTimeout> | undefined; |
| 262 | const shown = ms >= 1000 ? `${Math.round(ms / 1000)} s` : `${ms} ms`; | |
| 263 | 266 | const control = new AbortController(); |
| 264 | 267 | 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); | |
| 266 | 269 | }); |
| 267 | 270 | // The deadline's own rejection aborts the attempt, so the timer stays the |
| 268 | 271 | // 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 => { | ||
| 32 | 32 | const at = parts.findIndex(([n]) => n > 0); |
| 33 | 33 | return parts.slice(at, at + 2).filter(([n]) => n > 0).map(([n, w]) => unit(n, w)).join(" "); |
| 34 | 34 | }; |
| 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 | ||
| 20 | 20 | import { releaseNowAs, pendingNow } from "../../keeper/now.ts"; |
| 21 | 21 | import { listKeeperReleases, type Stage } from "../../keeper/record.ts"; |
| 22 | 22 | import { mayRead, mayRollBack } from "../../release/gate.ts"; |
| 23 | import { spanWords } from "../../system/format.ts"; | |
| 23 | 24 | import type { Ctx, Screen } from "../app/app.ts"; |
| 24 | 25 | import { binding } from "../app/keys.ts"; |
| 25 | 26 | import type { Session } from "../session.ts"; |
| @@ -79,7 +80,7 @@ export function keeperRows(releases: readonly LandedRelease[]): ListRow[] { | ||
| 79 | 80 | `known good ${r.knownGood.version}`, |
| 80 | 81 | `roll ${r.rollNon200}/${r.rollProbes} non-200`, |
| 81 | 82 | `${r.probes} probes, ${r.pages} pages`, |
| 82 | `worst ${r.worstMs} ms`, | |
| 83 | `worst ${spanWords(r.worstMs)}`, | |
| 83 | 84 | r.worstStallMs === 0 ? "" : `boot stall ${stallWords(r.worstStallMs, releases[i + 1]?.worstStallMs)}`, |
| 84 | 85 | `${r.secondsDark} s dark`, |
| 85 | 86 | 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"; | ||
| 29 | 29 | import type { FeedItem } from "../../feed/rank.ts"; |
| 30 | 30 | import type { Ctx } from "../../http/context.ts"; |
| 31 | 31 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 32 | import { spanWords } from "../../system/format.ts"; | |
| 32 | 33 | import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts"; |
| 33 | 34 | import { readForm, type Form } from "../form.ts"; |
| 34 | 35 | import { html, raw, when } from "../html.ts"; |
| @@ -226,7 +227,7 @@ function historyByTool(history: readonly Run[]): [string, Run[]][] { | ||
| 226 | 227 | |
| 227 | 228 | const historyRow = (r: Run) => row({ |
| 228 | 229 | 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)}`}`, | |
| 230 | 231 | }); |
| 231 | 232 | |
| 232 | 233 | 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"; | ||
| 16 | 16 | import { secondsWords, stagesLine, withLandedToLive } from "../../keeper/landed.ts"; |
| 17 | 17 | import { listKeeperReleases, type Stage } from "../../keeper/record.ts"; |
| 18 | 18 | import { stallWords } from "../../perf/boot_stall.ts"; |
| 19 | import { spanWords } from "../../system/format.ts"; | |
| 19 | 20 | import { html, when, type Html } from "../html.ts"; |
| 20 | 21 | import { badge, btn, time, type Tone } from "../ui.ts"; |
| 21 | 22 | |
| @@ -52,7 +53,7 @@ export function keeperPanel(db: Database, mayHold = false, now: Date = new Date( | ||
| 52 | 53 | <td>${r.knownGood.version}</td> |
| 53 | 54 | <td>${r.rollNon200} of ${r.rollProbes}</td> |
| 54 | 55 | <td>${r.probes} / ${r.pages}</td> |
| 55 | <td>${r.worstMs} ms</td> | |
| 56 | <td>${spanWords(r.worstMs)}</td> | |
| 56 | 57 | <td>${stallWords(r.worstStallMs, releases[i + 1]?.worstStallMs)}</td> |
| 57 | 58 | <td>${r.secondsDark} s</td> |
| 58 | 59 | <td>${r.writePauseMs === null ? "–" : pauseWords(r.writePauseMs)}</td> |
src/web/studio/schedules.ts +2 −1
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | import { requireWriter } from "../../actions/access.ts"; |
| 12 | 12 | import { scheduleRows, steerSchedule, when } from "../../actions/schedules.ts"; |
| 13 | 13 | import { getAppByRepo } from "../../core/apps.ts"; |
| 14 | import { spanWords } from "../../system/format.ts"; | |
| 14 | 15 | import type { Repo } from "../../core/repos.ts"; |
| 15 | 16 | import type { Ctx } from "../../http/context.ts"; |
| 16 | 17 | import { loadRepo, notFoundPage, repoBase } from "../chrome.ts"; |
| @@ -36,7 +37,7 @@ export function schedulesCard(ctx: Ctx, repo: Repo): Html | null { | ||
| 36 | 37 | <span class="muted">· ${r.cron} ${r.timezone} → <code>${r.path}</code></span><br> |
| 37 | 38 | ${r.last === null |
| 38 | 39 | ? 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>`}`} | |
| 40 | 41 | ${writer ? html`<br>${act("run", "Run now")} ${r.paused ? act("resume", "Resume") : act("pause", "Pause")}` : null}</dd>`; |
| 41 | 42 | })} |
| 42 | 43 | </dl> |
test/format-duration.test.ts +18 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | 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"; | |
| 3 | 5 | import { costFacts, costLine } from "../src/snapshot/drill_cost.ts"; |
| 4 | 6 | import { spokenSpan } from "../src/snapshot/drill_card_words.ts"; |
| 5 | 7 | |
| @@ -21,3 +23,18 @@ test("the drill card's words and cost line come from durationWords", () => { | ||
| 21 | 23 | expect(costFacts({ cost })[0]?.value).toBe("1 hour 5 minutes"); |
| 22 | 24 | expect(spokenSpan(3_900_000)).toBe("1 hour 5 minutes"); |
| 23 | 25 | }); |
| 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 | }); |
new above
offline
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.