Public: anyone can read this; the crew can change it.

A child forge's proposal carries its own check verdict and tree id, and the parent's pull shows them beside its own check #13676

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13645-a-child-forge-s-proposal-carries-its-own → main 11 commits fork 5 threads · 5 unresolved

  • Merged. scout/13645-a-child-forge-s-proposal-carries-its-own was merged into main as 0d7ce2b.

Review

Sign in to review this change.
20 files changed +351 −30
docs/features/README.md +1
@@ -385,6 +385,7 @@ Read with the guide page [Bring your own AI](../guide-own-ai.md).
385385 - [A child forge's cell may reach its model provider](child-model-egress.md)
386386 - [A forge with no model key](no-model-key.md)
387387 - [A parent funds a child's crew](child-credit.md)
388 - [A child's proposal says what the child proved](child-attestation.md)
388389 - [An org's model account](org-model-grant.md)
389390 - [Cost ledger](cost-ledger.md)
390391 - [Cost by day](cost-days.md)
docs/features/child-attestation.md added +13
@@ -0,0 +1,13 @@
1 # A child's proposal says what the child proved
2
3 When a child forge proposes a change to its parent, it also sends what its own check found on that commit (#13645). The parent shows this beside its own check. It never decides anything on it.
4
5 1. **On the child**, land a change on main and press **Propose**. The proposal (`src/actions/upstream.ts`) sends `attestation: { verdict, tree }`. The verdict is the child's own check of the tip (`green`, `red`, `pending` or `none`) and the tree is the tip's tree id.
6 2. **On the parent**, open the pull, on either tab. After *proposed by child* it reads `proven on <child>: green at 1a2b3c4d`. In the terminal, the pull screen's head line has the same line after *proposed by child*.
7 3. If the pull's head tree is not the tree the child proved, the line ends `· tree differs`. That happens when someone pushed on top of the proposal or main was combined into it. In that case the child's verdict is about a different tree.
8
9 The boundary (`src/http/api.ts`, `parseAttestation` in `src/core/attestation.ts`) accepts only a verdict from that set and a 40- or 64-character lowercase hex tree id. Anything else is refused with `422 invalid_attestation`. Only a proposal may carry one. The API's pull answer echoes it under `proposal.attestation`.
10
11 Every view reads it with `pullProposalAt` (`src/core/proposal_token.ts`): the page head (`changeHead`), the conflicts page and the terminal's local source. It reads the head's tree only when the child attested one. Nothing gates or ranks on the child's verdict. The parent's own check is still the one that lands a pull.
outdated

Medium. Both doors: the terminal's pull screen should show this line. A 'Not yet' gap fails the both-doors rule. Add it under src/tui/ with the pull screen's entry as AGENTS.md says.

12
13 Test: `test/attestation.test.ts` (the verdict mapping and the line), `test/proposal-token.test.ts` (accepted, refused, shown on both tabs and in the terminal, tree differs) and `test/upstream-forge.test.ts` (the child sends `none` with no check, and `green` when its check of the tip passed).
src/actions/upstream.ts +12 −1
@@ -16,7 +16,9 @@ import {
1616 } from "../core/repos.ts";
1717 import { listPulls, mergedPullsForRepos, type Pull } from "../core/pulls.ts";
1818 import type { User } from "../core/users.ts";
19 import { aheadOids, resolveOid } from "../git/merge.ts";
19 import { aheadOids, resolveOid, treeOf } from "../git/merge.ts";
20 import { commitCheck } from "../checks/commit_check.ts";
21 import { verdictOfCheck, type Attestation } from "../core/attestation.ts";
2022 import { repoDir } from "../git/repos.ts";
2123 import { basicHeader, gitAuthEnv, redact, secretsIn } from "../origins/credentials.ts";
2224 import { MIRROR_UNRESOLVED, pushToOrigin } from "../origins/git-mirror.ts";
@@ -253,6 +255,14 @@ export async function proposeToParentForge(
253255 : { kind: "refused", reason: reason.slice(0, 200) });
254256 }
255257
258 // What this forge proved of the tip it proposes (#13645): its own check's verdict on it and
259 // its tree id. The parent shows it beside its own check and decides nothing on it.
260 const tree = await treeOf(dir, tip);
261 const attestation: Attestation | undefined =
262 tree === undefined
263 ? undefined
264 : { verdict: verdictOfCheck(commitCheck(app.db, repo.id, repo.defaultBranch, tip).state), tree };
265
256266 let res: Response;
257267 try {
258268 res = await fetch(apiUrl(cred, ""), {
@@ -264,6 +274,7 @@ export async function proposeToParentForge(
264274 body: `Proposed by child ${cred.child}${here === "" ? "" : ` (${here})`}: ${source}.`,
265275 base: repo.defaultBranch,
266276 head,
277 ...(attestation === undefined ? {} : { attestation }),
267278 }),
268279 signal: AbortSignal.timeout(ASK_TIMEOUT_MS),
269280 });
src/contract/openapi/routes/postApiV1ReposOwnerNamePulls.ts +1 −1
@@ -6,5 +6,5 @@ export const route: Route = {
66 summary: "Offer a change as a pull",
77 auth: true,
88 role: "member",
9 body: { title: "string", head: "string", headRepo: "string" },
9 body: { title: "string", head: "string", headRepo: "string", attestation: "object" },
1010 };
src/core/attestation.ts added +48
@@ -0,0 +1,48 @@
1 /**
2 * What a child forge says of the commit it proposes: its own check's verdict
3 * on that commit and the commit's tree id (#13645). Information only: the
4 * parent's gate still runs on the pull, and nothing here admits or lands
5 * anything. It is read from the proposal's body at the boundary — a verdict
6 * from a fixed set and a hex tree id, or nothing — and said beside the pull
7 * as one line, with `tree differs` when the pull's head is not the tree the
8 * child proved.
9 */
10
11 export type AttestedVerdict = "green" | "red" | "pending" | "none";
12
13 export interface Attestation {
14 readonly verdict: AttestedVerdict;
15 readonly tree: string;
16 }
17
18 const VERDICTS: readonly AttestedVerdict[] = ["green", "red", "pending", "none"];
19
20 /** A tree id: SHA-1 or SHA-256 hex, lowercase. */
21 export const isTreeId = (s: string): boolean => /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(s);
22
23 /**
24 * The attestation in a proposal's body. `undefined` when none was sent;
25 * `"invalid"` when one was sent but is not a verdict and a tree id.
26 */
27 export function parseAttestation(raw: unknown): Attestation | undefined | "invalid" {
28 if (raw === undefined || raw === null) return undefined;
29 if (typeof raw !== "object" || Array.isArray(raw)) return "invalid";
30 const { verdict, tree } = raw as { verdict?: unknown; tree?: unknown };
31 if (typeof verdict !== "string" || !VERDICTS.includes(verdict as AttestedVerdict)) return "invalid";
32 if (typeof tree !== "string" || !isTreeId(tree)) return "invalid";
33 return { verdict: verdict as AttestedVerdict, tree };
34 }
35
36 /** A child's own check state of a commit, in the words it attests with. */
37 export const verdictOfCheck = (state: string): AttestedVerdict =>

Medium. Tests: this mapping is untested. Add a unit test for ok, failed, pending and anything else (superseded) to none. The behaviour is the child's verdict, and no test fails if it is wrong.

38 state === "ok" ? "green" : state === "failed" ? "red" : state === "pending" ? "pending" : "none";
39
40 /** Whether the pull's head tree is not the one the child proved. */
41 export const treeDiffers = (a: Attestation, headTree: string | undefined): boolean =>
42 headTree !== a.tree;
43
44 /**
45 * The one line the pull says: `proven on kid: green at 1a2b3c4d`, `· tree differs` when it does.
46 */
47 export const attestationLine = (child: string, a: Attestation, headTree: string | undefined): string =>
48 `proven on ${child}: ${a.verdict} at ${a.tree.slice(0, 8)}${treeDiffers(a, headTree) ? " · tree differs" : ""}`;
src/core/migration-pins/20261115150000-pull-proposal-attestation.pin added +1
@@ -0,0 +1,1 @@
1 8d03f37f56a9a1cd0e239eba14ed407181132788fb74815fb0084cf40a89a127
src/core/migrations/20261115150000-pull-proposal-attestation.ts added +7
@@ -0,0 +1,7 @@
1 // A child forge's proposal carries what it proved (#13645): its own check's verdict on the
2 // proposed commit and that commit's tree id, kept beside the pull's child and origin. Both
3 // NULL for a proposal that sent none. Information only; nothing admits on them. Additive.
4 export default `
5 ALTER TABLE pull_proposal ADD COLUMN attested_verdict TEXT;
6 ALTER TABLE pull_proposal ADD COLUMN attested_tree TEXT;
7 `;
src/core/proposal_token.ts +42 −6
@@ -7,8 +7,10 @@
77 * the data and the rules about names; it decides nothing about requests.
88 */
99
10 import { parseAttestation, type Attestation } from "./attestation.ts";
1011 import type { Database } from "bun:sqlite";
1112 import { isSafeRef } from "../git/guard.ts";
13 import { treeOf } from "../git/merge.ts";
1214 import { err, ok, type Result } from "../kernel/result.ts";
1315 import { createToken } from "./tokens.ts";
1416 import { foldsIn } from "./trusted_sources.ts";
@@ -187,22 +189,56 @@ export function recordPullProposal(
187189 db: Database,
188190 issueId: string,
189191 p: Pick<Proposal, "child" | "origin">,
192 attestation?: Attestation,
190193 ): void {
191194 db.query(
192 "INSERT OR REPLACE INTO pull_proposal (issue_id, child, origin) VALUES (?1, ?2, ?3)",
193 ).run(issueId, p.child, p.origin);
195 "INSERT OR REPLACE INTO pull_proposal (issue_id, child, origin, attested_verdict, attested_tree) VALUES (?1, ?2, ?3, ?4, ?5)",
196 ).run(issueId, p.child, p.origin, attestation?.verdict ?? null, attestation?.tree ?? null);
194197 }
195198
196199 export function pullProposalOf(
197200 db: Database,
198201 issueId: string,
199 ): { child: string; origin: string; folds: boolean } | undefined {
202 ): { child: string; origin: string; folds: boolean; attestation?: Attestation } | undefined {
200203 const row = db
201 .query<{ child: string; origin: string }, [string]>(
202 "SELECT child, origin FROM pull_proposal WHERE issue_id = ?1",
204 .query<{ child: string; origin: string; attested_verdict: string | null; attested_tree: string | null }, [string]>(
205 "SELECT child, origin, attested_verdict, attested_tree FROM pull_proposal WHERE issue_id = ?1",
203206 )
204207 .get(issueId);
205 return row === null ? undefined : { ...row, folds: foldsIn(db, issueId) };
208 if (row === null) return undefined;
209 // Read back through the same rule it was written by: a row that is not a verdict and a tree says
210 // nothing.
211 const attested = parseAttestation(
212 row.attested_tree === null ? undefined : { verdict: row.attested_verdict, tree: row.attested_tree },
213 );
214 return {
215 child: row.child,
216 origin: row.origin,
217 folds: foldsIn(db, issueId),
218 ...(typeof attested === "object" ? { attestation: attested } : {}),
219 };
220 }
221
222 /**
223 * A pull's proposal with the tree of the head it is shown at, so its attestation line can say
224 * `tree differs`.
225 */
226 export type PullProposalAt = NonNullable<ReturnType<typeof pullProposalOf>> & { readonly headTree?: string };
227
228 /**
229 * The proposal and, only when a child attested one, the tree of `headOid` in `dir` (#13645): one
230 * read for the page head and the terminal alike, and no git read for any other pull.
231 */
232 export async function pullProposalAt(
233 db: Database,
234 issueId: string,
235 dir: string,
236 headOid: string,
237 ): Promise<PullProposalAt | undefined> {
238 const p = pullProposalOf(db, issueId);
239 if (p?.attestation === undefined) return p;
240 const headTree = await treeOf(dir, headOid);
241 return headTree === undefined ? p : { ...p, headTree };
206242 }
207243
208244 export interface ProposalTokenInfo {
src/http/api.ts +14 −2
@@ -8,6 +8,7 @@
88 * back to continue); errors are `{ error, message }`.
99 */
1010
11 import { parseAttestation } from "../core/attestation.ts";
1112 import { listAppReleases } from "../core/app_releases.ts";
1213 import { openapiHandler } from "../contract/served.ts";
1314 import { CHECK_ASKED } from "../actions/pull_ask_words.ts";
@@ -2763,6 +2764,15 @@ export function apiRoutes(router: Router<Handler>): void {
27632764 422,
27642765 `a proposal pull comes from a child/${proposal.child}/… branch of this repository`,
27652766 );
2767 // What the child says it proved: a verdict and a tree id, or nothing. Shown beside the
2768 // pull, never admitted on (#13645); only a proposal may send one.
2769 const attested = proposal === undefined ? undefined : parseAttestation(input.attestation);
2770 if (attested === "invalid")
2771 return apiError(
2772 "invalid_attestation",
2773 422,
2774 "an attestation is { verdict: green|red|pending|none, tree: <40 or 64 hex> }",
2775 );
27662776 // `headRepo: "owner/name"` proposes a fork's branch into this base.
27672777 let headRepo: Repo | undefined;
27682778 const headSpec = str(input.headRepo);
@@ -2816,12 +2826,14 @@ export function apiRoutes(router: Router<Handler>): void {
28162826 ? originAware(created.error)
28172827 : respondAccess(created.error, 422);
28182828 if (proposal !== undefined)
2819 recordPullProposal(ctx.app.db, created.value.id, proposal);
2829 recordPullProposal(ctx.app.db, created.value.id, proposal, attested);
28202830 return json(
28212831 {
28222832 ...withLabels(ctx, created.value),
28232833 variantSiblings: variantSiblings(ctx.app.db, [created.value])[0] ?? [],
2824 ...(proposal ? { proposal: { child: proposal.child, origin: proposal.origin } } : {}),
2834 ...(proposal
2835 ? { proposal: { child: proposal.child, origin: proposal.origin, ...(attested ? { attestation: attested } : {}) } }
2836 : {}),
28252837 },
28262838 201,
28272839 );
src/spawn/preview-seed.ts +25
@@ -37,6 +37,10 @@ import { backBet } from "../actions/bets.ts";
3737 import { openIssue, setIssueState } from "../actions/issues.ts";
3838 import { pinBuild } from "../actions/builds.ts";
3939 import { addReview, mergePull, openPull } from "../actions/pulls.ts";
40 import { pullProposalOf, recordPullProposal } from "../core/proposal_token.ts";
41 import { getPull } from "../core/pulls.ts";
42 import { treeOf } from "../git/merge.ts";
43 import { repoDir } from "../git/repos.ts";
4044 import { commitToBranch, createRepo, forkRepo, updateRepoSettings } from "../actions/repos.ts";
4145 import { reviewGate } from "../actions/gate_review.ts";
4246 import { forgeHttp } from "../http/server.ts";
@@ -433,6 +437,8 @@ export async function seedPreview(
433437 seedGrace(app);
434438 const inventory = seedInventory(app, admin);
435439 if (!inventory.ok) return inventory;
440 const attested = await seedAttestedPull(app, admin);
441 if (!attested.ok) return attested;
436442 return ok({ seeded: false });
437443 }
438444 const world = await seedWorld(app, admin);
@@ -455,9 +461,28 @@ export async function seedPreview(
455461 seedGrace(app);
456462 const inventory = seedInventory(app, admin);
457463 if (!inventory.ok) return inventory;
464 const attested = await seedAttestedPull(app, admin);
465 if (!attested.ok) return attested;
458466 return ok({ seeded: true });
459467 }
460468
469 /**
470 * The sample pull, proposed by a child that attests its own green check on the head's tree, so
471 * the pull's page draws the attestation line its look pictures (#13645). A row only; no child
472 * exists. Every boot, so a preview seeded before it gains the row; a row already there is kept.
473 */
474 async function seedAttestedPull(app: App, admin: User): Promise<Result<void, string>> {
475 const repo = getRepo(app.db, admin.username, PREVIEW_REPO);
476 if (repo === undefined) return err("the sample repository is gone");
477 const pull = getPull(app.db, repo.id, PREVIEW_PULL);
478 if (pull === undefined) return err(`the sample pull #${String(PREVIEW_PULL)} is gone`);
479 if (pullProposalOf(app.db, pull.id)?.attestation !== undefined) return ok();
480 const tree = await treeOf(repoDir(app.reposRoot, repo.ownerName, repo.name), pull.headOid);
481 if (tree === undefined) return err("the sample pull's head tree");
482 recordPullProposal(app.db, pull.id, { child: "kid", origin: "https://kid.example" }, { verdict: "green", tree });
483 return ok();
484 }
485
461486 /** The client forge the preview's operator view shows in grace. */
462487 export const PREVIEW_GRACE_CLIENT = "preview-grace-client";
463488
src/tui/screens/pull.ts +2 −1
@@ -59,6 +59,7 @@ import {
5959 type EnvState,
6060 type EnvStatus, envsFor } from "../../apps/runtime.ts";
6161 import { proposedByText } from "../../core/proposal_token.ts";
62 import { attestationLine } from "../../core/attestation.ts";
6263 import { getAppByRepo } from "../../core/apps.ts";
6364 import { teamsHolding, teamVerdicts, type TeamVerdict } from "../../core/issue_teams.ts";
6465 import { getIssue, type Issue } from "../../core/issues.ts";
@@ -1281,7 +1282,7 @@ export function pullScreen(
12811282 x1,
12821283 head!.y + 1,
12831284 truncate(
1284 ` ${facts?.mergedAt != null ? "merged" : issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${guestWaiting() ? ` · ${isContribHead(facts?.headBranch ?? "") ? OUTSIDE_NOTE : repo !== undefined && crewFilters(repo) ? GUEST_NOTE_FILTERED : GUEST_NOTE}` : ""}${assignedText(issueRow, ctx.icons)}${facts?.proposal ? ` · ${proposedByText(facts.proposal)}` : ""}${hold === undefined ? "" : ` · held by ${hold.heldByName}: ${hold.why}`}${step === null ? "" : ` · step: ${stepLine(step)}`}${landing === null ? "" : ` · ${landing}`}${next === null ? "" : ` · next: ${next.who}, ${next.why}`}${ledgerLine === "" ? "" : ` · ${ledgerLine}`}`,
1285 ` ${facts?.mergedAt != null ? "merged" : issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${guestWaiting() ? ` · ${isContribHead(facts?.headBranch ?? "") ? OUTSIDE_NOTE : repo !== undefined && crewFilters(repo) ? GUEST_NOTE_FILTERED : GUEST_NOTE}` : ""}${assignedText(issueRow, ctx.icons)}${facts?.proposal ? ` · ${proposedByText(facts.proposal)}` : ""}${facts?.proposal?.attestation ? ` · ${attestationLine(facts.proposal.child, facts.proposal.attestation, facts.proposal.headTree)}` : ""}${hold === undefined ? "" : ` · held by ${hold.heldByName}: ${hold.why}`}${step === null ? "" : ` · step: ${stepLine(step)}`}${landing === null ? "" : ` · ${landing}`}${next === null ? "" : ` · next: ${next.who}, ${next.why}`}${ledgerLine === "" ? "" : ` · ${ledgerLine}`}`,
12851286 Math.max(0, edge - x1),
12861287 ),
12871288 style(c.mutedFg, c.bg),
src/view/local.ts +4 −6
@@ -9,7 +9,7 @@
99 */
1010
1111 import { STL_LIMIT } from "../web/render/stl.ts";
12 import { pullProposalOf } from "../core/proposal_token.ts";
12 import { pullProposalAt } from "../core/proposal_token.ts";
1313 import { mayView, sealedScope } from "../core/sealed.ts";
1414 import type { App } from "../app.ts";
1515 import {
@@ -311,10 +311,8 @@ export function localSource(
311311 if (issue.kind === "pull") {
312312 const row = getPull(app.db, repo.id, number);
313313 if (row !== undefined) {
314 const { status, diff } = await pullDiff(
315 await pullDir(app.db, app.reposRoot, repo, row),
316 row,
317 );
314 const dir = await pullDir(app.db, app.reposRoot, repo, row);
315 const { status, diff } = await pullDiff(dir, row);
318316 pull = {
319317 baseBranch: row.baseBranch,
320318 headBranch: row.headBranch,
@@ -325,7 +323,7 @@ export function localSource(
325323 diff,
326324 mergeable: status.mergeable,
327325 conflicts: status.conflicts,
328 proposal: pullProposalOf(app.db, row.id) ?? null,
326 proposal: (await pullProposalAt(app.db, row.id, dir, status.headOid)) ?? null,
329327 reviews: listReviews(app.db, row.id).map((review) => ({
330328 author: review.originAuthor ?? review.authorName,
331329 state: review.state,
src/view/source.ts +9 −2
@@ -28,6 +28,7 @@
2828 * (invariant 9).
2929 */
3030
31 import type { Attestation } from "../core/attestation.ts";
3132 import type { Label } from "../core/issues.ts";
3233 import { getOriginFor } from "../core/origins.ts";
3334 import { canRead, getRepo, type Repo } from "../core/repos.ts";
@@ -195,8 +196,14 @@ export interface PullFacts {
195196 readonly conflicts: readonly string[];
196197 /** Every verdict, newest last. Empty when nobody has reviewed. */
197198 readonly reviews: readonly ReviewFact[];
198 /** The child and origin a proposal token opened this pull for, if one did. */
199 readonly proposal: { readonly child: string; readonly origin: string } | null;
199 /** The child and origin a proposal token opened this pull for, if one did, with what the
200 * child attested of it and the head's tree (#13645). */
201 readonly proposal: {
202 readonly child: string;
203 readonly origin: string;
204 readonly attestation?: Attestation;
205 readonly headTree?: string;
206 } | null;
200207 }
201208
202209 export interface IssueDetail {
src/web/pages/conflicts.ts +4 −2
@@ -7,6 +7,7 @@
77 * running count and the merged file beneath. Writers only.
88 */
99
10 import { pullProposalAt } from "../../core/proposal_token.ts";
1011 import { canWrite, getRepoById, type Repo } from "../../core/repos.ts";
1112 import { pullDir, pullStatus, type Pull } from "../../core/pulls.ts";
1213 import { activeRunFor } from "../../core/runs.ts";
@@ -171,6 +172,7 @@ export async function conflictsPage(ctx: Ctx): Promise<Response> {
171172 );
172173 const status = await timePhaseAsync(req, "status", () => pullStatus(dir, pull));
173174 const files = status.conflicts;
175 const proposal = await pullProposalAt(ctx.app.db, pull.id, dir, status.headOid);
174176 const asked = ctx.url.searchParams.get("file") ?? "";
175177 // Only a path git itself named is read; the rest of the world is a 404.
176178 const file = asked === "" ? files[0] : files.find((f) => f === asked);
@@ -184,7 +186,7 @@ export async function conflictsPage(ctx: Ctx): Promise<Response> {
184186 crumbs: crumbsFor(repo),
185187 palette: repoPalette(ctx, repo),
186188 body: html`${repoHeader(ctx, repo, "pulls", { compact: true, ownTitle: true })}
187 ${changeHead(ctx, repo, pull)}${changeTabs(repo, pull, "files")}
189 ${changeHead(ctx, repo, pull, null, proposal)}${changeTabs(repo, pull, "files")}
188190 <p class="mt">${unknown && pull.state === "open"
189191 ? "No conflict in that file."
190192 : "This pull has no conflicts."}
@@ -237,7 +239,7 @@ export async function conflictsPage(ctx: Ctx): Promise<Response> {
237239 });
238240
239241 const body = html`${repoHeader(ctx, repo, "pulls", { compact: true, ownTitle: true })}
240 ${changeHead(ctx, repo, pull)}${changeTabs(repo, pull, "files")}
242 ${changeHead(ctx, repo, pull, null, proposal)}${changeTabs(repo, pull, "files")}
241243 <p class="muted small mt">
242244 <a href="${back}">← Files</a> · <span class="mono">${file}</span> ·
243245 <strong id="rs-count">${done} of ${total} resolved</strong>
src/web/pages/pull.ts +2 −1
@@ -8,6 +8,7 @@
88 * it needs.
99 */
1010
11 import { pullProposalAt } from "../../core/proposal_token.ts";
1112 import { returnTo, withReturn } from "../return_to.ts";
1213 import { pullRoster } from "../studio/pull_roster.ts";
1314 import { originCheckLead, originCheckOf } from "../../origins/pull-check.ts";
@@ -1143,7 +1144,7 @@ export async function pullFilesPage(ctx: Ctx): Promise<Response> {
11431144 compact: true,
11441145 ownTitle: true,
11451146 })}
1146 ${changeHead(ctx, repo, pull, { headOid: status.headOid, conflicts: status.conflicts.length })}
1147 ${changeHead(ctx, repo, pull, { headOid: status.headOid, conflicts: status.conflicts.length }, await pullProposalAt(ctx.app.db, pull.id, dir, status.headOid))}
11471148 ${changeTabs(repo, pull, "files")}
11481149 ${verdictLine(verdict)}
11491150 ${verdict.tone === "success" && mayMerge && check.state === "ok" && !stale
src/web/studio/change.ts +13 −5
@@ -12,7 +12,8 @@
1212 import { pausedSentence } from "../../crew/paused_now.ts";
1313 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1414 import { cardPath } from "../og/path.ts";
15 import { pullProposalOf } from "../../core/proposal_token.ts";
15 import { pullProposalAt, type PullProposalAt } from "../../core/proposal_token.ts";
16 import { attestationLine } from "../../core/attestation.ts";
1617 import { getIssueById } from "../../core/issues.ts";
1718 import { mayEditIssue } from "../../actions/issues.ts";
1819 import { marksByName, type Mark } from "../../core/marks.ts";
@@ -252,7 +253,10 @@ export function changeHead(
252253 ctx: Ctx,
253254 repo: Repo,
254255 pull: Pull,
255 live: { readonly headOid: string; readonly conflicts: number } | null = null,
256 live: { readonly headOid: string; readonly conflicts: number } | null,
257 // The child's proposal, if one opened this pull, read by the caller with `pullProposalAt`
258 // (async: it reads the head's tree when the child attested one, #13645).
259 proposal: PullProposalAt | undefined,
256260 ): Html {
outdated

Low. changeHead now has two paths: head given reads the proposal passed in, head absent reads it itself and draws no line. conflicts.ts and pull.ts take the second path, so the line shows on one tab only and the signature hides that. Make the caller pass the proposal and tree every time, or have changeHead read both itself.

257261 const next = live === null ? null : nextOfPull(ctx.app.db, pull, live, repo);
258262 const step =
@@ -288,11 +292,14 @@ export function changeHead(
288292 >`,
289293 )}
290294 ${workSpent(ctx, repo, pull, "pull")}${when(
291 pullProposalOf(ctx.app.db, pull.id),
295 proposal,
292296 (p) =>
293297 html`<span class="proposed-by"
294298 >proposed by child <span class="mono">${p.child}</span> from
295 <span class="mono">${p.origin}</span></span
299 <span class="mono">${p.origin}</span>${when(
300 p.attestation,
301 (a) => html` · <span class="mono">${attestationLine(p.child, a, p.headTree)}</span>`,
302 )}</span
296303 >`,
297304 )}
outdated

Low. data-attested is written but nothing reads it: no CSS, JS or test. It is dead markup. Remove it, or give it a use. Also, the first span's class is proposed-by, so this adds a second one. Hang the line off the existing span, or use a dl row for the fact (principle 7), rather than a second inline span.

298305 </div>
@@ -678,13 +685,14 @@ async function changeConversation(
678685 spent.decide += performance.now() - decideAt;
679686 const glyph = originGlyph(repo);
680687 const headOid = status?.headOid ?? pull.headOid;
688 const proposal = await pullProposalAt(db, pull.id, wordCtx.dir, headOid);
681689 const pageHead = tick(spent, "head", () => ({
682690 top: html`${repoHeader(ctx, repo, "pulls", {
683691 compact: true,
684692 ownTitle: true,
685693 quiet: true,
686694 })}
687 ${changeHead(ctx, repo, pull, status === undefined ? null : { headOid, conflicts: status.conflicts.length })}
695 ${changeHead(ctx, repo, pull, status === undefined ? null : { headOid, conflicts: status.conflicts.length }, proposal)}
688696 ${changeTabs(repo, pull, "change")}`,
689697 crumbs: crumbsFor(repo),
690698 palette: [
test/attestation.test.ts added +61
@@ -0,0 +1,61 @@
1 /** The words a child attests with, and the one line the pull says (#13645). */
2 import { expect, test } from "bun:test";
3 import { attestationLine, parseAttestation, verdictOfCheck } from "../src/core/attestation.ts";
4
5 test("a child's check state maps to its attested verdict", () => {
6 expect(verdictOfCheck("ok")).toBe("green");
7 expect(verdictOfCheck("failed")).toBe("red");
8 expect(verdictOfCheck("pending")).toBe("pending");
9 for (const other of ["none", "superseded", "running", "", "OK"]) expect(verdictOfCheck(other)).toBe("none");
10 });
11
12 test("only a known verdict and a lowercase hex tree id are an attestation", () => {
13 const tree = "1a2b3c4d".repeat(5);
14 expect(parseAttestation(undefined)).toBeUndefined();
15 expect(parseAttestation({ verdict: "red", tree })).toEqual({ verdict: "red", tree });
16 expect(parseAttestation({ verdict: "red", tree: tree.toUpperCase() })).toBe("invalid");
17 expect(parseAttestation({ verdict: "ok", tree })).toBe("invalid");
18 expect(parseAttestation([tree])).toBe("invalid");
19 });
20
21 test("the line names the child, the verdict and the short tree, and says when the head differs", () => {
22 const a = { verdict: "green" as const, tree: "1a2b3c4d".repeat(5) };
23 expect(attestationLine("kid", a, a.tree)).toBe("proven on kid: green at 1a2b3c4d");
24 expect(attestationLine("kid", a, "f".repeat(40))).toBe("proven on kid: green at 1a2b3c4d · tree differs");
25 expect(attestationLine("kid", a, undefined)).toBe("proven on kid: green at 1a2b3c4d · tree differs");
26 });
27
28 test("the preview's sample pull is proposed by a child that attests its head's own tree", async () => {
29 const { mkdtemp, rm } = await import("node:fs/promises");
30 const { tmpdir } = await import("node:os");
31 const { join } = await import("node:path");
32 const { createApp } = await import("../src/app.ts");
33 const { seedPreview } = await import("../src/spawn/preview-seed.ts");
34 const { PREVIEW_PULL_PAGE } = await import("../src/spawn/preview-looks.ts");
35 const { pullProposalAt } = await import("../src/core/proposal_token.ts");
36 const { repoDir } = await import("../src/git/repos.ts");
37 const dir = await mkdtemp(join(tmpdir(), "forge-attest-seed-"));
38 const app = createApp({ dataDir: dir, port: 0, previewIdentityKey: "attest-seed-key" });
39 try {
40 const seeded = await seedPreview(app, { FORGE_APP_ENV: "preview" });
41 if (!seeded.ok) throw new Error(seeded.error);
42 const [, owner, name, , number] = PREVIEW_PULL_PAGE.split("/");
43 const pull = app.db
44 .query("SELECT p.issue_id AS id, p.head_oid AS head FROM pull p JOIN issue i ON i.id = p.issue_id WHERE i.number = ?1")
45 .get(Number(number)) as { id: string; head: string };
46 const p = await pullProposalAt(app.db, pull.id, repoDir(app.reposRoot, owner!, name!), pull.head);
47 expect(p?.attestation?.verdict).toBe("green");
48 expect(attestationLine(p!.child, p!.attestation!, p!.headTree)).toMatch(/^proven on kid: green at [0-9a-f]{8}$/);
49
50 // A preview seeded before the attestation existed has no row: the next boot adds it.
51 app.db.query("DELETE FROM pull_proposal WHERE issue_id = ?1").run(pull.id);
52 const again = await seedPreview(app, { FORGE_APP_ENV: "preview" });
53 if (!again.ok) throw new Error(again.error);
54 expect(again.value.seeded).toBe(false);
55 const back = await pullProposalAt(app.db, pull.id, repoDir(app.reposRoot, owner!, name!), pull.head);
56 expect(back?.attestation).toEqual(p!.attestation);
57 } finally {
58 app.close();
59 await rm(dir, { recursive: true, force: true });
60 }
61 }, 30_000);
test/number-retired.test.ts +5 −2
@@ -1,4 +1,7 @@
1 /** An issue's or pull's number in a heading draws from base's `.num`; `.number` left the stylesheet (#5253). */
1 /**
2 * An issue's or pull's number in a heading draws from base's `.num`; `.number` left the stylesheet
3 * (#5253).
4 */
25 import { afterAll, beforeAll, expect, test } from "bun:test";
36 import { mkdtemp, rm } from "node:fs/promises";
47 import { tmpdir } from "node:os";
@@ -74,7 +77,7 @@ test("the pull heading marks its number with .num", () => {
7477 revertsPullId: null,
7578 variantGroup: null,
7679 };
77 const head = String(changeHead({ app, auth: { user: undefined, scope: undefined, via: "none" } } as Ctx, repo, pull));
80 const head = String(changeHead({ app, auth: { user: undefined, scope: undefined, via: "none" } } as Ctx, repo, pull, null, undefined));
7881 expect(head).toContain('<h1>a pull <span class="num">#2</span></h1>');
7982 expect(head).not.toContain('class="number"');
8083 });
test/proposal-token.test.ts +59
@@ -302,6 +302,65 @@ describe("over HTTP", () => {
302302 }
303303 });
304304
305 test("a proposal carries what the child proved, and the pull says when its tree differs (#13645)", async () => {
306 // Many pushes and pulls in one test: the per-token limit is another test's subject.
307 proposalLimiter(app).setLimits({ perMinute: 1000, adminPerMinute: 1000, enabled: true });
308 const tree = (await git(["rev-parse", "HEAD^{tree}"])).out.trim();
309 expect(tree).toMatch(/^[0-9a-f]{40}$/);
310 const open = async (head: string, attestation: unknown) => {
311 expect((await push(`refs/heads/${head}`)).code).toBe(0);
312 return api("/api/v1/repos/alice/lib/pulls", {
313 method: "POST",
314 body: JSON.stringify({ title: `Proven ${head}`, base: "main", head, attestation }),
315 });
316 };
317 // Refused at the boundary: not a verdict, not a hex tree id.
318 for (const bad of [{ verdict: "green", tree: "nope" }, { verdict: "great", tree }, "green"]) {
319 const refused = await open("child/kid/bad", bad);
320 expect(refused.status).toBe(422);
321 expect(((await refused.json()) as { error: string }).error).toBe("invalid_attestation");
322 }
323
324 const same = await open("child/kid/proven", { verdict: "green", tree });
325 expect(same.status).toBe(201);
326 const made = (await same.json()) as { number: number; proposal: { attestation: unknown } };
327 expect(made.proposal.attestation).toEqual({ verdict: "green", tree });
328 const page = await (await fetch(`${servers.url}/alice/lib/pulls/${made.number}`)).text();
329 expect(page).toContain(`proven on kid: green at ${tree.slice(0, 8)}`);
330 expect(page).not.toContain("tree differs");
331
332 const other = "a".repeat(40);
333 const differs = await open("child/kid/elsewhere", { verdict: "green", tree: other });
334 const n = ((await differs.json()) as { number: number }).number;
335 const text = await (await fetch(`${servers.url}/alice/lib/pulls/${n}`)).text();
336 expect(text).toContain(`proven on kid: green at aaaaaaaa · tree differs`);
337 // The files tab says it too: every caller of the head reads the proposal the same way.
338 const files = await (await fetch(`${servers.url}/alice/lib/pulls/${n}/files`)).text();
339 expect(files).toContain(`proven on kid: green at aaaaaaaa · tree differs`);
340
341 // The terminal's pull screen says the same line beside "proposed by child" (both doors).
342 const terminal = headlessTerminal(240, 44);
343 const { app: tui, session } = createForgeApp(
344 app,
345 { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:a", user: alice },
346 { terminal, exitHooks: false },
347 );
348 tui.start();
349 try {
350 tui.ctx.push(pullScreen(session, tui.ctx, local(session, lib), made.number));
351 await settleApp(tui);
352 const shown = tui.screen.toText();
353 expect(shown).toContain(`proposed by child kid from ${ORIGIN}`);
354 expect(shown).toContain(`proven on kid: green at ${tree.slice(0, 8)}`);
355 expect(shown).not.toContain("tree differs");
356 } finally {
357 tui.stop();
358 }
359 // Information only: the parent's own gate still holds the proposal.
360 const pull = getPull(app.db, lib.id, n)!;
361 expect(pullMayRun(app.db, lib, pull, pull.headOid)).toBe(false);
362 });
363
305364 test("a proposed pull runs nothing until a writer approves that exact head", async () => {
306365 const pull = getPull(app.db, lib.id, proposedNumber)!;
307366 const head = pull.headOid;
test/upstream-forge.test.ts +28 −1
@@ -17,8 +17,9 @@ import {
1717 STATE_TTL_MS,
1818 } from "../src/actions/upstream.ts";
1919 import { createApp, type App } from "../src/app.ts";
20 import { mintProposalToken } from "../src/core/proposal_token.ts";
20 import { mintProposalToken, pullProposalOf } from "../src/core/proposal_token.ts";
2121 import { getPull } from "../src/core/pulls.ts";
22 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
2223 import { getRepo, type Repo } from "../src/core/repos.ts";
2324 import { createSession } from "../src/core/sessions.ts";
2425 import { createToken } from "../src/core/tokens.ts";
@@ -174,6 +175,11 @@ describe("a child forge proposes to its parent forge", () => {
174175 expect(pull.headBranch).toBe(`child/kid/${made.value.branch}`);
175176 expect(pull.body).toContain(`kid/forge#${landed.number}`);
176177 expect(pull.body).toContain("Proposed by child kid");
178 // It carries what the child proved: its check's word on the tip (none ran here) and the
179 // tip's tree, which is the pull's own head tree on the parent (#13645).
180 const tip = (await runGit(["rev-parse", "refs/heads/main^{tree}"], { cwd: repoDir(child.reposRoot, "kid", "forge") }));
outdated

Medium. This only asserts verdict 'none'. Add a case where the child's check on the tip is ok and the parent stores 'green'. Without it, the child's side could send a constant and this test would pass.

181 if (!tip.ok) throw new Error("no tree");
182 expect(pullProposalOf(parent.db, pull.id)?.attestation).toEqual({ verdict: "none", tree: tip.value.trim() });
177183
178184 // Asking again for the same tip does not double it.
179185 const again = await proposeToParentForge(child, kid, forge);
@@ -385,6 +391,27 @@ describe("a child forge proposes to its parent forge", () => {
385391 }
386392 });
387393
394 test("the child's green check on the tip reaches the parent as green (#13645)", async () => {
395 await land("proven", "Add proven");
396 const dir = repoDir(child.reposRoot, "kid", "forge");
397 const tip = await runGit(["rev-parse", "refs/heads/main"], { cwd: dir });
398 const tree = await runGit(["rev-parse", "refs/heads/main^{tree}"], { cwd: dir });
399 if (!tip.ok || !tree.ok) throw new Error("no tip");
400 // The child's own check of its main at this tip, and an older failed one on another commit
401 // that must not be the one sent.
402 const older = createRun(child.db, { repoId: forge.id, kind: "check", env: "main", commitOid: "b".repeat(40) });
403 claimRun(child.db, older.id);
404 finishRun(child.db, older.id, { state: "failed", summary: "red" });
405 const run = createRun(child.db, { repoId: forge.id, kind: "check", env: "main", commitOid: tip.value.trim() });
406 claimRun(child.db, run.id);
407 finishRun(child.db, run.id, { state: "ok", summary: "all green" });
408
409 const made = await proposeToParentForge(child, kid, forge);
410 if (!made.ok) throw new Error(JSON.stringify(made.error));
411 const pull = parentPull(made.value.number);
412 expect(pullProposalOf(parent.db, pull.id)?.attestation).toEqual({ verdict: "green", tree: tree.value.trim() });
413 });
414
388415 test("an unreachable parent degrades to one line, not an error page", async () => {
389416 await land("second", "Add second");
390417 const made = await proposeToParentForge(child, kid, forge);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs