Public: anyone can read this; the crew can change it.
A pull reads green and can land while its tests are still queued #17258
Merged 42h 53m ago, live in production
mason/forge:mason/17256-a-pull-reads-green-and-can-land-while-it → main 0 commits fork 1 thread · 1 unresolved
2 files
changed +76
−1
src/core/runs.ts +6 −1
| @@ -1359,7 +1359,12 @@ export function checkSummary( | ||
| 1359 | 1359 | // row was read, so a red check under a later deploy read "Check passed" on the page, the API and |
| 1360 | 1360 | // MCP while the queue, reading every kind, never admitted it. |
| 1361 | 1361 | const verdict = verdictForHead(db, issueId, headOid); |
| 1362 | const latest = verdict.find((run) => run.state === "failed" && !isCut(run)) ?? verdict[0]; | |
| 1362 | // A head reads ok only when the newest run of every kind is ok: a preview deploy that finishes | |
| 1363 | // in seconds must not cover a check still queued or running (#17256). | |
| 1364 | const latest = | |
| 1365 | verdict.find((run) => run.state === "failed" && !isCut(run)) ?? | |
| 1366 | verdict.find((run) => run.state !== "ok") ?? | |
| 1367 | verdict[0]; | |
| 1363 | 1368 | // A check the forge cut short proved nothing: it is never red (#12594). |
| 1364 | 1369 | return latest |
| 1365 | 1370 | ? { state: latest.state === "failed" && isCut(latest) ? "cancelled" : latest.state, run: latest } |
test/check-summary-queued-under-deploy.test.ts added +70
| @@ -0,0 +1,70 @@ | ||
| 1 | /** | |
| 2 | * A head reads ok only when the newest run of every kind is ok (#17256): a preview deploy recorded | |
| 3 | * after the check, and finished in seconds with no tests, must not cover a check still queued. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 12 | import { getPull } from "../src/core/pulls.ts"; | |
| 13 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 14 | import { checkSummary, claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 15 | import { createUser } from "../src/core/users.ts"; | |
| 16 | import type { User } from "../src/core/users.ts"; | |
| 17 | ||
| 18 | let dataDir: string; | |
| 19 | let app: App; | |
| 20 | let alice: User; | |
| 21 | let repo: Repo; | |
| 22 | ||
| 23 | beforeAll(async () => { | |
| 24 | dataDir = await mkdtemp(join(tmpdir(), "forge-check-queued-")); | |
| 25 | app = createApp({ dataDir, port: 0 }); | |
| 26 | const a = await createUser(app.db, { | |
| 27 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 28 | password: "a-good-passphrase", adminIfFirst: true, | |
| 29 | }); | |
| 30 | if (!a.ok) throw new Error(a.error); | |
| 31 | alice = a.value; | |
| 32 | const made = await createRepo(app, alice, { name: "lib", visibility: "private" }); | |
| 33 | if (!made.ok) throw new Error(String(made.error)); | |
| 34 | repo = made.value; | |
| 35 | await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "a.ts", content: "export const a = 0;\n" }] }); | |
| 36 | await updateRepoSettings(app, alice, repo, { requireChecks: true }); | |
| 37 | repo = getRepoById(app.db, repo.id)!; | |
| 38 | await commitToBranch(app, alice, repo, { branch: "feature/x", base: "main", message: "X", files: [{ path: "x.ts", content: "export const x = 1;\n" }] }); | |
| 39 | }); | |
| 40 | ||
| 41 | afterAll(async () => { | |
| 42 | app.db.close(); | |
| 43 | await rm(dataDir, { recursive: true, force: true }); | |
| 44 | }); | |
| 45 | ||
| 46 | test("a deploy recorded after a queued check does not make the head green", async () => { | |
| 47 | // Invariant: ok needs the newest run of every kind ok; the failing order is check, then deploy. | |
| 48 | const opened = await openPull(app, alice, repo, { title: "X", body: "", baseBranch: "main", headBranch: "feature/x" }); | |
| 49 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 50 | const pull = getPull(app.db, repo.id, opened.value.number)!; | |
| 51 | const record = (kind: "check" | "deploy") => | |
| 52 | createRun(app.db, { repoId: repo.id, kind, env: `pull-${pull.number}`, issueId: pull.id, commitOid: pull.headOid, reason: "pull" }); | |
| 53 | const state = () => checkSummary(app.db, pull.id, pull.headOid).state; | |
| 54 | ||
| 55 | const check = record("check"); | |
| 56 | const deploy = record("deploy"); | |
| 57 | claimRun(app.db, deploy.id); | |
| 58 | finishRun(app.db, deploy.id, { state: "ok", summary: "running · no tests declared, none run" }); | |
| 59 | ||
| 60 | expect(state()).toBe("queued"); | |
| 61 | expect(checkSummary(app.db, pull.id, pull.headOid).run?.id).toBe(check.id); | |
| 62 | const refused = await mergePull(app, alice, repo, getPull(app.db, repo.id, pull.number)!, "merge"); | |
| 63 | expect(refused.ok).toBe(false); | |
| 64 | if (!refused.ok) expect(refused.error).toBe("checks_required"); | |
| 65 | ||
| 66 | claimRun(app.db, check.id); | |
| 67 | expect(state()).toBe("running"); | |
| 68 | finishRun(app.db, check.id, { state: "ok", summary: "check passed in 1s" }); | |
| 69 | expect(state()).toBe("ok"); | |
| 70 | }); |
new above
offline
Correct. The unfinished check is chosen over the newer finished deploy. The CheckSummary doc comment above still describes the old 'newest run' rule; update it.