Public: anyone can read this; the crew can change it.
/changelog.atom lists the latest 20 releases as entries; production's feed has none #13079
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/13066-changelog-atom-lists-the-latest-20-relea → main 11 commits fork 4 threads · 4 unresolved
6 files
changed +183
−34
docs/features/atom.md +2 −1
| @@ -2,7 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | Follow with a reader, no account needed. Each page that has a feed advertises it with `<link rel="alternate" type="application/atom+xml">`. |
| 4 | 4 | |
| 5 | - `/changelog.atom`, `/explore.atom`: what went live; the ranked public apps. | |
| 5 | - `/changelog.atom`: the newest 20 releases, newest first, each with a one-sentence summary and a link to its row's anchor on `/changelog` (`?release=…#release-…`, which opens the row's fold if it has one). See `changelog.md`. | |
| 6 | - `/explore.atom`: the ranked public apps. | |
| 6 | 7 | - `/{owner}/{name}/activity.atom`: a repository's activity. |
| 7 | 8 | - `/{owner}/{name}/ships.atom`: the newest 30 merged pulls of a repository (title, link, merge time, author). Linked from the repository page. |
| 8 | 9 | - `/{owner}.atom`: the newest 30 public posts of a person (issues they opened on repositories a stranger may read). Linked from their profile. |
docs/features/changelog.md +1 −1
| @@ -30,7 +30,7 @@ A squash keeps the people behind its commits: the landed message carries every d | ||
| 30 | 30 | |
| 31 | 31 | ## As a feed (#8213) |
| 32 | 32 | |
| 33 | `GET /changelog.atom` is the same list as an Atom feed, public, for a feed reader. It holds the newest 50 live landings of the forge's own repository (`FORGE_REPO`, public only), one entry each titled `Went live: <title>` and linked to its pull; what has landed but is not yet live is left out. A landing a wave covers collapses into one entry per wave (not per release or per landing): the wave's headline is the title, its highlights the summary, the link goes to the wave's page, and the entry is dated at the wave's newest landing. Waves are read from the forge repository's default branch, so the `ETag` moves with that branch's tip as well as with the list. The tip is read on every request, the 304 path included; the five-minute cache is what keeps git off the hot path. The 50 is the feed's own cap (`CHANGELOG_ENTRIES` in `web/feeds.ts`); the page and `/api/v1/changelog` are not capped. It is cached for five minutes (`cache-control: public, max-age=300`) and carries a weak `ETag`, so a reader that sends `If-None-Match` gets a 304. The page links it with `rel="alternate"`. | |
| 33 | `GET /changelog.atom` is the same list as an Atom feed, public, for a feed reader. It holds the newest 20 live landings of the forge's own repository (`FORGE_REPO`, public only), newest first, one entry each titled `Went live: <title>` with a one-sentence summary (`Landed in <repo> as pull #<n> on <date> and is live.`) and linked to that release's row on the page, `/changelog?release=release-<owner>-<name>-<n>#release-<owner>-<name>-<n>` (the row's `id`, from `release/anchor.ts`). The `release=` part opens a gathered line that holds the row, so the link lands on a row you can see without any script. what has landed but is not yet live is left out. A landing a wave covers collapses into one entry per wave (not per release or per landing): the wave's headline is the title, its highlights the summary, the link goes to the wave's page, and the entry is dated at the wave's newest landing. Waves are read from the forge repository's default branch, so the `ETag` moves with that branch's tip as well as with the list. The tip is read on every request, the 304 path included; the five-minute cache is what keeps git off the hot path. The 20 is the feed's own cap (`CHANGELOG_ENTRIES` in `web/feeds.ts`); the page and `/api/v1/changelog` are not capped. It is cached for five minutes (`cache-control: public, max-age=300`) and carries a weak `ETag`, so a reader that sends `If-None-Match` gets a 304. The page links it with `rel="alternate"`. | |
| 34 | 34 | |
| 35 | 35 | An agent reads the same data as JSON, not Atom: MCP `releases` with `{shipped: true}` or `GET /api/v1/changelog` (see above). The terminal has no screen for the feed, since a feed is for a reader program; its Changelog screen is the release-commit view. |
| 36 | 36 |
src/release/anchor.ts added +20
| @@ -0,0 +1,20 @@ | ||
| 1 | /** | |
| 2 | * The anchor of one release row on /changelog: the page's `<li id>` and the Atom entry's link | |
| 3 | * share it. | |
| 4 | */ | |
| 5 | ||
| 6 | /** | |
| 7 | * `release-owner-name-123`: lower-case words and dashes only, so it needs no escaping in an id | |
| 8 | * or a URL. | |
| 9 | */ | |
| 10 | export function releaseAnchor(repo: string, number: number): string { | |
| 11 | return `release-${repo.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}-${number}`; | |
| 12 | } | |
| 13 | ||
| 14 | /** | |
| 15 | * The `?release=` a link asks the page to show: an anchor's shape (at most 200 characters), or | |
| 16 | * undefined. The page opens the fold holding that row, so a link lands without JavaScript. | |
| 17 | */ | |
| 18 | export function askedAnchor(asked: string | null): string | undefined { | |
| 19 | return asked !== null && asked.length <= 200 && /^release-[a-z0-9-]+-\d+$/.test(asked) ? asked : undefined; | |
| 20 | } |
src/web/feeds.ts +8 −2
| @@ -26,6 +26,7 @@ import { pullRefs, readWaves, wavePath } from "../story/waves.ts"; | ||
| 26 | 26 | import type { Wave } from "../story/wave.ts"; |
| 27 | 27 | import { refTip } from "../git/read.ts"; |
| 28 | 28 | import { repoDir } from "../git/repos.ts"; |
| 29 | import { releaseAnchor } from "../release/anchor.ts"; | |
| 29 | 30 | import { shippedAnswer } from "../release/answer.ts"; |
| 30 | 31 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../core/route_timing.ts"; |
| 31 | 32 | import type { Ctx } from "../http/context.ts"; |
| @@ -198,7 +199,8 @@ ${entries.join("\n")} | ||
| 198 | 199 | }); |
| 199 | 200 | } |
| 200 | 201 | |
| 201 | const CHANGELOG_ENTRIES = 30; | |
| 202 | /** The newest releases the feed lists: 20 entries stay well under 20 KB. */ | |
| 203 | export const CHANGELOG_ENTRIES = 20; | |
| 202 | 204 | |
| 203 | 205 | /** Waves by the forge repository's default-branch tip, so the common request reads no files. */ |
| 204 | 206 | const waveCache = new Map<string, Wave[]>(); |
| @@ -280,12 +282,16 @@ export async function changelogAtom(ctx: Ctx): Promise<Response> { | ||
| 280 | 282 | <summary>${xml(summary)}</summary> |
| 281 | 283 | </entry>`]; |
| 282 | 284 | } |
| 283 | const link = `${origin}/${l.repo}/pulls/${l.number}`; | |
| 285 | // The page opens on the forge's own repository; another repository's rows sit under its filter. | |
| 286 | // `release=` opens the fold holding the row, so the fragment lands on a shown element. | |
| 287 | const anchor = releaseAnchor(l.repo, l.number); | |
| 288 | const link = `${origin}/changelog?${l.repo === `${ownerName}/${repoName}` ? "" : `repo=${encodeURIComponent(l.repo)}&`}release=${anchor}#${anchor}`; | |
| 284 | 289 | return [` <entry> |
| 285 | 290 | <id>urn:forge:landing:${xml(l.repo)}#${l.number}</id> |
| 286 | 291 | <title>${xml(`Went live: ${plainTitle(l.title)}`)}</title> |
| 287 | 292 | <updated>${xml(stamp(l.at))}</updated> |
| 288 | 293 | <link rel="alternate" type="text/html" href="${xml(link)}"/> |
| 294 | <summary>${xml(`Landed in ${l.repo} as pull #${l.number} on ${stamp(l.at).slice(0, 10)} and is live.`)}</summary> | |
| 289 | 295 | </entry>`]; |
| 290 | 296 | }); |
| 291 | 297 | const updated = live[0]?.at ?? STARTED; |
src/web/pages/changelog.ts +40 −21
| @@ -18,6 +18,7 @@ import type { User } from "../../core/users.ts"; | ||
| 18 | 18 | import { newestLive, secondsWords } from "../../keeper/landed.ts"; |
| 19 | 19 | import { dayHeading, dayOf, daysJs, shippedToday } from "../../release/days.ts"; |
| 20 | 20 | import { hasMerged, mergedRows, readLandings, type Landing, type Landings, type MergedRow } from "../../release/landings.ts"; |
| 21 | import { askedAnchor, releaseAnchor } from "../../release/anchor.ts"; | |
| 21 | 22 | import { gather, plainTitle, type Gathered } from "../../story/gather.ts"; |
| 22 | 23 | import { milestoneHref, progress } from "./milestones.ts"; |
| 23 | 24 | import { nearMilestones, nearWords, type Near } from "./milestones_near.ts"; |
| @@ -56,6 +57,7 @@ const FILTERS = 6; | ||
| 56 | 57 | function landingRow(l: Landing, own: string | undefined, showRepo: boolean): Html { |
| 57 | 58 | return row({ |
| 58 | 59 | href: `/${l.repo}/pulls/${l.number}`, |
| 60 | id: releaseAnchor(l.repo, l.number), | |
Rows in a closed fold carry this id but are hidden, so /changelog#release-… lands on nothing for older releases. Make the target visible without JavaScript and test it. |
||
| 59 | 61 | nav: true, |
| 60 | 62 | title: plainTitle(l.title), |
| 61 | 63 | meta: html`${showRepo || l.repo !== own ? html`${l.repo} · ` : null}#${l.number}${l.bet === undefined ? null : html` · ${badge(l.bet, { variant: "outline" })}`}${l.from === undefined ? null : html` · folded in from ${l.from}`}`, |
| @@ -64,8 +66,11 @@ function landingRow(l: Landing, own: string | undefined, showRepo: boolean): Htm | ||
| 64 | 66 | }); |
| 65 | 67 | } |
| 66 | 68 | |
| 67 | /** Several landings of one shape as one line, opening in place to each pull; who built them is said once. */ | |
| 68 | function gatheredRow(g: Gathered<Landing>, own: string | undefined, showRepo: boolean, day: string): Html { | |
| 69 | /** | |
| 70 | * Several landings of one shape as one line, opening in place to each pull; who built them is said | |
| 71 | * once. | |
| 72 | */ | |
| 73 | function gatheredRow(g: Gathered<Landing>, own: string | undefined, showRepo: boolean, day: string, target?: string): Html { | |
| 69 | 74 | const first = g.landings[0]!; |
| 70 | 75 | const credit = [...(g.by.length === 0 ? [] : [g.by.join(", ")]), ...(g.with.length === 0 ? [] : [`with ${g.with.join(", ")}`])].join(" · "); |
| 71 | 76 | const quiet = g.landings.map(({ by: _by, with: _with, ...l }): Landing => l); |
| @@ -74,14 +79,16 @@ function gatheredRow(g: Gathered<Landing>, own: string | undefined, showRepo: bo | ||
| 74 | 79 | meta: html`${g.landings.length} pulls${credit === "" ? null : html` · ${credit}`}`, |
| 75 | 80 | trail: time(first.at), |
| 76 | 81 | data: { count: String(g.landings.length) }, |
| 77 | fold: { open: false, id: `gathered-${day}-${first.repo.replace(/[^a-z0-9]+/gi, "-")}-${first.number}`, body: html`<ul class="row-children list setting-list">${quiet.map((l) => landingRow(l, own, showRepo))}</ul>` }, | |
| 82 | // A link to one of these rows (`?release=`, from the feed) opens the fold, | |
| 83 | // so it lands without JavaScript. | |
| 84 | fold: { open: target !== undefined && g.landings.some((l) => releaseAnchor(l.repo, l.number) === target), id: `gathered-${day}-${first.repo.replace(/[^a-z0-9]+/gi, "-")}-${first.number}`, body: html`<ul class="row-children list setting-list">${quiet.map((l) => landingRow(l, own, showRepo))}</ul>` }, | |
| 78 | 85 | }); |
| 79 | 86 | } |
| 80 | 87 | |
| 81 | 88 | /** |
| 82 | * One query that moves whenever a chapter opens, closes, is reopened or deleted, an item joins, leaves | |
| 83 | * or moves between them, or a repository with one changes visibility: what the page's tag holds in place of | |
| 84 | * the chapters themselves. | |
| 89 | * One query that moves whenever a chapter opens, closes, is reopened or deleted, an item joins, | |
| 90 | * leaves or moves between them, or a repository with one changes visibility: what the page's tag | |
| 91 | * holds in place of the chapters themselves. | |
| 85 | 92 | */ |
| 86 | 93 | export function chapterStamp(db: Database): string { |
| 87 | 94 | const r = db |
| @@ -138,12 +145,15 @@ function betweenSection(g: Extract<Group, { kind: "between" }>, own: string | un | ||
| 138 | 145 | return html`<section class="mt" data-between><ul class="list setting-list">${row({ title: "Between chapters" })}${g.landings.map((l) => landingRow(l, own, showRepo))}</ul></section>`; |
| 139 | 146 | } |
| 140 | 147 | |
| 141 | /** Day sections in `zone`; the browser regroups them in its own (see `localDaysJs`), so the zone is named while it has not. */ | |
| 142 | function byDay(list: readonly Landing[], own: string | undefined, showRepo: boolean, zone: string, today: string): Html[] { | |
| 148 | /** | |
| 149 | * Day sections in `zone`; the browser regroups them in its own (see `localDaysJs`), so the zone is | |
| 150 | * named while it has not. | |
| 151 | */ | |
| 152 | function byDay(list: readonly Landing[], own: string | undefined, showRepo: boolean, zone: string, today: string, target?: string): Html[] { | |
| 143 | 153 | const days = new Map<string, Landing[]>(); |
| 144 | 154 | for (const l of list) days.set(dayOf(l.at, zone), [...(days.get(dayOf(l.at, zone)) ?? []), l]); |
| 145 | 155 | return [...days].map(([day, items]) => |
| 146 | html`<section class="mt" data-day="${day}"><h2><time datetime="${day}">${dayHeading(day, today)}</time>${zone === "UTC" ? html` <span data-zone>${badge("UTC", { variant: "outline" })}</span>` : null} ${badge(String(items.length))}</h2><ul class="list setting-list">${gather(items).map((g) => (g.landings.length === 1 ? landingRow(g.landings[0]!, own, showRepo) : gatheredRow(g, own, showRepo, day)))}</ul></section>`, | |
| 156 | html`<section class="mt" data-day="${day}"><h2><time datetime="${day}">${dayHeading(day, today)}</time>${zone === "UTC" ? html` <span data-zone>${badge("UTC", { variant: "outline" })}</span>` : null} ${badge(String(items.length))}</h2><ul class="list setting-list">${gather(items).map((g) => (g.landings.length === 1 ? landingRow(g.landings[0]!, own, showRepo) : gatheredRow(g, own, showRepo, day, target)))}</ul></section>`, | |
| 147 | 157 | ); |
| 148 | 158 | } |
| 149 | 159 | |
| @@ -210,7 +220,10 @@ export const localDaysJs = /* js */ ` | ||
| 210 | 220 | })(); |
| 211 | 221 | `; |
| 212 | 222 | |
| 213 | /** Rendered regions kept by what they were rendered from; a few views (repo filters) are in use at once. */ | |
| 223 | /** | |
| 224 | * Rendered regions kept by what they were rendered from; a few views (repo filters) are in use at | |
| 225 | * once. | |
| 226 | */ | |
| 214 | 227 | const REGIONS = 8; |
| 215 | 228 | const rendered = new Map<string, Html>(); |
| 216 | 229 | |
| @@ -227,11 +240,12 @@ export function shippedRegion( | ||
| 227 | 240 | readable = true, |
| 228 | 241 | chapters: readonly ChapterEntry[] = [], |
| 229 | 242 | bet = "", |
| 243 | target?: string, | |
| 230 | 244 | ): Html { |
| 231 | const key = `${Bun.hash(JSON.stringify([read, choice, zone, toLive ?? null, readable, chapters, bet])).toString(36)}:${Math.floor(now.getTime() / 60_000)}`; | |
| 245 | const key = `${Bun.hash(JSON.stringify([read, choice, zone, toLive ?? null, readable, chapters, bet, target ?? null])).toString(36)}:${Math.floor(now.getTime() / 60_000)}`; | |
| 232 | 246 | const kept = rendered.get(key); |
| 233 | 247 | if (kept !== undefined) return kept; |
| 234 | const made = renderRegion(read, choice, now, zone, toLive, readable, chapters, bet); | |
| 248 | const made = renderRegion(read, choice, now, zone, toLive, readable, chapters, bet, target); | |
| 235 | 249 | if (rendered.size >= REGIONS) rendered.delete(rendered.keys().next().value as string); |
| 236 | 250 | rendered.set(key, made); |
| 237 | 251 | return made; |
| @@ -247,13 +261,15 @@ function renderRegion( | ||
| 247 | 261 | readable = true, |
| 248 | 262 | chapters: readonly ChapterEntry[] = [], |
| 249 | 263 | bet = "", |
| 264 | target?: string, | |
| 250 | 265 | ): Html { |
| 251 | 266 | const keep = (l: Landing) => choice === "all" || l.repo === choice; |
| 252 | 267 | const live = read.live.filter(keep); |
| 253 | 268 | const onItsWay = read.onItsWay.filter(keep); |
| 254 | 269 | const todayIs = dayOf(now.toISOString(), zone); |
| 255 | 270 | const today = live.filter((l) => dayOf(l.at, zone) === todayIs).length; |
| 256 | // The short sha is a way in to the commit's page, unless there is no repository or the reader may not open it. | |
| 271 | // The short sha is a way in to the commit's page, unless there is no repository or the reader may | |
| 272 | // not open it. | |
| 257 | 273 | const commit = |
| 258 | 274 | read.commit === null ? null : sha(read.commit, readable && read.own !== undefined ? `/${read.own}/commit/${read.commit}` : undefined); |
| 259 | 275 | // A build that is not a release has no version worth a reader's attention: the commit says it. |
| @@ -272,7 +288,7 @@ function renderRegion( | ||
| 272 | 288 | live.length === 0 |
| 273 | 289 | ? html`<p class="mt muted">Nothing has shipped yet.</p>` |
| 274 | 290 | : !grouped |
| 275 | ? html`${byDay(live, read.own, choice === "all", zone, todayIs)}` | |
| 291 | ? html`${byDay(live, read.own, choice === "all", zone, todayIs, target)}` | |
| 276 | 292 | : html`${groups.map((g) => (g.kind === "chapter" ? chapterSection(g, read.own, choice === "all") : betweenSection(g, read.own, choice === "all")))}`; |
| 277 | 293 | return html`${top}${way}${gone}${older(read.more, read.live[read.live.length - 1]?.at, choice, read.own, bet)}`; |
| 278 | 294 | } |
| @@ -288,13 +304,15 @@ export async function changelogPage(ctx: Ctx): Promise<Response> { | ||
| 288 | 304 | const planned = nearMilestones(ctx.app, landed.own ?? ctx.app.config.forgeRepo, ctx.auth.user); |
| 289 | 305 | const near = planned?.near ?? []; |
| 290 | 306 | const everything = [...read.onItsWay, ...read.live]; |
| 291 | // One aggregate read stands for the chapters in the tag; the per-repository reads wait until the tag has missed. | |
| 307 | // One aggregate read stands for the chapters in the tag; the per-repository reads wait until the | |
| 308 | // tag has missed. | |
| 292 | 309 | const stamp = chapterStamp(ctx.app.db); |
| 293 | 310 | // The tag comes from what the page would say, before any of it is rendered: |
| 294 | 311 | // a match answers 304 without building the page. |
| 295 | 312 | const toLive = newestLive(ctx.app.db); |
| 313 | const target = askedAnchor(ctx.url.searchParams.get("release")); | |
| 296 | 314 | const flashed = readFlash(ctx.request) !== undefined; |
| 297 | 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), 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]); | |
| 315 | 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), 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]); | |
| 298 | 316 | const keep = tag === undefined ? undefined : cacheHeaders(ctx, tag); |
| 299 | 317 | if (keep !== undefined && keep.matched) return keep.response; |
| 300 | 318 | const chapters = chapterEntries(ctx.app.db, read.live, ctx.auth.user); |
| @@ -312,7 +330,7 @@ export async function changelogPage(ctx: Ctx): Promise<Response> { | ||
| 312 | 330 | ...bets.map((b) => ({ label: b, href: `/changelog?bet=${encodeURIComponent(b)}`, current: bet === b })), |
| 313 | 331 | ]); |
| 314 | 332 | const body = html`${pageHead("Changelog", { sub: "What went live, as it happens." })}${nearBlock(planned === undefined ? "" : repoBase(planned.repo), near)}${filters}${betFilters}${read.own !== undefined && readable ? html`<p class="small"><a href="/${read.own}/waves" data-waves-link>Read it by wave</a></p>` : null} |
| 315 | <div id="shipped" data-live="${LIVE}" aria-live="polite">${shippedRegion(read, choice, new Date(), "UTC", toLive, readable, chapters, bet)}</div>`; | |
| 333 | <div id="shipped" data-live="${LIVE}" aria-live="polite">${shippedRegion(read, choice, new Date(), "UTC", toLive, readable, chapters, bet, target)}</div>`; | |
| 316 | 334 | const response = page({ ctx, title: "Changelog", body, feed: { href: "/changelog.atom", title: "Changelog" }, json: { href: `/api/v1/changelog${choice === read.own ? "" : `?repo=${encodeURIComponent(choice)}`}`, title: "Changelog (JSON)" }, scriptJs: `${liveRegionsJs}\n${localDaysJs}` }); |
| 317 | 335 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 318 | 336 | if (keep === undefined) return response; |
| @@ -368,7 +386,8 @@ export async function changelogJson(ctx: Ctx): Promise<Response> { | ||
| 368 | 386 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 369 | 387 | const asked = ctx.url.searchParams.get("repo"); |
| 370 | 388 | const answer = await shippedAnswer(ctx.app, asked); |
| 371 | // The answer is the same for every viewer (public repositories only), so a shared cache may keep it. | |
| 389 | // The answer is the same for every viewer (public repositories only), so a shared cache may keep | |
| 390 | // it. | |
| 372 | 391 | const etag = changelogTag(answer.version, [...answer.live, ...answer.onItsWay], [asked ?? "", answer.live.length]); |
| 373 | 392 | const headers = { etag, "cache-control": "public, max-age=5" }; |
| 374 | 393 | if (holds(ctx.request.headers.get("if-none-match"), etag)) return new Response(null, { status: 304, headers }); |
| @@ -376,9 +395,9 @@ export async function changelogJson(ctx: Ctx): Promise<Response> { | ||
| 376 | 395 | } |
| 377 | 396 | |
| 378 | 397 | /** |
| 379 | * What the reader asked to see, settled once the forge's own repository is known: the repository and | |
| 380 | * bet filters, the chips offered (from the newest merged pulls, not from the page), and the filter | |
| 381 | * the read applies to each batch of merged rows, so a page is full of matches. | |
| 398 | * What the reader asked to see, settled once the forge's own repository is known: the repository | |
| 399 | * and bet filters, the chips offered (from the newest merged pulls, not from the page), and the | |
| 400 | * filter the read applies to each batch of merged rows, so a page is full of matches. | |
| 382 | 401 | */ |
| 383 | 402 | function viewOf(ctx: Ctx) { |
| 384 | 403 | let settled: { own: string | undefined; choice: string; bet: string; bets: string[]; others: string[]; repo: Repo | undefined; readable: boolean } | undefined; |
test/changelog-atom.test.ts +112 −9
| @@ -1,4 +1,7 @@ | ||
| 1 | /** `GET /changelog.atom` lists what went live, escaped, without what is only on its way; the page links it. */ | |
| 1 | /** | |
| 2 | * `GET /changelog.atom` lists what went live, escaped, without what is only on its way; the page | |
| 3 | * links it. | |
| 4 | */ | |
| 2 | 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -63,26 +66,126 @@ describe("GET /changelog.atom", () => { | ||
| 63 | 66 | expect(titles).toEqual(["Went live: Fix <&> escaping", "Went live: j/k, enter, esc and ? on pulls"]); |
| 64 | 67 | expect(text).not.toContain("small:"); |
| 65 | 68 | expect(text).not.toContain("test/keys"); |
| 66 | expect(text).toContain(`href="${servers.url}/alice/forge/pulls/1"`); | |
| 69 | expect(text).toContain(`href="${servers.url}/changelog?release=release-alice-forge-1#release-alice-forge-1"`); | |
| 67 | 70 | expect(text).toContain("Fix <&> escaping"); |
| 68 | 71 | expect(text).not.toContain("Not shipped yet"); |
| 69 | 72 | }); |
| 70 | 73 | |
| 71 | test("caps the feed at the newest 30 entries", async () => { | |
| 74 | test("caps the feed at the newest 20 entries", async () => { | |
| 72 | 75 | const insertIssue = app.db.query( |
| 73 | 76 | `INSERT INTO issue (id, repo_id, number, kind, title, author_id, state) SELECT ?1, repo_id, ?2, 'pull', ?3, author_id, 'closed' FROM issue WHERE id = 'i1'`, |
| 74 | 77 | ); |
| 75 | 78 | const insertPull = app.db.query( |
| 76 | 79 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at, merged_oid) VALUES (?1, 'main', 'b', 'base', '', ?2, 'oid-live')`, |
| 77 | 80 | ); |
| 78 | for (let n = 10; n < 50; n++) { | |
| 79 | insertIssue.run(`bulk${n}`, n, `Bulk ${n}`); | |
| 80 | insertPull.run(`bulk${n}`, `2026-09-01T10:${String(n).padStart(2, "0")}:00.000Z`); | |
| 81 | try { | |
| 82 | for (let n = 10; n < 50; n++) { | |
| 83 | insertIssue.run(`bulk${n}`, n, `Bulk ${n}`); | |
| 84 | insertPull.run(`bulk${n}`, `2026-09-01T10:${String(n).padStart(2, "0")}:00.000Z`); | |
| 85 | } | |
| 86 | const text = await (await fetch(`${servers.url}/changelog.atom`)).text(); | |
| 87 | expect(text.match(/<entry>/g)?.length).toBe(20); | |
| 88 | } finally { | |
| 89 | app.db.query(`DELETE FROM pull WHERE issue_id LIKE 'bulk%'`).run(); | |
| 90 | app.db.query(`DELETE FROM issue WHERE id LIKE 'bulk%'`).run(); | |
| 81 | 91 | } |
| 92 | }); | |
| 93 | ||
| 94 | test("lists releases newest first, each with id, title, updated, anchor link and one-sentence summary", async () => { | |
| 82 | 95 | const text = await (await fetch(`${servers.url}/changelog.atom`)).text(); |
| 83 | expect(text.match(/<entry>/g)?.length).toBe(30); | |
| 84 | app.db.query(`DELETE FROM pull WHERE issue_id LIKE 'bulk%'`).run(); | |
| 85 | app.db.query(`DELETE FROM issue WHERE id LIKE 'bulk%'`).run(); | |
| 96 | const entries = text.match(/<entry>[\s\S]*?<\/entry>/g)!; | |
| 97 | expect(entries.length).toBe(2); // the two live landings before a third is added | |
| 98 | const insertIssue = app.db.query( | |
outdated
The DELETE cleanup runs only if nothing before it throws; wrap the insert/fetch in try/finally so a failure cannot leak the third landing into later tests. |
||
| 99 | `INSERT INTO issue (id, repo_id, number, kind, title, author_id, state) SELECT ?1, repo_id, ?2, 'pull', ?3, author_id, 'closed' FROM issue WHERE id = 'i1'`, | |
| 100 | ); | |
| 101 | const insertPull = app.db.query( | |
| 102 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at, merged_oid) VALUES (?1, 'main', 'b', 'base', '', ?2, 'oid-live')`, | |
| 103 | ); | |
| 104 | let three: string[]; | |
| 105 | try { | |
| 106 | insertIssue.run("three", 90, "Third"); | |
| 107 | insertPull.run("three", "2026-10-01T11:00:00.000Z"); | |
| 108 | three = (await (await fetch(`${servers.url}/changelog.atom`)).text()).match(/<entry>[\s\S]*?<\/entry>/g)!; | |
| 109 | } finally { | |
| 110 | app.db.query(`DELETE FROM pull WHERE issue_id = 'three'`).run(); | |
| 111 | app.db.query(`DELETE FROM issue WHERE id = 'three'`).run(); | |
| 112 | } | |
| 113 | expect(three.length).toBe(3); | |
outdated
Asserts the pull URL, which locks in the miss on box 2. Assert the /changelog# anchor instead, and add a <20 KB test. |
||
| 114 | expect(three[0]).toContain("Went live: Third"); | |
| 115 | for (const e of three) { | |
| 116 | expect(e).toMatch(/<id>urn:forge:landing:[^<]+<\/id>/); | |
| 117 | expect(e).toMatch(/<updated>\d{4}-\d\d-\d\dT[^<]+<\/updated>/); | |
| 118 | expect(e).toMatch(/<summary>[^<]+\.<\/summary>/); | |
| 119 | expect(e).toMatch(/href="[^"]*\/changelog\?release=(release-alice-forge-\d+)#\1"/); | |
| 120 | } | |
| 121 | expect(three[0]).toContain("Landed in alice/forge as pull #90 on 2026-10-01"); | |
| 122 | }); | |
| 123 | ||
| 124 | test("every entry's anchor is an id on /changelog", async () => { | |
| 125 | const text = await (await fetch(`${servers.url}/changelog.atom`)).text(); | |
| 126 | const html = await (await fetch(`${servers.url}/changelog`)).text(); | |
| 127 | const anchors = [...text.matchAll(/href="[^"]*\/changelog\?release=[^"#]+#([^"]+)"/g)].map((m) => m[1]!); | |
| 128 | expect(anchors.length).toBeGreaterThan(0); | |
| 129 | for (const a of anchors) expect(html).toContain(`id="${a}"`); | |
| 130 | }); | |
| 131 | ||
| 132 | test("stays under 20 KB with 20 long-titled entries", async () => { | |
| 133 | const insertIssue = app.db.query( | |
| 134 | `INSERT INTO issue (id, repo_id, number, kind, title, author_id, state) SELECT ?1, repo_id, ?2, 'pull', ?3, author_id, 'closed' FROM issue WHERE id = 'i1'`, | |
| 135 | ); | |
| 136 | const insertPull = app.db.query( | |
| 137 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at, merged_oid) VALUES (?1, 'main', 'b', 'base', '', ?2, 'oid-live')`, | |
| 138 | ); | |
| 139 | let text: string; | |
| 140 | try { | |
| 141 | for (let n = 100; n < 125; n++) { | |
| 142 | insertIssue.run(`long${n}`, n, `${"A very long release title ".repeat(8).trim()} ${n}`); | |
| 143 | insertPull.run(`long${n}`, `2026-09-02T10:${String(n - 100).padStart(2, "0")}:00.000Z`); | |
| 144 | } | |
| 145 | text = await (await fetch(`${servers.url}/changelog.atom`)).text(); | |
| 146 | } finally { | |
| 147 | app.db.query(`DELETE FROM pull WHERE issue_id LIKE 'long%'`).run(); | |
| 148 | app.db.query(`DELETE FROM issue WHERE id LIKE 'long%'`).run(); | |
| 149 | } | |
| 150 | expect(text.match(/<entry>/g)?.length).toBe(20); | |
| 151 | expect(new TextEncoder().encode(text).length).toBeLessThan(20480); | |
| 152 | }); | |
| 153 | ||
| 154 | test("a feed link to a row inside a closed fold opens that fold on /changelog, without JavaScript", async () => { | |
| 155 | const insertIssue = app.db.query( | |
| 156 | `INSERT INTO issue (id, repo_id, number, kind, title, author_id, state) SELECT ?1, repo_id, ?2, 'pull', ?3, author_id, 'closed' FROM issue WHERE id = 'i1'`, | |
| 157 | ); | |
| 158 | const insertPull = app.db.query( | |
| 159 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at, merged_oid) VALUES (?1, 'main', 'b', 'base', '', ?2, 'oid-live')`, | |
| 160 | ); | |
| 161 | try { | |
| 162 | // Three landings of one shape on one day: the page gathers them into one closed fold. | |
| 163 | ["issues", "pulls", "apps"].forEach((name, i) => { | |
| 164 | insertIssue.run(`fold${i}`, 200 + i, `Keys on the ${name} page`); | |
| 165 | insertPull.run(`fold${i}`, `2026-10-05T1${i}:00:00.000Z`); | |
| 166 | }); | |
| 167 | const feed = await (await fetch(`${servers.url}/changelog.atom`)).text(); | |
| 168 | const href = feed.match(/href="([^"]*\/changelog\?release=release-alice-forge-201#release-alice-forge-201)"/)![1]!; | |
| 169 | const { Window } = await import("happy-dom"); | |
| 170 | const fold = async (url: string) => { | |
| 171 | const window = new Window(); | |
| 172 | const doc = window.document as any; | |
| 173 | doc.body.innerHTML = await (await fetch(url)).text(); | |
| 174 | const li = doc.getElementById("release-alice-forge-201"); | |
| 175 | const details = li?.closest("details"); | |
| 176 | const open = details === null || details === undefined ? null : details.hasAttribute("open"); | |
| 177 | await window.happyDOM.close(); | |
| 178 | return open; | |
| 179 | }; | |
| 180 | expect(await fold(`${servers.url}/changelog`)).toBe(false); // folded and closed by default | |
| 181 | expect(await fold(href.replace(/#.*$/, ""))).toBe(true); // the feed's link opens it | |
| 182 | // A malformed ask opens nothing and is not echoed. | |
| 183 | const odd = await (await fetch(`${servers.url}/changelog?release=%22%3E%3Cb%3E`)).text(); | |
| 184 | expect(odd).not.toContain('"><b>'); | |
| 185 | } finally { | |
| 186 | app.db.query(`DELETE FROM pull WHERE issue_id LIKE 'fold%'`).run(); | |
| 187 | app.db.query(`DELETE FROM issue WHERE id LIKE 'fold%'`).run(); | |
| 188 | } | |
| 86 | 189 | }); |
| 87 | 190 | |
| 88 | 191 | test("answers 304 to its ETag", async () => { |
new above
offline
Box 2: link is the pull, not an anchor on /changelog. Add anchors on the page and link to /changelog#<id>.