Public: anyone can read this; the crew can change it.
Home tells the truth in few words: figures agree with their sources, blurbs become lines #10449
mason/forge:mason/10440-home-tells-the-truth-in-few-words-figure → main 2 commits fork
28 files
changed +478
−456
src/crew/ready_counts.ts added +26
| @@ -0,0 +1,26 @@ | ||
| 1 | /** | |
| 2 | * The ready issues across the autonomous repositories, and those a builder | |
| 3 | * may start: the very sets `/map` lists as ready and `heldNow` sorts, so the | |
| 4 | * home's "Ready" figure and the map agree. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { App } from "../app.ts"; | |
| 8 | import { listAutonomousRepos } from "../core/repos.ts"; | |
| 9 | import { HOLDS, heldNow } from "./held.ts"; | |
| 10 | ||
| 11 | export interface ReadyCounts { | |
| 12 | readonly ready: number; | |
| 13 | readonly startable: number; | |
| 14 | } | |
| 15 | ||
| 16 | export function readyCounts(app: App): ReadyCounts { | |
| 17 | let ready = 0; | |
| 18 | let startable = 0; | |
| 19 | for (const repo of listAutonomousRepos(app.db)) { | |
| 20 | if (repo.autonomy !== "autonomous" || repo.archivedAt !== null) continue; | |
| 21 | const held = heldNow(app, repo); | |
| 22 | startable += held.startable.length; | |
| 23 | ready += held.startable.length + HOLDS.reduce((n, h) => n + held.by[h].length, 0); | |
| 24 | } | |
| 25 | return { ready, startable }; | |
| 26 | } |
src/crew/week_read.ts +5 −1
| @@ -180,6 +180,8 @@ export function weekWords(app: App, now: Date = new Date(), besideCrewLine = fal | ||
| 180 | 180 | export interface CrewPace { |
| 181 | 181 | readonly freePct: number; |
| 182 | 182 | readonly runsOutAt: Date | null; |
| 183 | /** Percent of the week's time gone, from the meter's reset. */ | |
| 184 | readonly elapsedPct: number; | |
| 183 | 185 | } |
| 184 | 186 | |
| 185 | 187 | /** |
| @@ -190,7 +192,9 @@ export interface CrewPace { | ||
| 190 | 192 | export function crewPace(app: App, now: Date = new Date()): CrewPace | null { |
| 191 | 193 | return busiest(app, now, (repo, week) => { |
| 192 | 194 | const meter = weekOf(app, repo, now).meter; |
| 193 | return meter === null ? null : { freePct: meter.freePct, runsOutAt: week.runsOutAt }; | |
| 195 | return meter === null | |
| 196 | ? null | |
| 197 | : { freePct: meter.freePct, runsOutAt: week.runsOutAt, elapsedPct: Math.min(100, Math.max(0, (1 - (meter.resetsAt.getTime() - now.getTime()) / WINDOW_MS.week) * 100)) }; | |
| 194 | 198 | }); |
| 195 | 199 | } |
| 196 | 200 |
src/flow/alarm_stuck.ts +2 −2
| @@ -140,13 +140,13 @@ export function alarmStuck(from: App | Database, now: Date, scope: StuckScope = | ||
| 140 | 140 | repo, |
| 141 | 141 | number, |
| 142 | 142 | wall, |
| 143 | says: `${repo}#${number} is approved and waits for a person: ${wall.join("; ")}. Allow it (merge) or send it back.`, | |
| 143 | says: `${repo}#${number} approved, waits for you`, | |
| 144 | 144 | }; |
| 145 | 145 | return { |
| 146 | 146 | fired: true, |
| 147 | 147 | since: last.at, |
| 148 | 148 | repo, |
| 149 | 149 | number, |
| 150 | says: `${repo}#${number} has sat approved for ${sat(now.getTime() - Date.parse(last.at))}; its last event was ${last.what} at ${hhmm}.`, | |
| 150 | says: `${repo}#${number} sat approved ${sat(now.getTime() - Date.parse(last.at))}, last ${last.what} ${hhmm}`, | |
| 151 | 151 | }; |
| 152 | 152 | } |
src/flow/home_figures.ts added +106
| @@ -0,0 +1,106 @@ | ||
| 1 | /** | |
| 2 | * The figures on the owner's home, each one line (#10440): a label, a | |
| 3 | * number, at most four words of context, and the page that number comes | |
| 4 | * from. Plain data in, plain data out, so a test can hold every figure | |
| 5 | * against the others and against the sources it names. A figure that no | |
| 6 | * decision uses is not here (accounts, reporting browsers, traffic, page | |
| 7 | * speed live on their own boards). | |
| 8 | */ | |
| 9 | ||
| 10 | import { backupAge, backupOverdue, checkTime, shippedValue } from "./kpi_words.ts"; | |
| 11 | import type { Kpis } from "./kpis.ts"; | |
| 12 | ||
| 13 | export interface Figure { | |
| 14 | readonly key: string; | |
| 15 | readonly label: string; | |
| 16 | readonly value: string; | |
| 17 | /** At most `CONTEXT_WORDS` words. */ | |
| 18 | readonly context: string; | |
| 19 | /** Where the number comes from: the page that shows it whole. */ | |
| 20 | readonly href: string; | |
| 21 | readonly attn: boolean; | |
| 22 | } | |
| 23 | ||
| 24 | export const CONTEXT_WORDS = 4; | |
| 25 | ||
| 26 | /** What the figures need beyond `Kpis`, read live by the caller. */ | |
| 27 | export interface FigureExtras { | |
| 28 | /** `crew.concurrency`: the slots the crew really has. */ | |
| 29 | readonly concurrency: number; | |
| 30 | /** Ready and startable issues, as `/map` and the dispatcher count them; null while unread. */ | |
| 31 | readonly ready: { readonly ready: number; readonly startable: number } | null; | |
| 32 | /** The provider's week: percent used and percent of its time gone; null while unmeasured. */ | |
| 33 | readonly week: { readonly usedPct: number; readonly elapsedPct: number } | null; | |
| 34 | } | |
| 35 | ||
| 36 | /** Within this many points of the clock, usage is on pace. */ | |
| 37 | const PACE_TOLERANCE = 3; | |
| 38 | ||
| 39 | /** `behind` only when less of the week is used than has gone by; `ahead` only when more. */ | |
| 40 | export function paceWord(usedPct: number, elapsedPct: number): "behind" | "on pace" | "ahead" { | |
| 41 | if (usedPct < elapsedPct - PACE_TOLERANCE) return "behind"; | |
| 42 | if (usedPct > elapsedPct + PACE_TOLERANCE) return "ahead"; | |
| 43 | return "on pace"; | |
| 44 | } | |
| 45 | ||
| 46 | const money = (n: number): string => (n < 10 ? `$${n.toFixed(2)}` : `$${Math.round(n)}`); | |
| 47 | ||
| 48 | /** Hours since UTC midnight, at least a minute so the first minutes divide by something. */ | |
| 49 | function hoursToday(now: Date): number { | |
| 50 | const midnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()); | |
| 51 | return Math.max(1 / 60, (now.getTime() - midnight) / 3_600_000); | |
| 52 | } | |
| 53 | ||
| 54 | /** The words of `s` cut at a word boundary to at most `n`. */ | |
| 55 | export function fewWords(s: string, n: number): string { | |
| 56 | return s.trim().split(/\s+/).slice(0, n).join(" "); | |
| 57 | } | |
| 58 | ||
| 59 | function builders(k: Kpis, x: FigureExtras): Figure { | |
| 60 | const { running } = k.builders; | |
| 61 | const value = x.concurrency > 0 ? `${running} of ${x.concurrency}` : String(running); | |
| 62 | let context: string; | |
| 63 | let href = "/settings/crew"; | |
| 64 | if (x.concurrency > 0 && running >= x.concurrency) context = "all busy"; | |
| 65 | else if (running > 0) context = "running now"; | |
| 66 | else if (x.ready !== null && x.ready.ready === 0) { | |
| 67 | context = "nothing ready"; | |
| 68 | href = "/map"; | |
| 69 | } else if (k.builders.idle !== null) { | |
| 70 | context = k.builders.idle.word; | |
| 71 | href = k.builders.idle.href; | |
| 72 | } | |
| 73 | else context = "idle"; | |
| 74 | return { key: "builders", label: "Builders", value, context: fewWords(context, CONTEXT_WORDS), href, attn: false }; | |
| 75 | } | |
| 76 | ||
| 77 | /** The figures, in the order they are read; every one a line. */ | |
| 78 | export function homeFigures(k: Kpis, x: FigureExtras, live: { sha: string; at: string } | null, now: Date): Figure[] { | |
| 79 | const out: Figure[] = []; | |
| 80 | out.push({ key: "shipped", label: "Shipped", value: `${shippedValue(k.landed, k.landedHours.length)}`, context: "24 h average", href: "/board", attn: false }); | |
| 81 | out.push({ key: "live", label: "Live", value: live === null ? "—" : live.sha.slice(0, 7), context: live === null ? "nothing live" : `since ${live.at.slice(11, 16)}Z`, href: "/releases", attn: false }); | |
| 82 | out.push({ key: "check", label: "Check time", value: checkTime(k.medianCheckMs), context: "median, 24 h", href: "/boards", attn: false }); | |
| 83 | out.push(builders(k, x)); | |
| 84 | if (x.ready !== null) out.push({ key: "ready", label: "Ready", value: String(x.ready.ready), context: `${x.ready.startable} startable`, href: "/map", attn: false }); | |
| 85 | const ceiling = k.spend.ceilingUsd; | |
| 86 | out.push({ | |
| 87 | key: "spend", | |
| 88 | label: "Spend", | |
| 89 | value: money(k.spend.todayUsd), | |
| 90 | context: ceiling === null ? "today, no ceiling" : k.spend.hitAt ? `of ${money(ceiling)}, hit ${k.spend.hitAt.slice(11, 16)}Z` : `of ${money(ceiling)} today`, | |
| 91 | href: "/meter", | |
| 92 | attn: ceiling !== null && k.spend.todayUsd >= ceiling, | |
| 93 | }); | |
| 94 | // The same window as the spend: since UTC midnight. | |
| 95 | out.push({ key: "burn", label: "Burn", value: `${money(k.spend.todayUsd / hoursToday(now))}/h`, context: "since 00:00Z", href: "/meter", attn: false }); | |
| 96 | if (x.week !== null) { | |
| 97 | const used = Math.round(x.week.usedPct); | |
| 98 | const gone = Math.round(x.week.elapsedPct); | |
| 99 | out.push({ key: "week", label: "Week used", value: `${used}%`, context: `${gone}% gone, ${paceWord(x.week.usedPct, x.week.elapsedPct)}`, href: "/subscriptions", attn: false }); | |
| 100 | } | |
| 101 | const overdue = k.backup ? k.backup.state === "red" : backupOverdue(k.backupAt, now); | |
| 102 | out.push({ key: "backup", label: "Backup", value: backupAge(k.backupAt, now), context: overdue ? "overdue" : "off the machine", href: "/settings/backups", attn: overdue }); | |
| 103 | if (k.bugs !== undefined) | |
| 104 | out.push({ key: "bugs", label: "Open bugs", value: String(k.bugs.open), context: k.bugs.overdue > 0 ? `${k.bugs.overdue} late` : "none late", href: "/boards", attn: k.bugs.overdue > 0 }); | |
| 105 | return out; | |
| 106 | } |
src/flow/moving.ts +6 −3
| @@ -9,6 +9,7 @@ import type { Database } from "bun:sqlite"; | ||
| 9 | 9 | import { canRead, getReposByIds, type Repo } from "../core/repos.ts"; |
| 10 | 10 | import type { User } from "../core/users.ts"; |
| 11 | 11 | import { writeStamp } from "../core/write_clock.ts"; |
| 12 | import { clipAtWord } from "../text/clip.ts"; | |
| 12 | 13 | import type { PipelineStage } from "./pipeline.ts"; |
| 13 | 14 | |
| 14 | 15 | /** One line of a list: who, what, where it goes, and when. */ |
| @@ -22,6 +23,8 @@ export interface MovingRow { | ||
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | export const MOVING_ROWS = 3; |
| 26 | /** A title on the home is a line, cut at a word. */ | |
| 27 | export const TITLE_MAX = 60; | |
| 25 | 28 | /** Rows read before the viewer's access filters them; bounded, so the read is. */ |
| 26 | 29 | const SCAN = 40; |
| 27 | 30 | |
| @@ -66,7 +69,7 @@ function visible(db: Database, viewer: User, raw: readonly Raw[], path: string, | ||
| 66 | 69 | if (repo === undefined) continue; |
| 67 | 70 | out.push({ |
| 68 | 71 | who: r.who ?? "", |
| 69 | title: r.title, | |
| 72 | title: clipAtWord(r.title, TITLE_MAX), | |
| 70 | 73 | href: `/${repo.ownerName}/${repo.name}/${r.kind === undefined ? path : r.kind === "pull" ? "pulls" : "issues"}/${r.number}`, |
| 71 | 74 | at: r.at, |
| 72 | 75 | repo: `${repo.ownerName}/${repo.name}`, |
| @@ -89,13 +92,13 @@ export function readBuilding(db: Database, viewer: User, limit = MOVING_ROWS): M | ||
| 89 | 92 | return visible(db, viewer, raw, "issues", limit); |
| 90 | 93 | } |
| 91 | 94 | |
| 92 | /** Changes merged most recently, newest first, each linking to its pull. */ | |
| 95 | /** Changes merged most recently, newest first, each linking to its pull. A Sentinel alarm is not a shipment: it sits under "Needs you". */ | |
| 93 | 96 | export function readShipped(db: Database, viewer: User, limit = MOVING_ROWS): MovingRow[] { |
| 94 | 97 | const raw = scanned(db, "shipped", () => db |
| 95 | 98 | .query<Raw, [number]>( |
| 96 | 99 | `SELECT i.repo_id, i.number, i.title, i.sealed, u.username AS who, p.merged_at AS at |
| 97 | 100 | FROM pull p JOIN issue i ON i.id = p.issue_id LEFT JOIN user u ON u.id = p.merged_by |
| 98 | WHERE p.merged_at IS NOT NULL | |
| 101 | WHERE p.merged_at IS NOT NULL AND i.title NOT LIKE 'Sentinel:%' | |
| 99 | 102 | ORDER BY p.merged_at DESC LIMIT ?1`, |
| 100 | 103 | ) |
| 101 | 104 | .all(SCAN)); |
src/text/clip.ts +10
| @@ -7,3 +7,13 @@ export function clip(text: string, max: number): string { | ||
| 7 | 7 | if (limit === 0) return ""; |
| 8 | 8 | return `${points.slice(0, limit - 1).join("")}…`; |
| 9 | 9 | } |
| 10 | ||
| 11 | /** Like `clip`, but cut at a word boundary: never mid-word, never a dangling bracket or colon before the "…". */ | |
| 12 | export function clipAtWord(text: string, max: number): string { | |
| 13 | const flat = text.replace(/\s+/g, " ").trim(); | |
| 14 | if (Array.from(flat).length <= max) return flat; | |
| 15 | const head = Array.from(flat).slice(0, Math.max(0, max - 1)).join(""); | |
| 16 | const wholeWord = flat.charAt(head.length) === " "; | |
| 17 | const cut = wholeWord ? head : head.slice(0, Math.max(0, head.lastIndexOf(" "))); | |
| 18 | return `${(cut === "" ? head : cut).replace(/[\s(:,;-]+$/, "")}…`; | |
| 19 | } |
src/web/studio/held.ts +4 −8
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Home says what is being held back for a person (#8700): one line per |
| 3 | * repository whose Later gate holds open issues — how many, who set the | |
| 4 | * gate, when — and a link that opens the list. | |
| 3 | * repository whose Later gate holds open issues — how many — and a link that | |
| 4 | * opens the list, where who set the gate and when are written. | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { gateHold } from "../../core/gate_hold.ts"; |
| @@ -11,7 +11,6 @@ import type { User } from "../../core/users.ts"; | ||
| 11 | 11 | import type { Ctx } from "../../http/context.ts"; |
| 12 | 12 | import { repoBase } from "../chrome.ts"; |
| 13 | 13 | import { html, type Html } from "../html.ts"; |
| 14 | import { time } from "../ui.ts"; | |
| 15 | 14 | import { writableAppsOf } from "./asks.ts"; |
| 16 | 15 | |
| 17 | 16 | /** The repositories whose gate holds work back from this person, with the hold. */ |
| @@ -39,11 +38,8 @@ export function heldLine(ctx: Ctx, user: User): Html | null { | ||
| 39 | 38 | ${found.map( |
| 40 | 39 | ({ repo, hold }) => |
| 41 | 40 | html`<p class="small"> |
| 42 | <a href="${repoBase(repo)}/held" | |
| 43 | >${hold.held} ${hold.held === 1 ? "issue is" : "issues are"} held | |
| 44 | behind the Later gate</a | |
| 45 | > | |
| 46 | in ${repo.name}, set by ${hold.by} ${time(hold.since)} | |
| 41 | <a href="${repoBase(repo)}/held" title="Set by ${hold.by}">${hold.held} held behind Later</a> | |
| 42 | <span class="muted">in ${repo.name}</span> | |
| 47 | 43 | </p>`, |
| 48 | 44 | )} |
| 49 | 45 | </section>`; |
src/web/studio/home.ts +2 −4
| @@ -62,8 +62,7 @@ import { composer, feedJs, feedNote, feedRegion, registerWorkerJs } from "./feed | ||
| 62 | 62 | import { heldLine } from "./held.ts"; |
| 63 | 63 | import { appChips, movingRegion, tellBox } from "./living.ts"; |
| 64 | 64 | import { alarmLines, cachedAlarms } from "./alarm_lines.ts"; |
| 65 | import { kpiRow, waitingLine } from "./kpi_row.ts"; | |
| 66 | import { homeWeek } from "./week_line.ts"; | |
| 65 | import { figureExtras, kpiRow, waitingLine } from "./kpi_row.ts"; | |
| 67 | 66 | import { feedCandidateCache } from "../../feed/feed.ts"; |
| 68 | 67 | import { notePhase, notePhaseRest, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| 69 | 68 | import { idleReason } from "../../crew/idle_reason.ts"; |
| @@ -250,8 +249,7 @@ export function homeDraws(ctx: Ctx, user: User): Record<HomeRegion, () => Html | | ||
| 250 | 249 | // The figures and the week's pace open in place; alarms need the owner, so they sit under "Needs you". |
| 251 | 250 | return html`${disclosure( |
| 252 | 251 | "Figures", |
| 253 | html`${timePhase(request, "kpis", () => kpiRow(db, kpiOpts), () => kpiCache(db))} | |
| 254 | ${homeWeek(ctx.app, user)}`, | |
| 252 | html`${timePhase(request, "kpis", () => kpiRow(db, kpiOpts, figureExtras(ctx.app)), () => kpiCache(db))}`, | |
| 255 | 253 | { small: true, id: "home-figures" }, |
| 256 | 254 | )}`; |
| 257 | 255 | }, |
src/web/studio/kpi_row.ts +57 −128
| @@ -1,26 +1,27 @@ | ||
| 1 | 1 | /** |
| 2 | * Home's row of figures (#2871, #2713), from `flow/kpis.ts`: shipped per | |
| 3 | * hour with a day's sparkline, the live version and since when, the median | |
| 4 | * check time, the crew builders running of their slots, the crew's spend | |
| 5 | * today of the daily ceiling, the age of the last off-box backup, who used the | |
| 6 | * answering time, browsers that reported back with 30 days as a sparkline, | |
| 7 | * accounts seen today, and reported page speed. What each one counts is in | |
| 8 | * `KPI_COUNTS`; `/api/v1/admin/kpis/probe` recomputes them. | |
| 9 | * Server-rendered, one fixed-height §5 stat tile each, so nothing moves when | |
| 10 | * it paints. Only the studio's words: shipped, change, check time. | |
| 2 | * Home's figures (#2871, #10440), from `flow/kpis.ts` and `flow/home_figures.ts`: | |
| 3 | * each one line, a label, a number and a few words, opening the page it comes | |
| 4 | * from. Server-rendered, so nothing moves when it paints. What each one counts | |
| 5 | * is in `KPI_COUNTS`; `/api/v1/admin/kpis/probe` recomputes them. | |
| 11 | 6 | */ |
| 12 | 7 | |
| 13 | 8 | import type { Database } from "bun:sqlite"; |
| 14 | import { KPI_COUNTS, backupFull, backupOverdue, backupValue, buildersValue, checkTime, reactNote, shippedValue, speedWords, spendCeilingWords, spendFull, spendValue, trafficValue, trafficWords, usersValue, visitorsNote, visitorsValue, waitingWords } from "../../flow/kpi_words.ts"; | |
| 15 | import { perfRecord } from "../../perf/live.ts"; | |
| 16 | import type { TrafficClass, TrafficMinute, TrafficTotals } from "../../perf/traffic.ts"; | |
| 9 | import type { App } from "../../app.ts"; | |
| 10 | import { capacityValue } from "../../core/capacity.ts"; | |
| 11 | import { crewPace } from "../../crew/week_read.ts"; | |
| 12 | import { readyCounts } from "../../crew/ready_counts.ts"; | |
| 13 | import { waitingWords } from "../../flow/kpi_words.ts"; | |
| 14 | import { homeFigures, type Figure, type FigureExtras } from "../../flow/home_figures.ts"; | |
| 15 | import type { TrafficClass, TrafficMinute } from "../../perf/traffic.ts"; | |
| 17 | 16 | import type { IdleReason } from "../../crew/idle_reason.ts"; |
| 18 | 17 | import type { KpiTimer, Kpis } from "../../flow/kpis.ts"; |
| 19 | import { cachedKpis, cachedWaiting } from "./home_cache.ts"; | |
| 18 | import { HOME_MAX_AGE_MS, cachedKpis, cachedWaiting } from "./home_cache.ts"; | |
| 19 | import { Stamped } from "../../kernel/stamped.ts"; | |
| 20 | import { writeStamp } from "../../core/write_clock.ts"; | |
| 20 | 21 | import { escapeHtml, html, raw, type Html } from "../html.ts"; |
| 21 | 22 | import { BOOTED } from "../../release/gate.ts"; |
| 22 | 23 | import { running } from "../../kernel/version.ts"; |
| 23 | import { sha, stat, time } from "../ui.ts"; | |
| 24 | import { row } from "../ui.ts"; | |
| 24 | 25 | import type { User } from "../../core/users.ts"; |
| 25 | 26 | import { reviewSetOf } from "./review_set.ts"; |
| 26 | 27 | import { staleArchive } from "./review_stale.ts"; |
| @@ -38,13 +39,6 @@ function svg(label: string, body: string): Html { | ||
| 38 | 39 | return raw(`<svg viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" role="img" aria-label="${label}">${body}</svg>`); |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | /** A series oldest first as a fixed-size SVG polyline; the numbers are the only input. */ | |
| 42 | function spark(series: readonly number[], label: string): Html { | |
| 43 | const top = Math.max(1, ...series); | |
| 44 | const points = series.map((v, i) => at(i, series.length, v, top).join(",")).join(" "); | |
| 45 | return svg(label, `<polyline points="${points}" fill="none" stroke="currentColor" stroke-width="1.5"/>`); | |
| 46 | } | |
| 47 | ||
| 48 | 42 | /** |
| 49 | 43 | * Days oldest first where `null` is a day with no data: the line breaks there |
| 50 | 44 | * rather than dropping to zero. Each run of numbers is its own polyline on |
| @@ -75,16 +69,6 @@ export function daySpark(days: readonly (number | null)[], label: string): Html | ||
| 75 | 69 | return svg(escapeHtml(label), body); |
| 76 | 70 | } |
| 77 | 71 | |
| 78 | /** The last 24 hours, newest first in, oldest on the left out. */ | |
| 79 | export function sparkline(hours: readonly number[]): Html { | |
| 80 | return spark([...hours].reverse(), "Shipped each hour over the last 24 hours"); | |
| 81 | } | |
| 82 | ||
| 83 | /** Distinct visitors per day, oldest first, today on the right. */ | |
| 84 | export function visitorsSpark(days: readonly number[]): Html { | |
| 85 | return spark(days, `Distinct visitors each day over the last ${days.length} days`); | |
| 86 | } | |
| 87 | ||
| 88 | 72 | /** Lightest first, stacked from the bottom: the strangers sit on top and read darkest. */ |
| 89 | 73 | export const TRAFFIC_TONES: readonly (readonly [TrafficClass, string])[] = [ |
| 90 | 74 | ["internal", "0.12"], |
| @@ -109,115 +93,60 @@ export function trafficColumns(minutes: readonly TrafficMinute[], width: number, | ||
| 109 | 93 | return raw(`<svg viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" role="img" aria-label="${escapeHtml(label)}">${rects.join("")}</svg>`); |
| 110 | 94 | } |
| 111 | 95 | |
| 112 | function tile(label: string, href: string, value: Html | string, full: string, note: string | Html, title: string, extra: Html | null = null, tone: "attn" | null = null): Html { | |
| 113 | return stat({ label, href, value, title: full, note, noteTitle: title, aria: `${label}: ${full}, ${title}`, spark: extra, ...(tone === null ? {} : { tone }) }); | |
| 114 | } | |
| 115 | ||
| 116 | 96 | /** The version this forge is running, and since when: the same source as `/releases`. */ |
| 117 | 97 | export function liveNow(): { sha: string; at: string } | null { |
| 118 | 98 | const commit = running().commit; |
| 119 | 99 | return commit === null ? null : { sha: commit, at: BOOTED }; |
| 120 | 100 | } |
| 121 | 101 | |
| 122 | export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now: Date = new Date(), traffic: TrafficTotals | null = null): Html { | |
| 123 | const idle = k.builders.idle; | |
| 124 | const overdue = k.backup ? k.backup.state === "red" : backupOverdue(k.backupAt, now); | |
| 125 | const spendWords = spendCeilingWords(k.spend); | |
| 126 | const rate = shippedValue(k.landed, k.landedHours.length); | |
| 127 | const trafficSays = traffic === null ? null : trafficWords(traffic); | |
| 128 | return html`<section class="stats kpi-row mb" aria-label="The forge's figures, each over its own window; hover one for what it counts"> | |
| 129 | ${tile( | |
| 130 | "Shipped per hour", | |
| 131 | "/board", | |
| 132 | rate, | |
| 133 | Number((k.landed / k.landedHours.length).toFixed(2)).toString(), | |
| 134 | `${k.landed} ${k.landed === 1 ? "change" : "changes"} in 24 h`, | |
| 135 | `${k.landed} ${k.landed === 1 ? "change" : "changes"} in 24 h. ${KPI_COUNTS.shipped}`, | |
| 136 | sparkline(k.landedHours), | |
| 102 | /** Each figure one line: label, number, a few words, and the page it comes from. */ | |
| 103 | export function figureLines(figures: readonly Figure[]): Html { | |
| 104 | return html`<ul class="list kpi-row" aria-label="The forge's figures; each opens where it comes from"> | |
| 105 | ${figures.map((f) => | |
| 106 | row({ | |
| 107 | href: f.href, | |
| 108 | title: f.label, | |
| 109 | trail: html`<span class="num"${f.attn ? html` data-tone="attn"` : null}><strong>${f.value}</strong></span> <span class="muted small">${f.context}</span>`, | |
| 110 | }), | |
| 137 | 111 | )} |
| 138 | ${tile( | |
| 139 | "Live version", | |
| 140 | "/releases", | |
| 141 | live === null ? "—" : sha(live.sha), | |
| 142 | live === null ? "Nothing live yet" : live.sha, | |
| 143 | live === null ? "Nothing live yet" : html`live ${time(live.at)}`, | |
| 144 | live === null ? "Nothing live yet" : `Live since ${live.at}. ${KPI_COUNTS.live}`, | |
| 145 | )} | |
| 146 | ${tile( | |
| 147 | "Median check time", | |
| 148 | "/boards", | |
| 149 | checkTime(k.medianCheckMs), | |
| 150 | k.medianCheckMs === null ? "No check finished in 24 h" : checkTime(k.medianCheckMs), | |
| 151 | k.medianCheckMs === null ? "No check finished in 24 h" : "over the last 24 h", | |
| 152 | k.medianCheckMs === null ? "No check finished in 24 h" : KPI_COUNTS.checks, | |
| 153 | )} | |
| 154 | ${tile( | |
| 155 | "Builders running", | |
| 156 | idle?.href ?? "/settings/crew", | |
| 157 | buildersValue(k.builders), | |
| 158 | buildersValue(k.builders), | |
| 159 | k.builders.slots === 0 ? "No slots set" : idle?.word ?? "running now", | |
| 160 | k.builders.slots === 0 ? "No slots set" : `${KPI_COUNTS.builders} ${k.builders.slots} ${k.builders.slots === 1 ? "slot" : "slots"} set.`, | |
| 161 | )} | |
| 162 | ${tile( | |
| 163 | "Crew spend today", | |
| 164 | "/settings/crew", | |
| 165 | spendValue(k.spend), | |
| 166 | spendFull(k.spend), | |
| 167 | spendWords.note, | |
| 168 | spendWords.title, | |
| 169 | null, | |
| 170 | spendWords.attn ? "attn" : null, | |
| 171 | )} | |
| 172 | ${tile( | |
| 173 | "Last off-box backup", | |
| 174 | "/settings/backups", | |
| 175 | backupValue(k, now), | |
| 176 | backupFull(k.backupAt), | |
| 177 | k.backup ? k.backup.note : k.backupAt === null ? "no backup off the machine yet" : overdue ? "overdue, more than 24 h" : "off the machine", | |
| 178 | k.backup ? `${k.backup.reasons[0] ?? k.backup.unknowns[0] ?? k.backup.line} ${k.backup.checkLine}` : overdue ? "Overdue: the last off-box backup is more than 24 h old" : "Age of the last off-box backup", | |
| 179 | null, | |
| 180 | overdue ? "attn" : null, | |
| 181 | )} | |
| 182 | ${k.bugs === undefined ? null : tile( | |
| 183 | "Open bugs", | |
| 184 | "/boards", | |
| 185 | String(k.bugs.open), | |
| 186 | `${k.bugs.open} open ${k.bugs.open === 1 ? "bug" : "bugs"}`, | |
| 187 | k.bugs.overdue > 0 ? `${k.bugs.overdue} past its clock` : "none past its clock", | |
| 188 | "Open bugs, and those past their clock: 4 h high, 48 h otherwise", | |
| 189 | null, | |
| 190 | k.bugs.overdue > 0 ? "attn" : null, | |
| 191 | )} | |
| 192 | ${traffic === null || trafficSays === null ? null : tile( | |
| 193 | "Traffic, 15 min", | |
| 194 | "/settings/traffic", | |
| 195 | trafficValue(traffic), | |
| 196 | `${traffic.requests} requests, ${traffic.refused} refused`, | |
| 197 | trafficSays.note, | |
| 198 | trafficSays.title, | |
| 199 | trafficColumns(traffic.minutes, W, H, "Answering time each minute over the last 15 minutes, by who asked"), | |
| 200 | trafficSays.attn ? "attn" : null, | |
| 201 | )} | |
| 202 | ${tile("Reporting browsers", "/boards/reach", visitorsValue(k.reach), `${visitorsValue(k.reach)}, ${visitorsNote(k.reach)}`, visitorsNote(k.reach), KPI_COUNTS.visitors, visitorsSpark(k.reach.visitorDays))} | |
| 203 | ${tile("Accounts", "/boards/reach", usersValue(k.reach), usersValue(k.reach), "seen today", KPI_COUNTS.accounts)} | |
| 204 | ${tile( | |
| 205 | "Reported page speed", | |
| 206 | "/boards/reach", | |
| 207 | speedWords(k.reach.loadP75), | |
| 208 | speedWords(k.reach.loadP75), | |
| 209 | reactNote(k.reach), | |
| 210 | KPI_COUNTS.speed, | |
| 211 | )} | |
| 212 | </section>`; | |
| 112 | </ul>`; | |
| 113 | } | |
| 114 | ||
| 115 | export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now: Date = new Date(), extras?: FigureExtras): Html { | |
| 116 | return figureLines(homeFigures(k, extras ?? { concurrency: k.builders.slots, ready: null, week: null }, live, now)); | |
| 213 | 117 | } |
| 214 | 118 | |
| 215 | 119 | /** The figures count every repository, so the caller shows this to an admin only. */ |
| 216 | export function kpiRow(db: Database, opts: { ceilingUsd?: number; dataDir?: string; idle?: () => IdleReason | null; now?: Date; time?: KpiTimer } = {}): Html { | |
| 120 | export function kpiRow(db: Database, opts: { ceilingUsd?: number; dataDir?: string; idle?: () => IdleReason | null; now?: Date; time?: KpiTimer } = {}, extras?: FigureExtras): Html { | |
| 217 | 121 | const now = opts.now ?? new Date(); |
| 218 | 122 | const forge = { ceilingUsd: opts.ceilingUsd ?? null, ...(opts.dataDir === undefined ? {} : { dataDir: opts.dataDir }), ...(opts.idle === undefined ? {} : { idle: opts.idle }) }; |
| 219 | // Read fresh from memory: no query, so it costs home nothing during a flood. | |
| 220 | return kpiRowFor(cachedKpis(db, now, forge, opts.time), liveNow(), now, perfRecord.ledger.totals(now.getTime())); | |
| 123 | return kpiRowFor(cachedKpis(db, now, forge, opts.time), liveNow(), now, extras); | |
| 124 | } | |
| 125 | ||
| 126 | const extrasCaches = new WeakMap<Database, Stamped<FigureExtras>>(); | |
| 127 | ||
| 128 | /** | |
| 129 | * The live reads the figures need beyond `Kpis`: the crew's real concurrency, | |
| 130 | * what is ready, the week. The ready count walks every autonomous repository, | |
| 131 | * so it is read once per write (30 s at most), as the alarms are. | |
| 132 | */ | |
| 133 | export function figureExtras(app: App, now: Date = new Date()): FigureExtras { | |
| 134 | const read = (): FigureExtras => { | |
| 135 | const pace = crewPace(app, now); | |
| 136 | return { | |
| 137 | concurrency: Number(capacityValue(app.db, "crew.concurrency")), | |
| 138 | ready: readyCounts(app), | |
| 139 | week: pace === null ? null : { usedPct: 100 - pace.freePct, elapsedPct: pace.elapsedPct }, | |
| 140 | }; | |
| 141 | }; | |
| 142 | const stamp = writeStamp(app.db); | |
| 143 | if (stamp === undefined) return read(); | |
| 144 | let cache = extrasCaches.get(app.db); | |
| 145 | if (cache === undefined) { | |
| 146 | cache = new Stamped<FigureExtras>({ maxEntries: 2, maxAgeMs: HOME_MAX_AGE_MS }); | |
| 147 | extrasCaches.set(app.db, cache); | |
| 148 | } | |
| 149 | return cache.get("extras", stamp, read); | |
| 221 | 150 | } |
| 222 | 151 | |
| 223 | 152 | /** |
src/web/studio/week_line.ts +4 −16
| @@ -1,27 +1,15 @@ | ||
| 1 | 1 | /** |
| 2 | * Home's week (#8695, #8961): for the owner, the crew line (percent of the | |
| 3 | * week left, when it runs out at this pace), then the pace sentence without | |
| 4 | * those figures and beside it what a real landing costs (`weekWords`). Both | |
| 5 | * in the same muted small style, read as one block. Empty while no account | |
| 6 | * is metered. | |
| 2 | * The week's pace sentence (#8695), for the Spend page. Home shows the week as | |
| 3 | * one figure line (`flow/home_figures.ts`, #10440). Empty while no account is | |
| 4 | * metered. | |
| 7 | 5 | */ |
| 8 | 6 | |
| 9 | 7 | import type { App } from "../../app.ts"; |
| 10 | import { crewLineWords, weekWords } from "../../crew/week_read.ts"; | |
| 8 | import { weekWords } from "../../crew/week_read.ts"; | |
| 11 | 9 | import { html, type Html } from "../html.ts"; |
| 12 | 10 | |
| 13 | type Viewer = { readonly isAdmin: boolean } | undefined; | |
| 14 | ||
| 15 | 11 | /** The full pace sentence, for pages without the crew line (Spend). */ |
| 16 | 12 | export function weekLine(app: App, now: Date = new Date()): Html { |
| 17 | 13 | const words = weekWords(app, now); |
| 18 | 14 | return words === null ? html`` : html`<p class="small muted break">${words}</p>`; |
| 19 | 15 | } |
| 20 | ||
| 21 | /** Home's week: the owner reads the crew line and the sentence under it, the percent said once; anyone else the full sentence. */ | |
| 22 | export function homeWeek(app: App, viewer: Viewer, now: Date = new Date()): Html { | |
| 23 | const crew = viewer?.isAdmin === true ? crewLineWords(app, now) : null; | |
| 24 | if (crew === null) return weekLine(app, now); | |
| 25 | const words = weekWords(app, now, true); | |
| 26 | return html`<p class="small muted break" id="crew-pace">${crew}</p>${words === null ? html`` : html`<p class="small muted break">${words}</p>`}`; | |
| 27 | } |
test/backup-truth.test.ts +1 −2
| @@ -289,8 +289,7 @@ test("the check records each run; stopped past its interval, the verdict, tile, | ||
| 289 | 289 | expect(v.checkLine).toContain("2 runs on record"); |
| 290 | 290 | const tile = kpiRowFor({ landedHours: Array(24).fill(0), landed: 0, live: null, builders: { running: 0, slots: 1, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null, backupAt: null, backup: v, reach: NO_REACH }, null, new Date(later)).toString(); |
| 291 | 291 | expect(tile).toContain("attn"); |
| 292 | expect(tile).toContain("check stopped"); | |
| 293 | expect(tile).toContain(`last ran ${ranAt}`); | |
| 292 | expect(tile).toContain("overdue"); | |
| 294 | 293 | Date.now = () => later; |
| 295 | 294 | const card = vitals({ db: own.db, signals: own.signals, dataDir: dir, now: later }).degraded.find((d) => d.cause === "backup"); |
| 296 | 295 | expect(card?.sentence).toContain(`last ran ${ranAt}`); |
test/clip-at-word.test.ts added +17
| @@ -0,0 +1,17 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { clipAtWord } from "../src/text/clip.ts"; | |
| 3 | ||
| 4 | test("a title that fits is unchanged; a long one is cut at a word, not mid-sentence of a URL", () => { | |
| 5 | expect(clipAtWord("Short title", 60)).toBe("Short title"); | |
| 6 | const out = clipAtWord("Release 0.7.495 is unproven: https://forge.open-platform.sh/search?q=a did not answer within 200 ms", 40); | |
| 7 | expect(out).toBe("Release 0.7.495 is unproven…"); | |
| 8 | expect(Array.from(out).length).toBeLessThanOrEqual(40); | |
| 9 | }); | |
| 10 | ||
| 11 | test("a cut never leaves a dangling colon or bracket before the ellipsis", () => { | |
| 12 | expect(clipAtWord("Fix the thing (really long parenthetical here)", 15)).toBe("Fix the thing…"); | |
| 13 | }); | |
| 14 | ||
| 15 | test("one very long word is cut in place", () => { | |
| 16 | expect(clipAtWord("x".repeat(100), 10)).toBe("xxxxxxxxx…"); | |
| 17 | }); |
test/flow-alarm-private.test.ts +1 −1
| @@ -39,6 +39,6 @@ test("the owner's alarms name the private pull; an agent's leave it and the idle | ||
| 39 | 39 | }); |
| 40 | 40 | |
| 41 | 41 | test("the terminal's flow screen draws the fired alarm for the owner and not for an agent", () => { |
| 42 | expect(flowLines(app.db, NOW, []).join("\n")).toContain("alice/secretrepo#1 has sat approved"); | |
| 42 | expect(flowLines(app.db, NOW, []).join("\n")).toContain("alice/secretrepo#1 sat approved"); | |
| 43 | 43 | expect(flowLines(app.db, NOW, [], { queues: [] }).join("\n")).not.toContain("secretrepo"); |
| 44 | 44 | }); |
test/flow-alarm-stuck.test.ts +4 −4
| @@ -82,7 +82,7 @@ describe("alarmStuck", () => { | ||
| 82 | 82 | const a = alarmStuck(app.db, NOW); |
| 83 | 83 | expect(a.fired).toBe(true); |
| 84 | 84 | expect(a.since).toBe(ago(31)); |
| 85 | expect(a.says).toBe(`alice/r#${num} has sat approved for 31 minutes; its last event was a red check at 11:29.`); | |
| 85 | expect(a.says).toBe(`alice/r#${num} sat approved 31 minutes, last a red check 11:29`); | |
| 86 | 86 | }); |
| 87 | 87 | |
| 88 | 88 | test("a walled pull says a person must decide, in plain words (#7847)", () => { |
| @@ -99,7 +99,7 @@ describe("alarmStuck", () => { | ||
| 99 | 99 | wall("h"); |
| 100 | 100 | const a = alarmStuck(app, NOW); |
| 101 | 101 | expect(a.wall).toEqual(["anyone signed out could read pack records"]); |
| 102 | expect(a.says).toContain("waits for a person: anyone signed out could read pack records"); | |
| 102 | expect(a.says).toBe(`alice/r#${a.number} approved, waits for you`); | |
| 103 | 103 | }); |
| 104 | 104 | |
| 105 | 105 | test("an event 29 minutes ago does not fire", () => { |
| @@ -121,7 +121,7 @@ describe("alarmStuck", () => { | ||
| 121 | 121 | pull({ eventMin: 90 }); |
| 122 | 122 | const old = pull({ eventMin: 5 * 1440, check: "ok" }); |
| 123 | 123 | const a = alarmStuck(app, NOW); |
| 124 | expect(a.says).toStartWith(`alice/r#${old} has sat approved for 5 days; its last event was a green check at `); | |
| 124 | expect(a.says).toStartWith(`alice/r#${old} sat approved 5 days, last a green check `); | |
| 125 | 125 | }); |
| 126 | 126 | |
| 127 | 127 | test("a stale approval (for an old head) or a merged pull never counts", () => { |
| @@ -187,7 +187,7 @@ describe("alarmStuck", () => { | ||
| 187 | 187 | app.db.run("INSERT INTO repo (id, owner_id, name) VALUES ('q', ?1, 'quiet')", [userId("alice")]); |
| 188 | 188 | const num = pull({ eventMin: 600, repo: "q" }); |
| 189 | 189 | expect(alarmStuck(app, NOW).fired).toBe(false); |
| 190 | expect(alarmStuck(app, NOW, { repoId: "q" }).says).toStartWith(`alice/quiet#${num} has sat`); | |
| 190 | expect(alarmStuck(app, NOW, { repoId: "q" }).says).toStartWith(`alice/quiet#${num} sat approved`); | |
| 191 | 191 | expect(alarmStuck(app, NOW, { repoId: "r" }).fired).toBe(false); |
| 192 | 192 | app.db.run("DELETE FROM repo WHERE id = 'q'"); |
| 193 | 193 | }); |
test/flow-bugs.test.ts +2 −2
| @@ -95,11 +95,11 @@ describe("bug clock", () => { | ||
| 95 | 95 | }); |
| 96 | 96 | |
| 97 | 97 | describe("home's bug figure", () => { |
| 98 | test("the tile shows the open count and how many are past their clock", async () => { | |
| 98 | test("the figure shows the open count and how many are past their clock", async () => { | |
| 99 | 99 | const { kpiRowFor } = await import("../src/web/studio/kpi_row.ts"); |
| 100 | 100 | const { NO_REACH } = await import("../src/flow/reach.ts"); |
| 101 | 101 | const k = { landedHours: new Array<number>(24).fill(0), landed: 0, live: null, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }; |
| 102 | expect(kpiRowFor({ ...k, bugs: { open: 4, overdue: 2 } }, null).toString()).toContain("2 past its clock"); | |
| 102 | expect(kpiRowFor({ ...k, bugs: { open: 4, overdue: 2 } }, null).toString()).toContain("2 late"); | |
| 103 | 103 | expect(kpiRowFor(k, null).toString()).not.toContain("Open bugs"); |
| 104 | 104 | }); |
| 105 | 105 | }); |
test/home-builders-idle.test.ts +2 −2
| @@ -90,7 +90,7 @@ async function terminal(): Promise<string> { | ||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** The builders tile's anchor on home. */ |
| 93 | const tile = (page: string): string => /<a class="stat" href="[^"]*"[^>]*><span class="stat-label">Builders running.*?<\/a>/s.exec(page)?.[0] ?? ""; | |
| 93 | const tile = (page: string): string => /<a href="[^"]*" class="row"[^>]*>(?:(?!<\/a>)[\s\S])*?>Builders<\/span\s*>[\s\S]*?<\/a>/.exec(page)?.[0] ?? ""; | |
| 94 | 94 | |
| 95 | 95 | test("nothing ready: the map has nothing a builder may start", async () => { |
| 96 | 96 | const page = await home(); |
| @@ -104,7 +104,7 @@ test("a ready issue and a builder with room: no reason is named", async () => { | ||
| 104 | 104 | if (!opened.ok) throw new Error(String(opened.error)); |
| 105 | 105 | const page = await home(); |
| 106 | 106 | expect(tile(page)).not.toContain("nothing ready"); |
| 107 | expect(tile(page)).toContain("running now"); | |
| 107 | expect(tile(page)).toContain("idle"); | |
| 108 | 108 | expect(await terminal()).not.toMatch(/Builders running 0 of 1 · (nothing|no sub|ceiling)/); |
| 109 | 109 | }); |
| 110 | 110 |
test/home-cache.test.ts +2 −3
| @@ -45,7 +45,7 @@ afterAll(async () => { | ||
| 45 | 45 | |
| 46 | 46 | test("a warm home reads neither the KPIs nor the panels again, even after a write", async () => { |
| 47 | 47 | const a = await home(f.ownerCookie); |
| 48 | expect(a).toContain('class="stats kpi-row mb"'); | |
| 48 | expect(a).toContain('class="list kpi-row"'); | |
| 49 | 49 | expect(a).toContain("<h2>Pin A</h2>"); |
| 50 | 50 | const kpi = kpiCache(f.app.db); |
| 51 | 51 | const panel = panelCache(f.app.db); |
| @@ -66,8 +66,7 @@ test("the owner's KPIs and panels never render for another viewer, warm or not", | ||
| 66 | 66 | await home(f.ownerCookie); |
| 67 | 67 | for (const cookie of [f.peerCookie, undefined]) { |
| 68 | 68 | const page = await home(cookie); |
| 69 | expect(page).not.toContain('class="stats kpi-row mb"'); | |
| 70 | expect(page).not.toContain('class="stat"'); | |
| 69 | expect(page).not.toContain('class="list kpi-row"'); | |
| 71 | 70 | expect(page).not.toContain("Pin A"); |
| 72 | 71 | } |
| 73 | 72 | }); |
test/home-figures.test.ts added +140
| @@ -0,0 +1,140 @@ | ||
| 1 | /** | |
| 2 | * The home's figures agree with each other and with their sources (#10440): | |
| 3 | * slots shown are `crew.concurrency`, "nothing ready" only when the map has | |
| 4 | * nothing ready, spend and burn are one window, "behind" only when less of | |
| 5 | * the week is used than has gone by, and every figure is a label, a number | |
| 6 | * and at most four words, linking where it comes from. | |
| 7 | */ | |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 14 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 15 | import { createIssue } from "../src/core/issues.ts"; | |
| 16 | import { createSession } from "../src/core/sessions.ts"; | |
| 17 | import type { User } from "../src/core/users.ts"; | |
| 18 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 19 | import { readyCounts } from "../src/crew/ready_counts.ts"; | |
| 20 | import { CONTEXT_WORDS, homeFigures, paceWord, type FigureExtras } from "../src/flow/home_figures.ts"; | |
| 21 | import type { Kpis } from "../src/flow/kpis.ts"; | |
| 22 | import { NO_REACH } from "../src/flow/reach.ts"; | |
| 23 | import { kpiCache } from "../src/web/studio/home_cache.ts"; | |
| 24 | import { figureExtras } from "../src/web/studio/kpi_row.ts"; | |
| 25 | import { freshHome } from "./helpers/home-fresh.ts"; | |
| 26 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 27 | import { quietLogs } from "./helpers/globals.ts"; | |
| 28 | ||
| 29 | quietLogs(); | |
| 30 | ||
| 31 | const NOW = new Date("2026-11-09T23:30:00.000Z"); | |
| 32 | const kpis = (over: Partial<Kpis> = {}): Kpis => ({ | |
| 33 | landedHours: Array(24).fill(0), landed: 0, live: null, medianCheckMs: null, backupAt: null, reach: NO_REACH, | |
| 34 | builders: { running: 4, slots: 16, idle: null }, spend: { todayUsd: 511, ceilingUsd: 600 }, | |
| 35 | ...over, | |
| 36 | }); | |
| 37 | const extras = (over: Partial<FigureExtras> = {}): FigureExtras => ({ | |
| 38 | concurrency: 4, ready: { ready: 49, startable: 7 }, week: { usedPct: 27, elapsedPct: 27 }, ...over, | |
| 39 | }); | |
| 40 | const byKey = (k: Kpis, x: FigureExtras) => new Map(homeFigures(k, x, null, NOW).map((f) => [f.key, f])); | |
| 41 | ||
| 42 | describe("figures from a fixture", () => { | |
| 43 | test("builders show the crew's concurrency, not the slots' ceiling", () => { | |
| 44 | const f = byKey(kpis(), extras()).get("builders")!; | |
| 45 | expect(f.value).toBe("4 of 4"); | |
| 46 | expect(f.value).not.toContain("16"); | |
| 47 | }); | |
| 48 | ||
| 49 | test("'nothing ready' only when the map has none ready", () => { | |
| 50 | const idle = kpis({ builders: { running: 0, slots: 16, idle: null } }); | |
| 51 | expect(byKey(idle, extras()).get("builders")!.context).not.toContain("nothing ready"); | |
| 52 | expect(byKey(idle, extras({ ready: { ready: 0, startable: 0 } })).get("builders")!.context).toBe("nothing ready"); | |
| 53 | expect(byKey(idle, extras({ ready: { ready: 49, startable: 7 } })).get("ready")!.value).toBe("49"); | |
| 54 | }); | |
| 55 | ||
| 56 | test("spend and burn read the same window: since midnight UTC", () => { | |
| 57 | const f = byKey(kpis(), extras()); | |
| 58 | expect(f.get("spend")!.value).toBe("$511"); | |
| 59 | // 23.5 h into the day: $511 / 23.5 h = $21.74 an hour; never 0% beside $511. | |
| 60 | expect(f.get("burn")!.value).toBe("$22/h"); | |
| 61 | expect(f.get("burn")!.context).toBe("since 00:00Z"); | |
| 62 | expect(byKey(kpis({ spend: { todayUsd: 0, ceilingUsd: 600 } }), extras()).get("burn")!.value).toBe("$0.00/h"); | |
| 63 | }); | |
| 64 | ||
| 65 | test("'behind' only when less of the week is used than has gone by", () => { | |
| 66 | expect(paceWord(10, 27)).toBe("behind"); | |
| 67 | expect(paceWord(27, 27)).toBe("on pace"); | |
| 68 | expect(paceWord(25, 27)).toBe("on pace"); | |
| 69 | expect(paceWord(60, 27)).toBe("ahead"); | |
| 70 | // 25% of the week left at 27% gone is 73% used: ahead of the clock, not behind. | |
| 71 | const week = byKey(kpis(), extras({ week: { usedPct: 73, elapsedPct: 27 } })).get("week")!; | |
| 72 | expect(week.context).toContain("ahead"); | |
| 73 | expect(week.context).not.toContain("behind"); | |
| 74 | expect(byKey(kpis(), extras({ week: { usedPct: 5, elapsedPct: 27 } })).get("week")!.context).toContain("behind"); | |
| 75 | }); | |
| 76 | ||
| 77 | test("every figure is a label, a number and at most four words, and opens where it comes from", () => { | |
| 78 | for (const x of [extras(), extras({ ready: null, week: null }), extras({ ready: { ready: 0, startable: 0 } })]) { | |
| 79 | for (const f of homeFigures(kpis({ bugs: { open: 3, overdue: 1 } }), x, { sha: "abcdef0123", at: "2026-11-09T10:00:00.000Z" }, NOW)) { | |
| 80 | expect(f.label.length).toBeGreaterThan(0); | |
| 81 | expect(f.value.length).toBeGreaterThan(0); | |
| 82 | expect(f.context.split(/\s+/).length).toBeLessThanOrEqual(CONTEXT_WORDS); | |
| 83 | expect(f.href).toMatch(/^\/[a-z]/); | |
| 84 | } | |
| 85 | } | |
| 86 | }); | |
| 87 | ||
| 88 | test("figures that no decision uses are gone", () => { | |
| 89 | const labels = homeFigures(kpis(), extras(), null, NOW).map((f) => f.label.toLowerCase()).join(" "); | |
| 90 | for (const gone of ["accounts", "reporting", "traffic", "page speed"]) expect(labels).not.toContain(gone); | |
| 91 | }); | |
| 92 | }); | |
| 93 | ||
| 94 | describe("the page against its sources", () => { | |
| 95 | let dir: string, app: App, servers: Servers, admin: User; | |
| 96 | ||
| 97 | beforeAll(async () => { | |
| 98 | dir = await mkdtemp(join(tmpdir(), "forge-home-figures-")); | |
| 99 | app = createApp({ dataDir: dir, port: 0 }); | |
| 100 | servers = await serve(app); | |
| 101 | const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-passphrase" }); | |
| 102 | if (!a.ok) throw new Error("signup failed"); | |
| 103 | admin = a.value; | |
| 104 | }); | |
| 105 | afterAll(async () => { | |
| 106 | servers.stop(); | |
| 107 | app.close(); | |
| 108 | await rm(dir, { recursive: true, force: true }); | |
| 109 | }); | |
| 110 | ||
| 111 | test("slots shown equal crew.concurrency, and ready equals the map's", async () => { | |
| 112 | app.db.query("INSERT OR REPLACE INTO forge_setting (key, value, updated_by, updated_at) VALUES ('crew.concurrency', '4', ?1, '2026-11-09T00:00:00.000Z')").run(admin.id); | |
| 113 | const made = await createRepo(app, admin, { name: "engine", visibility: "private" }); | |
| 114 | if (!made.ok) throw new Error(String(made.error)); | |
| 115 | const seeded = await commitToBranch(app, admin, made.value, { message: "Start", files: [{ path: "README.md", content: "# engine\n" }] }); | |
| 116 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 117 | const agent = await createAgent(app, admin, { username: "mason" }); | |
| 118 | if (!agent.ok) throw new Error(String(agent.error)); | |
| 119 | expect(addToCrew(app, admin, made.value, "mason").ok).toBe(true); | |
| 120 | const on = await updateRepoSettings(app, admin, made.value, { autonomy: "autonomous", autonomyDirection: "Build.", autonomyCeilingUsd: 10, autonomySlots: 16, autonomyBy: admin.id }); | |
| 121 | expect(on.ok).toBe(true); | |
| 122 | for (const title of ["One", "Two", "Three"]) { | |
| 123 | const r = createIssue(app.db, { repoId: made.value.id, authorId: admin.id, title, body: "" }); | |
| 124 | if (!r.ok) throw new Error(r.error); | |
| 125 | } | |
| 126 | expect(figureExtras(app).concurrency).toBe(4); | |
| 127 | const cookie = `forge_session=${createSession(app.db, admin.id).token}; forge_mode=studio`; | |
| 128 | kpiCache(app.db).clear(); | |
| 129 | const page = await freshHome(servers.url, cookie); | |
| 130 | expect(page).toMatch(/<strong>\d+ of 4<\/strong>/); | |
| 131 | expect(page).not.toMatch(/of 16/); | |
| 132 | // The api's map for the repository: what it lists as ready is what the home counts. | |
| 133 | const login = await fetch(`${servers.url}/api/v1/repos/alice/engine/map`, { headers: { cookie } }); | |
| 134 | const map = (await login.json()) as { ready: unknown[]; startable: number[] }; | |
| 135 | const counts = readyCounts(app); | |
| 136 | expect(counts.ready).toBeGreaterThan(0); | |
| 137 | expect(counts.startable).toBe(map.startable.length); | |
| 138 | expect(counts.ready).toBe(map.ready.length); | |
| 139 | }); | |
| 140 | }); |
test/home-kpi-page.test.ts +10 −25
| @@ -25,7 +25,7 @@ afterAll(async () => { | ||
| 25 | 25 | await rm(dataDir, { recursive: true, force: true }); |
| 26 | 26 | }); |
| 27 | 27 | |
| 28 | test("home renders the eleven tiles; only an admin sees them", async () => { | |
| 28 | test("home renders the figures as one-line rows; only an admin sees them", async () => { | |
| 29 | 29 | const mk = async (username: string, first = false): Promise<User> => { |
| 30 | 30 | const r = await createUser(app.db, { |
| 31 | 31 | origin: "seed", |
| @@ -59,29 +59,15 @@ test("home renders the eleven tiles; only an admin sees them", async () => { | ||
| 59 | 59 | view(day, "a", 1900, null); |
| 60 | 60 | view(yesterday, "z", 400, 160); |
| 61 | 61 | const a = await home(admin); |
| 62 | expect(a).toContain('class="stats kpi-row mb"'); | |
| 63 | expect((a.match(/class="stat"/g) ?? []).length).toBe(11); | |
| 64 | for (const href of ["/board", "/releases", "/boards", "/settings/crew", "/settings/backups"]) expect(a).toContain(`class="stat" href="${href}"`); | |
| 65 | // The tiles are §5 stats (#3982): none of the page-local kpi classes is left on home. | |
| 66 | for (const name of ["kpis", "kpi", "kpi-value", "kpi-note", "kpi-spark"]) expect(a).not.toMatch(new RegExp(`class="[^"]*\\b${name}\\b(?!-)`)); | |
| 67 | expect(a).toContain('role="img" aria-label="Shipped each hour over the last 24 hours"'); | |
| 68 | ||
| 69 | // 2 accounts, the admin alone with a session today; visitors 3 today and 4 over 7 days; | |
| 70 | // load p75 of [100,200,300,400,1900] is 400 ms, INP p75 of [40,80,120,160] is 120 ms. | |
| 71 | expect(a).toContain(">1 of 2<"); | |
| 72 | expect(a).toContain(">3 today<"); | |
| 73 | expect(a).toContain(">4 in 7 days<"); | |
| 74 | expect(a).toContain(">400 ms<"); | |
| 75 | expect(a).toContain(">reacts in 120 ms<"); | |
| 76 | expect((a.match(/class="stat" href="\/boards\/reach"/g) ?? []).length).toBe(3); | |
| 62 | expect(a).toContain('class="list kpi-row"'); | |
| 63 | for (const href of ["/board", "/releases", "/boards", "/map", "/meter", "/settings/backups"]) expect(a).toContain(`href="${href}" class="row"`); | |
| 64 | // The owner called these out as figures no decision uses: they are not on home. | |
| 65 | for (const gone of ["Accounts", "Reporting browsers", "Traffic", "Reported page speed"]) expect(a).not.toContain(`>${gone}<`); | |
| 77 | 66 | |
| 78 | 67 | // The figures count every repository, so a non-admin sees none. |
| 79 | expect(a).toContain("no forge ceiling"); | |
| 80 | expect(a).toContain("last 30 days"); | |
| 81 | expect(await home(bob)).not.toContain('class="stats kpi-row mb"'); | |
| 82 | expect(await home(bob)).not.toContain("last 30 days"); | |
| 83 | expect(await home()).not.toContain('class="stats kpi-row mb"'); | |
| 84 | expect(await home()).not.toContain("last 30 days"); | |
| 68 | expect(a).toContain("no ceiling"); | |
| 69 | expect(await home(bob)).not.toContain('class="list kpi-row"'); | |
| 70 | expect(await home()).not.toContain('class="list kpi-row"'); | |
| 85 | 71 | }); |
| 86 | 72 | |
| 87 | 73 | test("home passes the forge's daily ceiling to the spend tile", async () => { |
| @@ -103,9 +89,8 @@ test("home passes the forge's daily ceiling to the spend tile", async () => { | ||
| 103 | 89 | headers: { cookie: `forge_session=${createSession(capped.db, r.value.id).token}; forge_mode=studio` }, |
| 104 | 90 | }); |
| 105 | 91 | const body = await res.text(); |
| 106 | expect(body).toContain("of $40"); | |
| 107 | expect(body).toContain("of the forge ceiling"); | |
| 108 | expect(body).not.toContain("no forge ceiling"); | |
| 92 | expect(body).toContain("of $40 today"); | |
| 93 | expect(body).not.toContain("no ceiling"); | |
| 109 | 94 | } finally { |
| 110 | 95 | s.stop(); |
| 111 | 96 | capped.close(); |
test/home-kpi-row.test.ts +40 −107
| @@ -13,59 +13,33 @@ import { serve } from "../src/http/server.ts"; | ||
| 13 | 13 | import { id } from "../src/kernel/id.ts"; |
| 14 | 14 | import { checkTime, kpiLines, sparkText, waitingWords } from "../src/flow/kpi_words.ts"; |
| 15 | 15 | import { running } from "../src/kernel/version.ts"; |
| 16 | import { components } from "../src/web/style/components.ts"; | |
| 17 | import { kpiRowFor, liveNow, sparkline } from "../src/web/studio/kpi_row.ts"; | |
| 16 | import { kpiRowFor, liveNow } from "../src/web/studio/kpi_row.ts"; | |
| 18 | 17 | |
| 19 | 18 | const hours = (n: number) => Array.from({ length: 24 }, (_, i) => (i === 3 ? n : 0)); |
| 20 | 19 | |
| 21 | describe("home kpi row", () => { | |
| 22 | test("five tiles with their links and figures", () => { | |
| 20 | const base = { landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }; | |
| 21 | const lineOf = (out: string, label: string) => new RegExp(`<li>(?:(?!</li>)[\\s\\S])*?>${label}</span\\s*>[\\s\\S]*?</li>`).exec(out)?.[0] ?? ""; | |
| 22 | ||
| 23 | describe("home figures", () => { | |
| 24 | test("each figure is one line with its link, label, number and a few words", () => { | |
| 23 | 25 | const out = kpiRowFor( |
| 24 | { landedHours: hours(6), landed: 6, live: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 26 | { ...base, landedHours: hours(6), landed: 6, medianCheckMs: 185_000 }, | |
| 25 | 27 | { sha: "abcdef0123456", at: "2026-10-19T11:00:00.000Z" }, |
| 26 | 28 | ).toString(); |
| 27 | expect(out).toContain('<span class="sha">abcdef0</span>'); | |
| 28 | expect(out).toContain("Shipped per hour"); | |
| 29 | expect(out).toContain("0.3"); | |
| 30 | expect(out).toContain("6 changes in 24 h"); | |
| 31 | expect(out).toContain("abcdef0"); | |
| 32 | expect(out).not.toContain(">abcdef01"); // shortened on screen; the whole id is in the title | |
| 33 | expect(out).toContain("3m 05s"); | |
| 34 | for (const href of ["/board", "/releases", "/boards"]) expect(out).toContain(`href="${href}"`); | |
| 29 | expect(lineOf(out, "Live")).toContain("abcdef0"); | |
| 30 | expect(out).not.toContain("abcdef01"); | |
| 31 | expect(lineOf(out, "Shipped")).toContain("0.3"); | |
| 32 | expect(lineOf(out, "Check time")).toContain("3m 05s"); | |
| 33 | for (const href of ["/board", "/releases", "/boards", "/settings/crew", "/meter", "/settings/backups"]) expect(out).toContain(`href="${href}"`); | |
| 35 | 34 | }); |
| 36 | 35 | |
| 37 | test("the whole figure is in the title and the link's label, rounded and in studio words", () => { | |
| 38 | const out = kpiRowFor( | |
| 39 | { landedHours: hours(7), landed: 7, live: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 40 | { sha: "abcdef0123456", at: "2026-10-19T11:00:00.000Z" }, | |
| 41 | ).toString(); | |
| 42 | expect(out).toContain('title="0.29"'); | |
| 43 | expect(out).not.toContain("0.2916"); | |
| 44 | expect(out).toContain('title="3m 05s"'); | |
| 45 | expect(out).not.toContain(" ms"); | |
| 46 | expect(out).toContain('aria-label="Live version: abcdef0123456, Live since 2026-10-19T11:00:00.000Z. The version this forge process is running'); | |
| 47 | expect(out).toContain('aria-label="Shipped per hour: 0.29, 7 changes in 24 h. Changes shipped'); | |
| 48 | }); | |
| 49 | ||
| 50 | test("empty figures say so", () => { | |
| 51 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 52 | expect(out).toContain("Nothing live yet"); | |
| 53 | expect(out).toContain("No check finished in 24 h"); | |
| 54 | }); | |
| 55 | ||
| 56 | test("no git words render, not even in a title or label", () => { | |
| 57 | const out = kpiRowFor({ landedHours: hours(1), landed: 1, live: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 1000, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 36 | test("empty figures say so, and no git word renders", () => { | |
| 37 | const out = kpiRowFor(base, null).toString(); | |
| 38 | expect(lineOf(out, "Live")).toContain("nothing live"); | |
| 58 | 39 | expect(out).not.toMatch(/commit|merge|branch|repositor|pull request|checks (passed|failed)/i); |
| 59 | 40 | }); |
| 60 | 41 | |
| 61 | test("the sparkline has one point per hour, oldest first", () => { | |
| 62 | const svg = sparkline(hours(4)).toString(); | |
| 63 | const pts = /points="([^"]+)"/.exec(svg)![1]!.split(" "); | |
| 64 | expect(pts).toHaveLength(24); | |
| 65 | expect(pts[20]!.endsWith(",2.0")).toBe(true); // hour 3 ago is index 20, at the top | |
| 66 | }); | |
| 67 | ||
| 68 | test("the live tile is the running commit, the same as /releases", () => { | |
| 42 | test("the live figure is the running commit, the same as /releases", () => { | |
| 69 | 43 | const prev = process.env["FORGE_COMMIT"]; |
| 70 | 44 | process.env["FORGE_COMMIT"] = "1234567abcdef"; |
| 71 | 45 | try { |
| @@ -77,38 +51,15 @@ describe("home kpi row", () => { | ||
| 77 | 51 | } |
| 78 | 52 | }); |
| 79 | 53 | |
| 80 | test("a truncated note carries its whole text as a title", () => { | |
| 81 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 82 | expect(out).toContain('title="No check finished in 24 h"'); | |
| 54 | test("the builders figure says running of the crew's concurrency and links to the crew", () => { | |
| 55 | const out = kpiRowFor(base, null, new Date(), { concurrency: 4, ready: { ready: 3, startable: 1 }, week: null }).toString(); | |
| 56 | expect(lineOf(out, "Builders")).toContain("2 of 4"); | |
| 57 | expect(lineOf(out, "Builders")).toContain('href="/settings/crew"'); | |
| 83 | 58 | }); |
| 84 | 59 | |
| 85 | test("the note wraps into two reserved lines instead of cutting off on a phone", () => { | |
| 86 | const rule = (sel: string) => new RegExp(`\\${sel} \\{([^}]*)\\}`).exec(components)![1]!; | |
| 87 | expect(rule(".stat-note")).not.toContain("nowrap"); | |
| 88 | expect(rule(".stat-note")).toContain("line-clamp: 2"); | |
| 89 | expect(rule(".stat-note")).toContain("height: 36px"); | |
| 90 | expect(rule(".stat")).toContain("height: 104px"); | |
| 91 | }); | |
| 92 | ||
| 93 | test("the builders tile says running of slots, titles it, and links to the crew", () => { | |
| 94 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 95 | expect(out).toContain('href="/settings/crew"'); | |
| 96 | expect(out).toContain('class="stat-value num" title="2 of 4">2 of 4<'); | |
| 97 | expect(out).toContain('title="Agent runs running now, of the slots set on projects whose autonomy is on. 4 slots set."'); | |
| 98 | expect(out).toContain('aria-label="Builders running: 2 of 4, Agent runs running now, of the slots set on projects whose autonomy is on. 4 slots set."'); | |
| 99 | }); | |
| 100 | ||
| 101 | test("with no slots set the builders tile shows a dash and says so", () => { | |
| 102 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 103 | expect(out).toContain('class="stat-value num" title="—">—<'); | |
| 104 | expect(out).toContain('title="No slots set">No slots set<'); | |
| 105 | expect(out).toContain(`aria-label="Builders running: —, No slots set"`); | |
| 106 | expect(out).not.toContain("Builders running: 0 of 0"); | |
| 107 | }); | |
| 108 | ||
| 109 | test("the builders note does not repeat the value", () => { | |
| 110 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 111 | expect(out).toContain(">running now<"); | |
| 60 | test("with no slots set the builders figure shows the running count alone", () => { | |
| 61 | const out = kpiRowFor({ ...base, builders: { running: 0, slots: 0, idle: null } }, null).toString(); | |
| 62 | expect(lineOf(out, "Builders")).not.toContain("of 0"); | |
| 112 | 63 | }); |
| 113 | 64 | |
| 114 | 65 | test("check time reads as a person would", () => { |
| @@ -158,26 +109,22 @@ describe("the terminal's figures", () => { | ||
| 158 | 109 | }); |
| 159 | 110 | }); |
| 160 | 111 | |
| 161 | describe("the spend tile", () => { | |
| 162 | const row = (spend: { todayUsd: number; ceilingUsd: number | null }) => | |
| 163 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null }, spend }, null).toString(); | |
| 112 | describe("the spend figure", () => { | |
| 113 | const row = (spend: { todayUsd: number; ceilingUsd: number | null }) => lineOf(kpiRowFor({ ...base, spend }, null).toString(), "Spend"); | |
| 164 | 114 | |
| 165 | test("shows today's spend of the ceiling, the cents in the title, linking to the crew page", () => { | |
| 115 | test("shows today's spend of the ceiling and links to the meter", () => { | |
| 166 | 116 | const out = row({ todayUsd: 12.34, ceilingUsd: 40 }); |
| 167 | expect(out).toContain('class="stat-value num" title="$12.34 of $40.00">$12 of $40<'); | |
| 168 | expect(out).toContain('aria-label="Crew spend today: $12.34 of $40.00, Crew spend today (UTC) at token list price, of the forge ceiling"'); | |
| 169 | expect(out).toContain(">of the forge ceiling<"); | |
| 117 | expect(out).toContain("<strong>$12</strong>"); | |
| 118 | expect(out).toContain("of $40 today"); | |
| 119 | expect(out).toContain('href="/meter"'); | |
| 170 | 120 | }); |
| 171 | 121 | |
| 172 | 122 | test("a small spend shows cents, not $0", () => { |
| 173 | expect(row({ todayUsd: 0.4, ceilingUsd: 40 })).toContain('>$0.40 of $40<'); | |
| 123 | expect(row({ todayUsd: 0.4, ceilingUsd: 40 })).toContain("$0.40"); | |
| 174 | 124 | }); |
| 175 | 125 | |
| 176 | test("without a ceiling it shows the spend alone and says no ceiling", () => { | |
| 177 | const out = row({ todayUsd: 12.34, ceilingUsd: null }); | |
| 178 | expect(out).toContain('title="$12.34">$12<'); | |
| 179 | expect(out).toContain(">no forge ceiling<"); | |
| 180 | expect(out).not.toContain(" of $"); | |
| 126 | test("without a ceiling it says so", () => { | |
| 127 | expect(row({ todayUsd: 12.34, ceilingUsd: null })).toContain("no ceiling"); | |
| 181 | 128 | }); |
| 182 | 129 | }); |
| 183 | 130 | |
| @@ -208,27 +155,26 @@ describe("home kpi row: the last off-box backup", () => { | ||
| 208 | 155 | const hoursAgo = (h: number) => new Date(NOW.getTime() - h * 3_600_000).toISOString(); |
| 209 | 156 | const row = (backupAt: string | null) => |
| 210 | 157 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt, reach: NO_REACH, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null }, null, NOW).toString(); |
| 211 | const tile = (out: string) => /<a class="stat"[^>]*href="\/settings\/backups"[^>]*>/.exec(out)![0]; | |
| 158 | const tile = (out: string) => lineOf(out, "Backup"); | |
| 212 | 159 | |
| 213 | 160 | test("a backup 2 h old reads its age, with the exact time, and is not flagged", () => { |
| 214 | 161 | const out = row(hoursAgo(2)); |
| 215 | 162 | expect(out).toContain("2 h ago"); |
| 216 | expect(out).toContain(`title="${hoursAgo(2)}"`); | |
| 217 | 163 | expect(tile(out)).not.toContain("data-tone"); |
| 218 | expect(tile(out)).not.toContain("Overdue"); | |
| 164 | expect(tile(out)).not.toContain("overdue"); | |
| 219 | 165 | }); |
| 220 | 166 | |
| 221 | 167 | test("a backup 25 h old is flagged and its label says overdue", () => { |
| 222 | 168 | const t = tile(row(hoursAgo(25))); |
| 223 | 169 | expect(t).toContain('data-tone="attn"'); |
| 224 | expect(t).toContain("Overdue"); | |
| 170 | expect(t).toContain("overdue"); | |
| 225 | 171 | }); |
| 226 | 172 | |
| 227 | 173 | test("no backup at all reads never and is flagged", () => { |
| 228 | 174 | const out = row(null); |
| 229 | 175 | expect(out).toContain(">never<"); |
| 230 | 176 | expect(tile(out)).toContain('data-tone="attn"'); |
| 231 | expect(tile(out)).toContain("Overdue"); | |
| 177 | expect(tile(out)).toContain("overdue"); | |
| 232 | 178 | }); |
| 233 | 179 | |
| 234 | 180 | test("readKpis reads the mirror's newest time from the data directory", async () => { |
| @@ -252,16 +198,7 @@ describe("home kpi row: the last off-box backup", () => { | ||
| 252 | 198 | }); |
| 253 | 199 | }); |
| 254 | 200 | |
| 255 | describe("the reach tiles", () => { | |
| 256 | test("say what they count in words, each linking to the reach board", () => { | |
| 257 | const reach = { usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, visitorDays: new Array<number>(30).fill(0), loadP75: 1250, inpP75: 180 }; | |
| 258 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 259 | for (const v of ["5 today", "31 in 7 days", "3 of 12", "seen today", "1.3 s", "reacts in 180 ms"]) expect(out).toContain(`>${v}<`); | |
| 260 | expect((out.match(/class="stat" href="\/boards\/reach"/g) ?? []).length).toBe(3); | |
| 261 | expect(out).not.toContain("INP"); | |
| 262 | expect(out).not.toContain("p75"); | |
| 263 | }); | |
| 264 | ||
| 201 | describe("the reach lines", () => { | |
| 265 | 202 | test("the terminal draws the 30 days as one block per day", () => { |
| 266 | 203 | const days = Array.from({ length: 30 }, (_, i) => (i === 29 ? 8 : 0)); |
| 267 | 204 | const reach = { usersToday: 0, usersTotal: 1, visitorsToday: 8, visitors7d: 8, visitorDays: days, loadP75: null, inpP75: null }; |
| @@ -289,10 +226,6 @@ describe("the visitors sparkline", () => { | ||
| 289 | 226 | expect(r.visitorDays[29]).toBe(2); |
| 290 | 227 | expect(r.visitorDays[0]).toBe(1); // 2026-09-20 is 29 days back; 09-19 is out |
| 291 | 228 | expect(r.visitorDays.reduce((a, b) => a + b, 0)).toBe(3); |
| 292 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: r, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 293 | const svg = /<svg[^>]*last 30 days[^>]*><polyline points="([^"]+)"/.exec(out)!; | |
| 294 | expect(svg[1]!.split(" ")).toHaveLength(30); | |
| 295 | expect(out).toContain('href="/boards/reach"'); | |
| 296 | 229 | }); |
| 297 | 230 | }); |
| 298 | 231 | |
| @@ -417,14 +350,14 @@ describe("the forge ceiling hit (#5798)", () => { | ||
| 417 | 350 | |
| 418 | 351 | test("past the cap the tile is attention-toned and names the time; the terminal says the same words", () => { |
| 419 | 352 | const out = kpiRowFor({ ...base, spend: over }, null).toString(); |
| 420 | expect(out).toContain("ceiling hit 14:03Z, builders idle"); | |
| 353 | expect(out).toContain("of $600, hit 14:03Z"); | |
| 421 | 354 | expect(out).toContain("attn"); |
| 422 | 355 | expect(kpiLines({ ...base, spend: over }, null)[4]).toBe("Crew spend today $601 of $600, ceiling hit 14:03Z, builders idle"); |
| 423 | 356 | }); |
| 424 | 357 | |
| 425 | 358 | test("under the cap there is no hit; with no cap both doors say no forge ceiling", () => { |
| 426 | expect(kpiRowFor({ ...base, spend: { todayUsd: 5, ceilingUsd: 600, hitAt: null } }, null).toString()).not.toContain("ceiling hit"); | |
| 427 | expect(kpiRowFor({ ...base, spend: { todayUsd: 5, ceilingUsd: null } }, null).toString()).toContain("no forge ceiling"); | |
| 359 | expect(kpiRowFor({ ...base, spend: { todayUsd: 5, ceilingUsd: 600, hitAt: null } }, null).toString()).not.toContain("hit 14"); | |
| 360 | expect(kpiRowFor({ ...base, spend: { todayUsd: 5, ceilingUsd: null } }, null).toString()).toContain("no ceiling"); | |
| 428 | 361 | expect(kpiLines({ ...base, spend: { todayUsd: 5, ceilingUsd: null } }, null)[4]).toContain("no forge ceiling"); |
| 429 | 362 | }); |
| 430 | 363 |
test/home-kpis.test.ts +8 −10
| @@ -130,23 +130,21 @@ describe("home kpis", () => { | ||
| 130 | 130 | }); |
| 131 | 131 | }); |
| 132 | 132 | |
| 133 | describe("home kpi row titles", () => { | |
| 133 | describe("home kpi row", () => { | |
| 134 | 134 | const full = kpiRowFor( |
| 135 | 135 | { landedHours: Array.from({ length: 24 }, (_, i) => (i === 0 ? 6 : 0)), landed: 6, live: null, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, |
| 136 | 136 | { sha: "abcdef0123456789", at: "2026-10-19T11:00:00.000Z" }, |
| 137 | 137 | ).toString(); |
| 138 | 138 | |
| 139 | test("every shortened value and note carries its whole text in a title", () => { | |
| 140 | expect(full).toContain('class="stat-value num" title="abcdef0123456789"'); | |
| 141 | expect(full).toContain('class="stat-value num" title="0.25"'); | |
| 142 | expect(full).toContain('class="stat-value num" title="3m 05s"'); | |
| 143 | expect(full).toContain('title="Live since 2026-10-19T11:00:00.000Z.'); | |
| 144 | expect(full).toContain('title="6 changes in 24 h. Changes shipped'); | |
| 139 | test("the version is shortened on screen and the figures read in studio words", () => { | |
| 140 | expect(full).toContain("abcdef0"); | |
| 141 | expect(full).not.toContain("abcdef01"); | |
| 142 | expect(full).toContain("<strong>0.3</strong>"); | |
| 143 | expect(full).toContain("3m 05s"); | |
| 145 | 144 | }); |
| 146 | 145 | |
| 147 | test("no value or note lacks a title, and none brings back a git word", () => { | |
| 148 | expect(full.match(/class="stat-(value num|note)"/g)).toHaveLength(18); | |
| 149 | expect(full.match(/class="stat-(value num|note)" title=/g)).toHaveLength(18); | |
| 146 | test("every figure is one link and no git word comes back", () => { | |
| 147 | expect(full.match(/<li>/g)).toHaveLength(full.match(/<a href=/g)!.length); | |
| 150 | 148 | expect(full).not.toMatch(/commit|merge|branch|repositor|pull request/i); |
| 151 | 149 | }); |
| 152 | 150 | }); |
test/home-living.test.ts +11
| @@ -179,6 +179,17 @@ describe("home", () => { | ||
| 179 | 179 | expect(readBuilding(app.db, bob).map((r) => r.title)).not.toContain("Hidden build"); |
| 180 | 180 | }); |
| 181 | 181 | |
| 182 | test("an alarm is not a shipment, and a long title is cut at a word (#10440)", () => { | |
| 183 | merged(secretRepoId, "Sentinel: release was degraded 180 minutes today", 2); | |
| 184 | merged(secretRepoId, "Fold the duplicated retry logic into one module so every caller waits the same way after a failure", 3); | |
| 185 | const titles = readShipped(app.db, alice).map((r) => r.title); | |
| 186 | expect(titles.some((t) => t.startsWith("Sentinel:"))).toBe(false); | |
| 187 | const long = titles.find((t) => t.startsWith("Fold the duplicated"))!; | |
| 188 | expect(long.endsWith("…")).toBe(true); | |
| 189 | expect(Array.from(long).length).toBeLessThanOrEqual(60); | |
| 190 | expect(long).toBe("Fold the duplicated retry logic into one module so every…"); | |
| 191 | }); | |
| 192 | ||
| 182 | 193 | test("the live fragment is for the signed in, and the region is wired to the stream", async () => { |
| 183 | 194 | expect((await get("/live/moving")).status).toBe(404); |
| 184 | 195 | expect((await get("/live/chips")).status).toBe(404); |
test/kpi-spark.test.ts +2 −16
| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The KPI sparklines (#3238): `daySpark` breaks the line at a day with no |
| 3 | * data, and the two numbers-only helpers draw exactly what they did before. | |
| 3 | * data. | |
| 4 | 4 | * Expected points are worked by hand on the 96 × 24 box: x = i · 96 / (n − 1), |
| 5 | 5 | * y = 22 − (v / top) · 20 with top = max(1, …values). |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { describe, expect, test } from "bun:test"; |
| 9 | import { daySpark, sparkline, visitorsSpark } from "../src/web/studio/kpi_row.ts"; | |
| 9 | import { daySpark } from "../src/web/studio/kpi_row.ts"; | |
| 10 | 10 | |
| 11 | 11 | const LINE = 'fill="none" stroke="currentColor" stroke-width="1.5"'; |
| 12 | 12 | |
| @@ -47,17 +47,3 @@ describe("daySpark", () => { | ||
| 47 | 47 | expect(daySpark([1], 'a"<b>')!.toString()).toContain('aria-label="a"<b>"'); |
| 48 | 48 | }); |
| 49 | 49 | }); |
| 50 | ||
| 51 | describe("the numbers-only sparklines are unchanged", () => { | |
| 52 | test("visitorsSpark", () => { | |
| 53 | expect(visitorsSpark([0, 2, 4]).toString()).toBe( | |
| 54 | `<svg viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Distinct visitors each day over the last 3 days"><polyline points="0.0,22.0 48.0,12.0 96.0,2.0" ${LINE}/></svg>`, | |
| 55 | ); | |
| 56 | }); | |
| 57 | ||
| 58 | test("sparkline, newest first in, oldest on the left", () => { | |
| 59 | expect(sparkline([2, 0]).toString()).toBe( | |
| 60 | `<svg viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Shipped each hour over the last 24 hours"><polyline points="0.0,22.0 96.0,2.0" ${LINE}/></svg>`, | |
| 61 | ); | |
| 62 | }); | |
| 63 | }); |
test/kpi-wrap.test.ts +7 −60
| @@ -1,20 +1,10 @@ | ||
| 1 | 1 | /** |
| 2 | * The home's KPI row at phone width (#6067). The row is `.stats` (an | |
| 3 | * auto-fit grid) plus `.kpi-row`; at 360px (328px of content) two 160px | |
| 4 | * tiles and the gap need 332px, so the grid alone falls to one column and | |
| 5 | * nine tiles stack to ~1,100px. This lays the real tiles and the real | |
| 6 | * stylesheet out in headless Chromium, inside a 360px iframe so the media | |
| 7 | * query sees a phone, and counts the columns the browser actually made. | |
| 2 | * The home's figures are a list of one-line rows (#10440), so a phone has no | |
| 3 | * grid to fit: one row each, nothing reserved, nothing that wraps into tiles. | |
| 8 | 4 | */ |
| 9 | 5 | import { expect, test } from "bun:test"; |
| 10 | import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; | |
| 11 | import { tmpdir } from "node:os"; | |
| 12 | import { join } from "node:path"; | |
| 13 | import { findChromium } from "../src/looks/capture.ts"; | |
| 14 | 6 | import { kpiRowFor } from "../src/web/studio/kpi_row.ts"; |
| 15 | import { components } from "../src/web/style/components.ts"; | |
| 16 | 7 | import type { Kpis } from "../src/flow/kpis.ts"; |
| 17 | import { chromiumRuns } from "./helpers/chrome.ts"; | |
| 18 | 8 | |
| 19 | 9 | const k = { |
| 20 | 10 | landedHours: Array(24).fill(0), landed: 0, live: null, medianCheckMs: null, |
| @@ -22,52 +12,9 @@ const k = { | ||
| 22 | 12 | reach: { visitorDays: [1, 2], loadP75: null }, |
| 23 | 13 | } as unknown as Kpis; |
| 24 | 14 | |
| 25 | const tiles = kpiRowFor(k, null).toString(); | |
| 26 | ||
| 27 | test("a six-digit value renders inside a tile of the row", () => { | |
| 28 | expect(tiles).toContain('class="stats kpi-row mb"'); | |
| 29 | expect(tiles).toMatch(/<span class="stat-value num"[^>]*>\$123457<\/span>/); | |
| 30 | }); | |
| 31 | ||
| 32 | const found = findChromium(); | |
| 33 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 34 | ||
| 35 | /** The distinct x offsets of the tiles' left edges in a frame `width` wide. */ | |
| 36 | function columnsAt(bin: string, width: number): number { | |
| 37 | const dir = mkdtempSync(join(tmpdir(), "forge-kpi-")); | |
| 38 | try { | |
| 39 | const inner = `<!doctype html><meta name=viewport content="width=device-width"><style> | |
| 40 | :root{--border:#ccc;--card:#fff;--fg:#000;--radius:6px;--muted-fg:#666;--fs-min:12px;--attn:red} | |
| 41 | body{margin:16px}${components}</style>${tiles}`; | |
| 42 | const page = `<!doctype html><body><iframe id=f width=${width} height=900 style="border:0" srcdoc="${inner | |
| 43 | .replace(/&/g, "&").replace(/"/g, """)}"></iframe><pre id=out></pre><script> | |
| 44 | document.getElementById("f").onload=function(){var d=this.contentDocument; | |
| 45 | var xs=new Set([].map.call(d.querySelectorAll(".kpi-row > .stat"),function(e){return Math.round(e.getBoundingClientRect().left)})); | |
| 46 | document.getElementById("out").textContent="COLS="+xs.size+" N="+d.querySelectorAll(".kpi-row > .stat").length}</script>`; | |
| 47 | const file = join(dir, "p.html"); | |
| 48 | writeFileSync(file, page); | |
| 49 | const run = Bun.spawnSync( | |
| 50 | [bin, "--headless", "--no-sandbox", "--disable-gpu", `--user-data-dir=${dir}/u`, | |
| 51 | "--virtual-time-budget=3000", "--dump-dom", `file://${file}`], | |
| 52 | { stdout: "pipe", stderr: "ignore", timeout: 20000 }, | |
| 53 | ); | |
| 54 | const m = /COLS=(\d+) N=(\d+)/.exec(run.stdout.toString()); | |
| 55 | if (m === null) throw new Error("no measurement: " + run.stdout.toString().slice(0, 300)); | |
| 56 | expect(Number(m[2])).toBeGreaterThan(2); | |
| 57 | return Number(m[1]); | |
| 58 | } finally { | |
| 59 | rmSync(dir, { recursive: true, force: true }); | |
| 60 | } | |
| 61 | } | |
| 62 | ||
| 63 | test.skipIf(chromium === undefined)("at 360px the tiles sit two to a line; at 1000px more", () => { | |
| 64 | expect(columnsAt(chromium!, 360)).toBe(2); | |
| 65 | expect(columnsAt(chromium!, 1000)).toBeGreaterThan(2); | |
| 66 | }); | |
| 67 | ||
| 68 | test("below 480px the row is two equal columns that may shrink to fit 328px", () => { | |
| 69 | const m = /@media \(max-width: 480px\) \{ \.kpi-row \{ grid-template-columns: repeat\((\d+), minmax\(0, 1fr\)\); \} \}/.exec(components); | |
| 70 | expect(m).not.toBeNull(); | |
| 71 | expect(Number(m![1])).toBe(2); | |
| 72 | // minmax(0, …) has no floor, so nothing forces the 332px the 160px basis needed. | |
| 15 | test("a six-digit value renders as one line of the list", () => { | |
| 16 | const out = kpiRowFor(k, null).toString(); | |
| 17 | expect(out).toContain('<ul class="list kpi-row"'); | |
| 18 | expect(out).toContain("<strong>$123457</strong>"); | |
| 19 | expect(out).not.toContain("stat-value"); | |
| 73 | 20 | }); |
test/later-gate.test.ts +2 −2
| @@ -102,8 +102,8 @@ describe("the Later gate in plain sight", () => { | ||
| 102 | 102 | expect(hold.by).toBe("alice"); |
| 103 | 103 | const home = await get("/"); |
| 104 | 104 | expect(home).toContain('id="held-line"'); |
| 105 | expect(home).toContain("2 issues are held"); | |
| 106 | expect(home).toContain("set by alice"); | |
| 105 | expect(home).toContain("2 held behind Later"); | |
| 106 | expect(home).toContain("Set by alice"); | |
| 107 | 107 | expect(home).toContain("/alice/engine/held"); |
| 108 | 108 | }); |
| 109 | 109 |
test/traffic-truth.test.ts +2 −39
| @@ -25,7 +25,6 @@ import { | ||
| 25 | 25 | repoOf, |
| 26 | 26 | } from "../src/perf/traffic.ts"; |
| 27 | 27 | import { addressBytes } from "../src/kernel/cidr.ts"; |
| 28 | import { kpiRowFor } from "../src/web/studio/kpi_row.ts"; | |
| 29 | 28 | import { probeKpis } from "../src/web/studio/kpi_probe.ts"; |
| 30 | 29 | |
| 31 | 30 | const NOW = new Date("2026-11-03T12:00:30Z"); |
| @@ -195,7 +194,7 @@ test("it keeps prefixes and a sketch, never an address, and its tables are bound | ||
| 195 | 194 | expect(familyOf("")).toBe("none"); |
| 196 | 195 | }); |
| 197 | 196 | |
| 198 | test("the tile says plainly when strangers hold most of the time, and not for a handful", () => { | |
| 197 | test("the traffic board says plainly when strangers hold most of the time, and not for a handful", () => { | |
| 199 | 198 | const flood = createPerfRecord(); |
| 200 | 199 | for (let i = 0; i < 40; i++) |
| 201 | 200 | flood.add("/a", sample(100, { deepStranger: true })); |
| @@ -205,39 +204,15 @@ test("the tile says plainly when strangers hold most of the time, and not for a | ||
| 205 | 204 | expect(trafficValue(t)).toBe("98%"); |
| 206 | 205 | expect(trafficWords(t).note).toContain("too much"); |
| 207 | 206 | expect(trafficWords(t).title).toStartWith("Something is wrong"); |
| 208 | const row = String(kpiRowFor(emptyKpis(), null, NOW, t)); | |
| 209 | expect(row).toMatch( | |
| 210 | /<a class="stat" href="\/settings\/traffic" data-tone="attn"/, | |
| 211 | ); | |
| 212 | 207 | |
| 213 | 208 | const handful = createPerfRecord(); |
| 214 | 209 | handful.add("/a", sample(5000, { deepStranger: true })); |
| 215 | 210 | expect(trafficAttention(handful.ledger.totals(END))).toBeNull(); |
| 216 | expect( | |
| 217 | String(kpiRowFor(emptyKpis(), null, NOW, handful.ledger.totals(END))), | |
| 218 | ).not.toMatch(/traffic" data-tone="attn"/); | |
| 219 | 211 | |
| 220 | 212 | expect(trafficValue(createPerfRecord().ledger.totals(END))).toBe("—"); |
| 221 | 213 | }); |
| 222 | 214 | |
| 223 | function emptyKpis() { | |
| 224 | return readKpis(app.db, NOW, { ceilingUsd: 40 }); | |
| 225 | } | |
| 226 | ||
| 227 | /** What each tile in the row shows, by its label, with the markup taken off. */ | |
| 228 | function tileValues(row: string): Map<string, string> { | |
| 229 | const out = new Map<string, string>(); | |
| 230 | for (const m of row.matchAll( | |
| 231 | /stat-label">([^<]+)<\/span><span class="stat-value num"[^>]*>(.*?)<\/span>(?=<span class="stat-note|<\/a>)/gs, | |
| 232 | )) | |
| 233 | out.set( | |
| 234 | m[1]!.trim().replace(/'/g, "'"), | |
| 235 | m[2]!.replace(/<[^>]+>/g, "").trim(), | |
| 236 | ); | |
| 237 | return out; | |
| 238 | } | |
| 239 | ||
| 240 | test("every tile's value equals the probe's, from known requests and page_vital rows", () => { | |
| 215 | test("every figure the probe recomputes agrees with itself, from known requests and page_vital rows", () => { | |
| 241 | 216 | const today = NOW.toISOString().slice(0, 10); |
| 242 | 217 | const yesterday = new Date(END - 86_400_000).toISOString().slice(0, 10); |
| 243 | 218 | const insert = app.db.query("INSERT INTO page_vital (day, at, route, visitor, load, inp, cls) VALUES (?1, 0, '/', ?2, ?3, ?4, 0)"); |
| @@ -256,8 +231,6 @@ test("every tile's value equals the probe's, from known requests and page_vital | ||
| 256 | 231 | |
| 257 | 232 | const kpis = readKpis(app.db, NOW, { ceilingUsd: 40 }); |
| 258 | 233 | const live = { sha: "a".repeat(40), at: "2026-11-03T11:00:00Z" }; |
| 259 | const traffic = record.ledger.totals(END); | |
| 260 | const tiles = tileValues(String(kpiRowFor(kpis, live, NOW, traffic))); | |
| 261 | 234 | const probe = probeKpis( |
| 262 | 235 | app.db, |
| 263 | 236 | NOW, |
| @@ -290,17 +263,7 @@ test("every tile's value equals the probe's, from known requests and page_vital | ||
| 290 | 263 | for (const n of probe.numbers) { |
| 291 | 264 | expect(n.counts.length).toBeGreaterThan(10); |
| 292 | 265 | expect([n.id, n.agrees, n.recomputed]).toEqual([n.id, true, n.value]); |
| 293 | const shown = tiles.get(n.label); | |
| 294 | expect([n.label, n.id === "live" ? shown !== undefined : shown]).toEqual([ | |
| 295 | n.label, | |
| 296 | n.id === "live" ? true : n.value, | |
| 297 | ]); | |
| 298 | 266 | } |
| 299 | expect(tiles.size).toBe(probe.numbers.length); | |
| 300 | // The live tile's short form is the start of the probe's full id. | |
| 301 | expect(byId.get("live")!.value.startsWith(tiles.get("Live version")!)).toBe( | |
| 302 | true, | |
| 303 | ); | |
| 304 | 267 | |
| 305 | 268 | // The probe reads past what the tile holds: a report after the tile was computed disagrees. |
| 306 | 269 | insert.run(today, "v9", 100, null); |
test/tui-dashboard-alarms.test.ts +3 −3
| @@ -66,15 +66,15 @@ function stuckPull(name: string, visibility: "public" | "private"): void { | ||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test("a quiet database draws no alarm line", async () => { |
| 69 | expect(await firstScreen(alice)).not.toContain("has sat approved"); | |
| 69 | expect(await firstScreen(alice)).not.toContain("sat approved"); | |
| 70 | 70 | }); |
| 71 | 71 | |
| 72 | 72 | test("a stuck approved pull draws the stuck line for an admin; a non-admin reads public ones alone", async () => { |
| 73 | 73 | stuckPull("secret", "private"); |
| 74 | expect(await firstScreen(alice)).toContain("alice/secret#1 has sat approved"); | |
| 74 | expect(await firstScreen(alice)).toContain("alice/secret#1 sat approved"); | |
| 75 | 75 | expect(await firstScreen(bob)).not.toContain("secret#1"); |
| 76 | 76 | stuckPull("open", "public"); |
| 77 | expect(await firstScreen(bob)).toContain("alice/open#1 has sat approved"); | |
| 77 | expect(await firstScreen(bob)).toContain("alice/open#1 sat approved"); | |
| 78 | 78 | }); |
| 79 | 79 | |
| 80 | 80 | test("a cleared clog's note is on the admin's home line and nobody else's", async () => { |
test/week-wiring.test.ts +2 −18
| @@ -23,7 +23,7 @@ import { capacityDefault } from "../src/core/capacity.ts"; | ||
| 23 | 23 | import { crewLineWords, forgetWeek, weekWords } from "../src/crew/week_read.ts"; |
| 24 | 24 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 25 | 25 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 26 | import { homeWeek, weekLine } from "../src/web/studio/week_line.ts"; | |
| 26 | import { weekLine } from "../src/web/studio/week_line.ts"; | |
| 27 | 27 | import { seedAdmin } from "./helpers/admin.ts"; |
| 28 | 28 | import { quietLogs } from "./helpers/globals.ts"; |
| 29 | 29 | import { serve } from "../src/http/server.ts"; |
| @@ -221,8 +221,6 @@ test("with no measurement of the week the pace is unknown and the crew holds at | ||
| 221 | 221 | expect(String(weekLine(app, NOW))).toContain("pace is unknown"); |
| 222 | 222 | // Nothing measured: no percent to state, so no crew line on either door. |
| 223 | 223 | expect(crewLineWords(app, NOW)).toBeNull(); |
| 224 | expect(String(homeWeek(app, alice, NOW))).not.toContain("crew-pace"); | |
| 225 | expect(String(homeWeek(app, alice, NOW))).toContain("pace is unknown"); | |
| 226 | 224 | expect(repoPace(app, repo, NOW).slots).toBe(2); |
| 227 | 225 | }); |
| 228 | 226 | |
| @@ -303,26 +301,12 @@ test("a week that fell 8 points in 3 hours slows the picks; a flat meter does no | ||
| 303 | 301 | expect(weekWords(app, NOW)).toContain("burning 0% an hour"); |
| 304 | 302 | }); |
| 305 | 303 | |
| 306 | test("home's crew line gives the owner the percent left and when it runs out, escaped, and nobody else", () => { | |
| 304 | test("the crew line gives the percent left and when it runs out", () => { | |
| 307 | 305 | week(70, 6); |
| 308 | 306 | const runsOut = repoPace(app, repo, NOW); |
| 309 | 307 | expect(runsOut.reason).toContain("running out about"); |
| 310 | 308 | const words = crewLineWords(app, NOW)!; |
| 311 | 309 | expect(words).toMatch(/^30% of the week left, runs out (Sun|Mon|Tue|Wed|Thu|Fri|Sat) \d\d:\d\d UTC at this pace$/); |
| 312 | const owner = String(homeWeek(app, alice, NOW)); | |
| 313 | expect(owner).toContain(words); | |
| 314 | expect(owner).toContain('id="crew-pace"'); | |
| 315 | // The sentence under the line does not say the percent or the run-out again. | |
| 316 | expect(owner.split("30% of the week left").length - 1).toBe(1); | |
| 317 | expect(owner).not.toContain("running out about"); | |
| 318 | expect(owner).toContain("Ahead of pace: the week has"); | |
| 319 | expect(owner).toContain('<p class="small muted break" id="crew-pace">'); | |
| 320 | const other = { isAdmin: false } as User; | |
| 321 | for (const viewer of [other, undefined]) { | |
| 322 | const page = String(homeWeek(app, viewer, NOW)); | |
| 323 | expect(page).not.toContain("crew-pace"); | |
| 324 | expect(page).toContain("Ahead of pace: 30% of the week left"); | |
| 325 | } | |
| 326 | 310 | week(20); |
| 327 | 311 | expect(crewLineWords(app, NOW)).toBe("80% of the week left, lasts to the reset at this pace"); |
| 328 | 312 | }); |
new above
offline