Public: anyone can read this; the crew can change it.
Each home figure tile opens the board that draws it, at the tile's range, and shows its change against the previous period #17017
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16937-each-home-figure-tile-opens-the-board-th → main 0 commits fork 2 threads · 2 unresolved
18 files
changed +341
−44
- docs/design/areas/home-flow.md
- docs/features/living-home.md
- src/boards/guide.ts
- src/boards/panel_data.ts
- src/boards/sources.ts
- src/boards/starting.ts
- src/boards/store.ts
- src/flow/figure_change.ts
- src/flow/figures.ts
- src/flow/reach.ts
- src/web/pages/boards-view.ts
- src/web/pages/home_figures.ts
- src/web/pages/home_flow_style.ts
- test/boards-starting.test.ts
- test/boards-view-bar.test.ts
- test/home-figure-tiles.test.ts
- test/home-no-shift.test.ts
- test/home-tile-board-offered.test.ts
docs/design/areas/home-flow.md +1
| @@ -44,6 +44,7 @@ One section under the lanes or the table (`web/pages/home_figures.ts`), an admin | ||
| 44 | 44 | - `.fg-grid` — the cards, as many 220px columns as fit. |
| 45 | 45 | - `.fg-body` — the figures' live region; holds one row of cards (172px, summed from the card's own rules) before they arrive, so nothing below moves. |
| 46 | 46 | - `.fg-card`, `.fg-label`, `.fg-value`, `.fg-n`, `.fg-unit`, `.fg-note` — a card: a name, the value with its unit, a note on two reserved lines so a row of cards is as tall as its tallest and nothing shifts. A card with a tone `attn` is the figure that is near or past a limit. |
| 47 | - `.fg-change` — a card's change against the window before it (`+12 vs prior 14 days`), muted, one 16px line; a card with no prior keeps the line as an empty `aria-hidden` block, so nothing is announced and no card changes height. | |
| 47 | 48 | - `.fg-chart`, `.fg-svg`, `.fg-line`, `.fg-area`, `.fg-base`, `.fg-dot`, `.fg-axis` — the one chart: a line over a faint area in the accent, scaled from zero to the series' own peak, a day with no value breaking the line; its two ends named underneath (`14 days ago`, `today`); a card with no daily series keeps the same 32px, empty. |
| 48 | 49 | - `.fs`, `.fs-sum`, `.fs-svg`, `.fs-bar`, `.fs-count`, `.fs-base`, `.fs-h`, `.fs-slow`, `.fs-item`, `.fs-took`, `.fs-why`, `.fs-assume` — ship time under the cards (`web/pages/home_ship.ts`): a disclosure whose summary is the sentence (44px), a histogram drawn as SVG on the server in the muted foreground (seven fixed ranges, counts above the bars), the slowest tenth as a list of links with what the time went to, and the assumptions in a muted line. Closed by default; the live region reserves its row. |
| 49 | 50 | - `.fg-reading` — the line a region shows before the first reading. |
docs/features/living-home.md +4
| @@ -27,3 +27,7 @@ The feed — the composer, the timeline, what is on you, since you were here — | ||
| 27 | 27 | Under the figures, an admin's one card, "Crew, last 30 days": the days without a red main (`3 days without a red main`; "Main is red now" while it is), then a row per crew member who landed something: `4 landed · 75% green first pass · 25% rework`, each row a link to that member's page (`/settings/crew/<name>`). *First pass green* is the share of its landed pulls whose first finished check was green; *rework* the share that drew a change request or a revert; the counts are the scorecard's (`crewScorecards`). A forge where nothing landed says so in one calm sentence. It is shown, never notified: no alarm, no toast. A worker reads it with the figures (`src/flow/crew_card.ts`, every 30 s), so a request reads memory and the card redraws with the figures' region; nothing polls. |
| 28 | 28 | |
| 29 | 29 | The terminal's home carries the same lines for an admin, under the figures: the streak, then one line per member (`src/flow/crew_card.ts`, `crewCardLines`). |
| 30 | ||
| 31 | ## Each figure tile opens its board (#16937) | |
| 32 | ||
| 33 | A tile on the home's figures is a number, its change against the window before it, a chart, and a link to the one board that draws that figure at the tile's own window: Changes merged, Crew spend and Check time open `/boards/delivery?range=14d`; Visitors and Page speed open `/boards/reach?range=7d`; Open bugs opens Delivery's "Open bugs" panel. (`14d` is a board range like the others; `Delivery` is a starting board, offered on a forge's next boot.) The change reads `+12 vs prior 14 days`, `−3 vs prior 7 days` or `No change vs prior 14 days`, in the figure's own units and in the same quiet grey whichever way it swings: more is not always better, so nothing is red. A tile with nothing earlier to compare has no change line (the space is kept, so nothing moves). Check time's change is the median over the 14 days against the 14 before. The terminal has no tiles; open the same boards from its boards screen (`boards`), where `r` steps the range. |
src/boards/guide.ts +3 −1
| @@ -45,6 +45,8 @@ export const GUIDE: Readonly<Record<string, Guide>> = { | ||
| 45 | 45 | queueVerdicts: { name: "Red merge batches", rows: "verdicts", kind: "events" }, |
| 46 | 46 | maintenanceRuns: { name: "Maintenance runs", rows: "duty runs", kind: "events" }, |
| 47 | 47 | maintenanceProbes: { name: "Maintenance probes", rows: "probe readings", kind: "samples", value: "number" }, |
| 48 | checks: { name: "Check time", rows: "finished checks", kind: "samples", value: "minutes" }, | |
| 49 | bugs: { name: "Open bugs", rows: "open bugs", kind: "events" }, | |
| 48 | 50 | stages: { name: "Work by stage", rows: "items entering a stage", kind: "events" }, |
| 49 | 51 | }; |
| 50 | 52 | |
| @@ -72,7 +74,7 @@ const UNITS: Readonly<Record<string, string>> = { | ||
| 72 | 74 | memory_bytes: "bytes", memory_bytes_max: "bytes", load: "runnable tasks", celsius: "°C", celsius_max: "°C", |
| 73 | 75 | lag_ms: "ms", lag_ms_max: "ms", checks: "runs", agents: "runs", load_p75: "ms", inp_p75: "ms", reports: "reports", |
| 74 | 76 | roll_probes: "probes", roll_non200: "probes", probes: "probes", pages: "pages", bad_in_row: "probes", worst_ms: "ms", |
| 75 | seconds_dark: "seconds", pull_number: "pull number", value: "a count, ms or score by metric", | |
| 77 | seconds_dark: "seconds", minutes: "minutes", pull_number: "pull number", value: "a count, ms or score by metric", | |
| 76 | 78 | }; |
| 77 | 79 | const UNIT_OF: Readonly<Record<string, Readonly<Record<string, string>>>> = { |
| 78 | 80 | reach: { value: "visitors, ms or a score, by metric" }, |
src/boards/panel_data.ts +1 −1
| @@ -12,7 +12,7 @@ import { drawChart, usesSeries, type Cell, type Chart, type Mark } from "./chart | ||
| 12 | 12 | import { BUCKETS, MAX_STEP, oldestTime, runQuery, type Answer, type Bucket, type Row } from "./query.ts"; |
| 13 | 13 | import type { Board, Panel } from "./store.ts"; |
| 14 | 14 | |
| 15 | export const RANGE_MS = { "1h": 3_600_000, "6h": 21_600_000, "24h": 86_400_000, "7d": 604_800_000, "30d": 2_592_000_000 } as const; | |
| 15 | export const RANGE_MS = { "1h": 3_600_000, "6h": 21_600_000, "24h": 86_400_000, "7d": 604_800_000, "14d": 1_209_600_000, "30d": 2_592_000_000 } as const; | |
| 16 | 16 | /** The steps a panel picks from on its own, in seconds: 1 min to a week. */ |
| 17 | 17 | export const STEPS = [60, 120, 300, 600, 900, 1800, 3600, 7200, 10_800, 21_600, 43_200, 86_400, 604_800] as const; |
| 18 | 18 | /** About one point per two pixels of a chart's plot: more says nothing a reader can see. */ |
src/boards/sources.ts +22
| @@ -396,6 +396,28 @@ export const SOURCES: Readonly<Record<string, Source>> = { | ||
| 396 | 396 | at: "when the new process began serving, UTC", |
| 397 | 397 | }, |
| 398 | 398 | }, |
| 399 | // How long each finished check took (#16937): the home's Check time tile draws its days. | |
| 400 | checks: { | |
| 401 | table: "run", | |
| 402 | owner: "repo_id", | |
| 403 | select: | |
| 404 | "SELECT repo_id, finished_at AS at, state, (julianday(finished_at) - julianday(started_at)) * 1440.0 AS minutes FROM run " + | |
| 405 | "WHERE kind = 'check' AND state IN ('ok', 'failed') AND started_at IS NOT NULL AND finished_at IS NOT NULL AND finished_at >= started_at", | |
| 406 | time: "at", | |
| 407 | columns: { repo_id: "text", state: "text", minutes: "number", at: "time" }, | |
| 408 | docs: { minutes: "wall-clock minutes from start to finish", at: "when the check finished, UTC" }, | |
| 409 | }, | |
| 410 | // Open bugs (#16937): issues labelled bug and still open, by when they were opened. | |
| 411 | bugs: { | |
| 412 | table: "issue", | |
| 413 | owner: "repo_id", | |
| 414 | select: | |
| 415 | "SELECT i.repo_id AS repo_id, i.created_at AS at FROM issue i JOIN issue_label il ON il.issue_id = i.id " + | |
| 416 | "JOIN label l ON l.id = il.label_id AND l.name = 'bug' COLLATE NOCASE WHERE i.kind = 'issue' AND i.state = 'open'", | |
| 417 | time: "at", | |
| 418 | columns: { repo_id: "text", at: "time" }, | |
| 419 | docs: { at: "when the bug was opened, UTC" }, | |
| 420 | }, | |
| 399 | 421 | // Red batches the merge queue named (#7639): a pull handed back, or a load red no pull is blamed for. |
| 400 | 422 | queueVerdicts: { |
| 401 | 423 | table: "queue_verdict", |
src/boards/starting.ts +19 −5
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | /** |
| 2 | * The boards the forge offers a new install: Usage, Serving, Crew, Releases, Maintenance, Apps, App restarts, Security, Throughput, Forges and Reach. They are plain | |
| 3 | * boards in `forge/boards` once written, so a person edits or deletes them | |
| 4 | * like any other; `.offered` (a JSON list of slugs, committed with the | |
| 5 | * boards) records what was offered so a deletion sticks and an edit is | |
| 6 | * never overwritten. Each panel uses a source already in `sources.ts`. | |
| 2 | * The boards the forge offers a new install: Usage, Serving, Crew, Releases, Maintenance, Apps, App | |
| 3 | * restarts, Security, Throughput, Forges, Reach and Delivery. They are plain boards in | |
| 4 | * `forge/boards` once written, so a person edits or deletes them like any other; `.offered` (a JSON | |
| 5 | * list of slugs, committed with the boards) records what was offered so a deletion sticks and an | |
| 6 | * edit is never overwritten. Each panel uses a source already in `sources.ts`. | |
| 7 | 7 | */ |
| 8 | 8 | import { repoDir } from "../git/repos.ts"; |
| 9 | 9 | import { readerFor } from "../git/read.ts"; |
| @@ -174,6 +174,20 @@ export const STARTING_BOARDS: Readonly<Record<string, Board>> = { | ||
| 174 | 174 | panel("Slow to react per day (ms, slowest quarter)", "line", reach("inp_p75", "max", DAY), 2), |
| 175 | 175 | ], |
| 176 | 176 | }, |
| 177 | // What the home's figure tiles draw (#16937): each tile opens this board, or Reach, at its own | |
| 178 | // window. | |
| 179 | delivery: { | |
| 180 | title: "Delivery", | |
| 181 | range: "14d", | |
| 182 | refresh: "1m", | |
| 183 | panels: [ | |
| 184 | panel("Changes merged per day", "bar", { source: "pulls", aggregate: "count", groupBy: DAY }, 2), | |
| 185 | panel("Crew spend per day (USD)", "bar", { source: "runs", aggregate: "sum", column: "cost_usd", groupBy: DAY, filter: [{ column: "kind", op: "eq", value: "agent" }] }, 2), | |
| 186 | panel("Check time per day (minutes, average)", "line", { source: "checks", aggregate: "avg", column: "minutes", groupBy: DAY }, 2), | |
| 187 | // Open now, whatever the range: its own start reaches back to the first bug. | |
| 188 | panel("Open bugs", "number", { source: "bugs", aggregate: "count", from: "1970-01-01T00:00:00.000Z" }), | |
| 189 | ], | |
| 190 | }, | |
| 177 | 191 | forges: { |
| 178 | 192 | title: "Forges", |
| 179 | 193 | range: "30d", |
src/boards/store.ts +1 −1
| @@ -17,7 +17,7 @@ export const BOARDS_OWNER = "forge"; | ||
| 17 | 17 | export const BOARDS_REPO = "boards"; |
| 18 | 18 | const BRANCH = "main"; |
| 19 | 19 | |
| 20 | export const RANGES = ["1h", "6h", "24h", "7d", "30d", "all"] as const; | |
| 20 | export const RANGES = ["1h", "6h", "24h", "7d", "14d", "30d", "all"] as const; | |
| 21 | 21 | export const REFRESHES = ["off", "10s", "1m"] as const; |
| 22 | 22 | export type Range = (typeof RANGES)[number]; |
| 23 | 23 | export type Refresh = (typeof REFRESHES)[number]; |
src/flow/figure_change.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** | |
| 2 | * A figure's change against the window before it (#16937): "+12 vs prior 14 days". Pure | |
| 3 | * over two numbers and the formatter that writes the figure. Calm by design: a swing is | |
| 4 | * a direction and a size, never an alarm; whether more is better depends on the figure, | |
| 5 | * so nothing here says good or bad. No line where there is nothing to compare. | |
| 6 | */ | |
| 7 | ||
| 8 | export interface Change { | |
| 9 | readonly text: string; | |
| 10 | /** | |
| 11 | * Only for a quiet mark beside the words; it carries no colour of its own that means good or bad. | |
| 12 | */ | |
| 13 | readonly dir: "up" | "down" | "flat"; | |
| 14 | } | |
| 15 | ||
| 16 | /** | |
| 17 | * `now` against `prior`, both in the figure's unit and written by `write`; null when there is no | |
| 18 | * prior or both are nothing. | |
| 19 | */ | |
| 20 | export function changeAgainst( | |
| 21 | now: number | null, | |
| 22 | prior: number | null | undefined, | |
| 23 | days: number, | |
| 24 | write: (n: number) => string, | |
| 25 | ): Change | null { | |
| 26 | if (now === null || prior === null || prior === undefined) return null; | |
| 27 | if (!Number.isFinite(now) || !Number.isFinite(prior)) return null; | |
| 28 | if (now === 0 && prior === 0) return null; | |
| 29 | const vs = `vs prior ${days} days`; | |
| 30 | const diff = now - prior; | |
| 31 | // A shift too small to show in the figure's own words is flat. | |
| 32 | const shown = write(Math.abs(diff)); | |
| 33 | if (diff === 0 || write(now) === write(prior) || /^[$]?0(\.0+)?(ms)?$/.test(shown)) return { text: `No change ${vs}`, dir: "flat" }; | |
| 34 | return diff > 0 ? { text: `+${shown} ${vs}`, dir: "up" } : { text: `−${shown} ${vs}`, dir: "down" }; | |
| 35 | } |
src/flow/figures.ts +41 −13
| @@ -31,7 +31,7 @@ export interface Figures { | ||
| 31 | 31 | /** The crew's spend at list price: today, against the daily ceiling, and per UTC day. */ |
| 32 | 32 | readonly spend: { readonly todayUsd: number; readonly ceilingUsd: number | null; readonly days: readonly number[]; readonly totalUsd: number }; |
| 33 | 33 | /** How long a finished check took: the median over 24 h and per UTC day (null for a day with none). */ |
| 34 | readonly checks: { readonly medianMs: number | null; readonly days: readonly (number | null)[] }; | |
| 34 | readonly checks: { readonly medianMs: number | null; readonly days: readonly (number | null)[]; /** The median over the 14 days shown, for the change against the 14 before. */ readonly windowMs?: number | null }; | |
| 35 | 35 | /** From the crew's first run on an issue to its closing as done, over 7 days (`ship_time.ts`). */ |
| 36 | 36 | readonly ship: ShipTime; |
| 37 | 37 | readonly bugs: { readonly open: number; readonly overdue: number } | null; |
| @@ -45,14 +45,27 @@ export interface Figures { | ||
| 45 | 45 | * (`crew_card.ts`). |
| 46 | 46 | */ |
| 47 | 47 | readonly crew?: CrewCard; |
| 48 | /** | |
| 49 | * The same figures over the window before the one shown (14 days before the last 14, 7 before the | |
| 50 | * last 7); null where that window held nothing to compare (`figure_change.ts`). | |
| 51 | */ | |
| 52 | readonly prior?: Prior; | |
| 48 | 53 | readonly backup: { readonly at: string | null; readonly state: "green" | "red" | "unknown" | null; readonly note: string }; |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | /** The last `SERIES_DAYS` UTC days as `YYYY-MM-DD`, oldest first. */ | |
| 52 | function dayKeys(now: Date): string[] { | |
| 56 | export interface Prior { | |
| 57 | readonly shipped: number | null; | |
| 58 | readonly visitors: number | null; | |
| 59 | readonly spendUsd: number | null; | |
| 60 | readonly checkMs: number | null; | |
| 61 | readonly loadMs: number | null; | |
| 62 | } | |
| 63 | ||
| 64 | /** The last `n` UTC days as `YYYY-MM-DD`, oldest first. */ | |
| 65 | function dayKeys(now: Date, n = SERIES_DAYS): string[] { | |
| 53 | 66 | const keys: string[] = []; |
| 54 | 67 | const midnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()); |
| 55 | for (let i = SERIES_DAYS - 1; i >= 0; i--) keys.push(new Date(midnight - i * DAY_MS).toISOString().slice(0, 10)); | |
| 68 | for (let i = n - 1; i >= 0; i--) keys.push(new Date(midnight - i * DAY_MS).toISOString().slice(0, 10)); | |
| 56 | 69 | return keys; |
| 57 | 70 | } |
| 58 | 71 | |
| @@ -63,10 +76,12 @@ function byDay<T>(keys: readonly string[], rows: readonly (readonly [string, T]) | ||
| 63 | 76 | } |
| 64 | 77 | |
| 65 | 78 | export function readFigures(db: Database, now: Date, kpis: Kpis): Figures { |
| 66 | const keys = dayKeys(now); | |
| 67 | const from = `${keys[0]}T00:00:00.000Z`; | |
| 68 | const shipped = byDay( | |
| 69 | keys, | |
| 79 | // One pass per source over twice the window: the older half is the prior window. | |
| 80 | const keys2 = dayKeys(now, 2 * SERIES_DAYS); | |
| 81 | const keys = keys2.slice(SERIES_DAYS); | |
| 82 | const from = `${keys2[0]}T00:00:00.000Z`; | |
| 83 | const shipped2 = byDay( | |
| 84 | keys2, | |
| 70 | 85 | db |
| 71 | 86 | .query<[string, number], [string]>( |
| 72 | 87 | `SELECT substr(p.merged_at, 1, 10), COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id |
| @@ -75,8 +90,8 @@ export function readFigures(db: Database, now: Date, kpis: Kpis): Figures { | ||
| 75 | 90 | .values(from) as [string, number][], |
| 76 | 91 | 0, |
| 77 | 92 | ); |
| 78 | const spend = byDay( | |
| 79 | keys, | |
| 93 | const spend2 = byDay( | |
| 94 | keys2, | |
| 80 | 95 | db |
| 81 | 96 | .query<[string, number | null], [string]>(`SELECT substr(created_at, 1, 10), SUM(cost_usd) FROM run WHERE kind = 'agent' AND created_at >= ?1 GROUP BY 1`) |
| 82 | 97 | .values(from) |
| @@ -95,14 +110,27 @@ export function readFigures(db: Database, now: Date, kpis: Kpis): Figures { | ||
| 95 | 110 | if (list === undefined) took.set(d, [ms]); |
| 96 | 111 | else list.push(ms); |
| 97 | 112 | } |
| 113 | const [shipped, shippedBefore] = [shipped2.slice(SERIES_DAYS), shipped2.slice(0, SERIES_DAYS)]; | |
| 114 | const [spend, spendBefore] = [spend2.slice(SERIES_DAYS), spend2.slice(0, SERIES_DAYS)]; | |
| 115 | const sum = (xs: readonly number[]): number => xs.reduce((a, b) => a + b, 0); | |
| 116 | const checkDays = keys.map((k) => median(took.get(k) ?? [])); | |
| 117 | const before = keys2.slice(0, SERIES_DAYS).flatMap((k) => took.get(k) ?? []); | |
| 98 | 118 | const r = kpis.reach; |
| 119 | const vd = r.visitorDays; | |
| 99 | 120 | const backupState = kpis.backup?.state ?? null; |
| 100 | 121 | return { |
| 101 | 122 | visitors: { today: r.visitorsToday, week: r.visitors7d, days: r.visitorDays, accountsToday: r.usersToday, accounts: r.usersTotal }, |
| 102 | 123 | speed: { load: r.loadP75, lcp: r.lcpP75, inp: r.inpP75 }, |
| 103 | shipped: { days: shipped, total: shipped.reduce((a, b) => a + b, 0) }, | |
| 104 | spend: { todayUsd: kpis.spend.todayUsd, ceilingUsd: kpis.spend.ceilingUsd, days: spend, totalUsd: spend.reduce((a, b) => a + b, 0) }, | |
| 105 | checks: { medianMs: kpis.medianCheckMs, days: keys.map((k) => median(took.get(k) ?? [])) }, | |
| 124 | shipped: { days: shipped, total: sum(shipped) }, | |
| 125 | spend: { todayUsd: kpis.spend.todayUsd, ceilingUsd: kpis.spend.ceilingUsd, days: spend, totalUsd: sum(spend) }, | |
| 126 | checks: { medianMs: kpis.medianCheckMs, days: checkDays, windowMs: median(keys.flatMap((k) => took.get(k) ?? [])) }, | |
| 127 | prior: { | |
| 128 | shipped: sum(shippedBefore) === 0 && sum(shipped) === 0 ? null : sum(shippedBefore), | |
| 129 | visitors: vd.length >= 14 ? sum(vd.slice(-14, -7)) : null, | |
| 130 | spendUsd: sum(spendBefore) === 0 ? null : sum(spendBefore), | |
| 131 | checkMs: median(before), | |
| 132 | loadMs: r.loadP75Prior ?? null, | |
| 133 | }, | |
| 106 | 134 | ship: readShipTime(db, now), |
| 107 | 135 | crew: readCrewCard(db, now), |
| 108 | 136 | maintenance: tally(readRuns(db), now), |
src/flow/reach.ts +17 −8
| @@ -24,12 +24,14 @@ export interface Reach { | ||
| 24 | 24 | readonly visitorDays: readonly number[]; |
| 25 | 25 | /** Milliseconds; null when no page view in 7 days measured it. */ |
| 26 | 26 | readonly loadP75: number | null; |
| 27 | /** The same over the seven days before those (`figure_change.ts`); null with none. */ | |
| 28 | readonly loadP75Prior?: number | null; | |
| 27 | 29 | readonly inpP75: number | null; |
| 28 | 30 | /** Largest contentful paint, the same window; null when none was measured. */ |
| 29 | 31 | readonly lcpP75: number | null; |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | export const NO_REACH: Reach = { usersToday: 0, usersTotal: 0, visitorsToday: 0, visitors7d: 0, visitorDays: new Array<number>(DAYS).fill(0), loadP75: null, inpP75: null, lcpP75: null }; | |
| 34 | export const NO_REACH: Reach = { usersToday: 0, usersTotal: 0, visitorsToday: 0, visitors7d: 0, visitorDays: new Array<number>(DAYS).fill(0), loadP75: null, loadP75Prior: null, inpP75: null, lcpP75: null }; | |
| 33 | 35 | |
| 34 | 36 | /** The 75th percentile, nearest rank: the value at rank ⌈0.75·n⌉ of `values` sorted. */ |
| 35 | 37 | export function p75(values: number[]): number | null { |
| @@ -42,21 +44,26 @@ export function p75(values: number[]): number | null { | ||
| 42 | 44 | * Page load and INP over the days since `fromDay`, read in one pass (#3693): |
| 43 | 45 | * two counts and two sorted OFFSET reads cost home 70 ms on a month of views. |
| 44 | 46 | */ |
| 45 | function vitals(db: Database, fromDay: string): { load: number[]; inp: number[]; lcp: number[] } { | |
| 47 | function vitals(db: Database, fromDay: string, priorFromDay: string): { load: number[]; inp: number[]; lcp: number[]; priorLoad: number[] } { | |
| 48 | const priorLoad: number[] = []; | |
| 46 | 49 | const load: number[] = []; |
| 47 | 50 | const inp: number[] = []; |
| 48 | 51 | const lcp: number[] = []; |
| 49 | 52 | // Rows as arrays: a week of views is tens of thousands, and objects cost. |
| 50 | for (const [l, i, c] of db | |
| 51 | .query<[number | null, number | null, number | null], [string]>( | |
| 52 | "SELECT load, inp, lcp FROM page_vital WHERE day >= ?1 AND (load IS NOT NULL OR inp IS NOT NULL OR lcp IS NOT NULL)", | |
| 53 | for (const [l, i, c, d] of db | |
| 54 | .query<[number | null, number | null, number | null, string], [string]>( | |
| 55 | "SELECT load, inp, lcp, day FROM page_vital WHERE day >= ?1 AND (load IS NOT NULL OR inp IS NOT NULL OR lcp IS NOT NULL)", | |
| 53 | 56 | ) |
| 54 | .values(fromDay) as [number | null, number | null, number | null][]) { | |
| 57 | .values(priorFromDay) as [number | null, number | null, number | null, string][]) { | |
| 58 | if (d < fromDay) { | |
| 59 | if (l !== null) priorLoad.push(l); | |
| 60 | continue; | |
| 61 | } | |
| 55 | 62 | if (c !== null) lcp.push(c); |
| 56 | 63 | if (l !== null) load.push(l); |
| 57 | 64 | if (i !== null) inp.push(i); |
| 58 | 65 | } |
| 59 | return { load, inp, lcp }; | |
| 66 | return { load, inp, lcp, priorLoad }; | |
| 60 | 67 | } |
| 61 | 68 | |
| 62 | 69 | export function readReach(db: Database, now: Date): Reach { |
| @@ -79,7 +86,8 @@ export function readReach(db: Database, now: Date): Reach { | ||
| 79 | 86 | perDay.get(new Date(now.getTime() - (DAYS - 1 - i) * DAY_MS).toISOString().slice(0, 10)) ?? 0, |
| 80 | 87 | ); |
| 81 | 88 | const days = month.filter((d) => d.day >= weekFrom); |
| 82 | const week = vitals(db, weekFrom); | |
| 89 | const priorFrom = new Date(now.getTime() - 13 * DAY_MS).toISOString().slice(0, 10); | |
| 90 | const week = vitals(db, weekFrom, priorFrom); | |
| 83 | 91 | return { |
| 84 | 92 | usersToday: users.today, |
| 85 | 93 | usersTotal: users.total, |
| @@ -87,6 +95,7 @@ export function readReach(db: Database, now: Date): Reach { | ||
| 87 | 95 | visitorDays, |
| 88 | 96 | visitors7d: days.reduce((a, d) => a + d.n, 0), |
| 89 | 97 | loadP75: p75(week.load), |
| 98 | loadP75Prior: p75(week.priorLoad), | |
| 90 | 99 | inpP75: p75(week.inp), |
| 91 | 100 | lcpP75: p75(week.lcp), |
| 92 | 101 | }; |
src/web/pages/boards-view.ts +11 −2
| @@ -10,6 +10,8 @@ | ||
| 10 | 10 | import { checkSlotsFold } from "./boards-slots.ts"; |
| 11 | 11 | import { CHART_NAMES } from "../../boards/chart.ts"; |
| 12 | 12 | import { isSlug, MAX_H, MAX_PANELS, MAX_TITLE, MAX_W, RANGES, type Board, type Panel } from "../../boards/store.ts"; |
| 13 | import { STARTING_BOARDS } from "../../boards/starting.ts"; | |
| 14 | import { offerStartingBoards } from "../../actions/boards.ts"; | |
| 13 | 15 | import type { App } from "../../app.ts"; |
| 14 | 16 | import type { Ctx } from "../../http/context.ts"; |
| 15 | 17 | import { driftSection } from "./boards-drift.ts"; |
| @@ -199,7 +201,7 @@ function viewBar(slug: string, board: Board, view: View): Html { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | /** A board's range as words. */ |
| 202 | const RANGE_WORDS: Readonly<Record<Board["range"], string>> = { "1h": "The last hour", "6h": "The last 6 hours", "24h": "The last 24 hours", "7d": "The last 7 days", "30d": "The last 30 days", all: "All of time" }; | |
| 204 | const RANGE_WORDS: Readonly<Record<Board["range"], string>> = { "1h": "The last hour", "6h": "The last 6 hours", "24h": "The last 24 hours", "7d": "The last 7 days", "14d": "The last 14 days", "30d": "The last 30 days", all: "All of time" }; | |
| 203 | 205 | |
| 204 | 206 | function panelForm(slug: string, op: string, p: Panel | undefined, index: number, fields: Html): Html { |
| 205 | 207 | const id = op === "edit" ? `panel-${String(index)}` : "panel-new"; |
| @@ -279,7 +281,14 @@ export async function boardShow(ctx: Ctx): Promise<Response> { | ||
| 279 | 281 | } |
| 280 | 282 | // The board's file and every panel's rows are read by a worker and kept: no query and no git on |
| 281 | 283 | // this thread. |
| 282 | const picture = await timePhaseAsync(ctx.request, "picture", () => boardPicture(ctx.app, slug, undefined, undefined, undefined, view.range ?? undefined)); | |
| 284 | const ask = () => boardPicture(ctx.app, slug, undefined, undefined, undefined, view.range ?? undefined); | |
| 285 | let picture = await timePhaseAsync(ctx.request, "picture", ask); | |
| 286 | // A starting board is written at boot, later than a tile that links to it can be clicked: the | |
| 287 | // first ask for one that was never offered offers it. A deleted one is recorded as offered, so it | |
| 288 | // stays deleted. | |
| 289 | if (picture !== undefined && !isFailed(picture) && picture.board === null && slug in STARTING_BOARDS && (await offerStartingBoards(ctx.app)).includes(slug)) { | |
| 290 | picture = await timePhaseAsync(ctx.request, "picture", ask); | |
| 291 | } | |
| 283 | 292 | if (picture === undefined || isFailed(picture)) { |
| 284 | 293 | return page({ |
| 285 | 294 | ctx, |
src/web/pages/home_figures.ts +25 −7
| @@ -25,6 +25,8 @@ import type { LanePicture } from "../../flow/lanes.ts"; | ||
| 25 | 25 | import { row, rowList } from "../ui.ts"; |
| 26 | 26 | import { html, raw, type Html } from "../html.ts"; |
| 27 | 27 | import { CREW_EMPTY, rowWords, streakWords, type CrewCard } from "../../flow/crew_card.ts"; |
| 28 | import { changeAgainst, type Change } from "../../flow/figure_change.ts"; | |
| 29 | import { viewHref } from "../../boards/view_bar.ts"; | |
| 28 | 30 | import { shipSection } from "./home_ship.ts"; |
| 29 | 31 | |
| 30 | 32 | /** The events that change a figure; they change by the minute, so these are few. */ |
| @@ -87,8 +89,16 @@ interface Card { | ||
| 87 | 89 | readonly ends?: readonly [string, string]; |
| 88 | 90 | readonly tone?: "attn"; |
| 89 | 91 | readonly href?: string; |
| 92 | /** | |
| 93 | * Against the window before this one; the line is kept (empty) when there is none, so a card | |
| 94 | * never changes height. | |
| 95 | */ | |
| 96 | readonly change?: Change | null; | |
| 90 | 97 | } |
| 91 | 98 | |
| 99 | /** The board that draws a tile's figure, at the tile's window: the board's own range link. */ | |
| 100 | export const tileHref = (slug: string, days: 7 | 14): string => viewHref(`/boards/${slug}`, { range: days === 7 ? "7d" : "14d", live: null }); | |
| 101 | ||
| 92 | 102 | function card(c: Card): Html { |
| 93 | 103 | const drawn = |
| 94 | 104 | c.series === undefined ? null : chart(c.series, c.seriesLabel ?? c.label); |
| @@ -97,6 +107,9 @@ function card(c: Card): Html { | ||
| 97 | 107 | <span class="fg-n num">${c.value}</span |
| 98 | 108 | ><span class="fg-unit">${c.unit}</span> |
| 99 | 109 | </p> |
| 110 | ${c.change == null | |
| 111 | ? html`<div class="fg-change" aria-hidden="true"></div>` | |
| 112 | : html`<p class="fg-change" data-dir="${c.change.dir}">${c.change.text}</p>`} | |
| 100 | 113 | <p class="fg-note">${c.note}</p> |
| 101 | 114 | <div class="fg-chart">${drawn}</div> |
| 102 | 115 | <p class="fg-axis" aria-hidden="true"> |
| @@ -145,7 +158,8 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 145 | 158 | series: f.shipped.days, |
| 146 | 159 | seriesLabel: `Changes merged per day over 14 days, most ${count(peak)}`, |
| 147 | 160 | ends: days(14), |
| 148 | href: "/board", | |
| 161 | href: tileHref("delivery", 14), | |
| 162 | change: changeAgainst(f.shipped.total, f.prior?.shipped, 14, count), | |
| 149 | 163 | }, |
| 150 | 164 | { |
| 151 | 165 | label: "Visitors", |
| @@ -155,7 +169,8 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 155 | 169 | series: f.visitors.days, |
| 156 | 170 | seriesLabel: `Visitors per day over ${f.visitors.days.length} days`, |
| 157 | 171 | ends: days(f.visitors.days.length), |
| 158 | href: "/boards/reach", | |
| 172 | href: tileHref("reach", 7), | |
| 173 | change: changeAgainst(f.visitors.week, f.prior?.visitors, 7, count), | |
| 159 | 174 | }, |
| 160 | 175 | { |
| 161 | 176 | label: "Crew spend", |
| @@ -171,7 +186,8 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 171 | 186 | ...(spendShare !== null && spendShare >= 0.9 |
| 172 | 187 | ? { tone: "attn" as const } |
| 173 | 188 | : {}), |
| 174 | href: "/settings/crew", | |
| 189 | href: tileHref("delivery", 14), | |
| 190 | change: changeAgainst(f.spend.totalUsd, f.prior?.spendUsd, 14, money), | |
| 175 | 191 | }, |
| 176 | 192 | { |
| 177 | 193 | label: "Check time", |
| @@ -180,11 +196,12 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 180 | 196 | f.checks.medianMs === null |
| 181 | 197 | ? "no check finished in 24 hours" |
| 182 | 198 | : "median, last 24 hours", |
| 183 | note: "How long a finished check took, per day below", | |
| 199 | note: "Median over 14 days; per day below", | |
| 184 | 200 | series: f.checks.days.map((ms) => (ms === null ? null : ms / 60_000)), |
| 185 | 201 | seriesLabel: "Median check time per day over 14 days, in minutes", |
| 186 | 202 | ends: days(14), |
| 187 | href: "/boards", | |
| 203 | href: tileHref("delivery", 14), | |
| 204 | change: changeAgainst(f.checks.windowMs ?? null, f.prior?.checkMs, 14, duration), | |
| 188 | 205 | }, |
| 189 | 206 | { |
| 190 | 207 | label: "Page speed", |
| @@ -200,7 +217,8 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 200 | 217 | ] |
| 201 | 218 | .filter((p) => p !== null) |
| 202 | 219 | .join(" · ") || "Reported by visitors' browsers over 7 days", |
| 203 | href: "/boards/reach", | |
| 220 | href: tileHref("reach", 7), | |
| 221 | change: changeAgainst(f.speed.load, f.prior?.loadMs, 7, pageTime), | |
| 204 | 222 | }, |
| 205 | 223 | ...(f.bugs === null |
| 206 | 224 | ? [] |
| @@ -214,7 +232,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 214 | 232 | ? `${count(f.bugs.overdue)} past their clock (4 h for high, 48 h otherwise)` |
| 215 | 233 | : "None past their clock", |
| 216 | 234 | ...(f.bugs.overdue > 0 ? { tone: "attn" as const } : {}), |
| 217 | href: "/boards", | |
| 235 | href: tileHref("delivery", 14), | |
| 218 | 236 | }, |
| 219 | 237 | ]), |
| 220 | 238 | // Quiet when the workers have found and fixed nothing: the home's first view is budgeted. |
src/web/pages/home_flow_style.ts +1
| @@ -248,6 +248,7 @@ export const homeFlowCss = /* css */ ` | ||
| 248 | 248 | .fg-area { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: none; } |
| 249 | 249 | .fg-base { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; } |
| 250 | 250 | .fg-dot { fill: var(--accent); } |
| 251 | .fg-change { min-height: 16px; margin: 0; font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 251 | 252 | .fg-axis { display: flex; justify-content: space-between; gap: 8px; min-height: 16px; margin: 0; font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } |
| 252 | 253 | .fg-reading { margin: 0; color: var(--muted-fg); } |
| 253 | 254 |
test/boards-starting.test.ts +3 −3
| @@ -36,10 +36,10 @@ test("a forge with no person to found the repo writes nothing", async () => { | ||
| 36 | 36 | expect(await offerStartingBoards(bare)).toEqual([]); |
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | test("a fresh boot writes the eleven starting boards, and every panel runs", async () => { | |
| 40 | expect((await offerStartingBoards(app)).sort()).toEqual(["apps", "crew", "forges", "maintenance", "reach", "releases", "restarts", "security", "serving", "throughput", "usage"]); | |
| 39 | test("a fresh boot writes the twelve starting boards, and every panel runs", async () => { | |
| 40 | expect((await offerStartingBoards(app)).sort()).toEqual(["apps", "crew", "delivery", "forges", "maintenance", "reach", "releases", "restarts", "security", "serving", "throughput", "usage"]); | |
| 41 | 41 | const boards = await listBoards(app.reposRoot); |
| 42 | expect(boards.map((b) => b.slug)).toEqual(["apps", "crew", "forges", "maintenance", "reach", "releases", "restarts", "security", "serving", "throughput", "usage"]); | |
| 42 | expect(boards.map((b) => b.slug)).toEqual(["apps", "crew", "delivery", "forges", "maintenance", "reach", "releases", "restarts", "security", "serving", "throughput", "usage"]); | |
| 43 | 43 | let panels = 0; |
| 44 | 44 | for (const { board } of boards) { |
| 45 | 45 | for (const p of board.panels) { |
test/boards-view-bar.test.ts +2 −2
| @@ -124,10 +124,10 @@ describe("the terminal's view", () => { | ||
| 124 | 124 | expect(tui.screen.toText()).toContain("range 7d · refresh off"); |
| 125 | 125 | terminal.feed("v"); |
| 126 | 126 | await settleApp(tui); |
| 127 | expect(tui.screen.toText()).toContain("range 30d · refresh off · 1 panel · a view, not saved"); | |
| 127 | expect(tui.screen.toText()).toContain("range 14d · refresh off · 1 panel · a view, not saved"); | |
| 128 | 128 | terminal.feed("l"); |
| 129 | 129 | await settleApp(tui); |
| 130 | expect(tui.screen.toText()).toContain("range 30d · refresh 10s"); | |
| 130 | expect(tui.screen.toText()).toContain("range 14d · refresh 10s"); | |
| 131 | 131 | terminal.feed("l"); |
| 132 | 132 | await settleApp(tui); |
| 133 | 133 | expect(tui.screen.toText()).toContain("refresh off"); |
test/home-figure-tiles.test.ts added +98
| @@ -0,0 +1,98 @@ | ||
| 1 | /** | |
| 2 | * The home's figure tiles (#16937): each opens the board that draws its figure at its own window, | |
| 3 | * and says its change against the window before it, calmly, with no line where there is nothing to | |
| 4 | * compare. | |
| 5 | */ | |
| 6 | import { expect, test } from "bun:test"; | |
| 7 | import { changeAgainst } from "../src/flow/figure_change.ts"; | |
| 8 | import type { Figures } from "../src/flow/figures.ts"; | |
| 9 | import { readParams } from "../src/boards/params.ts"; | |
| 10 | import { readView } from "../src/boards/view_bar.ts"; | |
| 11 | import { STARTING_BOARDS } from "../src/boards/starting.ts"; | |
| 12 | import { count, money } from "../src/flow/figure_format.ts"; | |
| 13 | import { cards } from "../src/web/pages/home_figures.ts"; | |
| 14 | ||
| 15 | const figures: Figures = { | |
| 16 | visitors: { today: 12, week: 147, days: Array.from({ length: 30 }, () => 3), accountsToday: 1, accounts: 4 }, | |
| 17 | speed: { load: 1130, lcp: 2300, inp: 201 }, | |
| 18 | shipped: { days: Array.from({ length: 14 }, () => 1), total: 14 }, | |
| 19 | spend: { todayUsd: 39, ceilingUsd: 50, days: Array.from({ length: 14 }, () => 20), totalUsd: 280 }, | |
| 20 | checks: { medianMs: 8 * 60_000, days: Array.from({ length: 14 }, () => 5 * 60_000), windowMs: 6 * 60_000 }, | |
| 21 | ship: { days: 7, count: 0, medianMs: null, p90Ms: null, histogram: [], slowest: [] }, | |
| 22 | bugs: { open: 3, overdue: 0 }, | |
| 23 | prior: { shipped: 2, visitors: 100, spendUsd: 300, checkMs: 6 * 60_000, loadMs: 1130 }, | |
| 24 | backup: { at: null, state: null, note: "" }, | |
| 25 | }; | |
| 26 | const now = Date.parse("2026-11-13T12:00:00Z"); | |
| 27 | ||
| 28 | test("every figure tile opens a board's own page at its window, never an index or a settings page", () => { | |
| 29 | const tiles = cards(figures, now).filter((c) => ["Shipped", "Visitors", "Crew spend", "Check time", "Page speed", "Open bugs"].includes(c.label)); | |
| 30 | expect(tiles).toHaveLength(6); | |
| 31 | for (const c of tiles) { | |
| 32 | const href = c.href ?? ""; | |
| 33 | expect(href).not.toMatch(/^\/boards?(\?|$)/); | |
| 34 | expect(href).not.toMatch(/^\/settings/); | |
| 35 | const url = new URL(href, "http://x"); | |
| 36 | const slug = url.pathname.replace(/^\/boards\//, ""); | |
| 37 | expect(Object.hasOwn(STARTING_BOARDS, slug)).toBe(true); | |
| 38 | // The window rides in the board's own range parameter and is one the board reads. | |
| 39 | expect(readView(url.searchParams).range).toBe(c.label === "Visitors" || c.label === "Page speed" ? "7d" : "14d"); | |
| 40 | expect(readParams(url.searchParams).source).toBeDefined(); | |
| 41 | } | |
| 42 | }); | |
| 43 | ||
| 44 | test("the tile's board draws the tile's figure", () => { | |
| 45 | const by = (label: string) => cards(figures, now).find((c) => c.label === label)!.href!.split("?")[0]!.replace("/boards/", ""); | |
| 46 | const titles = (slug: string) => STARTING_BOARDS[slug]!.panels.map((p) => p.title).join("|"); | |
| 47 | expect(titles(by("Shipped"))).toContain("Changes merged"); | |
| 48 | expect(titles(by("Crew spend"))).toContain("Crew spend"); | |
| 49 | expect(titles(by("Check time"))).toContain("Check time"); | |
| 50 | expect(titles(by("Open bugs"))).toContain("Open bugs"); | |
| 51 | expect(titles(by("Visitors"))).toContain("Visitors"); | |
| 52 | expect(titles(by("Page speed"))).toContain("Page load"); | |
| 53 | }); | |
| 54 | ||
| 55 | test("a change is up, down, flat or absent, in calm words", () => { | |
| 56 | expect(changeAgainst(14, 2, 14, count)).toEqual({ text: "+12 vs prior 14 days", dir: "up" }); | |
| 57 | expect(changeAgainst(3, 10, 7, count)).toEqual({ text: "−7 vs prior 7 days", dir: "down" }); | |
| 58 | expect(changeAgainst(5, 5, 14, count)).toEqual({ text: "No change vs prior 14 days", dir: "flat" }); | |
| 59 | expect(changeAgainst(5, null, 14, count)).toBeNull(); | |
| 60 | expect(changeAgainst(5, undefined, 14, count)).toBeNull(); | |
| 61 | expect(changeAgainst(0, 0, 14, count)).toBeNull(); | |
| 62 | expect(changeAgainst(280, 300, 14, money)?.text).toBe("−$20.00 vs prior 14 days"); | |
| 63 | expect(changeAgainst(null, 4, 14, count)).toBeNull(); | |
| 64 | }); | |
| 65 | ||
| 66 | const withoutPrior = (f: Figures): Figures => { | |
| 67 | const { prior: _p, ...rest } = f; | |
| 68 | return rest; | |
| 69 | }; | |
| 70 | ||
| 71 | test("the tiles carry the change, and keep an empty line where there is none", () => { | |
| 72 | const by = (f: Figures, label: string) => cards(f, now).find((c) => c.label === label)!; | |
| 73 | expect(by(figures, "Shipped").change?.text).toBe("+12 vs prior 14 days"); | |
| 74 | expect(by(figures, "Visitors").change?.text).toBe("+47 vs prior 7 days"); | |
| 75 | expect(by(figures, "Crew spend").change?.dir).toBe("down"); | |
| 76 | expect(by(figures, "Page speed").change?.dir).toBe("flat"); | |
| 77 | expect(by(withoutPrior(figures), "Shipped").change).toBeNull(); | |
| 78 | expect(by(figures, "Open bugs").change ?? null).toBeNull(); | |
| 79 | }); | |
| 80 | ||
| 81 | test("a forge with no history reads no prior and so draws no change", async () => { | |
| 82 | const { mkdtemp, rm } = await import("node:fs/promises"); | |
| 83 | const { tmpdir } = await import("node:os"); | |
| 84 | const { join } = await import("node:path"); | |
| 85 | const { createApp } = await import("../src/app.ts"); | |
| 86 | const { readFigures } = await import("../src/flow/figures.ts"); | |
| 87 | const { NO_REACH } = await import("../src/flow/reach.ts"); | |
| 88 | const dir = await mkdtemp(join(tmpdir(), "forge-tiles-")); | |
| 89 | try { | |
| 90 | const app = createApp({ dataDir: dir, port: 0 }); | |
| 91 | const f = readFigures(app.db, new Date(now), { landedHours: [0], landed: 0, live: null, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, backupAt: null, reach: NO_REACH }); | |
| 92 | expect(f.prior).toEqual({ shipped: null, visitors: 0, spendUsd: null, checkMs: null, loadMs: null }); | |
| 93 | expect(f.shipped.days).toHaveLength(14); | |
| 94 | expect(cards(f, now).every((c) => (c.change ?? null) === null)).toBe(true); | |
| 95 | } finally { | |
| 96 | await rm(dir, { recursive: true, force: true }); | |
| 97 | } | |
| 98 | }); |
test/home-no-shift.test.ts +2 −1
| @@ -194,8 +194,9 @@ describe("the signed-in home", () => { | ||
| 194 | 194 | need(px(css, ".fg-note", "min-height")) + |
| 195 | 195 | need(px(css, ".fg-chart", "height")) + |
| 196 | 196 | need(px(css, ".fg-chart", "margin-top")) + |
| 197 | need(px(css, ".fg-change", "min-height")) + | |
| 197 | 198 | need(px(css, ".fg-axis", "min-height")) + |
| 198 | 4 * need(px(css, ".fg-card", "gap")); | |
| 199 | 5 * need(px(css, ".fg-card", "gap")); | |
| 199 | 200 | // The card's padding is "12px 16px": top and bottom make 24. |
| 200 | 201 | expect(need(px(css, ".fg-body", "min-height"))).toBeGreaterThanOrEqual(card - 16 * 2 + 12); |
| 201 | 202 | }); |
test/home-tile-board-offered.test.ts added +55
| @@ -0,0 +1,55 @@ | ||
| 1 | /** | |
| 2 | * A tile on the home links to a starting board (#16937): the first ask for one that boot has not | |
| 3 | * written yet offers it, so the link is never dead; a board that was offered and deleted stays | |
| 4 | * gone. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { deleteBoard } from "../src/actions/boards.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { readBoard } from "../src/boards/store.ts"; | |
| 13 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve } from "../src/http/server.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | ||
| 18 | quietLogs(); | |
| 19 | ||
| 20 | let dir: string; | |
| 21 | let app: App; | |
| 22 | let servers: Awaited<ReturnType<typeof serve>>; | |
| 23 | let cookie = ""; | |
| 24 | const get = (path: string) => fetch(`${servers.url}${path}`, { headers: { cookie }, redirect: "manual" }); | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dir = await mkdtemp(join(tmpdir(), "forge-tile-board-")); | |
| 28 | app = createApp({ dataDir: dir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "carol", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 31 | if (!made.ok) throw new Error(made.error); | |
| 32 | cookie = `forge_session=${createSession(app.db, made.value.id).token}`; | |
| 33 | }, 30_000); | |
| 34 | ||
| 35 | afterAll(async () => { | |
| 36 | await servers.stop?.(); | |
| 37 | app.close(); | |
| 38 | await rm(dir, { recursive: true, force: true }); | |
| 39 | }); | |
| 40 | ||
| 41 | test("the Delivery board is there on the path a tile uses, before any boot offered it", async () => { | |
| 42 | expect(await readBoard(app.reposRoot, "delivery")).toBeUndefined(); | |
| 43 | const res = await get("/boards/delivery?range=14d"); | |
| 44 | expect(res.status).toBe(200); | |
| 45 | expect(await res.text()).toContain("Changes merged per day"); | |
| 46 | expect(await readBoard(app.reposRoot, "delivery")).toBeDefined(); | |
| 47 | }, 30_000); | |
| 48 | ||
| 49 | test("a deleted starting board is not offered again by a click, and a board that is no starting one stays 404", async () => { | |
| 50 | const user = app.db.query<{ id: string }, []>("SELECT id FROM user LIMIT 1").get()!; | |
| 51 | const { getUserById } = await import("../src/core/users.ts"); | |
| 52 | expect((await deleteBoard(app, getUserById(app.db, user.id)!, "delivery")).ok).toBe(true); | |
| 53 | expect((await get("/boards/delivery?range=14d")).status).toBe(404); | |
| 54 | expect((await get("/boards/nothing-here")).status).toBe(404); | |
| 55 | }, 30_000); |
new above
offline
Four tiles link to this board, but it only exists once offered at boot. On the preview
/boards/delivery?range=14dreturned 404. A tile must never link to a missing board.