Public: anyone can read this; the crew can change it.

Defect of #13072: production's /changelog.atom answers 200 with no <entry>, though 629 release tags exist #15502

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/15498-defect-of-13072-production-s-changelog-a → main 0 commits fork

  • Merged. torque/15498-defect-of-13072-production-s-changelog-a was merged into main as 7b372e6.

Review

Sign in to review this change.
5 files changed +242 −14
src/release/answer.ts +10 −1
@@ -7,6 +7,7 @@
77 import type { App } from "../app.ts";
88 import { listPublicReleases } from "../core/app_releases.ts";
99 import { getRepoById } from "../core/repos.ts";
10 import { publicForgeRepo } from "../core/forge_repo.ts";
1011 import type { User } from "../core/users.ts";
1112 import { releaseOf, running, shortOf } from "../kernel/version.ts";
1213 import { BOOTED, mayRead } from "./gate.ts";
@@ -43,6 +44,12 @@ function readOnce(app: App): Promise<Landings> {
4344 return read;
4445 }
4546
47 /** The public repository `FORGE_REPO` names, as `owner/name`, or undefined. */
48 function configuredOwn(app: App): string | undefined {
49 const repo = publicForgeRepo(app);
50 return repo === undefined ? undefined : `${repo.ownerName}/${repo.name}`;
51 }
52
4653 /**
4754 * What went live, for anyone: the list /changelog shows. `asked` is the
4855 * page's `?repo=`: "all" or `owner/name`; absent, or not a repository in the
@@ -59,7 +66,9 @@ export async function shippedAnswer(app: App, asked: string | null = null) {
5966 const live = read.live.filter(keep);
6067 // A repository's releases are also its `v*` tags: the forge's own is never an app here, so
6168 // `app_release` alone listed none of them (#15404). Absent names the forge's own.
62 const tagged = named ?? (asked === null ? read.own : undefined);
69 // With no merged pull yet, `own` is unknown (it is found from merged rows), so the configured
70 // `FORGE_REPO` names it: a forge whose record is only its tags still lists them (#15498).
71 const tagged = named ?? (asked === null ? (read.own ?? configuredOwn(app)) : undefined);
6372 const tags = tagged === undefined ? [] : await publicTagReleases(app, tagged);
6473 const waves = wavesOf(groupByChapter(live, await withWaves(app, chapterEntries(app.db, live, undefined))));
6574 return {
src/web/feeds.ts +71 −11
@@ -30,6 +30,8 @@ import { refTip } from "../git/read.ts";
3030 import { repoDir } from "../git/repos.ts";
3131 import { releaseAnchor } from "../release/anchor.ts";
3232 import { shippedAnswer } from "../release/answer.ts";
33 import type { PublicRelease } from "../core/app_releases.ts";
34 import { shortOf } from "../kernel/version.ts";
3335 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../core/route_timing.ts";
3436 import type { Ctx } from "../http/context.ts";
3537 import { notFound } from "../http/respond.ts";
@@ -245,21 +247,75 @@ export function changelogTag(
245247 return `W/"${Bun.hash(JSON.stringify(key)).toString(36)}"`;
246248 }
247249
250 /** One feed entry and the time it sorts by, newest first. */
251 interface FeedItem {
252 readonly at: string;
253 readonly body: string;
254 }
255
256 /**
257 * A kept release as an entry (#15498): a `v*` tag of the repository or a version an app served,
258 * as `/api/v1/changelog` lists it under `releases`. Its id names the repository and version, so
259 * a tag read twice is one entry to a reader.
260 */
261 export function releaseItem(origin: string, own: string, r: PublicRelease): FeedItem {
262 const link = `${origin}/changelog${r.repo === own ? "" : `?repo=${encodeURIComponent(r.repo)}`}`;
263 const said = r.subject.trim() === "" || r.subject === `v${r.version}` ? "" : `: ${plainTitle(r.subject)}`;
264 return {
265 at: r.servedAt,
266 body: ` <entry>
267 <id>urn:forge:release:${xml(`${r.repo}@${r.version}`)}</id>
268 <title>${xml(`Released v${r.version}${said}`)}</title>
269 <updated>${xml(stamp(r.servedAt))}</updated>
270 <link rel="alternate" type="text/html" href="${xml(link)}"/>
271 <summary>${xml(`${r.repo} v${r.version}, commit ${shortOf(r.commit)}, released on ${stamp(r.servedAt).slice(0, 10)}.`)}</summary>
272 </entry>`,
273 };
274 }
275
276 /**
277 * The build this forge runs, as the one entry of a feed that has no other (#15498). A forge run
278 * as an app (the forge's own production copy) starts from an exported tree with no `.git` and
279 * fresh data: no tags, no release rows, no landed pulls. It still runs one release, and the
280 * runtime names its commit; that release is live, so the feed says so, and says why it is alone.
281 */
282 export function runningItem(origin: string, commit: string, named: string, since: string): FeedItem {
283 return {
284 at: since,
285 body: ` <entry>
286 <id>urn:forge:running:${xml(commit)}</id>
287 <title>${xml(`Running ${named}`)}</title>
288 <updated>${xml(stamp(since))}</updated>
289 <link rel="alternate" type="text/html" href="${xml(`${origin}/changelog`)}"/>
290 <summary>${xml(`This forge has run commit ${commit} since ${stamp(since)}. No tags, release rows or landed pulls are kept here, so this build is the one release on record.`)}</summary>
291 </entry>`,
292 };
293 }
294
248295 /**
249296 * `GET /changelog.atom`: what went live, as /changelog lists it (the forge's
250 * own repository, public pulls only). Landed-but-not-shipped is left out.
297 * own repository, public pulls only), and the kept releases (`v*` tags and
298 * the versions apps served) beside it. Landed-but-not-shipped is left out.
299 * A feed with none of these names the running build (`runningItem`).
251300 */
252301 export async function changelogAtom(ctx: Ctx): Promise<Response> {
253302 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
254303 const answer = await timePhaseAsync(ctx.request, "releases", () => shippedAnswer(ctx.app));
255304 const origin = ctx.url.origin;
256305 const live = answer.live.slice(0, CHANGELOG_ENTRIES);
306 const releases = answer.releases.slice(0, CHANGELOG_ENTRIES);
257307 const { tip, waves } = await timePhaseAsync(ctx.request, "waves", () => ownWaves(ctx));
258308 const [ownerName = "", repoName = ""] = (ctx.app.config.forgeRepo ?? "").split("/");
309 const own = `${ownerName}/${repoName}`;
259310 // A build with no version stamp is named by its commit, as /changelog names it (#15482): the
260311 // generator carries it, and the tag changes with it so a cached feed never outlives a release.
261312 const named = answer.version ?? answer.short;
262 const etag = changelogTag(answer.version ?? answer.commit ?? "dev", live, [tip]);
313 const alone = live.length === 0 && releases.length === 0 && answer.commit !== null;
314 const etag = changelogTag(answer.version ?? answer.commit ?? "dev", live, [
315 tip,
316 releases.map((r) => [r.repo, r.version, r.commit, r.servedAt, r.subject]),
317 alone ? answer.liveSince : "",
318 ]);
263319 const headers = { etag, "cache-control": "public, max-age=300" };
264320 if (holds(ctx.request.headers.get("if-none-match"), etag)) return new Response(null, { status: 304, headers });
265321 const waveOf = new Map<string, Wave>();
@@ -269,34 +325,38 @@ export async function changelogAtom(ctx: Ctx): Promise<Response> {
269325 if (!waveOf.has(k)) waveOf.set(k, w);
270326 }
271327 const told = new Set<string>();
272 const entries = live.flatMap((l) => {
328 const landed: FeedItem[] = live.flatMap((l) => {
273329 const wave = waveOf.get(`${l.repo}#${l.number}`);
274330 if (wave !== undefined) {
275331 // One entry per wave, at its newest landing: the story is told once.
276332 if (told.has(wave.version)) return [];
277333 told.add(wave.version);
278334 const summary = wave.highlights.map((h) => `${h.title.trim()}: ${h.why.trim()}`).join(" · ");
279 return [` <entry>
280 <id>urn:forge:wave:${xml(`${ownerName}/${repoName}@${wave.version}`)}</id>
335 return [{ at: l.at, body: ` <entry>
336 <id>urn:forge:wave:${xml(`${own}@${wave.version}`)}</id>
281337 <title>${xml(wave.headline.trim())}</title>
282338 <updated>${xml(stamp(l.at))}</updated>
283339 <link rel="alternate" type="text/html" href="${xml(`${origin}${wavePath(ownerName, repoName, wave.version)}`)}"/>
284340 <summary>${xml(summary)}</summary>
285 </entry>`];
341 </entry>` }];
286342 }
287343 // The page opens on the forge's own repository; another repository's rows sit under its filter.
288344 // `release=` opens the fold holding the row, so the fragment lands on a shown element.
289345 const anchor = releaseAnchor(l.repo, l.number);
290 const link = `${origin}/changelog?${l.repo === `${ownerName}/${repoName}` ? "" : `repo=${encodeURIComponent(l.repo)}&`}release=${anchor}#${anchor}`;
291 return [` <entry>
346 const link = `${origin}/changelog?${l.repo === own ? "" : `repo=${encodeURIComponent(l.repo)}&`}release=${anchor}#${anchor}`;
347 return [{ at: l.at, body: ` <entry>
292348 <id>urn:forge:landing:${xml(l.repo)}#${l.number}</id>
293349 <title>${xml(`Went live: ${plainTitle(l.title)}`)}</title>
294350 <updated>${xml(stamp(l.at))}</updated>
295351 <link rel="alternate" type="text/html" href="${xml(link)}"/>
296352 <summary>${xml(`Landed in ${l.repo} as pull #${l.number} on ${stamp(l.at).slice(0, 10)} and is live.`)}</summary>
297 </entry>`];
353 </entry>` }];
298354 });
299 const updated = live[0]?.at ?? feedEpoch(ctx.app.db);
355 const items = [...landed, ...releases.map((r) => releaseItem(origin, own, r))]
356 .sort((a, b) => Date.parse(stamp(b.at)) - Date.parse(stamp(a.at)))
357 .slice(0, CHANGELOG_ENTRIES);
358 if (alone && answer.commit !== null) items.push(runningItem(origin, answer.commit, named ?? answer.commit, answer.liveSince));
359 const updated = items[0]?.at ?? feedEpoch(ctx.app.db);
300360 const body = `<?xml version="1.0" encoding="utf-8"?>
301361 <feed xmlns="http://www.w3.org/2005/Atom">
302362 <id>${xml(origin)}/changelog.atom</id>
@@ -307,7 +367,7 @@ export async function changelogAtom(ctx: Ctx): Promise<Response> {
307367 <link rel="self" type="application/atom+xml" href="${xml(origin)}/changelog.atom"/>
308368 <link rel="alternate" type="text/html" href="${xml(origin)}/changelog"/>
309369 <generator${named === null ? "" : ` version="${xml(named)}"`}>forge</generator>
310 ${entries.join("\n")}
370 ${items.map((i) => i.body).join("\n")}
311371 </feed>
312372 `;
313373 return new Response(body, { headers: { ...headers, "content-type": "application/atom+xml; charset=utf-8" } });
test/atom-feeds.test.ts +12 −1
@@ -1,5 +1,5 @@
11 /** Both of a repository's feeds parse as Atom, round-trip awkward titles, and cache. */
2 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test";
33 import { mkdtemp, rm } from "node:fs/promises";
44 import { tmpdir } from "node:os";
55 import { join } from "node:path";
@@ -20,6 +20,14 @@ import { checkAtom } from "./helpers/atom.ts";
2020 const TITLE = "Fish & <chips> 🍟 \"fresh\"";
2121
2222 describe("atom feeds", () => {
23 // A test that unsets the build stamp (the check runs stamped) gets it back after (#15498).
24 const stamp = { c: process.env["FORGE_COMMIT"], a: process.env["FORGE_APP_COMMIT"] };
25 afterEach(() => {
26 if (stamp.c === undefined) delete process.env["FORGE_COMMIT"];
27 else process.env["FORGE_COMMIT"] = stamp.c;
28 if (stamp.a === undefined) delete process.env["FORGE_APP_COMMIT"];
29 else process.env["FORGE_APP_COMMIT"] = stamp.a;
30 });
2331 let dataDir: string;
2432 let app: App;
2533 let servers: Servers;
@@ -100,6 +108,9 @@ describe("atom feeds", () => {
100108 const emptyDir = await mkdtemp(join(tmpdir(), "forge-atom-empty-"));
101109 const empty = createApp({ dataDir: emptyDir, port: 0 });
102110 const emptyServers = await serve(empty);
111 // An unstamped build: a stamped one names its running commit as the feed's one entry (#15498).
112 delete process.env["FORGE_COMMIT"];
113 delete process.env["FORGE_APP_COMMIT"];
103114 try {
104115 const u = await createUser(empty.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
105116 if (!u.ok) throw new Error(u.error);
test/changelog-atom-releases.test.ts added +111
@@ -0,0 +1,111 @@
1 /**
2 * /changelog.atom lists the kept releases, not only the landed pulls (#15498). Production answered
3 * 200 with no <entry>: the feed read only `live` landings, never the `releases` that
4 * /api/v1/changelog carries (the `v*` tags and the versions apps served), and the forge's own
5 * production copy runs from an exported tree with fresh data, so it holds no record at all. There
6 * the running build is the one release, and the feed names it.
7 */
8
9 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
10 import { mkdtemp, rm } from "node:fs/promises";
11 import { tmpdir } from "node:os";
12 import { join } from "node:path";
13 import { createApp, type App } from "../src/app.ts";
14 import { createRepo } from "../src/actions/repos.ts";
15 import { createUser } from "../src/core/users.ts";
16 import { repoDir } from "../src/git/repos.ts";
17 import { serve, type Servers } from "../src/http/server.ts";
18 import { BOOTED } from "../src/release/gate.ts";
19 import { gitAt } from "./helpers/plain-git.ts";
20 import { checkAtom } from "./helpers/atom.ts";
21
22 const entriesOf = (text: string): string[] => text.match(/<entry>[\s\S]*?<\/entry>/g) ?? [];
23 const saved = { commit: process.env["FORGE_COMMIT"], version: process.env["FORGE_VERSION"] };
24 function restore(): void {
25 for (const [k, v] of [["FORGE_COMMIT", saved.commit], ["FORGE_VERSION", saved.version]] as const) {
26 if (v === undefined) delete process.env[k];
27 else process.env[k] = v;
28 }
29 }
30
31 describe("GET /changelog.atom with one release tag and no landed pull", () => {
32 let data: string;
33 let app: App;
34 let servers: Servers;
35 let tagged = "";
36
37 beforeAll(async () => {
38 process.env["FORGE_VERSION"] = "0.7.629";
39 process.env["FORGE_COMMIT"] = "c".repeat(40);
40 data = await mkdtemp(join(tmpdir(), "forge-atom-releases-"));
41 app = createApp({ dataDir: data, port: 0, forgeRepo: "trevato/forge" });
42 servers = await serve(app);
43 const owner = await createUser(app.db, { origin: "seed", trusted: true, username: "trevato", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
44 if (!owner.ok) throw new Error(owner.error);
45 const repo = await createRepo(app, owner.value, { name: "forge", visibility: "public" });
46 if (!repo.ok) throw new Error(String(repo.error));
47 const work = join(data, "work");
48 await Bun.$`mkdir -p ${work}`.quiet();
49 gitAt(work, ["init", "-q", "-b", "main"], "2026-11-20T10:00:00Z");
50 gitAt(work, ["commit", "-q", "--allow-empty", "-m", "cut 0.7.629"], "2026-11-20T10:00:00Z");
51 tagged = gitAt(work, ["rev-parse", "HEAD"], "2026-11-20T10:00:00Z");
52 // As scripts/cut-release.ts cuts it: annotated, the message its JSON record.
53 gitAt(work, ["tag", "-a", "-F", "-", "v0.7.629"], "2026-11-20T10:00:00Z", JSON.stringify({ version: "0.7.629" }));
54 gitAt(repoDir(app.reposRoot, "trevato", "forge"), ["fetch", "-q", work, "main:main", "+refs/tags/*:refs/tags/*"], "2026-11-20T10:00:00Z");
55 }, 60_000);
56
57 afterAll(async () => {
58 restore();
59 servers.stop();
60 app.close();
61 await rm(data, { recursive: true, force: true });
62 });
63
64 test("the one release is one <entry>, with its version, commit and the time it was cut", async () => {
65 const res = await fetch(`${servers.url}/changelog.atom`);
66 expect(res.status).toBe(200);
67 const text = await res.text();
68 checkAtom(text, `${servers.url}/changelog.atom`);
69 const entries = entriesOf(text);
70 expect(entries.length).toBe(1);
71 expect(entries[0]).toContain("<id>urn:forge:release:trevato/[email protected]</id>");
72 expect(entries[0]).toContain("<title>Released v0.7.629</title>");
73 expect(entries[0]).toContain(`commit ${tagged.slice(0, 7)}`);
74 expect(entries[0]).toContain("<updated>2026-11-20T10:00:00.000Z</updated>");
75 // The feed's updated is its newest entry's, and no running-build entry stands beside a release.
76 expect(text.match(/<updated>([^<]*)<\/updated>/)![1]).toBe("2026-11-20T10:00:00.000Z");
77 expect(text).not.toContain("urn:forge:running:");
78 });
79
80 test("a cached reader is answered 304 while the record holds", async () => {
81 const etag = (await fetch(`${servers.url}/changelog.atom`)).headers.get("etag")!;
82 expect((await fetch(`${servers.url}/changelog.atom`, { headers: { "if-none-match": etag } })).status).toBe(304);
83 });
84 });
85
86 describe("GET /changelog.atom on a forge that keeps no release record", () => {
87 test("names the running build as its one entry, at the time it booted", async () => {
88 delete process.env["FORGE_VERSION"];
89 process.env["FORGE_COMMIT"] = "1701de1" + "0".repeat(33);
90 const data = await mkdtemp(join(tmpdir(), "forge-atom-running-"));
91 const app = createApp({ dataDir: data, port: 0, forgeRepo: "trevato/forge" });
92 const servers = await serve(app);
93 try {
94 const res = await fetch(`${servers.url}/changelog.atom`);
95 expect(res.status).toBe(200);
96 const text = await res.text();
97 checkAtom(text, `${servers.url}/changelog.atom`);
98 const entries = entriesOf(text);
99 expect(entries.length).toBe(1);
100 expect(entries[0]).toContain(`<id>urn:forge:running:1701de1${"0".repeat(33)}</id>`);
101 expect(entries[0]).toContain("<title>Running 1701de1</title>");
102 expect(entries[0]).toContain(`<updated>${BOOTED}</updated>`);
103 expect(text).toBe(await (await fetch(`${servers.url}/changelog.atom`)).text());
104 } finally {
105 restore();
106 servers.stop();
107 app.close();
108 await rm(data, { recursive: true, force: true });
109 }
110 }, 30_000);
111 });
test/changelog-atom.test.ts +38 −1
@@ -2,7 +2,7 @@
22 * `GET /changelog.atom` lists what went live, escaped, without what is only on its way; the page
33 * links it.
44 */
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
5 import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test";
66 import { mkdtemp, rm } from "node:fs/promises";
77 import { tmpdir } from "node:os";
88 import { join } from "node:path";
@@ -245,7 +245,44 @@ describe("GET /changelog.atom", () => {
245245 });
246246
247247 describe("GET /changelog.atom on an empty forge", () => {
248 // The check runs stamped (FORGE_APP_COMMIT); these say which build each case is (#15498).
249 const stamp = { c: process.env["FORGE_COMMIT"], a: process.env["FORGE_APP_COMMIT"] };
250 afterEach(() => {
251 if (stamp.c === undefined) delete process.env["FORGE_COMMIT"];
252 else process.env["FORGE_COMMIT"] = stamp.c;
253 if (stamp.a === undefined) delete process.env["FORGE_APP_COMMIT"];
254 else process.env["FORGE_APP_COMMIT"] = stamp.a;
255 });
256
257 test("stamped, it names the running build in one entry, at a fixed time, the same twice", async () => {
258 process.env["FORGE_COMMIT"] = "b".repeat(40);
259 delete process.env["FORGE_APP_COMMIT"];
260 const dataDir = await mkdtemp(join(tmpdir(), "forge-changelog-atom-stamped-"));
261 const app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" });
262 const servers = await serve(app);
263 try {
264 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
265 if (!made.ok) throw new Error(made.error);
266 const res = await fetch(`${servers.url}/changelog.atom`);
267 const text = await res.text();
268 expect(text.match(/<entry>/g)?.length).toBe(1);
269 expect(text).toContain("<title>Running bbbbbbb</title>");
270 // The feed is as new as its one entry, the boot time: not the first account, not now.
271 const times = [...text.matchAll(/<updated>([^<]*)<\/updated>/g)].map((m) => m[1]);
272 expect(times[0]).toBe(times[1]!);
273 expect(await (await fetch(`${servers.url}/changelog.atom`)).text()).toBe(text);
274 const etag = res.headers.get("etag")!;
275 expect((await fetch(`${servers.url}/changelog.atom`, { headers: { "if-none-match": etag } })).status).toBe(304);
276 } finally {
277 servers.stop();
278 app.close();
279 await rm(dataDir, { recursive: true, force: true });
280 }
281 }, 30_000);
282
248283 test("says when the forge was made (its first account), not now, and the same twice", async () => {
284 delete process.env["FORGE_COMMIT"];
285 delete process.env["FORGE_APP_COMMIT"];
249286 const dataDir = await mkdtemp(join(tmpdir(), "forge-changelog-atom-empty-"));
250287 const app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" });
251288 const servers = await serve(app);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs