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

/changelog.atom lists what went live: forge.open-platform.sh's feed has no entry while releases ship every hour #15325

Merged opened this

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

Merged

mason/forge:mason/15323-changelog-atom-lists-what-went-live-forg → main 0 commits fork 1 thread · 1 unresolved

  • Merged. mason/15323-changelog-atom-lists-what-went-live-forg was merged into main as b0d7e95.

Review

Sign in to review this change.
4 files changed +110 −32
src/release/landings.ts +17 −15
@@ -317,17 +317,19 @@ async function askLive(app: App, rows: readonly MergedRow[]): Promise<void> {
317317 }
318318 const oids = new Set(before?.oids ?? []);
319319 const misses = new Set(before?.misses ?? []);
320 const wanted = rows
321 .filter((r) => r.repo.toLowerCase() === named.toLowerCase() && r.oid !== "" && !oids.has(r.oid) && !misses.has(r.oid))
322 .slice(0, ASKED);
323 await Promise.all(
324 wanted.map(async (r) => {
325 const ancestor = await runGit(["merge-base", "--is-ancestor", r.oid, commit], { cwd: dir });
326 if (ancestor.ok) oids.add(r.oid);
327 // Exit 1 is git's "no"; any other failure may pass, so it is asked again.
328 else if (ancestor.error.code === 1) misses.add(r.oid);
329 }),
330 );
320 const wanted = rows.filter((r) => r.repo.toLowerCase() === named.toLowerCase() && r.oid !== "" && !oids.has(r.oid) && !misses.has(r.oid));
321 const ask = async (r: MergedRow): Promise<void> => {
322 const ancestor = await runGit(["merge-base", "--is-ancestor", r.oid, commit], { cwd: dir });
323 if (ancestor.ok) oids.add(r.oid);
324 // Exit 1 is git's "no"; any other failure may pass, so it is asked again.
325 else if (ancestor.error.code === 1) misses.add(r.oid);
326 };
327 // Newest first, ASKED at a time, until a pull is found live: everything older than it counts as
328 // live (`split`), so a forge whose running commit trails main by more than ASKED pulls still
329 // lists what went live instead of nothing (#15323). Misses are kept, so a chunk is asked once per
330 // commit.
331 const hasLive = () => rows.some((r) => r.repo.toLowerCase() === named.toLowerCase() && oids.has(r.oid));
332 for (let from = 0; from < wanted.length && (from === 0 || !hasLive()); from += ASKED) await Promise.all(wanted.slice(from, from + ASKED).map(ask));

This is the loop that fixes the feed, but it only reaches as far as the rows its callers hand it. The windowed callers slice to limit+ASKED, so /changelog stays empty when production is further behind than that. Pass the full batch, or walk here without relying on the caller's slice.

