Public: anyone can read this; the crew can change it.
Full suite red: test/merge-queue-suspect.test.ts #12812
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12799-full-suite-red-test-merge-queue-suspect → main 4 commits fork
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", () => { | ||
| 32 | 32 | }); |
| 33 | 33 | |
| 34 | 34 | /** 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); | |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | const verdictOf = (candidate: Candidate): LandVerdict => |
| @@ -64,9 +65,10 @@ describe("the merge queue judges a suspect alone", () => { | ||
| 64 | 65 | } |
| 65 | 66 | |
| 66 | 67 | 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")); | |
| 68 | 70 | 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`))); | |
| 70 | 72 | // The gate is held open and let go a wave at a time: "at once" is counted, never timed. |
| 71 | 73 | let pending: { candidate: Candidate; go: (v: LandVerdict) => void }[] = []; |
| 72 | 74 | const waves: number[][][] = []; |
| @@ -80,7 +82,7 @@ describe("the merge queue judges a suspect alone", () => { | ||
| 80 | 82 | waves.push(going.map((p) => p.candidate.steps.map((s) => s.entry.pull.number))); |
| 81 | 83 | for (const p of going) p.go(verdictOf(p.candidate)); |
| 82 | 84 | }; |
| 83 | const landed = enqueue("thirty", [bad, ...good], gate, { depth: 4, room: () => 8 }); | |
| 85 | const landed = enqueue(line, [bad, ...good], gate, { depth: 4, room: () => 8 }); | |
| 84 | 86 | // Gate-time one: four candidates, the first red on its head. |
| 85 | 87 | await letGo(4); |
| 86 | 88 | // 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", () => { | ||
| 95 | 97 | }); |
| 96 | 98 | |
| 97 | 99 | 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()}`; | |
| 98 | 102 | 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"))]; | |
| 101 | 105 | const gates: number[][] = []; |
| 102 | 106 | // The search is cut off twice (the forge stopping): the batch is red, and nothing is decided. |
| 103 | 107 | let cut = true; |
| @@ -106,12 +110,12 @@ describe("the merge queue judges a suspect alone", () => { | ||
| 106 | 110 | if (cut && candidate.steps.length < 3) return { lands: false, interrupted: true }; |
| 107 | 111 | return verdictOf(candidate); |
| 108 | 112 | }; |
| 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]); | |
| 111 | 115 | expect(gates.filter((g) => g.length === 3)).toHaveLength(2); |
| 112 | 116 | cut = false; |
| 113 | 117 | 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]); | |
| 115 | 119 | const after = gates.slice(before); |
| 116 | 120 | // Each was in two red batches: each is judged alone, and the bad one heads no batch. |
| 117 | 121 | expect(after.slice(0, 3)).toEqual([[1], [2], [3]]); |
new above
offline