Public: anyone can read this; the crew can change it.
Home: the lanes, their graphs, then one row of figures, each number said once #17678
Merged 20h 30m ago, live in production
home-one-row → main 0 commits
47 files
changed +676
−865
- docs/design/baseline.json
- docs/design/quiet-debt.json
- docs/features/living-home.md
- src/crew/idle_reason.ts
- src/crew/week_read.ts
- src/flow/crew_card.ts
- src/flow/kpi_words.ts
- src/flow/lane_times.ts
- src/flow/ship_words.ts
- src/http/lazy_lists.ts
- src/http/marks/live.json
- src/http/routes/live.ts
- src/release/prove.ts
- src/tui/screens/dashboard.ts
- src/web/desk_strip.ts
- src/web/flow_slots.ts
- src/web/home_row.ts
- src/web/layout.ts
- src/web/pages/home_figures.ts
- src/web/pages/home_flow.ts
- src/web/pages/home_flow_client.ts
- src/web/pages/home_flow_style.ts
- src/web/pages/home_ship.ts
- src/web/studio/fork_line.ts
- test/crew-card.test.ts
- test/docs-not-found.test.ts
- test/flow-slots.test.ts
- test/home-builders-idle.test.ts
- test/home-figures.test.ts
- test/home-flow.test.ts
- test/home-fork-flows.test.ts
- test/home-kpi-row.test.ts
- test/home-kpis.test.ts
- test/home-no-shift.test.ts
- test/home-one-row.test.ts
- test/home-vitals.test.ts
- test/idle-reason.test.ts
- test/kpi-words.test.ts
- test/lane-times.test.ts
- test/release-proof-words.test.ts
- test/release-prove.test.ts
- test/ship-time.test.ts
- test/snapshot-off-box.test.ts
- test/tui-dashboard-idle.test.ts
- test/tui-home-row.test.ts
- test/tui-kpis.test.ts
- test/week-wiring.test.ts
docs/design/baseline.json +1 −1
docs/design/quiet-debt.json −3
docs/features/living-home.md +12 −7
| @@ -9,8 +9,13 @@ Signed in, `/` is one page (`src/web/pages/home_flow.ts`): the pipeline as six l | ||
| 9 | 9 | 1. **The box** — one line that tells the crew (`POST /tell`, the same action the feed's composer posts to), with Notes and Talk beside it. |
| 10 | 10 | 2. **The one line that needs you** — a failed proof, a red main, a stopped landing line, then what waits on you (`3 waiting on you, oldest 2 days`, over `/review`, in the largest sensible unit); or "Nothing needs you right now". Everyone sees it; the five figures beside it are an admin's. |
| 11 | 11 | 3. **The lanes or the table** — each lane a live region of its own that redraws on its own events; the table is the same items one row each, with search, sort, filter chips and bulk actions that go through the fleet's verbs (previewed, receipted, undoable where they can be). `?view=` is remembered per browser. |
| 12 | 4. **Figures** (admins) — one section under them: shipped over 14 days, visitors, crew spend, check time, page speed, open bugs, the last off-box backup. One card, one chart, one number formatter (`src/flow/figure_format.ts`); open or closed is remembered in the browser. | |
| 13 | 5. **The hosted forges** in one line. | |
| 12 | 4. **The graphs** (admins) — the checks' and the crew runs' slots, right under the lanes. | |
| 13 | 5. **One row of figures** (admins), each number said once (`homeRow` in `src/web/home_row.ts`): shipped in 24 hours with its trend, the one median (open to landed), the crew running, the week used, visitors and page speed. Off-box backup and open bugs join the row only while they need someone. A figure not measured yet says so in words ("none yet"), never a dash. | |
| 14 | 6. **The foot** — The feed, and for an admin Crew (`/settings/crew`) and Forges (`/forges`), and "N archived" (`/archive`) once something is put away. The crew's table and the hosted forges' line are on those pages, not on the home. | |
| 15 | ||
| 16 | The desk line under the row keeps holds, findings and asks; what a crew member is doing is the Building lane's card, so a "doing" note is not repeated there. | |
| 17 | ||
| 18 | The home said shipped four ways, the crew's runs and its spend twice each, a second median, the crew's table and the forges' line under the lanes (the owner's walk, 2026-12-02); it now ends at the row. The terminal's home prints the same row as lines, once each (`homeRowLines`, `src/tui/screens/dashboard.ts`). | |
| 14 | 19 | |
| 15 | 20 | None of it is read on a request. A worker reads the picture (`src/flow/lanes_worker.ts`; the fast part in a few milliseconds, the slow part — the crew's order for what is asked next, the figures, the alarms, what waits on each person who has the home open — every 30 s) and the thread keeps the last one: a page is drawn from it, a lane redraws from it and answers 304 when its version has not moved. The first page after a restart draws "reading…" and fills in place. |
| 16 | 21 | |
| @@ -19,14 +24,14 @@ The feed — the composer, the timeline, what is on you, since you were here — | ||
| 19 | 24 | ## The figures tell the truth (#10440) |
| 20 | 25 | |
| 21 | 26 | - **Slots** in "Crew running" are `crew.concurrency` (`crewConcurrency` in `src/flow/slot_cap.ts`), or the repositories' slots when those are fewer. Home and the terminal read the same figure. |
| 22 | - **Dropped on purpose** from the old tiles: the ones the strip or a lane already says (shipped per hour, the live version, builders running, the week), and the Traffic, Reporting browsers and Accounts tiles; the same numbers stay on `/settings/traffic`, `/boards/reach` and the KPI probe. | |
| 23 | - **Page speed** shows the 75th-percentile page load and, under it, `LCP … · INP …` over seven days from the first-party beacon: LCP is how long the main content takes to show, INP how long a tap takes to answer. | |
| 27 | - **Dropped on purpose**: the live version (the footer says it, and the Live lane says what went live), shipped over 14 days and crew spend today (the row says shipped and the week once), check time (the Checks lane's typical), the ship-time histogram, and the Traffic, Reporting browsers and Accounts tiles; the same numbers stay on `/boards/delivery`, `/boards/reach`, `/settings/traffic` and the KPI probe. | |
| 28 | - **Idle words** name the repository, linked, for someone who reads it ("trevato/x's crew is paused: its autonomy names nobody to act as…"); anyone else gets the words and the crew settings (`idleFor`). | |
| 29 | - **A lane's clock** leaves out a time it does not know ("now 4m" alone), never "typical —". | |
| 30 | - **Page speed** shows the 75th-percentile page load over seven days from the first-party beacon. | |
| 24 | 31 | |
| 25 | 32 | ## The crew card (#16849) |
| 26 | 33 | |
| 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 | ||
| 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`). | |
| 34 | The crew's last 30 days (the red-main streak and a row per member) left the home with the figures' section: it is on the crew's pages (`/settings/crew`, linked as Crew from the home's foot), and the numbers stay `crewScorecards`'. | |
| 30 | 35 | |
| 31 | 36 | ## Each figure tile opens its board (#16937) |
| 32 | 37 |
src/crew/idle_reason.ts +3 −6
| @@ -41,7 +41,7 @@ export interface IdleReason { | ||
| 41 | 41 | * person is named to act as, so its ready work never starts. The repository's name is in the link, |
| 42 | 42 | * not the word, so the word may be said to anyone. |
| 43 | 43 | */ |
| 44 | export const NOBODY_WORD = "a repository's crew is on but names nobody to act as, so it starts nothing: turn autonomy on there again"; | |
| 44 | export const NOBODY_WORD = "a repository's crew is paused: its autonomy names nobody to act as, so nothing starts; turn it on again in its settings"; | |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The week's share or the subscriptions, when one of them is why this repository starts |
| @@ -121,10 +121,7 @@ export const governedWord = (slots: number, ceiling: number): string => | ||
| 121 | 121 | export function idleFor(app: App, viewer: User | undefined, reason: IdleReason | null): IdleReason | null { |
| 122 | 122 | if (reason === null || reason.repoId === undefined) return reason; |
| 123 | 123 | const repo = getRepoById(app.db, reason.repoId); |
| 124 | return repo !== undefined && canRead(app.db, repo, viewer) ? reason : { word: reason.word, href: "/settings/crew" }; | |
| 124 | // A reader is told which repository, by name, where the words say "a repository". | |
| 125 | return repo !== undefined && canRead(app.db, repo, viewer) ? { ...reason, word: reason.word.replace(/^a repository's /, `${repo.ownerName}/${repo.name}'s `) } : { word: reason.word, href: "/settings/crew" }; | |
| 125 | 126 | } |
| 126 | 127 | |
| 127 | /** The reason as one line, the same words wherever it is printed. */ | |
| 128 | export function idleLine(reason: IdleReason): string { | |
| 129 | return `Builders idle: ${reason.word} (${reason.href})`; | |
| 130 | } |
src/crew/week_read.ts −6
| @@ -261,12 +261,6 @@ export function weekWords(app: App, now: Date = new Date()): string | null { | ||
| 261 | 261 | return busiest(app, now, (repo, week) => `${week.sentence} ${efficiencyWords(weekEfficiency(app, repo, now), week)}${heldWords(app)}`); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | /** The owner's week on Home and the terminal. */ | |
| 265 | export function weekBlock(app: App, now: Date = new Date()): string[] { | |
| 266 | const words = weekWords(app, now); | |
| 267 | return words === null ? [] : [words]; | |
| 268 | } | |
| 269 | ||
| 270 | 264 | /** The weekly-budget knob's live effect (#10461): `25% of the week used, the crew may use up to 90%`. Plain words while the week is unmeasured. */ |
| 271 | 265 | export function budgetEffect(app: App, now: Date = new Date()): string { |
| 272 | 266 | return busiest(app, now, (_repo, week) => week.sentence.replace(/\.$/, "")) ?? "the week is not measured yet; nothing holds the crew but the provider"; |
src/flow/crew_card.ts −20
| @@ -109,28 +109,8 @@ const wholeDays = (now: Date, iso: string): number => Math.max(0, Math.floor((no | ||
| 109 | 109 | |
| 110 | 110 | const pct = (share: number): string => `${Math.round(share * 100)}%`; |
| 111 | 111 | |
| 112 | /** The streak in words: both doors say it the same way. */ | |
| 113 | export function streakWords(days: number | null, red: boolean): string { | |
| 114 | if (red) return "Main is red now"; | |
| 115 | if (days === null) return "No main check on record yet"; | |
| 116 | if (days === 0) return "Main went red today"; | |
| 117 | return `${days} ${days === 1 ? "day" : "days"} without a red main`; | |
| 118 | } | |
| 119 | ||
| 120 | 112 | /** A member's line in words. */ |
| 121 | 113 | export function rowWords(r: CrewRow): string { |
| 122 | 114 | return `${r.landed} landed · ${pct(r.firstPassGreen)} green first pass · ${pct(r.rework)} rework`; |
| 123 | 115 | } |
| 124 | 116 | |
| 125 | /** The empty card's sentence. */ | |
| 126 | export const CREW_EMPTY = "Nothing has landed from the crew in the last 30 days."; | |
| 127 | ||
| 128 | /** The card as terminal lines: the streak, then a line per member; or the calm empty sentence. */ | |
| 129 | export function crewCardLines(card: CrewCard): string[] { | |
| 130 | // A forge with no main check and no landed work has nothing to say here. | |
| 131 | if (card.rows.length === 0 && card.streakDays === null) return []; | |
| 132 | const head = `Crew, ${card.days} days: ${streakWords(card.streakDays, card.red)}`; | |
| 133 | // Empty is one line, so a quiet forge's dashboard keeps its height. | |
| 134 | if (card.rows.length === 0) return [`${head}. ${CREW_EMPTY}`]; | |
| 135 | return [head, ...card.rows.map((r) => ` ${r.username}: ${rowWords(r)}`)]; | |
| 136 | } |
src/flow/kpi_words.ts −62
| @@ -43,21 +43,6 @@ export function checkTime(ms: number | null): string { | ||
| 43 | 43 | return `${Math.floor(m / 60)}h ${String(m % 60).padStart(2, "0")}m`; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | const BLOCKS = "▁▂▃▄▅▆▇█"; | |
| 47 | ||
| 48 | /** The terminal's sparkline: the same 24 hours, oldest on the left, one block each. */ | |
| 49 | export function sparkText(hours: readonly number[]): string { | |
| 50 | return trendText([...hours].reverse()); | |
| 51 | } | |
| 52 | ||
| 53 | /** One block per value, oldest on the left; the series is already in that order. */ | |
| 54 | export function trendText(series: readonly number[]): string { | |
| 55 | const top = Math.max(1, ...series); | |
| 56 | return series | |
| 57 | .map((v) => (v === 0 ? BLOCKS[0]! : BLOCKS[Math.min(BLOCKS.length - 1, Math.ceil((v / top) * (BLOCKS.length - 1)))]!)) | |
| 58 | .join(""); | |
| 59 | } | |
| 60 | ||
| 61 | 46 | /** Builders running of their slots: `2 of 4`, or an em dash when no slots are set. */ |
| 62 | 47 | export function buildersValue(b: Pick<Kpis["builders"], "running" | "slots">): string { |
| 63 | 48 | return b.slots === 0 ? "—" : `${b.running} of ${b.slots}`; |
| @@ -71,25 +56,6 @@ export function spendValue(s: Kpis["spend"]): string { | ||
| 71 | 56 | return s.ceilingUsd === null ? whole(s.todayUsd) : `${whole(s.todayUsd)} of ${whole(s.ceilingUsd)}`; |
| 72 | 57 | } |
| 73 | 58 | |
| 74 | /** The `HH:MMZ` of an ISO time. */ | |
| 75 | const hhmmZ = (iso: string): string => `${iso.slice(11, 16)}Z`; | |
| 76 | ||
| 77 | /** The forge ceiling's state in words, shared by the tile and the terminal row. */ | |
| 78 | export function spendCeilingWords(s: Kpis["spend"]): { note: string; title: string; attn: boolean } { | |
| 79 | if (s.ceilingUsd === null) return { note: "no forge ceiling", title: "No forge ceiling is set", attn: false }; | |
| 80 | if (s.todayUsd >= s.ceilingUsd) { | |
| 81 | const note = s.hitAt ? `ceiling hit ${hhmmZ(s.hitAt)}, builders idle` : "ceiling hit, builders idle"; | |
| 82 | return { note, title: note, attn: true }; | |
| 83 | } | |
| 84 | return { note: "of the forge ceiling", title: "Crew spend today (UTC) at token list price, of the forge ceiling", attn: false }; | |
| 85 | } | |
| 86 | ||
| 87 | /** The terminal's tail on the spend line: only the two states worth a word. */ | |
| 88 | function spendLineNote(s: Kpis["spend"]): string { | |
| 89 | const w = spendCeilingWords(s); | |
| 90 | return w.attn || s.ceilingUsd === null ? `, ${w.note}` : ""; | |
| 91 | } | |
| 92 | ||
| 93 | 59 | const DAY_MS = 24 * 3_600_000; |
| 94 | 60 | |
| 95 | 61 | /** Past a day, or with no backup at all, the last off-box backup is overdue. */ |
| @@ -124,17 +90,6 @@ export function visitorsValue(r: Reach): string { | ||
| 124 | 90 | return `${r.visitorsToday} today`; |
| 125 | 91 | } |
| 126 | 92 | |
| 127 | /** The week behind it: `31 in 7 days`. */ | |
| 128 | export function visitorsNote(r: Reach): string { | |
| 129 | return `${r.visitors7d} in 7 days`; | |
| 130 | } | |
| 131 | ||
| 132 | /** The speed tile's quiet note: p75 LCP and INP over 7 days, or that nobody has reported yet. */ | |
| 133 | export function vitalsNote(r: Reach): string { | |
| 134 | const parts = [r.lcpP75 == null ? null : `LCP ${speedWords(r.lcpP75)}`, r.inpP75 == null ? null : `INP ${speedWords(r.inpP75)}`].filter((p) => p !== null); | |
| 135 | return parts.length === 0 ? "no visitors yet" : parts.join(" · "); | |
| 136 | } | |
| 137 | ||
| 138 | 93 | /** Shipped per hour, as the tile shows it. */ |
| 139 | 94 | export function shippedValue(landed: number, hours: number): string { |
| 140 | 95 | return (landed / hours).toFixed(1); |
| @@ -197,20 +152,3 @@ export function staleWords(count: number): string { | ||
| 197 | 152 | return `${count} stale, archive?`; |
| 198 | 153 | } |
| 199 | 154 | |
| 200 | /** | |
| 201 | * The terminal's row: the same figures in the same words, as plain | |
| 202 | * lines. Forge-wide like the web's, so the caller shows them to an admin only. | |
| 203 | */ | |
| 204 | export function kpiLines(k: Kpis, live: { sha: string; since: string } | null, now: Date = new Date()): string[] { | |
| 205 | return [ | |
| 206 | `Shipped per hour ${(k.landed / k.landedHours.length).toFixed(1)} ${sparkText(k.landedHours)} ${k.landed} ${k.landed === 1 ? "change" : "changes"} in 24 h`, | |
| 207 | `Live version ${live === null ? "— nothing live yet" : `${live.sha.slice(0, 7)}, live ${live.since}`}`, | |
| 208 | `Median check time ${checkTime(k.medianCheckMs)}`, | |
| 209 | `Builders running ${buildersValue(k.builders)}${k.builders.slots === 0 ? ", no slots set" : ""}${k.builders.idle === null ? "" : ` · ${k.builders.idle.word}`}`, | |
| 210 | `Crew spend today ${spendValue(k.spend)}${spendLineNote(k.spend)}`, | |
| 211 | k.backup ? k.backup.line : `Last off-box backup ${backupAge(k.backupAt, now)}${backupOverdue(k.backupAt, now) ? ", overdue" : ""}`, | |
| 212 | `Reporting browsers ${visitorsValue(k.reach)}, ${visitorsNote(k.reach)} ${trendText(k.reach.visitorDays)} 30 days`, | |
| 213 | `Accounts ${usersValue(k.reach)} seen today`, | |
| 214 | `Reported page speed ${k.reach.loadP75 === null ? "no page views measured yet" : `loads in ${speedWords(k.reach.loadP75)}`}, ${vitalsNote(k.reach)}`, | |
| 215 | ]; | |
| 216 | } |
src/flow/lane_times.ts +10 −10
| @@ -214,12 +214,11 @@ export function timesOf(lanes: Held, typicals: Typicals | null, now: number): La | ||
| 214 | 214 | return { nows, typicals: t, slowest: bottleneck(nows, t) }; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | /** "now 18m" and "typical 9m": a lane's two times, short. */ | |
| 218 | export function timeWords(nows: NowTimes | null, typical: Typical | null, say: (ms: number) => string): { now: string; typical: string } { | |
| 219 | return { | |
| 220 | now: nows === null ? "now —" : `now ${say(nows.medianMs)}`, | |
| 221 | typical: typical === null ? "typical —" : `typical ${say(typical.medianMs)}`, | |
| 222 | }; | |
| 217 | /** | |
| 218 | * "now 18m · typical 9m": a lane's two times, short; a time not known is left out, never a dash. | |
| 219 | */ | |
| 220 | export function timeWords(nows: NowTimes | null, typical: Typical | null, say: (ms: number) => string): string { | |
| 221 | return [nows === null ? null : `now ${say(nows.medianMs)}`, typical === null ? null : `typical ${say(typical.medianMs)}`].filter((p) => p !== null).join(" · "); | |
| 223 | 222 | } |
| 224 | 223 | |
| 225 | 224 | /** |
| @@ -230,9 +229,10 @@ export function laneLines(times: LaneTimes, names: Readonly<Record<LaneKey, stri | ||
| 230 | 229 | const n = times.nows[k]; |
| 231 | 230 | const t = times.typicals[k]; |
| 232 | 231 | const parts = [ |
| 233 | n === null ? "now —" : `now ${say(n.medianMs)} (oldest ${say(n.oldestMs)})`, | |
| 234 | t === null ? "typical —" : `typical ${say(t.medianMs)} (p90 ${say(t.p90Ms)})`, | |
| 235 | ]; | |
| 236 | return `${names[k]}: ${parts.join(" · ")}${times.slowest === k ? " · slowest" : ""}`; | |
| 232 | n === null ? null : `now ${say(n.medianMs)} (oldest ${say(n.oldestMs)})`, | |
| 233 | t === null ? null : `typical ${say(t.medianMs)} (p90 ${say(t.p90Ms)})`, | |
| 234 | times.slowest === k ? "slowest" : null, | |
| 235 | ].filter((p) => p !== null); | |
| 236 | return `${names[k]}: ${parts.length === 0 ? "no time yet" : parts.join(" · ")}`; | |
| 237 | 237 | }); |
| 238 | 238 | } |
src/flow/ship_words.ts −7
| @@ -23,13 +23,6 @@ export function shipSentence(s: Pick<ShipTime, "count" | "medianMs" | "p90Ms">): | ||
| 23 | 23 | return `Median ship time this week: ${shipSpan(s.medianMs)} (p90 ${shipSpan(s.p90Ms)}, ${s.count} ${s.count === 1 ? "issue" : "issues"}).`; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | /** The bar's range: `under 15 min`, `1 h to 2 h`, `1 d or more`. */ | |
| 27 | export function barWords(fromMs: number, toMs: number | null): string { | |
| 28 | if (fromMs === 0 && toMs !== null) return `under ${shipSpan(toMs)}`; | |
| 29 | if (toMs === null) return `${shipSpan(fromMs)} or more`; | |
| 30 | return `${shipSpan(fromMs)} to ${shipSpan(toMs)}`; | |
| 31 | } | |
| 32 | ||
| 33 | 26 | /** What a slow issue's time went to, one line: review, check, conflict and waiting named. */ |
| 34 | 27 | export function slowLine(i: SlowIssue): string { |
| 35 | 28 | const plural = (n: number, one: string, many: string): string => `${n} ${n === 1 ? one : many}`; |
src/http/lazy_lists.ts −2
| @@ -545,9 +545,7 @@ export const LIVE_ROUTES = [ | ||
| 545 | 545 | ["GET", "/live/milestones"], |
| 546 | 546 | ["GET", "/live/lane"], |
| 547 | 547 | ["GET", "/live/strip"], |
| 548 | ["GET", "/live/forges"], | |
| 549 | 548 | ["GET", "/live/table"], |
| 550 | ["GET", "/live/figures"], | |
| 551 | 549 | ["GET", "/feed"], |
| 552 | 550 | ["GET", "/feed.json"], |
| 553 | 551 | ["GET", "/feed/likes"], |
src/http/marks/live.json −2
src/http/routes/live.ts +1 −3
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | 5 | import { feedJson } from "../../web/feeds.ts"; |
| 6 | import { liveLaneFragment, liveStripFragment, liveForgesFragment, liveTableFragment, liveFiguresFragment } from "../../web/pages/home_flow.ts"; | |
| 6 | import { liveLaneFragment, liveStripFragment, liveTableFragment } from "../../web/pages/home_flow.ts"; | |
| 7 | 7 | import { liveFeedFragment } from "../../web/studio/feed.ts"; |
| 8 | 8 | import { HOME_REGIONS } from "../../web/studio/home_last.ts"; |
| 9 | 9 | import { liveAppsFragment, liveOnYouFragment, liveDeskFragment, liveClientAppsFragment, feedPage, liveHomeFragment } from "../../web/studio/home.ts"; |
| @@ -30,9 +30,7 @@ export function liveRoutes(router: Router<Handler>): void { | ||
| 30 | 30 | router.add("GET", "/live/milestones", liveMilestonesFragment); |
| 31 | 31 | router.add("GET", "/live/lane", liveLaneFragment); |
| 32 | 32 | router.add("GET", "/live/strip", liveStripFragment); |
| 33 | router.add("GET", "/live/forges", liveForgesFragment); | |
| 34 | 33 | router.add("GET", "/live/table", liveTableFragment); |
| 35 | router.add("GET", "/live/figures", liveFiguresFragment); | |
| 36 | 34 | router.add("GET", "/feed", feedPage); |
| 37 | 35 | router.add("GET", "/feed.json", feedJson); |
| 38 | 36 | // One post's like ledger as a page: what the feed's "and N more" opens. |
src/release/prove.ts −10
| @@ -167,16 +167,6 @@ export function clearProving(dataDir: string): void { | ||
| 167 | 167 | } catch {} |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | /** When the proof of `version` began, while it runs; undefined when none runs for it. */ | |
| 171 | export function provingSince(dataDir: string, version: string, now = Date.now()): string | undefined { | |
| 172 | try { | |
| 173 | const p = JSON.parse(readFileSync(provingFile(dataDir), "utf8")) as { version?: unknown; startedAt?: unknown }; | |
| 174 | return p.version === version && typeof p.startedAt === "string" && Number.isFinite(Date.parse(p.startedAt)) && now - Date.parse(p.startedAt) < HANG_MS ? p.startedAt : undefined; | |
| 175 | } catch { | |
| 176 | return undefined; | |
| 177 | } | |
| 178 | } | |
| 179 | ||
| 180 | 170 | /** The verdict for a proof that outran `HANG_MS`: a failure, so a release never has no word. */ |
| 181 | 171 | export function keepHung(dataDir: string, version: string, startedAt: number, now: number, ceilingMs = HANG_MS): Proof { |
| 182 | 172 | const before = lastProof(dataDir); |
src/tui/screens/dashboard.ts +22 −36
| @@ -82,7 +82,6 @@ import { decideAsk, undoDecideAsk } from "../../actions/asks_decide.ts"; | ||
| 82 | 82 | import { actOnProposal, type ProposalVerb } from "../../actions/proposals.ts"; |
| 83 | 83 | import { putAsideWaves } from "../../web/studio/asks.ts"; |
| 84 | 84 | import type { Proposal } from "../../core/proposals.ts"; |
| 85 | import type { App } from "../../app.ts"; | |
| 86 | 85 | import { |
| 87 | 86 | applyAsksBulk, |
| 88 | 87 | doneLine, |
| @@ -145,25 +144,19 @@ import { | ||
| 145 | 144 | plural, |
| 146 | 145 | linkScreen, |
| 147 | 146 | } from "./common.ts"; |
| 148 | import { readVitals, vitalsLine } from "../../flow/vitals.ts"; | |
| 149 | import { readKpis } from "../../flow/kpis.ts"; | |
| 150 | import { kpiLines } from "../../flow/kpi_words.ts"; | |
| 151 | import { shipTimeLines } from "./ship_time.ts"; | |
| 152 | import { BOOTED } from "../../release/gate.ts"; | |
| 153 | import { running } from "../../kernel/version.ts"; | |
| 147 | import { homeRow, homeRowLines } from "../../web/home_row.ts"; | |
| 148 | import { running, runningLine } from "../../kernel/version.ts"; | |
| 149 | import { spawnedForge } from "../../spawn/claim.ts"; | |
| 154 | 150 | import { deciderLine, deciderScreen } from "./decider.ts"; |
| 155 | 151 | import { issueScreen } from "./issue.ts"; |
| 156 | 152 | import { listPinned } from "../../actions/board-pins.ts"; |
| 157 | 153 | import { migrateScreen } from "./migrate.ts"; |
| 158 | 154 | import { newRepoScreen } from "./newrepo.ts"; |
| 159 | import { crewCardLines, readCrewCard } from "../../flow/crew_card.ts"; | |
| 160 | 155 | import { firedAlarms } from "../../flow/alarms.ts"; |
| 161 | 156 | import { lastClearedNote } from "../../flow/clog_tick.ts"; |
| 162 | 157 | import { forgeCeiling } from "../../flow/ceiling.ts"; |
| 163 | 158 | import { alarmIdleCrew } from "../../flow/alarm_idle_crew.ts"; |
| 164 | import { idleFor, idleLine, idleReason } from "../../crew/idle_reason.ts"; | |
| 165 | import type { User } from "../../core/users.ts"; | |
| 166 | import { weekBlock } from "../../crew/week_read.ts"; | |
| 159 | import { idleFor } from "../../crew/idle_reason.ts"; | |
| 167 | 160 | import { noReleaseAlarm } from "../../flow/alarm_no_release.ts"; |
| 168 | 161 | import { redMainAlarm } from "../../flow/alarm_red_main.ts"; |
| 169 | 162 | import { alarmStuck } from "../../flow/alarm_stuck.ts"; |
| @@ -187,15 +180,6 @@ const nextStepsLine = (user: Session["user"]): string => | ||
| 187 | 180 | .map((s) => `${s.key} ${s.label.toLowerCase()}`) |
| 188 | 181 | .join(" · "); |
| 189 | 182 | |
| 190 | /** | |
| 191 | * The forge-wide daily ceiling, from config, for the spend figure; the data directory, for the | |
| 192 | * backup's age. | |
| 193 | */ | |
| 194 | export const kpiForge = (app: { config: { crewCeilingUsd?: number; dataDir: string } }) => ({ | |
| 195 | ceilingUsd: forgeCeiling(app.config), | |
| 196 | dataDir: app.config.dataDir, | |
| 197 | }); | |
| 198 | ||
| 199 | 183 | /** |
| 200 | 184 | * The three things the launcher is about. Order is the `tab` order: the |
| 201 | 185 | * repositories, then what is waiting on you, then what is on your machine. |
| @@ -314,6 +298,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 314 | 298 | * repository). |
| 315 | 299 | */ |
| 316 | 300 | let figures: string[] = []; |
| 301 | /** The home's row of figures as lines, read with the lanes' picture (`loadWrong`). */ | |
| 302 | let row: string[] = []; | |
| 317 | 303 | /** |
| 318 | 304 | * A new forge's owner before their first tell: the home is one line, "what do you want built". |
| 319 | 305 | */ |
| @@ -453,6 +439,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 453 | 439 | if (!f.user || steps === undefined) return; |
| 454 | 440 | // A client's home never carries the forge-wide figures, on either door. |
| 455 | 441 | figures = []; |
| 442 | row = []; | |
| 456 | 443 | firstTell = steps.some((s) => s.key === "tell" && !s.done); |
| 457 | 444 | if (firstTell) { |
| 458 | 445 | clientLines = [FIRST_TELL_LINE, crewFirstText(f.app), ...firstStepLines(steps)]; |
| @@ -502,6 +489,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 502 | 489 | if (f.user !== undefined) { |
| 503 | 490 | const picture = await lanePicture(f.db, { dataDir: f.app.config.dataDir, ceilingUsd: forgeCeiling(f.app.config), viewer: f.user.id }, "lane"); |
| 504 | 491 | if (f.user.isAdmin) crewWeek = picture?.strip?.week ?? null; |
| 492 | // The page's one row of figures, each said once (`homeRow`): the same list, as lines. | |
| 493 | // As on the page: an admin's, and never on a hosted forge, whose owner is a client. | |
| 494 | row = f.user.isAdmin && picture !== undefined && (await spawnedForge(f.app)) === undefined ? [...homeRowLines(homeRow(picture, (idle) => idleFor(f.app, f.user, idle), Date.now())), liveVersionLine()] : []; | |
| 505 | 495 | // Every viewer reads the parked pulls of the repositories they can read, as on the web home. |
| 506 | 496 | parked = terminalLines(parkedFor(f.db, f.user, picture?.strip?.parked)); |
| 507 | 497 | asks = picture === undefined ? [] : asksLines(f.db, f.user, picture); |
| @@ -517,7 +507,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 517 | 507 | ctx.invalidate(); |
| 518 | 508 | }; |
| 519 | 509 | |
| 520 | ||
| 521 | 510 | const reload = (): void => { |
| 522 | 511 | // The server remembers the *choice* and nothing about the laptop, so |
| 523 | 512 | // this is a list of decisions — never a status that would be stale. |
| @@ -590,18 +579,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 590 | 579 | tokens = returnsStrip(f); |
| 591 | 580 | decider = deciderLine(f.app, f.user); |
| 592 | 581 | moving = f.user ? movingLines(f.db, f.user, f.user.isAdmin ? pipelineNow(f.db) : undefined) : []; |
| 593 | const commit = running().commit; | |
| 594 | 582 | const cleared = lastClearedNote(f.db, now); |
| 595 | 583 | figures = |
| 596 | 584 | f.user?.isAdmin !== true |
| 597 | 585 | ? [] |
| 598 | 586 | : [ |
| 599 | ...idleLines(f.app, f.user, now), | |
| 600 | ...weekBlock(f.app, now), | |
| 601 | ...kpiLines(readKpis(f.db, now, { ...kpiForge(f.app), idle: () => idleReason(f.app, now) }), commit === null ? null : { sha: commit, since: ago(BOOTED) }), | |
| 602 | ...shipTimeLines(f.db, now), | |
| 603 | vitalsLine(readVitals(f.db, now)), | |
| 604 | ...crewCardLines(readCrewCard(f.db, now)), | |
| 605 | 587 | ...firedAlarms(f.db, now, { ceilingUsd: forgeCeiling(f.app.config), dataDir: f.app.config.dataDir }).map((a) => a.says), |
| 606 | 588 | ...(cleared === undefined ? [] : [cleared]), |
| 607 | 589 | ]; |
| @@ -1398,7 +1380,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1398 | 1380 | body = rest!; |
| 1399 | 1381 | } |
| 1400 | 1382 | // A short terminal drops lesser figures before it drops the list; the spend line goes last. |
| 1401 | const shown = keepFigures(figures, body.h - FIGURES_ROOM); | |
| 1383 | // The row is read with the lanes' picture, after the rest: it leads, as on the page. | |
| 1384 | const shown = keepFigures([...row, ...figures], body.h - FIGURES_ROOM); | |
| 1402 | 1385 | if (shown.length > 0) { |
| 1403 | 1386 | const [strip, rest] = split(body, "v", [len(shown.length), fill(1)]); |
| 1404 | 1387 | shown.forEach((line, i) => |
| @@ -1963,15 +1946,18 @@ export function keepFigures(figures: readonly string[], room: number): string[] | ||
| 1963 | 1946 | return figures.filter((_, i) => kept.has(i)); |
| 1964 | 1947 | } |
| 1965 | 1948 | |
| 1966 | /** How the crew spend figure begins, as `kpiLines` says it. */ | |
| 1967 | const SPEND_LINE = "Crew spend today"; | |
| 1968 | ||
| 1969 | /** Why the builders are idle, as the one line an admin's home reads; none while they are not. */ | |
| 1970 | function idleLines(app: App, viewer: User | undefined, now: Date): string[] { | |
| 1971 | const reason = idleFor(app, viewer, idleReason(app, now)); | |
| 1972 | return reason === null ? [] : [idleLine(reason)]; | |
| 1949 | /** | |
| 1950 | * The live version, as the page's footer says it for an admin (linked to the releases there): the | |
| 1951 | * version and its commit, or that nothing live is stamped yet. | |
| 1952 | */ | |
| 1953 | function liveVersionLine(): string { | |
| 1954 | const r = running(); | |
| 1955 | return `Live version: ${r.commit === null ? "nothing live yet" : `forge ${runningLine(r)}`} /releases`; | |
| 1973 | 1956 | } |
| 1974 | 1957 | |
| 1958 | /** How the week's spend figure begins, as the row says it (`homeRow`). */ | |
| 1959 | const SPEND_LINE = "Week used"; | |
| 1960 | ||
| 1975 | 1961 | /** |
| 1976 | 1962 | * The mark a repository row wears. |
| 1977 | 1963 | * |
src/web/desk_strip.ts +8
| @@ -59,6 +59,14 @@ export function holdsOnPull(notes: readonly DeskNote[], forgeUrl: string, ref: P | ||
| 59 | 59 | }); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | /** | |
| 63 | * The notes the home's desk line says: holds, findings and asks. What a crew member is doing is the | |
| 64 | * Building lane's card, so a "doing" note is not said again there. | |
| 65 | */ | |
| 66 | export function homeNotes(notes: readonly DeskNote[]): DeskNote[] { | |
| 67 | return notes.filter((n) => n.kind !== "doing"); | |
| 68 | } | |
| 69 | ||
| 62 | 70 | /** The region: always present, so a note arriving moves nothing; empty when no note is live. */ |
| 63 | 71 | export function deskStrip(db: Database, notes: readonly DeskNote[]): Html { |
| 64 | 72 | const [first] = notes; |
src/web/flow_slots.ts +8 −1
| @@ -74,6 +74,13 @@ const roomData = (kind: SlotLine["kind"], r: SlotRoom): Html => html` data-room= | ||
| 74 | 74 | * One kind's line. For an admin it is also a figure the bridge can select (`bridge_client.ts`): |
| 75 | 75 | * what waits, the median run, and the wait estimated at today's setting ride on it as data. |
| 76 | 76 | */ |
| 77 | /** | |
| 78 | * How busy the slots are, honestly: "2 of 4 slots busy", but never "2 of 1" when more run than | |
| 79 | * there are slots (a local fallback runs past them): then "2 running, 1 slot". | |
| 80 | */ | |
| 81 | const slotsWords = (busy: number, slots: number): string => | |
| 82 | busy > slots ? `${String(busy)} running, ${String(slots)} ${slots === 1 ? "slot" : "slots"}` : `${String(busy)} of ${String(slots)} slots busy`; | |
| 83 | ||
| 77 | 84 | function line(l: SlotLine, now: number, admin = false): Html { |
| 78 | 85 | const full = isFull(l); |
| 79 | 86 | // What waits, the median wait and the pace, each only when there is one: a free lane is its |
| @@ -89,7 +96,7 @@ function line(l: SlotLine, now: number, admin = false): Html { | ||
| 89 | 96 | <p class="sl-head"> |
| 90 | 97 | <strong>${NAME[l.kind]}</strong> |
| 91 | 98 | <span class="sl-used" data-busy="${String(l.busy)}" data-slots="${String(l.slots)}" |
| 92 | >${String(l.busy)} of ${String(l.slots)} slots busy</span | |
| 99 | >${slotsWords(l.busy, l.slots)}</span | |
| 93 | 100 | >${full ? html` ${badge("full", { tone: "danger" })}` : null} |
| 94 | 101 | ${says.length === 0 ? null : html`<span class="sl-say small">${says.map((s, i) => html`${i === 0 ? "" : " · "}${s}`)}</span>`} |
| 95 | 102 | </p> |
src/web/home_row.ts added +124
| @@ -0,0 +1,124 @@ | ||
| 1 | /** | |
| 2 | * The home's one row of figures, each number said once (the owner's walk, 2026-12-02: shipped was | |
| 3 | * said four ways, the crew's runs and its spend twice each): shipped in 24 hours with its trend, | |
| 4 | * the one median (open to landed), the crew running, the week used, visitors and page speed. | |
| 5 | * Off-box backup and overdue bugs join it only while they need someone. The page draws it as | |
| 6 | * figures (`stripRegion`), the terminal's home as lines (`homeRowLines`): one list, both doors. | |
| 7 | */ | |
| 8 | import type { IdleReason } from "../crew/idle_reason.ts"; | |
| 9 | import { count, duration, money } from "../flow/figure_format.ts"; | |
| 10 | import type { LanePicture, StripPart } from "../flow/lanes.ts"; | |
| 11 | import { cards, tileHref, type CardKey } from "./pages/home_figures.ts"; | |
| 12 | ||
| 13 | /** | |
| 14 | * The row's figures that are always there, in order, with where each opens: the loaded row draws | |
| 15 | * these, and the reading row (`readingStrip`) draws the same list before the picture exists, so the | |
| 16 | * two cannot drift. | |
| 17 | */ | |
| 18 | export const ROW_ALWAYS: readonly (readonly [label: string, href: string])[] = [ | |
| 19 | ["Shipped in 24 hours", "/board"], | |
| 20 | ["Median open to landed", "/boards"], | |
| 21 | ["Crew running", "/settings/crew"], | |
| 22 | ["Week used", "/settings/crew"], | |
| 23 | ["Visitors", tileHref("reach", 7)], | |
| 24 | ["Page speed", tileHref("reach", 7)], | |
| 25 | ]; | |
| 26 | ||
| 27 | /** The figures' cards that join the row: these always; the attention ones only while they need someone. */ | |
| 28 | const ALWAYS: readonly CardKey[] = ["visitors", "speed"]; | |
| 29 | const WHILE_ATTN: readonly CardKey[] = ["backup", "bugs", "spend"]; | |
| 30 | ||
| 31 | export interface RowFigure { | |
| 32 | readonly label: string; | |
| 33 | readonly value: string; | |
| 34 | readonly note: string; | |
| 35 | readonly href: string; | |
| 36 | readonly tone: "attn" | null; | |
| 37 | /** Shipped's changes landed per hour over the last 24, oldest first. */ | |
| 38 | readonly series?: readonly number[]; | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * The week the figure shows: the provider's own meter when it has reported one, else the forge's | |
| 43 | * own estimate, said as one ("about"): the crew's seven days at list price, against seven days of | |
| 44 | * the daily ceiling when the forge has one. | |
| 45 | */ | |
| 46 | function weekFigure(strip: StripPart): { value: string; note: string; attn: boolean } { | |
| 47 | const w = strip.week; | |
| 48 | if (w !== null) return { value: `${w.usedPct}%`, note: `of the crew's week; it may use ${w.mayUsePct}%`, attn: w.usedPct >= w.mayUsePct }; | |
| 49 | if (strip.ceilingUsd !== null && strip.ceilingUsd > 0) { | |
| 50 | const pct = Math.round((strip.weekSpendUsd / (strip.ceilingUsd * 7)) * 100); | |
| 51 | return { | |
| 52 | value: `about ${pct}%`, | |
| 53 | note: "the provider has not reported its week; this is the crew's seven days at list price against seven days of the daily ceiling", | |
| 54 | attn: pct >= 100, | |
| 55 | }; | |
| 56 | } | |
| 57 | return { | |
| 58 | value: `about ${money(strip.weekSpendUsd)}`, | |
| 59 | note: "spent by the crew in seven days, at list price; the provider has not reported its week", | |
| 60 | attn: false, | |
| 61 | }; | |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * The row for an admin. `reads` is `idleFor` for the viewer: an idle crew's words name and link the | |
| 66 | * repository only for someone who reads it. | |
| 67 | */ | |
| 68 | export function homeRow(picture: LanePicture, reads: (idle: IdleReason | null) => IdleReason | null, now: number): RowFigure[] { | |
| 69 | const strip = picture.strip; | |
| 70 | const b = picture.builders; | |
| 71 | // The reason is only said while a slot is free: a busy crew has none. | |
| 72 | const idle = b.slots > 0 && b.running < b.slots ? reads(picture.idle ?? null) : null; | |
| 73 | const week = strip === null ? null : weekFigure(strip); | |
| 74 | const lead = strip?.lead.medianHours ?? null; | |
| 75 | const row: RowFigure[] = [ | |
| 76 | { | |
| 77 | label: "Shipped in 24 hours", | |
| 78 | value: strip === null ? "none" : count(strip.landed), | |
| 79 | note: strip?.landed === 1 ? "change landed on main" : "changes landed on main", | |
| 80 | href: "/board", | |
| 81 | tone: null, | |
| 82 | ...(strip === null ? {} : { series: [...strip.landedHours].reverse() }), | |
| 83 | }, | |
| 84 | { | |
| 85 | label: "Median open to landed", | |
| 86 | // A median under a second reads so, never "0ms". | |
| 87 | value: lead === null ? "none" : lead * 3_600_000 < 1000 ? "under a second" : duration(lead * 3_600_000), | |
| 88 | note: | |
| 89 | lead === null | |
| 90 | ? "nothing landed in 24 hours" | |
| 91 | : `median of ${count(strip!.lead.landed)} ${strip!.lead.landed === 1 ? "change" : "changes"}, 24 hours`, | |
| 92 | href: "/boards", | |
| 93 | tone: null, | |
| 94 | }, | |
| 95 | { | |
| 96 | label: "Crew running", | |
| 97 | value: b.slots === 0 ? count(b.running) : `${count(b.running)} of ${count(b.slots)}`, | |
| 98 | note: b.slots === 0 ? "no builder slots set" : idle === null ? "builders at work now" : `idle: ${idle.word}`, | |
| 99 | href: idle === null ? "/settings/crew" : idle.href, | |
| 100 | tone: null, | |
| 101 | }, | |
| 102 | { | |
| 103 | label: "Week used", | |
| 104 | value: week === null ? "not read" : week.value, | |
| 105 | note: week === null ? "the week is not read yet" : week.note, | |
| 106 | href: "/settings/crew", | |
| 107 | tone: week?.attn === true ? "attn" : null, | |
| 108 | }, | |
| 109 | ]; | |
| 110 | // Visitors and page speed always; off-box backup and open bugs only while they need someone. | |
| 111 | const f = picture.figures; | |
| 112 | if (f !== null) | |
| 113 | for (const c of cards(f, now)) | |
| 114 | if (ALWAYS.includes(c.key) || (WHILE_ATTN.includes(c.key) && c.tone === "attn")) | |
| 115 | // A figure not measured yet says so in words, never a dash. | |
| 116 | // A figure that needs someone says why (its note), as its alarm says it. | |
| 117 | row.push({ label: c.label, value: c.value === "—" ? "none yet" : c.value, note: c.tone === "attn" ? `${c.unit} ${c.note}` : c.unit, href: c.href ?? "/boards", tone: c.tone ?? null }); | |
| 118 | return row; | |
| 119 | } | |
| 120 | ||
| 121 | /** The row as the terminal's home prints it: one line a figure, the path that opens it last. */ | |
| 122 | export function homeRowLines(row: readonly RowFigure[]): string[] { | |
| 123 | return row.map((r) => `${r.label}: ${r.value} · ${r.note} ${r.href}`); | |
| 124 | } |
src/web/layout.ts +1 −1
| @@ -774,7 +774,7 @@ function footer(ctx: Ctx, own?: Html): Html { | ||
| 774 | 774 | <span class="mark"></span> |
| 775 | 775 | <span |
| 776 | 776 | >${ctx.auth.user?.isAdmin === true |
| 777 | ? `forge ${runningLine()}` | |
| 777 | ? html`<a href="/releases">forge ${runningLine()}</a>` | |
| 778 | 778 | : "Open Platform. Open source under AGPL-3.0."}</span |
| 779 | 779 | > |
| 780 | 780 | ${reduced === undefined |
src/web/pages/home_figures.ts +13 −109
| @@ -21,17 +21,9 @@ import { | ||
| 21 | 21 | share, |
| 22 | 22 | } from "../../flow/figure_format.ts"; |
| 23 | 23 | import type { Figures } from "../../flow/figures.ts"; |
| 24 | import type { LanePicture } from "../../flow/lanes.ts"; | |
| 25 | import { row, rowList } from "../ui.ts"; | |
| 26 | import { html, raw, type Html } from "../html.ts"; | |
| 27 | import { CREW_EMPTY, rowWords, streakWords, type CrewCard } from "../../flow/crew_card.ts"; | |
| 24 | import { raw, type Html } from "../html.ts"; | |
| 28 | 25 | import { changeAgainst, type Change } from "../../flow/figure_change.ts"; |
| 29 | 26 | import { viewHref } from "../../boards/view_bar.ts"; |
| 30 | import { shipSection } from "./home_ship.ts"; | |
| 31 | ||
| 32 | /** The events that change a figure; they change by the minute, so these are few. */ | |
| 33 | export const FIGURES_LIVE = | |
| 34 | "pull.merged,run.finished,release.*,app.serving,issue.opened,issue.closed"; | |
| 35 | 27 | |
| 36 | 28 | const W = 120; |
| 37 | 29 | const H = 32; |
| @@ -77,7 +69,11 @@ export function chart( | ||
| 77 | 69 | ); |
| 78 | 70 | } |
| 79 | 71 | |
| 72 | /** A card's stable name: what picks it, whatever its label says. */ | |
| 73 | export type CardKey = "shipped" | "visitors" | "spend" | "checks" | "speed" | "bugs" | "maintenance" | "backup"; | |
| 74 | ||
| 80 | 75 | interface Card { |
| 76 | readonly key: CardKey; | |
| 81 | 77 | readonly label: string; |
| 82 | 78 | readonly value: string; |
| 83 | 79 | /** What the value is of: always shown. */ |
| @@ -99,38 +95,6 @@ interface Card { | ||
| 99 | 95 | /** The board that draws a tile's figure, at the tile's window: the board's own range link. */ |
| 100 | 96 | export const tileHref = (slug: string, days: 7 | 14): string => viewHref(`/boards/${slug}`, { range: days === 7 ? "7d" : "14d", live: null }); |
| 101 | 97 | |
| 102 | function card(c: Card): Html { | |
| 103 | const drawn = | |
| 104 | c.series === undefined ? null : chart(c.series, c.seriesLabel ?? c.label); | |
| 105 | const inner = html`<h3 class="fg-label">${c.label}</h3> | |
| 106 | <p class="fg-value"> | |
| 107 | <span class="fg-n num">${c.value}</span | |
| 108 | ><span class="fg-unit">${c.unit}</span> | |
| 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>`} | |
| 113 | <p class="fg-note">${c.note}</p> | |
| 114 | <div class="fg-chart">${drawn}</div> | |
| 115 | <p class="fg-axis" aria-hidden="true"> | |
| 116 | <span>${drawn === null ? "" : (c.ends?.[0] ?? "")}</span | |
| 117 | ><span>${drawn === null ? "" : (c.ends?.[1] ?? "")}</span> | |
| 118 | </p>`; | |
| 119 | return c.href === undefined | |
| 120 | ? html`<article | |
| 121 | class="fg-card" | |
| 122 | ${c.tone === undefined ? null : html` data-tone="${c.tone}"`} | |
| 123 | > | |
| 124 | ${inner} | |
| 125 | </article>` | |
| 126 | : html`<a | |
| 127 | class="fg-card" | |
| 128 | href="${c.href}" | |
| 129 | ${c.tone === undefined ? null : html` data-tone="${c.tone}"`} | |
| 130 | >${inner}</a | |
| 131 | >`; | |
| 132 | } | |
| 133 | ||
| 134 | 98 | const days = (n: number): readonly [string, string] => [ |
| 135 | 99 | `${n} days ago`, |
| 136 | 100 | "today", |
| @@ -145,6 +109,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 145 | 109 | const backupAge = f.backup.at === null ? null : now - Date.parse(f.backup.at); |
| 146 | 110 | return [ |
| 147 | 111 | { |
| 112 | key: "shipped", | |
| 148 | 113 | label: "Shipped", |
| 149 | 114 | value: count(f.shipped.total), |
| 150 | 115 | unit: |
| @@ -162,6 +127,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 162 | 127 | change: changeAgainst(f.shipped.total, f.prior?.shipped, 14, count), |
| 163 | 128 | }, |
| 164 | 129 | { |
| 130 | key: "visitors", | |
| 165 | 131 | label: "Visitors", |
| 166 | 132 | value: count(f.visitors.today), |
| 167 | 133 | unit: f.visitors.today === 1 ? "visitor today" : "visitors today", |
| @@ -173,6 +139,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 173 | 139 | change: changeAgainst(f.visitors.week, f.prior?.visitors, 7, count), |
| 174 | 140 | }, |
| 175 | 141 | { |
| 142 | key: "spend", | |
| 176 | 143 | label: "Crew spend", |
| 177 | 144 | value: money(f.spend.todayUsd), |
| 178 | 145 | unit: "today, at list price", |
| @@ -190,6 +157,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 190 | 157 | change: changeAgainst(f.spend.totalUsd, f.prior?.spendUsd, 14, money), |
| 191 | 158 | }, |
| 192 | 159 | { |
| 160 | key: "checks", | |
| 193 | 161 | label: "Check time", |
| 194 | 162 | value: f.checks.medianMs === null ? "—" : duration(f.checks.medianMs), |
| 195 | 163 | unit: |
| @@ -204,6 +172,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 204 | 172 | change: changeAgainst(f.checks.windowMs ?? null, f.prior?.checkMs, 14, duration), |
| 205 | 173 | }, |
| 206 | 174 | { |
| 175 | key: "speed", | |
| 207 | 176 | label: "Page speed", |
| 208 | 177 | value: f.speed.load === null ? "—" : pageTime(f.speed.load), |
| 209 | 178 | unit: |
| @@ -224,6 +193,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 224 | 193 | ? [] |
| 225 | 194 | : [ |
| 226 | 195 | { |
| 196 | key: "bugs" as const, | |
| 227 | 197 | label: "Open bugs", |
| 228 | 198 | value: count(f.bugs.open), |
| 229 | 199 | unit: f.bugs.open === 1 ? "open bug" : "open bugs", |
| @@ -240,6 +210,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 240 | 210 | ? [] |
| 241 | 211 | : [ |
| 242 | 212 | { |
| 213 | key: "maintenance" as const, | |
| 243 | 214 | label: "Maintenance", |
| 244 | 215 | value: count(f.maintenance.open), |
| 245 | 216 | unit: f.maintenance.open === 1 ? "finding open" : "findings open", |
| @@ -249,6 +220,7 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 249 | 220 | }, |
| 250 | 221 | ]), |
| 251 | 222 | { |
| 223 | key: "backup", | |
| 252 | 224 | label: "Off-box backup", |
| 253 | 225 | value: backupAge === null ? "—" : duration(backupAge), |
| 254 | 226 | unit: |
| @@ -272,71 +244,3 @@ export function cards(f: Figures, now: number): Card[] { | ||
| 272 | 244 | }, |
| 273 | 245 | ]; |
| 274 | 246 | } |
| 275 | ||
| 276 | /** | |
| 277 | * The crew card: the red-main streak, then a row per member linking to their page; calm when empty. | |
| 278 | * Shown, never notified. | |
| 279 | */ | |
| 280 | export function crewSection(c: CrewCard | undefined): Html | null { | |
| 281 | if (c === undefined) return null; | |
| 282 | return html`<section class="cc" aria-labelledby="cc-title"> | |
| 283 | <h3 class="cc-title" id="cc-title">Crew, last ${c.days} days</h3> | |
| 284 | <p class="cc-streak num">${streakWords(c.streakDays, c.red)}</p> | |
| 285 | ${c.rows.length === 0 | |
| 286 | ? html`<p class="cc-empty muted">${CREW_EMPTY}</p>` | |
| 287 | : rowList(c.rows.map((r) => row({ href: `/settings/crew/${encodeURIComponent(r.username)}`, title: r.username, meta: html`${rowWords(r)}` })), { bare: true, label: "Crew members" })} | |
| 288 | </section>`; | |
| 289 | } | |
| 290 | ||
| 291 | /** The cards in their grid: the live region's body. */ | |
| 292 | export function figuresGrid(picture: LanePicture, now: number): Html { | |
| 293 | const f = picture.figures; | |
| 294 | if (f === null) | |
| 295 | return html`<div | |
| 296 | class="fg-body" | |
| 297 | id="hf-figures-body" | |
| 298 | data-reading | |
| 299 | aria-busy="true" | |
| 300 | data-live="${FIGURES_LIVE}" | |
| 301 | data-live-src="/live/figures" | |
| 302 | > | |
| 303 | <p class="fg-reading">Reading the figures…</p> | |
| 304 | </div>`; | |
| 305 | return html`<div | |
| 306 | class="fg-body" | |
| 307 | id="hf-figures-body" | |
| 308 | data-live="${FIGURES_LIVE}" | |
| 309 | data-live-src="/live/figures" | |
| 310 | > | |
| 311 | <div class="fg-grid">${cards(f, now).map(card)}</div> | |
| 312 | ${shipSection(f.ship)} | |
| 313 | ${crewSection(f.crew)} | |
| 314 | </div>`; | |
| 315 | } | |
| 316 | ||
| 317 | /** The section: a disclosure whose open state the page remembers, around the live grid. Admin only: the numbers are the forge's. */ | |
| 318 | export function figuresSection( | |
| 319 | picture: LanePicture | undefined, | |
| 320 | now: number, | |
| 321 | ): Html { | |
| 322 | const grid = | |
| 323 | picture === undefined | |
| 324 | ? html`<div | |
| 325 | class="fg-body" | |
| 326 | id="hf-figures-body" | |
| 327 | data-reading | |
| 328 | aria-busy="true" | |
| 329 | data-live="${FIGURES_LIVE}" | |
| 330 | data-live-src="/live/figures" | |
| 331 | > | |
| 332 | <p class="fg-reading">Reading the figures…</p> | |
| 333 | </div>` | |
| 334 | : figuresGrid(picture, now); | |
| 335 | return html`<details class="fg" id="hf-figures" open> | |
| 336 | <summary class="fg-sum"> | |
| 337 | <h2 class="fg-title">Figures</h2> | |
| 338 | <span class="fg-hint">What the forge measures beyond the lanes</span> | |
| 339 | </summary> | |
| 340 | ${grid} | |
| 341 | </details>`; | |
| 342 | } |
src/web/pages/home_flow.ts +23 −188
| @@ -24,12 +24,8 @@ import { time } from "../time_element.ts"; | ||
| 24 | 24 | import { requestHolds } from "../../http/conditional.ts"; |
| 25 | 25 | import { setCookie } from "../../auth/cookies.ts"; |
| 26 | 26 | import type { App } from "../../app.ts"; |
| 27 | import { listChildren } from "../../actions/spawn.ts"; | |
| 28 | import { lastHeard, MAX_CHILDREN, QUIET_MS } from "../../spawn/heartbeat.ts"; | |
| 29 | import { cellsHere, isAwakeBody } from "../../spawn/host.ts"; | |
| 30 | 27 | import { forgeCeiling } from "../../flow/ceiling.ts"; |
| 31 | 28 | import { timesOf, timeWords, type LaneTimes } from "../../flow/lane_times.ts"; |
| 32 | import { count, duration, money } from "../../flow/figure_format.ts"; | |
| 33 | 29 | import { |
| 34 | 30 | LANES, |
| 35 | 31 | LANE_HOLDS, |
| @@ -44,13 +40,12 @@ import { | ||
| 44 | 40 | type LanePicture, |
| 45 | 41 | type LaneView, |
| 46 | 42 | type PictureOptions, |
| 47 | type StripPart, | |
| 48 | 43 | type Viewing, |
| 49 | 44 | queueWords, |
| 50 | 45 | } from "../../flow/lanes.ts"; |
| 51 | 46 | import { span } from "../../flow/pipeline.ts"; |
| 52 | import { lastProof, proofNotice, provingSince, type Proof } from "../../release/prove.ts"; | |
| 53 | import { running, UNSTAMPED } from "../../kernel/version.ts"; | |
| 47 | import { proofNotice } from "../../release/prove.ts"; | |
| 48 | import { running } from "../../kernel/version.ts"; | |
| 54 | 49 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| 55 | 50 | import type { Ctx } from "../../http/context.ts"; |
| 56 | 51 | import { signInFirst } from "../chrome.ts"; |
| @@ -63,20 +58,19 @@ import { behaviorsJs } from "../behaviors.ts"; | ||
| 63 | 58 | import { liveRegionsJs } from "../client.ts"; |
| 64 | 59 | import { html, type Html } from "../html.ts"; |
| 65 | 60 | import { fragment, page, redirect } from "../layout.ts"; |
| 66 | import { BOOTED } from "../../release/gate.ts"; | |
| 67 | 61 | import { secureFor } from "../../http/cookie_secure.ts"; |
| 68 | 62 | import { cookieValue } from "../../http/context.ts"; |
| 69 | 63 | import { parseTable, tableParams, tableRows, type TableQuery } from "../../flow/lanes_table.ts"; |
| 70 | 64 | import { TABLE_LIVE, tableRegion, tableTag, tableTools } from "./home_table.ts"; |
| 71 | 65 | import { readableNotes } from "../../actions/desk.ts"; |
| 72 | import { deskStrip } from "../desk_strip.ts"; | |
| 66 | import { deskStrip, homeNotes } from "../desk_strip.ts"; | |
| 73 | 67 | import { askedSection } from "../studio/standing.ts"; |
| 74 | 68 | import { waitingOnMe, waitsDigest } from "../studio/waiting_on_me.ts"; |
| 75 | import { chart, figuresGrid, figuresSection } from "./home_figures.ts"; | |
| 69 | import { chart } from "./home_figures.ts"; | |
| 70 | import { homeRow, ROW_ALWAYS } from "../home_row.ts"; | |
| 76 | 71 | import { tellBox } from "../studio/living.ts"; |
| 77 | 72 | import { requestsCard } from "../requests_card.ts"; |
| 78 | 73 | import { asksToAnswer } from "../../actions/ask_admin.ts"; |
| 79 | import { whereOf } from "../../spawn/where.ts"; | |
| 80 | 74 | import { untoldAnswer, markTold } from "../../core/requests.ts"; |
| 81 | 75 | import { YOURE_IN_MESSAGE } from "../../actions/users.ts"; |
| 82 | 76 | import { spawnedForge } from "../../spawn/claim.ts"; |
| @@ -86,7 +80,6 @@ import { parkedFor } from "../../flow/parked_read.ts"; | ||
| 86 | 80 | import { firstWeekBlock } from "../first_week.ts"; |
| 87 | 81 | import { idleFor, type IdleReason } from "../../crew/idle_reason.ts"; |
| 88 | 82 | |
| 89 | ||
| 90 | 83 | /** |
| 91 | 84 | * The events that can move work between lanes, per lane. A burst of them is one fetch of the lane. |
| 92 | 85 | */ |
| @@ -99,7 +92,6 @@ const LANE_LIVE: Record<LaneKey, string> = { | ||
| 99 | 92 | live: "app.serving,release.*,run.finished,run.started,pull.merged", |
| 100 | 93 | }; |
| 101 | 94 | const STRIP_LIVE = "pull.merged,run.finished,release.*,app.serving,app.stopped,forge.*,queue.*"; |
| 102 | const FORGES_LIVE = "forge.*"; | |
| 103 | 95 | |
| 104 | 96 | /** An `owner/name` the filter may hold; anything else is no filter. */ |
| 105 | 97 | const APP_SLUG = /^[A-Za-z0-9._-]{1,100}\/[A-Za-z0-9._-]{1,100}$/; |
| @@ -243,7 +235,7 @@ export function laneRegion( | ||
| 243 | 235 | > |
| 244 | 236 | ${health.words} |
| 245 | 237 | </p> |
| 246 | <p class="lane-times num">${times?.nows[key] == null && times?.typicals[key] == null ? "" : html`${said.now} · ${said.typical}`}</p> | |
| 238 | <p class="lane-times num">${said}</p> | |
| 247 | 239 | ${shown === 0 |
| 248 | 240 | ? null |
| 249 | 241 | : html`<ol class="lane-list"> |
| @@ -264,7 +256,6 @@ export function laneRegion( | ||
| 264 | 256 | </section>`; |
| 265 | 257 | } |
| 266 | 258 | |
| 267 | ||
| 268 | 259 | /** What the lanes' reading needs of the forge. */ |
| 269 | 260 | const pictureOptions = (app: App): PictureOptions => ({ dataDir: app.config.dataDir, ceilingUsd: forgeCeiling(app.config) }); |
| 270 | 261 | const optionsOf = (ctx: Ctx, user: { readonly id: string } | undefined = ctx.auth.user): PictureOptions => ({ ...pictureOptions(ctx.app), ...(user === undefined ? {} : { viewer: user.id }) }); |
| @@ -283,30 +274,6 @@ const healthOf = (view: LaneView, picture: LanePicture, now: number): Health => | ||
| 283 | 274 | |
| 284 | 275 | // ---- the header's one line, and the strip: today's figures ---- |
| 285 | 276 | |
| 286 | export function proofWords(proof: Proof | undefined, version: string, since?: string): { text: string; tone: "attn" | null } { | |
| 287 | // A proof under way says so and when it began, so no release goes a quarter hour unspoken. | |
| 288 | if (since !== undefined && (proof === undefined || proof.version !== version || !proof.ok)) return { text: `still proving, started ${since.slice(11, 16)} UTC`, tone: null }; | |
| 289 | if (proof === undefined) return { text: "not proven yet", tone: null }; | |
| 290 | if (proof.version !== version) return { text: "proof running", tone: null }; | |
| 291 | return proof.ok ? { text: "journey proof passed", tone: null } : { text: "journey proof failed", tone: "attn" }; | |
| 292 | } | |
| 293 | ||
| 294 | /** | |
| 295 | * The week the figure shows: the provider's own meter when it has reported | |
| 296 | * one, else the forge's own estimate, said as one ("about"): the crew's | |
| 297 | * seven days at list price, against seven days of the daily ceiling when the | |
| 298 | * forge has one. | |
| 299 | */ | |
| 300 | function weekFigure(strip: StripPart): { value: string; note: string; attn: boolean } { | |
| 301 | const w = strip.week; | |
| 302 | if (w !== null) return { value: `${w.usedPct}%`, note: `of the crew's week; it may use ${w.mayUsePct}%`, attn: w.usedPct >= w.mayUsePct }; | |
| 303 | if (strip.ceilingUsd !== null && strip.ceilingUsd > 0) { | |
| 304 | const pct = Math.round((strip.weekSpendUsd / (strip.ceilingUsd * 7)) * 100); | |
| 305 | return { value: `about ${pct}%`, note: "the provider has not reported its week; this is the crew's seven days at list price against seven days of the daily ceiling", attn: pct >= 100 }; | |
| 306 | } | |
| 307 | return { value: `about ${money(strip.weekSpendUsd)}`, note: "spent by the crew in seven days, at list price; the provider has not reported its week", attn: false }; | |
| 308 | } | |
| 309 | ||
| 310 | 277 | /** |
| 311 | 278 | * Who the home is drawn for. Its one line counts only what is broken about the forge itself (a |
| 312 | 279 | * failing proof, a fired alarm of `FORGE_BROKEN`) and the people stopped until this viewer changes |
| @@ -362,27 +329,17 @@ export function needLine(broken: readonly { says: string; href: string }[], aske | ||
| 362 | 329 | } |
| 363 | 330 | |
| 364 | 331 | /** |
| 365 | * The strip, under the lanes: for an admin, five figures, each with its unit and, where the data | |
| 366 | * has one, a trend. Everyone else gets none: the figures are the forge's. | |
| 332 | * The one row of figures under the lanes and their graphs, each number said once (the owner's walk, | |
| 333 | * 2026-12-02: shipped was said four ways and the crew's runs and spend twice each): shipped in 24 | |
| 334 | * hours with its trend, the one median (open to landed), the crew running, the week used, visitors | |
| 335 | * and page speed. Off-box backup and overdue bugs join it only while they need someone. For an | |
| 336 | * admin; everyone else gets none: the figures are the forge's. | |
| 367 | 337 | */ |
| 368 | export function stripRegion(picture: LanePicture, viewer: StripViewer, dataDir: string, now: number): Html | null { | |
| 338 | export function stripRegion(picture: LanePicture, viewer: StripViewer, now: number): Html | null { | |
| 369 | 339 | if (!viewer.isAdmin) return null; |
| 370 | const strip = picture.strip; | |
| 371 | const version = running().version; | |
| 372 | const proof = proofWords(lastProof(dataDir), version, provingSince(dataDir, version)); | |
| 373 | const b = picture.builders; | |
| 374 | // The reason is only said while a slot is free: a busy crew has none. | |
| 375 | const idle = b.slots > 0 && b.running < b.slots ? (viewer.reads ?? (() => null))(picture.idle ?? null) : null; | |
| 376 | const week = strip === null ? null : weekFigure(strip); | |
| 377 | const lead = strip?.lead.medianHours ?? null; | |
| 340 | const row = homeRow(picture, viewer.reads ?? (() => null), now); | |
| 378 | 341 | return html`<section class="hf-strip" id="hf-strip" aria-label="Today's figures" data-live="${STRIP_LIVE}" data-live-src="/live/strip"> |
| 379 | <div class="hf-figs"> | |
| 380 | ${fig("Shipped in 24 hours", strip === null ? "—" : count(strip.landed), strip?.landed === 1 ? "change landed on main" : "changes landed on main", "/board", strip === null ? null : chart([...strip.landedHours].reverse(), "Changes landed per hour over the last 24 hours"))} | |
| 381 | ${fig("Median open to landed", lead === null ? "—" : duration(lead * 3_600_000), lead === null ? "nothing landed in 24 hours" : `median of ${count(strip!.lead.landed)} ${strip!.lead.landed === 1 ? "change" : "changes"}, 24 hours`, "/boards")} | |
| 382 | ${fig("Crew running", b.slots === 0 ? count(b.running) : `${count(b.running)} of ${count(b.slots)}`, b.slots === 0 ? "no builder slots set" : idle === null ? "builders at work now" : `idle: ${idle.word}`, idle === null ? "/settings/crew" : idle.href)} | |
| 383 | ${fig("Week used", week === null ? "—" : week.value, week === null ? "the week is not read yet" : week.note, "/settings/crew", null, week?.attn === true ? "attn" : null)} | |
| 384 | ${fig("Live version", version === UNSTAMPED ? "—" : version, html`live ${time(BOOTED, { class: "hf-age-ago", text: span(now - Date.parse(BOOTED)), count: "span" })} · ${proof.text}`, "/releases", null, proof.tone)} | |
| 385 | </div> | |
| 342 | <div class="hf-figs">${row.map((r) => fig(r.label, r.value, r.note, r.href, r.series === undefined ? null : chart(r.series, "Changes landed per hour over the last 24 hours"), r.tone))}</div> | |
| 386 | 343 | </section>`; |
| 387 | 344 | } |
| 388 | 345 | |
| @@ -411,107 +368,20 @@ export function readingLane(key: LaneKey, only: string | null): Html { | ||
| 411 | 368 | * gets none, as with the loaded strip. |
| 412 | 369 | */ |
| 413 | 370 | export const readingStrip = (wide: boolean): Html | null => |
| 414 | wide ? html`<section class="hf-strip" id="hf-strip" data-reading aria-busy="true" aria-label="Today's figures" data-live="${STRIP_LIVE}" data-live-src="/live/strip"><div class="hf-figs">${READING_FIGS.map(([label, href]) => fig(label, "—", "\u00a0", href))}</div></section>` : null; | |
| 415 | const READING_FIGS: readonly (readonly [string, string])[] = [ | |
| 416 | ["Shipped in 24 hours", "/board"], | |
| 417 | ["Median open to landed", "/boards"], | |
| 418 | ["Crew running", "/settings/crew"], | |
| 419 | ["Week used", "/settings/crew"], | |
| 420 | ["Live version", "/releases"], | |
| 421 | ]; | |
| 371 | wide ? html`<section class="hf-strip" id="hf-strip" data-reading aria-busy="true" aria-label="Today's figures" data-live="${STRIP_LIVE}" data-live-src="/live/strip"><div class="hf-figs">${ROW_ALWAYS.map(([label, href]) => fig(label, "…", "reading", href))}</div></section>` : null; | |
| 422 | 372 | |
| 423 | 373 | export const readingTable = (q: TableQuery): Html => { |
| 424 | 374 | const params = tableParams(q); |
| 425 | 375 | return html`<section class="tb-region" id="hf-table" data-reading aria-busy="true" data-live="${TABLE_LIVE}" data-live-src="/live/table${params === "" ? "" : `?${params}`}"><p class="tb-empty">Reading what the forge is doing…</p></section>`; |
| 426 | 376 | }; |
| 427 | 377 | |
| 428 | // ---- hosted forges, in one line ---- | |
| 429 | ||
| 430 | interface Forges { | |
| 431 | readonly at: number; | |
| 432 | readonly total: number; | |
| 433 | readonly awake: number; | |
| 434 | readonly quiet: readonly string[]; | |
| 435 | /** | |
| 436 | * Forges that run inside this forge's own process on a host that could hold them in a cell | |
| 437 | * (`spawn/where.ts`). | |
| 438 | */ | |
| 439 | readonly inProcess: number; | |
| 440 | } | |
| 441 | const forgesKept = new WeakMap<App, Forges>(); | |
| 442 | const forgesReading = new WeakMap<App, Promise<Forges | undefined>>(); | |
| 443 | const FORGES_REUSE_MS = process.env["NODE_ENV"] === "test" ? 0 : 20_000; | |
| 444 | ||
| 445 | /** | |
| 446 | * The hosted forges as the ledgers and the last heartbeats say: every file is | |
| 447 | * read at once (on a cold disk a hundred small reads one after another were | |
| 448 | * 1.6 s), and awake is a look at what this process holds open, never a read. | |
| 449 | * One reading at a time; it is started after a response or at boot, never | |
| 450 | * waited for by a page. | |
| 451 | */ | |
| 452 | function readForges(app: App, now: number): Promise<Forges | undefined> { | |
| 453 | const going = forgesReading.get(app); | |
| 454 | if (going !== undefined) return going; | |
| 455 | const reading = (async (): Promise<Forges | undefined> => { | |
| 456 | const children = await listChildren(app); | |
| 457 | const listed = children.slice(0, MAX_CHILDREN); | |
| 458 | const heard = await Promise.all(listed.map((c) => lastHeard(app, c.name))); | |
| 459 | const awake = listed.flatMap((c, i) => (isAwakeBody(app, c.bodyId) ? [{ name: c.name, heard: heard[i] }] : [])); | |
| 460 | // An awake forge that has stopped reporting to this one is the one worth a name. | |
| 461 | const quiet = awake.filter((c) => c.heard !== undefined && now - c.heard.receivedAt > QUIET_MS).map((c) => c.name); | |
| 462 | // Counted over every ledger, and only where the move is possible: the line asks for something | |
| 463 | // that can be done. | |
| 464 | const cells = children.some((c) => c.placement !== "cell") ? await cellsHere() : { ok: true as const }; | |
| 465 | const inProcess = children.filter((c) => whereOf(c, cells).inProcess && whereOf(c, cells).movable).length; | |
| 466 | const out: Forges = { at: now, total: children.length, awake: awake.length, quiet, inProcess }; | |
| 467 | forgesKept.set(app, out); | |
| 468 | return out; | |
| 469 | })().catch(() => undefined).finally(() => forgesReading.delete(app)); | |
| 470 | forgesReading.set(app, reading); | |
| 471 | return reading; | |
| 472 | } | |
| 473 | ||
| 474 | /** Start reading the hosted forges now: the forge calls this once it is listening. */ | |
| 378 | /** Start reading the lanes now: the forge calls this once it is listening. */ | |
| 475 | 379 | export function warmHome(app: App): void { |
| 476 | 380 | if (process.env["NODE_ENV"] === "test") return; |
| 477 | 381 | // The people who run the forge are counted first: the line that says what waits on them is ready |
| 478 | 382 | // for their first page. |
| 479 | 383 | const owners = app.db.query<{ id: string }, []>("SELECT id FROM user WHERE is_admin = 1 AND is_agent = 0 LIMIT 4").all().map((u) => u.id); |
| 480 | 384 | warmLanes(app.db, pictureOptions(app), Date.now(), owners); |
| 481 | void readForges(app, Date.now()); | |
| 482 | } | |
| 483 | ||
| 484 | function forgesHtml(f: Forges): Html { | |
| 485 | const words = | |
| 486 | f.total === 0 | |
| 487 | ? "No hosted forges yet." | |
| 488 | : `${f.total} hosted ${f.total === 1 ? "forge" : "forges"}: ${f.awake} awake, ${f.total - f.awake} asleep (a sleeping forge wakes when someone opens it). ${f.quiet.length === 0 ? "None is stuck." : `${f.quiet.join(", ")} ${f.quiet.length === 1 ? "is" : "are"} awake but not reporting.`}`; | |
| 489 | return html`<p class="hf-forges" id="hf-forges" data-live="${FORGES_LIVE}" data-live-src="/live/forges" data-tone="${f.quiet.length === 0 ? "ok" : "attn"}"><span class="dot" ${f.quiet.length === 0 ? null : html`data-tone="attn"`}></span><a href="/forges">${words}</a></p>`; | |
| 490 | } | |
| 491 | ||
| 492 | export const readingForges = (): Html => | |
| 493 | html`<p class="hf-forges" id="hf-forges" data-reading data-live="${FORGES_LIVE}" data-live-src="/live/forges"><span class="dot"></span><span>Reading the hosted forges…</span></p>`; | |
| 494 | ||
| 495 | /** | |
| 496 | * The hosted forges' line from the last reading, never a probe on a request: | |
| 497 | * older than 20 s, a new reading starts behind it; before any, the line says | |
| 498 | * it is reading and the page's script fetches it. A fragment (`wait`) waits | |
| 499 | * for the reading, off the thread. `bun test` waits, so a test reads what it wrote. | |
| 500 | */ | |
| 501 | export async function forgesRegion(app: App, wait: boolean): Promise<Html> { | |
| 502 | const now = Date.now(); | |
| 503 | const kept = forgesKept.get(app); | |
| 504 | if (kept === undefined) { | |
| 505 | const reading = readForges(app, now); | |
| 506 | if (!wait && process.env["NODE_ENV"] !== "test") return readingForges(); | |
| 507 | const f = await reading; | |
| 508 | return f === undefined ? readingForges() : forgesHtml(f); | |
| 509 | } | |
| 510 | if (now - kept.at >= FORGES_REUSE_MS) { | |
| 511 | const reading = readForges(app, now); | |
| 512 | if (process.env["NODE_ENV"] === "test") return forgesHtml((await reading) ?? kept); | |
| 513 | } | |
| 514 | return forgesHtml(kept); | |
| 515 | 385 | } |
| 516 | 386 | |
| 517 | 387 | // ---- the page ---- |
| @@ -531,7 +401,7 @@ function filterForm(repos: readonly string[], only: string | null, mine = false) | ||
| 531 | 401 | <noscript><input class="input" name="app" placeholder="owner/name" aria-label="An app, as owner/name" /><button class="btn" type="submit">Show</button></noscript> |
| 532 | 402 | ${mine ? html`<input type="hidden" name="waits" value="me" />` : null} |
| 533 | 403 | </form> |
| 534 | <a class="small" id="hf-waits" href="/?view=lanes${mine ? "" : "&waits=me"}${only === null ? "" : `&app=${encodeURIComponent(only)}`}" ${mine ? html`aria-current="true"` : null}>${mine ? "Waiting for me · show all" : "Waiting for me"}</a>`; | |
| 404 | <a class="small" id="hf-waits" href="/?view=lanes${mine ? "" : "&waits=me"}${only === null ? "" : `&app=${encodeURIComponent(only)}`}" ${mine ? html`aria-current="true"` : null}>${mine ? "Show everything" : "Show only what waits for me"}</a>`; | |
| 535 | 405 | } |
| 536 | 406 | |
| 537 | 407 | /** |
| @@ -578,7 +448,7 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 578 | 448 | // or lean. |
| 579 | 449 | const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app)); |
| 580 | 450 | const wide = user.isAdmin && spawned === undefined; |
| 581 | const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, ctx.app.config.dataDir, now); | |
| 451 | const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, now); | |
| 582 | 452 | const need = needLine(brokenOf(picture, wide, ctx.app.config.dataDir, now), new Set(asksToAnswer(ctx.app, user).map((a) => a.username)).size); |
| 583 | 453 | // What the old home also carried and is not a lane: the box that tells the crew (with Notes and |
| 584 | 454 | // Talk), the welcome after an account is allowed, a |
| @@ -594,12 +464,10 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 594 | 464 | // A client who asked for the whole home (`?all=1`) has a way back to their apps. |
| 595 | 465 | const after = html`${ctx.url.searchParams.has("all") ? html`<p class="small muted" id="lean-home"><a href="/">Just my apps</a></p>` : null}${focusLine(ctx, user)}${requestsCard(ctx, "home")} |
| 596 | 466 | ${spawned?.url === undefined ? null : html`<p class="small muted" id="forge-address">Your forge: <a href="${spawned.url}">${new URL(spawned.url).host}</a></p>`} |
| 597 | ${startedFromLine(ctx.app.db, ctx.app.config.dataDir, user)} | |
| 598 | ${archived === 0 ? null : html`<p class="small muted" id="archived-link"><a href="/archive">${archived} archived</a></p>`}`; | |
| 467 | ${startedFromLine(ctx.app.db, ctx.app.config.dataDir, user)}`; | |
| 599 | 468 | // The slots are a forge admin's: read and drawn for one only, so no one else sees the queue, the |
| 600 | 469 | // estimates, or a figure whose Enter would be refused. |
| 601 | 470 | const slots = view === "lanes" && wide ? slotsBlock(readSlots(ctx.app, new Date(now), { pace: false }), now, wide) : null; |
| 602 | const forges = wide ? await timePhaseAsync(ctx.request, "forges", () => forgesRegion(ctx.app, false)) : null; | |
| 603 | 471 | let main: Html; |
| 604 | 472 | const q = parseTable(ctx.url.searchParams); |
| 605 | 473 | // Each lane's health, read once: the lanes draw it and the header's "All quiet." asks its tone. |
| @@ -630,18 +498,16 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 630 | 498 | ${mine ? askedSection(ctx, user) : null} |
| 631 | 499 | ${main} |
| 632 | 500 | ${slots} |
| 501 | ${strip} | |
| 633 | 502 | ${parkedSection(parkedFor(ctx.app.db, user, picture?.strip?.parked))} |
| 634 | 503 | ${before} |
| 635 | ${strip} | |
| 636 | ${deskStrip(ctx.app.db, readableNotes(ctx.app, ctx.auth.user))} | |
| 504 | ${deskStrip(ctx.app.db, homeNotes(readableNotes(ctx.app, ctx.auth.user)))} | |
| 637 | 505 | ${pinnedSeries(ctx, now)} |
| 638 | 506 | ${after} |
| 639 | ${wide ? figuresSection(picture, now) : null} | |
| 640 | ${forges} | |
| 641 | 507 | ${view === "lanes" ? bridgeBar : null} |
| 642 | 508 | <p class="hf-foot small muted"> |
| 643 | 509 | <span>${view === "table" ? "Every item of every lane, one row each; sort, filter and search are in the address, so a link is a view." : "Each lane is a step a change takes; a tile moves on by itself when its work does."}</span> |
| 644 | <a href="/feed">The feed</a> | |
| 510 | <a href="/feed">The feed</a>${wide ? html` <a href="/settings/crew">Crew</a> <a href="/forges">Forges</a>` : null}${archived === 0 ? null : html` <a href="/archive" id="archived-link">${archived} archived</a>`} | |
| 645 | 511 | </p> |
| 646 | 512 | </div>`; |
| 647 | 513 | const res = page({ ctx, title: "Home", body, wide: true, scriptJs: `${liveRegionsJs}\n${homeFlowJs}\n${bridgeJs}\n${behaviorsJs}` }); |
| @@ -731,38 +597,7 @@ export async function liveStripFragment(ctx: Ctx): Promise<Response> { | ||
| 731 | 597 | const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now)); |
| 732 | 598 | const rendering = performance.now(); |
| 733 | 599 | const wide = user.isAdmin && (await spawnedForge(ctx.app)) === undefined; |
| 734 | const res = fragment((picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, ctx.app.config.dataDir, now)) ?? html``, { request: ctx.request, ...(wide ? {} : { status: 404 }) }); | |
| 735 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 736 | return res; | |
| 737 | } | |
| 738 | ||
| 739 | // GET /live/forges — the hosted forges' line, alone. | |
| 740 | export async function liveForgesFragment(ctx: Ctx): Promise<Response> { | |
| 741 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 742 | const user = ctx.auth.user; | |
| 743 | if (user === undefined || !user.isAdmin) { | |
| 744 | notePhase(ctx.request, "render", 0); | |
| 745 | return fragment(html``, { status: 404 }); | |
| 746 | } | |
| 747 | const rendering = performance.now(); | |
| 748 | const res = fragment(await timePhaseAsync(ctx.request, "forges", () => forgesRegion(ctx.app, true)), { request: ctx.request }); | |
| 749 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 750 | return res; | |
| 751 | } | |
| 752 | ||
| 753 | // GET /live/figures — the figures' grid alone, for the region that shows it. An admin's: the | |
| 754 | // numbers are the forge's. | |
| 755 | export async function liveFiguresFragment(ctx: Ctx): Promise<Response> { | |
| 756 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 757 | const user = ctx.auth.user; | |
| 758 | if (user === undefined || !user.isAdmin) { | |
| 759 | notePhase(ctx.request, "render", 0); | |
| 760 | return fragment(html``, { status: 404 }); | |
| 761 | } | |
| 762 | const now = Date.now(); | |
| 763 | const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx), "lane", now)); | |
| 764 | const rendering = performance.now(); | |
| 765 | const res = fragment(picture === undefined ? figuresSection(undefined, now) : figuresGrid(picture, now), { request: ctx.request }); | |
| 600 | const res = fragment((picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, now)) ?? html``, { request: ctx.request, ...(wide ? {} : { status: 404 }) }); | |
| 766 | 601 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 767 | 602 | return res; |
| 768 | 603 | } |
src/web/pages/home_flow_client.ts −10
| @@ -11,7 +11,6 @@ | ||
| 11 | 11 | * event arrives, a lane is swapped, or the tab comes back: time |
| 12 | 12 | * spent in a lane is always as old as the last thing that happened. |
| 13 | 13 | * stream the dot beside the title says whether the stream is connected. |
| 14 | * figures the section's open or closed state is remembered in this browser. | |
| 15 | 14 | * filter the select lists the other apps only when it is first used. |
| 16 | 15 | * reading a region drawn as "reading…" (the first page after a restart, before the worker |
| 17 | 16 | * has read the picture) fetches its own address once and takes the answer in place. |
| @@ -306,15 +305,6 @@ export const homeFlowJs = /* js */ ` | ||
| 306 | 305 | .catch(function () { giveUp(region, 'The forge could not read this just now. '); }); |
| 307 | 306 | }); |
| 308 | 307 | |
| 309 | // ---- the figures: open or closed, as this reader left it ---- | |
| 310 | var figures = doc.getElementById('hf-figures'); | |
| 311 | if (figures) { | |
| 312 | try { if (window.localStorage.getItem('forge.home.figures') === 'closed') figures.open = false; } catch (err) { /* no storage: the page's default */ } | |
| 313 | figures.addEventListener('toggle', function () { | |
| 314 | try { window.localStorage.setItem('forge.home.figures', figures.open ? 'open' : 'closed'); } catch (err) { /* nothing to remember with */ } | |
| 315 | }); | |
| 316 | } | |
| 317 | ||
| 318 | 308 | // A lane's "Show all N" is the disclose behavior (behaviors.ts); the lane keeps data-open through every redraw. |
| 319 | 309 | root.setAttribute('data-js', ''); |
| 320 | 310 | remember(); |
src/web/pages/home_flow_style.ts +5 −45
| @@ -22,7 +22,7 @@ export const homeFlowCss = /* css */ ` | ||
| 22 | 22 | |
| 23 | 23 | /* ---- the strip ---- */ |
| 24 | 24 | .hf-strip { display: flex; flex-direction: column; gap: 8px; } |
| 25 | .hf-need, .hf-forges { display: flex; align-items: center; gap: 8px; margin: 0; min-height: 24px; font-size: 13px; color: var(--muted-fg); } | |
| 25 | .hf-need { display: flex; align-items: center; gap: 8px; margin: 0; min-height: 24px; font-size: 13px; color: var(--muted-fg); } | |
| 26 | 26 | .hf-need { flex: 1 1 100%; min-width: 0; } |
| 27 | 27 | .hf-need a { flex: none; color: var(--fg); text-decoration: underline; text-underline-offset: 2px; } |
| 28 | 28 | .hf-need-first { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } |
| @@ -95,7 +95,7 @@ export const homeFlowCss = /* css */ ` | ||
| 95 | 95 | .lane-more .lane-toggle, .lane-more .lane-all { display: none; min-height: 44px; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; } |
| 96 | 96 | |
| 97 | 97 | .hf-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; margin: 0; } |
| 98 | .hf-foot a, .hf-forges a, .hf-need a { display: inline-flex; align-items: center; min-height: 44px; } | |
| 98 | .hf-foot a, .hf-need a { display: inline-flex; align-items: center; min-height: 44px; } | |
| 99 | 99 | @keyframes hf-arrive { from { background: color-mix(in srgb, var(--accent) 18%, var(--card)); } to { background: var(--card); } } |
| 100 | 100 | @keyframes hf-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } } |
| 101 | 101 | @media (prefers-reduced-motion: reduce) { |
| @@ -131,7 +131,8 @@ export const homeFlowCss = /* css */ ` | ||
| 131 | 131 | .hf-title { flex-direction: column; gap: 0; } |
| 132 | 132 | } |
| 133 | 133 | @media (min-width: 720px) { |
| 134 | .hf-figs { grid-template-columns: repeat(5, minmax(0, 1fr)); } | |
| 134 | /* One row of however many figures the row holds (four to eight), wrapping only when narrow. */ | |
| 135 | .hf-figs { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); } | |
| 135 | 136 | .hf-fig:last-child:nth-child(odd) { grid-column: auto; } |
| 136 | 137 | .hf-lanes { grid-template-columns: repeat(3, minmax(0, 1fr)); } |
| 137 | 138 | .lane-more-sm { display: none; } |
| @@ -222,66 +223,25 @@ export const homeFlowCss = /* css */ ` | ||
| 222 | 223 | /* ---- the figures ---- */ |
| 223 | 224 | /* The answers an ask can be given where it is read (/asks, web/studio/standing.ts). */ |
| 224 | 225 | .hf-need-acts { display: inline-flex; align-items: center; gap: 8px; } |
| 225 | .fg { display: flex; flex-direction: column; gap: 8px; } | |
| 226 | .fg-sum { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; list-style: none; } | |
| 227 | .fg-sum::-webkit-details-marker { display: none; } | |
| 228 | .fg-sum::before { content: ""; flex: none; width: 8px; height: 8px; margin-left: 4px; border-right: 1.5px solid var(--muted-fg); border-bottom: 1.5px solid var(--muted-fg); transform: rotate(-45deg); transition: transform var(--dur-2) var(--ease); } | |
| 229 | .fg[open] > .fg-sum::before { transform: rotate(45deg); } | |
| 230 | .cc { margin-top: 16px; } | |
| 231 | .cc-title { margin: 0; font-size: 14px; } | |
| 232 | .cc-streak { margin: 4px 0 8px; } | |
| 233 | .cc-empty { margin: 0; } | |
| 234 | .fg-title { margin: 0; font-size: 16px; } | |
| 235 | .fg-hint { font-size: var(--fs-min); color: var(--muted-fg); } | |
| 236 | .fg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; } | |
| 237 | .fg-card { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-1); color: var(--fg); } | |
| 238 | @media (hover: hover) and (pointer: fine) { a.fg-card:hover { border-color: var(--border-strong); color: var(--fg); } } | |
| 239 | .fg-card[data-tone="attn"] { border-color: color-mix(in srgb, var(--attn) 40%, var(--border)); } | |
| 240 | .fg-card[data-tone="attn"] .fg-n { color: var(--attn); } | |
| 241 | .fg-label { margin: 0; font-size: var(--fs-min); font-weight: 400; color: var(--muted-fg); } | |
| 242 | .fg-value { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; margin: 0; min-width: 0; } | |
| 243 | .fg-n { font-size: 20px; font-weight: 600; line-height: 28px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; } | |
| 244 | .fg-unit { font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 245 | .fg-note { min-height: 32px; margin: 0; font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 246 | .fg-chart { height: 32px; margin-top: 4px; } | |
| 247 | 226 | .fg-svg { display: block; width: 100%; height: 32px; } |
| 248 | 227 | .fg-line { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; } |
| 249 | 228 | .fg-area { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: none; } |
| 250 | 229 | .fg-base { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; } |
| 251 | 230 | .fg-dot { fill: var(--accent); } |
| 252 | .fg-change { min-height: 16px; margin: 0; font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 253 | .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); } | |
| 254 | .fg-reading { margin: 0; color: var(--muted-fg); } | |
| 255 | 231 | |
| 256 | 232 | /* ---- first paint reserves what fills in later (test/home-no-shift.test.ts) ---- |
| 257 | 233 | A region in its reading state is the loaded region's own markup where the |
| 258 | loaded one is fixed (the strip draws its five figures with "—"), and holds | |
| 234 | loaded one is fixed (the strip draws the row's own figures, "…" and "reading"), and holds | |
| 259 | 235 | the loaded floor where the data decides the rest. The floors are summed |
| 260 | 236 | from the loaded rules above, not guessed: change a part, change its sum. |
| 261 | 237 | Not measured in a browser (none ran where this was written); the data |
| 262 | 238 | decides the rest, so a long note or a busy lane still grows past its floor. */ |
| 263 | .hf-forges { min-height: 44px; } | |
| 264 | 239 | /* A lane: its head and health line are in the reading markup already; the |
| 265 | 240 | floor adds, under its 8px padding, one tile row: a gap (8px) and the tile's |
| 266 | 241 | min-height (44px). */ |
| 267 | 242 | .lane[data-reading] { padding-bottom: 64px; } |
| 268 | 243 | /* A table: its header row and one row, each 44px (.tb-pick), and the gap. */ |
| 269 | 244 | .tb-region[data-reading] { min-height: calc(44px + 8px + 44px); } |
| 270 | /* A figures card (and the ship time disclosure under them, 12 + 44): border 2 + padding 24 + label 18 + gap 4 + value 28 + gap 4 | |
| 271 | + note 32 + gap 4 + chart (4 + 32) + gap 4 + axis 16 = 172px, one row. */ | |
| 272 | .fg-body { min-height: 228px; } | |
| 273 | /* Ship time (#14649), under the cards: the disclosure's summary is 44px, a gap of 12px above it. */ | |
| 274 | .fs { margin-top: 12px; } | |
| 275 | .fs-sum { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; } | |
| 276 | .fs-svg { display: block; width: 100%; max-width: 480px; height: auto; aspect-ratio: 320 / 96; } | |
| 277 | .fs-bar { fill: var(--muted-fg); } | |
| 278 | .fs-count { font-size: var(--fs-min); fill: var(--muted-fg); font-variant-numeric: tabular-nums; } | |
| 279 | .fs-base { stroke: var(--border); stroke-width: 1; } | |
| 280 | .fs-h { margin: 12px 0 4px; font-size: var(--fs-min); font-weight: 400; color: var(--muted-fg); } | |
| 281 | .fs-slow { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; } | |
| 282 | .fs-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; } | |
| 283 | .fs-took, .fs-why, .fs-assume { font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 284 | .fs-assume { margin: 12px 0 0; } | |
| 285 | 245 | |
| 286 | 246 | /* ---- the box that tells the crew, kept to one row on a desk ---- */ |
| 287 | 247 | .hf-tell { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; } |
src/web/pages/home_ship.ts deleted −61
| @@ -1,61 +0,0 @@ | ||
| 1 | /** | |
| 2 | * Ship time under the figures (#14649): the sentence as the summary of one disclosure, and inside | |
| 3 | * it a histogram drawn as SVG on the server (no script, no chart library) and, for the slowest | |
| 4 | * decile, what each one's time went to, each linked to its issue. The data is `flow/ship_time.ts`, | |
| 5 | * the definition is in its header and shown here as the assumptions. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { ShipTime } from "../../flow/ship_time.ts"; | |
| 9 | import { barWords, shipSentence, shipSpan, slowLine } from "../../flow/ship_words.ts"; | |
| 10 | import { html, type Html } from "../html.ts"; | |
| 11 | ||
| 12 | const W = 320; | |
| 13 | const H = 96; | |
| 14 | ||
| 15 | /** | |
| 16 | * The histogram: one bar per fixed range, scaled to the fullest, its count above and its range | |
| 17 | * named in the title. | |
| 18 | */ | |
| 19 | export function histogramSvg(s: ShipTime): Html { | |
| 20 | const top = Math.max(1, ...s.histogram.map((b) => b.count)); | |
| 21 | const slot = W / s.histogram.length; | |
| 22 | const bars = s.histogram.map((b, i) => { | |
| 23 | const h = Math.round((b.count / top) * (H - 20)); | |
| 24 | const x = (i * slot + 3).toFixed(1); | |
| 25 | return html`<g> | |
| 26 | <title>${barWords(b.fromMs, b.toMs)}: ${b.count}</title> | |
| 27 | <rect class="fs-bar" x="${x}" y="${H - 4 - h}" width="${(slot - 6).toFixed(1)}" height="${h}" /> | |
| 28 | <text class="fs-count" x="${(i * slot + slot / 2).toFixed(1)}" y="${H - 7 - h}" text-anchor="middle">${b.count}</text> | |
| 29 | </g>`; | |
| 30 | }); | |
| 31 | return html`<svg class="fs-svg" viewBox="0 0 ${W} ${H}" role="img" | |
| 32 | aria-label="Ship times of ${s.count} issues, in ${s.histogram.length} ranges from under ${shipSpan(s.histogram[0]!.toMs ?? 0)} to ${shipSpan(s.histogram[s.histogram.length - 1]!.fromMs)} or more"> | |
| 33 | <line class="fs-base" x1="0" y1="${H - 3.5}" x2="${W}" y2="${H - 3.5}" />${bars} | |
| 34 | </svg>`; | |
| 35 | } | |
| 36 | ||
| 37 | /** The disclosure: sentence, histogram, the slowest decile, and what is assumed. */ | |
| 38 | export function shipSection(s: ShipTime): Html { | |
| 39 | const slow = | |
| 40 | s.slowest.length === 0 | |
| 41 | ? null | |
| 42 | : html`<h4 class="fs-h">The slowest tenth, and what the time went to</h4> | |
| 43 | <ol class="fs-slow"> | |
| 44 | ${s.slowest.map( | |
| 45 | (i) => html`<li class="fs-item"> | |
| 46 | <a href="${i.path}">${i.repo}#${i.number} ${i.title}</a> | |
| 47 | <span class="fs-took">shipped in ${shipSpan(i.shipMs)}</span> | |
| 48 | <span class="fs-why">${slowLine(i)} · work ${shipSpan(i.workMs)}</span> | |
| 49 | </li>`, | |
| 50 | )} | |
| 51 | </ol>`; | |
| 52 | return html`<details class="fs" id="hf-ship"> | |
| 53 | <summary class="fs-sum">${shipSentence(s)}</summary> | |
| 54 | ${s.count === 0 ? null : histogramSvg(s)} | |
| 55 | ${slow} | |
| 56 | <p class="fs-assume"> | |
| 57 | First crew run to closing as done, last 7 days; the rest is in | |
| 58 | <a href="/docs/features/ship-time.md">the ship time doc</a>. | |
| 59 | </p> | |
| 60 | </details>`; | |
| 61 | } |
src/web/studio/fork_line.ts +7 −1
| @@ -30,6 +30,12 @@ export function forkFlowsLine(ctx: Ctx, user: User): Html | null { | ||
| 30 | 30 | if (!hasForkFamily(ctx.app.db, user)) return null; |
| 31 | 31 | const c = forkCounts(forkFlows(ctx.app, user)); |
| 32 | 32 | if (c === null) return null; |
| 33 | const words = `${String(c.waiting)} ${c.waiting === 1 ? "offer" : "offers"} waiting upstream · ${String(c.offered)} offered to you · ${String(c.behind)} ${c.behind === 1 ? "fork" : "forks"} behind`; | |
| 33 | // Only what is there is said: a zero is no fact ("0 forks behind"), and all zeros say nothing. | |
| 34 | const words = [ | |
| 35 | c.waiting === 0 ? null : `${String(c.waiting)} ${c.waiting === 1 ? "offer" : "offers"} waiting upstream`, | |
| 36 | c.offered === 0 ? null : `${String(c.offered)} offered to you`, | |
| 37 | c.behind === 0 ? null : `${String(c.behind)} ${c.behind === 1 ? "fork" : "forks"} behind`, | |
| 38 | ].filter((w) => w !== null).join(" · "); | |
| 39 | if (words === "") return null; | |
| 34 | 40 | return html`<p class="small muted" id="hf-forks"><a href="/forks/flows">${words}</a></p>`; |
| 35 | 41 | } |
test/crew-card.test.ts +5 −48
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | * The home's crew card (#16849): landed, first-pass green and rework per member, the red-main | |
| 3 | * streak, calm when empty, an admin's alone, and drawn from the worker's picture. | |
| 2 | * The crew card's reading (#16849): landed, first-pass green and rework per member, and the | |
| 3 | * red-main streak, as the worker's figures carry it (the home no longer draws a card, 2026-12-02). | |
| 4 | 4 | */ |
| 5 | 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 6 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -10,13 +10,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { createIssue } from "../src/core/issues.ts"; |
| 11 | 11 | import { submitReview } from "../src/core/reviews.ts"; |
| 12 | 12 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; |
| 13 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 14 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 15 | import { dashboardScreen } from "../src/tui/screens/dashboard.ts"; | |
| 16 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 17 | import { settleApp } from "./helpers/tui.ts"; | |
| 18 | import { crewCardLines, readCrewCard, streakWords } from "../src/flow/crew_card.ts"; | |
| 19 | import { crewSection } from "../src/web/pages/home_figures.ts"; | |
| 13 | import { getUserByName } from "../src/core/users.ts"; | |
| 14 | import { readCrewCard, rowWords } from "../src/flow/crew_card.ts"; | |
| 20 | 15 | import { serve, type Servers } from "../src/http/server.ts"; |
| 21 | 16 | import { adminCookie } from "./helpers/admin.ts"; |
| 22 | 17 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -73,8 +68,6 @@ describe("the crew card", () => { | ||
| 73 | 68 | expect(card.rows).toEqual([]); |
| 74 | 69 | expect(card.streakDays).toBeNull(); |
| 75 | 70 | expect(card.red).toBe(false); |
| 76 | expect(crewCardLines(card)).toEqual([]); | |
| 77 | expect(String(crewSection(card))).toContain("Nothing has landed"); | |
| 78 | 71 | }); |
| 79 | 72 | |
| 80 | 73 | test("landed, first-pass green and rework per member, over merged pulls only", () => { |
| @@ -94,8 +87,7 @@ describe("the crew card", () => { | ||
| 94 | 87 | expect(row.landed).toBe(4); |
| 95 | 88 | expect(row.firstPassGreen).toBeCloseTo(3 / 4); |
| 96 | 89 | expect(row.rework).toBeCloseTo(1 / 4); |
| 97 | expect(crewCardLines(readCrewCard(app.db, new Date()))[1]).toContain("4 landed · 75% green first pass · 25% rework"); | |
| 98 | expect(String(crewSection(readCrewCard(app.db, new Date())))).toContain('href="/settings/crew/smith"'); | |
| 90 | expect(rowWords(row)).toBe("4 landed · 75% green first pass · 25% rework"); | |
| 99 | 91 | }); |
| 100 | 92 | |
| 101 | 93 | test("the streak counts days since main's last red; red now and red today read apart", () => { |
| @@ -105,44 +97,9 @@ describe("the crew card", () => { | ||
| 105 | 97 | check(undefined, "ok", new Date(now.getTime() - 3_600_000).toISOString()); |
| 106 | 98 | expect(readCrewCard(app.db, now).streakDays).toBe(4); |
| 107 | 99 | expect(readCrewCard(app.db, now).red).toBe(false); |
| 108 | expect(streakWords(4, false)).toBe("4 days without a red main"); | |
| 109 | expect(streakWords(1, false)).toBe("1 day without a red main"); | |
| 110 | expect(streakWords(0, false)).toBe("Main went red today"); | |
| 111 | 100 | check(undefined, "failed"); |
| 112 | 101 | const red = readCrewCard(app.db, now); |
| 113 | 102 | expect(red.streakDays).toBe(0); |
| 114 | 103 | expect(red.red).toBe(true); |
| 115 | expect(streakWords(red.streakDays, red.red)).toBe("Main is red now"); | |
| 116 | }); | |
| 117 | ||
| 118 | test("the figures region answers an admin and refuses a visitor", async () => { | |
| 119 | await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 120 | const res = await fetch(`${servers.url}/live/figures`, { headers: { cookie } }); | |
| 121 | expect(res.status).toBe(200); | |
| 122 | // The picture is read by the worker; until it has read, the card says it is reading. | |
| 123 | const text = await res.text(); | |
| 124 | expect(text.includes("Crew, last 30 days") || text.includes("Reading the figures")).toBe(true); | |
| 125 | const anon = await fetch(`${servers.url}/live/figures`, { redirect: "manual" }); | |
| 126 | expect(anon.status).toBe(404); | |
| 127 | }); | |
| 128 | ||
| 129 | async function dashboardText(username: string): Promise<string> { | |
| 130 | const user = getUserByName(app.db, username)!; | |
| 131 | const { app: tui, session } = createForgeApp( | |
| 132 | app, | |
| 133 | { sshUsername: username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user }, | |
| 134 | { terminal: headlessTerminal(120, 60), exitHooks: false }, | |
| 135 | ); | |
| 136 | tui.start(); | |
| 137 | tui.ctx.push(dashboardScreen(session, tui.ctx)); | |
| 138 | await settleApp(tui); | |
| 139 | const text = tui.screen.toText(); | |
| 140 | tui.stop?.(); | |
| 141 | return text; | |
| 142 | } | |
| 143 | ||
| 144 | test("the terminal dashboard shows an admin the streak line and a guest not", async () => { | |
| 145 | expect(await dashboardText("ada")).toContain("Crew, 30 days: Main is red now"); | |
| 146 | expect(await dashboardText("bob")).not.toContain("Crew, 30 days"); | |
| 147 | 104 | }); |
| 148 | 105 | }); |
test/docs-not-found.test.ts +1 −1
| @@ -86,7 +86,7 @@ const OFF = [ | ||
| 86 | 86 | "/settings/runners/lending/live", "/settings/backups/live", "/settings/teams", |
| 87 | 87 | "/settings/teams/stream", "/infra/live", "/fleet/graph/live", "/live/apps", "/live/talk-work", |
| 88 | 88 | "/live/talk-plan", "/live/talk-crew", "/live/on-you", "/live/desk", "/live/client-apps", |
| 89 | "/live/feed", "/live/lane", "/live/strip", "/live/forges", "/live/table", "/live/figures", | |
| 89 | "/live/feed", "/live/lane", "/live/strip", "/live/table", | |
| 90 | 90 | "/live/home/waiting", "/live/home/panels", "/live/home/feed", |
| 91 | 91 | ]; |
| 92 | 92 |
test/flow-slots.test.ts +3
| @@ -87,6 +87,9 @@ test("drawn, a full lane reads as full: the danger badge, solid bars at the line | ||
| 87 | 87 | const out = slotsBlock([full, calm], NOW, true).text.replace(/\s+/g, " "); |
| 88 | 88 | expect(out).toContain('data-kind="checks" data-full'); |
| 89 | 89 | expect(out).toContain("4 of 4 slots busy"); |
| 90 | // More running than slots (a local fallback) is said as it is, never "5 of 4". | |
| 91 | expect(String(slotsBlock([{ ...calm, busy: 5, slots: 4 }], NOW, true))).toContain("5 running, 4 slots"); | |
| 92 | expect(String(slotsBlock([{ ...calm, busy: 2, slots: 1 }], NOW, true))).toContain("2 running, 1 slot<"); | |
| 90 | 93 | expect(out).toContain(">full<"); |
| 91 | 94 | expect(out).toContain("17 waiting · oldest 44m · median wait 12m (last hour)"); |
| 92 | 95 | expect(out).toContain('class="sl-full"'); |
test/home-builders-idle.test.ts +12 −13
| @@ -16,7 +16,6 @@ import { idleFor, idleReason, NOBODY_WORD } from "../src/crew/idle_reason.ts"; | ||
| 16 | 16 | import { writeStamp } from "../src/core/write_clock.ts"; |
| 17 | 17 | import { cachedKpis, kpiCache } from "../src/web/studio/home_cache.ts"; |
| 18 | 18 | import { readKpis } from "../src/flow/kpis.ts"; |
| 19 | import { kpiLines } from "../src/flow/kpi_words.ts"; | |
| 20 | 19 | import { createSession } from "../src/core/sessions.ts"; |
| 21 | 20 | import { noteLimit } from "../src/core/standing.ts"; |
| 22 | 21 | import { addSubscription, EVERYONE, setGrants } from "../src/core/subscriptions.ts"; |
| @@ -105,7 +104,7 @@ test("nothing ready: the map has nothing a builder may start", async () => { | ||
| 105 | 104 | const page = await home(); |
| 106 | 105 | expect(tile(page)).toContain("nothing ready"); |
| 107 | 106 | expect(tile(page)).toContain('href="/map"'); |
| 108 | expect(await terminal()).toContain("Builders running 0 of 1 · nothing ready"); | |
| 107 | expect(await terminal()).toContain("Crew running: 0 of 1 · idle: nothing ready"); | |
| 109 | 108 | }); |
| 110 | 109 | |
| 111 | 110 | test("a crew that names nobody to act as is said, with the one control that fixes it, never skipped", async () => { |
| @@ -122,7 +121,8 @@ test("a crew that names nobody to act as is said, with the one control that fixe | ||
| 122 | 121 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-long-passphrase" }); |
| 123 | 122 | const bob = made.ok ? made.value : getUserByName(app.db, "bob")!; |
| 124 | 123 | for (const viewer of [bob, undefined]) expect(idleFor(app, viewer, reason)).toEqual({ word: NOBODY_WORD, href: "/settings/crew" }); |
| 125 | expect(idleFor(app, admin, reason)).toEqual(reason); | |
| 124 | // A reader is told which repository, by name. | |
| 125 | expect(idleFor(app, admin, reason)).toEqual({ ...reason!, word: NOBODY_WORD.replace("a repository's", "alice/engine's") }); | |
| 126 | 126 | const bobHome = await freshHome(servers.url, `forge_session=${createSession(app.db, bob.id).token}; forge_mode=studio`); |
| 127 | 127 | expect(bobHome).not.toContain("alice/engine"); |
| 128 | 128 | const guest = await (await fetch(`${servers.url}/`)).text(); |
| @@ -140,7 +140,7 @@ test("a ready issue and a builder with room: no reason is named", async () => { | ||
| 140 | 140 | const page = await home(); |
| 141 | 141 | expect(tile(page)).not.toContain("nothing ready"); |
| 142 | 142 | expect(tile(page)).toContain("at work now"); |
| 143 | expect(await terminal()).not.toMatch(/Builders running 0 of 1 · (nothing|no sub|week)/); | |
| 143 | expect(await terminal()).not.toMatch(/Crew running: 0 of 1 · idle: (nothing|no sub|week)/); | |
| 144 | 144 | }); |
| 145 | 145 | |
| 146 | 146 | test("no subscription with headroom: the granted account's window is full", async () => { |
| @@ -158,7 +158,7 @@ test("no subscription with headroom: the granted account's window is full", asyn | ||
| 158 | 158 | expect(writeStamp(app.db)).toBe(stampBefore); |
| 159 | 159 | expect(tile(page)).toContain("no subscription with headroom"); |
| 160 | 160 | expect(tile(page)).toContain('href="/subscriptions"'); |
| 161 | expect(await terminal()).toContain("Builders running 0 of 1 · no subscription with headroom"); | |
| 161 | expect(await terminal()).toContain("Crew running: 0 of 1 · idle: no subscription with headroom"); | |
| 162 | 162 | }); |
| 163 | 163 | |
| 164 | 164 | test("week spent outranks the others: dollars alone do not, the provider's week does", async () => { |
| @@ -174,7 +174,7 @@ test("week spent outranks the others: dollars alone do not, the provider's week | ||
| 174 | 174 | const page = await home(); |
| 175 | 175 | expect(tile(page)).toContain("week spent"); |
| 176 | 176 | expect(tile(page)).toContain('href="/meter"'); |
| 177 | expect(await terminal()).toContain("Builders running 0 of 1 · week spent"); | |
| 177 | expect(await terminal()).toContain("Crew running: 0 of 1 · idle: week spent"); | |
| 178 | 178 | }); |
| 179 | 179 | |
| 180 | 180 | test("every slot busy: no reason is shown", async () => { |
| @@ -183,7 +183,7 @@ test("every slot busy: no reason is shown", async () => { | ||
| 183 | 183 | const page = await home(); |
| 184 | 184 | expect(tile(page)).toContain("1 of 1"); |
| 185 | 185 | expect(tile(page)).not.toContain("week spent"); |
| 186 | expect(await terminal()).toContain("Builders running 1 of 1"); | |
| 186 | expect(await terminal()).toContain("Crew running: 1 of 1"); | |
| 187 | 187 | expect(await terminal()).not.toContain("week spent"); |
| 188 | 188 | }); |
| 189 | 189 | |
| @@ -196,16 +196,15 @@ test("both doors agree within home's 60 s KPI entry: the run ends, each says 0 o | ||
| 196 | 196 | const page = await home(true); |
| 197 | 197 | expect(tile(page)).toContain("0 of 1"); |
| 198 | 198 | expect(tile(page)).toContain("week spent"); |
| 199 | expect(await terminal()).toContain("Builders running 0 of 1 · week spent"); | |
| 199 | expect(await terminal()).toContain("Crew running: 0 of 1 · idle: week spent"); | |
| 200 | 200 | }); |
| 201 | 201 | |
| 202 | test("the reason rides in the cached KPI answer: readKpis carries it, the tile and line print it (#7664)", async () => { | |
| 202 | test("the reason rides in the cached KPI answer: readKpis carries it, the tile prints it (#7664)", async () => { | |
| 203 | 203 | for (const r of app.db.query<{ id: string }, []>("SELECT id FROM run WHERE kind = 'agent' AND state = 'running'").all()) |
| 204 | 204 | finishRun(app.db, r.id, { state: "ok", summary: "done" }); |
| 205 | 205 | const now = new Date(); |
| 206 | 206 | const k = readKpis(app.db, now, { ceilingUsd: null, idle: () => idleReason(app, now) }); |
| 207 | 207 | expect(k.builders.idle).toEqual({ word: "week spent", href: "/meter" }); |
| 208 | expect(kpiLines(k, null)[3]).toBe("Builders running 0 of 1 · week spent"); | |
| 209 | 208 | // Every slot busy: nothing is added, and the reason is not asked. |
| 210 | 209 | claimRun(app.db, createRun(app.db, { repoId: repo.id, kind: "agent", actorId: builder.id, reason: "assigned" }).id); |
| 211 | 210 | const busy = readKpis(app.db, now, { ceilingUsd: null, idle: () => { throw new Error("asked"); } }); |
| @@ -240,7 +239,7 @@ test("slots shown are the crew's concurrency, not the sum of the repositories' c | ||
| 240 | 239 | const page = await home(); |
| 241 | 240 | expect(tile(page)).toMatch(/\d of 4/); |
| 242 | 241 | expect(tile(page)).not.toContain("of 16"); |
| 243 | expect(kpiLines(readKpis(app.db, new Date()), null).find((l) => l.startsWith("Builders running"))).toMatch(/Builders running \d of 4/); | |
| 242 | expect(readKpis(app.db, new Date()).builders.slots).toBe(4); | |
| 244 | 243 | // Never more than the repositories offer: 8 here, under the setting's most (16). A value |
| 245 | 244 | // the setting refuses (40) reads as the machine's own default, which follows its memory. |
| 246 | 245 | const narrow = await updateRepoSettings(app, admin, wide.ok ? wide.value : repo, { autonomySlots: 8 }); |
| @@ -259,8 +258,8 @@ test("the slots figure is crew.concurrency on home and in the terminal, and the | ||
| 259 | 258 | app.db.query("INSERT OR REPLACE INTO forge_setting (key, value, updated_by, updated_at) VALUES ('crew.concurrency', '3', ?1, datetime('now'))").run(admin.id); |
| 260 | 259 | const running = app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM run WHERE kind = 'agent' AND state = 'running'").get()!.n; |
| 261 | 260 | const text = await terminal(); |
| 262 | expect(text).toContain(`Builders running ${running} of 3`); | |
| 263 | expect(text.split("\n").find((l) => l.startsWith("Builders running"))).not.toContain("of 16"); | |
| 261 | expect(text).toContain(`Crew running: ${running} of 3`); | |
| 262 | expect(text.split("\n").find((l) => l.trimStart().startsWith("Crew running"))).not.toContain("of 16"); | |
| 264 | 263 | expect(tile(await home())).toContain(`${running} of 3`); |
| 265 | 264 | } finally { |
| 266 | 265 | app.db.query("DELETE FROM forge_setting WHERE key = 'crew.concurrency'").run(); |
test/home-figures.test.ts +14 −9
| @@ -117,19 +117,24 @@ describe("the figures come from the picture", () => { | ||
| 117 | 117 | await rm(dataDir, { recursive: true, force: true }); |
| 118 | 118 | }); |
| 119 | 119 | |
| 120 | test("the worker's picture carries them, and the home draws one section of cards that is the owner's alone", async () => { | |
| 120 | test("the worker's picture carries them, and the home's strip says Visitors and Page speed once, with no section of cards", async () => { | |
| 121 | 121 | const picture = await lanePicture(app.db, { dataDir, ceilingUsd: null, viewer: seed.owner.id }); |
| 122 | 122 | expect(picture?.figures?.shipped.days.length).toBe(14); |
| 123 | 123 | expect(picture?.figures?.shipped.total).toBeGreaterThan(0); |
| 124 | 124 | const html = await (await fetch(`${servers.url}/`, { headers: { cookie: owner } })).text(); |
| 125 | expect(html).toContain('id="hf-figures"'); | |
| 126 | expect(html.match(/class="fg-card/g)?.length).toBe(7); | |
| 127 | expect(html).toContain('id="hf-ship"'); | |
| 128 | expect(html).toContain("Median ship time this week:"); | |
| 125 | const strip = /<section[^>]*id="hf-strip"[\s\S]*?<\/section>/.exec(html)?.[0] ?? ""; | |
| 126 | for (const label of ["Visitors", "Page speed"]) { | |
| 127 | expect(strip.split(`<span class="hf-fig-label">${label}</span>`).length - 1).toBe(1); | |
| 128 | expect(html.split(`<span class="hf-fig-label">${label}</span>`).length - 1).toBe(1); | |
| 129 | } | |
| 130 | expect(html).not.toContain('id="hf-figures"'); | |
| 131 | expect(html).not.toContain('class="fg-card'); | |
| 132 | expect(html).not.toContain('id="hf-ship"'); | |
| 133 | expect(html).not.toContain("Median ship time"); | |
| 134 | // No backup has left the machine, so the backup is not said as safe, nor drawn while not | |
| 135 | // overdue. | |
| 129 | 136 | expect(html).not.toContain("Safe off the machine"); |
| 130 | const body = await fetch(`${servers.url}/live/figures`, { headers: { cookie: owner } }); | |
| 131 | expect(body.status).toBe(200); | |
| 132 | expect((await body.text()).match(/class="fg-card/g)?.length).toBe(7); | |
| 133 | expect((await fetch(`${servers.url}/live/figures`)).status).toBeGreaterThanOrEqual(400); | |
| 137 | expect((await fetch(`${servers.url}/live/figures`, { headers: { cookie: owner } })).status).toBe(404); | |
| 138 | expect((await fetch(`${servers.url}/live/figures`)).status).toBe(404); | |
| 134 | 139 | }); |
| 135 | 140 | }); |
test/home-flow.test.ts +10 −6
| @@ -68,9 +68,10 @@ describe("the new home draws every lane", () => { | ||
| 68 | 68 | expect(titles(html, "live")).toContain("The merge queue says why it is waiting"); |
| 69 | 69 | // a lane never holds another lane's work |
| 70 | 70 | expect(titles(html, "checks")).not.toContain("Show a hosted forge's state in one line"); |
| 71 | // the strip, the hosted forges line, and the way back | |
| 71 | // the strip, and the foot's way to the hosted forges (the line that read them is gone) | |
| 72 | 72 | expect(html).toContain('id="hf-strip"'); |
| 73 | expect(html).toContain('id="hf-forges"'); | |
| 73 | expect(html).not.toContain('id="hf-forges"'); | |
| 74 | expect(html).toContain('<a href="/forges">Forges</a>'); | |
| 74 | 75 | expect(html).not.toContain("classic"); |
| 75 | 76 | expect(html).not.toContain("Try the new home"); |
| 76 | 77 | }); |
| @@ -126,7 +127,9 @@ describe("the new home draws every lane", () => { | ||
| 126 | 127 | // the line that needs him, never the owner's figures |
| 127 | 128 | expect(html).not.toContain("hf-figs"); |
| 128 | 129 | expect(html).not.toContain('id="hf-figures"'); |
| 129 | expect((await get("/live/figures", bob)).status).toBe(403); | |
| 130 | // the figures section and its region are gone for everyone | |
| 131 | expect((await get("/live/figures", bob)).status).toBe(404); | |
| 132 | expect(html).not.toContain('href="/forges"'); | |
| 130 | 133 | expect(await (await get("/live/strip", bob)).text()).not.toContain("hf-figs"); |
| 131 | 134 | // signed out, `/` is the public door and nothing of the pipeline |
| 132 | 135 | const door = await fetch(`${servers.url}/`, { redirect: "manual" }); |
| @@ -290,7 +293,7 @@ describe("before the first reading, a page never reads on the thread", () => { | ||
| 290 | 293 | const html = await first.text(); |
| 291 | 294 | expect(html).toContain("data-reading"); |
| 292 | 295 | expect(html).toContain("Reading what the forge is doing"); |
| 293 | expect(html).toContain("Reading the hosted forges"); | |
| 296 | expect(html).not.toContain("Reading the hosted forges"); | |
| 294 | 297 | for (const lane of LANES) expect(html).toContain(`id="lane-${lane}"`); |
| 295 | 298 | expect(html).not.toContain("A cost ledger per delivery"); |
| 296 | 299 | // its script fills each region from the region's own address: the lane waits for the worker, |
| @@ -298,8 +301,9 @@ describe("before the first reading, a page never reads on the thread", () => { | ||
| 298 | 301 | const lane = await (await fetch(`${srv.url}/live/lane?s=building`, { headers: { cookie } })).text(); |
| 299 | 302 | expect(lane).toContain("A cost ledger per delivery"); |
| 300 | 303 | expect(lane).not.toContain("data-reading"); |
| 301 | const forges = await (await fetch(`${srv.url}/live/forges`, { headers: { cookie } })).text(); | |
| 302 | expect(forges).toContain("hosted forge"); | |
| 304 | // the hosted forges are a link in the foot, not a region read on the home | |
| 305 | expect(html).toContain('<a href="/forges">Forges</a>'); | |
| 306 | expect((await fetch(`${srv.url}/live/forges`, { headers: { cookie } })).status).toBe(404); | |
| 303 | 307 | const next = await (await fetch(`${srv.url}/`, { headers: { cookie } })).text(); |
| 304 | 308 | expect(next).not.toContain("data-reading"); |
| 305 | 309 | expect(next).toContain("A cost ledger per delivery"); |
test/home-fork-flows.test.ts +4 −3
| @@ -51,12 +51,13 @@ describe("home fork flows line", () => { | ||
| 51 | 51 | |
| 52 | 52 | test("a fork that offered upstream sees its counts, linked", async () => { |
| 53 | 53 | const html = await get("bob"); |
| 54 | expect(html).toContain('<a href="/forks/flows">1 offer waiting upstream · 0 offered to you · 0 forks behind</a>'); | |
| 54 | // Only what is there is said: a zero is no fact. | |
| 55 | expect(html).toContain('<a href="/forks/flows">1 offer waiting upstream</a>'); | |
| 55 | 56 | }); |
| 56 | 57 | |
| 57 | 58 | test("the parent's owner sees what was offered to them", async () => { |
| 58 | 59 | const html = await get("alice"); |
| 59 | expect(html).toContain("0 offers waiting upstream · 1 offered to you · 0 forks behind"); | |
| 60 | expect(html).toContain('<a href="/forks/flows">1 offered to you</a>'); | |
| 60 | 61 | }); |
| 61 | 62 | |
| 62 | 63 | test("a fork behind its parent counts as one fork behind, with no offers made", async () => { |
| @@ -69,7 +70,7 @@ describe("home fork flows line", () => { | ||
| 69 | 70 | await commitToBranch(app, users["alice"]!, parent.value, { message: "Theirs", files: [{ path: "b.txt", content: "b\n" }] }); |
| 70 | 71 | expect((await forkRelation(app, fork.value, parent.value))?.state).toBe("diverged"); |
| 71 | 72 | const html = await get("dana"); |
| 72 | expect(html).toContain('<a href="/forks/flows">0 offers waiting upstream · 0 offered to you · 1 fork behind</a>'); | |
| 73 | expect(html).toContain('<a href="/forks/flows">1 fork behind</a>'); | |
| 73 | 74 | }); |
| 74 | 75 | |
| 75 | 76 | test("no family, no line", async () => { |
test/home-kpi-row.test.ts +98 −38
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | * Home's figures row (#2871): the tiles, their links, studio words only, a sparkline of 24 points | |
| 3 | * and one of 30 days of visitors (#3186). | |
| 2 | * Home's figures row (#2871): the one row (`homeRow`, each number once), its links, studio words | |
| 3 | * only, a series of 24 hourly points, and the readings behind it (#3186). | |
| 4 | 4 | */ |
| 5 | 5 | import { Database } from "bun:sqlite"; |
| 6 | 6 | import { bugTables, reachTables } from "./helpers/reach-tables.ts"; |
| @@ -14,7 +14,11 @@ import { createRepo as createRepoRow } from "../src/core/repos.ts"; | ||
| 14 | 14 | import { createUser } from "../src/core/users.ts"; |
| 15 | 15 | import { serve } from "../src/http/server.ts"; |
| 16 | 16 | import { id } from "../src/kernel/id.ts"; |
| 17 | import { checkTime, kpiLines, sparkText, waitingWords } from "../src/flow/kpi_words.ts"; | |
| 17 | import { checkTime, waitingWords } from "../src/flow/kpi_words.ts"; | |
| 18 | import type { Figures } from "../src/flow/figures.ts"; | |
| 19 | import type { LanePicture, StripPart } from "../src/flow/lanes.ts"; | |
| 20 | import type { IdleReason } from "../src/crew/idle_reason.ts"; | |
| 21 | import { homeRow, homeRowLines } from "../src/web/home_row.ts"; | |
| 18 | 22 | import { running } from "../src/kernel/version.ts"; |
| 19 | 23 | import { components } from "../src/web/style/components.ts"; |
| 20 | 24 | import { liveNow } from "../src/web/studio/kpi_row.ts"; |
| @@ -69,30 +73,82 @@ describe("the builders figure from the database", () => { | ||
| 69 | 73 | }); |
| 70 | 74 | }); |
| 71 | 75 | |
| 76 | /** A picture with only what the row reads; the rest of the worker's picture is not looked at. */ | |
| 77 | function pictureOf( | |
| 78 | strip: Partial<StripPart> | null, | |
| 79 | builders = { running: 2, slots: 4 }, | |
| 80 | figures: Figures | null = null, | |
| 81 | idle: IdleReason | null = null, | |
| 82 | ): LanePicture { | |
| 83 | const full: StripPart | null = | |
| 84 | strip === null | |
| 85 | ? null | |
| 86 | : { landed: 6, landedHours: hours(6), lead: { landed: 6, medianHours: 2, maxHours: 5 }, week: null, weekSpendUsd: 12, ceilingUsd: null, needs: [], ...strip }; | |
| 87 | return { builders, strip: full, figures, idle } as unknown as LanePicture; | |
| 88 | } | |
| 89 | ||
| 90 | /** Figures with only what the row's last cards read. */ | |
| 91 | function figuresOf(over: { backupAt?: string | null; visitorsToday?: number; load?: number | null; bugs?: { open: number; overdue: number } | null } = {}): Figures { | |
| 92 | return { | |
| 93 | visitors: { today: over.visitorsToday ?? 5, week: 31, days: new Array<number>(30).fill(0), accountsToday: 3, accounts: 12 }, | |
| 94 | speed: { load: over.load === undefined ? 1250 : over.load, lcp: 2400, inp: 180 }, | |
| 95 | shipped: { days: new Array<number>(14).fill(0), total: 0 }, | |
| 96 | spend: { todayUsd: 0, ceilingUsd: null, days: new Array<number>(14).fill(0), totalUsd: 0 }, | |
| 97 | checks: { medianMs: null, days: new Array<number | null>(14).fill(null) }, | |
| 98 | bugs: over.bugs ?? null, | |
| 99 | backup: { at: over.backupAt === undefined ? new Date().toISOString() : over.backupAt, state: null, note: "" }, | |
| 100 | } as unknown as Figures; | |
| 101 | } | |
| 102 | ||
| 103 | const asIs = (idle: IdleReason | null): IdleReason | null => idle; | |
| 104 | const NOW = Date.now(); | |
| 105 | const line = (lines: readonly string[], label: string): string | undefined => lines.find((l) => l.startsWith(`${label}: `)); | |
| 106 | ||
| 72 | 107 | describe("the terminal's figures", () => { |
| 73 | const k = { landedHours: hours(6), landed: 6, live: { sha: "abcdef0123456", at: new Date().toISOString() }, builders: { running: 2, slots: 4, idle: null }, spend: { todayUsd: 12, ceilingUsd: 40 }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }; | |
| 74 | test("the same nine figures in the same words", () => { | |
| 75 | const lines = kpiLines(k, { sha: "abcdef0123456", since: "5m ago" }); | |
| 76 | expect(lines).toHaveLength(9); | |
| 77 | expect(lines).toContain("Last off-box backup never, overdue"); | |
| 78 | expect(lines[4]).toBe("Crew spend today $12 of $40"); | |
| 79 | expect(kpiLines({ ...k, spend: { todayUsd: 0.4, ceilingUsd: null } }, null)[4]).toBe("Crew spend today $0.40, no forge ceiling"); | |
| 80 | expect(lines[3]).toBe("Builders running 2 of 4"); | |
| 81 | expect(kpiLines({ ...k, builders: { running: 0, slots: 0, idle: null } }, null)[3]).toBe("Builders running —, no slots set"); | |
| 82 | expect(lines[0]).toContain("Shipped per hour 0.3"); | |
| 83 | expect(lines[0]).toContain("6 changes in 24 h"); | |
| 84 | expect(lines[1]).toContain("Live version abcdef0"); | |
| 85 | expect(lines[2]).toBe("Median check time 3m 05s"); | |
| 108 | test("the same row in the same words, one line a figure, each figure once", () => { | |
| 109 | const lines = homeRowLines(homeRow(pictureOf({}), asIs, NOW)); | |
| 110 | expect(lines).toEqual([ | |
| 111 | "Shipped in 24 hours: 6 · changes landed on main /board", | |
| 112 | "Median open to landed: 2h · median of 6 changes, 24 hours /boards", | |
| 113 | "Crew running: 2 of 4 · builders at work now /settings/crew", | |
| 114 | "Week used: about $12.00 · spent by the crew in seven days, at list price; the provider has not reported its week /settings/crew", | |
| 115 | ]); | |
| 116 | expect(line(homeRowLines(homeRow(pictureOf({}, { running: 0, slots: 0 }), asIs, NOW)), "Crew running")).toBe("Crew running: 0 · no builder slots set /settings/crew"); | |
| 117 | // A median under a second reads so, never "0ms". | |
| 118 | expect(line(homeRowLines(homeRow(pictureOf({ lead: { landed: 3, medianHours: 0, maxHours: 0 } }), asIs, NOW)), "Median open to landed")).toBe("Median open to landed: under a second · median of 3 changes, 24 hours /boards"); | |
| 119 | expect(line(homeRowLines(homeRow(pictureOf({ landed: 1 }), asIs, NOW)), "Shipped in 24 hours")).toBe("Shipped in 24 hours: 1 · change landed on main /board"); | |
| 86 | 120 | expect(lines.join(" ")).not.toMatch(/commit|merge|branch|repositor|pull request/i); |
| 87 | 121 | }); |
| 88 | test("the block sparkline has 24 cells, the busy hour tallest", () => { | |
| 89 | const s = sparkText(hours(4)); | |
| 90 | expect([...s]).toHaveLength(24); | |
| 91 | expect(s[20]).toBe("█"); | |
| 122 | ||
| 123 | test("the week against the ceiling: under it quiet, at or past it the figure asks for someone", () => { | |
| 124 | const under = homeRow(pictureOf({ weekSpendUsd: 84, ceilingUsd: 40 }), asIs, NOW).find((r) => r.label === "Week used")!; | |
| 125 | expect(under.value).toBe("about 30%"); | |
| 126 | expect(under.tone).toBeNull(); | |
| 127 | const over = homeRow(pictureOf({ weekSpendUsd: 300, ceilingUsd: 40 }), asIs, NOW).find((r) => r.label === "Week used")!; | |
| 128 | expect(over.value).toBe("about 107%"); | |
| 129 | expect(over.tone).toBe("attn"); | |
| 130 | // The provider's own week, when it has reported one, is the figure. | |
| 131 | const metered = homeRow(pictureOf({ week: { usedPct: 92, mayUsePct: 90 } }), asIs, NOW).find((r) => r.label === "Week used")!; | |
| 132 | expect([metered.value, metered.tone]).toEqual(["92%", "attn"]); | |
| 133 | }); | |
| 134 | ||
| 135 | test("the shipped series has 24 points, oldest first, the busy hour tallest", () => { | |
| 136 | const shipped = homeRow(pictureOf({ landedHours: hours(4) }), asIs, NOW)[0]!; | |
| 137 | expect(shipped.series).toHaveLength(24); | |
| 138 | expect(shipped.series![20]).toBe(4); | |
| 139 | expect(Math.max(...shipped.series!)).toBe(4); | |
| 140 | }); | |
| 141 | ||
| 142 | test("an idle crew's reason is said on the crew figure, and links to what fixes it", () => { | |
| 143 | const idle = { word: "nothing ready", href: "/map" }; | |
| 144 | const row = homeRow(pictureOf({}, { running: 0, slots: 1 }, null, idle), asIs, NOW); | |
| 145 | expect(line(homeRowLines(row), "Crew running")).toBe("Crew running: 0 of 1 · idle: nothing ready /map"); | |
| 146 | // A busy crew has no free slot, so no reason is asked. | |
| 147 | const busy = homeRow(pictureOf({}, { running: 1, slots: 1 }, null, idle), () => { throw new Error("asked"); }, NOW); | |
| 148 | expect(busy.find((r) => r.label === "Crew running")!.note).toBe("builders at work now"); | |
| 92 | 149 | }); |
| 93 | 150 | }); |
| 94 | 151 | |
| 95 | ||
| 96 | 152 | describe("the spend figure from the database", () => { |
| 97 | 153 | test("only today's agent runs count, not yesterday's", async () => { |
| 98 | 154 | const { Database } = await import("bun:sqlite"); |
| @@ -118,21 +174,25 @@ describe("the spend figure from the database", () => { | ||
| 118 | 174 | }); |
| 119 | 175 | |
| 120 | 176 | |
| 121 | describe("the reach tiles", () => { | |
| 122 | ||
| 123 | test("the terminal draws the 30 days as one block per day", () => { | |
| 124 | const days = Array.from({ length: 30 }, (_, i) => (i === 29 ? 8 : 0)); | |
| 125 | const reach = { usersToday: 0, usersTotal: 1, visitorsToday: 8, visitors7d: 8, visitorDays: days, loadP75: null, inpP75: null, lcpP75: null }; | |
| 126 | const line = kpiLines({ 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).find((l) => l.startsWith("Reporting browsers"))!; | |
| 127 | expect(line).toContain("▁".repeat(29) + "█"); | |
| 177 | describe("the reach figures", () => { | |
| 178 | test("visitors and page speed join the row from the figures, once each", () => { | |
| 179 | const lines = homeRowLines(homeRow(pictureOf({}, undefined, figuresOf()), asIs, NOW)); | |
| 180 | expect(line(lines, "Visitors")).toStartWith("Visitors: 5 · visitors today /boards/reach"); | |
| 181 | expect(line(lines, "Page speed")).toStartWith("Page speed: 1.3s · page load, 75th percentile /boards/reach"); | |
| 182 | expect(lines.filter((l) => l.startsWith("Visitors: "))).toHaveLength(1); | |
| 183 | expect(lines.filter((l) => l.startsWith("Page speed: "))).toHaveLength(1); | |
| 184 | expect(line(homeRowLines(homeRow(pictureOf({}, undefined, figuresOf({ visitorsToday: 1, load: null })), asIs, NOW)), "Page speed")).toContain("no page view measured it in 7 days"); | |
| 128 | 185 | }); |
| 129 | 186 | |
| 130 | test("the terminal says the same", () => { | |
| 131 | const lines = kpiLines({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: { usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, visitorDays: new Array<number>(30).fill(0), loadP75: 1250, inpP75: 180, lcpP75: 2400 }, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null }, spend: { todayUsd: 0, ceilingUsd: null } }, null); | |
| 132 | expect(lines.find((l) => l.startsWith("Reporting browsers"))).toContain("Reporting browsers 5 today, 31 in 7 days"); | |
| 133 | expect(lines).toContain("Accounts 3 of 12 seen today"); | |
| 134 | expect(lines.find((l) => l.startsWith("Reporting browsers"))).toContain("▁".repeat(30)); | |
| 135 | expect(lines).toContain("Reported page speed loads in 1.3 s, LCP 2.4 s · INP 180 ms"); | |
| 187 | test("the off-box backup joins only while it is overdue", () => { | |
| 188 | expect(line(homeRowLines(homeRow(pictureOf({}, undefined, figuresOf()), asIs, NOW)), "Off-box backup")).toBeUndefined(); | |
| 189 | // Open bugs, likewise: on the row only while one is past its clock. | |
| 190 | expect(line(homeRowLines(homeRow(pictureOf({}, undefined, figuresOf({ bugs: { open: 3, overdue: 0 } })), asIs, NOW)), "Open bugs")).toBeUndefined(); | |
| 191 | expect(line(homeRowLines(homeRow(pictureOf({}, undefined, figuresOf({ bugs: { open: 3, overdue: 1 } })), asIs, NOW)), "Open bugs")).toMatch(/^Open bugs: 3 · open bugs /); | |
| 192 | const stale = homeRow(pictureOf({}, undefined, figuresOf({ backupAt: new Date(NOW - 2 * 86_400_000).toISOString() })), asIs, NOW); | |
| 193 | const backup = stale.find((r) => r.label === "Off-box backup")!; | |
| 194 | expect(backup.tone).toBe("attn"); | |
| 195 | expect(backup.href).toBe("/settings/backups"); | |
| 136 | 196 | }); |
| 137 | 197 | }); |
| 138 | 198 | |
| @@ -274,10 +334,10 @@ describe("home waiting line", () => { | ||
| 274 | 334 | }); |
| 275 | 335 | |
| 276 | 336 | describe("the forge ceiling hit (#5798)", () => { |
| 277 | const base = { landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0, idle: null } }; | |
| 278 | ||
| 279 | test("under the cap there is no hit; with no cap both doors say no forge ceiling", () => { | |
| 280 | expect(kpiLines({ ...base, spend: { todayUsd: 5, ceilingUsd: null } }, null)[4]).toContain("no forge ceiling"); | |
| 337 | test("with no cap the week is said in dollars, not against a ceiling", () => { | |
| 338 | const week = homeRow(pictureOf({ weekSpendUsd: 5, ceilingUsd: null }), asIs, NOW).find((r) => r.label === "Week used")!; | |
| 339 | expect(week.value).toBe("about $5.00"); | |
| 340 | expect(week.tone).toBeNull(); | |
| 281 | 341 | }); |
| 282 | 342 | |
| 283 | 343 | test("the hit time is when the run that crossed the cap was created", async () => { |
test/home-kpis.test.ts +3 −3
| @@ -157,9 +157,9 @@ describe("terminal dashboard figures", () => { | ||
| 157 | 157 | await settleApp(tui); |
| 158 | 158 | const text = tui.screen.toText(); |
| 159 | 159 | tui.stop?.(); |
| 160 | expect(text).toContain("Shipped per hour"); | |
| 161 | expect(text).toContain("nothing live yet"); | |
| 162 | expect(text).toContain("Median check time"); | |
| 160 | // The home's one row, then the live version the page's footer says. | |
| 161 | expect(text).toContain("Shipped in 24 hours: "); | |
| 162 | expect(text).toContain("Live version: nothing live yet"); | |
| 163 | 163 | } finally { |
| 164 | 164 | if (saved.c !== undefined) process.env["FORGE_COMMIT"] = saved.c; |
| 165 | 165 | if (saved.a !== undefined) process.env["FORGE_APP_COMMIT"] = saved.a; |
test/home-no-shift.test.ts +5 −24
| @@ -12,9 +12,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 12 | 12 | import { createSession } from "../src/core/sessions.ts"; |
| 13 | 13 | import { serve, type Servers } from "../src/http/server.ts"; |
| 14 | 14 | import { LANES } from "../src/flow/lanes_read.ts"; |
| 15 | import { readingForges, readingLane, readingStrip, readingTable } from "../src/web/pages/home_flow.ts"; | |
| 15 | import { readingLane, readingStrip, readingTable } from "../src/web/pages/home_flow.ts"; | |
| 16 | 16 | import { parseTable } from "../src/flow/lanes_table.ts"; |
| 17 | import { figuresSection } from "../src/web/pages/home_figures.ts"; | |
| 18 | 17 | import { seedHomeFlow } from "./helpers/home-flow-seed.ts"; |
| 19 | 18 | |
| 20 | 19 | const tags = (html: string): { name: string; attrs: string }[] => |
| @@ -130,7 +129,7 @@ describe("the signed-in home", () => { | ||
| 130 | 129 | css = await get(href); |
| 131 | 130 | rules = rulesOf(css); |
| 132 | 131 | // The live addresses warm the picture; the page after them is the loaded one. |
| 133 | for (const path of ["/live/strip", "/live/figures", "/live/table", "/live/lane?s=ready"]) await get(path); | |
| 132 | for (const path of ["/live/strip", "/live/table", "/live/lane?s=ready"]) await get(path); | |
| 134 | 133 | loaded = await get("/"); |
| 135 | 134 | }); |
| 136 | 135 | afterAll(async () => { |
| @@ -147,7 +146,7 @@ describe("the signed-in home", () => { | ||
| 147 | 146 | const q = parseTable(new URLSearchParams()); |
| 148 | 147 | // Only an admin has a strip, so only an admin's is reserved for. |
| 149 | 148 | expect(readingStrip(false)).toBeNull(); |
| 150 | const states = [readingStrip(true), readingTable(q), readingForges(), ...LANES.map((k) => readingLane(k, null))]; | |
| 149 | const states = [readingStrip(true), readingTable(q), ...LANES.map((k) => readingLane(k, null))]; | |
| 151 | 150 | for (const state of states) { |
| 152 | 151 | expect(String(state)).toContain("data-reading"); |
| 153 | 152 | expect(unreserved(String(state), rules)).toEqual([]); |
| @@ -155,7 +154,7 @@ describe("the signed-in home", () => { | ||
| 155 | 154 | }); |
| 156 | 155 | |
| 157 | 156 | test("a reading page carries only the regions this file reserves for, and the loaded page none", () => { |
| 158 | const named = new Set(["hf-strip", "hf-forges", "hf-table", "hf-figures-body"]); | |
| 157 | const named = new Set(["hf-strip", "hf-table"]); | |
| 159 | 158 | const left = tags(reading).filter((t) => attr(t.attrs, "data-reading") !== null).map((t) => attr(t.attrs, "id") ?? ""); |
| 160 | 159 | for (const id of left) expect(named.has(id) || id.startsWith("lane-")).toBe(true); |
| 161 | 160 | expect(tags(loaded).filter((t) => attr(t.attrs, "data-reading") !== null)).toEqual([]); |
| @@ -163,7 +162,7 @@ describe("the signed-in home", () => { | ||
| 163 | 162 | |
| 164 | 163 | test("the reading strip is the loaded strip's figures: same labels, links and count", () => { |
| 165 | 164 | const figs = (h: string): string[] => [...h.matchAll(/<a class="hf-fig" href="([^"]+)"[^>]*>\s*<span class="hf-fig-label">([^<]*)</g)].map((m) => `${m[2]} ${m[1]}`); |
| 166 | expect(figs(loaded)).toHaveLength(5); | |
| 165 | expect(figs(loaded)).toHaveLength(6); | |
| 167 | 166 | expect(figs(reading)).toEqual(figs(loaded)); |
| 168 | 167 | }); |
| 169 | 168 | |
| @@ -182,22 +181,4 @@ describe("the signed-in home", () => { | ||
| 182 | 181 | expect(need(px(css, ".tb-region[data-reading]", "min-height"))).toBeGreaterThanOrEqual(2 * row + need(px(css, ".tb-region", "gap"))); |
| 183 | 182 | }); |
| 184 | 183 | |
| 185 | test("the figures' reading state reserves the loaded row of cards, summed from the card's own rules", () => { | |
| 186 | const section = String(figuresSection(undefined, Date.now())); | |
| 187 | expect(section).toContain("data-reading"); | |
| 188 | expect(unreserved(section, rules)).toEqual([]); | |
| 189 | const card = | |
| 190 | need(px(css, ".fg-card", "padding")) + | |
| 191 | 2 + | |
| 192 | 18 + // the label: 12px at the body's 1.5 line | |
| 193 | need(px(css, ".fg-n", "line-height")) + | |
| 194 | need(px(css, ".fg-note", "min-height")) + | |
| 195 | need(px(css, ".fg-chart", "height")) + | |
| 196 | need(px(css, ".fg-chart", "margin-top")) + | |
| 197 | need(px(css, ".fg-change", "min-height")) + | |
| 198 | need(px(css, ".fg-axis", "min-height")) + | |
| 199 | 5 * need(px(css, ".fg-card", "gap")); | |
| 200 | // The card's padding is "12px 16px": top and bottom make 24. | |
| 201 | expect(need(px(css, ".fg-body", "min-height"))).toBeGreaterThanOrEqual(card - 16 * 2 + 12); | |
| 202 | }); | |
| 203 | 184 | }); |
test/home-one-row.test.ts added +100
| @@ -0,0 +1,100 @@ | ||
| 1 | /** | |
| 2 | * The owner's home says each figure once (2026-12-02): one row (`homeRow`) on the page and in the | |
| 3 | * terminal, never the old second, third and fourth tellings (the live version, the median ship | |
| 4 | * time, the crew card, the hosted forges line, the figures section). | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, 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 { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createSession } from "../src/core/sessions.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 14 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 15 | import { seedHomeFlow, type HomeFlowSeed } from "./helpers/home-flow-seed.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | import { settleApp } from "./helpers/tui.ts"; | |
| 18 | import { deskStrip, homeNotes } from "../src/web/desk_strip.ts"; | |
| 19 | import type { DeskNote } from "../src/core/desk.ts"; | |
| 20 | import { readingStrip } from "../src/web/pages/home_flow.ts"; | |
| 21 | import { ROW_ALWAYS } from "../src/web/home_row.ts"; | |
| 22 | ||
| 23 | quietLogs(); | |
| 24 | ||
| 25 | const LABELS = ["Shipped in 24 hours", "Median open to landed", "Crew running", "Week used", "Visitors", "Page speed"]; | |
| 26 | const GONE = ["Live version", "Median ship time", "Crew, last", "hosted forges", 'id="hf-figures"']; | |
| 27 | ||
| 28 | /** How many times `needle` occurs in `hay`. */ | |
| 29 | const times = (hay: string, needle: string): number => hay.split(needle).length - 1; | |
| 30 | ||
| 31 | describe("the owner's home says each figure once", () => { | |
| 32 | let dataDir: string; | |
| 33 | let app: App; | |
| 34 | let servers: Servers; | |
| 35 | let seed: HomeFlowSeed; | |
| 36 | ||
| 37 | beforeAll(async () => { | |
| 38 | dataDir = await mkdtemp(join(tmpdir(), "forge-home-one-row-")); | |
| 39 | app = createApp({ dataDir, port: 0 }); | |
| 40 | seed = await seedHomeFlow(app); | |
| 41 | servers = await serve(app); | |
| 42 | }); | |
| 43 | afterAll(async () => { | |
| 44 | servers.stop(); | |
| 45 | app.close(); | |
| 46 | await rm(dataDir, { recursive: true, force: true }); | |
| 47 | }); | |
| 48 | ||
| 49 | test("the page: each label once, none of the old tellings", async () => { | |
| 50 | const res = await fetch(`${servers.url}/`, { headers: { cookie: `forge_session=${createSession(app.db, seed.owner.id).token}` } }); | |
| 51 | expect(res.status).toBe(200); | |
| 52 | const body = await res.text(); | |
| 53 | for (const label of LABELS) expect({ label, times: times(body, label) }).toEqual({ label, times: 1 }); | |
| 54 | for (const gone of GONE) expect({ gone, there: body.includes(gone) }).toEqual({ gone, there: false }); | |
| 55 | }); | |
| 56 | ||
| 57 | test("the reading row is the loaded row's own list: the same labels in the same order, words for the value", async () => { | |
| 58 | const labelsOf = (html: string): string[] => [...html.matchAll(/class="hf-fig-label">([^<]*)</g)].map((m) => m[1]!.trim()); | |
| 59 | const reading = String(readingStrip(true)); | |
| 60 | expect(labelsOf(reading)).toEqual(ROW_ALWAYS.map(([label]) => label)); | |
| 61 | expect(reading).not.toContain("—"); | |
| 62 | const res = await fetch(`${servers.url}/`, { headers: { cookie: `forge_session=${createSession(app.db, seed.owner.id).token}` } }); | |
| 63 | const strip = (await res.text()).match(/<section class="hf-strip"[\s\S]*?<\/section>/)?.[0] ?? ""; | |
| 64 | expect(labelsOf(strip)).toEqual(labelsOf(reading)); | |
| 65 | }); | |
| 66 | ||
| 67 | test("the filter is a toggle whose words say what it does", async () => { | |
| 68 | const page = async (q: string) => (await fetch(`${servers.url}/${q}`, { headers: { cookie: `forge_session=${createSession(app.db, seed.owner.id).token}` } })).text(); | |
| 69 | expect(await page("?view=lanes")).toMatch(/id="hf-waits" href="\/\?view=lanes&waits=me"[^>]*>Show only what waits for me</); | |
| 70 | expect(await page("?view=lanes&waits=me")).toMatch(/id="hf-waits" href="\/\?view=lanes"[^>]*aria-current="true">Show everything</); | |
| 71 | }); | |
| 72 | ||
| 73 | test("the desk line leaves out what a crew member is doing (the Building lane says it) and keeps a hold", async () => { | |
| 74 | const note = (kind: DeskNote["kind"], body: string, at: string): DeskNote => ({ id: `n-${kind}`, repoId: seed.repos.notes.id, authorId: seed.owner.id, kind, body, createdAt: at, expiresAt: "2999-01-01T00:00:00.000Z" }) as DeskNote; | |
| 75 | // The newest first, as the desk is read: the doing note is newer, and still not said. | |
| 76 | const notes = [note("doing", "Doing notes#2: the draft", "2026-12-02T10:01:00.000Z"), note("hold", "the release waits for the key to rotate", "2026-12-02T10:00:00.000Z")]; | |
| 77 | const line = String(deskStrip(app.db, homeNotes(notes))); | |
| 78 | expect(line).toContain("the release waits for the key to rotate"); | |
| 79 | expect(line).not.toContain("notes#2: the draft"); | |
| 80 | // The page draws its desk line from the same choice. | |
| 81 | const body = await (await fetch(`${servers.url}/`, { headers: { cookie: `forge_session=${createSession(app.db, seed.owner.id).token}` } })).text(); | |
| 82 | expect(body).toContain('id="desk-strip"'); | |
| 83 | }); | |
| 84 | ||
| 85 | test("the terminal's home: the same labels, once each", async () => { | |
| 86 | const { app: tui } = createForgeApp( | |
| 87 | app, | |
| 88 | { sshUsername: seed.owner.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: seed.owner }, | |
| 89 | { terminal: headlessTerminal(200, 60), exitHooks: false }, | |
| 90 | ); | |
| 91 | tui.start(); | |
| 92 | await settleApp(tui); | |
| 93 | const text = tui.screen.toText(); | |
| 94 | tui.stop(); | |
| 95 | for (const label of LABELS) expect({ label, times: times(text, `${label}: `) }).toEqual({ label, times: 1 }); | |
| 96 | // The terminal has no footer: it says the live version on one line after the row, once. | |
| 97 | for (const gone of GONE.filter((g) => g !== "Live version")) expect({ gone, there: text.includes(gone) }).toEqual({ gone, there: false }); | |
| 98 | expect(times(text, "Live version: ")).toBe(1); | |
| 99 | }); | |
| 100 | }); |
test/home-vitals.test.ts +28 −22
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | * Home's quiet speed note (#10738): p75 LCP and INP over seven days from the | |
| 3 | * first-party beacon's page_vital, "no visitors yet" when empty, and the whole | |
| 4 | * reach read stays at a fixed number of queries however many views there are. | |
| 2 | * Home's page speed (#10738): p75 LCP and INP over seven days from the first-party beacon's | |
| 3 | * page_vital, the row's Page speed figure (`homeRow`) on both doors, and the whole reach read stays | |
| 4 | * at a fixed number of queries however many views there are. | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { Database } from "bun:sqlite"; |
| @@ -10,25 +10,32 @@ import { mkdtemp } from "node:fs/promises"; | ||
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| 12 | 12 | import { createApp } from "../src/app.ts"; |
| 13 | import { readReach, NO_REACH, type Reach } from "../src/flow/reach.ts"; | |
| 14 | import type { Kpis } from "../src/flow/kpis.ts"; | |
| 15 | import { kpiLines, vitalsNote } from "../src/flow/kpi_words.ts"; | |
| 13 | import { readReach } from "../src/flow/reach.ts"; | |
| 14 | import type { Figures } from "../src/flow/figures.ts"; | |
| 15 | import type { LanePicture } from "../src/flow/lanes.ts"; | |
| 16 | import { homeRow, homeRowLines } from "../src/web/home_row.ts"; | |
| 16 | 17 | import { expectWork } from "./helpers/work.ts"; |
| 17 | 18 | import { once } from "./helpers/statements.ts"; |
| 18 | 19 | |
| 19 | 20 | const NOW = new Date("2026-10-19T12:00:00.000Z"); |
| 20 | const kpis = (reach: Reach): Kpis => ({ landedHours: 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 }); | |
| 21 | ||
| 22 | describe("home vitals note", () => { | |
| 23 | test("empty says no visitors yet, without a figure", () => { | |
| 24 | expect(vitalsNote(NO_REACH)).toBe("no visitors yet"); | |
| 25 | }); | |
| 26 | ||
| 27 | test("only the measured figure shows when one of LCP or INP is missing", () => { | |
| 28 | expect(vitalsNote({ ...NO_REACH, lcpP75: 2500, inpP75: null })).toBe("LCP 2.5 s"); | |
| 29 | expect(vitalsNote({ ...NO_REACH, lcpP75: null, inpP75: 120 })).toBe("INP 120 ms"); | |
| 30 | }); | |
| 21 | /** A picture with only the figures the row's Page speed reads. */ | |
| 22 | const picture = (speed: Figures["speed"]): LanePicture => | |
| 23 | ({ | |
| 24 | builders: { running: 0, slots: 0 }, | |
| 25 | strip: null, | |
| 26 | idle: null, | |
| 27 | figures: { | |
| 28 | visitors: { today: 0, week: 0, days: [], accountsToday: 0, accounts: 0 }, | |
| 29 | speed, | |
| 30 | shipped: { days: [], total: 0 }, | |
| 31 | spend: { todayUsd: 0, ceilingUsd: null, days: [], totalUsd: 0 }, | |
| 32 | checks: { medianMs: null, days: [] }, | |
| 33 | bugs: null, | |
| 34 | backup: { at: null, state: null, note: "" }, | |
| 35 | }, | |
| 36 | }) as unknown as LanePicture; | |
| 31 | 37 | |
| 38 | describe("home page speed", () => { | |
| 32 | 39 | test("p75 LCP and INP over 7 days, old days left out, one query", async () => { |
| 33 | 40 | const app = createApp({ dataDir: await mkdtemp(join(tmpdir(), "forge-vitals-")), port: 0 }); |
| 34 | 41 | const db: Database = app.db; |
| @@ -46,13 +53,12 @@ describe("home vitals note", () => { | ||
| 46 | 53 | expect(queries).toBeLessThanOrEqual(2); |
| 47 | 54 | expect(reach.lcpP75).toBe(3000); |
| 48 | 55 | expect(reach.inpP75).toBe(300); |
| 49 | expect(vitalsNote(reach)).toBe("LCP 3.0 s · INP 300 ms"); | |
| 50 | 56 | }); |
| 51 | 57 | |
| 52 | test("the terminal line says LCP and INP too, not the old reacts-in words", () => { | |
| 53 | const line = (r: Reach) => kpiLines(kpis(r), null, NOW).find((l) => l.startsWith("Reported page speed"))!; | |
| 54 | expect(line({ ...NO_REACH, loadP75: 900, lcpP75: 2500, inpP75: 120 })).toBe("Reported page speed loads in 900 ms, LCP 2.5 s · INP 120 ms"); | |
| 55 | expect(line(NO_REACH)).toBe("Reported page speed no page views measured yet, no visitors yet"); | |
| 58 | test("the terminal's Page speed line says the load p75, or that no page view measured it", () => { | |
| 59 | const line = (speed: Figures["speed"]) => homeRowLines(homeRow(picture(speed), (i) => i, NOW.getTime())).find((l) => l.startsWith("Page speed: ")); | |
| 60 | expect(line({ load: 900, lcp: 2500, inp: 120 })).toBe("Page speed: 900ms · page load, 75th percentile /boards/reach?range=7d"); | |
| 61 | expect(line({ load: null, lcp: null, inp: null })).toBe("Page speed: none yet · no page view measured it in 7 days /boards/reach?range=7d"); | |
| 56 | 62 | }); |
| 57 | 63 | |
| 58 | 64 | test("reading a seeded week of 3000 views stays at a fixed few statements", async () => { |
test/idle-reason.test.ts +6 −3
| @@ -19,7 +19,9 @@ import { forgetWeek } from "../src/crew/week_read.ts"; | ||
| 19 | 19 | import { noteLimit } from "../src/core/standing.ts"; |
| 20 | 20 | import { addSubscription, PLATFORM, setGrants, setLimited } from "../src/core/subscriptions.ts"; |
| 21 | 21 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 22 | import { idleLine, idleReason } from "../src/crew/idle_reason.ts"; | |
| 22 | import { idleReason } from "../src/crew/idle_reason.ts"; | |
| 23 | import type { LanePicture } from "../src/flow/lanes.ts"; | |
| 24 | import { homeRow, homeRowLines } from "../src/web/home_row.ts"; | |
| 23 | 25 | |
| 24 | 26 | const NOW = new Date("2026-10-02T12:00:00Z"); |
| 25 | 27 | |
| @@ -149,7 +151,8 @@ describe("idleReason", () => { | ||
| 149 | 151 | expect(idleReason(app, NOW)).toEqual({ word: "none startable", href: "/map" }); |
| 150 | 152 | }); |
| 151 | 153 | |
| 152 | test("the line says the word and the link", () => { | |
| 153 | expect(idleLine({ word: "flow only", href: "/map" })).toBe("Builders idle: flow only (/map)"); | |
| 154 | test("the home row's crew figure says the word and the link", () => { | |
| 155 | const picture = { builders: { running: 0, slots: 1 }, strip: null, figures: null, idle: { word: "flow only", href: "/map" } } as unknown as LanePicture; | |
| 156 | expect(homeRowLines(homeRow(picture, (i) => i, Date.now()))).toContain("Crew running: 0 of 1 · idle: flow only /map"); | |
| 154 | 157 | }); |
| 155 | 158 | }); |
test/kpi-words.test.ts +2 −24
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | import { backupAge, backupOverdue, buildersValue, speedWords, spendValue, trendText, usersValue, visitorsNote, visitorsValue } from "../src/flow/kpi_words.ts"; | |
| 2 | import { backupAge, backupOverdue, buildersValue, speedWords, spendValue, usersValue, visitorsValue } from "../src/flow/kpi_words.ts"; | |
| 3 | 3 | import { NO_REACH, type Reach } from "../src/flow/reach.ts"; |
| 4 | 4 | |
| 5 | 5 | const NOW = new Date("2026-10-27T12:00:00.000Z"); |
| @@ -10,25 +10,6 @@ const clean = (s: string): void => { | ||
| 10 | 10 | for (const bad of ["NaN", "undefined", "Infinity", "-0"]) expect(s).not.toContain(bad); |
| 11 | 11 | }; |
| 12 | 12 | |
| 13 | describe("trendText", () => { | |
| 14 | test("empty and all-zero series draw the lowest block, one each", () => { | |
| 15 | expect(trendText([])).toBe(""); | |
| 16 | expect(trendText([0, 0, 0])).toBe("▁▁▁"); | |
| 17 | }); | |
| 18 | test("up, down and flat read in the blocks' height", () => { | |
| 19 | const up = trendText([0, 2, 4, 8]); | |
| 20 | const down = trendText([8, 4, 2, 0]); | |
| 21 | const flat = trendText([3, 3, 3]); | |
| 22 | expect(up).toBe("▁▃▅█"); | |
| 23 | expect(down).toBe("█▅▃▁"); | |
| 24 | expect(flat).toBe("███"); | |
| 25 | expect(up).not.toBe(down); | |
| 26 | }); | |
| 27 | test("a single count of one is a full block", () => { | |
| 28 | expect(trendText([1])).toBe("█"); | |
| 29 | }); | |
| 30 | }); | |
| 31 | ||
| 32 | 13 | describe("spend", () => { |
| 33 | 14 | test("the ten-dollar edge: cents below, whole dollars from ten", () => { |
| 34 | 15 | expect(spendValue({ todayUsd: 9.99, ceilingUsd: null })).toBe("$9.99"); |
| @@ -91,23 +72,20 @@ describe("reach words", () => { | ||
| 91 | 72 | test("zero and no data", () => { |
| 92 | 73 | expect(usersValue(NO_REACH)).toBe("0 of 0"); |
| 93 | 74 | expect(visitorsValue(NO_REACH)).toBe("0 today"); |
| 94 | expect(visitorsNote(NO_REACH)).toBe("0 in 7 days"); | |
| 95 | 75 | }); |
| 96 | 76 | test("one", () => { |
| 97 | 77 | const r = reach({ usersToday: 1, usersTotal: 1, visitorsToday: 1, visitors7d: 1, inpP75: 1 }); |
| 98 | 78 | expect(usersValue(r)).toBe("1 of 1"); |
| 99 | 79 | expect(visitorsValue(r)).toBe("1 today"); |
| 100 | expect(visitorsNote(r)).toBe("1 in 7 days"); | |
| 101 | 80 | }); |
| 102 | 81 | test("many, and react speed crossing a second", () => { |
| 103 | 82 | const r = reach({ usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, inpP75: 180 }); |
| 104 | 83 | expect(usersValue(r)).toBe("3 of 12"); |
| 105 | 84 | expect(visitorsValue(r)).toBe("5 today"); |
| 106 | expect(visitorsNote(r)).toBe("31 in 7 days"); | |
| 107 | 85 | }); |
| 108 | 86 | test("none of them is dirty", () => { |
| 109 | 87 | for (const r of [NO_REACH, reach({ inpP75: 0 })]) { |
| 110 | for (const s of [usersValue(r), visitorsValue(r), visitorsNote(r)]) clean(s); | |
| 88 | for (const s of [usersValue(r), visitorsValue(r)]) clean(s); | |
| 111 | 89 | } |
| 112 | 90 | }); |
| 113 | 91 | }); |
test/lane-times.test.ts +2 −1
| @@ -208,7 +208,8 @@ describe("the home, the terminal and the MCP say it, to whoever may read it", () | ||
| 208 | 208 | expect(lines.slice(0, 2)).toEqual(["", "Lane times"]); |
| 209 | 209 | expect(lines).toHaveLength(8); |
| 210 | 210 | expect(lines.find((l) => l.startsWith("Checks: "))).toMatch(/^Checks: now \S+ \(oldest \S+\) · typical 6m \(p90 8m\) · slowest$/); |
| 211 | expect(lines.find((l) => l.startsWith("Asked: "))).toMatch(/typical —/); | |
| 211 | // A time not known is left out, never a dash. | |
| 212 | expect(lines.find((l) => l.startsWith("Asked: "))).toBe("Asked: no time yet"); | |
| 212 | 213 | expect(laneTimeLines(app.db, getUserByName(app.db, "stranger")!, NOW)).toEqual([]); |
| 213 | 214 | expect(laneTimeLines(app.db, { ...seed.owner, kind: "agent" }, NOW)).toEqual([]); |
| 214 | 215 | expect(laneTimeLines(app.db, null, NOW)).toEqual([]); |
test/release-proof-words.test.ts +4 −12
| @@ -1,9 +1,11 @@ | ||
| 1 | /** What a person reads of a proof: the home page's figure and the /releases card (#12367). */ | |
| 1 | /** | |
| 2 | * What a person reads of a proof: the /releases card (#12367). The home no longer shows a live | |
| 3 | * version. | |
| 4 | */ | |
| 2 | 5 | import { afterEach, beforeEach, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| 5 | 8 | import { join } from "node:path"; |
| 6 | import { proofWords } from "../src/web/pages/home_flow.ts"; | |
| 7 | 9 | import { proofCard } from "../src/web/pages/releases.ts"; |
| 8 | 10 | import type { Proof } from "../src/release/prove.ts"; |
| 9 | 11 | |
| @@ -21,16 +23,6 @@ afterEach(() => { | ||
| 21 | 23 | |
| 22 | 24 | const base: Proof = { version: "9.9.9", at: "2026-11-14T06:00:00.000Z", ok: true }; |
| 23 | 25 | |
| 24 | test("the home figure says a proof is running and when it began, until a pass replaces it", () => { | |
| 25 | const since = "2026-11-14T06:01:30.000Z"; | |
| 26 | expect(proofWords(undefined, "9.9.9", since)).toEqual({ text: "still proving, started 06:01 UTC", tone: null }); | |
| 27 | expect(proofWords({ ...base, ok: false }, "9.9.9", since).text).toBe("still proving, started 06:01 UTC"); | |
| 28 | expect(proofWords({ ...base, version: "9.9.8" }, "9.9.9", since).text).toBe("still proving, started 06:01 UTC"); | |
| 29 | expect(proofWords(base, "9.9.9", since).text).toBe("journey proof passed"); | |
| 30 | expect(proofWords({ ...base, ok: false }, "9.9.9").tone).toBe("attn"); | |
| 31 | expect(proofWords(undefined, "9.9.9").text).toBe("not proven yet"); | |
| 32 | }); | |
| 33 | ||
| 34 | 26 | test("the /releases card counts failed attempts and the last one's tries in one plain word", () => { |
| 35 | 27 | mkdirSync(join(dir, "release"), { recursive: true }); |
| 36 | 28 | writeFileSync(join(dir, "release", "proof.json"), JSON.stringify({ ...base, ok: false, failure: "a stranger's journey failed: x", failures: 2, tries: 3 })); |
test/release-prove.test.ts +16 −7
| @@ -6,16 +6,28 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; |
| 9 | import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; | |
| 9 | import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | |
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| 12 | import { GIVE_UP_MS, HANG_MS, JOURNEY_TRIES, JOURNEY_RETRY_MS, SETTLE_MS, markProving, isNewer, lastProof, leftoverProbes, proofDue, proofNeed, proofNotice, provingSince, proveRelease, proveRunning, QUICK_RETRIES, retryAfter, RETRY_MS, startProving, type Proof, type ProveOptions } from "../src/release/prove.ts"; | |
| 12 | import { GIVE_UP_MS, HANG_MS, JOURNEY_TRIES, JOURNEY_RETRY_MS, SETTLE_MS, markProving, isNewer, lastProof, leftoverProbes, proofDue, proofNeed, proofNotice, proveRelease, proveRunning, QUICK_RETRIES, retryAfter, RETRY_MS, startProving, type Proof, type ProveOptions } from "../src/release/prove.ts"; | |
| 13 | 13 | import { journeyLine, plain } from "../src/release/words.ts"; |
| 14 | 14 | import type { JourneyResult } from "../src/release/journey.ts"; |
| 15 | 15 | import { owned } from "../src/crew/incidents.ts"; |
| 16 | 16 | import type { SmallReading } from "../src/release/small_reading.ts"; |
| 17 | 17 | import type { Footprint } from "../src/system/footprint.ts"; |
| 18 | 18 | |
| 19 | /** | |
| 20 | * The running proof's marker as written (release/proving.json): its start, for `version`, or none. | |
| 21 | */ | |
| 22 | function provingSince(dir: string, version: string): string | undefined { | |
| 23 | try { | |
| 24 | const p = JSON.parse(readFileSync(join(dir, "release", "proving.json"), "utf8")) as { version?: unknown; startedAt?: unknown }; | |
| 25 | return p.version === version && typeof p.startedAt === "string" ? p.startedAt : undefined; | |
| 26 | } catch { | |
| 27 | return undefined; | |
| 28 | } | |
| 29 | } | |
| 30 | ||
| 19 | 31 | const CSS = '<html><link rel="stylesheet" href="/a.css"></html>'; |
| 20 | 32 | |
| 21 | 33 | function site(version: string, over: Record<string, () => Response> = {}) { |
| @@ -456,7 +468,7 @@ describe("proving a release", () => { | ||
| 456 | 468 | stop(); |
| 457 | 469 | }); |
| 458 | 470 | |
| 459 | test("while a proof runs the start time is kept for the home page, and cleared when it ends (#12367)", async () => { | |
| 471 | test("while a proof runs its start time is kept, and cleared when it ends (#12367)", async () => { | |
| 460 | 472 | let release!: () => void; |
| 461 | 473 | const prove = () => new Promise<Proof | undefined>((resolve) => (release = () => resolve(undefined))); |
| 462 | 474 | const stop = startProving({ dataDir: dir, version: "4.2.0", url: "https://forge.test" }, () => {}, 60_000, () => () => {}, prove); |
| @@ -474,12 +486,9 @@ describe("proving a release", () => { | ||
| 474 | 486 | expect(HANG_MS).toBeGreaterThanOrEqual(GIVE_UP_MS + walks + 3 * 60_000); |
| 475 | 487 | }); |
| 476 | 488 | |
| 477 | test("a marker left by a process that died mid-proof is cleared at boot, and one older than the ceiling is not believed", async () => { | |
| 489 | test("a marker left by a process that died mid-proof is cleared at boot", async () => { | |
| 478 | 490 | markProving(dir, "4.2.0", Date.now()); |
| 479 | 491 | expect(provingSince(dir, "4.2.0")).toBeDefined(); |
| 480 | markProving(dir, "4.2.0", Date.now() - HANG_MS - 1000); | |
| 481 | expect(provingSince(dir, "4.2.0")).toBeUndefined(); | |
| 482 | markProving(dir, "4.2.0", Date.now()); | |
| 483 | 492 | // a failed version whose retry is not yet due: the boot finds nothing to prove and says nothing |
| 484 | 493 | writeFileSync(join(dir, "release", "proof.json"), JSON.stringify({ version: "4.2.0", at: new Date().toISOString(), ok: false, failure: "x", failures: 1 })); |
| 485 | 494 | let release!: () => void; |
test/ship-time.test.ts −12
| @@ -14,7 +14,6 @@ import { cachedShipTime } from "../src/flow/ship_cache.ts"; | ||
| 14 | 14 | import { bars, medianOf, percentileOf, readShipTime } from "../src/flow/ship_time.ts"; |
| 15 | 15 | import { shipSentence, shipSpan } from "../src/flow/ship_words.ts"; |
| 16 | 16 | import { serve } from "../src/http/server.ts"; |
| 17 | import { histogramSvg, shipSection } from "../src/web/pages/home_ship.ts"; | |
| 18 | 17 | |
| 19 | 18 | const NOW = new Date("2026-11-20T12:00:00.000Z"); |
| 20 | 19 | // The two cache tests read the real clock, so they seed relative to it; a fixed date ages out of |
| @@ -171,17 +170,6 @@ describe("the slowest tenth, and what its time went to", () => { | ||
| 171 | 170 | }); |
| 172 | 171 | }); |
| 173 | 172 | |
| 174 | test("it draws as a histogram and a list that links each slow issue", async () => { | |
| 175 | const s = await seed(); | |
| 176 | for (let m = 10; m <= 100; m += 10) s.shipped(m); | |
| 177 | const t = readShipTime(s.app.db, NOW); | |
| 178 | expect(String(histogramSvg(t))).toContain("<rect"); | |
| 179 | const page = String(shipSection(t)); | |
| 180 | expect(page).toContain("Median ship time this week: 55 min (p90 1 h 30 min, 10 issues)."); | |
| 181 | expect(page).toContain('href="/alice/r/issues/'); | |
| 182 | expect(page).toMatch(/review .*checks .*conflicts .*waiting/); | |
| 183 | expect(page).toContain("First crew run to closing as done"); | |
| 184 | }); | |
| 185 | 173 | }); |
| 186 | 174 | |
| 187 | 175 | describe("one source, three doors", () => { |
test/snapshot-off-box.test.ts +4 −2
| @@ -18,7 +18,9 @@ import { isOffBox, lastOffBox } from "../src/snapshot/off_box.ts"; | ||
| 18 | 18 | import { lastSnapshotOutcome, noteOffBox, recordSnapshotOutcome } from "../src/snapshot/outcome.ts"; |
| 19 | 19 | import { startSnapshots } from "../src/snapshot/service.ts"; |
| 20 | 20 | import { dirStore, type Store } from "../src/blob/store.ts"; |
| 21 | import { kpiForge } from "../src/tui/screens/dashboard.ts"; | |
| 21 | ||
| 22 | /** What the figures read for the backup's age: the forge's data directory. */ | |
| 23 | const kpiForge = (app: { config: { dataDir: string } }) => ({ ceilingUsd: null, dataDir: app.config.dataDir }); | |
| 22 | 24 | |
| 23 | 25 | describe("isOffBox", () => { |
| 24 | 26 | test("a bucket elsewhere is off the machine; a directory or a loopback bucket is not", () => { |
| @@ -112,7 +114,7 @@ describe("a snapshot that lands", () => { | ||
| 112 | 114 | } |
| 113 | 115 | const kept = lastSnapshotOutcome(app.config.dataDir); |
| 114 | 116 | expect(kept?.offBox).toBe(true); |
| 115 | // The terminal's figures read the same data directory as home. | |
| 117 | // The figures read the backup's age from the same data directory the snapshot wrote. | |
| 116 | 118 | expect(readKpis(app.db, new Date(), kpiForge(app)).backupAt).toBe(kept!.landedAt!); |
| 117 | 119 | }, 30_000); |
| 118 | 120 | }); |
test/tui-dashboard-idle.test.ts +12 −8
| @@ -1,4 +1,7 @@ | ||
| 1 | /** The terminal's dashboard says why the builders are idle in the one line, for an admin alone (#7663). */ | |
| 1 | /** | |
| 2 | * The terminal's dashboard says why the builders are idle on the row's crew line, for an admin | |
| 3 | * alone (#7663). | |
| 4 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -7,11 +10,11 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts"; | ||
| 7 | 10 | import { createRepo } from "../src/actions/repos.ts"; |
| 8 | 11 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 9 | 12 | import { noteMeasure } from "../src/core/measure.ts"; |
| 10 | import { createRun } from "../src/core/runs.ts"; | |
| 13 | import { claimRun, createRun } from "../src/core/runs.ts"; | |
| 11 | 14 | import { PLATFORM } from "../src/core/subscriptions.ts"; |
| 12 | 15 | import { forgetWeek } from "../src/crew/week_read.ts"; |
| 13 | 16 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 14 | import { idleLine, idleReason } from "../src/crew/idle_reason.ts"; | |
| 17 | import { idleReason } from "../src/crew/idle_reason.ts"; | |
| 15 | 18 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 16 | 19 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 17 | 20 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -86,8 +89,8 @@ test("the admin's home prints the reason's line; nobody else's does", async () = | ||
| 86 | 89 | |
| 87 | 90 | const reason = idleReason(forge, new Date()); |
| 88 | 91 | expect(reason).toEqual({ word: "week spent", href: "/meter" }); |
| 89 | expect(await firstScreen(alice)).toContain(idleLine(reason!)); | |
| 90 | expect(await firstScreen(bob)).not.toContain("Builders idle"); | |
| 92 | expect(await firstScreen(alice)).toContain(`Crew running: 0 of 2 · idle: ${reason!.word} ${reason!.href}`); | |
| 93 | expect(await firstScreen(bob)).not.toContain("Crew running"); | |
| 91 | 94 | }); |
| 92 | 95 | |
| 93 | 96 | test("the builders line ends with the reason's word while a slot is free; with every slot busy it has none", async () => { |
| @@ -96,12 +99,13 @@ test("the builders line ends with the reason's word while a slot is free; with e | ||
| 96 | 99 | const reason = idleReason(forge, new Date()); |
| 97 | 100 | expect(reason?.word).toBe("nothing ready"); |
| 98 | 101 | const free = await firstScreen(alice); |
| 99 | expect(free).toMatch(new RegExp(`Builders running .* · ${reason!.word}`)); | |
| 102 | expect(free).toMatch(new RegExp(`Crew running: .* · idle: ${reason!.word}`)); | |
| 100 | 103 | |
| 101 | 104 | const bot = getUserByName(forge.db, "idlebot")!; |
| 102 | for (let i = 0; i < 2; i++) createRun(forge.db, { repoId: repo.id, kind: "agent", actorId: bot.id }); | |
| 105 | // Both slots running: a claimed run is a builder at work, a queued one is not. | |
| 106 | for (let i = 0; i < 2; i++) claimRun(forge.db, createRun(forge.db, { repoId: repo.id, kind: "agent", actorId: bot.id }).id); | |
| 103 | 107 | expect(idleReason(forge, new Date())).toBeNull(); |
| 104 | 108 | const busy = await firstScreen(alice); |
| 105 | expect(busy).toContain("Builders running"); | |
| 109 | expect(busy).toContain("Crew running: 2 of 2"); | |
| 106 | 110 | expect(busy).not.toContain("nothing ready"); |
| 107 | 111 | }); |
test/tui-home-row.test.ts added +61
| @@ -0,0 +1,61 @@ | ||
| 1 | /** | |
| 2 | * The terminal home prints the page's one row of figures (`web/home_row.ts`) on its first draw. The | |
| 3 | * row is read by the dashboard's `loadWrong`, which runs after `reload` has built the figures: built | |
| 4 | * only in `reload`, the row stayed empty until a later outbox reload, and an admin opening the | |
| 5 | * terminal saw no row at all. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 13 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 14 | import type { User } from "../src/core/users.ts"; | |
| 15 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 16 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 17 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | import { settleApp } from "./helpers/tui.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | let dir = ""; | |
| 24 | let app: App; | |
| 25 | let admin: User; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dir = await mkdtemp(join(tmpdir(), "forge-tui-home-row-")); | |
| 29 | app = createApp({ dataDir: dir, port: 0 }); | |
| 30 | const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-passphrase" }); | |
| 31 | if (!a.ok) throw new Error("signup failed"); | |
| 32 | admin = a.value; | |
| 33 | const made = await createRepo(app, admin, { name: "engine", visibility: "private" }); | |
| 34 | if (!made.ok) throw new Error(String(made.error)); | |
| 35 | const seeded = await commitToBranch(app, admin, made.value, { message: "Start", files: [{ path: "README.md", content: "# engine\n" }] }); | |
| 36 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 37 | const agent = await createAgent(app, admin, { username: "mason" }); | |
| 38 | if (!agent.ok) throw new Error(String(agent.error)); | |
| 39 | expect(addToCrew(app, admin, made.value, "mason").ok).toBe(true); | |
| 40 | const on = await updateRepoSettings(app, admin, made.value, { autonomy: "autonomous", autonomyDirection: "Build.", autonomySlots: 1 }); | |
| 41 | expect(on.ok).toBe(true); | |
| 42 | }); | |
| 43 | ||
| 44 | afterAll(async () => { | |
| 45 | app.close(); | |
| 46 | await rm(dir, { recursive: true, force: true }); | |
| 47 | }); | |
| 48 | ||
| 49 | test("an admin's terminal home prints the row on its first draw, with no write in between", async () => { | |
| 50 | const t = headlessTerminal(200, 40); | |
| 51 | const { app: tui } = createForgeApp( | |
| 52 | app, | |
| 53 | { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: admin }, | |
| 54 | { terminal: t, exitHooks: false }, | |
| 55 | ); | |
| 56 | tui.start(); | |
| 57 | await settleApp(tui); | |
| 58 | const text = tui.screen.toText(); | |
| 59 | tui.stop(); | |
| 60 | expect(text).toMatch(/Crew running: 0 of 1 · idle: /); | |
| 61 | }); |
test/tui-kpis.test.ts +46 −37
| @@ -1,4 +1,7 @@ | ||
| 1 | /** The terminal's first screen carries the figures the web home does (#2871): an admin sees them; nobody else does. */ | |
| 1 | /** | |
| 2 | * The terminal's first screen carries the row the web home does (#2871, `homeRow`): an admin sees | |
| 3 | * it; nobody else does. | |
| 4 | */ | |
| 2 | 5 | import { noteMeasure } from "../src/core/measure.ts"; |
| 3 | 6 | import { PLATFORM } from "../src/core/subscriptions.ts"; |
| 4 | 7 | import { forgetWeek } from "../src/crew/week_read.ts"; |
| @@ -12,7 +15,8 @@ import { createApp, type App as Forge } from "../src/app.ts"; | ||
| 12 | 15 | import { createRun } from "../src/core/runs.ts"; |
| 13 | 16 | import { keepFigures } from "../src/tui/screens/dashboard.ts"; |
| 14 | 17 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 15 | import { readVitals, vitalsLine } from "../src/flow/vitals.ts"; | |
| 18 | import type { LanePicture } from "../src/flow/lanes.ts"; | |
| 19 | import { homeRow } from "../src/web/home_row.ts"; | |
| 16 | 20 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 17 | 21 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 18 | 22 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -77,49 +81,54 @@ async function withCommit<T>(commit: string | undefined, fn: () => Promise<T>): | ||
| 77 | 81 | } |
| 78 | 82 | } |
| 79 | 83 | |
| 80 | test("the terminal's first screen shows the three figures; a non-admin and a guest have none", async () => { | |
| 84 | /** The row's labels, as the terminal prints them at the start of a line. */ | |
| 85 | const LABELS = ["Shipped in 24 hours", "Median open to landed", "Crew running", "Week used"]; | |
| 86 | const figureLines = (text: string): string[] => text.split("\n").map((l) => l.trim()).filter((l) => LABELS.some((label) => l.startsWith(`${label}: `))); | |
| 87 | ||
| 88 | test("the terminal's first screen shows the row's figures, each once; a non-admin and a guest have none", async () => { | |
| 81 | 89 | const text = await withCommit(undefined, () => firstScreen(alice)); |
| 82 | expect(text).toContain("Shipped per hour 0.0"); | |
| 83 | expect(text).toContain("Live version — nothing live yet"); | |
| 84 | expect(text).toContain("Median check time —"); | |
| 85 | expect(await firstScreen(bob)).not.toContain("Shipped per hour"); | |
| 86 | expect(await firstScreen()).not.toContain("Shipped per hour"); | |
| 90 | expect(text).toContain("Shipped in 24 hours: 0 · changes landed on main"); | |
| 91 | expect(text).toContain("Median open to landed: none · nothing landed in 24 hours"); | |
| 92 | for (const label of LABELS) expect(figureLines(text).filter((l) => l.startsWith(`${label}: `))).toHaveLength(1); | |
| 93 | // The live version, said once: the web says it in its footer, the terminal on one line after the row. | |
| 94 | expect(text.split("Live version: ").length - 1).toBe(1); | |
| 95 | expect(figureLines(await firstScreen(bob))).toEqual([]); | |
| 96 | expect(figureLines(await firstScreen())).toEqual([]); | |
| 87 | 97 | }); |
| 88 | 98 | |
| 89 | test("the live figure is the running commit, as /releases shows it", async () => { | |
| 90 | const text = await withCommit("1234567abcdef", () => firstScreen(alice)); | |
| 91 | expect(text).toContain("Live version 1234567, live"); | |
| 92 | }); | |
| 93 | ||
| 94 | test("the admin's figures carry the configured daily ceiling, and say so when there is none", async () => { | |
| 99 | test("the admin's week is said against the configured daily ceiling, and in dollars when there is none", async () => { | |
| 95 | 100 | const capped = { ...forge, config: { ...forge.config, crewCeilingUsd: 40 } }; |
| 96 | expect(await firstScreen(alice, capped)).toContain("Crew spend today $0.00 of $40"); | |
| 97 | expect(await firstScreen(alice)).toContain("Crew spend today $0.00, no forge ceiling"); | |
| 98 | expect(await firstScreen(alice)).toContain("Reporting browsers 0 today, 0 in 7 days"); | |
| 101 | // The lanes' picture is kept until something is written; the ceiling is config, read with it. | |
| 102 | const bump = () => forge.db.run("UPDATE user SET username = username WHERE username = 'alice'"); | |
| 103 | bump(); | |
| 104 | expect(await firstScreen(alice, capped)).toContain("Week used: about 0% · the provider has not reported its week"); | |
| 105 | bump(); | |
| 106 | expect(await firstScreen(alice)).toContain("Week used: about $0.00 · spent by the crew in seven days"); | |
| 99 | 107 | }); |
| 100 | 108 | |
| 101 | test("past the forge cap the terminal and the web tile read the same words", async () => { | |
| 102 | const { spendCeilingWords } = await import("../src/flow/kpi_words.ts"); | |
| 103 | const w = spendCeilingWords({ todayUsd: 601, ceilingUsd: 600, hitAt: "2026-10-25T14:03:20.000Z" }); | |
| 104 | expect(w).toEqual({ note: "ceiling hit 14:03Z, builders idle", title: "ceiling hit 14:03Z, builders idle", attn: true }); | |
| 105 | }); | |
| 106 | ||
| 107 | test("an admin's first screen carries the flow vitals line; a non-admin's does not (#5935)", async () => { | |
| 108 | const text = await withCommit(undefined, () => firstScreen(alice)); | |
| 109 | expect(text).toContain(vitalsLine(readVitals(forge.db))); | |
| 110 | expect(await firstScreen(bob)).not.toContain("open pulls"); | |
| 109 | test("past the forge cap the week figure asks for someone, on the row both doors draw", () => { | |
| 110 | const picture = (weekSpendUsd: number) => | |
| 111 | ({ | |
| 112 | builders: { running: 0, slots: 0 }, | |
| 113 | figures: null, | |
| 114 | idle: null, | |
| 115 | strip: { landed: 0, landedHours: [], lead: { landed: 0, medianHours: null, maxHours: null }, week: null, weekSpendUsd, ceilingUsd: 600, needs: [] }, | |
| 116 | }) as unknown as LanePicture; | |
| 117 | const week = (usd: number) => homeRow(picture(usd), (i) => i, Date.now()).find((r) => r.label === "Week used")!; | |
| 118 | expect(week(4201)).toMatchObject({ value: "about 100%", tone: "attn" }); | |
| 119 | expect(week(600)).toMatchObject({ value: "about 14%", tone: null }); | |
| 111 | 120 | }); |
| 112 | 121 | |
| 113 | 122 | test("a short strip keeps the spend line ahead of lesser figures, in the order they are drawn (#9512)", () => { |
| 114 | const figures = ["Builders idle", "Week", "Shipped", "Crew spend today $1 of $40", "Vitals"]; | |
| 115 | expect(keepFigures(figures, 2)).toEqual(["Builders idle", "Crew spend today $1 of $40"]); | |
| 116 | expect(keepFigures(figures, 1)).toEqual(["Crew spend today $1 of $40"]); | |
| 123 | const figures = ["Shipped in 24 hours: 3", "Median open to landed: 2h", "Crew running: 0 of 2", "Week used: about 12%", "Visitors: 4"]; | |
| 124 | expect(keepFigures(figures, 2)).toEqual(["Shipped in 24 hours: 3", "Week used: about 12%"]); | |
| 125 | expect(keepFigures(figures, 1)).toEqual(["Week used: about 12%"]); | |
| 117 | 126 | expect(keepFigures(figures, 0)).toEqual([]); |
| 118 | 127 | expect(keepFigures(figures, 9)).toEqual(figures); |
| 119 | 128 | expect(keepFigures(["a", "b", "c"], 2)).toEqual(["a", "b"]); |
| 120 | 129 | }); |
| 121 | 130 | |
| 122 | test("with since-lines, moving-lines and idle crew all drawn, the admin still sees the spend and ceiling line, at 32 rows and when trimmed (#9512)", async () => { | |
| 131 | test("with since-lines, moving-lines and idle crew all drawn, the admin still sees the week line, at 32 rows and when trimmed (#9512)", async () => { | |
| 123 | 132 | const d = await mkdtemp(join(tmpdir(), "forge-tui-kpis-full-")); |
| 124 | 133 | const full = createApp({ dataDir: d, port: 0 }); |
| 125 | 134 | try { |
| @@ -142,7 +151,7 @@ test("with since-lines, moving-lines and idle crew all drawn, the admin still se | ||
| 142 | 151 | observedAt: new Date().toISOString(), |
| 143 | 152 | }); |
| 144 | 153 | forgetWeek(); |
| 145 | // The day's spend the line below prints. | |
| 154 | // A day's spend, so the week is not empty. | |
| 146 | 155 | const run = createRun(full.db, { repoId: made.value.id, kind: "agent", actorId: getUserByName(full.db, "idlebot")!.id }); |
| 147 | 156 | full.db.query("UPDATE run SET cost_usd = 5, state = 'ok' WHERE id = ?1").run(run.id); |
| 148 | 157 | // Since-lines: pulls landed in the last hour. |
| @@ -159,13 +168,13 @@ test("with since-lines, moving-lines and idle crew all drawn, the admin still se | ||
| 159 | 168 | const text = await withCommit(undefined, () => firstScreen(admin, capped)); |
| 160 | 169 | expect(text).toContain("Since you were here"); |
| 161 | 170 | expect(text).toContain("Being built"); |
| 162 | expect(text).toContain("Builders idle"); | |
| 163 | expect(text).toContain("Crew spend today $5.00 of $40"); | |
| 164 | // Shorter still, the strip is trimmed: lesser figures go, the spend line and the list stay. | |
| 171 | expect(text).toContain("Crew running: 0 of 2 · idle: week spent"); | |
| 172 | expect(text).toContain("Week used: 100%"); | |
| 173 | // Shorter still, the strip is trimmed: lesser figures go, the week line and the list stay. | |
| 165 | 174 | const short = await withCommit(undefined, () => firstScreen(admin, capped, 20)); |
| 166 | 175 | expect(short).toContain("Being built"); |
| 167 | expect(short).toContain("Crew spend today $5.00 of $40"); | |
| 168 | expect(short).not.toContain("Reporting browsers"); | |
| 176 | expect(short).toContain("Week used: 100%"); | |
| 177 | expect(figureLines(short).length).toBeLessThan(figureLines(text).length); | |
| 169 | 178 | expect(short).toContain("alice/svc"); |
| 170 | 179 | } finally { |
| 171 | 180 | full.close(); |
test/week-wiring.test.ts +2 −1
| @@ -135,7 +135,8 @@ test("home and the terminal print the same sentence, the terminal for an admin", | ||
| 135 | 135 | await settleApp(tui); |
| 136 | 136 | const text = tui.screen.toText(); |
| 137 | 137 | tui.stop(); |
| 138 | expect(text).toContain("20% of the week used"); | |
| 138 | // The home's row says the week once (Week used), on both doors; the sentence is the crew's Spend tab's. | |
| 139 | expect(text).toContain("Week used: 20% · of the crew's week; it may use 90%"); | |
| 139 | 140 | }); |
| 140 | 141 | |
| 141 | 142 | test("the week sentence says when crew concurrency is below its ceiling, and not at it", () => { |
new above
offline