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

Deploys still run for closed and old pulls: never deploy a closed pull #16664

Merged opened this in answer to

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

Merged

scout/forge:scout/16662-deploys-still-run-for-closed-and-old-pul → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/16662-deploys-still-run-for-closed-and-old-pul was merged into main as bb38e45.

Review

Sign in to review this change.
2 files changed +42 −1
src/checks/request.ts +17 −1
@@ -1,5 +1,5 @@
11
2 import { runDir } from "../core/pulls.ts";
2 import { getIssueById, getPull, runDir } from "../core/pulls.ts";
33 import { announceRun } from "../actions/runs.ts";
44 import { isContributionFork } from "../core/contribute.ts";
55 import { issueMayRun } from "../core/pull_trust.ts";
@@ -31,6 +31,22 @@ export async function request(
3131 if (lane.stopped || !accountActive(app.db, repo.ownerId)) return undefined;
3232 // A guest's fork runs nothing: its code runs only as a pull a person approved.
3333 if (isContributionFork(app.db, repo.id)) return undefined;
34 // A closed or merged pull is checked no more, whoever asks and whenever (a retry, a
35 // stale-red recheck, a late event): nothing it could prove will land (#16662).
36 if (issueId !== undefined) {
37 const issue = getIssueById(app.db, issueId);
38 const pull = issue?.kind === "pull" ? getPull(app.db, repo.id, issue.number) : undefined;
39 if (pull !== undefined && pull.state !== "open") {
40 log.info("check refused: its pull is not open", {
41 repo: `${repo.ownerName}/${repo.name}`,
42 pull: pull.number,
43 state: pull.state,
44 reason,
45 commit: commitOid.slice(0, 7),
46 });
47 return undefined;
48 }
49 }
3450 // A pull from someone who cannot write runs nothing until a writer
3551 // approves this exact head (`core/pull_trust.ts`).
3652 if (!issueMayRun(app.db, repo, issueId, commitOid)) {
test/checks-queue.test.ts +25
@@ -243,6 +243,31 @@ describe("checks", () => {
243243 );
244244 });
245245
246 test("a check asked for a closed pull is refused and queues nothing (#16662)", async () => {
247 // Invariant: lane.request returns no run for a pull that is not open, for any reason.
248 const branched = await commitToBranch(f.app, f.alice, f.repo, {
249 branch: "closed-ask",
250 message: "Closed before the ask",
251 files: [{ path: "CLOSED.md", content: "x\n" }],
252 });
253 if (!branched.ok) throw new Error(JSON.stringify(branched.error));
254 const opened = await openPull(f.app, f.alice, f.repo, {
255 title: "Closed before the ask",
256 baseBranch: "main",
257 headBranch: "closed-ask",
258 });
259 if (!opened.ok) throw new Error(String(opened.error));
260 const closed = setIssueState(f.app, f.alice, f.repo, opened.value, "closed");
261 if (!closed.ok) throw new Error(String(closed.error));
262 const before = listRuns(f.app.db, f.repo.id, { kind: "check" }).length;
263 for (const reason of ["retry", "asked", "push"])
264 expect(
265 await f.checks.request(f.repo, `pull-${opened.value.number}`, branched.value.commitOid, reason, opened.value.id),
266 ).toBeUndefined();
267 expect(listRuns(f.app.db, f.repo.id, { kind: "check" }).filter((r) => r.issueId === opened.value.id && r.state === "queued")).toEqual([]);
268 expect(listRuns(f.app.db, f.repo.id, { kind: "check" }).length).toBe(before);
269 });
270
246271 test("a queued gate keeps the last free slot from pull checks", () => {
247272 // One slot free, a gate queued: the pull check passes, the gate starts.
248273 expect(holdsLastSlot(1, true)).toBe(true);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs