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

The runtime's approval gate reads a pull's combined tip without a blocking git call #17898

opened this

Merged 22h 39m ago, live in production

scout/forge:scout/17883-the-runtime-s-approval-gate-reads-a-pull → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/17883-the-runtime-s-approval-gate-reads-a-pull was merged into main as 9883372.

Review

Sign in to review this change.
13 files changed +232 −40
src/actions/apps.ts +2 −2
@@ -76,7 +76,7 @@ import type { Run } from "../core/runs.ts";
7676 import { type User } from "../core/users.ts";
7777 import { resolveOid } from "../git/merge.ts";
7878 import { exactRefOid } from "../git/branches.ts";
79 import { previewCommit } from "../git/combined.ts";
79 import { carriedOf, previewCommit } from "../git/combined.ts";
8080 import { repoDir } from "../git/repos.ts";
8181 import { err, ok, type Result } from "../kernel/result.ts";
8282 import {
@@ -891,7 +891,7 @@ async function commitFor(
891891 if (!pull || pull.state !== "open") return undefined;
892892 const at = await pullDir(app.db, app.reposRoot, repo, pull);
893893 // A fork's pull combined on our side previews the combined build (#9012).
894 return previewCommit(at, pull);
894 return previewCommit(at, pull, carriedOf(app.db));
895895 }
896896
897897 export { previewEnv };
src/apps/runtime.ts +8
@@ -39,6 +39,7 @@ import { Gate } from "../git/env.ts";
3939 import { resolveOid } from "../git/merge.ts";
4040 import { exactRefOid } from "../git/branches.ts";
4141 import { repoDir } from "../git/repos.ts";
42 import { carriedOf, type Carried } from "../git/combined.ts";
4243 import { STALE_AFTER_MS } from "../runs/lease.ts";
4344 import { appendRunLog } from "../runs/log.ts";
4445 import { primaryDomain, primaryHosts } from "../core/domains.ts";
@@ -75,12 +76,19 @@ export class AppsRuntime {
7576 stopped = false;
7677 /** Counts build previews as they start, so the oldest is the lowest. */
7778 buildCount = 0;
79 /**
80 * Heads seen carried by their combined tips, this forge's: the approval gate reads it with no
81 * git call (#17883). `combine` fills it as it writes a tip; at boot, `reconcileApp` reads each
82 * open pull's head (`pullHead`) before it asks `mayRun`.
83 */
84 readonly carried: Carried;
7885
7986 constructor(
8087 readonly app: App,
8188 readonly options: RuntimeOptions,
8289 ) {
8390 this.gate = options.gate ?? new Gate(options.concurrency ?? 2);
91 this.carried = carriedOf(app.db);
8492 registerRuntime(app, this);
8593 // Closing the forge closes the database next: end every open awake
8694 // interval now, while it can be written, and write nothing after.
src/apps/runtime_events.ts +1 −1
@@ -89,7 +89,7 @@ export function pruneDirs(rt: AppsRuntime, known: Set<string>): void {
8989 export async function pullHead(rt: AppsRuntime, repo: Repo, pull: Pull): Promise<string | undefined> {
9090 const dir = await pullDir(rt.app.db, rt.app.reposRoot, repo, pull);
9191 // A fork's pull combined on our side previews the combined build (#9012).
92 return previewCommit(dir, pull);
92 return previewCommit(dir, pull, rt.carried);
9393 }
9494
9595 // ---- events ----
src/apps/runtime_sleep.ts +2 −2
@@ -112,11 +112,11 @@ export function mayRun(
112112 number === undefined ? undefined : getPull(rt.app.db, repo.id, number);
113113 // A closed or merged pull has no preview: nothing starts, wakes or redeploys one (#16594).
114114 if (pull !== undefined && pull.state !== "open") return false;
115 // A combined preview runs under the head it carries, read from git (#9012).
115 // A combined preview runs under the head it carries (#9012), read without a git process (#17883).
116116 const head =
117117 pull === undefined
118118 ? commitOid
119 : headUnder(repoDir(rt.app.reposRoot, repo.ownerName, repo.name), pull, commitOid);
119 : headUnder(repoDir(rt.app.reposRoot, repo.ownerName, repo.name), pull, commitOid, rt.carried);
120120 // An outside agent's branch (`contrib/…`) is previewed only once a person who can write has
121121 // approved the pull (`origins/guest.ts`); its check, in a cell, is what runs before that.
122122 if (pull !== undefined && previewMayRun(rt.app.db, repo, pull, head)) return true;
src/core/following.ts +2 −2
@@ -42,7 +42,7 @@ import { describeLink, syncLink, type Reconcile } from "../git/sync_link.ts";
4242 import { readTipOrAbsent, readTipSync } from "../git/tip.ts";
4343 import { readTips } from "../git/tips.ts";
4444 import { repoDir } from "../git/repos.ts";
45 import { combine } from "../git/combined.ts";
45 import { carriedOf, combine } from "../git/combined.ts";
4646 import { fromKeptFork } from "./landing_kind.ts";
4747 import { forkFollowMode, forkFollowModes, lastTookAt, FORK_DEFAULT_MODE, type ForkFollowMode } from "./fork_follow.ts";
4848 import { linkWord, sayLink } from "../flows/link_word.ts";
@@ -562,7 +562,7 @@ export async function refreshPullHead(
562562 if (!apart && fromKeptFork(forge.db, pull)) {
563563 const baseTip = await resolveOid(baseDir, `refs/heads/${pull.baseBranch}`);
564564 if (baseTip !== undefined)
565 await combine(baseDir, { number: pull.number, baseOid: baseTip, headOid: tip });
565 await combine(baseDir, { number: pull.number, baseOid: baseTip, headOid: tip }, carriedOf(forge.db));
566566 }
567567 return tip;
568568 }
src/core/pulls.ts +3 −3
@@ -16,7 +16,7 @@ import { OVER_CAP } from "../git/env.ts";
1616 import { diffRange, type Diff, type DiffLaps } from "../git/diff.ts";
1717 import { isSafeRef } from "../git/guard.ts";
1818 import { refTip } from "../git/read.ts";
19 import { combine, combinedTip } from "../git/combined.ts";
19 import { carriedOf, combine, combinedTip } from "../git/combined.ts";
2020 import { fromKeptFork } from "./landing_kind.ts";
2121 import { readTips } from "../git/tips.ts";
2222 import {
@@ -356,7 +356,7 @@ export async function createPull(
356356 const pull = join(db, issue.value)!;
357357 // A kept fork's pull is combined with main on our side (#9012).
358358 if (at === dir && fromKeptFork(db, pull))
359 await combine(dir, { number: pull.number, baseOid, headOid });
359 await combine(dir, { number: pull.number, baseOid, headOid }, carriedOf(db));
360360 return ok(pull);
361361 }
362362
@@ -1341,7 +1341,7 @@ export async function mergePull(
13411341 // the author's head is its ancestor, so it lands too (#9012).
13421342 const combined =
13431343 input.sealedFrom === undefined && input.strategy === "merge" && fromKeptFork(db, pull)
1344 ? await combine(dir, { number: pull.number, baseOid: status.baseOid, headOid: status.headOid })
1344 ? await combine(dir, { number: pull.number, baseOid: status.baseOid, headOid: status.headOid }, carriedOf(db))
13451345 : undefined;
13461346 // Overlapping edits are never settled by picking a side: the pull is held.
13471347 if (combined?.held === true)
src/core/recombine.ts +2 −2
@@ -8,7 +8,7 @@
88
99 import { REPO_KEYED } from "../kernel/repo_keyed.ts";
1010 import type { Database } from "bun:sqlite";
11 import { combine, readFailure, setFailure } from "../git/combined.ts";
11 import { carriedOf, combine, readFailure, setFailure } from "../git/combined.ts";
1212 import { repoDir } from "../git/repos.ts";
1313 import { resolveOid } from "../git/merge.ts";
1414 import type { Log } from "../kernel/log.ts";
@@ -55,7 +55,7 @@ async function pass(forge: RecombineForge, repoId: string): Promise<void> {
5555 try {
5656 const headOid = await resolveOid(dir, `refs/pull/${pull.number}/head`);
5757 const made =
58 headOid === undefined ? undefined : await combine(dir, { number: pull.number, baseOid, headOid });
58 headOid === undefined ? undefined : await combine(dir, { number: pull.number, baseOid, headOid }, carriedOf(forge.db));
5959 if (made === undefined) {
6060 forge.log.warn("recombine skipped a pull", { repo: repoId, pull: pull.number });
6161 // A refusal has written its own sentence (naming the files);
src/git/combined.ts +60 −17
@@ -13,9 +13,11 @@
1313 * still carries the author's head.
1414 */
1515
16 import { gitEnv, runGit, runGitCapture } from "./env.ts";
16 import type { Database } from "bun:sqlite";
17 import { runGit, runGitCapture } from "./env.ts";
1718 import { isSafeOid, isSafeTreePath } from "./guard.ts";
1819 import { refTip } from "./read.ts";
20 import { readTipSync } from "./tip.ts";
1921 import { mergeBase, resolveOid } from "./merge.ts";
2022 import { unionTree } from "./union.ts";
2123
@@ -42,6 +44,42 @@ const IDENTITY = {
4244 const isAncestor = async (dir: string, a: string, b: string): Promise<boolean> =>
4345 a === b || (await mergeBase(dir, a, b)) === a;
4446
47 /**
48 * Heads seen carried by a combined tip, as `head tip` (#17883), for one forge: kept on the two
49 * oids, never on time. A commit's ancestry never changes, and a force-push moves the ref or the
50 * head to a new oid, so a new key. Filled wherever the forge writes or reads a combined tip
51 * (`combine`, `combinedTip`), read by `headUnder` without a git process.
52 */
53 export class Carried {
54 private readonly pairs = new Set<string>();
55 /** Heads whose tip is being read now: one reading at a time, however often the gate asks. */
56 private readonly reading = new Set<string>();
57 constructor(private readonly max = 4096) {}
58 note(head: string, tip: string): void {
59 if (this.pairs.size >= this.max) this.pairs.clear();
60 this.pairs.add(`${head} ${tip}`);
61 }
62 has(head: string, tip: string): boolean {
63 return this.pairs.has(`${head} ${tip}`);
64 }
65 /** Start `read` for this key unless one is already under way. */
66 readOnce(key: string, read: () => Promise<unknown>): void {
67 if (this.reading.has(key)) return;
68 this.reading.add(key);
69 void read()
70 .catch(() => undefined)
71 .finally(() => this.reading.delete(key));
72 }
73 }
74
75 /** Each forge's `Carried`, by its database: two forges in one process never share one. */
76 const carriedBy = new WeakMap<Database, Carried>();
77 export function carriedOf(db: Database): Carried {
78 let kept = carriedBy.get(db);
79 if (kept === undefined) carriedBy.set(db, (kept = new Carried()));
80 return kept;
81 }
82
4583 /**
4684 * Whether the branch has a commit beyond the head and main that the forge's own combining did not
4785 * make: main's own commits ride in through the combining merge and are no writer's (#14780).
@@ -137,8 +175,12 @@ export function heldSentence(number: number, files: readonly Kept[]): string {
137175 export async function combine(
138176 dir: string,
139177 input: { readonly number: number; readonly baseOid: string; readonly headOid: string },
178 carried?: Carried,
140179 ): Promise<Combined | undefined> {
141180 const made = await build(dir, input);
181 // Every tip a combining answers carries the head (it is the head, the branch that carries it,
182 // or a merge with it as first parent): the approval gate may run it under the head.
183 if (made !== undefined && made.oid !== input.headOid) carried?.note(input.headOid, made.oid);
142184 // A rebuild that worked ends any earlier failure's sentence, whoever asked for it;
143185 // one that held the pull says why in its place.
144186 if (made !== undefined)
@@ -211,10 +253,12 @@ export async function combinedTip(
211253 dir: string,
212254 number: number,
213255 headOid: string,
256 carried?: Carried,
214257 ): Promise<string | undefined> {
215258 if (!Number.isInteger(number) || number < 1 || !isSafeOid(headOid)) return undefined;
216259 const tip = await refTip(dir, combinedRef(number));
217260 if (tip === undefined || !(await isAncestor(dir, headOid, tip))) return undefined;
261 carried?.note(headOid, tip);
218262 return tip;
219263 }
220264
@@ -235,28 +279,25 @@ export async function readCombined(
235279 }
236280
237281 /**
238 * The head a preview commit runs under, read from git as it stands: the
239 * pull's head when `commit` is its combined tip and still carries it, the
240 * commit itself otherwise. Synchronous, for the runtime's approval gate.
282 * The head a preview commit runs under: the pull's head when `commit` is its combined tip and
283 * carries it, the commit itself otherwise. For the runtime's approval gate, which is synchronous:
284 * it starts no git process (#17883). The tip is read from the ref's own files on every call; that
285 * it carries the head is what `combine` or `combinedTip` saw in this forge. Unseen, the commit
286 * answers for itself, so its own approval is asked, and a reading starts for the next ask.
241287 */
242288 export function headUnder(
243289 dir: string,
244290 pull: { readonly crossRepo: boolean; readonly number: number; readonly headOid: string },
245291 commit: string,
292 carried: Carried,
246293 ): string {
247294 if (!pull.crossRepo || commit === pull.headOid || !isSafeOid(commit) || !isSafeOid(pull.headOid))
248295 return commit;
249 const git = (args: string[]) => {
250 try {
251 return Bun.spawnSync(["git", ...args], { cwd: dir, env: gitEnv(), stdout: "pipe", stderr: "ignore" });
252 } catch {
253 // git cannot start (the directory is gone): the commit stands as given.
254 return { exitCode: 1, stdout: Buffer.alloc(0) };
255 }
256 };
257 const tip = git(["rev-parse", "--verify", "--quiet", combinedRef(pull.number)]);
258 if (tip.exitCode !== 0 || tip.stdout.toString().trim() !== commit) return commit;
259 return git(["merge-base", "--is-ancestor", pull.headOid, commit]).exitCode === 0 ? pull.headOid : commit;
296 if (!Number.isInteger(pull.number) || pull.number < 1) return commit;
297 if (readTipSync(dir, combinedRef(pull.number)) !== commit) return commit;
298 if (carried.has(pull.headOid, commit)) return pull.headOid;
299 carried.readOnce(`${dir} ${pull.number} ${pull.headOid}`, () => combinedTip(dir, pull.number, pull.headOid, carried));
300 return commit;
260301 }
261302
262303 /**
@@ -266,19 +307,21 @@ export function headUnder(
266307 export async function previewCommit(
267308 dir: string,
268309 pull: { readonly crossRepo: boolean; readonly number: number; readonly headBranch: string; readonly headOid: string },
310 carried?: Carried,
269311 ): Promise<string | undefined> {
270 return (await previewHead(dir, pull))?.commit;
312 return (await previewHead(dir, pull, carried))?.commit;
271313 }
272314
273315 /** The head a preview commit stands for: a combined tip answers as the head it carries. */
274316 export async function previewHead(
275317 dir: string,
276318 pull: { readonly crossRepo: boolean; readonly number: number; readonly headBranch: string; readonly headOid: string },
319 carried?: Carried,
277320 ): Promise<{ commit: string; head: string } | undefined> {
278321 const ref = pull.crossRepo ? `refs/pull/${pull.number}/head` : `refs/heads/${pull.headBranch}`;
279322 const head = (await resolveOid(dir, ref)) ?? (pull.headOid || undefined);
280323 if (head === undefined) return undefined;
281 const combined = pull.crossRepo ? await combinedTip(dir, pull.number, head) : undefined;
324 const combined = pull.crossRepo ? await combinedTip(dir, pull.number, head, carried) : undefined;
282325 return { commit: combined ?? head, head };
283326 }
284327
test/combined-gate.test.ts added +108
@@ -0,0 +1,108 @@
1 /**
2 * The runtime's approval gate and a fork's combined tip (#17883): what the forge has read or
3 * written of the combined branch is what lets `mayRun` answer under the pull's head, with no git
4 * process on the serving thread; a tip it never saw carry the head answers for itself.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { newApp } from "../src/actions/apps.ts";
11 import { openPull, submitReview } from "../src/actions/pulls.ts";
12 import { commitToBranch, forkRepo } from "../src/actions/repos.ts";
13 import { createApp, type App } from "../src/app.ts";
14 import { previewEnv } from "../src/apps/data.ts";
15 import { AppsRuntime } from "../src/apps/runtime.ts";
16 import type { AppRecord } from "../src/core/apps.ts";
17 import { getPull, type Pull } from "../src/core/pulls.ts";
18 import { recombine } from "../src/core/recombine.ts";
19 import type { Repo } from "../src/core/repos.ts";
20 import { createUser, type User } from "../src/core/users.ts";
21 import { repoDir } from "../src/git/repos.ts";
22 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { quietLogs } from "./helpers/globals.ts";
24 import { promote } from "./helpers/members.ts";
25
26 quietLogs();
27
28 let dataDir = "";
29 let app: App;
30 let runtime: AppsRuntime;
31 let alice: User;
32 let bob: User;
33 let repo: Repo;
34 let record: AppRecord;
35 let pull: Pull;
36 let bare = "";
37
38 const env = gitClientEnv({
39 GIT_AUTHOR_NAME: "Jay Moran",
40 GIT_AUTHOR_EMAIL: "[email protected]",
41 GIT_COMMITTER_NAME: "Jay Moran",
42 GIT_COMMITTER_EMAIL: "[email protected]",
43 });
44 function git(...args: string[]): string {
45 const p = Bun.spawnSync(["git", ...args], { cwd: bare, env, stdout: "pipe", stderr: "pipe" });
46 if (p.exitCode !== 0) throw new Error(`git ${args.join(" ")}: ${p.stderr.toString()}`);
47 return p.stdout.toString().trim();
48 }
49 function ok<T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T {
50 if (!r.ok) throw new Error(JSON.stringify(r.error));
51 return r.value;
52 }
53 const gate = (commit: string): boolean => runtime.mayRun(record, repo, previewEnv(pull.number), commit);
54
55 beforeAll(async () => {
56 dataDir = await mkdtemp(join(tmpdir(), "forge-combined-gate-"));
57 app = createApp({ dataDir, port: 0 });
58 runtime = new AppsRuntime(app, { domain: "apps.test", scheme: "http", publicPort: 0, forgeUrl: "http://forge.test", concurrency: 1 });
59 alice = ok(await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }));
60 bob = ok(await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }));
61 // Bob is a member who cannot write the repository: his pull waits for a writer's approval.
62 promote(app.db, bob);
63 const made = ok(await newApp(app, alice, { name: "gate", visibility: "public" }));
64 repo = made.repo;
65 record = made.app;
66 ok(await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "a.txt", content: "a\n" }] }));
67 const fork = ok(await forkRepo(app, bob, repo, "gate-bob"));
68 ok(await commitToBranch(app, bob, fork, { branch: "work", base: "main", message: "bob's b", files: [{ path: "b.txt", content: "b\n" }] }));
69 const opened = ok(await openPull(app, bob, repo, { title: "Bob's b", baseBranch: "main", headBranch: "work", headRepo: fork }));
70 bare = repoDir(app.reposRoot, repo.ownerName, repo.name);
71 pull = getPull(app.db, repo.id, opened.number)!;
72 // A writer approves bob's head: his code may run at it, and at nothing else.
73 ok(await submitReview(app, alice, repo, pull, { state: "approved", body: "" }));
74 pull = getPull(app.db, repo.id, opened.number)!;
75 });
76
77 afterAll(async () => {
78 await runtime.stop();
79 app.close();
80 await rm(dataDir, { recursive: true, force: true });
81 });
82
83 test("a combined tip the runtime read through pullHead runs under the approved head", async () => {
84 expect(gate(pull.headOid)).toBe(true);
85 // Written past the forge (a hand on the branch): nothing has read that it carries the head yet.
86 const tip = git("commit-tree", `${pull.headOid}^{tree}`, "-p", pull.headOid, "-m", "by hand");
87 git("update-ref", `refs/heads/combined/${pull.number}`, tip);
88 expect(gate(tip)).toBe(false);
89 // The runtime reads the pull's head, as every door does before it deploys, prepares or boots one.
90 expect(await runtime.pullHead(repo, pull)).toBe(tip);
91 expect(gate(tip)).toBe(true);
92 });
93
94 test("a tip that does not carry the head never runs under it", async () => {
95 const stray = git("commit-tree", `${pull.headOid}^{tree}`, "-m", "not the head's");
96 git("update-ref", `refs/heads/combined/${pull.number}`, stray);
97 expect(await runtime.pullHead(repo, pull)).toBe(pull.headOid);
98 expect(gate(stray)).toBe(false);
99 });
100
101 test("a tip the forge's own combining wrote runs under the head with no read first", async () => {
102 git("update-ref", "-d", `refs/heads/combined/${pull.number}`);
103 ok(await commitToBranch(app, alice, repo, { message: "main moves", files: [{ path: "c.txt", content: "c\n" }] }));
104 await recombine({ db: app.db, reposRoot: app.reposRoot, log: app.log }, repo.id);
105 const tip = git("rev-parse", `refs/heads/combined/${pull.number}`);
106 expect(tip).not.toBe(pull.headOid);
107 expect(gate(tip)).toBe(true);
108 });
test/combined-git.test.ts +42 −6
@@ -3,7 +3,7 @@ import { afterAll, beforeAll, 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";
6 import { combine, headUnder, parseCombined, readCombined, readFailure } from "../src/git/combined.ts";
6 import { Carried, combine, combinedTip, headUnder, parseCombined, readCombined, readFailure } from "../src/git/combined.ts";
77 import { runGit } from "../src/git/env.ts";
88 import { gitClientEnv } from "./helpers/git-client.ts";
99
@@ -105,19 +105,55 @@ test("a writer's commit on the combined branch survives main moving on", async (
105105 expect(git("show", `${again!.oid}:two.txt`)).toBe("two");
106106 });
107107
108 test("a combined preview runs under the head it carries, and nothing else does", () => {
108 test("a combined preview runs under the head it carries, and nothing else does", async () => {
109109 const head = git("rev-parse", "adds");
110110 const tip = git("rev-parse", "combined/9");
111111 const pull = { crossRepo: true, number: 9, headOid: git("rev-parse", "adds") };
112 expect(headUnder(gitDir(), pull, tip)).toBe(head);
112 const carried = new Carried();
113 expect(await combinedTip(gitDir(), 9, head, carried)).toBe(tip);
114 expect(headUnder(gitDir(), pull, tip, carried)).toBe(head);
113115 // Not the combined tip: it answers for itself, so its own approval is asked.
114116 const main = git("rev-parse", "main");
115 expect(headUnder(gitDir(), pull, main)).toBe(main);
117 expect(headUnder(gitDir(), pull, main, carried)).toBe(main);
116118 // A pull whose head the branch no longer carries: the tip answers for itself.
117119 const elsewhere = git("commit-tree", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", "-m", "elsewhere");
118 expect(headUnder(gitDir(), { ...pull, headOid: elsewhere }, tip)).toBe(tip);
120 expect(headUnder(gitDir(), { ...pull, headOid: elsewhere }, tip, carried)).toBe(tip);
119121 // A branch pull is never combined.
120 expect(headUnder(gitDir(), { ...pull, crossRepo: false }, tip)).toBe(tip);
122 expect(headUnder(gitDir(), { ...pull, crossRepo: false }, tip, carried)).toBe(tip);
123 });
124
125 test("the approval gate reads the combined tip without a synchronous git process (#17883)", async () => {
126 const head = git("rev-parse", "adds");
127 const pull = { crossRepo: true, number: 10, headOid: head };
128 const carried = new Carried();
129 // A combined branch nobody here has read yet: written by hand, it carries the head.
130 const tip = git("commit-tree", `${head}^{tree}`, "-p", head, "-m", "by hand");
131 git("update-ref", "refs/heads/combined/10", tip);
132 const real = Bun.spawnSync;
133 let spawns = 0;
134 const count = ((...a: Parameters<typeof Bun.spawnSync>) => {
135 spawns++;
136 return real(...a);
137 }) as typeof Bun.spawnSync;
138 Bun.spawnSync = count;
139 let unseen = "", seen = "";
140 try {
141 // Unseen, the tip answers for itself: its own approval is asked, never a guess.
142 unseen = headUnder(gitDir(), pull, tip, carried);
143 Bun.spawnSync = real;
144 expect(await combinedTip(gitDir(), 10, head, carried)).toBe(tip);
145 Bun.spawnSync = count;
146 seen = headUnder(gitDir(), pull, tip, carried);
147 } finally {
148 Bun.spawnSync = real;
149 }
150 expect([unseen, seen, spawns]).toEqual([tip, head, 0]);
151 // Force-pushed elsewhere: the tip that was seen is no longer the branch, so it answers for
152 // itself.
153 const moved = git("commit-tree", `${head}^{tree}`, "-p", head, "-m", "again");
154 git("update-ref", "refs/heads/combined/10", moved);
155 expect(headUnder(gitDir(), pull, tip, carried)).toBe(tip);
156 expect(headUnder(gitDir(), pull, moved, carried)).toBe(moved);
121157 });
122158
123159 test("trailers that are not ours are not read as facts", () => {
test/git-spawn-failure.test.ts +2 −2
@@ -8,7 +8,7 @@ import { createApp, type App } from "../src/app.ts";
88 import { serve, type Servers } from "../src/http/server.ts";
99 import { runGit, runGitCapture, runGitRaw } from "../src/git/env.ts";
1010 import { diff, runLocal } from "../src/git/local.ts";
11 import { headUnder } from "../src/git/combined.ts";
11 import { Carried, headUnder } from "../src/git/combined.ts";
1212 import { blobHead, blobStream, readerFor, closeReader } from "../src/git/read.ts";
1313 import { mediaGate } from "../src/git/env.ts";
1414 import { repoDir } from "../src/git/repos.ts";
@@ -62,7 +62,7 @@ test("a work-screen diff of a gone directory is an Err with the sentence", async
6262
6363 test("headUnder of a gone directory leaves the commit as given", () => {
6464 const pull = { crossRepo: true, number: 1, headOid: OTHER };
65 expect(headUnder(gone, pull, OID)).toBe(OID);
65 expect(headUnder(gone, pull, OID, new Carried())).toBe(OID);
6666 });
6767
6868 let dataDir = "";
test/spawn-pipes.test.ts −1
@@ -35,7 +35,6 @@ const PIPING: Record<string, { sites: string[]; reason: string }> = {
3535 "src/crew/workdir.ts": { sites: ["stderr"], reason: "stderr read to its end alongside the exit; stdout ignored" },
3636 "src/data/query.ts": { sites: ["stdout"], reason: "stdout read to its end for the one JSON answer, under a timer that kills the child; stderr ignored" },
3737 "src/git/env.ts": { sites: ["stdout+stderr", "stdout+stderr"], reason: "stdout and stderr both read to the end, finally clears the timer" },
38 "src/git/combined.ts": { sites: ["stdout"], reason: "spawnSync buffers rev-parse stdout; stderr ignored" },
3938 "src/git/local.ts": { sites: ["stdout+stderr", "stdout+stderr"], reason: "stdout and stderr both read to the end" },
4039 "src/git/own_refs.ts": { sites: ["stdout", "stdout", "stdout", "stdout", "stdout"], reason: "each git stdout is read to the end (four as text alongside exited, cat-file and show-index under a kill timer, the rev-list walk chunk by chunk); stderr ignored; a timer kills a walk that hangs" },
4140 "src/git/read.ts": { sites: ["stdout", "stdout", "stdout", "stdout", "stdout"], reason: "cat-file stdout is read by the long-lived reader, by blobStream until its window ends or the reader hangs up, and by blobHead until its bytes are in (then killed), by blobRange until its range is in (then killed), and by blobTail until the blob ends, keeping a ring of its last bytes; stderr ignored" },
test/spawn-sites.test.ts −2
@@ -63,8 +63,6 @@ const SITES: Record<string, string> = {
6363 "runBounded is called only with the fixed `bun install --frozen-lockfile --ignore-scripts` argv",
6464 "src/data/query.ts":
6565 "bun on the forge's own query_child.ts, a fixed argv with an empty environment; the SQL a person typed travels on stdin, never argv",
66 "src/git/combined.ts":
67 "git plumbing with oids checked by isSafeOid before they reach argv",
6866 "src/git/env.ts":
6967 "the one git runner: argv to the git binary, no shell; callers pass refs and paths validated at their boundary and after `--` where git accepts it",
7068 "src/git/local.ts":

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs