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

The changelog stops finding what is live when production trails main by more than 300 merged pulls #15328

Merged opened this

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

Merged

scout/forge:scout/15327-the-changelog-stops-finding-what-is-live → main 0 commits fork

  • Merged. scout/15327-the-changelog-stops-finding-what-is-live was merged into main as eaf609e.

Review

Sign in to review this change.
2 files changed +64 −6
src/release/landings.ts +25 −6
@@ -385,6 +385,15 @@ async function buildersOfRepo(app: App, own: string, rows: readonly MergedRow[])
385385
386386 /** Merged rows read per round while a window fills. */
387387 const BATCH = 300;
388 /** Rounds of `BATCH` an unwindowed read makes at most while it looks for a live pull. */
389 const MAX_BATCHES = 10;
390
391 /** Whether one of `rows` that belongs to the forge's own repository is live. */
392 function liveOfItsOwn(rows: readonly MergedRow[], state: LiveState | undefined): boolean {
393 if (state === undefined) return true;
394 const own = state.own.toLowerCase();
395 return split(rows, state).live.some((l) => l.repo.toLowerCase() === own);
396 }
388397
389398 /**
390399 * Every landing, live or on its way, as of the running commit. With a
@@ -394,16 +403,26 @@ const BATCH = 300;
394403 * pulls run out. A cursor that names nothing is the first page. Without a
395404 * window, the full read.
396405 */
397 export async function readLandings(app: App, window?: Window): Promise<Landings> {
406 export async function readLandings(app: App, window?: Window, size = BATCH): Promise<Landings> {
398407 let rows: readonly MergedRow[];
399408 let point: string | undefined;
400409 if (window === undefined) {
401 rows = mergedRows(app.db);
402 await askLive(app, rows).catch(() => undefined);
410 let all = mergedRows(app.db, size);
411 await askLive(app, all).catch(() => undefined);
412 // Production may trail by more than one batch: read older rows, at most `MAX_BATCHES` in all,
413 // until a live one of the forge's own shows. Git is asked of each commit once (`askLive`
414 // keeps its answers), so a pass costs a query and no new git. At the cap the read stops
415 // with what it has: nothing listed as live, as it was before the loop.
416 for (let n = 1; n < MAX_BATCHES && all.length === n * size && !liveOfItsOwn(all, keeps.get(app.db)); n++) {
417 const last = all[all.length - 1]!;
418 all = [...all, ...mergedRows(app.db, size, `${last.repo}#${last.number}`)];
419 await askLive(app, all).catch(() => undefined);
420 }
421 rows = all;
403422 } else {
404423 point = window.before !== undefined && cursorPoint(app.db, window.before) !== undefined ? window.before : undefined;
405424 // The forge's own repository is found from the newest rows, so `keep` can name it.
406 let batch = mergedRows(app.db, BATCH, point);
425 let batch = mergedRows(app.db, size, point);
407426 const key = (r: readonly MergedRow[]) => r.map((m) => `${m.repo}#${m.number}`).join();
408427 let asked = key(batch);
409428 await askLive(app, batch).catch(() => undefined);
@@ -412,11 +431,11 @@ export async function readLandings(app: App, window?: Window): Promise<Landings>
412431 const got: MergedRow[] = [];
413432 let after = point;
414433 for (let first = true; ; first = false) {
415 if (!first) batch = mergedRows(app.db, BATCH, after);
434 if (!first) batch = mergedRows(app.db, size, after);
416435 got.push(...wanted(batch, own));
417436 const last = batch[batch.length - 1];
418437 if (last !== undefined) after = `${last.repo}#${last.number}`;
419 if (batch.length < BATCH) break;
438 if (batch.length < size) break;
420439 asked = key(got);
421440 await askLive(app, got).catch(() => undefined);
422441 if (split(got, keeps.get(app.db)).live.length > window.limit) break;
test/landings-asked-once.test.ts +39
@@ -73,4 +73,43 @@ describe("landings ask git once per merge commit", () => {
7373 expect(asks(c)).toBe(1);
7474 expect(mergeBases()).toBe(3);
7575 });
76
77 // Rows are read 4 at a time here, so a trail of 10 crosses the batch boundary twice.
78 const trailing = async (live: boolean, total: number) => {
79 const dir = mkdtempSync(join(tmpdir(), "forge-trail-"));
80 dirs.push(dir);
81 const app = createApp({ dataDir: dir, port: 0 });
82 const u = await createUser(app.db, { username: "alice", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true });
83 if (!u.ok) throw new Error(u.error);
84 const repo = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "r", visibility: "public", description: "r" });
85 if (!repo.ok) throw new Error(repo.error);
86 const gitDir = repoDir(app.reposRoot, "alice", "r");
87 const running = git(gitDir, "commit-tree", EMPTY_TREE, "-m", "running");
88 process.env.FORGE_COMMIT = running; // env-restored: afterEach
89 (app.config as { forgeRepo?: string }).forgeRepo = "alice/r";
90 for (let n = 1; n <= total; n++) {
91 // Pull 1 is the running commit (unless none is live); every other is a root commit outside
92 // it.
93 const oid = n === 1 && live ? running : git(gitDir, "commit-tree", EMPTY_TREE, "-m", `c${n}`);
94 const at = new Date(Date.UTC(2026, 0, 1) + n * 60_000).toISOString();
95 mergedPull(app.db, { repoId: repo.value.id, branch: repo.value.defaultBranch, authorId: u.value.id, n, oid, at, title: "P" });
96 }
97 return app;
98 };
99
100 test("production older than the newest batch of merged pulls still finds what is live", async () => {
101 const app = await trailing(true, 10);
102 const full = await readLandings(app, undefined, 4);
103 expect(full.live.map((l) => l.number)).toEqual([1]);
104 expect(full.onItsWay.length).toBe(9);
105 const paged = await readLandings(app, { limit: 30 }, 4);
106 expect(paged.live.map((l) => l.number)).toEqual([1]);
107 });
108
109 test("with no live pull the read ends, listing none live", async () => {
110 const app = await trailing(false, 10);
111 const full = await readLandings(app, undefined, 4);
112 expect(full.live).toEqual([]);
113 expect(full.onItsWay.length).toBe(10);
114 });
76115 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs