Public: anyone can read this; the crew can change it.
A check run records the base tip it was merged with, and the pull page and MCP name it #1628
scout/forge:scout/1585-a-check-run-records-the-base-tip-it-was → main 3 commits fork 1 thread · 1 unresolved
9 files
changed +91
−8
README.md +1 −1
| @@ -710,7 +710,7 @@ Invariants are proven by faults, not by hope. No dependencies were added. | ||
| 710 | 710 | |
| 711 | 711 | `forge.json`'s `check` may declare `fast` beside `run` (the full gate; `full` names it explicitly). `bun scripts/test-shards.ts --tier fast --diff <base>..<head>` runs the tests that touch the diff (changed, named for a changed source file, or importing one within two hops), every test the times table records under 1 s, and any named by `--learned a,b`. `src/checks/tiers.ts` decides; it adds no dependency. |
| 712 | 712 | |
| 713 | In the forge itself: a pull's check runs `fast` when the manifest has one, in a clone holding the fork point and the head as `FORGE_CHECK_BASE` and `HEAD` (`origin/main` is not a ref there), with `FORGE_CHECK_LEARNED` naming tests earlier land attempts taught the pull (`src/checks/history.ts`, `learned.ts`). Landing (`landIfGreen`) runs `full` once on the merge with its base before merging (`src/checks/landing.ts`); red comments on the pull with the tests named, is remembered per head and base, and the files ride the pull's next fast run. The pull page's checks line shows the tier words. | |
| 713 | In the forge itself: a pull's check runs `fast` when the manifest has one, in a clone holding the fork point and the head as `FORGE_CHECK_BASE` and `HEAD` (`origin/main` is not a ref there), with `FORGE_CHECK_LEARNED` naming tests earlier land attempts taught the pull (`src/checks/history.ts`, `learned.ts`). Landing (`landIfGreen`) runs `full` once on the merge with its base before merging (`src/checks/landing.ts`); red comments on the pull with the tests named, is remembered per head and base, and the files ride the pull's next fast run. The pull page's checks line shows the tier words. A pull's check records the base tip its head was merged with (`run.base_oid`; empty for a push to a branch): the page and terminal checks lines say "checked against main at abc1234", and the API's check reading and MCP `pull` (`check.baseOid`) carry it. | |
| 714 | 714 | |
| 715 | 715 | ## Limits |
| 716 | 716 |
src/checks/service.ts +2
| @@ -491,6 +491,8 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle { | ||
| 491 | 491 | if (!merged.ok) return { ok: false, error: merged.error }; |
| 492 | 492 | source = merged.commit; |
| 493 | 493 | mergeLine = merged.line; |
| 494 | if (x.runId !== undefined) | |
| 495 | noteRunProgress(app.db, x.runId, { baseOid: tip }); | |
| 494 | 496 | } |
| 495 | 497 | const run = { id: x.id, commitOid: source }; |
| 496 | 498 | const [forgeJson, packageJson] = await Promise.all([ |
src/core/runs.ts +9 −1
| @@ -78,6 +78,8 @@ export interface Run { | ||
| 78 | 78 | readonly sandboxNote: string; |
| 79 | 79 | /** A failed check's own detail, when its output was recognised; null otherwise. */ |
| 80 | 80 | readonly checkDetail: CheckDetail | null; |
| 81 | /** For a pull's check: the base tip its head was merged with; empty otherwise. */ | |
| 82 | readonly baseOid: string; | |
| 81 | 83 | readonly createdAt: string; |
| 82 | 84 | readonly startedAt: string | null; |
| 83 | 85 | /** When this deploy's environment started serving — set once, at the swap-in. */ |
| @@ -106,6 +108,7 @@ interface RunRow { | ||
| 106 | 108 | sandbox_enforced: number | null; |
| 107 | 109 | sandbox_note: string; |
| 108 | 110 | check_detail: string; |
| 111 | base_oid: string; | |
| 109 | 112 | created_at: string; |
| 110 | 113 | started_at: string | null; |
| 111 | 114 | serving_at: string | null; |
| @@ -134,6 +137,7 @@ const toRun = (r: RunRow): Run => ({ | ||
| 134 | 137 | r.sandbox_enforced === null ? null : r.sandbox_enforced !== 0, |
| 135 | 138 | sandboxNote: r.sandbox_note, |
| 136 | 139 | checkDetail: r.check_detail ? (JSON.parse(r.check_detail) as CheckDetail) : null, |
| 140 | baseOid: r.base_oid, | |
| 137 | 141 | createdAt: r.created_at, |
| 138 | 142 | startedAt: r.started_at, |
| 139 | 143 | servingAt: r.serving_at, |
| @@ -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 head was merged with for this check. */ | |
| 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 |
src/core/schema.ts +5
| @@ -1631,6 +1631,11 @@ export const migrations: readonly string[] = [ | ||
| 1631 | 1631 | scopes TEXT NOT NULL |
| 1632 | 1632 | ); |
| 1633 | 1633 | `, |
| 1634 | // 78 — the base tip a pull's check was merged with (#1585): empty for a run | |
| 1635 | // that merged nothing (a push to a branch) or that predates the record. | |
| 1636 | ` | |
| 1637 | ALTER TABLE run ADD COLUMN base_oid TEXT NOT NULL DEFAULT ''; | |
| 1638 | `, | |
| 1634 | 1639 | ]; |
| 1635 | 1640 | |
| 1636 | 1641 | /** |
src/http/mcp.ts +11 −2
| @@ -84,7 +84,7 @@ import { | ||
| 84 | 84 | type Repo, |
| 85 | 85 | } from "../core/repos.ts"; |
| 86 | 86 | import { plannerDeclines } from "../crew/autonomy.ts"; |
| 87 | import { listActiveRuns } from "../core/runs.ts"; | |
| 87 | import { checksForHead, listActiveRuns } from "../core/runs.ts"; | |
| 88 | 88 | import { scopeAllows } from "../core/tokens.ts"; |
| 89 | 89 | import { getUsersByIds, type User } from "../core/users.ts"; |
| 90 | 90 | import { openapi } from "../contract/openapi.ts"; |
| @@ -414,7 +414,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 414 | 414 | { |
| 415 | 415 | name: "pull", |
| 416 | 416 | description: |
| 417 | "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.", | |
| 417 | "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 `check`, the latest check of its head with the `baseOid` it was merged with. The same fields as GET /api/v1/repos/:owner/:name/pulls/:number.", | |
| 418 | 418 | inputSchema: { |
| 419 | 419 | type: "object", |
| 420 | 420 | properties: { |
| @@ -438,12 +438,21 @@ const TOOLS: readonly Tool[] = [ | ||
| 438 | 438 | await pullDir(ctx.app.db, ctx.app.reposRoot, repo, pull), |
| 439 | 439 | pull, |
| 440 | 440 | ); |
| 441 | const latest = checksForHead(ctx.app.db, pull.id, pull.headOid)[0]; | |
| 441 | 442 | return good({ |
| 442 | 443 | number: pull.number, |
| 443 | 444 | title: pull.title, |
| 444 | 445 | state: pull.mergedAt !== null ? "merged" : pull.state, |
| 445 | 446 | base: pull.baseBranch, |
| 446 | 447 | head: pull.headBranch, |
| 448 | check: | |
| 449 | latest === undefined | |
| 450 | ? { state: "none" } | |
| 451 | : { | |
| 452 | state: latest.state, | |
| 453 | commit: latest.commitOid, | |
| 454 | baseOid: latest.baseOid, | |
| 455 | }, | |
| 447 | 456 | ...(state ?? {}), |
| 448 | 457 | }); |
| 449 | 458 | }, |
src/tui/screens/pull.ts +9 −3
| @@ -683,7 +683,7 @@ export function pullScreen( | ||
| 683 | 683 | // The box is exactly as tall as what is in it: the state, then a row |
| 684 | 684 | // for the verdicts when there are any, then a row for the checks when |
| 685 | 685 | // a deploy has run or the gate demands one. |
| 686 | const checksLine = checksText(check, requireChecks, isApp); | |
| 686 | const checksLine = checksText(check, requireChecks, isApp, facts?.baseBranch); | |
| 687 | 687 | const boxH = |
| 688 | 688 | 3 + |
| 689 | 689 | (standingText(standing(), requireReview) === "" ? 0 : 1) + |
| @@ -1088,6 +1088,8 @@ export function checksText( | ||
| 1088 | 1088 | check: CheckSummary, |
| 1089 | 1089 | required: boolean, |
| 1090 | 1090 | isApp: boolean, |
| 1091 | /** The branch the pull lands on, named beside the base tip a check used. */ | |
| 1092 | baseBranch = "the base", | |
| 1091 | 1093 | ): string { |
| 1092 | 1094 | if (check.state === "none") |
| 1093 | 1095 | return required |
| @@ -1097,11 +1099,15 @@ export function checksText( | ||
| 1097 | 1099 | : ""; |
| 1098 | 1100 | const run = check.run; |
| 1099 | 1101 | const summary = run === null || run.summary === "" ? "" : ` · ${run.summary}`; |
| 1102 | const base = | |
| 1103 | run === null || run.baseOid === "" | |
| 1104 | ? "" | |
| 1105 | : ` · checked against ${baseBranch} at ${run.baseOid.slice(0, 7)}`; | |
| 1100 | 1106 | switch (check.state) { |
| 1101 | 1107 | case "ok": |
| 1102 | return `checks: passed${summary}`; | |
| 1108 | return `checks: passed${summary}${base}`; | |
| 1103 | 1109 | case "failed": |
| 1104 | return `checks: failed${summary}`; | |
| 1110 | return `checks: failed${summary}${base}`; | |
| 1105 | 1111 | case "running": |
| 1106 | 1112 | return "checks: deploying this head"; |
| 1107 | 1113 | case "queued": |
src/web/pages/pull.ts +11 −1
| @@ -211,6 +211,8 @@ function checksLine( | ||
| 211 | 211 | tier = "", |
| 212 | 212 | /** A writer's button to ask for a check again; empty for anyone else. */ |
| 213 | 213 | again: Html | "" = "", |
| 214 | /** The branch the pull lands on, named beside the base tip a check used. */ | |
| 215 | pullBase = "the base", | |
| 214 | 216 | ): Html { |
| 215 | 217 | if (!isApp && !required && check.state === "none" && !waiting && again === "") |
| 216 | 218 | return html``; |
| @@ -221,7 +223,14 @@ function checksLine( | ||
| 221 | 223 | : html`<span class="where-sep" aria-hidden="true">·</span |
| 222 | 224 | ><a href="${base}/runs/${run.id}" |
| 223 | 225 | >deploy ${run.commitOid.slice(0, 7)}</a |
| 224 | >`; | |
| 226 | >${when( | |
| 227 | run.baseOid !== "", | |
| 228 | () => | |
| 229 | html`<span class="where-sep" aria-hidden="true">·</span | |
| 230 | ><span class="base-line" | |
| 231 | >checked against ${pullBase} at ${run.baseOid.slice(0, 7)}</span | |
| 232 | >`, | |
| 233 | )}`; | |
| 225 | 234 | const body = |
| 226 | 235 | check.state === "ok" |
| 227 | 236 | ? html`<span class="ok">${icon("check")}Checks passed</span>${link}` |
| @@ -320,6 +329,7 @@ function mergeBox( | ||
| 320 | 329 | ${btn("Check again", { size: "sm", icon: "loader" })} |
| 321 | 330 | </form>` |
| 322 | 331 | : "", |
| 332 | pull.baseBranch, | |
| 323 | 333 | ); |
| 324 | 334 | const reopen = html`<form method="post" action="${thread}/state"> |
| 325 | 335 | <input type="hidden" name="state" value="open" /> |
test/checks.test.ts +28
| @@ -381,6 +381,34 @@ describe("checks", () => { | ||
| 381 | 381 | // `test -f` is not `bun test`: its output is not this shape, so nothing |
| 382 | 382 | // is guessed at it. |
| 383 | 383 | expect(failed.checkDetail).toBeNull(); |
| 384 | // The run records the base tip its head was merged with; a push to the | |
| 385 | // default branch merged nothing, so records none. | |
| 386 | expect(failed.baseOid).toBe(gate.value.commitOid); | |
| 387 | const onMain = listRuns(app.db, repo.id, { kind: "check" }).find( | |
| 388 | (r) => r.commitOid === gate.value.commitOid, | |
| 389 | ); | |
| 390 | expect(onMain?.baseOid).toBe(""); | |
| 391 | const signedIn = await fetch(`${servers.url}/signin`, { | |
| 392 | method: "POST", | |
| 393 | body: new URLSearchParams({ | |
| 394 | username: "alice", | |
| 395 | password: "a-good-passphrase", | |
| 396 | }), | |
| 397 | redirect: "manual", | |
| 398 | }); | |
| 399 | const cookie = (signedIn.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 400 | const page = await ( | |
| 401 | await fetch(`${servers.url}/alice/lib/pulls/${pull.number}/files`, { | |
| 402 | headers: { cookie }, | |
| 403 | }) | |
| 404 | ).text(); | |
| 405 | expect(page).toContain( | |
| 406 | `checked against main at ${gate.value.commitOid.slice(0, 7)}`, | |
| 407 | ); | |
| 408 | const api = (await ( | |
| 409 | await fetch(`${servers.url}/api/v1/repos/alice/lib/pulls/${pull.number}/checks`) | |
| 410 | ).json()) as { run: { baseOid: string } }; | |
| 411 | expect(api.run.baseOid).toBe(gate.value.commitOid); | |
| 384 | 412 | expect( |
| 385 | 413 | checksForHead(app.db, pull.id, branched.value.commitOid)[0]?.id, |
| 386 | 414 | ).toBe(failed.id); |
test/tui-apps.test.ts +15
| @@ -41,6 +41,8 @@ import { createUser, getUserByName, type User } from "../src/core/users.ts"; | ||
| 41 | 41 | import { serve, type Servers } from "../src/http/server.ts"; |
| 42 | 42 | import { quietLogs } from "./helpers/globals.ts"; |
| 43 | 43 | import { appendRunLog } from "../src/runs/log.ts"; |
| 44 | import { checksText } from "../src/tui/screens/pull.ts"; | |
| 45 | import type { Run } from "../src/core/runs.ts"; | |
| 44 | 46 | import type { App, Screen } from "../src/tui/app/app.ts"; |
| 45 | 47 | import { createForgeApp, forgeCommands } from "../src/tui/forge.ts"; |
| 46 | 48 | import { issueScreen } from "../src/tui/screens/issue.ts"; |
| @@ -496,3 +498,16 @@ describe("terminal: apps, runs and the crew", () => { | ||
| 496 | 498 | } |
| 497 | 499 | }, 30_000); |
| 498 | 500 | }); |
| 501 | ||
| 502 | describe("checksText names the base a check was merged with", () => { | |
| 503 | const run = (baseOid: string) => | |
| 504 | ({ summary: "", baseOid, createdAt: "" }) as unknown as Run; | |
| 505 | test("a recorded base tip is named; none recorded says nothing of it", () => { | |
| 506 | expect( | |
| 507 | checksText({ state: "ok", run: run("abc1234def") }, false, true, "main"), | |
| 508 | ).toBe("checks: passed · checked against main at abc1234"); | |
| 509 | expect( | |
| 510 | checksText({ state: "failed", run: run("") }, false, true, "main"), | |
| 511 | ).toBe("checks: failed"); | |
| 512 | }); | |
| 513 | }); |
new above
offline
Good on the page. The terminal's
checksText(src/tui/screens/pull.ts) needs the same clause so both doors say which base was checked.