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

Full suite red: test/merge-queue-suspect.test.ts #12812

Merged opened this in answer to

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

Merged

scout/forge:scout/12799-full-suite-red-test-merge-queue-suspect → main 4 commits fork

  • Merged. scout/12799-full-suite-red-test-merge-queue-suspect was merged into main as 7a91a55.

Review

Sign in to review this change.
1 file changed +20 −16
test/merge-queue-suspect.test.ts +20 −16
@@ -32,14 +32,15 @@ describe("the merge queue judges a suspect alone", () => {
3232 });
3333
3434 /** A pull's head: one file added on main as it is now. */
35 async function headAdding(branch: string, file: string): Promise<string> {
36 git("checkout", "-q", "-B", branch, "main");
37 git("reset", "-q", "--hard", "main");
38 await Bun.write(join(dir, file), `${file}\n`);
39 git("add", file);
40 git("commit", "-q", "-m", file);
41 git("checkout", "-q", "--detach");
42 return git("rev-parse", branch);
35 function headAdding(file: string): string {
36 // Plumbing only (three spawns, no checkout): main's tree plus one blob.
37 const run = (input: string, ...args: string[]) =>
38 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { stdin: Buffer.from(input) })
39 .stdout.toString().trim();
40 const blob = run(`${file}\n`, "hash-object", "-w", "--stdin");
41 // The replace drops the leading newline when main's tree is empty.
42 const tree = run(`${git("ls-tree", "refs/heads/main")}\n100644 blob ${blob}\t${file}\n`.replace(/^\n/, ""), "mktree");
43 return run("", "commit-tree", tree, "-p", "refs/heads/main", "-m", file);
4344 }
4445
4546 const verdictOf = (candidate: Candidate): LandVerdict =>
@@ -64,9 +65,10 @@ describe("the merge queue judges a suspect alone", () => {
6465 }
6566
6667 test("one bad pull at the head, thirty good behind: the thirty land in two gate-times, the bad one is handed back after its solo red", async () => {
67 const bad = entry("thirty", 1, await headAdding("bad", "bad.txt"));
68 const line = `thirty-${crypto.randomUUID()}`;
69 const bad = entry(line, 1, headAdding("bad.txt"));
6870 const good: Queued[] = [];
69 for (let i = 0; i < 30; i++) good.push(entry("thirty", 2 + i, await headAdding(`g${i}`, `g${i}.txt`)));
71 for (let i = 0; i < 30; i++) good.push(entry(line, 2 + i, headAdding(`g${i}.txt`)));
7072 // The gate is held open and let go a wave at a time: "at once" is counted, never timed.
7173 let pending: { candidate: Candidate; go: (v: LandVerdict) => void }[] = [];
7274 const waves: number[][][] = [];
@@ -80,7 +82,7 @@ describe("the merge queue judges a suspect alone", () => {
8082 waves.push(going.map((p) => p.candidate.steps.map((s) => s.entry.pull.number)));
8183 for (const p of going) p.go(verdictOf(p.candidate));
8284 };
83 const landed = enqueue("thirty", [bad, ...good], gate, { depth: 4, room: () => 8 });
85 const landed = enqueue(line, [bad, ...good], gate, { depth: 4, room: () => 8 });
8486 // Gate-time one: four candidates, the first red on its head.
8587 await letGo(4);
8688 // Gate-time two: the head alone, beside the thirty in four candidates without it.
@@ -95,9 +97,11 @@ describe("the merge queue judges a suspect alone", () => {
9597 });
9698
9799 test("a pull in two red batches never heads a third: it is gated alone, and handed back on its own red", async () => {
100 // The queue remembers suspects by pull id: each run of a repeated file gets its own line.
101 const line = `twice-${crypto.randomUUID()}`;
98102 told.length = 0;
99 const bad = entry("twice", 1, await headAdding("bad2", "bad.txt"));
100 const [g1, g2] = [entry("twice", 2, await headAdding("h1", "h1.txt")), entry("twice", 3, await headAdding("h2", "h2.txt"))];
103 const bad = entry(line, 1, headAdding("bad.txt"));
104 const [g1, g2] = [entry(line, 2, headAdding("h1.txt")), entry(line, 3, headAdding("h2.txt"))];
101105 const gates: number[][] = [];
102106 // The search is cut off twice (the forge stopping): the batch is red, and nothing is decided.
103107 let cut = true;
@@ -106,12 +110,12 @@ describe("the merge queue judges a suspect alone", () => {
106110 if (cut && candidate.steps.length < 3) return { lands: false, interrupted: true };
107111 return verdictOf(candidate);
108112 };
109 expect(await enqueue("twice", [bad, g1, g2], gate)).toEqual([false, false, false]);
110 expect(await enqueue("twice", [bad, g1, g2], gate)).toEqual([false, false, false]);
113 expect(await enqueue(line, [bad, g1, g2], gate)).toEqual([false, false, false]);
114 expect(await enqueue(line, [bad, g1, g2], gate)).toEqual([false, false, false]);
111115 expect(gates.filter((g) => g.length === 3)).toHaveLength(2);
112116 cut = false;
113117 const before = gates.length;
114 expect(await enqueue("twice", [bad, g1, g2], gate)).toEqual([false, true, true]);
118 expect(await enqueue(line, [bad, g1, g2], gate)).toEqual([false, true, true]);
115119 const after = gates.slice(before);
116120 // Each was in two red batches: each is judged alone, and the bad one heads no batch.
117121 expect(after.slice(0, 3)).toEqual([[1], [2], [3]]);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs