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

A push to main recombines every open kept-fork pull, so its combined preview is never stale for long #9941

Parked opened this
Closed without merging

scout/forge:scout/9931-a-push-to-main-recombines-every-open-kep → main 9 commits fork 4 threads · 4 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
9 files changed +361 −11
docs/features/upstream-landing.md +10
@@ -24,9 +24,15 @@ The rule lives in `landingKind` (`src/core/landing_kind.ts`) and `mergePull` app
2424
2525 When main has moved since a kept fork's head, the forge merges main into that head in a branch of the base repository, `combined/N` (`src/git/combined.ts`), on opening the pull, on every push to the fork, and again just before landing. The author's branch is never written. Each conflicting block keeps main's side, with no review: the author's side of that block is dropped from the landed tree, and the note says so and how to get it back (merge main into their branch, resolve, push: a head that already has main is its own combined build). A conflict git cannot pick a side of (modify/delete, rename) is left open. The combined commit's message is the note, and its `Combined-Base` and `Combined-Kept` trailers are the facts the pull renders from (`src/core/combined_view.ts`): a "Combined with main" card on the page and the same section on the terminal's pull screen. The preview builds `combined/N`, under the approval of the head it carries (read from git, `headUnder`), and landing merges it, so the author's head stays an ancestor of main. Commits pushed on top of `combined/N` by a writer are kept by the next combining.
2626
27 <<<<<<< HEAD
28 A push to main recombines every open kept-fork pull into it (`src/core/recombine.ts`, #9931): off the push's answer, one pass at a time per repository, a burst of pushes coalescing into one more pass. The card marks itself stale, naming the main commit it was built on, only while that runs; if a rebuild fails it stays stale and says why, until the next push to the fork or main, or the landing. Checks run on the pull's head, not on the combined commit, and the card says that too.
29
30 Test: `test/combined-fork.test.ts` (open, page, terminal, a push recombining, landing), `test/combined-recombine.test.ts` (main alone moving, a failed rebuild, coalescing) and `test/combined-git.test.ts` (a writer's commit surviving, modify/delete left open, the head a preview runs under).
31 =======
2732 A push to main alone does not recombine: the card marks itself stale, naming the main commit it was built on, until the next push to the fork or the landing recombines. The pull's fast check runs on the combined commit, not the author's head alone (`checks/service.ts`): its log and the checks line say "checked as combined with main at abc1234", the run records that base, and the green is stale only when `combined/N` is built on an older main than the tip. A pull from inside one repository is still checked as its head merged into main. The run stays keyed to the head (`commit_oid`), so head lookups and the merge gate find it; the combined commit it tested is recorded on the run (`combined_oid`), and the checks line reads "as combined" from that, never from the tree, so a check that ran before `combined/N` existed says "against".
2833
2934 Test: `test/combined-check.test.ts` (the check's source, its words, stale, an in-repository pull unchanged), `test/combined-fork.test.ts` (open, page, terminal, a push recombining, stale, landing) and `test/combined-git.test.ts` (a writer's commit surviving, modify/delete left open, the head a preview runs under).
35 >>>>>>> origin/main
3036
3137 ## A merge must bring the work
3238
@@ -38,4 +44,8 @@ Test: `test/source-merge-held.test.ts` (two forges, an `-s ours` merge held, a m
3844
3945 ## Not yet
4046
47 <<<<<<< HEAD
48 Landing a very large fork in reviewed slices that still end as a merge of the author's head; routing a pull opened on the Forgejo mirror to trunk; a crew run sent to refine `combined/N` beyond main's side; running the check on the combined commit; and running his code under the guest rule until a person approves (#8903 is not in this repository). Resolving conflicts on our side is today's resolve page (`docs/PULLS.md`).
49 =======
4150 Landing a very large fork in reviewed slices that still end as a merge of the author's head; routing a pull opened on the Forgejo mirror to trunk; a crew run sent to refine `combined/N` beyond main's side; recombining when main alone moves and running his code under the guest rule until a person approves (#8903 is not in this repository). Resolving conflicts on our side is today's resolve page (`docs/PULLS.md`).
51 >>>>>>> origin/main
src/actions/pulls.ts +15 −1
@@ -4,6 +4,7 @@
44 * issues — a pull is an issue with a diff.
55 */
66
7 import { exclusive } from "../core/recombine.ts";
78 import { isContributionFork, type GuestRefusal } from "../core/contribute.ts";
89 import { takeGuestPull } from "./guests.ts";
910 import { requireAbility } from "./roles.ts";
@@ -468,7 +469,20 @@ function postLine(
468469 return added;
469470 }
470471
471 export async function mergePull(
472 /** Landing takes the repository's turn: it never overlaps a recombine pass (#9931). */
473 export function mergePull(
474 app: App,
475 actor: User | undefined,
476 repo: Repo,
477 pull: Pull,
478 requested: MergeStrategy,
479 expect?: LandingExpect,
480 opts: { readonly pastGate?: boolean } = {},
481 ): ReturnType<typeof mergeNow> {
482 return exclusive(repo.id, () => mergeNow(app, actor, repo, pull, requested, expect, opts));
483 }
484
485 async function mergeNow(
472486 app: App,
473487 actor: User | undefined,
474488 repo: Repo,
src/core/combined_view.ts +8 −2
@@ -6,6 +6,7 @@
66 */
77
88 import type { Pull } from "./pulls.ts";
9 import { recombineFailure } from "./recombine.ts";
910 import { keptLine, readCombined, TAKE_BACK, type Kept } from "../git/combined.ts";
1011
1112 export interface CombinedView {
@@ -15,6 +16,8 @@ export interface CombinedView {
1516 readonly builtOn: string;
1617 /** Main has moved past `builtOn`: the preview is not what lands until it recombines. */
1718 readonly stale: boolean;
19 /** Why the rebuild on the new main failed, when it did. */
20 readonly failure?: string;
1821 readonly files: readonly Kept[];
1922 }
2023
@@ -29,11 +32,14 @@ export async function combinedView(
2932 const read = await readCombined(dir, pull.number, headOid);
3033 // Main already in the head: the preview is the head itself, nothing to say.
3134 if (read === undefined || read.oid === headOid) return undefined;
35 const stale = read.baseOid !== "" && read.baseOid !== baseOid;
36 const failure = stale ? recombineFailure(pull.repoId, pull.number) : undefined;
3237 return {
38 ...(failure === undefined ? {} : { failure }),
3339 branch: read.branch,
3440 oid: read.oid,
3541 builtOn: read.baseOid,
36 stale: read.baseOid !== "" && read.baseOid !== baseOid,
42 stale,
3743 files: read.files,
3844 };
3945 }
@@ -46,7 +52,7 @@ export function combinedWords(
4652 const notes: string[] = [];
4753 if (view.stale)
4854 notes.push(
49 `Stale: main has moved since ${view.builtOn.slice(0, 10)}, which this was built on. It recombines on the next push to the fork, and merging recombines before it lands, so what lands may differ from the preview.`,
55 `Stale: main has moved since ${view.builtOn.slice(0, 10)}, which this was built on. ${view.failure === undefined ? "It recombines on its own" : `Recombining failed: ${view.failure} It recombines on the next push`}, and merging recombines before it lands, so what lands may differ from the preview.`,
5056 );
5157 notes.push("The checks line says which commit the check ran on.");
5258 if (view.files.some((f) => f.kept === "main")) notes.push(TAKE_BACK);
src/core/recombine.ts added +109
@@ -0,0 +1,109 @@
1 /**
2 * A push to a repository's default branch recombines every open kept-fork
3 * pull into it (#9931): `combined/N` is rebuilt on the new tip, so the card
4 * is stale only while the rebuild runs. Off the request path, one rebuild
5 * pass at a time per repository; pushes that arrive during a pass coalesce
6 * into one more pass that reads the tip as it then stands. A rebuild that
7 * fails leaves the card stale and keeps the failure's sentence for it.
8 */
9
10 import type { App } from "../app.ts";
11 import type { Repo } from "./repos.ts";
12 import { listOpenPulls } from "./pulls.ts";
13 import { fromKeptFork } from "./landing_kind.ts";
14 import { combine } from "../git/combined.ts";
15 import { resolveOid } from "../git/merge.ts";
16 import { repoDir } from "../git/repos.ts";
17
18 type Combine = typeof combine;
19
20 interface Lane {
21 running: Promise<void>;
22 again: boolean;
23 }
24
25 const lanes = new Map<string, Lane>();
26 const failures = new Map<string, string>();
27 const turns = new Map<string, Promise<unknown>>();
28
29 /**
30 * Run `work` when nothing else holds this repository's turn: a pass and a
31 * landing never overlap, so a merge cannot lose its compare-and-set to a
32 * rebuild and land the bare head instead of `combined/N`.
33 */
34 export function exclusive<T>(repoId: string, work: () => Promise<T>): Promise<T> {
35 const mine = (turns.get(repoId) ?? Promise.resolve()).then(work, work);
outdated

Security/correctness: the pass is not serialized with mergePull. The author admits a landing racing a pass can lose the update-ref compare-and-set and then land the head instead of combined/N, silently landing something other than what the card promised. Make mergePull wait for (or join) the repository lane before it recombines and lands, or retry the CAS; add a test for it.

36 const tail = mine.catch(() => undefined);
37 turns.set(repoId, tail);
38 void tail.then(() => {
39 if (turns.get(repoId) === tail) turns.delete(repoId);
40 });
41 return mine;
42 }
43
44 /** Resolves when no pass is running or waiting for this repository. */
45 export async function settled(repoId: string): Promise<void> {
46 for (let lane = lanes.get(repoId); lane !== undefined; lane = lanes.get(repoId)) await lane.running;
47 }
48
outdated

Leak: String(error).slice(0,200) is raw git/runtime error text (paths, stderr) and is rendered to every viewer of the pull page and terminal. Store a fixed plain sentence for the viewer and log the detail server-side only. Also the failures map is never pruned for closed/merged pulls (and the early continue on a missing oid leaves a stale entry): delete the entry when the pull is not open.

49 const key = (repoId: string, number: number): string => `${repoId}:${number}`;
50
51 /** Why the last rebuild of this pull failed, while it is still the last word. */
52 export const recombineFailure = (repoId: string, number: number): string | undefined =>
53 failures.get(key(repoId, number));
54
55 /** One pass: each open kept-fork pull into this repository, one after another. */
56 async function pass(app: App, repo: Repo, run: Combine): Promise<void> {
57 const dir = repoDir(app.reposRoot, repo.ownerName, repo.name);
58 const open = listOpenPulls(app.db, repo.id);
59 // A pull that is no longer open keeps no sentence.
60 for (const k of [...failures.keys()])
61 if (k.startsWith(`${repo.id}:`) && !open.some((p) => key(repo.id, p.number) === k)) failures.delete(k);
62 for (const pull of open) {
63 if (pull.baseBranch !== repo.defaultBranch || !fromKeptFork(app.db, pull)) continue;
64 const k = key(repo.id, pull.number);
65 try {
66 const baseOid = await resolveOid(dir, `refs/heads/${pull.baseBranch}`);
67 const headOid = (await resolveOid(dir, `refs/pull/${pull.number}/head`)) ?? pull.headOid;
68 if (baseOid === undefined || !headOid) {
69 failures.delete(k);
70 continue;
71 }
72 const built = await run(dir, { number: pull.number, baseOid, headOid });
73 if (built === undefined) failures.set(k, "git could not merge main into this head.");
74 else failures.delete(k);
75 } catch (error) {
76 failures.set(k, "the rebuild did not finish.");
77 app.log.warn("could not recombine a pull", {
78 repo: `${repo.ownerName}/${repo.name}`,
79 pull: pull.number,
80 error: String(error),
81 });
82 }
83 }
84 }
85
86 /**
87 * Ask for a recombine of this repository's pulls. Answers at once; the
88 * promise settles when the pass that covers this request has finished.
89 */
90 export function recombineOnMain(app: App, repo: Repo, run: Combine = combine): Promise<void> {
91 const lane = lanes.get(repo.id);
92 if (lane !== undefined) {
93 lane.again = true;
94 return lane.running;
95 }
96 const next: Lane = { again: false, running: Promise.resolve() };
97 next.running = (async () => {
98 try {
99 do {
100 next.again = false;
101 await exclusive(repo.id, () => pass(app, repo, run));
102 } while (next.again);
103 } finally {
104 lanes.delete(repo.id);
105 }
106 })();
107 lanes.set(repo.id, next);
108 return next.running;
109 }
src/http/server.ts +15
@@ -68,6 +68,7 @@ import {
6868 getRepoById,
6969 } from "../core/repos.ts";
7070 import { trackPullHead } from "../core/pulls.ts";
71 import { recombineOnMain } from "../core/recombine.ts";
7172 import { createRepo, repositoryLimitMessage, resolveOwner } from "../actions/repos.ts";
7273 import { sessionOf } from "../core/sessions.ts";
7374 import { scopeAllows, verifyToken } from "../core/tokens.ts";
@@ -2031,6 +2032,20 @@ async function handleHook(app: App, request: Request): Promise<Response> {
20312032 );
20322033 }
20332034
2035 // A push to the default branch recombines the kept forks' pulls into it,
2036 // off the hook's answer (`core/recombine.ts`, #9931).
2037 if (
2038 input.updates.some(
2039 (u) => u.ref === `refs/heads/${repo.defaultBranch}` && !ZERO_OID.test(u.newOid),
2040 )
2041 )
2042 void recombineOnMain(app, repo).catch((error) =>
2043 app.log.warn("could not recombine pulls", {
2044 repo: `${repo.ownerName}/${repo.name}`,
2045 error: String(error),
2046 }),
2047 );
2048
20342049 // post-receive: the push is durable — record it and wake listeners.
20352050 app.bus.append({
20362051 kind: "push",
src/web/pages/pull.ts +6 −2
@@ -8,6 +8,7 @@
88 * it needs.
99 */
1010
11 import { aheadCount } from "../../git/merge.ts";
1112 import { pullRoster } from "../studio/pull_roster.ts";
1213 import { originCheckLead, originCheckOf } from "../../origins/pull-check.ts";
1314 import { askCheck } from "../../checks/again.ts";
@@ -987,8 +988,11 @@ export async function pullFilesPage(ctx: Ctx): Promise<Response> {
987988 ),
988989 )
989990 : [];
991 // The author's own commits left: `status.ahead` counts the combined

Scope: the slices-count change (aheadCount) is unrelated to the issue and leaves the files-page status line still wrong, as the pull itself says. Split it into its own small pull, or fix the count at its source; the direction asks for small single-purpose pulls.

992 // branch, whose merge of main is not one of them (#9931).
993 const own = pull.crossRepo ? await aheadCount(dir, status.baseOid, status.headOid) : status.ahead;
990994 const ends =
991 pull.crossRepo && mayLand && pull.state === "open" && pull.mergedAt === null && status.ahead > 1
995 pull.crossRepo && mayLand && pull.state === "open" && pull.mergedAt === null && own > 1
992996 ? await lap("git", () =>
993997 keptRead(`slice-ends:${repo.id}:${status.baseOid}:${status.headOid}`, () =>
994998 sliceEnds(dir, status.baseOid, status.headOid),
@@ -1054,7 +1058,7 @@ export async function pullFilesPage(ctx: Ctx): Promise<Response> {
10541058 ${holdCard(ctx, repo, pull, { act: false })}
10551059 ${teamsCard(teamVerdicts(ctx.app.db, { ...pull, headOid: status.headOid }))}
10561060 ${mergeBox(ctx, repo, pull, status, mayMerge, by, check, isApp, tier, stale)}
1057 ${slicesCard(base, thread, slices, status.ahead, ends, pull.state === "open" && pull.mergedAt === null, mayLand)}
1061 ${slicesCard(base, thread, slices, own, ends, pull.state === "open" && pull.mergedAt === null, mayLand)}
10581062 ${await combinedCard(dir, pull, status.headOid, status.baseOid)}
10591063 <div class="split">
10601064 <div>
test/combined-fork.test.ts +1 −4
@@ -181,14 +181,11 @@ describe("a conflicting fork pull is combined on our side (#9012)", () => {
181181 expect((await git(["log", "-1", "--format=%P", retip], bare)).split(" ")).toEqual([bobNext, aliceMain]);
182182 expect(await previewCommit(bare, getPull(app.db, repo.id, number)!)).toBe(retip);
183183
184 // Main moves on its own: the card says the preview is stale, and on what it was built.
184 // Main moves on its own: it recombines by itself (test/combined-recombine.test.ts).
185185 await Bun.write(join(a, "four.txt"), "four\n");
186186 await git(["add", "."], a);
187187 await git(["commit", "-m", "alice's four"], a);
188188 await git(["push", "origin", "main"], a);
189 const stale = await (await call(`/alice/app/pulls/${number}`, alice)).text();
190 expect(stale).toContain(`Stale: main has moved since ${aliceMain.slice(0, 10)}`);
191 expect(await screenText()).toContain("Combined with main · stale");
192189
193190 // The merge lands the combined branch: his head is an ancestor of main.
194191 const merged = await call(`/api/v1/repos/alice/app/pulls/${number}/merge`, alice, { strategy: "merge" });
test/combined-recombine.test.ts added +195
@@ -0,0 +1,195 @@
1 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { mkdtemp, rm } from "node:fs/promises";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import { createApp, type App } from "../src/app.ts";
6 import { serve, type Servers } from "../src/http/server.ts";
7 import { gitClientEnv } from "./helpers/git-client.ts";
8 import { proveAll } from "./helpers/verified.ts";
9 import { promote } from "./helpers/members.ts";
10 import { getRepo } from "../src/core/repos.ts";
11 import { repoDir } from "../src/git/repos.ts";
12 import { combinedWords } from "../src/core/combined_view.ts";
13 import { exclusive, recombineFailure, recombineOnMain, settled } from "../src/core/recombine.ts";
14 import { tokenFor } from "./helpers/tokens.ts";
15
16 const gitEnv = gitClientEnv({
17 GIT_AUTHOR_NAME: "Jay Moran",
18 GIT_AUTHOR_EMAIL: "[email protected]",
19 GIT_COMMITTER_NAME: "Jay Moran",
20 GIT_COMMITTER_EMAIL: "[email protected]",
21 });
22
23 describe("a push to main recombines every open kept-fork pull (#9931)", () => {
24 let dataDir: string;
25 let work: string;
26 let app: App;
27 let servers: Servers;
28 let base: string;
29 let alice = "";
30 let bob = "";
31
32 async function git(args: string[], cwd: string): Promise<string> {
33 const p = Bun.spawn(["git", ...args], { cwd, env: gitEnv, stdout: "pipe", stderr: "pipe" });
34 const [out, err, code] = await Promise.all([
35 new Response(p.stdout).text(),
36 new Response(p.stderr).text(),
37 p.exited,
38 ]);
39 if (code !== 0) throw new Error(`git ${args.join(" ")}: ${err}`);
40 return out.trim();
41 }
42 const call = (path: string, token: string, body?: unknown): Promise<Response> =>
43 fetch(`${base}${path}`, {
44 method: body === undefined ? "GET" : "POST",
45 headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
46 ...(body === undefined ? {} : { body: JSON.stringify(body) }),
47 });
48 const authed = (user: string, token: string) =>
49 `${base.replace("http://", `http://${user}:${token}@`)}`;
50
51 async function signup(username: string): Promise<string> {
52 await fetch(`${base}/signup`, {
53 method: "POST",
54 body: new URLSearchParams({ username, email: `${username}@f.dev`, password: "kept-fork-pass" }),
55 redirect: "manual",
56 });
57 return tokenFor(app, username, "admin", "k");
58 }
59
60 beforeAll(async () => {
61 dataDir = await mkdtemp(join(tmpdir(), "forge-cb-"));
62 work = await mkdtemp(join(tmpdir(), "forge-cb-work-"));
63 app = createApp({ dataDir, port: 0 });
64 servers = await serve(app);
65 base = servers.url;
66 alice = await signup("alice");
67 bob = await signup("bob");
68 proveAll(app);
69 promote(app.db);
70 await call("/api/v1/repos", alice, { name: "app", visibility: "public" });
71 await git(["clone", `${authed("alice", alice)}/alice/app.git`, "a"], work);
72 await Bun.write(join(work, "a/one.txt"), "one\n");
73 await git(["add", "."], join(work, "a"));
74 await git(["commit", "-m", "seed"], join(work, "a"));
75 await git(["push", "origin", "main"], join(work, "a"));
76 await call("/api/v1/repos/alice/app/forks", bob, {});
77 });
78
79 afterAll(async () => {
80 servers.stop();
81 app.close();
82 await rm(dataDir, { recursive: true, force: true });
83 await rm(work, { recursive: true, force: true });
outdated

Test: polling git with Bun.sleep up to 5s for a background pass is timing-dependent, against the direction of fast tests that never flake. Expose a way to await the lane (e.g. the lane promise for the repo) and await it. Also move the mid-file imports to the top. The removed stale assertions in combined-fork.test.ts leave the stale card (page and terminal) covered only by a unit call; add a page-level stale test using an injected failure.

84 });
85
86 test("main alone moving rebuilds combined/N on the new tip, and the card clears", async () => {
87 const a = join(work, "a");
88 const b = join(work, "b");
89 await git(["clone", `${authed("bob", bob)}/bob/app.git`, "b"], work);
90 await Bun.write(join(b, "bob.txt"), "bob\n");
91 await git(["add", "."], b);
92 await git(["commit", "-m", "bob's work"], b);
93 await git(["push", "origin", "main"], b);
94
95 await Bun.write(join(a, "two.txt"), "two\n");
96 await git(["add", "."], a);
97 await git(["commit", "-m", "alice two"], a);
98 await git(["push", "origin", "main"], a);
99
100 const opened = await call("/api/v1/repos/alice/app/pulls", bob, {
101 title: "work", base: "main", head: "main", headRepo: "bob/app",
102 });
103 const { number } = (await opened.json()) as { number: number };
104 const bare = repoDir(app.reposRoot, "alice", "app");
105 const before = await git(["rev-parse", `refs/heads/combined/${number}`], bare);
106
107 await Bun.write(join(a, "three.txt"), "three\n");
108 await git(["add", "."], a);
109 await git(["commit", "-m", "alice three"], a);
110 await git(["push", "origin", "main"], a);
111 const main = await git(["rev-parse", "HEAD"], a);
112
113 // The push's own pass, off the hook's answer: wait for the lane, never poll git.
114 await settled(getRepo(app.db, "alice", "app")!.id);
115 const after = await git(["rev-parse", `refs/heads/combined/${number}`], bare);
116 expect(after).not.toBe(before);
117 expect((await git(["log", "-1", "--format=%P", after], bare)).split(" ")).toContain(main);
118 const page = await (await call(`/alice/app/pulls/${number}`, alice)).text();
119 expect(page).toContain(`combined/${number}`);
120 expect(page).not.toContain("Stale: main has moved");
121 }, 30_000);
122
123 test("a failed rebuild keeps its sentence for the card, and the next success clears it", async () => {
124 const repo = getRepo(app.db, "alice", "app")!;
125 const [pull] = [...app.db.query("SELECT i.number FROM issue i JOIN pull p ON p.issue_id = i.id WHERE i.repo_id = ?1 AND i.state = 'open'").all(repo.id)] as { number: number }[];
126 await recombineOnMain(app, repo, async () => undefined);
127 expect(recombineFailure(repo.id, pull!.number)).toContain("could not merge main");
128 const view = {
129 branch: "combined/1", oid: "a".repeat(40), builtOn: "b".repeat(40), stale: true,
130 failure: recombineFailure(repo.id, pull!.number)!, files: [],
131 };
132 expect(combinedWords(view, 1).notes[0]).toContain("Recombining failed: git could not merge main");
133 await recombineOnMain(app, repo);
134 expect(recombineFailure(repo.id, pull!.number)).toBeUndefined();
135 }, 30_000);
136
137 test("the card says a failed rebuild in plain words, never git's own", async () => {
138 const repo = getRepo(app.db, "alice", "app")!;
139 const bare = repoDir(app.reposRoot, "alice", "app");
140 const [pull] = [...app.db.query("SELECT i.number FROM issue i JOIN pull p ON p.issue_id = i.id WHERE i.repo_id = ?1 AND i.state = 'open'").all(repo.id)] as { number: number }[];
141 // Main moves without the hook, so the combined branch is behind it.
142 const a = join(work, "a");
143 await Bun.write(join(a, "quiet.txt"), "quiet\n");
144 await git(["add", "."], a);
145 await git(["commit", "-m", "quiet"], a);
146 const tip = await git(["rev-parse", "HEAD"], a);
147 await git(["fetch", join(work, "a"), "HEAD"], bare);
148 await git(["update-ref", "refs/heads/main", tip], bare);
149 await recombineOnMain(app, repo, async () => {
150 throw new Error("fatal: /secret/path exploded");
151 });
152 const page = await (await call(`/alice/app/pulls/${pull!.number}`, alice)).text();
153 expect(page).toContain("Recombining failed: the rebuild did not finish.");
154 expect(page).not.toContain("/secret/path");
155 await recombineOnMain(app, repo);
156 const fine = await (await call(`/alice/app/pulls/${pull!.number}`, alice)).text();
157 expect(fine).not.toContain("Recombining failed");
158 }, 30_000);
159
160 test("a landing waits for the pass in flight, and a pass for the landing", async () => {
161 const repo = getRepo(app.db, "alice", "app")!;
162 const log: string[] = [];
163 let release = () => {};
164 const gate = new Promise<void>((r) => (release = r));
165 const held = recombineOnMain(app, repo, async () => {
166 log.push("pass:start");
167 await gate;
168 log.push("pass:end");
169 return undefined;
170 });
171 while (!log.includes("pass:start")) await Bun.sleep(1);
172 const landing = exclusive(repo.id, async () => void log.push("landing"));
173 release();
174 await Promise.all([held, landing]);
175 expect(log).toEqual(["pass:start", "pass:end", "landing"]);
176 });
177
178 test("bursts coalesce: at most one pass at a time, one more after", async () => {
179 const repo = getRepo(app.db, "alice", "app")!;
180 let live = 0;
181 let peak = 0;
182 let calls = 0;
183 const slow = async () => {
184 calls++;
185 live++;
186 peak = Math.max(peak, live);
187 await Bun.sleep(30);
188 live--;
189 return undefined;
190 };
191 await Promise.all([1, 2, 3, 4].map(() => recombineOnMain(app, repo, slow)));
192 expect(peak).toBe(1);
193 expect(calls).toBe(2); // the pass that ran, and one more for the burst behind it
194 }, 30_000);
195 });
test/tui-crawlers.test.ts +2 −2
@@ -11,7 +11,7 @@ import { createForgeApp, forgeCommands } from "../src/tui/forge.ts";
1111 import { crawlersScreen } from "../src/tui/screens/crawlers.ts";
1212 import { headlessTerminal } from "../src/tui/term/terminal.ts";
1313 import { quietLogs } from "./helpers/globals.ts";
14 import { settleApp } from "./helpers/tui.ts";
14 import { settleUntil } from "./helpers/tui.ts";
1515
1616 quietLogs();
1717
@@ -57,7 +57,7 @@ test("the screen shows the share, the budgets that refused and the agent refused
5757 const { app: tui, session } = createForgeApp(app, identity(carol), { terminal: headlessTerminal(140, 20), exitHooks: false });
5858 tui.start();
5959 tui.ctx.push(crawlersScreen(session, tui.ctx));
60 await settleApp(tui);
60 await settleUntil(tui, "screenbot");
6161 const text = tui.screen.toText();
6262 expect(text).toContain("Share of answering time");
6363 expect(text).toContain("address 2");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs