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

A green change's card on the asks page says "its tests passed" every time, not "its check passed" when another run sorts first #14407

Merged opened this

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

Merged

scout/forge:scout/14406-a-green-change-s-card-on-the-asks-page-s → main 3 commits fork

  • Merged. scout/14406-a-green-change-s-card-on-the-asks-page-s was merged into main as 5074df6.

Review

Sign in to review this change.
3 files changed +92 −1
src/core/runs.ts +33
@@ -1291,6 +1291,39 @@ export function latestRunsForIssues(
12911291 return out;
12921292 }
12931293
1294 /**
1295 * Each pull's green check and deploy runs at the commit it names, newest first
1296 * by a total order — `created_at`, then id — so two runs made in the same
1297 * millisecond always read back the same way (#14406). One read for the set.
1298 */
1299 export function greenRunsAt(
1300 db: Database,
1301 heads: readonly { issueId: string; commitOid: string }[],
1302 ): Map<string, Run[]> {
1303 const out = new Map<string, Run[]>();
1304 const want = new Map(heads.map((h) => [h.issueId, h.commitOid]));
1305 const ids = [...want.keys()];
1306 const CHUNK = 400;
1307 for (let i = 0; i < ids.length; i += CHUNK) {
1308 const batch = ids.slice(i, i + CHUNK);
1309 const rows = db
1310 .query<RunRow, string[]>(
1311 `SELECT * FROM run INDEXED BY run_issue
1312 WHERE issue_id IN (${batch.map((_, n) => `?${n + 1}`).join(",")})
1313 AND kind IN ('check','deploy') AND state = 'ok'
1314 ORDER BY created_at DESC, id DESC`,
1315 )
1316 .all(...batch);
1317 for (const row of rows) {
1318 if (row.issue_id === null || want.get(row.issue_id) !== row.commit_oid) continue;
1319 const list = out.get(row.issue_id) ?? [];
1320 list.push(toRun(row));
1321 out.set(row.issue_id, list);
1322 }
1323 }
1324 return out;
1325 }
1326
12941327 /**
12951328 * How many automatic follow-ups for a failed check an agent has had on a
12961329 * pull since a person last spoke: the bound behind rule 7 in docs/APPS.md.
src/web/studio/decisions.ts +20 −1
@@ -21,6 +21,8 @@ import { thumbLook, type Reader } from "../pages/looks.ts";
2121 import { changeHref } from "./nouns.ts";
2222 import { flatten } from "./note.ts";
2323 import { testsClause } from "./words.ts";
24 import { greenRunsAt, type Run } from "../../core/runs.ts";
25 import { TESTS_PASSED_TAIL } from "../../apps/runtime.ts";
2426 import { MOVED_SINCE_APPROVAL } from "../../core/approval_at.ts";
2527 import { reviewerPaused } from "../../crew/reviewer_paused.ts";
2628 import { conflictsOf, conflictWords } from "../../crew/stale_asks.ts";
@@ -79,6 +81,11 @@ export function decisionsFor(
7981 look && lookUrl(repoBase(repo), look)
8082 );
8183 };
84 // The look cards' green runs, in one read: the card speaks for the one whose tests passed.
85 const lookChecks = candidates.flatMap((c) =>
86 c.kind === "look" && c.check?.issueId ? [{ issueId: c.check.issueId, commitOid: c.check.commitOid }] : [],
87 );
88 const greens = lookChecks.length === 0 ? new Map<string, Run[]>() : greenRunsAt(db, lookChecks);
8289 const worded = (c: Scored): Omit<Decision, "consequence" | "waiting"> => {
8390 if (c.kind === "assigned") {
8491 const thing = c.pull ?? c.issue!;
@@ -180,7 +187,7 @@ export function decisionsFor(
180187 };
181188 if (c.kind === "look" && c.pull) {
182189 const picture = pictureOf(c.repo, c.pull);
183 const clause = testsClause(c.check ?? null);
190 const clause = testsClause(c.check ? speakingRun(greens, c.check) : null);
184191 // The crew's own words say who finished it; a person's own change
185192 // gets the wording that is true of it — nobody "finished" it for
186193 // them, it is simply green and waiting.
@@ -416,3 +423,15 @@ function proposalForms(d: Decision, back?: string): Html {
416423 return html`<form id="${id}" method="post" action="${post("approve")}" hidden data-now="Approved" data-now-once>${where}</form>
417424 <form id="${id}-later" method="post" action="${post("later")}" hidden>${where}</form>`;
418425 }
426
427 /**
428 * The green run a look card speaks for: of the pull's green check and deploy
429 * runs at the green run's commit (`greenRunsAt`, newest first by time then
430 * id), the one whose summary says its tests passed wins — a check that went
431 * green beside it in the same moment says less (#14406). Otherwise the newest
432 * green, else the run the card was found with.
433 */
434 export function speakingRun(greens: ReadonlyMap<string, readonly Run[]>, check: Run): Run {
435 const runs = check.issueId === null ? [] : greens.get(check.issueId) ?? [];
436 return runs.find((r) => r.summary.endsWith(TESTS_PASSED_TAIL)) ?? runs[0] ?? check;
437 }
test/asks.test.ts +39
@@ -279,6 +279,45 @@ describe("the asks page", () => {
279279 expect(card?.says).toContain("its tests passed");
280280 expect(card?.short).toContain("its tests passed");
281281 });
282 test("a green deploy and a green check in the same millisecond: the tests tail wins (#14406)", async () => {
283 const bot = getUserByName(app.db, "bot")!;
284 const branch = await commitToBranch(app, getUserByName(app.db, "alice")!, repo, {
285 branch: "bot/14406-tie",
286 base: "main",
287 message: "Bot tie",
288 files: [{ path: "TIE.md", content: "x\n" }],
289 });
290 expect(branch.ok).toBe(true);
291 const opened = await openPull(app, bot, repo, {
292 title: "Bot tie",
293 body: "",
294 baseBranch: "main",
295 headBranch: "bot/14406-tie",
296 });
297 if (!opened.ok) throw new Error(String(opened.error));
298 const pull = opened.value;
299 const make = (kind: "deploy" | "check") =>
300 createRun(app.db, { repoId: repo.id, kind, issueId: pull.id, env: `pull-${pull.number}`, commitOid: pull.headOid });
301 const deploy = make("deploy");
302 const check = make("check");
303 for (const [run, summary] of [
304 [deploy, `running at x${TESTS_PASSED_TAIL}`],
305 [check, "passed"],
306 ] as const) {
307 claimRun(app.db, run.id);
308 finishRun(app.db, run.id, { state: "ok", summary });
309 }
310 // Both made in the same millisecond: the check's id is the larger.
311 app.db
312 .query("UPDATE run SET created_at = '2026-11-19T00:00:00.000Z' WHERE id IN (?1, ?2)")
313 .run(deploy.id, check.id);
314 const card = decisionsFor(
315 { app, auth: { user: getUserByName(app.db, "alice")! } } as unknown as Ctx,
316 [repo],
317 ).find((d) => d.id === `look:${pull.id}`);
318 expect(card?.says).toContain("its tests passed");
319 expect(card?.short).toContain("its tests passed");
320 });
282321 describe("a legacy setting finding (#3314)", () => {
283322 // The sentinel files no setting now (#3269); one filed before asks
284323 // nobody and is answered nowhere.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs