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

Full suite red: test/merge-queue-search.test.ts #12818

Merged opened this in answer to

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

Merged

scout/forge:scout/12803-full-suite-red-test-merge-queue-search-t → main 6 commits fork

  • Merged. scout/12803-full-suite-red-test-merge-queue-search-t was merged into main as 5f92812.

Review

Sign in to review this change.
1 file changed +40 −23
test/merge-queue-search.test.ts +40 −23
@@ -1,43 +1,53 @@
11 /**
22 * A red candidate is searched by prefixes of its own chain, each stacked on
33 * 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`.
77 */
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { afterEach, beforeEach, describe, expect, test } from "bun:test";
99 import { mkdtemp, rm } from "node:fs/promises";
1010 import { tmpdir } from "node:os";
11 import { join } from "node:path";
11 import { basename, join } from "node:path";
1212 import { type Candidate, enqueue, type Expect, type Queued } from "../src/checks/queue.ts";
1313 import type { LandVerdict } from "../src/checks/tiers.ts";
1414 import type { Pull } from "../src/core/pulls.ts";
1515
1616 describe("the merge queue searches a red candidate by stacked prefixes", () => {
1717 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 = "";
1821 const told: number[] = [];
1922
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 };
2231
23 beforeAll(async () => {
32 beforeEach(async () => {
2433 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-search-"));
34 run = basename(dir);
2535 Bun.spawnSync(["git", "init", "-q", "-b", "main", dir]);
2636 git("commit", "-q", "--allow-empty", "-m", "start");
2737 });
2838
29 afterAll(async () => {
39 afterEach(async () => {
3040 await rm(dir, { recursive: true, force: true });
3141 });
3242
43 /** A commit on main adding one file, by plumbing: no checkout, a few git calls. */
3344 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;
4151 }
4252
4353 const verdictOf = (candidate: Candidate): LandVerdict =>
@@ -47,7 +57,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => {
4757
4858 function entry(number: number, headOid: string): Queued {
4959 return {
50 pull: { id: `search-${number}`, number, baseBranch: "main", headOid } as Pull,
60 pull: { id: `search-${run}-${number}`, number, baseBranch: "main", headOid } as Pull,
5161 dir,
5262 land: async (expect: Expect) => {
5363 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", () => {
6575 let pending: { candidate: Candidate; go: (v: LandVerdict) => void }[] = [];
6676 const seen: number[][][] = [];
6777 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 });
6984 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;
7188 expect(pending).toHaveLength(n);
7289 const going = pending;
7390 pending = [];
@@ -86,7 +103,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => {
86103 const pulls: Queued[] = [];
87104 for (let i = 1; i <= 7; i++) pulls.push(entry(i, await headAdding(`s${i}`, i === 5 ? "bad.txt" : `f${i}.txt`)));
88105 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 });
90107 await letGo(1); // the whole candidate: red
91108 await letGo(2); // its head alone (#4999), beside the six without it
92109 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", () => {
103120 const pulls: Queued[] = [];
104121 for (let i = 21; i <= 28; i++) pulls.push(entry(i, await headAdding(`u${i}`, i === 24 ? "bad.txt" : `f${i}.txt`)));
105122 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 });
107124 await letGo(1); // the eight: red
108125 await letGo(2); // its head alone (#4999), beside the seven without it: red
109126 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", () => {
126143 gates.push(candidate.steps.map((s) => s.entry.pull.number));
127144 return verdictOf(candidate);
128145 };
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 });
130147 // The whole, then the front half; the back half has the whole's tree on it: known red.
131148 expect(gates).toEqual([[11, 12, 13, 14], [11, 12], [13]]);
132149 expect(told).toEqual([14]);
@@ -148,7 +165,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => {
148165 };
149166 let calls = 0;
150167 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, {
152169 depth: 1,
153170 room,
154171 onFlake: (_repo, reds) => flaked.push(...reds.flatMap((r) => ("tests" in r ? (r.tests?.failing.map((t) => t.name) ?? []) : []))),

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs