Public: anyone can read this; the crew can change it.
A pull's check runs on its head merged into today's base, and records the base it checked #1536
scout/forge:scout/1178-a-pull-s-check-runs-on-its-head-merged-i → main 3 commits fork 3 threads · 3 unresolved
12 files
changed +196
−7
src/checks/service.ts +2
| @@ -490,6 +490,8 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle { | ||
| 490 | 490 | const merged = await mergeForCheck(bare, x.pull.baseBranch, tip, x.commitOid); |
| 491 | 491 | if (!merged.ok) return { ok: false, error: merged.error }; |
| 492 | 492 | source = merged.commit; |
| 493 | if (x.runId !== undefined) | |
| 494 | noteRunProgress(app.db, x.runId, { baseOid: tip }); | |
| 493 | 495 | mergeLine = merged.line; |
| 494 | 496 | } |
| 495 | 497 | const run = { id: x.id, commitOid: source }; |
src/contract/openapi.ts +6
| @@ -51,6 +51,12 @@ export const ROUTES: readonly Route[] = [ | ||
| 51 | 51 | auth: true, |
| 52 | 52 | body: { title: "string", head: "string", headRepo: "string" }, |
| 53 | 53 | }, |
| 54 | { | |
| 55 | method: "get", | |
| 56 | path: `${REPO}/pulls/{number}`, | |
| 57 | auth: false, | |
| 58 | summary: "Read a pull: its diff, mergeability, and `check` (the verdict at its head and the `baseOid` it was merged into when checked)", | |
| 59 | }, | |
| 54 | 60 | { |
| 55 | 61 | method: "post", |
| 56 | 62 | path: `${REPO}/pulls/{number}/reviews`, |
src/core/runs.ts +32 −1
| @@ -52,6 +52,8 @@ export interface Run { | ||
| 52 | 52 | /** For a deploy: `production` or `pull-<n>`. Empty for an agent run. */ |
| 53 | 53 | readonly env: string; |
| 54 | 54 | readonly commitOid: string; |
| 55 | /** The base tip a pull's check merged the head into; '' when it merged nothing. */ | |
| 56 | readonly baseOid: string; | |
| 55 | 57 | /** For an agent run: the branch it works on. */ |
| 56 | 58 | readonly branch: string; |
| 57 | 59 | readonly state: RunState; |
| @@ -92,6 +94,7 @@ interface RunRow { | ||
| 92 | 94 | issue_id: string | null; |
| 93 | 95 | env: string; |
| 94 | 96 | commit_oid: string; |
| 97 | base_oid: string; | |
| 95 | 98 | branch: string; |
| 96 | 99 | state: RunState; |
| 97 | 100 | summary: string; |
| @@ -119,6 +122,7 @@ const toRun = (r: RunRow): Run => ({ | ||
| 119 | 122 | issueId: r.issue_id, |
| 120 | 123 | env: r.env, |
| 121 | 124 | commitOid: r.commit_oid, |
| 125 | baseOid: r.base_oid, | |
| 122 | 126 | branch: r.branch, |
| 123 | 127 | state: r.state, |
| 124 | 128 | summary: r.summary, |
| @@ -335,13 +339,16 @@ export function noteRunProgress( | ||
| 335 | 339 | subscriptionId?: string | undefined; |
| 336 | 340 | /** Whether the shell is held to the sandbox, and why not when it is not. */ |
| 337 | 341 | sandbox?: { enforced: boolean; note: string } | undefined; |
| 342 | /** The base tip a pull's check merged the head into. */ | |
| 343 | baseOid?: string | undefined; | |
| 338 | 344 | }, |
| 339 | 345 | ): void { |
| 340 | 346 | db.query( |
| 341 | 347 | `UPDATE run SET session_id = COALESCE(?2, session_id), cost_usd = COALESCE(?3, cost_usd), |
| 342 | 348 | branch = COALESCE(?4, branch), subscription_id = COALESCE(?5, subscription_id), |
| 343 | 349 | sandbox_enforced = COALESCE(?6, sandbox_enforced), |
| 344 | sandbox_note = COALESCE(?7, sandbox_note) | |
| 350 | sandbox_note = COALESCE(?7, sandbox_note), | |
| 351 | base_oid = COALESCE(?8, base_oid) | |
| 345 | 352 | WHERE id = ?1`, |
| 346 | 353 | ).run( |
| 347 | 354 | runId, |
| @@ -351,6 +358,7 @@ export function noteRunProgress( | ||
| 351 | 358 | progress.subscriptionId ?? null, |
| 352 | 359 | progress.sandbox === undefined ? null : progress.sandbox.enforced ? 1 : 0, |
| 353 | 360 | progress.sandbox?.note.slice(0, 300) ?? null, |
| 361 | progress.baseOid ?? null, | |
| 354 | 362 | ); |
| 355 | 363 | } |
| 356 | 364 | |
| @@ -731,6 +739,29 @@ export function checkSummary( | ||
| 731 | 739 | : { state: "none", run: null }; |
| 732 | 740 | } |
| 733 | 741 | |
| 742 | /** A pull's check as the API and the MCP read it. */ | |
| 743 | export interface CheckReading { | |
| 744 | state: CheckSummary["state"]; | |
| 745 | head: string; | |
| 746 | /** The base commit the head was merged into when checked; null when none. */ | |
| 747 | baseOid: string | null; | |
| 748 | summary: string | null; | |
| 749 | } | |
| 750 | ||
| 751 | export function checkReading( | |
| 752 | db: Database, | |
| 753 | issueId: string, | |
| 754 | headOid: string, | |
| 755 | ): CheckReading { | |
| 756 | const { state, run } = checkSummary(db, issueId, headOid); | |
| 757 | return { | |
| 758 | state, | |
| 759 | head: headOid, | |
| 760 | baseOid: run?.baseOid || null, | |
| 761 | summary: run?.summary ?? null, | |
| 762 | }; | |
| 763 | } | |
| 764 | ||
| 734 | 765 | /** |
| 735 | 766 | * The latest run per issue for a set of issues — one query, for a list that |
| 736 | 767 | * shows a check mark beside every pull without asking per row. |
src/core/schema.ts +6
| @@ -1595,6 +1595,12 @@ export const migrations: readonly string[] = [ | ||
| 1595 | 1595 | PRIMARY KEY (repo_id, parent_id, issue_id) |
| 1596 | 1596 | ); |
| 1597 | 1597 | `, |
| 1598 | // 76 — the base a pull's check was run against (#1178): the check is of the | |
| 1599 | // head merged into this commit, so the verdict names it. '' for a run that | |
| 1600 | // merged nothing (a push to a branch). | |
| 1601 | ` | |
| 1602 | ALTER TABLE run ADD COLUMN base_oid TEXT NOT NULL DEFAULT ''; | |
| 1603 | `, | |
| 1598 | 1604 | ]; |
| 1599 | 1605 | |
| 1600 | 1606 | /** |
src/http/api.ts +2
| @@ -281,6 +281,7 @@ import { | ||
| 281 | 281 | } from "../core/issues.ts"; |
| 282 | 282 | import type { Closing } from "../actions/issues.ts"; |
| 283 | 283 | import { |
| 284 | checkReading, | |
| 284 | 285 | checksForHead, |
| 285 | 286 | getRun, |
| 286 | 287 | isTerminal, |
| @@ -2819,6 +2820,7 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2819 | 2820 | : {}), |
| 2820 | 2821 | status, |
| 2821 | 2822 | diff, |
| 2823 | check: checkReading(ctx.app.db, found.pull.id, found.pull.headOid), | |
| 2822 | 2824 | hold: hold === undefined ? null : holdJson(hold), |
| 2823 | 2825 | }); |
| 2824 | 2826 | }); |
src/http/mcp.ts +3 −2
| @@ -82,7 +82,7 @@ import { | ||
| 82 | 82 | type Repo, |
| 83 | 83 | } from "../core/repos.ts"; |
| 84 | 84 | import { plannerDeclines } from "../crew/autonomy.ts"; |
| 85 | import { listActiveRuns } from "../core/runs.ts"; | |
| 85 | import { checkReading, listActiveRuns } from "../core/runs.ts"; | |
| 86 | 86 | import { scopeAllows } from "../core/tokens.ts"; |
| 87 | 87 | import { getUsersByIds, type User } from "../core/users.ts"; |
| 88 | 88 | import { openapi } from "../contract/openapi.ts"; |
| @@ -412,7 +412,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 412 | 412 | { |
| 413 | 413 | name: "pull", |
| 414 | 414 | description: |
| 415 | "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`). The same two fields as GET /api/v1/repos/:owner/:name/pulls/:number.", | |
| 415 | "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`), and its `check`: the verdict at its head and the `baseOid` it was checked against (the head merged into that commit). The same fields as GET /api/v1/repos/:owner/:name/pulls/:number.", | |
| 416 | 416 | inputSchema: { |
| 417 | 417 | type: "object", |
| 418 | 418 | properties: { |
| @@ -443,6 +443,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 443 | 443 | base: pull.baseBranch, |
| 444 | 444 | head: pull.headBranch, |
| 445 | 445 | ...(state ?? {}), |
| 446 | check: checkReading(ctx.app.db, pull.id, pull.headOid), | |
| 446 | 447 | }); |
| 447 | 448 | }, |
| 448 | 449 | }, |
src/tui/screens/pull.ts +13 −2
| @@ -643,7 +643,12 @@ export function pullScreen( | ||
| 643 | 643 | // The box is exactly as tall as what is in it: the state, then a row |
| 644 | 644 | // for the verdicts when there are any, then a row for the checks when |
| 645 | 645 | // a deploy has run or the gate demands one. |
| 646 | const checksLine = checksText(check, requireChecks, isApp); | |
| 646 | const checksLine = checksText( | |
| 647 | check, | |
| 648 | requireChecks, | |
| 649 | isApp, | |
| 650 | facts?.baseBranch, | |
| 651 | ); | |
| 647 | 652 | const boxH = |
| 648 | 653 | 3 + |
| 649 | 654 | (standingText(standing(), requireReview) === "" ? 0 : 1) + |
| @@ -1044,6 +1049,7 @@ export function checksText( | ||
| 1044 | 1049 | check: CheckSummary, |
| 1045 | 1050 | required: boolean, |
| 1046 | 1051 | isApp: boolean, |
| 1052 | baseName = "the base", | |
| 1047 | 1053 | ): string { |
| 1048 | 1054 | if (check.state === "none") |
| 1049 | 1055 | return required |
| @@ -1052,7 +1058,12 @@ export function checksText( | ||
| 1052 | 1058 | ? "checks: no deploy of this head yet" |
| 1053 | 1059 | : ""; |
| 1054 | 1060 | const run = check.run; |
| 1055 | const summary = run === null || run.summary === "" ? "" : ` · ${run.summary}`; | |
| 1061 | const merged = | |
| 1062 | run === null || run.baseOid === "" | |
| 1063 | ? "" | |
| 1064 | : ` · checked on ${baseName}@${run.baseOid.slice(0, 7)}`; | |
| 1065 | const summary = | |
| 1066 | (run === null || run.summary === "" ? "" : ` · ${run.summary}`) + merged; | |
| 1056 | 1067 | switch (check.state) { |
| 1057 | 1068 | case "ok": |
| 1058 | 1069 | return `checks: passed${summary}`; |
src/web/pages/pull.ts +10 −1
| @@ -210,6 +210,7 @@ function checksLine( | ||
| 210 | 210 | tier = "", |
| 211 | 211 | /** A writer's button to ask for a check again; empty for anyone else. */ |
| 212 | 212 | again: Html | "" = "", |
| 213 | baseName = "the base", | |
| 213 | 214 | ): Html { |
| 214 | 215 | if (!isApp && !required && check.state === "none" && !waiting && again === "") |
| 215 | 216 | return html``; |
| @@ -220,7 +221,14 @@ function checksLine( | ||
| 220 | 221 | : html`<span class="where-sep" aria-hidden="true">·</span |
| 221 | 222 | ><a href="${base}/runs/${run.id}" |
| 222 | 223 | >deploy ${run.commitOid.slice(0, 7)}</a |
| 223 | >`; | |
| 224 | >${when( | |
| 225 | run.baseOid !== "", | |
| 226 | () => | |
| 227 | html`<span class="where-sep" aria-hidden="true">·</span | |
| 228 | ><span class="base-oid" | |
| 229 | >checked on ${baseName}@${run.baseOid.slice(0, 7)}</span | |
| 230 | >`, | |
| 231 | )}`; | |
| 224 | 232 | const body = |
| 225 | 233 | check.state === "ok" |
| 226 | 234 | ? html`<span class="ok">${icon("check")}Checks passed</span>${link}` |
| @@ -319,6 +327,7 @@ function mergeBox( | ||
| 319 | 327 | ${btn("Check again", { size: "sm", icon: "loader" })} |
| 320 | 328 | </form>` |
| 321 | 329 | : "", |
| 330 | pull.baseBranch, | |
| 322 | 331 | ); |
| 323 | 332 | const reopen = html`<form method="post" action="${thread}/state"> |
| 324 | 333 | <input type="hidden" name="state" value="open" /> |
test/checks.test.ts +51
| @@ -9,6 +9,7 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import { askCheck } from "../src/checks/again.ts"; | |
| 12 | 13 | import { mergePull, openPull, submitReview } from "../src/actions/pulls.ts"; |
| 13 | 14 | import { setIssueState } from "../src/actions/issues.ts"; |
| 14 | 15 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| @@ -26,6 +27,7 @@ import { | ||
| 26 | 27 | cancelRunsForPull, |
| 27 | 28 | CHECK_RESTART_LIMIT, |
| 28 | 29 | checksForHead, |
| 30 | checkSummary, | |
| 29 | 31 | claimRun, |
| 30 | 32 | createRun, |
| 31 | 33 | getRun, |
| @@ -398,6 +400,55 @@ describe("checks", () => { | ||
| 398 | 400 | expect(passed.reason).toBe("push"); |
| 399 | 401 | }, 60_000); |
| 400 | 402 | |
| 403 | test("a pull green alone but red merged with a newer base reads red, and names the base it was checked on", async () => { | |
| 404 | const gate = await commitToBranch(app, alice, repo, { | |
| 405 | message: "The base forbids BAD.md", | |
| 406 | files: [{ path: "forge.json", content: checkJson("test ! -f BAD.md") }], | |
| 407 | }); | |
| 408 | if (!gate.ok) throw new Error(JSON.stringify(gate.error)); | |
| 409 | await settled((r) => r.commitOid === gate.value.commitOid); | |
| 410 | const branched = await commitToBranch(app, alice, repo, { | |
| 411 | branch: "merged-red", | |
| 412 | message: "Green on its own", | |
| 413 | files: [{ path: "own.txt", content: "own\n" }], | |
| 414 | }); | |
| 415 | if (!branched.ok) throw new Error(JSON.stringify(branched.error)); | |
| 416 | const opened = await openPull(app, alice, repo, { | |
| 417 | title: "Green alone", | |
| 418 | baseBranch: "main", | |
| 419 | headBranch: "merged-red", | |
| 420 | }); | |
| 421 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 422 | const pull = opened.value; | |
| 423 | const green = await settled( | |
| 424 | (r) => r.issueId === pull.id && r.commitOid === branched.value.commitOid, | |
| 425 | ); | |
| 426 | expect(green.state).toBe("ok"); | |
| 427 | expect(green.baseOid).toBe(gate.value.commitOid); | |
| 428 | ||
| 429 | const moved = await commitToBranch(app, alice, repo, { | |
| 430 | message: "The base learns BAD.md", | |
| 431 | files: [{ path: "BAD.md", content: "bad\n" }], | |
| 432 | }); | |
| 433 | if (!moved.ok) throw new Error(JSON.stringify(moved.error)); | |
| 434 | await settled((r) => r.commitOid === moved.value.commitOid); | |
| 435 | const again = await askCheck(app, alice, repo, pull); | |
| 436 | if (!again.ok) throw new Error(again.message); | |
| 437 | const red = await settled((r) => r.id === again.run.id); | |
| 438 | expect(red.state).toBe("failed"); | |
| 439 | expect(red.baseOid).toBe(moved.value.commitOid); | |
| 440 | expect(red.baseOid).not.toBe(green.baseOid); | |
| 441 | expect(checkSummary(app.db, pull.id, branched.value.commitOid).state).toBe( | |
| 442 | "failed", | |
| 443 | ); | |
| 444 | // The merge is never written to a branch. | |
| 445 | expect( | |
| 446 | listRuns(app.db, repo.id, { kind: "check" }).find( | |
| 447 | (r) => r.env === "main" && r.commitOid === moved.value.commitOid, | |
| 448 | )?.baseOid, | |
| 449 | ).toBe(""); | |
| 450 | }, 60_000); | |
| 451 | ||
| 401 | 452 | test("a bun test failure in the check step is summarised: how many passed, how many failed, and their names", async () => { |
| 402 | 453 | const gate = await commitToBranch(app, alice, repo, { |
| 403 | 454 | message: "The base's check runs bun test", |
test/pull-check-again.test.ts +54
| @@ -12,6 +12,9 @@ import { openPull } from "../src/actions/pulls.ts"; | ||
| 12 | 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 13 | 13 | import { startChecks, type ChecksHandle } from "../src/checks/service.ts"; |
| 14 | 14 | import { createToken } from "../src/core/tokens.ts"; |
| 15 | import { checkSummary } from "../src/core/runs.ts"; | |
| 16 | import { getPull } from "../src/core/pulls.ts"; | |
| 17 | import { getRepo } from "../src/core/repos.ts"; | |
| 15 | 18 | import { createSession } from "../src/core/sessions.ts"; |
| 16 | 19 | import { createUser, type User } from "../src/core/users.ts"; |
| 17 | 20 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -129,3 +132,54 @@ describe("asking again over HTTP", () => { | ||
| 129 | 132 | expect(await page(alice, closedNumber)).not.toContain("Check again"); |
| 130 | 133 | }); |
| 131 | 134 | }); |
| 135 | ||
| 136 | describe("a check that merged names the base it checked", () => { | |
| 137 | test("the page, the REST read and the MCP all say which base commit", async () => { | |
| 138 | const repo = getRepo(app.db, "alice", "gate"); | |
| 139 | const pull = repo && getPull(app.db, repo.id, openNumber); | |
| 140 | if (!repo || !pull) throw new Error("no pull"); | |
| 141 | const deadline = Date.now() + 30_000; | |
| 142 | let baseOid = ""; | |
| 143 | while (Date.now() < deadline) { | |
| 144 | const { state, run } = checkSummary(app.db, pull.id, pull.headOid); | |
| 145 | if (state === "ok" && run && run.baseOid !== "") { | |
| 146 | baseOid = run.baseOid; | |
| 147 | break; | |
| 148 | } | |
| 149 | await Bun.sleep(100); | |
| 150 | } | |
| 151 | expect(baseOid).toMatch(/^[0-9a-f]{40}$/); | |
| 152 | ||
| 153 | const html = await page(alice, openNumber); | |
| 154 | expect(html).toContain(`checked on main@${baseOid.slice(0, 7)}`); | |
| 155 | ||
| 156 | const rest = (await ( | |
| 157 | await fetch(`${servers.url}/api/v1/repos/alice/gate/pulls/${openNumber}`) | |
| 158 | ).json()) as { check: { state: string; head: string; baseOid: string } }; | |
| 159 | expect(rest.check).toMatchObject({ | |
| 160 | state: "ok", | |
| 161 | head: pull.headOid, | |
| 162 | baseOid, | |
| 163 | }); | |
| 164 | ||
| 165 | const res = await fetch(`${servers.url}/mcp`, { | |
| 166 | method: "POST", | |
| 167 | headers: { | |
| 168 | "content-type": "application/json", | |
| 169 | accept: "application/json, text/event-stream", | |
| 170 | authorization: `Bearer ${writerToken}`, | |
| 171 | }, | |
| 172 | body: JSON.stringify({ | |
| 173 | jsonrpc: "2.0", | |
| 174 | id: 1, | |
| 175 | method: "tools/call", | |
| 176 | params: { | |
| 177 | name: "pull", | |
| 178 | arguments: { repo: "alice/gate", number: openNumber }, | |
| 179 | }, | |
| 180 | }), | |
| 181 | }); | |
| 182 | const text = await res.text(); | |
| 183 | expect(text).toContain(baseOid); | |
| 184 | }, 40_000); | |
| 185 | }); |
test/pull-mergeable.test.ts +1
| @@ -140,6 +140,7 @@ describe("a pull says whether it merges", () => { | ||
| 140 | 140 | const seen = await mcp("pull", { repo: "dev/app", number: 1 }); |
| 141 | 141 | expect(seen.mergeable).toBe(false); |
| 142 | 142 | expect(seen.conflicts).toEqual(["code.txt"]); |
| 143 | expect(seen.check).toMatchObject({ state: "none", baseOid: null }); | |
This only checks the empty case. Also add a case where the check has merged into the base, and assert |
||
| 143 | 144 | |
| 144 | 145 | // The base moves to hold the same line the pull wants. |
| 145 | 146 | await write("alpha\nBETA\ngamma\n", "the same edit"); |
test/tui-apps.test.ts +16 −1
| @@ -44,7 +44,7 @@ import { appendRunLog } from "../src/runs/log.ts"; | ||
| 44 | 44 | import type { App, Screen } from "../src/tui/app/app.ts"; |
| 45 | 45 | import { createForgeApp, forgeCommands } from "../src/tui/forge.ts"; |
| 46 | 46 | import { issueScreen } from "../src/tui/screens/issue.ts"; |
| 47 | import { pullScreen } from "../src/tui/screens/pull.ts"; | |
| 47 | import { checksText, pullScreen } from "../src/tui/screens/pull.ts"; | |
| 48 | 48 | import { local } from "../src/tui/screens/where.ts"; |
| 49 | 49 | import type { Session, TuiIdentity } from "../src/tui/session.ts"; |
| 50 | 50 | import { |
| @@ -496,3 +496,18 @@ describe("terminal: apps, runs and the crew", () => { | ||
| 496 | 496 | } |
| 497 | 497 | }, 30_000); |
| 498 | 498 | }); |
| 499 | ||
| 500 | describe("terminal: the check line names the base it checked", () => { | |
| 501 | const ran = (baseOid: string) => | |
| 502 | ({ | |
| 503 | state: "ok", | |
| 504 | run: { summary: "", baseOid, commitOid: "a".repeat(40) } as Run, | |
| 505 | }) as const; | |
| 506 | ||
| 507 | test("a merged check says checked on <base>@<oid>; a plain one says nothing of it", () => { | |
| 508 | expect(checksText(ran("b".repeat(40)), false, true, "main")).toBe( | |
| 509 | "checks: passed · checked on main@bbbbbbb", | |
| 510 | ); | |
| 511 | expect(checksText(ran(""), false, true, "main")).toBe("checks: passed"); | |
| 512 | }); | |
| 513 | }); |
new above
offline
No test renders this line. Add a page test where a pull's check has merged and assert the page shows
checked on main@<7 chars of baseOid>. The terminal's check line insrc/tui/screens/pull.ts(~1048–1080) also needs the same words.