Public: anyone can read this; the crew can change it.
The MCP `pull` tool omits review verdict bodies: on #16496 juniper asked for… #16527
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16505-the-mcp-pull-tool-omits-review-verdict-b → main 0 commits fork 3 threads · 3 unresolved
6 files
changed +141
−5
src/core/reviews.ts +11
| @@ -353,6 +353,17 @@ function latestByAuthor(reviews: readonly Review[]): Map<string, Review> { | ||
| 353 | 353 | return latest; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | /** Each reviewer's current verdict, when it was passed on `headOid`: what the head stands on. */ | |
| 357 | export function reviewsOnHead(db: Database, issueId: string, headOid: string): Review[] { | |
| 358 | return [...latestReviewByAuthor(db, issueId).values()].filter((r) => r.commitOid === headOid); | |
| 359 | } | |
| 360 | ||
| 361 | /** The words naming the review that asks for changes on `headOid`, or null when none does. */ | |
| 362 | export function blockingReviewWords(db: Database, issueId: string, headOid: string): string | null { | |
| 363 | const r = reviewsOnHead(db, issueId, headOid).find((x) => x.state === "changes_requested"); | |
| 364 | return r === undefined ? null : `${r.originAuthor ?? r.authorName} asked for changes (review ${r.id})`; | |
| 365 | } | |
| 366 | ||
| 356 | 367 | export interface ReviewSummary { |
| 357 | 368 | /** Distinct reviewers whose current verdict approves *this* head. */ |
| 358 | 369 | readonly approvals: number; |
src/flow/next_actor.ts +5 −2
| @@ -8,7 +8,7 @@ import type { Database } from "bun:sqlite"; | ||
| 8 | 8 | import { getHold } from "../core/holds.ts"; |
| 9 | 9 | import type { Pull } from "../core/pulls.ts"; |
| 10 | 10 | import { checkSummary, type CheckSummary, type RunState } from "../core/runs.ts"; |
| 11 | import { reviewSummary } from "../core/reviews.ts"; | |
| 11 | import { blockingReviewWords, reviewSummary } from "../core/reviews.ts"; | |
| 12 | 12 | import type { Repo } from "../core/repos.ts"; |
| 13 | 13 | import { reviewsOff } from "../crew/review.ts"; |
| 14 | 14 | import { isFirstChange } from "../crew/first_change.ts"; |
| @@ -37,6 +37,8 @@ export interface NextInput { | ||
| 37 | 37 | readonly reviewOff?: boolean; |
| 38 | 38 | /** The app's first change (`crew/first_change.ts`): it lands on green whatever the reviewer asked. */ |
| 39 | 39 | readonly firstChange?: boolean; |
| 40 | /** Who asked for changes on this head, and which review (`blockingReviewWords`). */ | |
| 41 | readonly askedBy?: string | null; | |
| 40 | 42 | } |
| 41 | 43 | |
| 42 | 44 | const WAITING = { |
| @@ -56,7 +58,7 @@ export function nextActor(i: NextInput): Next { | ||
| 56 | 58 | return { who: "queue", why: WAITING[i.check] }; |
| 57 | 59 | } |
| 58 | 60 | if (i.changesRequested > 0) |
| 59 | return { who: "builder", why: "changes were asked on this head" }; | |
| 61 | return { who: "builder", why: i.askedBy == null ? "changes were asked on this head" : `changes were asked on this head: ${i.askedBy}` }; | |
| 60 | 62 | if (i.check === "failed") return { who: "builder", why: "its check is red" }; |
| 61 | 63 | if (i.wall != null && i.wall.length > 0) return { who: "person", why: wallAsk(i.wall) }; |
| 62 | 64 | if (i.approvals > 0) { |
| @@ -105,6 +107,7 @@ export function nextOfPull( | ||
| 105 | 107 | approvals: reviews.approvals, |
| 106 | 108 | pushedSince: reviews.stale, |
| 107 | 109 | wall: wallWords(db, pull.id, live.headOid), |
| 110 | askedBy: reviews.changesRequested > 0 ? blockingReviewWords(db, pull.id, live.headOid) : null, | |
| 108 | 111 | firstChange: reviews.changesRequested > 0 && repo !== undefined && isFirstChange(db, repo, pull), |
| 109 | 112 | }, |
| 110 | 113 | () => repo !== undefined && reviewsOff(db, repo), |
src/flow/path.ts +2 −1
| @@ -17,7 +17,7 @@ import { latestDecisionsFor } from "../core/decisions.ts"; | ||
| 17 | 17 | import { holdsFor } from "../core/holds.ts"; |
| 18 | 18 | import { getPull, type Pull } from "../core/pulls.ts"; |
| 19 | 19 | import type { Repo } from "../core/repos.ts"; |
| 20 | import { reviewSummariesFor, reviewSummary } from "../core/reviews.ts"; | |
| 20 | import { blockingReviewWords, reviewSummariesFor, reviewSummary } from "../core/reviews.ts"; | |
| 21 | 21 | import { checksForHeads, checkSummary, type CheckSummary, type RunState } from "../core/runs.ts"; |
| 22 | 22 | import { reviewsOff } from "../crew/review.ts"; |
| 23 | 23 | import { isFirstChange } from "../crew/first_change.ts"; |
| @@ -191,6 +191,7 @@ export function stepsOfStored(db: Database, repo: Repo, pulls: readonly Pull[]): | ||
| 191 | 191 | approvals: r.approvals, |
| 192 | 192 | pushedSince: r.stale, |
| 193 | 193 | wall: wallWordsOf(walls.get(pull.id), pull.headOid), |
| 194 | askedBy: r.changesRequested > 0 ? blockingReviewWords(db, pull.id, pull.headOid) : null, | |
| 194 | 195 | firstChange: r.changesRequested > 0 && isFirstChange(db, repo, pull), |
| 195 | 196 | }, |
| 196 | 197 | reviewOff, |
src/http/mcp/tools/merge.ts +3 −1
| @@ -4,6 +4,7 @@ import { mergePull } from "../../../actions/pulls.ts"; | ||
| 4 | 4 | import { getPull, pullDir, pullMergeState } from "../../../core/pulls.ts"; |
| 5 | 5 | import { checkSummary } from "../../../core/runs.ts"; |
| 6 | 6 | import { canWrite } from "../../../core/repos.ts"; |
| 7 | import { blockingReviewWords } from "../../../core/reviews.ts"; | |
| 7 | 8 | import { canVerdict } from "../../../core/verdict.ts"; |
| 8 | 9 | import { reviewWords } from "../../../actions/review_words.ts"; |
| 9 | 10 | |
| @@ -115,7 +116,8 @@ export const tool: Tool = { | ||
| 115 | 116 | // A team reviewer judges and does not land: the page's words (#12631). |
| 116 | 117 | const words = |
| 117 | 118 | code === "forbidden" && canVerdict(ctx.app.db, repo, user) ? reviewWords.reviewerLands : mergeFailure(error); |
| 118 | return bad(code, words); | |
| 119 | const blocker = code === "review_required" ? blockingReviewWords(ctx.app.db, pull.id, pull.headOid) : null; | |
| 120 | return bad(code, blocker === null ? words : `${words} Blocking: ${blocker}.`); | |
| 119 | 121 | } |
| 120 | 122 | return good({ |
| 121 | 123 | dryRun: false, |
src/http/mcp/tools/pull.ts +12 −1
| @@ -14,6 +14,7 @@ import { pullWaitsFor } from "../../../flow/waits_for.ts"; | ||
| 14 | 14 | import { landingLine } from "../../../flow/landing_line.ts"; |
| 15 | 15 | import { pullLooks } from "../../../looks/readable.ts"; |
| 16 | 16 | import { reviewSteps } from "../../../actions/review_steps.ts"; |
| 17 | import { reviewsOnHead } from "../../../core/reviews.ts"; | |
| 17 | 18 | import { isCrew } from "../../../core/agents.ts"; |
| 18 | 19 | import { markReaders } from "../../../crew/direct.ts"; |
| 19 | 20 | import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| @@ -22,10 +23,12 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts" | ||
| 22 | 23 | * The comments `pull` carries by default: the summary comes first, older ones by `commentsNext`. |
| 23 | 24 | */ |
| 24 | 25 | const PULL_COMMENTS = 10; |
| 26 | /** A review's body is cut here in the answer; the pull page has the rest. */ | |
| 27 | const REVIEW_BODY = 1000; | |
| 25 | 28 | |
| 26 | 29 | export const tool: Tool = { |
| 27 | 30 | name: "pull", |
| 28 | doc: "`{ repo, number }`: a pull's title, state, head and base, `summary` (two or three sentences: what changed, what was verified), and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), and `next: { who, why }` (open only; who acts next: builder, reviewer, queue or person), `step: { step, why, done }` (check, review, land or live; null once closed unlanded), and `comments` (the newest 10: author, body, at, `untrusted` on an outsider's), `commentsTotal` and `commentsNext` (older: `GET …/issues/:number/comments?cursor=`), and `looks` (newest first: `{ id, width, says, by, commit, url, at }`, the same as `GET …/pulls/:number/looks`), and `eta: { minutes, says }` (approved open pull only, else null), `waitsFor: { cause, says, action, line }` (green, unlanded 6 h+; else null), and `check: { state, baseOid }`: the latest check's state and the base tip it was merged with (empty when it merged nothing), `checkStale` (the base has moved since that check) and `checkedAgainst` (that base tip, or null; the same as `GET …/pulls/:number`); `mergeable` and `conflicts` are the same fields as `GET …/pulls/:number`, `check` is `state` and `run.baseOid` from `GET …/pulls/:number/checks`; `reviewSteps` (the review steps), draws the `ui://forge/pull` card: `#N title`, state with check and conflicts while open, `head → base` linked to the pull, and the preview link when the pull has an environment", | |
| 31 | doc: "`{ repo, number }`: a pull's title, state, head and base, `summary` (two or three sentences: what changed, what was verified), and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), and `next: { who, why }` (open only; who acts next: builder, reviewer, queue or person), `step: { step, why, done }` (check, review, land or live; null once closed unlanded), and `reviews` (each reviewer's verdict on the current head: id, author, verdict, body, at), and `comments` (the newest 10: author, body, at, `untrusted` on an outsider's), `commentsTotal` and `commentsNext` (older: `GET …/issues/:number/comments?cursor=`), and `looks` (newest first: `{ id, width, says, by, commit, url, at }`, the same as `GET …/pulls/:number/looks`), and `eta: { minutes, says }` (approved open pull only, else null), `waitsFor: { cause, says, action, line }` (green, unlanded 6 h+; else null), and `check: { state, baseOid }`: the latest check's state and the base tip it was merged with (empty when it merged nothing), `checkStale` (the base has moved since that check) and `checkedAgainst` (that base tip, or null; the same as `GET …/pulls/:number`); `mergeable` and `conflicts` are the same fields as `GET …/pulls/:number`, `check` is `state` and `run.baseOid` from `GET …/pulls/:number/checks`; `reviewSteps` (the review steps), draws the `ui://forge/pull` card: `#N title`, state with check and conflicts while open, `head → base` linked to the pull, and the preview link when the pull has an environment", | |
| 29 | 32 | description: |
| 30 | 33 | "A pull: title, state, head, base; open adds `mergeable`, `conflicts`, `check`.", |
| 31 | 34 | inputSchema: { |
| @@ -68,6 +71,14 @@ export const tool: Tool = { | ||
| 68 | 71 | at: c.createdAt, |
| 69 | 72 | ...("untrusted" in c && c.untrusted !== undefined ? { untrusted: true } : {}), |
| 70 | 73 | })), |
| 74 | reviews: (marking ? markReaders(db, repo, reviewsOnHead(db, pull.id, pull.headOid)) : reviewsOnHead(db, pull.id, pull.headOid)).map((r) => ({ | |
| 75 | id: r.id, | |
| 76 | author: r.originAuthor ?? r.authorName, | |
| 77 | verdict: r.state, | |
| 78 | body: r.body.length > REVIEW_BODY ? `${r.body.slice(0, REVIEW_BODY)}… (cut; the rest is on the pull page)` : r.body, | |
| 79 | at: r.createdAt, | |
| 80 | ...("untrusted" in r && r.untrusted !== undefined ? { untrusted: true } : {}), | |
| 81 | })), | |
| 71 | 82 | commentsTotal: total, |
| 72 | 83 | commentsNext: comments.length > 0 && comments.length < total ? comments[0]!.id : null, |
| 73 | 84 | looks: pullLooks(ctx.app, repo, pull, user), |
test/mcp-pull-verdicts.test.ts added +108
| @@ -0,0 +1,108 @@ | ||
| 1 | /** | |
| 2 | * MCP `pull` lists each reviewer's verdict on the head (a verdict on an older head is left out, a | |
| 3 | * long body is cut) and `next.why` names the review that blocks; `stepsOfStored` says the same. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { commitToBranch } from "../src/actions/repos.ts"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { stepsOfStored } from "../src/flow/path.ts"; | |
| 12 | import { createPull, getPull } from "../src/core/pulls.ts"; | |
| 13 | import { createRepo, getRepoById } from "../src/core/repos.ts"; | |
| 14 | import { submitReview } from "../src/core/reviews.ts"; | |
| 15 | import { createToken } from "../src/core/tokens.ts"; | |
| 16 | import { createUser } from "../src/core/users.ts"; | |
| 17 | import { repoDir } from "../src/git/repos.ts"; | |
| 18 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | import { mcpTool } from "./helpers/mcp.ts"; | |
| 21 | ||
| 22 | quietLogs(); | |
| 23 | ||
| 24 | let dataDir: string; | |
| 25 | let app: App; | |
| 26 | let servers: Servers; | |
| 27 | let token = ""; | |
| 28 | let asked = ""; | |
| 29 | const numbers: Record<string, number> = {}; | |
| 30 | let repoId = ""; | |
| 31 | ||
| 32 | const ok = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 33 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 34 | return r.value; | |
| 35 | }; | |
| 36 | ||
| 37 | beforeAll(async () => { | |
| 38 | dataDir = await mkdtemp(join(tmpdir(), "forge-mcp-verdict-")); | |
| 39 | app = createApp({ dataDir, port: 0 }); | |
| 40 | servers = await serve(app); | |
| 41 | const make = async (username: string, adminIfFirst = false) => | |
| 42 | ok(await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst })); | |
| 43 | const ada = await make("ada", true); | |
| 44 | const juniper = await make("juniper"); | |
| 45 | const repo = ok(await createRepo(app.db, app.reposRoot, { ownerId: ada.id, name: "vault", visibility: "public" })); | |
| 46 | ok(await commitToBranch(app, ada, repo, { message: "seed", files: [{ path: "a.txt", content: "a\n" }] })); | |
| 47 | ok(await commitToBranch(app, ada, repo, { message: "one", branch: "one", files: [{ path: "o.txt", content: "o\n" }] })); | |
| 48 | const pull = ok(await createPull(app.db, repoDir(app.reposRoot, ada.username, "vault"), { repoId: repo.id, authorId: ada.id, title: "Pull one", baseBranch: "main", headBranch: "one" })); | |
| 49 | asked = ok(submitReview(app.db, { issueId: pull.id, authorId: juniper.id, state: "changes_requested", body: "Document the flag in the README", commitOid: pull.headOid })).id; | |
| 50 | const open = async (name: string, state: "approved" | "changes_requested", opts: { oid?: string; body?: string } = {}) => { | |
| 51 | ok(await commitToBranch(app, ada, repo, { message: name, branch: name, files: [{ path: `${name}.txt`, content: `${name}\n` }] })); | |
| 52 | const p = ok(await createPull(app.db, repoDir(app.reposRoot, ada.username, "vault"), { repoId: repo.id, authorId: ada.id, title: name, baseBranch: "main", headBranch: name })); | |
| 53 | ok(submitReview(app.db, { issueId: p.id, authorId: juniper.id, state, body: opts.body ?? "", commitOid: opts.oid ?? p.headOid })); | |
| 54 | return p.number; | |
| 55 | }; | |
| 56 | repoId = repo.id; | |
| 57 | numbers.approved = await open("two", "approved"); | |
| 58 | numbers.stale = await open("three", "changes_requested", { oid: "0".repeat(40) }); | |
| 59 | numbers.long = await open("four", "changes_requested", { body: "x".repeat(5000) }); | |
| 60 | token = createToken(app.db, ada.id, "rw", "rw").token; | |
| 61 | }); | |
| 62 | ||
| 63 | afterAll(async () => { | |
| 64 | await servers.stop(); | |
| 65 | await rm(dataDir, { recursive: true, force: true }); | |
| 66 | }); | |
| 67 | ||
| 68 | test("pull shows each review on the head and names the blocking one in next.why", async () => { | |
| 69 | const r = await mcpTool(servers.url, token, "pull", { repo: "ada/vault", number: 1 }); | |
| 70 | expect(r.value.reviews).toEqual([ | |
| 71 | expect.objectContaining({ id: asked, author: "juniper", verdict: "changes_requested", body: "Document the flag in the README" }), | |
| 72 | ]); | |
| 73 | expect(r.value.next.who).toBe("builder"); | |
| 74 | expect(r.value.next.why).toContain("juniper"); | |
| 75 | expect(r.value.next.why).toContain(asked); | |
| 76 | }); | |
| 77 | ||
| 78 | test("the merge refusal review_required names the blocking review", async () => { | |
| 79 | const r = await mcpTool(servers.url, token, "merge", { repo: "ada/vault", number: 1, dryRun: false }); | |
| 80 | expect(r.error).toContain("juniper"); | |
| 81 | expect(r.error).toContain(asked); | |
| 82 | }); | |
| 83 | ||
| 84 | test("an approval on the head is listed as approved and next.why stays plain", async () => { | |
| 85 | const r = await mcpTool(servers.url, token, "pull", { repo: "ada/vault", number: numbers.approved }); | |
| 86 | expect(r.value.reviews).toEqual([expect.objectContaining({ author: "juniper", verdict: "approved" })]); | |
| 87 | expect(r.value.next.why).not.toContain("asked for changes"); | |
| 88 | }); | |
| 89 | ||
| 90 | test("a verdict on an older head is not listed and names no blocker", async () => { | |
| 91 | const r = await mcpTool(servers.url, token, "pull", { repo: "ada/vault", number: numbers.stale }); | |
| 92 | expect(r.value.reviews).toEqual([]); | |
| 93 | expect(r.value.next.why).not.toContain("juniper"); | |
| 94 | }); | |
| 95 | ||
| 96 | test("a long review body is cut with a pointer to the pull page", async () => { | |
| 97 | const r = await mcpTool(servers.url, token, "pull", { repo: "ada/vault", number: numbers.long }); | |
| 98 | const body: string = r.value.reviews[0].body; | |
| 99 | expect(body.length).toBeLessThan(1200); | |
| 100 | expect(body).toContain("pull page"); | |
| 101 | }); | |
| 102 | ||
| 103 | test("stepsOfStored names the blocking review as stepOfStored does", () => { | |
| 104 | const repo = getRepoById(app.db, repoId)!; | |
| 105 | const p = getPull(app.db, repoId, 1)!; | |
| 106 | const step = stepsOfStored(app.db, repo, [p]).get(p.id); | |
| 107 | expect(JSON.stringify(step)).toContain(asked); | |
| 108 | }); |
new above
offline
The batched path has no test; add one that fails without
askedBy. Also this runs one query per pull with changes requested: check it is not a problem on a large list.