Public: anyone can read this; the crew can change it.
Full suite red: test/merge-queue-search.test.ts #12818
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12803-full-suite-red-test-merge-queue-search-t → main 6 commits fork
1 file
changed +40
−23
test/merge-queue-search.test.ts +40 −23
| @@ -1,43 +1,53 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * A red candidate is searched by prefixes of its own chain, each stacked on |
| 3 | 3 | * the one before (#5994), so every green piece lands in order: a disjoint |
| 4 | * segment gated on the base alone was void once another landed (#6353). The gate here is held open and | |
| 5 | * let go a wave at a time, so "at once" is counted, never timed; it reads | |
| 6 | * the candidate's tree: red when it holds `bad.txt`. | |
| 4 | * segment gated on the base alone was void once another landed (#6353). The | |
| 5 | * gate here is held open and let go a wave at a time, so "at once" is counted, | |
| 6 | * never timed; it reads the candidate's tree: red when it holds `bad.txt`. | |
| 7 | 7 | */ |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 9 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | import { join } from "node:path"; | |
| 11 | import { basename, join } from "node:path"; | |
| 12 | 12 | import { type Candidate, enqueue, type Expect, type Queued } from "../src/checks/queue.ts"; |
| 13 | 13 | import type { LandVerdict } from "../src/checks/tiers.ts"; |
| 14 | 14 | import type { Pull } from "../src/core/pulls.ts"; |
| 15 | 15 | |
| 16 | 16 | describe("the merge queue searches a red candidate by stacked prefixes", () => { |
| 17 | 17 | let dir: string; |
| 18 | /** Unique to each run (a counter would repeat when the file is reloaded): | |
| 19 | * the queue keeps state per repo name. */ | |
| 20 | let run = ""; | |
| 18 | 21 | const told: number[] = []; |
| 19 | 22 | |
| 20 | const git = (...args: string[]) => | |
| 21 | Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim(); | |
| 23 | const git = (...args: (string | { input: string })[]) => { | |
| 24 | const last = args[args.length - 1]; | |
| 25 | const input = typeof last === "object" ? last.input : undefined; | |
| 26 | const words = args.filter((a): a is string => typeof a === "string"); | |
| 27 | return Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...words], { stdin: input === undefined ? undefined : Buffer.from(input) }) | |
| 28 | .stdout.toString() | |
| 29 | .trim(); | |
| 30 | }; | |
| 22 | 31 | |
| 23 | beforeAll(async () => { | |
| 32 | beforeEach(async () => { | |
| 24 | 33 | dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-search-")); |
| 34 | run = basename(dir); | |
| 25 | 35 | Bun.spawnSync(["git", "init", "-q", "-b", "main", dir]); |
| 26 | 36 | git("commit", "-q", "--allow-empty", "-m", "start"); |
| 27 | 37 | }); |
| 28 | 38 | |
| 29 | afterAll(async () => { | |
| 39 | afterEach(async () => { | |
| 30 | 40 | await rm(dir, { recursive: true, force: true }); |
| 31 | 41 | }); |
| 32 | 42 | |
| 43 | /** A commit on main adding one file, by plumbing: no checkout, a few git calls. */ | |
| 33 | 44 | async function headAdding(branch: string, file: string): Promise<string> { |
| 34 | git("checkout", "-q", "-B", branch, "main"); | |
| 35 | git("reset", "-q", "--hard", "main"); | |
| 36 | await Bun.write(join(dir, file), `${file}\n`); | |
| 37 | git("add", file); | |
| 38 | git("commit", "-q", "-m", file); | |
| 39 | git("checkout", "-q", "--detach"); | |
| 40 | return git("rev-parse", branch); | |
| 45 | const blob = git("hash-object", "-w", "--stdin", { input: `${file} ${run}\n` }); | |
| 46 | const rows = git("ls-tree", "main").split("\n").filter(Boolean); | |
| 47 | const tree = git("mktree", { input: [...rows, `100644 blob ${blob}\t${file}`].join("\n") + "\n" }); | |
| 48 | const oid = git("commit-tree", tree, "-p", "main", "-m", file); | |
| 49 | git("update-ref", `refs/heads/${branch}`, oid); | |
| 50 | return oid; | |
| 41 | 51 | } |
| 42 | 52 | |
| 43 | 53 | const verdictOf = (candidate: Candidate): LandVerdict => |
| @@ -47,7 +57,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => { | ||
| 47 | 57 | |
| 48 | 58 | function entry(number: number, headOid: string): Queued { |
| 49 | 59 | return { |
| 50 | pull: { id: `search-${number}`, number, baseBranch: "main", headOid } as Pull, | |
| 60 | pull: { id: `search-${run}-${number}`, number, baseBranch: "main", headOid } as Pull, | |
| 51 | 61 | dir, |
| 52 | 62 | land: async (expect: Expect) => { |
| 53 | 63 | if (git("rev-parse", "refs/heads/main") !== expect.baseOid) return undefined; |
| @@ -65,9 +75,16 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => { | ||
| 65 | 75 | let pending: { candidate: Candidate; go: (v: LandVerdict) => void }[] = []; |
| 66 | 76 | const seen: number[][][] = []; |
| 67 | 77 | const greens: number[][] = []; |
| 68 | const gate = (candidate: Candidate) => new Promise<LandVerdict>((go) => pending.push({ candidate, go })); | |
| 78 | let wake: (() => void) | undefined; | |
| 79 | const gate = (candidate: Candidate) => | |
| 80 | new Promise<LandVerdict>((go) => { | |
| 81 | pending.push({ candidate, go }); | |
| 82 | wake?.(); | |
| 83 | }); | |
| 69 | 84 | const letGo = async (n: number) => { |
| 70 | for (let i = 0; i < 2000 && pending.length < n; i++) await Bun.sleep(5); | |
| 85 | // Woken by each gate that arrives; the test's own timeout bounds a wave that never comes. | |
| 86 | while (pending.length < n) await new Promise<void>((r) => (wake = r)); | |
| 87 | wake = undefined; | |
| 71 | 88 | expect(pending).toHaveLength(n); |
| 72 | 89 | const going = pending; |
| 73 | 90 | pending = []; |
| @@ -86,7 +103,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => { | ||
| 86 | 103 | const pulls: Queued[] = []; |
| 87 | 104 | for (let i = 1; i <= 7; i++) pulls.push(entry(i, await headAdding(`s${i}`, i === 5 ? "bad.txt" : `f${i}.txt`))); |
| 88 | 105 | const { gate, letGo, seen } = waves(); |
| 89 | const landed = enqueue("search", pulls, gate, { depth: 1, room: () => 3 }); | |
| 106 | const landed = enqueue(`search-${run}`, pulls, gate, { depth: 1, room: () => 3 }); | |
| 90 | 107 | await letGo(1); // the whole candidate: red |
| 91 | 108 | await letGo(2); // its head alone (#4999), beside the six without it |
| 92 | 109 | await letGo(4); // the six: four prefixes of their own chain, each on the one before |
| @@ -103,7 +120,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => { | ||
| 103 | 120 | const pulls: Queued[] = []; |
| 104 | 121 | for (let i = 21; i <= 28; i++) pulls.push(entry(i, await headAdding(`u${i}`, i === 24 ? "bad.txt" : `f${i}.txt`))); |
| 105 | 122 | const { gate, letGo, seen, greens } = waves(); |
| 106 | const landed = enqueue("search-eight", pulls, gate, { depth: 1, room: () => 7 }); | |
| 123 | const landed = enqueue(`search-eight-${run}`, pulls, gate, { depth: 1, room: () => 7 }); | |
| 107 | 124 | await letGo(1); // the eight: red |
| 108 | 125 | await letGo(2); // its head alone (#4999), beside the seven without it: red |
| 109 | 126 | await letGo(6); // round one: the seven, six prefixes at once; the culprit is named |
| @@ -126,7 +143,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => { | ||
| 126 | 143 | gates.push(candidate.steps.map((s) => s.entry.pull.number)); |
| 127 | 144 | return verdictOf(candidate); |
| 128 | 145 | }; |
| 129 | const answers = await enqueue("search-solo", pulls, gate, { depth: 1, room: () => 0 }); | |
| 146 | const answers = await enqueue(`search-solo-${run}`, pulls, gate, { depth: 1, room: () => 0 }); | |
| 130 | 147 | // The whole, then the front half; the back half has the whole's tree on it: known red. |
| 131 | 148 | expect(gates).toEqual([[11, 12, 13, 14], [11, 12], [13]]); |
| 132 | 149 | expect(told).toEqual([14]); |
| @@ -148,7 +165,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => { | ||
| 148 | 165 | }; |
| 149 | 166 | let calls = 0; |
| 150 | 167 | const room = () => (calls++ === 0 ? 0 : 1); |
| 151 | const answers = await enqueue("search-flake", pulls, gate, { | |
| 168 | const answers = await enqueue(`search-flake-${run}`, pulls, gate, { | |
| 152 | 169 | depth: 1, |
| 153 | 170 | room, |
| 154 | 171 | onFlake: (_repo, reds) => flaked.push(...reds.flatMap((r) => ("tests" in r ? (r.tests?.failing.map((t) => t.name) ?? []) : []))), |
new above
offline