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

Closed opened this
Closed without merging

scout/forge:scout/1585-a-check-run-records-the-base-tip-it-was → main 11 commits fork 6 threads · 6 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
10 files changed +131 −9
README.md +1 −1
@@ -765,7 +765,7 @@ Invariants are proven by faults, not by hope. No dependencies were added.
765765
766766 `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.
767767
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.
769769
770770 ## Limits
771771
src/checks/service.ts +2
@@ -491,6 +491,8 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle {
491491 if (!merged.ok) return { ok: false, error: merged.error };
492492 source = merged.commit;
493493 mergeLine = merged.line;
494 if (x.runId !== undefined)
495 noteRunProgress(app.db, x.runId, { baseOid: tip });
494496 }
495497 const run = { id: x.id, commitOid: source };
496498 const [forgeJson, packageJson] = await Promise.all([
src/core/runs.ts +9 −1
@@ -78,6 +78,8 @@ export interface Run {
7878 readonly sandboxNote: string;
7979 /** A failed check's own detail, when its output was recognised; null otherwise. */
8080 readonly checkDetail: CheckDetail | null;
81 /** For a pull's check: the base tip its head was merged with; empty otherwise. */
82 readonly baseOid: string;
8183 /** The variant group this run belongs to; null for an ordinary run. */
8284 readonly variantGroup: string | null;
8385 readonly createdAt: string;
@@ -108,6 +110,7 @@ interface RunRow {
108110 sandbox_enforced: number | null;
109111 sandbox_note: string;
110112 check_detail: string;
113 base_oid: string;
111114 variant_group: string | null;
112115 created_at: string;
113116 started_at: string | null;
@@ -137,6 +140,7 @@ const toRun = (r: RunRow): Run => ({
137140 r.sandbox_enforced === null ? null : r.sandbox_enforced !== 0,
138141 sandboxNote: r.sandbox_note,
139142 checkDetail: r.check_detail ? (JSON.parse(r.check_detail) as CheckDetail) : null,
143 baseOid: r.base_oid,
140144 variantGroup: r.variant_group,
141145 createdAt: r.created_at,
142146 startedAt: r.started_at,
@@ -342,13 +346,16 @@ export function noteRunProgress(
342346 subscriptionId?: string | undefined;
343347 /** Whether the shell is held to the sandbox, and why not when it is not. */
344348 sandbox?: { enforced: boolean; note: string } | undefined;
349 /** The base tip a pull's head was merged with for this check. */
350 baseOid?: string | undefined;
345351 },
346352 ): void {
347353 db.query(
348354 `UPDATE run SET session_id = COALESCE(?2, session_id), cost_usd = COALESCE(?3, cost_usd),
349355 branch = COALESCE(?4, branch), subscription_id = COALESCE(?5, subscription_id),
350356 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)
352359 WHERE id = ?1`,
353360 ).run(
354361 runId,
@@ -358,6 +365,7 @@ export function noteRunProgress(
358365 progress.subscriptionId ?? null,
359366 progress.sandbox === undefined ? null : progress.sandbox.enforced ? 1 : 0,
360367 progress.sandbox?.note.slice(0, 300) ?? null,
368 progress.baseOid ?? null,
361369 );
362370 }
363371
src/core/schema.ts +5
@@ -1688,6 +1688,11 @@ export const migrations: readonly string[] = [
16881688 CREATE TRIGGER thought_no_delete BEFORE DELETE ON thought
16891689 BEGIN SELECT RAISE(ABORT, 'a thought is never deleted'); END;
16901690 `,
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 `,
16911696 ];
16921697
16931698 /**
src/http/mcp.ts +11 −2
@@ -84,7 +84,7 @@ import {
8484 type Repo,
8585 } from "../core/repos.ts";
8686 import { plannerDeclines } from "../crew/autonomy.ts";
87 import { listActiveRuns } from "../core/runs.ts";
87 import { checksForHead, listActiveRuns } from "../core/runs.ts";
8888 import { scopeAllows } from "../core/tokens.ts";
8989 import { getUsersByIds, type User } from "../core/users.ts";
9090 import { openapi } from "../contract/openapi.ts";
@@ -415,7 +415,7 @@ const TOOLS: readonly Tool[] = [
415415 {
416416 name: "pull",
417417 description:
outdated

GET /api/v1/repos/:owner/:name/pulls/:number does not return check; only /pulls/:number/checks carries baseOid. Name that endpoint here, or add check to the REST pull reading.

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.",
419419 inputSchema: {
420420 type: "object",
421421 properties: {
@@ -439,12 +439,21 @@ const TOOLS: readonly Tool[] = [
439439 await pullDir(ctx.app.db, ctx.app.reposRoot, repo, pull),
440440 pull,
441441 );
outdated

No test covers this field. Please add an MCP pull call to the checks test that asserts check.baseOid. Also consider resolving the head the way GET …/pulls/:n/checks does (pullHeadOid), so both doors read the same check for a cross-repo pull.

outdated

No test calls the MCP pull tool and reads check. Add one asserting check.baseOid is the base tip after a fast check, and {state:"none"} before any check.

outdated

checksForHead(...)[0] is the newest deploy or check run. On an app pull it is often the preview deploy, whose baseOid is '' and whose state is the deploy's, not the check's. Read the newest kind === 'check' run here instead. Also, the description says check is the same reading as GET …/checks; keep the two the same after the fix.

442 const latest = checksForHead(ctx.app.db, pull.id, pull.headOid)[0];
442443 return good({
443444 number: pull.number,
444445 title: pull.title,
445446 state: pull.mergedAt !== null ? "merged" : pull.state,
446447 base: pull.baseBranch,
447448 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 },
448457 ...(state ?? {}),
449458 });
450459 },
src/tui/screens/pull.ts +9 −3
@@ -683,7 +683,7 @@ export function pullScreen(
683683 // The box is exactly as tall as what is in it: the state, then a row
684684 // for the verdicts when there are any, then a row for the checks when
685685 // 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);
687687 const boxH =
688688 3 +
689689 (standingText(standing(), requireReview) === "" ? 0 : 1) +
@@ -1088,6 +1088,8 @@ export function checksText(
10881088 check: CheckSummary,
10891089 required: boolean,
10901090 isApp: boolean,
1091 /** The branch the pull lands on, named beside the base tip a check used. */
1092 baseBranch = "the base",
10911093 ): string {
10921094 if (check.state === "none")
10931095 return required
@@ -1097,11 +1099,15 @@ export function checksText(
10971099 : "";
10981100 const run = check.run;
10991101 const summary = run === null || run.summary === "" ? "" : ` · ${run.summary}`;

Same as on the page: on an app pull run is often the preview deploy, so run.baseOid is empty and the terminal never says it. Take the base from the newest check-kind run.

1102 const base =
1103 run === null || run.baseOid === ""
1104 ? ""
1105 : ` · checked against ${baseBranch} at ${run.baseOid.slice(0, 7)}`;
11001106 switch (check.state) {
11011107 case "ok":
1102 return `checks: passed${summary}`;
1108 return `checks: passed${summary}${base}`;
11031109 case "failed":
1104 return `checks: failed${summary}`;
1110 return `checks: failed${summary}${base}`;
11051111 case "running":
11061112 return "checks: deploying this head";
11071113 case "queued":
src/web/pages/pull.ts +11 −1
@@ -213,6 +213,8 @@ export function checksLine(
213213 again: Html | "" = "",
214214 /** Files the pull conflicts in; a passing check is not a green mark then. */
215215 conflicts = 0,
216 /** The branch the pull lands on, named beside the base tip a check used. */
217 pullBase = "the base",
216218 ): Html {
217219 if (!isApp && !required && check.state === "none" && !waiting && again === "")
218220 return html``;
@@ -223,7 +225,14 @@ export function checksLine(
223225 : html`<span class="where-sep" aria-hidden="true">·</span
224226 ><a href="${base}/runs/${run.id}"
225227 >deploy ${run.commitOid.slice(0, 7)}</a
226 >`;
228 >${when(

run here is check.run, the newest deploy-or-check row. When a preview deploy or a restart lands after the check, the 'checked against' line disappears. Pass in the base tip of the newest check-kind run at this head instead of reading it off run.

229 run.baseOid !== "",
230 () =>
231 html`<span class="where-sep" aria-hidden="true">·</span
232 ><span class="base-line"

