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

Main's push check runs on a connected runner and keeps only its verdict here #17687

opened this

Merged 13h 9m ago, live in production

fix/main-check-on-runner → main 0 commits 1 thread · 1 unresolved

  • Merged. fix/main-check-on-runner was merged into main as 9e2eabc.

Review

Sign in to review this change.
6 files changed +190 −42
src/checks/run_tier.ts +6 −4
@@ -445,15 +445,17 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr
445445 write,
446446 signal,
447447 }, options.deepsec);
448 // Only a green check of the default branch is kept for the next.
448 // Only a green check of the default branch, run here whole, is kept for the next: one a runner
449 // ran (its red re-run here alone) keeps only its verdict (`runnerTakes`).
450 const keep = x.keep === true && runnerRed === undefined;

Correct for the red-alone path. Add a one-line comment that a runner's green never reaches here (it returns above), so a reader doesn't think a runner's green is being kept.

449451 if (
450 x.keep === true &&
452 keep &&
451453 keepCache(app.config.dataDir, repo.id, run.commitOid, dir)
452454 )
453455 write(`cache kept for ${run.commitOid.slice(0, 7)}`);
454456 // Only a green check of the default branch becomes the snapshot (#16380).
455 if (x.keep === true && job === undefined) await keepAfterGreen(app, repo.id, dir, manifest.install, run.commitOid, write);
456 if (x.tier === "full" || x.keepImpact === true) {
457 if (keep && job === undefined) await keepAfterGreen(app, repo.id, dir, manifest.install, run.commitOid, write);
458 if (runnerRed === undefined && (x.tier === "full" || x.keepImpact === true)) {
457459 try {
458460 const kept = keepImpact(app.config.dataDir, repo.id, dir);
459461 if (kept !== undefined) write(kept);
src/checks/runner_step.ts +8 −19
@@ -46,28 +46,17 @@ export const MAX_CLAIMS = 2;
4646 const LOOK_MS = 1_000;
4747
4848 /**
49 * Whether a runner may take this check. Only one that hands nothing back but its log and its
50 * verdict: a pull's check. The default branch's own run and a verification keep what they
51 * measured (the cache, the impact map, kept results) from the checkout, and a runner has no way
52 * to send those yet, so they stay on the forge's machine.
49 * Whether a runner may take this check: a pull's, and main's own push check too. Main's keeps
50 * only its verdict when a runner ran it (`redMain` reads it): no cache and no snapshot here, and
51 * no impact map, which its verification hands back (`runner_hands.ts`). Its cold start here is
52 * paid only when no runner is connected. A bisection step (`only`) stays here.
5353 */
54 export function runnerTakes(x: {
55 readonly tier: CheckTier;
56 readonly keep?: boolean | undefined;
57 readonly keepImpact?: boolean | undefined;
58 readonly isMain?: boolean | undefined;
59 readonly only?: readonly string[] | undefined;
60 }): boolean {
54 export function runnerTakes(x: { readonly tier: CheckTier; readonly keepImpact?: boolean | undefined; readonly only?: readonly string[] | undefined }): boolean {
55 if (x.only !== undefined) return false;
6156 // Main's whole verification goes to a runner (#17099 adoption survives a release; 14 of 35 were
6257 // cut here on 2026-12-01, keeping nothing): what it measures comes back (`runner_hands.ts`).
63 if (x.tier === "verify") return x.keepImpact === true && x.only === undefined;
64 return (
65 (x.tier === "fast" || x.tier === "run") &&
66 x.keep !== true &&
67 x.keepImpact !== true &&
68 x.isMain !== true &&
69 x.only === undefined
70 );
58 if (x.tier === "verify") return x.keepImpact === true;
59 return x.tier === "fast" || x.tier === "run";
7160 }
7261
7362 export type RunnerStepEnd =
test/checks-runner-placement.test.ts +6 −13
@@ -126,22 +126,15 @@ describe("the setting", () => {
126126 expect(placementWords({ placement: "process", node: "" })).toBe("");
127127 });
128128
129 test("only a check that hands back nothing but its verdict goes to a runner", () => {
130 expect(
131 runnerTakes({
132 tier: "fast",
133 keep: false,
134 keepImpact: false,
135 isMain: false,
136 }),
137 ).toBe(true);
138 expect(
139 runnerTakes({ tier: "run", keep: true, keepImpact: true, isMain: true }),
140 ).toBe(false);
129 test("a pull's check and main's push check go to a runner; a bisection step and the full tier stay here", () => {
130 expect(runnerTakes({ tier: "fast", keepImpact: false })).toBe(true);
131 // Main's push check keeps only its verdict when a runner ran it (`run_tier.ts`).
132 expect(runnerTakes({ tier: "run", keepImpact: true })).toBe(true);
141133 // Main's whole verification goes to a runner and hands back what it measured (`runner_hands.ts`).
142 expect(runnerTakes({ tier: "verify", keep: false, keepImpact: true })).toBe(true);
134 expect(runnerTakes({ tier: "verify", keepImpact: true })).toBe(true);
143135 expect(runnerTakes({ tier: "full" })).toBe(false);
144136 expect(runnerTakes({ tier: "fast", only: ["a.test.ts"] })).toBe(false);
137 expect(runnerTakes({ tier: "run", only: ["a.test.ts"] })).toBe(false);
145138 });
146139
147140 test("a result is held to the steps the job asked for: an empty or partial one is no answer", () => {
test/main-check-on-runner.test.ts added +159
@@ -0,0 +1,159 @@
1 /**
2 * Main's push check goes to a connected runner too (`runnerTakes`), and keeps only its verdict:
3 * no checkout, cache or snapshot on the forge, and no impact map, which main's verification hands
4 * back. On 2026-12-02 main's check ran inside the forge's container while six runners stood idle.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { existsSync } from "node:fs";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
12 import { createApp, type App } from "../src/app.ts";
13 import { redMain } from "../src/checks/red_main.ts";
14 import type { runRunnerStep } from "../src/checks/runner_step.ts";
15 import { startChecks } from "../src/checks/service.ts";
16 import { listRuns, type Run } from "../src/core/runs.ts";
17 import { createUser, type User } from "../src/core/users.ts";
18 import { err, ok } from "../src/kernel/result.ts";
19 import { readRunLog } from "../src/runs/log.ts";
20 import { quietLogs } from "./helpers/globals.ts";
21 import { waitFor } from "./helpers/poll.ts";
22
23 quietLogs();
24
25 const priorCells = process.env["FORGE_CELLS"]; // env-restored: afterAll
26 let dir = "";
27 let app: App;
28 let alice: User;
29 beforeAll(async () => {
30 process.env["FORGE_CELLS"] = "off"; // env-restored: afterAll
31 dir = await mkdtemp(join(tmpdir(), "main-check-on-runner-"));
32 app = createApp({ dataDir: dir, port: 0, host: "forge.test" });
33 const u = await createUser(app.db, {
34 origin: "seed",
35 trusted: true,
36 username: "alice",
37 email: "[email protected]",
38 password: "a-good-passphrase",
39 adminIfFirst: true,
40 });
41 if (!u.ok) throw new Error(u.error);
42 alice = u.value;
43 });
44 afterAll(async () => {
45 if (priorCells === undefined) delete process.env["FORGE_CELLS"];
46 else process.env["FORGE_CELLS"] = priorCells;
47 app.close();
48 await rm(dir, { recursive: true, force: true });
49 });
50
51 const spec = (body: string) =>
52 `import { describe, test } from "bun:test";\nimport { mkdirSync, writeFileSync } from "node:fs";\ndescribe("grp", () => { test("flaky", () => { ${body} }); });\n`;
53 /** A test that, run here, leaves a cache a green check of main would keep. */
54 const leavesCache = `mkdirSync(".forge-cache", { recursive: true }); writeFileSync(".forge-cache/tsbuildinfo", "x");`;
55
56 /** What each push's check was sent to the runner as, by run id. */
57 const sentRuns: string[] = [];
58 /** The stood-in runner's answer to the next job. */
59 let answer: "green" | "red" | "flaky" = "green";
60 const runnerStep: typeof runRunnerStep = async (_app, input) => {
61 sentRuns.push(input.runId);
62 if (answer === "green") {
63 input.output.push("ran");
64 return { taken: true, ran: ok(undefined), runner: "local-1", contained: true, note: "" };
65 }
66 const lines = answer === "flaky" ? ["t/a.test.ts:", "(fail) grp > flaky", " 41 pass", " 1 fail", "Ran 42 tests across 9 files."] : ["the gate failed"];
67 for (const line of lines) {
68 input.output.push(line);
69 input.log(line);
70 }
71 return { taken: true, ran: err("check exited with code 1"), failed: "check", runner: "local-1", contained: true, note: "" };
72 };
73
74 const mainCheck = (repoId: string, commit: string): Run | undefined =>
75 listRuns(app.db, repoId, { kind: "check", limit: 50 }).find(
76 (r) => r.issueId === null && r.env === "main" && r.commitOid === commit && (r.state === "ok" || r.state === "failed"),
77 );
78
79 /** Nothing of `run` is kept on the forge: no checkout, no cache, no snapshot, no impact map. */
80 function keptNothing(repoId: string, run: Run): void {
81 const log = readRunLog(app.config.dataDir, run.id).lines.join("\n");
82 expect(log).not.toContain("cache kept");
83 expect(log).not.toContain("snapshot kept");
84 expect(log).not.toContain("impact map");
85 expect(existsSync(join(dir, "check-cache", repoId.replace(/[^A-Za-z0-9_-]/g, "_")))).toBe(false);
86 }
87
88 test("main's push check goes to a connected runner, keeps nothing here, and its red is main's red", async () => {
89 const made = await createRepo(app, alice, { name: "lib", visibility: "public" });
90 if (!made.ok) throw new Error("repo");
91 const repo = made.value;
92 const checks = startChecks(app, {
93 forgeUrl: "http://forge.test",
94 concurrency: 1,
95 placement: { mode: "runner", waitMs: 300 },
96 runnerStep,
97 });
98 try {
99 const green = await commitToBranch(app, alice, repo, {
100 message: "green",
101 files: [{ path: "forge.json", content: JSON.stringify({ check: { run: "true", install: "" } }) }],
102 });
103 if (!green.ok) throw new Error(JSON.stringify(green.error));
104 expect(await waitFor(() => mainCheck(repo.id, green.value.commitOid) !== undefined, { within: 30_000 })).toBe(true);
105 const greenRun = mainCheck(repo.id, green.value.commitOid)!;
106 expect(greenRun.state).toBe("ok");
107 expect(sentRuns).toContain(greenRun.id);
108 expect(greenRun.placement).toBe("runner");
109 // It never checked out here.
110 expect(existsSync(join(dir, "checks", greenRun.id))).toBe(false);
111 keptNothing(repo.id, greenRun);
112 expect(redMain(app.db, repo.id)).toBeUndefined();
113
114 answer = "red";
115 const red = await commitToBranch(app, alice, repo, { message: "red", files: [{ path: "b.txt", content: "b\n" }] });
116 if (!red.ok) throw new Error(JSON.stringify(red.error));
117 expect(await waitFor(() => mainCheck(repo.id, red.value.commitOid) !== undefined, { within: 30_000 })).toBe(true);
118 const redRun = mainCheck(repo.id, red.value.commitOid)!;
119 expect(redRun.state).toBe("failed");
120 expect(sentRuns).toContain(redRun.id);
121 keptNothing(repo.id, redRun);
122 // The runner's verdict is main's: the red card names its commit.
123 expect(redMain(app.db, repo.id)?.commitOid).toBe(red.value.commitOid);
124 } finally {
125 await checks.stop();
126 }
127 }, 90_000);
128
129 test("a runner's red of one test that passes alone here makes main green, and still keeps nothing here", async () => {
130 const made = await createRepo(app, alice, { name: "flaked", visibility: "public" });
131 if (!made.ok) throw new Error("repo");
132 const repo = made.value;
133 answer = "flaky";
134 const checks = startChecks(app, {
135 forgeUrl: "http://forge.test",
136 concurrency: 1,
137 placement: { mode: "runner", waitMs: 300 },
138 runnerStep,
139 });
140 try {
141 const made2 = await commitToBranch(app, alice, repo, {
142 message: "base",
143 files: [
144 { path: "forge.json", content: JSON.stringify({ check: { run: "true", install: "" } }) },
145 { path: "t/a.test.ts", content: spec(leavesCache) },
146 ],
147 });
148 if (!made2.ok) throw new Error(JSON.stringify(made2.error));
149 expect(await waitFor(() => mainCheck(repo.id, made2.value.commitOid) !== undefined, { within: 60_000 })).toBe(true);
150 const run = mainCheck(repo.id, made2.value.commitOid)!;
151 const log = readRunLog(app.config.dataDir, run.id).lines.join("\n");
152 expect(log).toContain("re-running 1 failed test(s) alone");
153 expect(run.state).toBe("ok");
154 expect(sentRuns).toContain(run.id);
155 keptNothing(repo.id, run);
156 } finally {
157 await checks.stop();
158 }
159 }, 90_000);
test/main-slot.test.ts +7 −2
@@ -66,10 +66,12 @@ test(`with ${SLOTS} runner jobs holding every slot and a pull's check queued beh
6666 });
6767 if (!topic.ok) throw new Error(JSON.stringify(topic.error));
6868 }
69 // A runner (stood in) takes each pull's check and holds it until released.
69 // A runner (stood in) takes each pull's check and holds it until released; main's, offered with
70 // every runner busy, nobody takes.
7071 const held: (() => void)[] = [];
7172 let released = false;
7273 const runnerStep: typeof runRunnerStep = async (_app, input) => {
74 if (mainChecks().some((r) => r.id === input.runId)) return { taken: false, why: "no runner took it" };
7375 if (!released) await new Promise<void>((resolve) => held.push(resolve));
7476 input.output.push("passed");
7577 return { taken: true, ran: ok(undefined), runner: "local-1", contained: true, note: "" };
@@ -138,7 +140,10 @@ test("one main slot for the whole forge: with the check slot full, a second repo
138140 if (!topic.ok) throw new Error(JSON.stringify(topic.error));
139141 const held: (() => void)[] = [];
140142 let released = false;
141 const runnerStep: typeof runRunnerStep = async () => {
143 // It holds the pull's check; main's, offered with the runner busy, nobody takes.
144 const runnerStep: typeof runRunnerStep = async (_app, input) => {
145 if (listRuns(app.db, input.repoId, { kind: "check", limit: 50 }).some((r) => r.id === input.runId && r.issueId === null))
146 return { taken: false, why: "no runner took it" };
142147 if (!released) await new Promise<void>((resolve) => held.push(resolve));
143148 return { taken: true, ran: ok(undefined), runner: "local-1", contained: true, note: "" };
144149 };
test/runner-hands.test.ts +4 −4
@@ -81,12 +81,12 @@ const store = (kind: string): string => join(f.dataDir, "checks", kind, `${f.rep
8181
8282 describe("which runs a runner takes", () => {
8383 test("main's whole verification now goes to a runner; a bisection step, and a verification of nothing kept, stay here", () => {
84 expect(runnerTakes({ tier: "verify", keepImpact: true, isMain: true })).toBe(true);
85 expect(runnerTakes({ tier: "verify", keepImpact: true, isMain: true, only: ["test/a.test.ts"] })).toBe(false);
84 expect(runnerTakes({ tier: "verify", keepImpact: true })).toBe(true);
85 expect(runnerTakes({ tier: "verify", keepImpact: true, only: ["test/a.test.ts"] })).toBe(false);
8686 expect(runnerTakes({ tier: "verify", keepImpact: false })).toBe(false);
87 // Unchanged: a pull's fast tier goes, main's own check does not.
87 // A pull's fast tier goes, and main's own push check now too: it keeps only its verdict.
8888 expect(runnerTakes({ tier: "fast" })).toBe(true);
89 expect(runnerTakes({ tier: "run", keep: true, isMain: true })).toBe(false);
89 expect(runnerTakes({ tier: "run", keepImpact: true })).toBe(true);
9090 });
9191 });
9292

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

Keyboard shortcuts

Docs