331333 // Misses are kept only for the merged rows still listed.
332334 const listed = new Set(rows.map((r) => r.oid));
333335 for (const o of misses) if (!listed.has(o)) misses.delete(o);
@@ -402,9 +404,9 @@ export async function readLandings(app: App, window?: Window): Promise<Landings>
402404 point = window.before !== undefined && cursorPoint(app.db, window.before) !== undefined ? window.before : undefined;
403405 // The forge's own repository is found from the newest rows, so `keep` can name it.
404406 let batch = mergedRows(app.db, BATCH, point);
405 const key = (r: readonly MergedRow[]) => r.slice(0, window.limit + ASKED).map((m) => `${m.repo}#${m.number}`).join();
407 const key = (r: readonly MergedRow[]) => r.map((m) => `${m.repo}#${m.number}`).join();
406408 let asked = key(batch);
407 await askLive(app, batch.slice(0, window.limit + ASKED)).catch(() => undefined);
409 await askLive(app, batch).catch(() => undefined);
408410 const own = keeps.get(app.db)?.own;
409411 const wanted = window.keep ?? ((r: readonly MergedRow[]) => r);
410412 const got: MergedRow[] = [];
@@ -416,12 +418,12 @@ export async function readLandings(app: App, window?: Window): Promise<Landings>
416418 if (last !== undefined) after = `${last.repo}#${last.number}`;
417419 if (batch.length < BATCH) break;
418420 asked = key(got);
419 await askLive(app, got.slice(0, window.limit + ASKED)).catch(() => undefined);
421 await askLive(app, got).catch(() => undefined);
420422 if (split(got, keeps.get(app.db)).live.length > window.limit) break;
421423 }
422424 rows = got;
423425 // Asked once already when the page's rows are the ones the first read found.
424 if (key(got) !== asked) await askLive(app, got.slice(0, window.limit + ASKED)).catch(() => undefined);
426 if (key(got) !== asked) await askLive(app, got).catch(() => undefined);
425427 }
426428 const kept = keeps.get(app.db);
427429 const parts = split(rows, kept);
test/changelog-atom-behind.test.ts added +71
@@ -0,0 +1,71 @@
1 /**
2 * A forge whose running commit trails main by more than the pulls asked of git at once still lists
3 * what went live in /changelog.atom, and never a private repository's landings (#15323).
4 */
5 import { afterEach, describe, expect, test } from "bun:test";
6 import { mkdtempSync, rmSync } from "node:fs";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp } from "../src/app.ts";
10 import { createRepo } from "../src/core/repos.ts";
11 import { createUser } from "../src/core/users.ts";
12 import { repoDir } from "../src/git/repos.ts";
13 import { EMPTY_TREE, git, mergedPull } from "./helpers/plain-git.ts";
14 import { serve } from "../src/http/server.ts";
15
16 const dirs: string[] = [];
17 const saved = process.env.FORGE_COMMIT;
18 afterEach(() => {
19 if (saved === undefined) delete process.env.FORGE_COMMIT;
20 else process.env.FORGE_COMMIT = saved;
21 for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
22 });
23
24 describe("GET /changelog.atom when production trails main", () => {
25 test("lists the live pull behind 150 on their way, newest first, escaped; private landings stay out", async () => {
26 const dir = mkdtempSync(join(tmpdir(), "forge-atom-behind-"));
27 dirs.push(dir);
28 const app = createApp({ dataDir: dir, port: 0, forgeRepo: "alice/r" });
29 const servers = await serve(app);
30 try {
31 const u = await createUser(app.db, { username: "alice", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true });
32 if (!u.ok) throw new Error(u.error);
33 const open = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "r", visibility: "public", description: "r" });
34 const closed = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "secret", visibility: "private", description: "s" });
35 if (!open.ok || !closed.ok) throw new Error("repo");
36 const gitDir = repoDir(app.reposRoot, "alice", "r");
37 const running = git(gitDir, "commit-tree", EMPTY_TREE, "-m", "running");
38 process.env.FORGE_COMMIT = running;
39 let n = 0;
40 const merge = (repoId: string, branch: string, oid: string, title: string) => {
41 n++;
42 const at = new Date(Date.parse("2026-11-01T00:00:00Z") + n * 60_000).toISOString();
43 mergedPull(app.db, { repoId, branch, authorId: u.value.id, n, oid, at, title });
44 };
45 merge(open.value.id, open.value.defaultBranch, running, "Fix <b>&</b> live");
46 for (let i = 0; i < 150; i++) merge(open.value.id, open.value.defaultBranch, git(gitDir, "commit-tree", EMPTY_TREE, "-m", `wait ${i}`), `Waiting ${i}`);
47 merge(closed.value.id, closed.value.defaultBranch, running, "Private secret");
48
49 // The page is read first, on a cold read: it must find the live pull by itself.
50 const html = await (await fetch(`${servers.url}/changelog`)).text();
51 const text = await (await fetch(`${servers.url}/changelog.atom`)).text();
52 const entries = text.match(/<entry>[\s\S]*?<\/entry>/g) ?? [];
53 expect(entries.length).toBe(1);
54 expect(entries[0]).toContain("Went live: Fix &lt;b&gt;&amp;&lt;/b&gt; live");
55 expect(text).not.toContain("Private secret");
56 expect(text).not.toContain("Waiting");
57 expect(text).toContain("<updated>2026-11-01T00:01:00.000Z</updated>");
58
59 // The page agrees with the feed: the same live pull, and the same count of them.
60 expect(html).not.toContain("Private secret");
61 // What is on its way is a section of its own; what went live follows it.
62 const wentLive = html.slice(html.indexOf("</ul>", html.indexOf("On its way")));
63 expect(wentLive).toContain("Fix &lt;b&gt;&amp;&lt;/b&gt; live");
64 expect(wentLive).not.toContain("Waiting");
65 expect(wentLive.match(/id="release-alice-r-\d+"/g)?.length).toBe(entries.length);
66 } finally {
67 servers.stop();
68 app.close();
69 }
70 }, 30_000);
71 });
test/helpers/plain-git.ts added +16
@@ -0,0 +1,16 @@
1 /** Run `git` in `cwd` with a fixed identity; the trimmed stdout. */
2 export const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
3 export function git(cwd: string, ...args: string[]): string {
4 const p = Bun.spawnSync(["git", ...args], {
5 cwd,
6 env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" },
7 });
8 return p.stdout.toString().trim();
9 }
10
11 /** Insert a closed, merged pull numbered `n` whose merge commit is `oid`. */
12 export function mergedPull(db: import("bun:sqlite").Database, p: { repoId: string; branch: string; authorId: string; n: number; oid: string; at: string; title: string }): void {
13 const issueId = crypto.randomUUID();
14 db.query(`INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at) VALUES (?1, ?2, ?3, 'pull', ?4, '', ?5, 'closed', ?6)`).run(issueId, p.repoId, p.n, p.title, p.authorId, p.at);
15 db.query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id, merged_at, merged_oid) VALUES (?1, ?2, ?3, '', '', ?4, ?5, ?6)`).run(issueId, p.branch, `b/${p.n}`, p.repoId, p.at, p.oid);
16 }
test/landings-asked-once.test.ts +6 −17
@@ -6,8 +6,8 @@ import { createRepo } from "../src/core/repos.ts";
66 import { createApp } from "../src/app.ts";
77 import { createUser } from "../src/core/users.ts";
88 import { repoDir } from "../src/git/repos.ts";
9 import { id } from "../src/kernel/id.ts";
109 import { readLandings } from "../src/release/landings.ts";
10 import { EMPTY_TREE, git, mergedPull } from "./helpers/plain-git.ts";
1111
1212 const dirs: string[] = [];
1313 const saved = { path: process.env.PATH, commit: process.env.FORGE_COMMIT };
@@ -18,15 +18,6 @@ afterEach(() => {
1818 for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
1919 });
2020
21 const TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
22 function git(cwd: string, ...args: string[]): string {
23 const p = Bun.spawnSync(["git", ...args], {
24 cwd,
25 env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" },
26 });
27 return p.stdout.toString().trim();
28 }
29
3021 describe("landings ask git once per merge commit", () => {
3122 test("a pull on its way costs no git on the next read; a new one is asked once", async () => {
3223 const dir = mkdtempSync(join(tmpdir(), "forge-asked-once-"));
@@ -37,17 +28,15 @@ describe("landings ask git once per merge commit", () => {
3728 const repo = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "r", visibility: "public", description: "r" });
3829 if (!repo.ok) throw new Error(repo.error);
3930 const gitDir = repoDir(app.reposRoot, "alice", "r");
40 const a = git(gitDir, "commit-tree", TREE, "-m", "a");
41 const b = git(gitDir, "commit-tree", TREE, "-p", a, "-m", "b");
42 const c = git(gitDir, "commit-tree", TREE, "-m", "c");
43 const d = git(gitDir, "commit-tree", TREE, "-m", "d");
31 const a = git(gitDir, "commit-tree", EMPTY_TREE, "-m", "a");
32 const b = git(gitDir, "commit-tree", EMPTY_TREE, "-p", a, "-m", "b");
33 const c = git(gitDir, "commit-tree", EMPTY_TREE, "-m", "c");
34 const d = git(gitDir, "commit-tree", EMPTY_TREE, "-m", "d");
4435 let n = 0;
4536 const merge = (oid: string) => {
4637 n++;
4738 const at = new Date(Date.now() - (10 - n) * 60_000).toISOString();
48 const issueId = id();
49 app.db.query(`INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at) VALUES (?1, ?2, ?3, 'pull', 'P', '', ?4, 'closed', ?5)`).run(issueId, repo.value.id, n, u.value.id, at);
50 app.db.query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id, merged_at, merged_oid) VALUES (?1, ?2, ?3, '', '', ?4, ?5, ?6)`).run(issueId, repo.value.defaultBranch, `b/${n}`, repo.value.id, at, oid);
39 mergedPull(app.db, { repoId: repo.value.id, branch: repo.value.defaultBranch, authorId: u.value.id, n, oid, at, title: "P" });
5140 };
5241
5342 // A `git` that logs its arguments, then runs the real one.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs