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

Closed opened this
Closed without merging

scout/forge:scout/1585-a-check-run-records-the-base-tip-it-was → main 3 commits fork 1 thread · 1 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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.
710710
711711 `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.
712712
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.
714714
715715 ## Limits
716716
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 readonly createdAt: string;
8284 readonly startedAt: string | null;
8385 /** When this deploy's environment started serving — set once, at the swap-in. */
@@ -106,6 +108,7 @@ interface RunRow {
106108 sandbox_enforced: number | null;
107109 sandbox_note: string;
108110 check_detail: string;
111 base_oid: string;
109112 created_at: string;
110113 started_at: string | null;
111114 serving_at: string | null;
@@ -134,6 +137,7 @@ const toRun = (r: RunRow): Run => ({
134137 r.sandbox_enforced === null ? null : r.sandbox_enforced !== 0,
135138 sandboxNote: r.sandbox_note,
136139 checkDetail: r.check_detail ? (JSON.parse(r.check_detail) as CheckDetail) : null,
140 baseOid: r.base_oid,
137141 createdAt: r.created_at,
138142 startedAt: r.started_at,
139143 servingAt: r.serving_at,
@@ -335,13 +339,16 @@ export function noteRunProgress(
335339 subscriptionId?: string | undefined;
336340 /** Whether the shell is held to the sandbox, and why not when it is not. */
337341 sandbox?: { enforced: boolean; note: string } | undefined;
342 /** The base tip a pull's head was merged with for this check. */
343 baseOid?: string | undefined;
338344 },
339345 ): void {
340346 db.query(
341347 `UPDATE run SET session_id = COALESCE(?2, session_id), cost_usd = COALESCE(?3, cost_usd),
342348 branch = COALESCE(?4, branch), subscription_id = COALESCE(?5, subscription_id),
343349 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)
345352 WHERE id = ?1`,
346353 ).run(
347354 runId,
@@ -351,6 +358,7 @@ export function noteRunProgress(
351358 progress.subscriptionId ?? null,
352359 progress.sandbox === undefined ? null : progress.sandbox.enforced ? 1 : 0,
353360 progress.sandbox?.note.slice(0, 300) ?? null,
361 progress.baseOid ?? null,
354362 );
355363 }
356364
src/core/schema.ts +5
@@ -1631,6 +1631,11 @@ export const migrations: readonly string[] = [
16311631 scopes TEXT NOT NULL
16321632 );
16331633 `,
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 `,
16341639 ];
16351640
16361641 /**
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";
@@ -414,7 +414,7 @@ const TOOLS: readonly Tool[] = [
414414 {
415415 name: "pull",
416416 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.",
418418 inputSchema: {
419419 type: "object",
420420 properties: {
@@ -438,12 +438,21 @@ const TOOLS: readonly Tool[] = [
438438 await pullDir(ctx.app.db, ctx.app.reposRoot, repo, pull),
439439 pull,
440440 );
441 const latest = checksForHead(ctx.app.db, pull.id, pull.headOid)[0];
441442 return good({
442443 number: pull.number,
443444 title: pull.title,
444445 state: pull.mergedAt !== null ? "merged" : pull.state,
445446 base: pull.baseBranch,
446447 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 },
447456 ...(state ?? {}),
448457 });
449458 },
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}`;
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
@@ -211,6 +211,8 @@ function checksLine(
211211 tier = "",
212212 /** A writer's button to ask for a check again; empty for anyone else. */
213213 again: Html | "" = "",
214 /** The branch the pull lands on, named beside the base tip a check used. */
215 pullBase = "the base",
214216 ): Html {
215217 if (!isApp && !required && check.state === "none" && !waiting && again === "")
216218 return html``;
@@ -221,7 +223,14 @@ function checksLine(
221223 : html`<span class="where-sep" aria-hidden="true">·</span
222224 ><a href="${base}/runs/${run.id}"
223225 >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

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.

232 >`,
233 )}`;
225234 const body =
226235 check.state === "ok"
227236 ? html`<span class="ok">${icon("check")}Checks passed</span>${link}`
@@ -320,6 +329,7 @@ function mergeBox(
320329 ${btn("Check again", { size: "sm", icon: "loader" })}
321330 </form>`
322331 : "",
332 pull.baseBranch,
323333 );
324334 const reopen = html`<form method="post" action="${thread}/state">
325335 <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/tui-apps.test.ts +15
@@ -41,6 +41,8 @@ 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";
45 import type { Run } from "../src/core/runs.ts";
4446 import type { App, Screen } from "../src/tui/app/app.ts";
4547 import { createForgeApp, forgeCommands } from "../src/tui/forge.ts";
4648 import { issueScreen } from "../src/tui/screens/issue.ts";
@@ -496,3 +498,16 @@ describe("terminal: apps, runs and the crew", () => {
496498 }
497499 }, 30_000);
498500 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs