Public: anyone can read this; the crew can change it.
A closed chapter's wave shows as an entry on /changelog itself, with its sentence and up to ten pull links #14226
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14221-a-closed-chapter-s-wave-shows-as-an-entr → main 9 commits fork 3 threads · 3 unresolved
7 files
changed +226
−10
docs/features/changelog.md +4
| @@ -89,3 +89,7 @@ A release still `pending` when the forge restarts is settled to `none` on boot: | ||
| 89 | 89 | ## Nothing released yet |
| 90 | 90 | |
| 91 | 91 | When no pull has landed, `/changelog` shows one sentence in place of the "Live:" line and "Nothing has shipped yet.": "Running <version · commit>; changes appear on release." A development build says "a development build" when no commit is known. The terminal's Changelog screen, with no releases, reads "No releases yet" and "Changes appear on release." The page is held to the first-view word budget in `test/attention.test.ts`, which is why the sentence is short. Tested in `test/changelog.test.ts`. |
| 92 | ||
| 93 | ## A closed chapter's wave | |
| 94 | ||
| 95 | When a chapter closes (for example one named `v1.1.0`), its wave is told on `/changelog`, in the JSON (`waves[].sentence`, `waves[].links`) and on the terminal's Changelog screen. The sentence is the chapter row's meta; a pull the wave names that the chapter's landed rows do not already list gets a row of its own, and on the terminal each such line carries its pull number, so Enter opens it. The page's tag holds the default branch tip of each repository, one ref read, and wave files are read only when the tag misses (`waveTips`, `withWaves` in `src/release/chapter_waves.ts`). To try it, close a chapter, then open `/changelog`. Tested in `test/changelog-chapters.test.ts`. |
src/release/answer.ts +2 −1
| @@ -10,6 +10,7 @@ import { getRepoById } from "../core/repos.ts"; | ||
| 10 | 10 | import type { User } from "../core/users.ts"; |
| 11 | 11 | import { releaseOf, running, shortOf } from "../kernel/version.ts"; |
| 12 | 12 | import { BOOTED, mayRead } from "./gate.ts"; |
| 13 | import { withWaves } from "./chapter_waves.ts"; | |
| 13 | 14 | import { chapterEntries, groupByChapter, wavesOf } from "./chapter_groups.ts"; |
| 14 | 15 | import { chosenRepo, readLandings, type Landing, type Landings } from "./landings.ts"; |
| 15 | 16 | import { keeperReleaseOfSha, type Stage } from "../keeper/record.ts"; |
| @@ -55,7 +56,7 @@ export async function shippedAnswer(app: App, asked: string | null = null) { | ||
| 55 | 56 | // else is all. |
| 56 | 57 | const named = asked !== null && /^[^/\s]{1,80}\/[^/\s]{1,80}$/.test(asked) ? asked : undefined; |
| 57 | 58 | const live = read.live.filter(keep); |
| 58 | const waves = wavesOf(groupByChapter(live, chapterEntries(app.db, live, undefined))); | |
| 59 | const waves = wavesOf(groupByChapter(live, await withWaves(app, chapterEntries(app.db, live, undefined)))); | |
| 59 | 60 | return { |
| 60 | 61 | // The release number, or null for a build that is not one: never the word "dev". |
| 61 | 62 | version: releaseOf({ version: read.version, commit: read.commit }), |
src/release/chapter_groups.ts +13 −4
| @@ -9,6 +9,7 @@ import type { Database } from "bun:sqlite"; | ||
| 9 | 9 | import { chapterOfPulls, listChapters, type Chapter } from "../core/chapters.ts"; |
| 10 | 10 | import { canRead, getRepo } from "../core/repos.ts"; |
| 11 | 11 | import type { User } from "../core/users.ts"; |
| 12 | import type { ChapterWave } from "./chapter_waves.ts"; | |
| 12 | 13 | import type { Landing } from "./landings.ts"; |
| 13 | 14 | |
| 14 | 15 | /** |
| @@ -20,10 +21,12 @@ export interface ChapterEntry { | ||
| 20 | 21 | readonly chapter: Chapter; |
| 21 | 22 | readonly canSee: boolean; |
| 22 | 23 | readonly pulls: readonly number[]; |
| 24 | /** What the chapter wrote when it closed, where it did (`chapter_waves.ts`). */ | |
| 25 | readonly wave?: ChapterWave; | |
| 23 | 26 | } |
| 24 | 27 | |
| 25 | 28 | export type Group = |
| 26 | | { readonly kind: "chapter"; readonly repo: string; readonly chapter: Chapter; readonly landings: readonly Landing[] } | |
| 29 | | { readonly kind: "chapter"; readonly repo: string; readonly chapter: Chapter; readonly landings: readonly Landing[]; readonly wave?: ChapterWave } | |
| 27 | 30 | | { readonly kind: "between"; readonly landings: readonly Landing[] }; |
| 28 | 31 | |
| 29 | 32 | /** Newest chapter first: the open one, then by closing time, later position breaking a tie. */ |
| @@ -50,7 +53,7 @@ export function groupByChapter(landings: readonly Landing[], entries: readonly C | ||
| 50 | 53 | const e = owner.get(`${l.repo.toLowerCase()}#${l.number}`); |
| 51 | 54 | (e === undefined ? between : served.get(e)!).push(l); |
| 52 | 55 | } |
| 53 | const out: Group[] = usable.map((e) => ({ kind: "chapter", repo: e.repo, chapter: e.chapter, landings: served.get(e)! })); | |
| 56 | const out: Group[] = usable.map((e) => ({ kind: "chapter", repo: e.repo, chapter: e.chapter, landings: served.get(e)!, ...(e.wave === undefined ? {} : { wave: e.wave }) })); | |
| 54 | 57 | if (between.length > 0) out.push({ kind: "between", landings: between }); |
| 55 | 58 | return out; |
| 56 | 59 | } |
| @@ -81,6 +84,12 @@ export function chapterEntries(db: Database, live: readonly Landing[], user: Use | ||
| 81 | 84 | * The chapters of a grouping as the answer tells them (waves): repository, name, closing time (null |
| 82 | 85 | * while open) and how many landed pulls it holds, in the page's order. |
| 83 | 86 | */ |
| 84 | export function wavesOf(groups: readonly Group[]): { repo: string; name: string; closed: string | null; pulls: number }[] { | |
| 85 | return groups.flatMap((g) => (g.kind === "chapter" ? [{ repo: g.repo, name: g.chapter.name, closed: g.chapter.closedAt, pulls: g.landings.length }] : [])); | |
| 87 | export function wavesOf( | |
| 88 | groups: readonly Group[], | |
| 89 | ): { repo: string; name: string; closed: string | null; pulls: number; sentence?: string; links?: { title: string; url: string }[] }[] { | |
| 90 | return groups.flatMap((g) => | |
| 91 | g.kind === "chapter" | |
| 92 | ? [{ repo: g.repo, name: g.chapter.name, closed: g.chapter.closedAt, pulls: g.landings.length, ...(g.wave === undefined ? {} : { sentence: g.wave.sentence, links: g.wave.pulls.map((p) => ({ ...p })) }) }] | |
| 93 | : [], | |
| 94 | ); | |
| 86 | 95 | } |
src/release/chapter_waves.ts added +110
| @@ -0,0 +1,110 @@ | ||
| 1 | /** | |
| 2 | * The wave a closed chapter wrote, read back for the changelog (#14221): the plain sentence and up | |
| 3 | * to ten pull links of `waves/<version>.md`, as the page, its JSON and the terminal all tell them. | |
| 4 | * No new storage: the file is the one `actions/chapter_wave.ts` committed. A chapter with no such | |
| 5 | * file (open, not a version, written before waves, unreadable) has none, and says nothing. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { App } from "../app.ts"; | |
| 9 | import { getRepo } from "../core/repos.ts"; | |
| 10 | import { repoDir } from "../git/repos.ts"; | |
| 11 | import { readTip } from "../git/tip.ts"; | |
| 12 | import { versionOfChapter, MAX_CHAPTER_PULLS } from "../story/wave.ts"; | |
| 13 | import { readWave } from "../story/waves.ts"; | |
| 14 | import type { ChapterEntry } from "./chapter_groups.ts"; | |
| 15 | ||
| 16 | export interface ChapterWave { | |
| 17 | readonly version: string; | |
| 18 | readonly sentence: string; | |
| 19 | /** | |
| 20 | * Each pull the wave names: its title, link and number in the repository (rows open it by | |
| 21 | * number). | |
| 22 | */ | |
| 23 | readonly pulls: readonly { readonly title: string; readonly url: string; readonly number: number }[]; | |
| 24 | } | |
| 25 | ||
| 26 | /** | |
| 27 | * What a branch tip held, kept while the tip stands: a request costs one ref read, not a tree read. | |
| 28 | */ | |
| 29 | const KEPT = 200; | |
| 30 | const keptOf = new WeakMap<App, Map<string, ChapterWave | null>>(); | |
| 31 | ||
| 32 | function keptFor(app: App): Map<string, ChapterWave | null> { | |
| 33 | let m = keptOf.get(app); | |
| 34 | if (m === undefined) keptOf.set(app, (m = new Map())); | |
| 35 | return m; | |
| 36 | } | |
| 37 | ||
| 38 | const PULL_PATH = /\/pulls\/([1-9]\d{0,8})\/?$/; | |
| 39 | ||
| 40 | /** The pulls of a wave that link to one, with their numbers; any other link is left out. */ | |
| 41 | function numbered(pulls: readonly { title: string; url: string }[]): ChapterWave["pulls"] { | |
| 42 | const out: { title: string; url: string; number: number }[] = []; | |
| 43 | for (const p of pulls) { | |
| 44 | let path: string; | |
| 45 | try { | |
| 46 | path = new URL(p.url, "http://forge.invalid").pathname; | |
| 47 | } catch { | |
| 48 | continue; | |
| 49 | } | |
| 50 | const m = PULL_PATH.exec(path); | |
| 51 | if (m !== null) out.push({ ...p, number: Number(m[1]) }); | |
| 52 | } | |
| 53 | return out.slice(0, MAX_CHAPTER_PULLS); | |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * A repository's directory, default branch and tip: one ref read, the whole cost of a wave already | |
| 58 | * kept. | |
| 59 | */ | |
| 60 | async function tipOf(app: App, repoName: string): Promise<{ dir: string; branch: string; tip: string | undefined } | undefined> { | |
| 61 | const [o = "", n = ""] = repoName.split("/"); | |
| 62 | const repo = getRepo(app.db, o, n); | |
| 63 | if (repo === undefined) return undefined; | |
| 64 | const dir = repoDir(app.reposRoot, repo.ownerName, repo.name); | |
| 65 | return { dir, branch: repo.defaultBranch, tip: await readTip(dir, `refs/heads/${repo.defaultBranch}`) }; | |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * What the repositories' default branches stand at, one ref read each and no wave file: the page's | |
| 70 | * tag holds this, so a request nothing changed for answers 304 without reading any wave (#14221). | |
| 71 | */ | |
| 72 | export async function waveTips(app: App, repoNames: readonly string[]): Promise<string[]> { | |
| 73 | const names = [...new Set(repoNames)].sort(); | |
| 74 | return Promise.all(names.map(async (r) => `${r}@${(await tipOf(app, r))?.tip ?? ""}`)); | |
| 75 | } | |
| 76 | ||
| 77 | async function waveAt(app: App, at: { dir: string; branch: string; tip: string | undefined }, version: string): Promise<ChapterWave | undefined> { | |
| 78 | const { dir, tip } = at; | |
| 79 | const kept = keptFor(app); | |
| 80 | const key = tip === undefined ? undefined : `${dir}|${tip}|${version}`; | |
| 81 | if (key !== undefined && kept.has(key)) return kept.get(key) ?? undefined; | |
| 82 | const read = await readWave(dir, at.branch, version).catch(() => null); | |
| 83 | const wave: ChapterWave | null = | |
| 84 | read?.ok === true | |
| 85 | ? { version, sentence: read.wave.headline, pulls: numbered(read.wave.pulls) } | |
| 86 | : null; | |
| 87 | if (key !== undefined) { | |
| 88 | if (kept.size >= KEPT) kept.delete(kept.keys().next().value as string); | |
| 89 | kept.set(key, wave); | |
| 90 | } | |
| 91 | return wave ?? undefined; | |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * The entries, each closed chapter of a readable repository carrying its wave when it wrote one. | |
| 96 | */ | |
| 97 | export async function withWaves(app: App, entries: readonly ChapterEntry[]): Promise<ChapterEntry[]> { | |
| 98 | const tips = new Map<string, ReturnType<typeof tipOf>>(); | |
| 99 | return Promise.all( | |
| 100 | entries.map(async (e) => { | |
| 101 | const version = e.chapter.state === "closed" && e.canSee ? versionOfChapter(e.chapter.name) : undefined; | |
| 102 | if (version === undefined) return e; | |
| 103 | if (!tips.has(e.repo)) tips.set(e.repo, tipOf(app, e.repo)); | |
| 104 | const at = await tips.get(e.repo)!; | |
| 105 | if (at === undefined) return e; | |
| 106 | const wave = await waveAt(app, at, version); | |
| 107 | return wave === undefined ? e : { ...e, wave }; | |
| 108 | }), | |
| 109 | ); | |
| 110 | } |
src/tui/screens/changelog.ts +6 −1
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import { chapterOfPulls, listChapters } from "../../core/chapters.ts"; |
| 11 | import { withWaves } from "../../release/chapter_waves.ts"; | |
| 11 | 12 | import { groupByChapter, type ChapterEntry, type Group } from "../../release/chapter_groups.ts"; |
| 12 | 13 | import { gather, plainTitle } from "../../story/gather.ts"; |
| 13 | 14 | import { monthLabel } from "../../release/month.ts"; |
| @@ -78,6 +79,10 @@ export function chapterLines(groups: readonly Group[], keep: (l: Landing) => boo | ||
| 78 | 79 | const title = g.kind === "chapter" ? `Chapter ${g.chapter.name}` : "Between chapters"; |
| 79 | 80 | const when = g.kind === "chapter" ? (g.chapter.closedAt === null ? "open" : `closed ${g.chapter.closedAt.slice(0, 10)}`) : ""; |
| 80 | 81 | out.push({ row: { title, meta: metaOf(when, `${pulls.length} ${pulls.length === 1 ? "pull" : "pulls"}`) } }); |
| 82 | if (g.kind === "chapter" && g.wave !== undefined && !filtering) { | |
| 83 | out.push({ row: { title: ` ${g.wave.sentence}` } }); | |
| 84 | for (const p of g.wave.pulls) out.push({ row: { title: ` #${p.number} ${plainTitle(p.title)}` }, pull: p.number }); | |
outdated
Both doors: these rows carry no |
||
| 85 | } | |
| 81 | 86 | for (const l of pulls) out.push({ row: { title: ` #${l.number} ${plainTitle(l.title)}`.trimEnd(), meta: ago(l.at) }, pull: l.number }); |
| 82 | 87 | } |
| 83 | 88 | return out; |
| @@ -256,7 +261,7 @@ export function changelogScreen(f: Session, ctx: Ctx): Screen { | ||
| 256 | 261 | pulls: [...served].filter(([, id]) => id === chapter.id).map(([n]) => n), |
| 257 | 262 | })); |
| 258 | 263 | const live = (landings?.live ?? []).filter((l) => l.repo.toLowerCase() === name.toLowerCase()); |
| 259 | groups = groupByChapter(live, entries); | |
| 264 | groups = groupByChapter(live, await withWaves(f.app, entries)); | |
| 260 | 265 | } |
| 261 | 266 | near = nearLines(nearMilestones(f.app, f.app.config.forgeRepo, f.user)?.near ?? []); |
| 262 | 267 | home(); |
src/web/pages/changelog.ts +14 −4
| @@ -12,6 +12,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 12 | 12 | import { betNamesOfPulls } from "../../core/bets.ts"; |
| 13 | 13 | import { sourcesOfPulls } from "../../core/trusted_sources.ts"; |
| 14 | 14 | import { canRead, getRepo, type Repo } from "../../core/repos.ts"; |
| 15 | import { waveTips, withWaves } from "../../release/chapter_waves.ts"; | |
| 15 | 16 | import { chapterEntries, groupByChapter, type ChapterEntry, type Group } from "../../release/chapter_groups.ts"; |
| 16 | 17 | import type { Database } from "bun:sqlite"; |
| 17 | 18 | import { newestLive, secondsWords } from "../../keeper/landed.ts"; |
| @@ -133,14 +134,20 @@ export function chapterStamp(db: Database): string { | ||
| 133 | 134 | */ |
| 134 | 135 | function chapterSection(g: Extract<Group, { kind: "chapter" }>, own: string | undefined, showRepo: boolean): Html { |
| 135 | 136 | const c = g.chapter; |
| 137 | // The wave's sentence is the head row's meta; its pulls that the landings below do not already | |
| 138 | // list are rows of their own, so no pull is told twice. | |
| 139 | const listed = new Set(g.landings.filter((l) => l.repo === g.repo).map((l) => l.number)); | |
| 140 | const more = (g.wave?.pulls ?? []).filter((p) => !listed.has(p.number)); | |
| 136 | 141 | const head = row({ |
| 137 | 142 | href: `/${g.repo}/chapters/${c.name}`, |
| 138 | 143 | nav: true, |
| 139 | 144 | title: c.name, |
| 140 | ...(g.landings.length === 0 ? { meta: html`Nothing landed yet.` } : {}), | |
| 145 | ...(g.wave !== undefined ? { meta: html`${g.wave.sentence}` } : g.landings.length === 0 ? { meta: html`Nothing landed yet.` } : {}), | |
| 141 | 146 | trail: c.closedAt === null ? html`open` : time(c.closedAt, { date: true }), |
| 147 | ...(g.wave === undefined ? {} : { data: { wave: "" } }), | |
outdated
Principles 1, 6, 7: hand-rolled |
||
| 142 | 148 | }); |
| 143 | return html`<section class="mt" data-chapter="${c.name}"><ul class="list setting-list">${head}${g.landings.map((l) => landingRow(l, own, showRepo))}</ul></section>`; | |
| 149 | const waveRows = more.map((p) => row({ href: p.url, nav: true, title: p.title, meta: html`#${p.number}` })); | |
| 150 | return html`<section class="mt" data-chapter="${c.name}"><ul class="list setting-list">${head}${waveRows}${g.landings.map((l) => landingRow(l, own, showRepo))}</ul></section>`; | |
| 144 | 151 | } |
| 145 | 152 | |
| 146 | 153 | /** The pulls that served no chapter, under a row of the same shape as a chapter's. */ |
| @@ -353,15 +360,18 @@ export async function changelogPage(ctx: Ctx): Promise<Response> { | ||
| 353 | 360 | // One aggregate read stands for the chapters in the tag; the per-repository reads wait until the |
| 354 | 361 | // tag has missed. |
| 355 | 362 | const stamp = chapterStamp(ctx.app.db); |
| 363 | // A closed chapter's wave lands after the close itself, so the tag holds what the waves say too | |
| 364 | // (#14221). | |
| 365 | const tips = await waveTips(ctx.app, read.live.map((l) => l.repo)); | |
| 356 | 366 | // The tag comes from what the page would say, before any of it is rendered: |
| 357 | 367 | // a match answers 304 without building the page. |
| 358 | 368 | const toLive = newestLive(ctx.app.db); |
| 359 | 369 | const target = askedAnchor(ctx.url.searchParams.get("release")); |
| 360 | 370 | const flashed = readFlash(ctx.request) !== undefined; |
| 361 | const tag = flashed ? undefined : changelogTag(read.version, everything, [choice, bet, read.commit, read.live.map((l) => `${l.repo}#${l.number}`), readable, toLive ?? null, everything.map((l) => timeAgo(l.at)), new Date().toISOString().slice(0, 10), releases?.entries[0]?.oid ?? null, releases?.entries.length ?? 0, ctx.auth.user?.id ?? null, ctx.auth.user?.isAdmin === true, ctx.theme ?? null, near, stamp, read.more ?? null, ctx.url.searchParams.get("before") === null ? 0 : 1, target ?? null]); | |
| 371 | const tag = flashed ? undefined : changelogTag(read.version, everything, [choice, bet, read.commit, read.live.map((l) => `${l.repo}#${l.number}`), readable, toLive ?? null, everything.map((l) => timeAgo(l.at)), new Date().toISOString().slice(0, 10), releases?.entries[0]?.oid ?? null, releases?.entries.length ?? 0, ctx.auth.user?.id ?? null, ctx.auth.user?.isAdmin === true, ctx.theme ?? null, near, stamp, tips, read.more ?? null, ctx.url.searchParams.get("before") === null ? 0 : 1, target ?? null]); | |
| 362 | 372 | const keep = tag === undefined ? undefined : cacheHeaders(ctx, tag); |
| 363 | 373 | if (keep !== undefined && keep.matched) return keep.response; |
| 364 | const chapters = chapterEntries(ctx.app.db, read.live, ctx.auth.user); | |
| 374 | const chapters = await withWaves(ctx.app, chapterEntries(ctx.app.db, read.live, ctx.auth.user)); | |
| 365 | 375 | const rendering = performance.now(); |
| 366 | 376 | const filters = seg([ |
| 367 | 377 | ...(read.own === undefined ? [] : [{ label: "This forge", href: "/changelog", current: choice === read.own }]), |
test/changelog-chapters.test.ts +77
| @@ -3,12 +3,21 @@ import { expect, test } from "bun:test"; | ||
| 3 | 3 | import type { Chapter } from "../src/core/chapters.ts"; |
| 4 | 4 | import type { Landing, Landings } from "../src/release/landings.ts"; |
| 5 | 5 | import { chapterStamp, shippedRegion } from "../src/web/pages/changelog.ts"; |
| 6 | import { withWaves } from "../src/release/chapter_waves.ts"; | |
| 7 | import { chapterLines } from "../src/tui/screens/changelog.ts"; | |
| 6 | 8 | import { chapterEntries, groupByChapter, type ChapterEntry } from "../src/release/chapter_groups.ts"; |
| 7 | 9 | import { chapterOfPulls } from "../src/core/chapters.ts"; |
| 8 | 10 | import { createRepo } from "../src/actions/repos.ts"; |
| 9 | 11 | import { getRepo } from "../src/core/repos.ts"; |
| 10 | 12 | import { createUser } from "../src/core/users.ts"; |
| 11 | 13 | import { createApp } from "../src/app.ts"; |
| 14 | import { newApp } from "../src/actions/apps.ts"; | |
| 15 | import { close, draft, fill, open } from "../src/actions/chapters.ts"; | |
| 16 | import { createIssue } from "../src/core/issues.ts"; | |
| 17 | import { repoDir } from "../src/git/repos.ts"; | |
| 18 | import { commitFiles } from "../src/git/write.ts"; | |
| 19 | import { serve } from "../src/http/server.ts"; | |
| 20 | import { quietLogs } from "./helpers/globals.ts"; | |
| 12 | 21 | import { mkdtempSync } from "node:fs"; |
| 13 | 22 | import { tmpdir } from "node:os"; |
| 14 | 23 | import { join } from "node:path"; |
| @@ -175,3 +184,71 @@ test("a pull that closes issues in two chapters is placed in the first match, in | ||
| 175 | 184 | app.close(); |
| 176 | 185 | } |
| 177 | 186 | }); |
| 187 | ||
| 188 | quietLogs(); | |
| 189 | ||
| 190 | test("a closed chapter's wave is an entry on /changelog, in its JSON and on the terminal's lines; the tag moves when it lands (#14221)", async () => { | |
| 191 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "forge-chap-")), port: 0, host: "forge.test" }); | |
| 192 | const servers = await serve(app); | |
| 193 | try { | |
| 194 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 195 | if (!u.ok) throw new Error(u.error); | |
| 196 | const a = await newApp(app, u.value, { name: "shop", description: "Words", visibility: "public" }); | |
| 197 | if (!a.ok) throw new Error(String(a.error)); | |
| 198 | const repo = getRepo(app.db, "alice", "shop")!; | |
| 199 | const first = await commitFiles(repoDir(app.reposRoot, "alice", "shop"), { branch: repo.defaultBranch, message: "first", files: [{ path: "README.md", content: "hi" }], author: { name: "T", email: "[email protected]" } }); | |
| 200 | if (!first.ok) throw new Error("commit"); | |
| 201 | expect(draft(app, u.value, repo, { name: "v1.1.0" }).ok).toBe(true); | |
| 202 | for (let k = 1; k <= 12; k++) { | |
| 203 | const made = createIssue(app.db, { repoId: repo.id, authorId: u.value.id, title: `Item ${k}`, body: "" }); | |
| 204 | if (!made.ok) throw new Error(String(made.error)); | |
| 205 | app.db.query("UPDATE issue SET state = 'closed', closed_at = ?2 WHERE id = ?1").run(made.value.id, "2026-11-10T00:00:00.000Z"); | |
| 206 | const n = 7000 + k; | |
| 207 | app.db.query(`INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state) VALUES (?1, ?2, ?3, 'pull', ?4, ?5, ?6, 'closed')`).run(`p${n}`, repo.id, n, `Build ${k}`, `Closes #${made.value.number}`, u.value.id); | |
| 208 | app.db.query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', ?2, 'a', 'b', '2026-11-10T00:00:00.000Z')`).run(`p${n}`, `b${n}`); | |
| 209 | app.db.query(`INSERT INTO release (sha, repo_id, pull_number, ok, line, created_at) VALUES ('abc', ?1, ?2, 1, 'ok', '2026-11-11T08:00:00.000Z')`).run(repo.id, n); | |
| 210 | expect(fill(app, u.value, repo, "v1.1.0", made.value.number, true).ok).toBe(true); | |
| 211 | } | |
| 212 | expect(open(app, u.value, repo, "v1.1.0").ok).toBe(true); | |
| 213 | const sentence = "v1.1.0 shipped 12 changes: Item 1, Item 2, Item 3, and 9 more."; | |
| 214 | const before = await fetch(`${servers.url}/changelog?repo=alice/shop`); | |
| 215 | const beforeTag = before.headers.get("etag"); | |
| 216 | expect(await before.text()).not.toContain(sentence); | |
| 217 | expect((await close(app, u.value, repo, "v1.1.0", false, new Date("2026-11-16T12:00:00.000Z"))).ok).toBe(true); | |
| 218 | const res = await fetch(`${servers.url}/changelog?repo=alice/shop`); | |
| 219 | const page = await res.text(); | |
| 220 | expect(page).toContain(sentence); | |
| 221 | const section = /<section class="mt" data-chapter="v1.1.0">.*?<\/section>/s.exec(page)?.[0] ?? ""; | |
| 222 | expect(section).toContain("data-wave"); | |
| 223 | expect(section).not.toContain("<ul><li>"); | |
| 224 | // Every pull the chapter holds is a row once: the wave's links add none the landings list. | |
| 225 | expect(section.match(/href="\/alice\/shop\/pulls\/7001"/g)).toHaveLength(1); | |
| 226 | // A repeat is a 304 that reads no wave. | |
| 227 | const again = await fetch(`${servers.url}/changelog?repo=alice/shop`, { headers: { "if-none-match": res.headers.get("etag")! } }); | |
| 228 | expect(again.status).toBe(304); | |
| 229 | expect(res.headers.get("etag")).not.toBe(beforeTag); | |
| 230 | const json = (await (await fetch(`${servers.url}/api/v1/changelog?repo=alice/shop`)).json()) as { waves: { name: string; sentence?: string; links?: { url: string }[] }[] }; | |
| 231 | const w = json.waves.find((x) => x.name === "v1.1.0")!; | |
| 232 | expect(w.sentence).toBe(sentence); | |
| 233 | expect(w.links).toHaveLength(10); | |
| 234 | const live = [{ repo: "alice/shop", number: 7001, title: "Build 1", at: "2026-11-10T00:00:00.000Z", live: true }]; | |
| 235 | const entries = await withWaves(app, chapterEntries(app.db, live, undefined)); | |
| 236 | const lines = chapterLines(groupByChapter(live, entries)); | |
| 237 | expect(lines.map((l) => l.row.title)).toContain(` ${sentence}`); | |
| 238 | const links = lines.filter((l) => l.row.title.startsWith(" #")); | |
| 239 | expect(links).toHaveLength(10); | |
| 240 | expect(links.map((l) => l.pull)).toEqual(Array.from({ length: 10 }, (_, i) => 7001 + i)); | |
| 241 | } finally { | |
| 242 | servers.stop(); | |
| 243 | app.close(); | |
| 244 | } | |
| 245 | }, 30_000); | |
| 246 | ||
| 247 | test("a wave's pull that no landing lists gets a row of its own, and one that is listed does not repeat (#14221)", () => { | |
| 248 | const wave = { version: "v2", sentence: "v2 shipped 2 changes.", pulls: [{ title: "Listed", url: "/a/b/pulls/20", number: 20 }, { title: "Unlisted", url: "/a/b/pulls/99", number: 99 }] }; | |
| 249 | const e = { ...entry(chapter("v2", day(21), 2), [20]), wave }; | |
| 250 | const html = String(shippedRegion(read(landings), "a/b", NOW, "UTC", undefined, true, [e])); | |
| 251 | expect(html).toContain("v2 shipped 2 changes."); | |
| 252 | expect(html.match(/href="\/a\/b\/pulls\/20"/g)).toHaveLength(1); | |
| 253 | expect(html.match(/href="\/a\/b\/pulls\/99"/g)).toHaveLength(1); | |
| 254 | }); |
new above
offline
A ref read per closed chapter on every request, before the ETag is built, defeats the 304 fast path. Hash the tips into the tag and read waves only on a miss.