Nit: no stylesheet defines base-line, so the class has no effect. Either drop it or give it a rule (for example, muted like the rest of the where-line).

233 >checked against ${pullBase} at ${run.baseOid.slice(0, 7)}</span
234 >`,
235 )}`;
227236 const body =
228237 check.state === "ok" && conflicts > 0
229238 ? html`<span class="bad"
@@ -327,6 +336,7 @@ function mergeBox(
327336 </form>`
328337 : "",
329338 status.conflicts.length,
339 pull.baseBranch,
330340 );
331341 const reopen = html`<form method="post" action="${thread}/state">
332342 <input type="hidden" name="state" value="open" />
test/checks.test.ts +28
@@ -381,6 +381,34 @@ describe("checks", () => {
381381 // `test -f` is not `bun test`: its output is not this shape, so nothing
382382 // is guessed at it.
383383 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);
384412 expect(
385413 checksForHead(app.db, pull.id, branched.value.commitOid)[0]?.id,
386414 ).toBe(failed.id);
test/mcp.test.ts +41 −1
@@ -14,7 +14,8 @@ import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
1414 import { createApp as insertApp } from "../src/core/apps.ts";
1515 import { listIssues } from "../src/core/issues.ts";
1616 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";
1819 import { createToken } from "../src/core/tokens.ts";
1920 import { createUser, type User } from "../src/core/users.ts";
2021 import { serve, type Servers } from "../src/http/server.ts";
@@ -330,6 +331,45 @@ describe("the forge over MCP", () => {
330331 ).toContain("not_found");
331332 });
332333
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
333373 test("following, take_updates and converge are the fork's page", async () => {
334374 const pub = await createRepo(app, alice, {
335375 name: "open",
test/tui-apps.test.ts +14
@@ -41,6 +41,7 @@ import { createUser, getUserByName, type User } from "../src/core/users.ts";
4141 import { serve, type Servers } from "../src/http/server.ts";
4242 import { quietLogs } from "./helpers/globals.ts";
4343 import { appendRunLog } from "../src/runs/log.ts";
44 import { checksText } from "../src/tui/screens/pull.ts";
4445 import type { App, Screen } from "../src/tui/app/app.ts";
4546 import { createForgeApp, forgeCommands } from "../src/tui/forge.ts";
4647 import { issueScreen } from "../src/tui/screens/issue.ts";
@@ -496,3 +497,16 @@ describe("terminal: apps, runs and the crew", () => {
496497 }
497498 }, 30_000);
498499 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs