Public: anyone can read this; the crew can change it.
A wave's page links the wave before it and the wave after it, by name, so the story reads in order #14573
Check · Review · Land · Live — No review yet.
mason/forge:mason/14554-a-wave-s-page-links-the-wave-before-it-a → main 5 commits fork
This pull asks to reach lab--forge-trevato-apps.open-platform.sh. Its preview and check reach what main reaches; the new host opens when the pull lands.
3 files
changed +122
−2
src/story/waves.ts +41
| @@ -184,6 +184,47 @@ export function waveLine(w: Wave, size: { pulls: number; apps: number }): string | ||
| 184 | 184 | return `${w.version} · ${w.date} · ${w.headline} · ${sizeWords(size)}`; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | /** The wave files before and after `version` in release order, each the nearest that parses. */ | |
| 188 | export interface WaveNeighbours { | |
| 189 | /** The next older wave, or null for the oldest. */ | |
| 190 | earlier: Wave | null; | |
| 191 | /** The next newer wave, or null for the newest. */ | |
| 192 | later: Wave | null; | |
| 193 | } | |
| 194 | ||
| 195 | /** | |
| 196 | * The waves either side of `version`. A file that does not parse (or is too large, or unreadable) | |
| 197 | * is skipped, never named. Reads the tree once and only the files it takes to find each side. | |
| 198 | */ | |
| 199 | export async function waveNeighbours(dir: string, branch: string, version: string): Promise<WaveNeighbours> { | |
| 200 | const none: WaveNeighbours = { earlier: null, later: null }; | |
| 201 | const tree = await listTree(dir, branch, "waves"); | |
| 202 | if (!tree.ok) return none; | |
| 203 | // Newest first, like the list. | |
| 204 | const files = tree.value | |
| 205 | .filter((e) => e.type === "blob" && e.name.endsWith(".md") && WAVE_VERSION.test(e.name.slice(0, -3))) | |
| 206 | .sort((x, y) => byVersionDesc(x.name.slice(0, -3), y.name.slice(0, -3))) | |
| 207 | .slice(0, MAX_FILES); | |
| 208 | const at = files.findIndex((f) => f.name === `${version}.md`); | |
| 209 | if (at < 0) return none; | |
| 210 | const reader = readerFor(dir); | |
| 211 | const nearest = async (indexes: number[]): Promise<Wave | null> => { | |
| 212 | for (const i of indexes) { | |
| 213 | const f = files[i]!; | |
| 214 | if (f.size > MAX_BYTES) continue; | |
| 215 | const obj = await reader.object(f.oid); | |
| 216 | if (!obj.ok) continue; | |
| 217 | const parsed = parseWave(`waves/${f.name}`, new TextDecoder().decode(obj.value.body)); | |
| 218 | if (parsed.ok) return parsed.value; | |
| 219 | } | |
| 220 | return null; | |
| 221 | }; | |
| 222 | const after = Array.from({ length: files.length - at - 1 }, (_, k) => at + 1 + k); | |
| 223 | const before = Array.from({ length: at }, (_, k) => at - 1 - k); | |
| 224 | const [earlier, later] = await Promise.all([nearest(after), nearest(before)]); | |
| 225 | return { earlier, later }; | |
| 226 | } | |
| 227 | ||
| 187 | 228 | /** Unreadable files tried before giving up on finding the newest good wave. */ |
| 188 | 229 | const LATEST_TRIES = 5; |
| 189 | 230 |
src/web/pages/waves.ts +15 −2
| @@ -19,7 +19,7 @@ import { VERSION, type Wave } from "../../story/wave.ts"; | ||
| 19 | 19 | import { movedWithPulls, type MovedMilestone, shippedOf, shippedWords, waveProgress, widestMoved } from "../../story/wave_moved.ts"; |
| 20 | 20 | import { waveDuration } from "../../story/wave_duration.ts"; |
| 21 | 21 | import { carriedPulls, inLandingOrder, pullPath } from "../../story/wave_pulls.ts"; |
| 22 | import { appsOf, fromWave, inApp, parseAppFilter, pullRefs, readWave, readWaves, sizeWords, waveSize } from "../../story/waves.ts"; | |
| 22 | import { appsOf, fromWave, inApp, parseAppFilter, pullRefs, readWave, readWaves, sizeWords, waveNeighbours, wavePath, waveSize } from "../../story/waves.ts"; | |
| 23 | 23 | import { FIRST_WAVE_TELL, landedSentence, waveSentence } from "../../story/words.ts"; |
| 24 | 24 | import { wordClip } from "../../text/word_clip.ts"; |
| 25 | 25 | import { loadRepo, notFoundPage, repoBase, scopeHeader } from "../chrome.ts"; |
| @@ -216,6 +216,11 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 216 | 216 | ), |
| 217 | 217 | ); |
| 218 | 218 | if (!entry) return notFoundPage(ctx); |
| 219 | const near = entry.ok | |
| 220 | ? await timePhaseAsync(ctx.request, "neighbours", () => | |
| 221 | waveNeighbours(repoDir(ctx.app.reposRoot, repo.ownerName, repo.name), repo.defaultBranch, entry.wave.version), | |
| 222 | ) | |
| 223 | : { earlier: null, later: null }; | |
| 219 | 224 | const carried = entry.ok |
| 220 | 225 | ? timePhase(ctx.request, "pulls", () => |
| 221 | 226 | inLandingOrder(carriedPulls(ctx.app.db, pullRefs(entry.wave), ctx.auth.user)), |
| @@ -304,7 +309,7 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 304 | 309 | <p class="muted">Not a wave: ${entry.reason}</p>`; |
| 305 | 310 | |
| 306 | 311 | const body = html`${scopeHeader(ctx, scope, "none", { compact: true })} |
| 307 | <div class="mt">${content}<p>${back}</p></div>`; | |
| 312 | <div class="mt">${content}${neighbourNav(repo, near)}<p>${back}</p></div>`; | |
| 308 | 313 | |
| 309 | 314 | const response = page({ |
| 310 | 315 | ctx, |
| @@ -327,6 +332,14 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 327 | 332 | return response; |
| 328 | 333 | } |
| 329 | 334 | |
| 335 | /** `Earlier: <name>` and `Later: <name>` at the foot of a wave; a side with no wave has no link. */ | |
| 336 | function neighbourNav(repo: { ownerName: string; name: string }, near: { earlier: Wave | null; later: Wave | null }): Html { | |
| 337 | if (near.earlier === null && near.later === null) return html``; | |
| 338 | const link = (label: "Earlier" | "Later", w: Wave | null): Html => | |
| 339 | w === null ? html`` : html`<span data-wave-neighbour="${label.toLowerCase()}">${label}: <a href="${wavePath(repo.ownerName, repo.name, w.version)}">${w.headline}</a></span>`; | |
| 340 | return html`<nav class="small" aria-label="Neighbouring waves" data-wave-neighbours>${link("Earlier", near.earlier)} ${link("Later", near.later)}</nav>`; | |
| 341 | } | |
| 342 | ||
| 330 | 343 | /** The longest description a wave's card carries. */ |
| 331 | 344 | const WAVE_CARD_MAX = 200; |
| 332 | 345 |
test/wave-neighbours.test.ts added +66
| @@ -0,0 +1,66 @@ | ||
| 1 | /** | |
| 2 | * A wave's page links the wave before and after it, by escaped name, skipping files that are not | |
| 3 | * waves (#14554). | |
| 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 { createUser } from "../src/core/users.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { writeWave } from "../src/story/wave.ts"; | |
| 14 | ||
| 15 | let dir: string; | |
| 16 | let app: App; | |
| 17 | let servers: Servers; | |
| 18 | const wave = (version: string, headline: string): string => { | |
| 19 | const w = writeWave({ version, date: "2026-01-01", headline, highlights: [1, 2, 3].map((n) => ({ title: `T${n}`, why: "because" })), pulls: [] }); | |
| 20 | if (!w.ok) throw w.error; | |
| 21 | return w.value; | |
| 22 | }; | |
| 23 | const page = async (v: string) => await (await fetch(`${servers.url}/alice/pub/waves/${v}`)).text(); | |
| 24 | ||
| 25 | beforeAll(async () => { | |
| 26 | dir = await mkdtemp(join(tmpdir(), "forge-wave-neighbours-")); | |
| 27 | app = createApp({ dataDir: dir, port: 0 }); | |
| 28 | servers = await serve(app); | |
| 29 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 30 | if (!u.ok) throw new Error(u.error); | |
| 31 | const made = await createRepo(app, u.value, { name: "pub", visibility: "public" }); | |
| 32 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 33 | const c = await commitToBranch(app, u.value, made.value, { | |
| 34 | message: "waves", | |
| 35 | files: [ | |
| 36 | { path: "waves/0.1.0.md", content: wave("0.1.0", "Oldest") }, | |
| 37 | { path: "waves/0.2.0.md", content: wave("0.2.0", "Second <b>bold</b>") }, | |
| 38 | { path: "waves/0.3.0.md", content: wave("0.3.0", "Middle <i>one</i>") }, | |
| 39 | { path: "waves/0.4.0.md", content: "not a wave\n" }, | |
| 40 | { path: "waves/0.5.0.md", content: wave("0.5.0", "Newest") }, | |
| 41 | ], | |
| 42 | }); | |
| 43 | if (!c.ok) throw new Error(JSON.stringify(c.error)); | |
| 44 | }, 60_000); | |
| 45 | afterAll(async () => { | |
| 46 | servers.stop(); | |
| 47 | app.close(); | |
| 48 | await rm(dir, { recursive: true, force: true }); | |
| 49 | }); | |
| 50 | ||
| 51 | test("a middle wave links both neighbours, names escaped, a file that is no wave skipped", async () => { | |
| 52 | const body = await page("0.3.0"); | |
| 53 | expect(body).toContain('data-wave-neighbour="earlier">Earlier: <a href="/alice/pub/waves/0.2.0">Second <b>bold</b></a>'); | |
| 54 | expect(body).toContain('data-wave-neighbour="later">Later: <a href="/alice/pub/waves/0.5.0">Newest</a>'); | |
| 55 | }); | |
| 56 | test("the oldest has no Earlier link", async () => { | |
| 57 | const body = await page("0.1.0"); | |
| 58 | expect(body).not.toContain("Earlier:"); | |
| 59 | expect(body).toContain('Later: <a href="/alice/pub/waves/0.2.0">'); | |
| 60 | }); | |
| 61 | test("the newest has no Later link, and skips the file that is no wave", async () => { | |
| 62 | const body = await page("0.5.0"); | |
| 63 | expect(body).not.toContain("Later:"); | |
| 64 | expect(body).toContain('Earlier: <a href="/alice/pub/waves/0.3.0">Middle <i>one</i></a>'); | |
| 65 | expect(body).not.toContain("0.4.0"); | |
| 66 | }); |
new above
offline