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

A red check under a later green deploy reads red, as the merge queue reads it #16502

Merged opened this From outsidein answer to

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

Merged

grokbot/forge:fix/16451-check-summary-red-under-deploy → main 0 commits fork

  • Merged. fix/16451-check-summary-red-under-deploy was merged into main as d83448f.

Review

Sign in to review this change.
2 files changed +93 −8
src/core/runs.ts +10 −8
@@ -1229,7 +1229,10 @@ export function verdictForHead(
12291229 }
12301230
12311231 export interface CheckSummary {
1232 /** `ok` when the latest deploy of this head succeeded; `none` when there is none. */
1232 /**
1233 * `failed` when the newest run of any kind at this head is red (a cut one is not); else the
1234 * newest run's state; `none` when there is none.
1235 */
12331236 readonly state: RunState | "none";
12341237 readonly run: Run | null;
12351238 }
@@ -1239,13 +1242,12 @@ export function checkSummary(
12391242 issueId: string,
12401243 headOid: string,
12411244 ): CheckSummary {
1242 const row = db
1243 .query<
1244 RunRow,
1245 [string, string]
1246 >("SELECT * FROM run WHERE kind IN ('deploy','check') AND issue_id = ?1 AND commit_oid = ?2 ORDER BY id DESC LIMIT 1")
1247 .get(issueId, headOid);
1248 const latest = row ? toRun(row) : undefined;
1245 // The newest run of each kind speaks, as it does for the merge queue (`verdictForHead`): a
1246 // preview that deployed after the check went red does not make the head green. Only the newest
1247 // row was read, so a red check under a later deploy read "Check passed" on the page, the API and
1248 // MCP while the queue, reading every kind, never admitted it.
1249 const verdict = verdictForHead(db, issueId, headOid);
1250 const latest = verdict.find((run) => run.state === "failed" && !isCut(run)) ?? verdict[0];
12491251 // A check the forge cut short proved nothing: it is never red (#12594).
12501252 return latest
12511253 ? { state: latest.state === "failed" && isCut(latest) ? "cancelled" : latest.state, run: latest }
test/check-summary-red-under-deploy.test.ts added +83
@@ -0,0 +1,83 @@
1 /**
2 * A head's check summary reads every kind's newest run, as the merge queue does: a preview that
3 * deployed after the check went red does not make the head green. Before, only the newest row was
4 * read, so a red check under a later deploy said "Check passed" on the page, the API and MCP while
5 * the queue (`verdictForHead`) never admitted the pull.
6 */
7 import { afterAll, beforeAll, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { openPull } from "../src/actions/pulls.ts";
13 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
14 import { getPull } from "../src/core/pulls.ts";
15 import { checkSummary, createRun, verdictForHead } from "../src/core/runs.ts";
16 import { createUser } from "../src/core/users.ts";
17 import { nextOfPull } from "../src/flow/next_actor.ts";
18
19 let dataDir: string;
20 let app: App;
21 let pull: NonNullable<ReturnType<typeof getPull>>;
22 let repoId: string;
23
24 beforeAll(async () => {
25 dataDir = await mkdtemp(join(tmpdir(), "forge-check-summary-"));
26 app = createApp({ dataDir, port: 0 });
27 const a = await createUser(app.db, {
28 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
29 password: "a-good-passphrase", adminIfFirst: true,
30 });
31 if (!a.ok) throw new Error(a.error);
32 const made = await createRepo(app, a.value, { name: "lib", visibility: "private" });
33 if (!made.ok) throw new Error(String(made.error));
34 repoId = made.value.id;
35 await commitToBranch(app, a.value, made.value, { message: "Start", files: [{ path: "a.ts", content: "export const a = 0;\n" }] });
36 await commitToBranch(app, a.value, made.value, { branch: "feature/x", base: "main", message: "X", files: [{ path: "x.ts", content: "export const x = 1;\n" }] });
37 const opened = await openPull(app, a.value, made.value, { title: "X", body: "", baseBranch: "main", headBranch: "feature/x" });
38 if (!opened.ok) throw new Error(String(opened.error));
39 pull = getPull(app.db, repoId, opened.value.number)!;
40 });
41
42 afterAll(async () => {
43 app.db.close();
44 await rm(dataDir, { recursive: true, force: true });
45 });
46
47 const mark = (id: string, state: string, summary: string) =>
48 app.db.query("UPDATE run SET state = ?2, summary = ?3, finished_at = strftime('%Y-%m-%dT%H:%M:%fZ','now') WHERE id = ?1").run(id, state, summary);
49 const run = (kind: "check" | "deploy") =>
50 createRun(app.db, { repoId, kind, env: `pull-${pull.number}`, issueId: pull.id, commitOid: pull.headOid, reason: "pull" });
51
52 test("a red check under a later green deploy reads red, as the queue reads it", () => {
53 // Invariant: checkSummary is red whenever verdictForHead holds a red that was not cut.
54 const check = run("check");
55 const deploy = run("deploy");
56 mark(deploy.id, "ok", "running at https://preview · no tests declared, none run");
57 mark(check.id, "failed", 'check failed: gate: rule "both doors"');
58 const verdict = verdictForHead(app.db, pull.id, pull.headOid);
59 expect(verdict.some((r) => r.state !== "ok")).toBe(true);
60 const seen = checkSummary(app.db, pull.id, pull.headOid);
61 expect(seen.state).toBe("failed");
62 expect(seen.run?.id).toBe(check.id);
63 // The next-actor line follows: the builder, not a reviewer of a green head.
64 const next = nextOfPull(app.db, pull, { headOid: pull.headOid, conflicts: 0 }, undefined);
65 expect(next?.who).toBe("builder");
66 });
67
68 test("a re-run that turns the check green makes the head green again", () => {
69 // Invariant: the newest run of each kind supersedes its own older red.
70 const again = run("check");
71 mark(again.id, "ok", "check passed in 1s");
72 const seen = checkSummary(app.db, pull.id, pull.headOid);
73 expect(seen.state).toBe("ok");
74 expect(seen.run?.id).toBe(again.id);
75 });
76
77 test("a check the forge cut short is never red, even under a later deploy", () => {
78 // Invariant: a cut check reads cancelled when it is the newest run, and never failed (#12594).
79 const cut = run("check");
80 mark(cut.id, "failed", "interrupted by a restart; queued again");
81 const seen = checkSummary(app.db, pull.id, pull.headOid);
82 expect(seen.state).toBe("cancelled");
83 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs