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

Review is owed from the check's green, not the preview's: a slow check queue lapsed every pull to a person tonight #1291

Closed opened this in answer to
Closed without merging

scout/forge:scout/1216-review-is-owed-from-the-check-s-green-no → main 5 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +155 −7
scripts/gate.ts +1
@@ -45,6 +45,7 @@ export const GATE: readonly string[] = [
4545 "test/refresh-meta.test.ts",
4646 "test/restore-card.test.ts",
4747 "test/returns.test.ts",
48 "test/review-from-check.test.ts",
4849 "test/review-route.test.ts",
4950 "test/review-lines.test.ts",
5051 "test/review-gate.test.ts",
src/crew/review.ts +14 −7
@@ -392,13 +392,7 @@ export async function sweepReviews(app: App): Promise<number> {
392392 const key = `${pull.headOid}:${result}`;
393393 if (said.get(pull.id) === key) continue;
394394 said.set(pull.id, key);
395 const since = reviewAttempts(app.db, pull)?.greenAt;
396 log.info(
397 result === "lapsed"
398 ? `review: lapsed since ${since}`
399 : "review: not sent yet",
400 { repo: `${repo.ownerName}/${repo.name}`, pull: pull.number },
401 );
395 skipped(app, repo, pull, result);
402396 }
403397 }
404398 }
@@ -410,3 +404,16 @@ function forgetSettled(stalled: Set<string>, queued: number): number {
410404 for (const id of said.keys()) if (!stalled.has(id)) said.delete(id);
411405 return queued;
412406 }
407
408 /** One line for a pull the sweep leaves be, and why, so a stall reads in the log. */
409 function skipped(app: App, repo: Repo, pull: Pull, why: "wait" | "lapsed"): void {
410 const history = reviewAttempts(app.db, pull);
411 if (history === undefined) return;
412 let line = `review: lapsed since ${history.greenAt.slice(11, 16)}`;
413 if (why === "wait") {
414 const out = history.attempts.at(-1)?.reviewerId;
415 const who = reviewersOf(app.db, repo.id).find((r) => r.user.id === out);
416 line = `review: waiting on ${who?.user.username ?? "the reviewer"}`;
417 }
418 log.info(line, { repo: `${repo.ownerName}/${repo.name}`, pull: pull.number });
419 }
test/review-green-origin.test.ts added +140
@@ -0,0 +1,140 @@
1 /**
2 * Review is owed from the check's green, not the preview deploy's (#1216):
3 * a slow check queue must not lapse a pull before review was ever sent.
4 */
5
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { addToCrew, createAgent } from "../src/actions/crew.ts";
11 import { openPull } from "../src/actions/pulls.ts";
12 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
13 import { createApp, type App } from "../src/app.ts";
14 import { setCrewRole } from "../src/core/agents.ts";
15 import type { Pull } from "../src/core/pulls.ts";
16 import { getRepoById, type Repo } from "../src/core/repos.ts";
17 import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
18 import { createUser, getUserByName, type User } from "../src/core/users.ts";
19 import { sendToReview, waitsForPerson } from "../src/crew/review.ts";
20 import { quietLogs } from "./helpers/globals.ts";
21
22 quietLogs();
23
24 const T0 = Date.parse("2026-10-13T03:00:00.000Z");
25 const at = (min: number) => new Date(T0 + min * 60_000);
26
27 describe("review is owed from the check's green", () => {
28 let dataDir = "";
29 let app: App;
30 let alice: User;
31 let repo: Repo;
32 let n = 0;
33
34 const fresh = () => getRepoById(app.db, repo.id)!;
35 const reviewRuns = (pull: Pull) =>
36 listRuns(app.db, repo.id, { issueId: pull.id }).filter(
37 (r) => r.reason === "review",
38 );
39 const pullOn = async (): Promise<Pull> => {
40 const branch = `b${++n}`;
41 const c = await commitToBranch(app, alice, repo, {
42 branch,
43 base: "main",
44 message: branch,
45 files: [{ path: `${branch}.md`, content: "x\n" }],
46 });
47 if (!c.ok) throw new Error(JSON.stringify(c.error));
48 const o = await openPull(app, alice, repo, {
49 title: branch,
50 body: "",
51 baseBranch: "main",
52 headBranch: branch,
53 });
54 if (!o.ok) throw new Error(String(o.error));
55 return o.value;
56 };
57 const green = (pull: Pull, kind: "check" | "deploy", queued: number, done: number) => {
58 const run = createRun(app.db, {
59 repoId: repo.id,
60 kind,
61 issueId: pull.id,
62 env: `pull-${pull.number}`,
63 commitOid: pull.headOid,
64 reason: "pull",
65 });
66 claimRun(app.db, run.id);
67 finishRun(app.db, run.id, { state: "ok", summary: "ok" });
68 app.db
69 .query("UPDATE run SET created_at = ?2, finished_at = ?3 WHERE id = ?1")
70 .run(run.id, at(queued).toISOString(), at(done).toISOString());
71 };
72 const agentPull = async () => {
73 const pull = await pullOn();
74 return { ...pull, authorIsAgent: true };
75 };
76
77 beforeAll(async () => {
78 dataDir = await mkdtemp(join(tmpdir(), "forge-review-check-"));
79 app = createApp({ dataDir, port: 0 });
80 const made = await createUser(app.db, {
81 trusted: true,
82 username: "alice",
83 email: "[email protected]",
84 password: "a-good-passphrase",
85 adminIfFirst: true,
86 });
87 if (!made.ok) throw new Error(made.error);
88 alice = made.value;
89 const r = await createRepo(app, alice, { name: "garden", visibility: "private" });
90 if (!r.ok) throw new Error(String(r.error));
91 repo = r.value;
92 const seeded = await commitToBranch(app, alice, repo, {
93 message: "seed",
94 files: [{ path: "README.md", content: "# garden\n" }],
95 });
96 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
97 const agent = await createAgent(app, alice, { username: "quill" });
98 if (!agent.ok) throw new Error(String(agent.error));
99 addToCrew(app, alice, repo, "quill");
100 setCrewRole(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
101 }, 30_000);
102
103 afterAll(async () => {
104 app.close();
105 await rm(dataDir, { recursive: true, force: true });
106 });
107
108 test("a deploy green at t=0 and a check green at t=70 min: sent at t=70, not lapsed", async () => {
109 const pull = await agentPull();
110 green(pull, "deploy", 0, 0);
111 green(pull, "check", 0, 70);
112 expect(waitsForPerson(app.db, repo.id, pull, at(70))).toBeUndefined();
113 expect(await sendToReview(app, fresh(), pull, at(70))).toBe("sent");
114 expect(reviewRuns(pull)).toHaveLength(1);
115 });
116
117 test("a head with no check is reviewed from its deploy, as before", async () => {
118 const pull = await agentPull();
119 green(pull, "deploy", 0, 0);
120 expect(await sendToReview(app, fresh(), pull, at(1))).toBe("sent");
121 expect(await sendToReview(app, fresh(), pull, at(1))).toBe("wait");
122 });
123
124 test("a head that went green long ago and was never sent is sent once, late, and says so if it lapses", async () => {
125 const pull = await agentPull();
126 green(pull, "check", 0, 72);
127 // Green at 72; the first look comes at 140, past the lapse.
128 expect(await sendToReview(app, fresh(), pull, at(72 + 70))).toBe("sent");
129 const run = reviewRuns(pull)[0]!;
130 app.db
131 .query("UPDATE run SET created_at = ?2 WHERE id = ?1")
132 .run(run.id, at(72 + 70).toISOString());
133 // The late review is out: the lapse counts from its sending.
134 expect(waitsForPerson(app.db, repo.id, pull, at(72 + 80))).toBeUndefined();
135 app.db.query("UPDATE run SET state = 'failed' WHERE id = ?1").run(run.id);
136 const wait = waitsForPerson(app.db, repo.id, pull, at(72 + 70 + 61));
137 expect(wait?.why).toBe("lapsed");
138 expect(wait?.lateCheckMinutes).toBe(72);
139 });
140 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs