Public: anyone can read this; the crew can change it.
A pull whose green was checked on an older main reads "checked against an older main" on its page, in the API and in the MCP #2238
scout/forge:scout/2237-a-pull-whose-green-was-checked-on-an-old → main 3 commits fork 2 threads · 2 unresolved
8 files
changed +161
−7
src/checks/stale.ts added +19
| @@ -0,0 +1,19 @@ | ||
| 1 | /** | |
| 2 | * Whether a green is on today's base. A check records the base tip it was | |
| 3 | * merged with (`run.baseOid`, #1810); when the base has moved on since, the | |
| 4 | * green was earned against an older tree. A run that recorded none (made | |
| 5 | * before #1810, or a default-branch push) and a tip that could not be read | |
| 6 | * are never called stale: nothing is guessed. Pure; the caller reads the | |
| 7 | * tip once per request. | |
| 8 | */ | |
| 9 | ||
| 10 | import type { Run } from "../core/runs.ts"; | |
| 11 | ||
| 12 | export function checkStale( | |
| 13 | run: Pick<Run, "baseOid"> | null, | |
| 14 | baseTipOid: string | undefined, | |
| 15 | ): boolean { | |
| 16 | if (run === null || run.baseOid === "") return false; | |
| 17 | if (baseTipOid === undefined || baseTipOid === "") return false; | |
| 18 | return run.baseOid !== baseTipOid; | |
| 19 | } |
src/http/api.ts +8
| @@ -20,6 +20,7 @@ import { DOMAINS } from "../kernel/domains.ts"; | ||
| 20 | 20 | import { SOURCES } from "../boards/sources.ts"; |
| 21 | 21 | import { bodyCapFor, readBounded } from "./limits.ts"; |
| 22 | 22 | import { askCheck } from "../checks/again.ts"; |
| 23 | import { checkStale } from "../checks/stale.ts"; | |
| 23 | 24 | import { mayView, mayViewId, sealedScope } from "../core/sealed.ts"; |
| 24 | 25 | import { changeCapacity, listCapacity } from "../actions/capacity.ts"; |
| 25 | 26 | import { changeLimit, listLimits } from "../actions/limits.ts"; |
| @@ -320,6 +321,7 @@ import { | ||
| 320 | 321 | } from "../core/issues.ts"; |
| 321 | 322 | import type { Closing } from "../actions/issues.ts"; |
| 322 | 323 | import { |
| 324 | checkSummary, | |
| 323 | 325 | checksForHead, |
| 324 | 326 | getRun, |
| 325 | 327 | isTerminal, |
| @@ -3228,9 +3230,15 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 3228 | 3230 | { db: ctx.app.db, requireReview: found.repo.requireReview }, |
| 3229 | 3231 | ); |
| 3230 | 3232 | const hold = getHold(ctx.app.db, found.pull.id); |
| 3233 | const check = checkSummary(ctx.app.db, found.pull.id, status.headOid); | |
| 3231 | 3234 | return json({ |
| 3232 | 3235 | ...withLabels(ctx, found.pull), |
| 3233 | 3236 | variantSiblings: variantSiblings(ctx.app.db, [found.pull])[0] ?? [], |
| 3237 | // Only a pull that can still land has a green worth qualifying. | |
| 3238 | checkStale: | |
| 3239 | found.pull.state === "open" && | |
| 3240 | found.pull.mergedAt === null && | |
| 3241 | checkStale(check.run, status.baseOid), | |
| 3234 | 3242 | ...(found.pull.state === "open" && found.pull.mergedAt === null |
| 3235 | 3243 | ? { mergeable: status.mergeable, conflicts: status.conflicts } |
| 3236 | 3244 | : {}), |
src/http/mcp.ts +10 −5
| @@ -92,6 +92,8 @@ import { waitsForPerson } from "../crew/review.ts"; | ||
| 92 | 92 | import { attachLook } from "../actions/attach_look.ts"; |
| 93 | 93 | import { lookUrl } from "../core/looks.ts"; |
| 94 | 94 | import { pullProposalOf } from "../core/proposal_token.ts"; |
| 95 | import { checkStale } from "../checks/stale.ts"; | |
| 96 | import { resolveOid } from "../git/merge.ts"; | |
| 95 | 97 | import { getPull, pullDir, pullMergeState } from "../core/pulls.ts"; |
| 96 | 98 | import { repoGraph } from "../core/dependencies.ts"; |
| 97 | 99 | import { pillarView } from "../core/pillars.ts"; |
| @@ -502,7 +504,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 502 | 504 | { |
| 503 | 505 | name: "pull", |
| 504 | 506 | description: |
| 505 | "Read a pull: its title, state and head and base, and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), `proposal` ({child, origin}, or null) when a child's proposal token opened it, and `check`: the latest check's state and the base tip it was merged with (`baseOid`, empty when it merged nothing). `mergeable` and `conflicts` are the same fields as GET /api/v1/repos/:owner/:name/pulls/:number; `check` is the latest check's `state` and `run.baseOid` from GET …/pulls/:number/checks.", | |
| 507 | "Read a pull: its title, state and head and base, and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), `proposal` ({child, origin}, or null) when a child's proposal token opened it, and `check`: the latest check's state and the base tip it was merged with (`baseOid`, empty when it merged nothing), and `checkStale`: true when that tip is no longer the base's, so a green is from an older base. `mergeable` and `conflicts` are the same fields as GET /api/v1/repos/:owner/:name/pulls/:number; `check` is the latest check's `state` and `run.baseOid` from GET …/pulls/:number/checks.", | |
| 506 | 508 | inputSchema: { |
| 507 | 509 | type: "object", |
| 508 | 510 | properties: { |
| @@ -522,11 +524,10 @@ const TOOLS: readonly Tool[] = [ | ||
| 522 | 524 | : undefined; |
| 523 | 525 | if (pull === undefined || !mayView(ctx.app.db, repo, pull, user)) |
| 524 | 526 | return bad("no_such_pull", `no pull #${String(n)}`); |
| 525 | const state = await pullMergeState( | |
| 526 | await pullDir(ctx.app.db, ctx.app.reposRoot, repo, pull), | |
| 527 | pull, | |
| 528 | ); | |
| 527 | const dir = await pullDir(ctx.app.db, ctx.app.reposRoot, repo, pull); | |
| 528 | const state = await pullMergeState(dir, pull); | |
| 529 | 529 | const check = checkSummary(ctx.app.db, pull.id, pull.headOid); |
| 530 | const tip = await resolveOid(dir, `refs/heads/${pull.baseBranch}`); | |
| 530 | 531 | return good({ |
| 531 | 532 | number: pull.number, |
| 532 | 533 | title: pull.title, |
| @@ -535,6 +536,10 @@ const TOOLS: readonly Tool[] = [ | ||
| 535 | 536 | head: pull.headBranch, |
| 536 | 537 | proposal: pullProposalOf(ctx.app.db, pull.id) ?? null, |
| 537 | 538 | check: { state: check.state, baseOid: check.run?.baseOid ?? "" }, |
| 539 | checkStale: | |
| 540 | pull.state === "open" && | |
| 541 | pull.mergedAt === null && | |
| 542 | checkStale(check.run, tip), | |
| 538 | 543 | ...(state ?? {}), |
| 539 | 544 | }); |
| 540 | 545 | }, |
src/tui/screens/pull.ts +23 −2
| @@ -46,6 +46,8 @@ import { | ||
| 46 | 46 | type EnvState, |
| 47 | 47 | type EnvStatus, envsFor } from "../../apps/runtime.ts"; |
| 48 | 48 | import { proposedByText } from "../../core/proposal_token.ts"; |
| 49 | import { checkStale } from "../../checks/stale.ts"; | |
| 50 | import { resolveOid } from "../../git/merge.ts"; | |
| 49 | 51 | import { getAppByRepo } from "../../core/apps.ts"; |
| 50 | 52 | import { getIssue, type Issue } from "../../core/issues.ts"; |
| 51 | 53 | import { isProposed, pullMayRun } from "../../core/pull_trust.ts"; |
| @@ -227,6 +229,8 @@ export function pullScreen( | ||
| 227 | 229 | let check: CheckSummary = NO_CHECK; |
| 228 | 230 | /** The pull's base branch, to name what the check was merged with. */ |
| 229 | 231 | let checkBase = ""; |
| 232 | /** The base branch's tip now, to say when the green was on an older one. */ | |
| 233 | let baseTip = ""; | |
| 230 | 234 | /** Agent runs about this pull, newest first. */ |
| 231 | 235 | const crew = new RunList(f); |
| 232 | 236 | const mayWrite = (): boolean => src.capabilities.write && repo !== undefined; |
| @@ -275,6 +279,16 @@ export function pullScreen( | ||
| 275 | 279 | ? NO_CHECK |
| 276 | 280 | : checkSummary(f.db, row.id, row.headOid || (facts?.headOid ?? "")); |
| 277 | 281 | checkBase = row?.baseBranch ?? facts?.baseBranch ?? ""; |
| 282 | baseTip = | |
| 283 | repo === undefined || | |
| 284 | row === undefined || | |
| 285 | row.state !== "open" || | |
| 286 | row.mergedAt !== null | |
| 287 | ? "" | |
| 288 | : ((await resolveOid( | |
| 289 | await pullDir(f.app.db, f.app.reposRoot, repo, row), | |
| 290 | `refs/heads/${row.baseBranch}`, | |
| 291 | )) ?? ""); | |
| 278 | 292 | const runs = |
| 279 | 293 | repo === undefined || row === undefined |
| 280 | 294 | ? undefined |
| @@ -757,7 +771,13 @@ export function pullScreen( | ||
| 757 | 771 | // The box is exactly as tall as what is in it: the state, then a row |
| 758 | 772 | // for the verdicts when there are any, then a row for the checks when |
| 759 | 773 | // a deploy has run or the gate demands one. |
| 760 | const checksLine = checksText(check, requireChecks, isApp, checkBase); | |
| 774 | const checksLine = checksText( | |
| 775 | check, | |
| 776 | requireChecks, | |
| 777 | isApp, | |
| 778 | checkBase, | |
| 779 | checkStale(check.run, baseTip), | |
| 780 | ); | |
| 761 | 781 | const boxH = |
| 762 | 782 | 3 + |
| 763 | 783 | (standingText(standing(), requireReview) === "" ? 0 : 1) + |
| @@ -1198,6 +1218,7 @@ export function checksText( | ||
| 1198 | 1218 | required: boolean, |
| 1199 | 1219 | isApp: boolean, |
| 1200 | 1220 | baseBranch = "", |
| 1221 | stale = false, | |
| 1201 | 1222 | ): string { |
| 1202 | 1223 | if (check.state === "none") |
| 1203 | 1224 | return required |
| @@ -1215,7 +1236,7 @@ export function checksText( | ||
| 1215 | 1236 | }`; |
| 1216 | 1237 | switch (check.state) { |
| 1217 | 1238 | case "ok": |
| 1218 | return `checks: passed${summary}`; | |
| 1239 | return `checks: passed${stale ? " against an older " + (baseBranch || "base") : ""}${summary}`; | |
| 1219 | 1240 | case "failed": |
| 1220 | 1241 | return `checks: failed${summary}`; |
| 1221 | 1242 | case "running": |
src/web/pages/pull.ts +9
| @@ -21,6 +21,7 @@ import { | ||
| 21 | 21 | } from "../../actions/pulls.ts"; |
| 22 | 22 | import { readFileAt } from "../../apps/checkout.ts"; |
| 23 | 23 | import { parseCheck } from "../../apps/manifest.ts"; |
| 24 | import { checkStale } from "../../checks/stale.ts"; | |
| 24 | 25 | import { tierLine, type TierState } from "../../checks/tiers.ts"; |
| 25 | 26 | import { getAppByRepo } from "../../core/apps.ts"; |
| 26 | 27 | import { labelsFor, listLabels } from "../../core/issues.ts"; |
| @@ -215,6 +216,8 @@ export function checksLine( | ||
| 215 | 216 | conflicts = 0, |
| 216 | 217 | /** The pull's base branch, to name what the check was merged with. */ |
| 217 | 218 | baseBranch = "", |
| 219 | /** The passing check was merged with a base tip that is no longer the base's. */ | |
| 220 | stale = false, | |
| 218 | 221 | ): Html { |
| 219 | 222 | if (!isApp && !required && check.state === "none" && !waiting && again === "") |
| 220 | 223 | return html``; |
| @@ -238,6 +241,10 @@ export function checksLine( | ||
| 238 | 241 | ? html`<span class="bad" |
| 239 | 242 | >${icon("x")}Conflicts in ${conflicts} ${conflicts === 1 ? "file" : "files"}</span |
| 240 | 243 | >${link}` |
| 244 | : check.state === "ok" && stale | |
Right on the page. |
||
| 245 | ? html`<span class="now" | |
| 246 | >${icon("clock")}Checked against an older ${baseBranch === "" ? "base" : baseBranch}</span | |
| 247 | >${link}` | |
| 241 | 248 | : check.state === "ok" |
| 242 | 249 | ? html`<span class="ok">${icon("check")}Checks passed</span>${link}` |
| 243 | 250 | : check.state === "failed" |
| @@ -321,6 +328,7 @@ function mergeBox( | ||
| 321 | 328 | tier = "", |
| 322 | 329 | ): Html { |
| 323 | 330 | const thread = `${repoBase(repo)}/pulls/${pull.number}`; |
| 331 | const stale = checkStale(check.run, status.baseOid); | |
| 324 | 332 | // A reader's head runs nothing until a writer approves it; say so rather |
| 325 | 333 | // than leave "no checks yet" waiting for something that will not come. |
| 326 | 334 | const checks = checksLine( |
| @@ -337,6 +345,7 @@ function mergeBox( | ||
| 337 | 345 | : "", |
| 338 | 346 | status.conflicts.length, |
| 339 | 347 | pull.baseBranch, |
| 348 | stale, | |
| 340 | 349 | ); |
| 341 | 350 | const reopen = html`<form method="post" action="${thread}/state"> |
| 342 | 351 | <input type="hidden" name="state" value="open" /> |
test/check-stale.test.ts added +27
| @@ -0,0 +1,27 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { checkStale } from "../src/checks/stale.ts"; | |
| 3 | import { checksLine } from "../src/web/pages/pull.ts"; | |
| 4 | ||
| 5 | const A = "a".repeat(40); | |
| 6 | const B = "b".repeat(40); | |
| 7 | ||
| 8 | test("a check on an older base tip is stale; on the tip it is not", () => { | |
| 9 | expect(checkStale({ baseOid: A }, B)).toBe(true); | |
| 10 | expect(checkStale({ baseOid: B }, B)).toBe(false); | |
| 11 | }); | |
| 12 | ||
| 13 | test("nothing is guessed: no run, no recorded base, or no readable tip is not stale", () => { | |
| 14 | expect(checkStale(null, B)).toBe(false); | |
| 15 | expect(checkStale({ baseOid: "" }, B)).toBe(false); | |
| 16 | expect(checkStale({ baseOid: A }, undefined)).toBe(false); | |
| 17 | }); | |
| 18 | ||
| 19 | test("a stale green reads as an older main instead of green", () => { | |
| 20 | const ok = { state: "ok", run: null } as const; | |
| 21 | const args = ["/a/b", ok, false, true, false, "", "", 0, "main"] as const; | |
| 22 | const stale = checksLine(...args, true).text; | |
| 23 | expect(stale).toContain("Checked against an older main"); | |
| 24 | expect(stale).not.toContain('class="ok"'); | |
| 25 | expect(stale).not.toContain("Checks passed"); | |
| 26 | expect(checksLine(...args, false).text).toContain("Checks passed"); | |
| 27 | }); |
test/checks.test.ts +7
| @@ -407,6 +407,13 @@ describe("checks", () => { | ||
| 407 | 407 | // The terminal says the same words (#1810). |
| 408 | 408 | expect(checksText(seen, false, true, "main")).toContain(` · ${said}`); |
| 409 | 409 | expect(checksText(seen, false, true)).not.toContain("checked against"); |
| 410 | // A green on an older base is not an unqualified pass in the terminal (#2237). | |
| 411 | const green = { ...seen, state: "ok" as const }; | |
| 412 | expect(checksText(green, false, true, "main", true)).toContain( | |
| 413 | "checks: passed against an older main", | |
| 414 | ); | |
| 415 | expect(checksText(green, false, true, "main", false)).toContain("checks: passed"); | |
| 416 | expect(checksText(green, false, true, "main", false)).not.toContain("older"); | |
| 410 | 417 | expect( |
| 411 | 418 | checksForHead(app.db, pull.id, branched.value.commitOid)[0]?.id, |
| 412 | 419 | ).toBe(failed.id); |
test/mcp.test.ts +58
| @@ -487,6 +487,64 @@ describe("the forge over MCP", () => { | ||
| 487 | 487 | expect(read.value.check.baseOid).toBe("abc1234abc1234abc1234abc1234abc1234abc12"); |
| 488 | 488 | }); |
| 489 | 489 | |
| 490 | test("pull says checkStale in the MCP and the API when its check was on an older base (#2237)", async () => { | |
| 491 | const branched = await commitToBranch(app, alice, game, { | |
| 492 | branch: "stale-feat", | |
| 493 | message: "another change", | |
| 494 | files: [{ path: "c.txt", content: "c\n" }], | |
| 495 | }); | |
| 496 | if (!branched.ok) throw new Error(JSON.stringify(branched.error)); | |
| 497 | const opened = await openPull(app, alice, game, { | |
| 498 | title: "Stale", | |
| 499 | baseBranch: "main", | |
| 500 | headBranch: "stale-feat", | |
| 501 | }); | |
| 502 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 503 | const pull = opened.value; | |
| 504 | const viaApi = async () => | |
| 505 | (await ( | |
| 506 | await fetch(`${base}/api/v1/repos/alice/game/pulls/${pull.number}`, { | |
| 507 | headers: { authorization: `Bearer ${ro}` }, | |
| 508 | }) | |
| 509 | ).json()) as any; | |
| 510 | const viaMcp = async () => | |
| 511 | (await tool(ro, "pull", { repo: "alice/game", number: pull.number })).value; | |
| 512 | // No check, or one that recorded no base: not stale. | |
| 513 | expect((await viaMcp()).checkStale).toBe(false); | |
| 514 | expect((await viaApi()).checkStale).toBe(false); | |
| 515 | const run = createRun(app.db, { | |
| 516 | repoId: game.id, | |
| 517 | kind: "check", | |
| 518 | issueId: pull.id, | |
| 519 | env: `pull-${pull.number}`, | |
| 520 | commitOid: branched.value.commitOid, | |
| 521 | }); | |
| 522 | expect((await viaMcp()).checkStale).toBe(false); | |
| 523 | // Checked on the base's tip: not stale. | |
| 524 | const tip: string = (await viaApi()).status.baseOid; | |
| 525 | setRunBase(app.db, run.id, tip); | |
| 526 | expect((await viaMcp()).checkStale).toBe(false); | |
| 527 | expect((await viaApi()).checkStale).toBe(false); | |
| 528 | // The base moves on: the green is from an older main. | |
| 529 | const moved = await commitToBranch(app, alice, game, { | |
| 530 | message: "main moves", | |
| 531 | files: [{ path: "d.txt", content: "d\n" }], | |
| 532 | }); | |
| 533 | if (!moved.ok) throw new Error(JSON.stringify(moved.error)); | |
| 534 | expect((await viaMcp()).checkStale).toBe(true); | |
| 535 | expect((await viaApi()).checkStale).toBe(true); | |
| 536 | // A new check on the new tip is current again. | |
| 537 | setRunBase(app.db, run.id, moved.value.commitOid); | |
| 538 | expect((await viaMcp()).checkStale).toBe(false); | |
| 539 | expect((await viaApi()).checkStale).toBe(false); | |
| 540 | // Stale again, then closed: a pull that cannot land reads false, not noise. | |
| 541 | setRunBase(app.db, run.id, tip); | |
| 542 | expect((await viaApi()).checkStale).toBe(true); | |
| 543 | app.db.run("UPDATE issue SET state = 'closed' WHERE id = ?", [pull.id]); | |
| 544 | expect((await viaMcp()).checkStale).toBe(false); | |
| 545 | expect((await viaApi()).checkStale).toBe(false); | |
| 546 | }); | |
| 547 | ||
| 490 | 548 | test("stop takes a run id from now, and refuses a stale or foreign one", async () => { |
| 491 | 549 | const run = createRun(app.db, { |
| 492 | 550 | repoId: game.id, |
new above
offline
This is computed for merged and closed pulls as well, so every merged pull reads
checkStale: trueonce main moves. Gate it likemergeablejust below (open and not merged), and do the same in the MCPpulltool.