Public: anyone can read this; the crew can change it.
/waves entries state how many pulls and how many days each wave took, read from the story modules #14733
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14708-waves-entries-state-how-many-pulls-and-h → main 6 commits fork 2 threads · 2 unresolved
7 files
changed +200
−26
docs/features/wave-size-line.md added +20
| @@ -0,0 +1,20 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: A wave says how many changes and days it took | |
| 4 | --- | |
| 5 | # A wave says how many changes and days it took | |
| 6 | ||
| 7 | Each wave on the waves list says how big it was and how long it took, in one | |
| 8 | phrase: "3 changes in 1 app over 4 days" once every change has landed, "2 | |
| 9 | changes in 1 app so far, day 6" while one still waits. Day 1 is the day the | |
| 10 | wave's first issue was opened. A wave naming no change you can see gives only | |
| 11 | its count. | |
| 12 | ||
| 13 | ## Where to read it | |
| 14 | ||
| 15 | - The web: open `/<owner>/<repo>/waves`; the phrase sits in each row's trail, | |
| 16 | and in the summary of each entry of `/<owner>/<repo>/waves.atom`. | |
| 17 | - The terminal: open the Waves screen of a repository; the same phrase ends | |
| 18 | each row's title. | |
| 19 | ||
| 20 | Only the pulls you may read are counted. |
src/story/wave_duration.ts +33 −6
| @@ -16,17 +16,28 @@ export function daysWords(ms: number): string { | ||
| 16 | 16 | return days < 1 ? "less than a day" : days === 1 ? "1 day" : `${days} days`; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | /** | |
| 20 | * The one open/landed decision: how much time has gone by (`ms`) and whether a change still waits | |
| 21 | * (`open`). While open it runs from the start to now; once every change landed, to the last | |
| 22 | * landing. Null when there is no start to count from or nothing to count. | |
| 23 | */ | |
| 24 | function span(startedAt: string | null, pulls: readonly { mergedAt: string | null }[], now: Date): { open: boolean; ms: number } | null { | |
| 25 | if (startedAt === null || pulls.length === 0) return null; | |
| 26 | const start = Date.parse(startedAt); | |
| 27 | if (Number.isNaN(start)) return null; | |
| 28 | const landed = pulls.flatMap((p) => (p.mergedAt === null ? [] : [Date.parse(p.mergedAt)])).filter((t) => !Number.isNaN(t)); | |
| 29 | if (landed.length < pulls.length) return { open: true, ms: now.getTime() - start }; | |
| 30 | return { open: false, ms: Math.max(...landed) - start }; | |
| 31 | } | |
| 32 | ||
| 19 | 33 | /** |
| 20 | 34 | * "took 3 days" when every change has landed, else "open for 3 days"; empty when there is no start |
| 21 | 35 | * to count from (a wave naming no change the viewer can see). |
| 22 | 36 | */ |
| 23 | 37 | export function durationWords(startedAt: string | null, pulls: readonly { mergedAt: string | null }[], now: Date): string { |
| 24 | if (startedAt === null || pulls.length === 0) return ""; | |
| 25 | const start = Date.parse(startedAt); | |
| 26 | if (Number.isNaN(start)) return ""; | |
| 27 | const landed = pulls.flatMap((p) => (p.mergedAt === null ? [] : [Date.parse(p.mergedAt)])).filter((t) => !Number.isNaN(t)); | |
| 28 | if (landed.length < pulls.length) return `open for ${daysWords(now.getTime() - start)}`; | |
| 29 | return `took ${daysWords(Math.max(...landed) - start)}`; | |
| 38 | const t = span(startedAt, pulls, now); | |
| 39 | if (t === null) return ""; | |
| 40 | return t.open ? `open for ${daysWords(t.ms)}` : `took ${daysWords(t.ms)}`; | |
| 30 | 41 | } |
| 31 | 42 | |
| 32 | 43 | /** |
| @@ -77,3 +88,19 @@ export function waveStart(db: Database, pulls: readonly CarriedPull[]): string | | ||
| 77 | 88 | |
| 78 | 89 | /** The wave's duration sentence, from the pulls the viewer may see. */ |
| 79 | 90 | export const waveDuration = (db: Database, pulls: readonly CarriedPull[], now: Date): string => durationWords(waveStart(db, pulls), pulls, now); |
| 91 | ||
| 92 | /** | |
| 93 | * How long, as the tail of the wave's size phrase: "over 4 days" once every change has landed, | |
| 94 | * "within a day" when it was quicker, "so far, day 6" while one waits (day 1 is the day it opened). | |
| 95 | * Empty when there is nothing to count. Fixed words and numbers only; the caller still escapes. | |
| 96 | */ | |
| 97 | export function daysSpan(startedAt: string | null, pulls: readonly { mergedAt: string | null }[], now: Date): string { | |
| 98 | const t = span(startedAt, pulls, now); | |
| 99 | if (t === null) return ""; | |
| 100 | if (t.open) return `so far, day ${Math.floor(Math.max(t.ms, 0) / DAY) + 1}`; | |
| 101 | const days = daysWords(t.ms); | |
| 102 | return days === "less than a day" ? "within a day" : `over ${days}`; | |
| 103 | } | |
| 104 | ||
| 105 | /** The wave's day span, from the pulls the viewer may see. */ | |
| 106 | export const waveDays = (db: Database, pulls: readonly CarriedPull[], now: Date): string => daysSpan(waveStart(db, pulls), pulls, now); |
src/story/waves.ts +13 −6
| @@ -174,14 +174,21 @@ export function waveSize(refs: readonly { owner: string; name: string }[]): { pu | ||
| 174 | 174 | return { pulls: refs.length, apps: new Set(refs.map((r) => `${r.owner}/${r.name}`)).size }; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | /** `7 changes in 3 apps`; `1 change in 1 app`. Numbers only, so nothing here needs escaping. */ | |
| 178 | export function sizeWords(size: { pulls: number; apps: number }): string { | |
| 179 | return `${size.pulls} ${size.pulls === 1 ? "change" : "changes"} in ${size.apps} ${size.apps === 1 ? "app" : "apps"}`; | |
| 177 | /** | |
| 178 | * `7 changes in 3 apps`; `1 change in 1 app`; with a day span (`daysSpan`) one phrase says both, | |
| 179 | * `3 changes in 1 app over 4 days`. Numbers and fixed words only. | |
| 180 | */ | |
| 181 | export function sizeWords(size: { pulls: number; apps: number }, days = ""): string { | |
| 182 | return `${size.pulls} ${size.pulls === 1 ? "change" : "changes"} in ${size.apps} ${size.apps === 1 ? "app" : "apps"}${days === "" ? "" : ` ${days}`}`; | |
| 180 | 183 | } |
| 181 | 184 | |
| 182 | /** A wave's one-line title, on the terminal's list: `<version> · <date> · <headline> · N changes in M apps`, counted over what this viewer can see. */ | |
| 183 | export function waveLine(w: Wave, size: { pulls: number; apps: number }): string { | |
| 184 | return `${w.version} · ${w.date} · ${w.headline} · ${sizeWords(size)}`; | |
| 185 | /** | |
| 186 | * A wave's one-line title, on the terminal's list: | |
| 187 | * `<version> · <date> · <headline> · N changes in M apps [over D days]`, counted over what this | |
| 188 | * viewer can see. | |
| 189 | */ | |
| 190 | export function waveLine(w: Wave, size: { pulls: number; apps: number }, days = ""): string { | |
| 191 | return `${w.version} · ${w.date} · ${w.headline} · ${sizeWords(size, days)}`; | |
| 185 | 192 | } |
| 186 | 193 | |
| 187 | 194 | /** Unreadable files tried before giving up on finding the newest good wave. */ |
src/tui/screens/waves.ts +17 −4
| @@ -10,7 +10,7 @@ import { canRead, getRepo } from "../../core/repos.ts"; | ||
| 10 | 10 | import { mayDirectCrew } from "../../crew/direct.ts"; |
| 11 | 11 | import { nearMilestones, standingLine } from "../../web/pages/milestones_near.ts"; |
| 12 | 12 | import { VERSION } from "../../story/wave.ts"; |
| 13 | import { waveDuration } from "../../story/wave_duration.ts"; | |
| 13 | import { waveDays, waveDuration } from "../../story/wave_duration.ts"; | |
| 14 | 14 | import { movedWithPulls, shippedOf, shippedWords, waveProgress, type MovedMilestone } from "../../story/wave_moved.ts"; |
| 15 | 15 | import { milestonePath, planNow } from "../../story/wave_plan.ts"; |
| 16 | 16 | import { repoBase } from "../../web/chrome.ts"; |
| @@ -19,6 +19,8 @@ import { carriedPulls, inLandingOrder, pullPath, type CarriedPull } from "../../ | ||
| 19 | 19 | import { pullRefs, readWave, readWaves, sizeWords, waveLine, waveSize, appsOf, wavesInApp, type WaveEntry } from "../../story/waves.ts"; |
| 20 | 20 | import { EMPTY_WORDS } from "../../core/empty_words.ts"; |
| 21 | 21 | import { FIRST_WAVE_TELL, landedSentence, waveSentence } from "../../story/words.ts"; |
| 22 | import type { Database } from "bun:sqlite"; | |
| 23 | import type { User } from "../../core/users.ts"; | |
| 22 | 24 | import type { RepoSource } from "../../view/source.ts"; |
| 23 | 25 | import type { Ctx, Screen } from "../app/app.ts"; |
| 24 | 26 | import { binding } from "../app/keys.ts"; |
| @@ -32,15 +34,23 @@ import { pullScreen } from "./pull.ts"; | ||
| 32 | 34 | import { tellHereNow } from "./tell_here.ts"; |
| 33 | 35 | import { local, localRepo, sourceName, whereRows, whereStrip } from "./where.ts"; |
| 34 | 36 | |
| 37 | /** | |
| 38 | * Each readable wave's day span by file ("over 4 days", "so far, day 6"), counted over the pulls | |
| 39 | * `viewer` can see: the tail of the size phrase `waveRows` draws, as the page draws it. | |
| 40 | */ | |
| 41 | export function daysByFile(db: Database, entries: readonly WaveEntry[], viewer: User | undefined, now: Date): Map<string, string> { | |
| 42 | return new Map(entries.flatMap((e) => (e.ok ? [[e.file, waveDays(db, carriedPulls(db, pullRefs(e.wave), viewer), now)] as const] : []))); | |
| 43 | } | |
| 44 | ||
| 35 | 45 | /** |
| 36 | 46 | * One line per wave, as the screen draws it, sized as the page sizes it: `sizeOf` counts the pulls |
| 37 | 47 | * this viewer can see. |
| 38 | 48 | */ |
| 39 | export function waveRows(entries: WaveEntry[], sizeOf: (e: WaveEntry & { ok: true }) => { pulls: number; apps: number }, shipped: (e: WaveEntry & { ok: true }) => string = () => "") { | |
| 49 | export function waveRows(entries: WaveEntry[], sizeOf: (e: WaveEntry & { ok: true }) => { pulls: number; apps: number }, shipped: (e: WaveEntry & { ok: true }) => string = () => "", days: (e: WaveEntry & { ok: true }) => string = () => "") { | |
| 40 | 50 | return entries.map((e) => |
| 41 | 51 | e.ok |
| 42 | 52 | ? { |
| 43 | title: plain(waveLine(e.wave, sizeOf(e))), | |
| 53 | title: plain(waveLine(e.wave, sizeOf(e), days(e))), | |
| 44 | 54 | secondary: "", |
| 45 | 55 | meta: plain(shipped(e)), |
| 46 | 56 | } |
| @@ -184,6 +194,8 @@ export function wavesScreen(f: Session, ctx: Ctx, src: RepoSource): Screen { | ||
| 184 | 194 | let sizes = new Map<string, { pulls: number; apps: number }>(); |
| 185 | 195 | /** Each wave's "N live, M landing" by file, as the page's trail says it. */ |
| 186 | 196 | let shipped = new Map<string, string>(); |
| 197 | /** Each wave's "over D days" by file, as the page's size phrase ends. */ | |
| 198 | let days = new Map<string, string>(); | |
| 187 | 199 | let loaded = false; |
| 188 | 200 | const state = new ListState(); |
| 189 | 201 | /** The app the list is narrowed to (`a` cycles through the apps the waves carry), as `?app=`. */ |
| @@ -243,6 +255,7 @@ export function wavesScreen(f: Session, ctx: Ctx, src: RepoSource): Screen { | ||
| 243 | 255 | e.ok ? [[e.file, shippedWords(shippedOf(carriedPulls(f.db, pullRefs(e.wave), f.user), waiting))] as const] : [], |
| 244 | 256 | ), |
| 245 | 257 | ); |
| 258 | days = daysByFile(f.db, entries, f.user, new Date()); | |
| 246 | 259 | apps = [...new Set(entries.flatMap((e) => (e.ok ? appsOf(carriedPulls(f.db, pullRefs(e.wave), f.user)) : [])))]; |
| 247 | 260 | if (app !== null && !apps.includes(app)) app = null; |
| 248 | 261 | loaded = true; |
| @@ -342,7 +355,7 @@ export function wavesScreen(f: Session, ctx: Ctx, src: RepoSource): Screen { | ||
| 342 | 355 | }); |
| 343 | 356 | return; |
| 344 | 357 | } |
| 345 | const rows = waveRows(shown(), (e) => sizes.get(e.file) ?? { pulls: 0, apps: 0 }, (e) => shipped.get(e.file) ?? ""); | |
| 358 | const rows = waveRows(shown(), (e) => sizes.get(e.file) ?? { pulls: 0, apps: 0 }, (e) => shipped.get(e.file) ?? "", (e) => days.get(e.file) ?? ""); | |
| 346 | 359 | drawList(s, body!, c, state, rows); |
| 347 | 360 | hitList(ctx, body!, state, rows.length, { open: openAt }); |
| 348 | 361 | }, |
src/web/pages/waves.ts +15 −8
| @@ -17,7 +17,7 @@ import { repoDir } from "../../git/repos.ts"; | ||
| 17 | 17 | import type { Ctx } from "../../http/context.ts"; |
| 18 | 18 | import { VERSION, type Wave } from "../../story/wave.ts"; |
| 19 | 19 | import { movedWithPulls, type MovedMilestone, shippedOf, shippedWords, waveProgress, widestMoved } from "../../story/wave_moved.ts"; |
| 20 | import { waveDuration } from "../../story/wave_duration.ts"; | |
| 20 | import { waveDays, waveDuration } from "../../story/wave_duration.ts"; | |
| 21 | 21 | import { carriedPulls, inLandingOrder, pullPath } from "../../story/wave_pulls.ts"; |
| 22 | 22 | import { appsOf, fromWave, inApp, parseAppFilter, pullRefs, readWave, readWaves, sizeWords, waveSize } from "../../story/waves.ts"; |
| 23 | 23 | import { FIRST_WAVE_TELL, landedSentence, waveSentence } from "../../story/words.ts"; |
| @@ -44,7 +44,7 @@ export const WAVES_CSS = `[data-waves] { overflow-wrap: anywhere; } | ||
| 44 | 44 | * One wave on the list: its headline, the first highlight's why as the one sentence under it, and |
| 45 | 45 | * version, date and pull count as a muted trail. |
| 46 | 46 | */ |
| 47 | export function waveRow(w: Wave, href: string, size: { pulls: number; apps: number }, shipped = "", apps: readonly Html[] = []) { | |
| 47 | export function waveRow(w: Wave, href: string, size: { pulls: number; apps: number }, shipped = "", apps: readonly Html[] = [], days = "") { | |
| 48 | 48 | const why = w.highlights[0]?.why; |
| 49 | 49 | return row({ |
| 50 | 50 | href, |
| @@ -52,7 +52,7 @@ export function waveRow(w: Wave, href: string, size: { pulls: number; apps: numb | ||
| 52 | 52 | title: w.headline, |
| 53 | 53 | ...(why === undefined || why === "" ? {} : { meta: html`${why}` }), |
| 54 | 54 | ...(apps.length === 0 ? {} : { after: html`${apps.map((a, i) => html`${i === 0 ? "" : " "}${a}`)}` }), |
| 55 | trail: html`<span class="muted small">${w.version} · ${w.date} · <span data-wave-size>${sizeWords(size)}</span>${shipped === "" ? "" : html` · <span data-wave-shipped>${shipped}</span>`}</span>`, | |
| 55 | trail: html`<span class="muted small">${w.version} · ${w.date} · <span data-wave-size>${sizeWords(size, days)}</span>${shipped === "" ? "" : html` · <span data-wave-shipped>${shipped}</span>`}</span>`, | |
| 56 | 56 | }); |
| 57 | 57 | } |
| 58 | 58 | |
| @@ -89,7 +89,7 @@ export async function wavesPage(ctx: Ctx): Promise<Response> { | ||
| 89 | 89 | if (filtering && (app === null || !carried.some((p) => inApp(p, app)))) return []; |
| 90 | 90 | // The app names sit beside the row, outside its link: a link cannot hold links. |
| 91 | 91 | const links = appsOf(carried).map((a) => html`<a data-wave-app href="${listHref}?app=${encodeURIComponent(a)}">${a}</a>`); |
| 92 | return [waveRow(e.wave, fileHref(e.file), waveSize(carried), shippedWords(shippedOf(carried, waiting)), links)]; | |
| 92 | return [waveRow(e.wave, fileHref(e.file), waveSize(carried), shippedWords(shippedOf(carried, waiting)), links, waveDays(ctx.app.db, carried, new Date()))]; | |
| 93 | 93 | }); |
| 94 | 94 | // The set filter is named as the list's tabs are: All, then the app, current. A malformed app is |
| 95 | 95 | // never echoed. |
| @@ -158,7 +158,14 @@ export async function wavesAtom(ctx: Ctx): Promise<Response> { | ||
| 158 | 158 | const newest = waves[0]; |
| 159 | 159 | // What waits to ship changes without a wave file changing, so it is in the tag. |
| 160 | 160 | const waiting = waitingKeys(ctx.app.db); |
| 161 | const shown = Bun.hash(JSON.stringify([repo.ownerName, repo.name, repo.description, waves, waiting === undefined ? null : [...waiting].sort()])) | |
| 161 | // Pulls land and days pass without a wave file changing, so each wave's lines are in the tag. | |
| 162 | const now = new Date(); | |
| 163 | const lines = waves.map((w) => { | |
| 164 | const carried = carriedPulls(ctx.app.db, pullRefs(w), ctx.auth.user); | |
| 165 | const days = waveDays(ctx.app.db, carried, now); | |
| 166 | return { words: shippedWords(shippedOf(carried, waiting)), took: days === "" ? "" : sizeWords(waveSize(carried), days) }; | |
| 167 | }); | |
| 168 | const shown = Bun.hash(JSON.stringify([repo.ownerName, repo.name, repo.description, waves, lines, waiting === undefined ? null : [...waiting].sort()])) | |
| 162 | 169 | .toString(36); |
| 163 | 170 | const etag = `W/"${newest?.version ?? "none"}.${shown}"`; |
| 164 | 171 | const cacheControl = repo.visibility === "public" ? "public, max-age=300" : "private, no-store"; |
| @@ -166,9 +173,9 @@ export async function wavesAtom(ctx: Ctx): Promise<Response> { | ||
| 166 | 173 | if (holds(ctx.request.headers.get("if-none-match"), etag)) |
| 167 | 174 | return new Response(null, { status: 304, headers: { etag, "cache-control": cacheControl, vary } }); |
| 168 | 175 | const renderStart = performance.now(); |
| 169 | const entries = waves.map((w) => { | |
| 170 | const words = shippedWords(shippedOf(carriedPulls(ctx.app.db, pullRefs(w), ctx.auth.user), waiting)); | |
| 171 | const summary = `${words === "" ? "" : `<p>${escapeHtml(words)}</p>`}<ul>${w.highlights | |
| 176 | const entries = waves.map((w, i) => { | |
| 177 | const { words, took } = lines[i]!; | |
| 178 | const summary = `${took === "" ? "" : `<p>${escapeHtml(took)}</p>`}${words === "" ? "" : `<p>${escapeHtml(words)}</p>`}<ul>${w.highlights | |
| 172 | 179 | .map((h) => `<li><strong>${escapeHtml(h.title)}</strong> — ${escapeHtml(h.why)}</li>`) |
| 173 | 180 | .join("")}</ul>`; |
| 174 | 181 | const link = `${base}/waves/${encodeURIComponent(w.version)}`; |
test/waves-page.test.ts +2 −2
| @@ -271,9 +271,9 @@ describe("waves page", () => { | ||
| 271 | 271 | |
| 272 | 272 | test("a row counts the pulls this viewer can see, as the wave's page lists them", async () => { |
| 273 | 273 | const body = await (await get("/alice/pub/waves")).text(); |
| 274 | expect(body).toContain("0.1.0 · 2026-03-05 · <span data-wave-size>2 changes in 2 apps<"); | |
| 274 | expect(body).toContain("0.1.0 · 2026-03-05 · <span data-wave-size>2 changes in 2 apps within a day<"); | |
| 275 | 275 | const guest = await (await get("/alice/pub/waves", false)).text(); |
| 276 | expect(guest).toContain("0.1.0 · 2026-03-05 · <span data-wave-size>1 change in 1 app<"); | |
| 276 | expect(guest).toContain("0.1.0 · 2026-03-05 · <span data-wave-size>1 change in 1 app within a day<"); | |
| 277 | 277 | expect(guest).not.toContain("2 changes"); |
| 278 | 278 | expect(guest).not.toMatch(/\d+ pulls?</); |
| 279 | 279 | expect(guest).not.toContain("Secret work"); |
test/waves-size-line.test.ts added +100
| @@ -0,0 +1,100 @@ | ||
| 1 | /** | |
| 2 | * A wave says, in one phrase, how many changes and how many days it took, or "so far, day D" while | |
| 3 | * open (#14708). | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createSession } from "../src/core/sessions.ts"; | |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | import { repoDir } from "../src/git/repos.ts"; | |
| 15 | import { readWaves } from "../src/story/waves.ts"; | |
| 16 | import { daysByFile, waveRows } from "../src/tui/screens/waves.ts"; | |
| 17 | import { daysSpan } from "../src/story/wave_duration.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | import { mergedPull, waveNaming } from "./helpers/wave-pulls.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | let dataDir = ""; | |
| 24 | let app: App; | |
| 25 | let servers: Servers; | |
| 26 | let cookie = ""; | |
| 27 | ||
| 28 | const day = (n: number): string => new Date(Date.now() - n * 86_400_000).toISOString(); | |
| 29 | ||
| 30 | beforeAll(async () => { | |
| 31 | dataDir = await mkdtemp(join(tmpdir(), "forge-wave-size-")); | |
| 32 | app = createApp({ dataDir, port: 0 }); | |
| 33 | servers = await serve(app); | |
| 34 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 35 | if (!u.ok) throw new Error(String(u.error)); | |
| 36 | cookie = `forge_session=${createSession(app.db, u.value.id).token}; forge_mode=dev`; | |
| 37 | const made = await createRepo(app, u.value, { name: "plan", visibility: "public" }); | |
| 38 | if (!made.ok) throw new Error(String(made.error)); | |
| 39 | const repo = made.value; | |
| 40 | const init = await commitToBranch(app, u.value, repo, { message: "init", files: [{ path: "README.md", content: "hi\n" }] }); | |
| 41 | if (!init.ok) throw new Error(JSON.stringify(init.error)); | |
| 42 | const opened = (n: number, at: string) => app.db.query("UPDATE issue SET created_at = ? WHERE repo_id = ? AND number = ?").run(at, repo.id, n); | |
| 43 | const merged = async (title: string, openedAt: string, mergedAt: string | null) => { | |
| 44 | const n = await mergedPull(app, u.value, repo, title); | |
| 45 | opened(n, openedAt); | |
| 46 | app.db.query("UPDATE pull SET merged_at = ? WHERE issue_id = (SELECT id FROM issue WHERE repo_id = ? AND number = ?)").run(mergedAt, repo.id, n); | |
| 47 | return n; | |
| 48 | }; | |
| 49 | const closed = await merged("Closed work", "2026-03-01T09:00:00.000Z", "2026-03-04T10:00:00.000Z"); | |
| 50 | const closed2 = await merged("Second work", "2026-03-02T09:00:00.000Z", "2026-03-03T10:00:00.000Z"); | |
| 51 | const half = await merged("Half work", day(5), day(4)); | |
| 52 | const waiting = await merged("Waiting work", day(5), null); | |
| 53 | const ref = (number: number) => ({ owner: "alice", name: "plan", number }); | |
| 54 | const c = await commitToBranch(app, u.value, repo, { | |
| 55 | message: "waves", | |
| 56 | files: [ | |
| 57 | { path: "waves/0.1.0.md", content: waveNaming("0.1.0", [ref(closed), ref(closed2)]) }, | |
| 58 | { path: "waves/0.2.0.md", content: waveNaming("0.2.0", [ref(half), ref(waiting)]) }, | |
| 59 | ], | |
| 60 | }); | |
| 61 | if (!c.ok) throw new Error(JSON.stringify(c.error)); | |
| 62 | }, 60_000); | |
| 63 | ||
| 64 | afterAll(async () => { | |
| 65 | servers?.stop(); | |
| 66 | app?.close(); | |
| 67 | await rm(dataDir, { recursive: true, force: true }); | |
| 68 | }); | |
| 69 | ||
| 70 | test("the words: over days when landed, so far with the day number while open", () => { | |
| 71 | const now = new Date("2026-03-10T00:00:00.000Z"); | |
| 72 | expect(daysSpan("2026-03-01T09:00:00.000Z", [{ mergedAt: "2026-03-04T10:00:00.000Z" }, { mergedAt: "2026-03-03T00:00:00.000Z" }], now)).toBe("over 3 days"); | |
| 73 | expect(daysSpan("2026-03-01T09:00:00.000Z", [{ mergedAt: "2026-03-01T10:00:00.000Z" }], now)).toBe("within a day"); | |
| 74 | expect(daysSpan("2026-03-01T00:00:00.000Z", [{ mergedAt: "2026-03-02T00:00:00.000Z" }, { mergedAt: null }], now)).toBe("so far, day 10"); | |
| 75 | expect(daysSpan(null, [], now)).toBe(""); | |
| 76 | }); | |
| 77 | ||
| 78 | test("the list and its Atom entry say count and days in one phrase, for a closed and an open wave", async () => { | |
| 79 | const list = await (await fetch(`${servers.url}/alice/plan/waves`, { headers: { cookie } })).text(); | |
| 80 | expect(list).toContain("<span data-wave-size>2 changes in 1 app over 3 days</span>"); | |
| 81 | expect(list).toContain("<span data-wave-size>2 changes in 1 app so far, day 6</span>"); | |
| 82 | // The count is said once: no second span repeats it. | |
| 83 | expect(list).not.toContain("data-wave-took"); | |
| 84 | expect(list).not.toMatch(/\d+ pulls? (over|so far|in )/); | |
outdated
This only proves waveRows joins a string it was handed. It would still pass if wavesScreen stopped computing the line. Test the wiring. |
||
| 85 | const atom = await (await fetch(`${servers.url}/alice/plan/waves.atom`)).text(); | |
| 86 | expect(atom).toContain("<p>2 changes in 1 app over 3 days</p>"); | |
| 87 | expect(atom).toContain("<p>2 changes in 1 app so far, day 6</p>"); | |
| 88 | }); | |
| 89 | ||
| 90 | test("the terminal's wave row ends its size phrase with the days the screen computes", async () => { | |
| 91 | const entries = await readWaves(repoDir(app.reposRoot, "alice", "plan"), "main"); | |
| 92 | const days = daysByFile(app.db, entries, undefined, new Date()); | |
| 93 | expect(days.get("0.1.0.md")).toBe("over 3 days"); | |
| 94 | expect(days.get("0.2.0.md")).toBe("so far, day 6"); | |
| 95 | const rows = waveRows(entries, () => ({ pulls: 2, apps: 1 }), () => "", (e) => days.get(e.file) ?? ""); | |
| 96 | const titles = rows.map((r) => r.title); | |
| 97 | expect(titles.some((t) => t.endsWith("· 2 changes in 1 app over 3 days"))).toBe(true); | |
| 98 | expect(titles.some((t) => t.endsWith("· 2 changes in 1 app so far, day 6"))).toBe(true); | |
| 99 | expect(rows.every((r) => !/pulls? (over|so far)/.test(r.meta))).toBe(true); | |
| 100 | }); |
new above
offline
Principle 1: nothing explains itself twice. data-wave-size ('N changes in M apps') and data-wave-took ('N pulls over D days') both state the count. Merge them into one phrase, or drop the count from one. On a phone this trail wraps to an extra line.