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 #1636
scout/forge:scout/1585-a-check-run-records-the-base-tip-it-was → main 11 commits fork 6 threads · 6 unresolved
README.md +1 −1
| @@ -765,7 +765,7 @@ Invariants are proven by faults, not by hope. No dependencies were added. | ||
| 765 | 765 | |
| 766 | 766 | `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. |
| 767 | 767 | |
| 768 | 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. | |
| 768 | 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. | |
| 769 | 769 | |
| 770 | 770 | ## Limits |
| 771 | 771 |
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 | /** The variant group this run belongs to; null for an ordinary run. */ |
| 82 | 84 | readonly variantGroup: string | null; |
| 83 | 85 | readonly createdAt: string; |
| @@ -108,6 +110,7 @@ interface RunRow { | ||
| 108 | 110 | sandbox_enforced: number | null; |
| 109 | 111 | sandbox_note: string; |
| 110 | 112 | check_detail: string; |
| 113 | base_oid: string; | |
| 111 | 114 | variant_group: string | null; |
| 112 | 115 | created_at: string; |
| 113 | 116 | started_at: string | null; |
| @@ -137,6 +140,7 @@ const toRun = (r: RunRow): Run => ({ | ||
| 137 | 140 | r.sandbox_enforced === null ? null : r.sandbox_enforced !== 0, |
| 138 | 141 | sandboxNote: r.sandbox_note, |
| 139 | 142 | checkDetail: r.check_detail ? (JSON.parse(r.check_detail) as CheckDetail) : null, |
| 143 | baseOid: r.base_oid, | |
| 140 | 144 | variantGroup: r.variant_group, |
| 141 | 145 | createdAt: r.created_at, |
| 142 | 146 | startedAt: r.started_at, |
| @@ -342,13 +346,16 @@ export function noteRunProgress( | ||
| 342 | 346 | subscriptionId?: string | undefined; |
| 343 | 347 | /** Whether the shell is held to the sandbox, and why not when it is not. */ |
| 344 | 348 | sandbox?: { enforced: boolean; note: string } | undefined; |
| 349 | /** The base tip a pull's head was merged with for this check. */ | |
| 350 | baseOid?: string | undefined; | |
| 345 | 351 | }, |
| 346 | 352 | ): void { |
| 347 | 353 | db.query( |
| 348 | 354 | `UPDATE run SET session_id = COALESCE(?2, session_id), cost_usd = COALESCE(?3, cost_usd), |
| 349 | 355 | branch = COALESCE(?4, branch), subscription_id = COALESCE(?5, subscription_id), |
| 350 | 356 | sandbox_enforced = COALESCE(?6, sandbox_enforced), |
| 351 | sandbox_note = COALESCE(?7, sandbox_note) | |
| 357 | sandbox_note = COALESCE(?7, sandbox_note), | |
| 358 | base_oid = COALESCE(?8, base_oid) | |
| 352 | 359 | WHERE id = ?1`, |
| 353 | 360 | ).run( |
| 354 | 361 | runId, |
| @@ -358,6 +365,7 @@ export function noteRunProgress( | ||
| 358 | 365 | progress.subscriptionId ?? null, |
| 359 | 366 | progress.sandbox === undefined ? null : progress.sandbox.enforced ? 1 : 0, |
| 360 | 367 | progress.sandbox?.note.slice(0, 300) ?? null, |
| 368 | progress.baseOid ?? null, | |
| 361 | 369 | ); |
| 362 | 370 | } |
| 363 | 371 |
src/core/schema.ts +5
| @@ -1688,6 +1688,11 @@ export const migrations: readonly string[] = [ | ||
| 1688 | 1688 | CREATE TRIGGER thought_no_delete BEFORE DELETE ON thought |
| 1689 | 1689 | BEGIN SELECT RAISE(ABORT, 'a thought is never deleted'); END; |
| 1690 | 1690 | `, |
| 1691 | // 82 — the base tip a pull's check was merged with (#1585): empty for a run | |
| 1692 | // that merged nothing (a push to a branch) or that predates the record. | |
| 1693 | ` | |
| 1694 | ALTER TABLE run ADD COLUMN base_oid TEXT NOT NULL DEFAULT ''; | |
| 1695 | `, | |
| 1691 | 1696 | ]; |
| 1692 | 1697 | |
| 1693 | 1698 | /** |
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"; |
| @@ -415,7 +415,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 415 | 415 | { |
| 416 | 416 | name: "pull", |
| 417 | 417 | description: |
| 418 | "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.", | |
| 418 | "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. `check` is the same reading as GET /api/v1/repos/:owner/:name/pulls/:number/checks.", | |
| 419 | 419 | inputSchema: { |
| 420 | 420 | type: "object", |
| 421 | 421 | properties: { |
| @@ -439,12 +439,21 @@ const TOOLS: readonly Tool[] = [ | ||
| 439 | 439 | await pullDir(ctx.app.db, ctx.app.reposRoot, repo, pull), |
| 440 | 440 | pull, |
| 441 | 441 | ); |
outdated
No test covers this field. Please add an MCP
outdated
No test calls the MCP
outdated
|
||
| 442 | const latest = checksForHead(ctx.app.db, pull.id, pull.headOid)[0]; | |
| 442 | 443 | return good({ |
| 443 | 444 | number: pull.number, |
| 444 | 445 | title: pull.title, |
| 445 | 446 | state: pull.mergedAt !== null ? "merged" : pull.state, |
| 446 | 447 | base: pull.baseBranch, |
| 447 | 448 | head: pull.headBranch, |
| 449 | check: | |
| 450 | latest === undefined | |
| 451 | ? { state: "none" } | |
| 452 | : { | |
| 453 | state: latest.state, | |
| 454 | commit: latest.commitOid, | |
| 455 | baseOid: latest.baseOid, | |
| 456 | }, | |
| 448 | 457 | ...(state ?? {}), |
| 449 | 458 | }); |
| 450 | 459 | }, |
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}`; |
Same as on the page: on an app pull |
||
| 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
| @@ -213,6 +213,8 @@ export function checksLine( | ||
| 213 | 213 | again: Html | "" = "", |
| 214 | 214 | /** Files the pull conflicts in; a passing check is not a green mark then. */ |
| 215 | 215 | conflicts = 0, |
| 216 | /** The branch the pull lands on, named beside the base tip a check used. */ | |
| 217 | pullBase = "the base", | |
| 216 | 218 | ): Html { |
| 217 | 219 | if (!isApp && !required && check.state === "none" && !waiting && again === "") |
| 218 | 220 | return html``; |
| @@ -223,7 +225,14 @@ export function checksLine( | ||
| 223 | 225 | : html`<span class="where-sep" aria-hidden="true">·</span |
| 224 | 226 | ><a href="${base}/runs/${run.id}" |
| 225 | 227 | >deploy ${run.commitOid.slice(0, 7)}</a |
| 226 | >`; | |
| 228 | >${when( | |
|
||
| 229 | run.baseOid !== "", | |
| 230 | () => | |
| 231 | html`<span class="where-sep" aria-hidden="true">·</span | |
| 232 | ><span class="base-line" | |
Nit: no stylesheet defines |
||
| 233 | >checked against ${pullBase} at ${run.baseOid.slice(0, 7)}</span | |
| 234 | >`, | |
| 235 | )}`; | |
| 227 | 236 | const body = |
| 228 | 237 | check.state === "ok" && conflicts > 0 |
| 229 | 238 | ? html`<span class="bad" |
| @@ -327,6 +336,7 @@ function mergeBox( | ||
| 327 | 336 | </form>` |
| 328 | 337 | : "", |
| 329 | 338 | status.conflicts.length, |
| 339 | pull.baseBranch, | |
| 330 | 340 | ); |
| 331 | 341 | const reopen = html`<form method="post" action="${thread}/state"> |
| 332 | 342 | <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/mcp.test.ts +41 −1
| @@ -14,7 +14,8 @@ import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | ||
| 14 | 14 | import { createApp as insertApp } from "../src/core/apps.ts"; |
| 15 | 15 | import { listIssues } from "../src/core/issues.ts"; |
| 16 | 16 | import { getRepoById, type Repo } from "../src/core/repos.ts"; |
| 17 | import { createRun, listRuns } from "../src/core/runs.ts"; | |
| 17 | import { createRun, listRuns, noteRunProgress } from "../src/core/runs.ts"; | |
| 18 | import { openPull } from "../src/actions/pulls.ts"; | |
| 18 | 19 | import { createToken } from "../src/core/tokens.ts"; |
| 19 | 20 | import { createUser, type User } from "../src/core/users.ts"; |
| 20 | 21 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -330,6 +331,45 @@ describe("the forge over MCP", () => { | ||
| 330 | 331 | ).toContain("not_found"); |
| 331 | 332 | }); |
| 332 | 333 | |
| 334 | test("pull names the check of its head and the base tip it was merged with", async () => { | |
| 335 | const made = await createRepo(app, alice, { | |
| 336 | name: "tipped", | |
| 337 | visibility: "private", | |
| 338 | }); | |
| 339 | if (!made.ok) throw new Error(String(made.error)); | |
| 340 | const seed = await commitToBranch(app, alice, made.value, { | |
| 341 | message: "seed", | |
| 342 | files: [{ path: "README.md", content: "# tipped\n" }], | |
| 343 | }); | |
| 344 | if (!seed.ok) throw new Error(String(seed.error)); | |
| 345 | const branched = await commitToBranch(app, alice, made.value, { | |
| 346 | message: "feature", | |
| 347 | branch: "feature", | |
| 348 | files: [{ path: "f.txt", content: "f\n" }], | |
| 349 | }); | |
| 350 | if (!branched.ok) throw new Error(String(branched.error)); | |
| 351 | const opened = await openPull(app, alice, getRepoById(app.db, made.value.id)!, { | |
| 352 | title: "Feature", | |
| 353 | baseBranch: "main", | |
| 354 | headBranch: "feature", | |
| 355 | }); | |
| 356 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 357 | const pull = opened.value; | |
| 358 | const args = { repo: "alice/tipped", number: pull.number }; | |
| 359 | expect((await tool(rw, "pull", args)).value.check).toEqual({ state: "none" }); | |
| 360 | const run = createRun(app.db, { | |
| 361 | repoId: made.value.id, | |
| 362 | kind: "check", | |
| 363 | issueId: pull.id, | |
| 364 | commitOid: pull.headOid, | |
| 365 | reason: "pull", | |
| 366 | }); | |
| 367 | noteRunProgress(app.db, run.id, { baseOid: seed.value.commitOid }); | |
| 368 | const check = (await tool(rw, "pull", args)).value.check; | |
| 369 | expect(check.baseOid).toBe(seed.value.commitOid); | |
| 370 | expect(check.commit).toBe(pull.headOid); | |
| 371 | }); | |
| 372 | ||
| 333 | 373 | test("following, take_updates and converge are the fork's page", async () => { |
| 334 | 374 | const pub = await createRepo(app, alice, { |
| 335 | 375 | name: "open", |
test/tui-apps.test.ts +14
| @@ -41,6 +41,7 @@ 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"; | |
| 44 | 45 | import type { App, Screen } from "../src/tui/app/app.ts"; |
| 45 | 46 | import { createForgeApp, forgeCommands } from "../src/tui/forge.ts"; |
| 46 | 47 | import { issueScreen } from "../src/tui/screens/issue.ts"; |
| @@ -496,3 +497,16 @@ describe("terminal: apps, runs and the crew", () => { | ||
| 496 | 497 | } |
| 497 | 498 | }, 30_000); |
| 498 | 499 | }); |
| 500 | ||
| 501 | describe("checksText names the base a check was merged with", () => { | |
| 502 | const run = (baseOid: string) => | |
| 503 | ({ summary: "", baseOid, createdAt: "" }) as unknown as Run; | |
| 504 | test("a recorded base tip is named; none recorded says nothing of it", () => { | |
| 505 | expect( | |
| 506 | checksText({ state: "ok", run: run("abc1234def") }, false, true, "main"), | |
| 507 | ).toBe("checks: passed · checked against main at abc1234"); | |
| 508 | expect( | |
| 509 | checksText({ state: "failed", run: run("") }, false, true, "main"), | |
| 510 | ).toBe("checks: failed"); | |
| 511 | }); | |
| 512 | }); |
GET /api/v1/repos/:owner/:name/pulls/:numberdoes not returncheck; only/pulls/:number/checkscarriesbaseOid. Name that endpoint here, or addcheckto the REST pull reading.