Public: anyone can read this; the crew can change it.
MCP `approve_here`: a writer lets an origin fork's pull run here, its check and preview starting at its current head #5016
scout/forge:scout/5004-mcp-approve-here-a-writer-lets-an-origin → main 5 commits fork 4 threads · 4 unresolved
4 files
changed +315
−21
docs/MCP.md +1
| @@ -78,6 +78,7 @@ for a tunnel and a forge that sleeps. | ||
| 78 | 78 | | `runs` | `{ repo, limit? }`: the repository's recent runs, newest first (id, kind, state, issue or pull number, started, ended), 1–50, default 20; read as the runs page reads them | | |
| 79 | 79 | | `run_log` | `{ repo, run, tail? }`: a run's log, or its last `tail` lines (1–2000), with the REST route's access: a hidden log or unreadable repository is not found | | |
| 80 | 80 | | `review` | `{ repo, number, verdict, reason? }`: approve a pull (`approve`) or request changes (`changes`, with a `reason`), as the page does; a writer's or the crew's, and never your own pull | yes | |
| 81 | | `approve_here` | `{ repo, number }`: let an origin fork's pull run here: approve its current head so its check and preview start, through `POST …/pulls/:number/approve-here`'s action and refusals (a writer's, never an agent's, never your own pull); answers `says`, the `commit` approved and `url`; a later push needs approving again | yes | | |
| 81 | 82 | | `threads` | `{ repo, number, anchor?, resolved? }`: a pull's review threads with their comments; with `anchor` (from the list) resolve it (`resolved` true, the default) or reopen it (false), by the API's rules: a writer or someone who commented in the thread | yes | |
| 82 | 83 | | `usage` | `{ repo, days? }`: what the crew's runs spent — tokens, cost, wall time — by subscription, agent, issue, and each account's 5-hour and weekly standing; a writer's | | |
| 83 | 84 | | `labels` | `{ repo, number, labels }`: set an issue's or a pull's labels to exactly these (`[]` clears); only labels the repository has, by a writer | yes | |
src/http/mcp.ts +68 −21
| @@ -69,6 +69,7 @@ import { | ||
| 69 | 69 | unlinkIssue, |
| 70 | 70 | } from "../actions/dependencies.ts"; |
| 71 | 71 | import { |
| 72 | approveToRun, | |
| 72 | 73 | pullThreads, |
| 73 | 74 | resolveReviewThread, |
| 74 | 75 | submitReview, |
| @@ -619,7 +620,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 619 | 620 | { |
| 620 | 621 | name: "tell", |
| 621 | 622 | description: |
| 622 | "Tell an app's crew what should change (first line is the title). Without `repo` it is only kept; answers a thought id.", | |
| 623 | "Tell an app's crew what to change (first line is the title). Without `repo` it is kept; answers a thought id.", | |
| 623 | 624 | inputSchema: { |
| 624 | 625 | type: "object", |
| 625 | 626 | properties: { |
| @@ -757,7 +758,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 757 | 758 | { |
| 758 | 759 | name: "issue", |
| 759 | 760 | description: |
| 760 | "Read one issue with its comments, `blockedBy` and `blocks`. A crew agent sees `untrusted: true` on text by non-writers.", | |
| 761 | "One issue with comments, `blockedBy`, `blocks`. A crew agent sees `untrusted: true` on non-writers' text.", | |
| 761 | 762 | inputSchema: { |
| 762 | 763 | type: "object", |
| 763 | 764 | properties: { |
| @@ -1110,7 +1111,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1110 | 1111 | { |
| 1111 | 1112 | name: "asks_act", |
| 1112 | 1113 | description: |
| 1113 | "Decide many asks: dismiss, decline, ship (never undone), close (`reason`), mute, replan. `items`: ids from `asks`, or `issue:<id>`.", | |
| 1114 | "Decide many asks: dismiss, decline, ship (final), close (`reason`), mute, replan. `items`: `asks` ids/`issue:<id>`.", | |
| 1114 | 1115 | inputSchema: { |
| 1115 | 1116 | type: "object", |
| 1116 | 1117 | properties: { |
| @@ -1134,7 +1135,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1134 | 1135 | { |
| 1135 | 1136 | name: "asks_decide", |
| 1136 | 1137 | description: |
| 1137 | "Let the decider answer a hand-over (`item` is the row's `parked:<id>`). Only a sure set_aside (70%+) clears the card.", | |
| 1138 | "Let the decider answer a hand-over (`item`: the row's `parked:<id>`). Only a sure set_aside (70%+) clears it.", | |
| 1138 | 1139 | inputSchema: { |
| 1139 | 1140 | type: "object", |
| 1140 | 1141 | properties: { item: { type: "string", maxLength: 80 } }, |
| @@ -1298,7 +1299,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1298 | 1299 | { |
| 1299 | 1300 | name: "issue_teams", |
| 1300 | 1301 | description: |
| 1301 | "Name the crew teams (design, data-science, security, platform) on an issue: at most two; each reviews the closing pull.", | |
| 1302 | "Name crew teams (design, data-science, security, platform) on an issue: at most two; each reviews its closing pull.", | |
| 1302 | 1303 | inputSchema: { |
| 1303 | 1304 | type: "object", |
| 1304 | 1305 | properties: { |
| @@ -1371,7 +1372,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1371 | 1372 | { |
| 1372 | 1373 | name: "now", |
| 1373 | 1374 | description: |
| 1374 | "What the crew is doing now across your apps: who, on what, since when, cost so far; what waits on your review first.", | |
| 1375 | "What the crew is doing now across your apps: who, on what, since when, cost; what waits on your review first.", | |
| 1375 | 1376 | inputSchema: { type: "object", properties: {} }, |
| 1376 | 1377 | writes: false, |
| 1377 | 1378 | run(ctx, user) { |
| @@ -1542,7 +1543,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1542 | 1543 | { |
| 1543 | 1544 | name: "model_grant", |
| 1544 | 1545 | description: |
| 1545 | "Give a person's account a capped monthly model grant in dollars (`usdPerMonth` 0 takes it back). Person admins only.", | |
| 1546 | "Give a person a capped monthly model grant in dollars (`usdPerMonth` 0 takes it back). Person admins only.", | |
| 1546 | 1547 | inputSchema: { |
| 1547 | 1548 | type: "object", |
| 1548 | 1549 | properties: { |
| @@ -1686,7 +1687,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1686 | 1687 | { |
| 1687 | 1688 | name: "model_ceiling", |
| 1688 | 1689 | description: |
| 1689 | "Set an account's daily and per-run model spend ceilings in dollars; a run past either does not start.", | |
| 1690 | "Set an account's daily and per-run model spend ceilings in dollars; a run past either won't start.", | |
| 1690 | 1691 | inputSchema: { |
| 1691 | 1692 | type: "object", |
| 1692 | 1693 | properties: { |
| @@ -1750,7 +1751,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1750 | 1751 | { |
| 1751 | 1752 | name: "outsiders", |
| 1752 | 1753 | description: |
| 1753 | "Whether people who cannot write an app may direct its crew (off by default). Without `on`, says which.", | |
| 1754 | "Whether people who cannot write an app may direct its crew (off by default). Without `on`, reads it.", | |
| 1754 | 1755 | inputSchema: { |
| 1755 | 1756 | type: "object", |
| 1756 | 1757 | properties: { |
| @@ -1827,7 +1828,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1827 | 1828 | { |
| 1828 | 1829 | name: "decisions_by", |
| 1829 | 1830 | description: |
| 1830 | "The standing rule for a repository's parked hand-over cards: `me`, `decider`, or `decider_tell`. Without `by`, reads it.", | |
| 1831 | "The rule for a repository's parked hand-over cards: `me`, `decider`, `decider_tell`. Without `by`, reads it.", | |
| 1831 | 1832 | inputSchema: { |
| 1832 | 1833 | type: "object", |
| 1833 | 1834 | properties: { |
| @@ -2201,7 +2202,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2201 | 2202 | { |
| 2202 | 2203 | name: "spawn", |
| 2203 | 2204 | description: |
| 2204 | "Spawn a child forge with the named apps and the crew's briefs. Plans first (dryRun false spawns).", | |
| 2205 | "Spawn a child forge with the named apps and crew briefs. Plans first (dryRun false spawns).", | |
| 2205 | 2206 | inputSchema: { |
| 2206 | 2207 | type: "object", |
| 2207 | 2208 | properties: { |
| @@ -2336,7 +2337,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2336 | 2337 | { |
| 2337 | 2338 | name: "forges", |
| 2338 | 2339 | description: |
| 2339 | "The forges you sent from here (an admin's list): name, address, whom for, apps, claimed or not, last activity.", | |
| 2340 | "The forges you sent from here (admin): name, address, whom for, apps, claimed or not, last activity.", | |
| 2340 | 2341 | inputSchema: { type: "object", properties: {} }, |
| 2341 | 2342 | writes: false, |
| 2342 | 2343 | async run(ctx, user) { |
| @@ -2355,7 +2356,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2355 | 2356 | { |
| 2356 | 2357 | name: "claim_link", |
| 2357 | 2358 | description: |
| 2358 | "A new claim link for an unclaimed child forge, only with `reveal: true`; the old one then stops at once. Nothing changes without it.", | |
| 2359 | "A new claim link for an unclaimed child forge, only with `reveal: true`; the old one stops. Else nothing changes.", | |
| 2359 | 2360 | inputSchema: { |
| 2360 | 2361 | type: "object", |
| 2361 | 2362 | properties: { |
| @@ -2377,7 +2378,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2377 | 2378 | { |
| 2378 | 2379 | name: "take_updates", |
| 2379 | 2380 | description: |
| 2380 | "Take the parent forge's updates into a fork: one pull on a spawned forge; otherwise a fast-forward or clean merge.", | |
| 2381 | "Take the parent's updates into a fork: one pull on a spawned forge; else a fast-forward or clean merge.", | |
| 2381 | 2382 | inputSchema: { |
| 2382 | 2383 | type: "object", |
| 2383 | 2384 | properties: { repo: REPO_ARG }, |
| @@ -2597,7 +2598,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2597 | 2598 | { |
| 2598 | 2599 | name: "asked", |
| 2599 | 2600 | description: |
| 2600 | "What people asked the crew for, in repositories you can write: by default what has nothing merged yet, oldest first.", | |
| 2601 | "What people asked the crew for, in repositories you can write: by default nothing merged yet, oldest first.", | |
| 2601 | 2602 | inputSchema: { |
| 2602 | 2603 | type: "object", |
| 2603 | 2604 | properties: { |
| @@ -2922,7 +2923,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2922 | 2923 | { |
| 2923 | 2924 | name: "front_page", |
| 2924 | 2925 | description: |
| 2925 | "The forge's front page as a stranger sees it. A site admin also gets the picks and sets them with `pinned`, `hidden`, `weights`.", | |
| 2926 | "The front page as a stranger sees it. A site admin also gets the picks and sets `pinned`, `hidden`, `weights`.", | |
| 2926 | 2927 | inputSchema: { |
| 2927 | 2928 | type: "object", |
| 2928 | 2929 | properties: { |
| @@ -3001,7 +3002,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3001 | 3002 | { |
| 3002 | 3003 | name: "milestones", |
| 3003 | 3004 | description: |
| 3004 | "How far each thing asked for is. With `app`: the plan's top-level limbs with done/total, building and recent merges.", | |
| 3005 | "How far each thing asked for is. With `app`: the plan's top limbs with done/total, building and recent merges.", | |
| 3005 | 3006 | inputSchema: { |
| 3006 | 3007 | type: "object", |
| 3007 | 3008 | properties: { |
| @@ -3161,7 +3162,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3161 | 3162 | { |
| 3162 | 3163 | name: "limb", |
| 3163 | 3164 | description: |
| 3164 | "One action on a plan limb: `defer`, `resume` (`pillar`), `close` (`reason`), `raise`/`lower` (`under`), `replan`, `takeback`, `undo`.", | |
| 3165 | "A limb action: `defer`, `resume` (`pillar`), `close` (`reason`), `raise`/`lower` (`under`), `replan`, `takeback`, `undo`.", | |
| 3165 | 3166 | inputSchema: { |
| 3166 | 3167 | type: "object", |
| 3167 | 3168 | properties: { |
| @@ -3254,7 +3255,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3254 | 3255 | { |
| 3255 | 3256 | name: "returns", |
| 3256 | 3257 | description: |
| 3257 | "What the crew's tokens bought over the last days (1–90, default 7): dollars, runs, changes landed, cost per change.", | |
| 3258 | "What the crew's tokens bought over `days` (1–90, default 7): dollars, runs, changes landed, cost per change.", | |
| 3258 | 3259 | inputSchema: { |
| 3259 | 3260 | type: "object", |
| 3260 | 3261 | properties: { |
| @@ -3332,6 +3333,52 @@ const TOOLS: readonly Tool[] = [ | ||
| 3332 | 3333 | }); |
| 3333 | 3334 | }, |
| 3334 | 3335 | }, |
| 3336 | { | |
| 3337 | name: "approve_here", | |
| 3338 | description: | |
| 3339 | "Let an origin fork's pull run here, at its current head.", | |
| 3340 | inputSchema: { | |
| 3341 | type: "object", | |
| 3342 | properties: { | |
| 3343 | repo: REPO_ARG, | |
| 3344 | number: { type: "integer", minimum: 1 }, | |
| 3345 | }, | |
| 3346 | required: ["repo", "number"], | |
| 3347 | }, | |
| 3348 | writes: true, | |
| 3349 | async run(ctx, user, args) { | |
| 3350 | const repo = repoArg(ctx, user, args); | |
| 3351 | if (isAnswer(repo)) return repo; | |
| 3352 | const n = args["number"]; | |
| 3353 | const pull = | |
| 3354 | typeof n === "number" && Number.isInteger(n) && n > 0 | |
| 3355 | ? getPull(ctx.app.db, repo.id, n) | |
| 3356 | : undefined; | |
| 3357 | if (pull === undefined || !mayView(ctx.app.db, repo, pull, user)) | |
| 3358 | return bad("no_such_pull", `no pull #${String(n)}`); | |
| 3359 | const done = await approveToRun(ctx.app, user, repo, pull); | |
| 3360 | if (!done.ok) { | |
| 3361 | const error = done.error; | |
| 3362 | return bad( | |
| 3363 | "refused", | |
| 3364 | error === "self_review" | |
| 3365 | ? "You cannot approve your own pull request." | |
| 3366 | : error === "not_foreign" | |
| 3367 | ? "This pull needs no approval to run." | |
| 3368 | : error === "not_open" | |
| 3369 | ? "This pull is closed." | |
| 3370 | : error === "forbidden" | |
| 3371 | ? "Letting a pull run needs write access, and a person's." | |
| 3372 | : "That pull could not be approved.", | |
| 3373 | ); | |
| 3374 | } | |
| 3375 | return good({ | |
| 3376 | says: `Approved to run at ${done.value.commitOid.slice(0, 7)}; a new push needs approving again.`, | |
| 3377 | commit: done.value.commitOid, | |
| 3378 | url: `/${repo.ownerName}/${repo.name}/pulls/${pull.number}`, | |
| 3379 | }); | |
| 3380 | }, | |
| 3381 | }, | |
| 3335 | 3382 | { |
| 3336 | 3383 | name: "threads", |
| 3337 | 3384 | description: |
| @@ -3809,7 +3856,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3809 | 3856 | { |
| 3810 | 3857 | name: "access", |
| 3811 | 3858 | description: |
| 3812 | "What outside agents tried: the redacted log of non-browser requests to public paths, newest first, max 500. Forge admin.", | |
| 3859 | "What outside agents tried: redacted non-browser requests to public paths, newest first, max 500. Forge admin.", | |
| 3813 | 3860 | inputSchema: { |
| 3814 | 3861 | type: "object", |
| 3815 | 3862 | properties: { |
| @@ -3888,7 +3935,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3888 | 3935 | { |
| 3889 | 3936 | name: "flow", |
| 3890 | 3937 | description: |
| 3891 | "The forge's pipeline (forge admin): per stage counts, `oldestWaiting`, `capacity`, the bottleneck, merge `queue`, `reviewing` per reviewer.", | |
| 3938 | "The pipeline (forge admin): stage counts, `oldestWaiting`, `capacity`, bottleneck, merge `queue`, `reviewing`.", | |
| 3892 | 3939 | inputSchema: { type: "object", properties: {} }, |
| 3893 | 3940 | writes: false, |
| 3894 | 3941 | run(ctx, user) { |
test/mcp-approve-here.test.ts added +245
| @@ -0,0 +1,245 @@ | ||
| 1 | /** | |
| 2 | * The `approve_here` tool over MCP: the route's action, rules and refusals — | |
| 3 | * a writer approves an origin fork's pull at its head, a reader, an agent and | |
| 4 | * a stranger are refused, a later push waits, and bad input stops at the edge. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 12 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { pullMayRun } from "../src/core/pull_trust.ts"; | |
| 15 | import { getPull } from "../src/core/pulls.ts"; | |
| 16 | import type { Repo } from "../src/core/repos.ts"; | |
| 17 | import { createToken } from "../src/core/tokens.ts"; | |
| 18 | import { createUser, type User } from "../src/core/users.ts"; | |
| 19 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 20 | import { promote } from "./helpers/members.ts"; | |
| 21 | ||
| 22 | describe("the approve_here tool over MCP", () => { | |
| 23 | let dataDir: string; | |
| 24 | let app: App; | |
| 25 | let servers: Servers; | |
| 26 | let alice: User; | |
| 27 | let carol: User; | |
| 28 | let dave: User; | |
| 29 | let lib: Repo; | |
| 30 | let tokens: Record<string, string>; | |
| 31 | let nextId = 1; | |
| 32 | ||
| 33 | const call = async (token: string, name: string, args: unknown) => { | |
| 34 | const res = await fetch(`${servers.url}/mcp`, { | |
| 35 | method: "POST", | |
| 36 | headers: { | |
| 37 | "content-type": "application/json", | |
| 38 | accept: "application/json, text/event-stream", | |
| 39 | authorization: `Bearer ${token}`, | |
| 40 | }, | |
| 41 | body: JSON.stringify({ | |
| 42 | jsonrpc: "2.0", | |
| 43 | id: nextId++, | |
| 44 | method: "tools/call", | |
| 45 | params: { name, arguments: args }, | |
| 46 | }), | |
| 47 | }); | |
| 48 | if (res.status === 401) return { error: "unauthorized" }; | |
| 49 | const body = (await res.json()) as any; | |
| 50 | if (body.error) return { error: body.error.message as string }; | |
| 51 | const text: string = body.result.content[0].text; | |
| 52 | return body.result.isError === true | |
| 53 | ? { error: text } | |
| 54 | : { value: JSON.parse(text) }; | |
| 55 | }; | |
| 56 | const tool = (token: string, args: unknown) => | |
| 57 | call(token, "approve_here", args); | |
| 58 | ||
| 59 | let carolFork: Repo | undefined; | |
| 60 | let n = 0; | |
| 61 | async function originPull() { | |
| 62 | const branch = `b${++n}`; | |
| 63 | if (!carolFork) { | |
| 64 | const forked = await forkRepo(app, carol, lib, "fork"); | |
| 65 | if (!forked.ok) throw new Error(String(forked.error)); | |
| 66 | carolFork = forked.value; | |
| 67 | } | |
| 68 | const committed = await commitToBranch(app, carol, carolFork, { | |
| 69 | branch, | |
| 70 | message: "From the origin's fork", | |
| 71 | files: [{ path: `${branch}.md`, content: "hi\n" }], | |
| 72 | }); | |
| 73 | if (!committed.ok) throw new Error(JSON.stringify(committed.error)); | |
| 74 | const opened = await openPull(app, carol, lib, { | |
| 75 | title: "Theirs", | |
| 76 | baseBranch: "main", | |
| 77 | headBranch: branch, | |
| 78 | headRepo: carolFork, | |
| 79 | }); | |
| 80 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 81 | app.db.run("UPDATE pull SET origin_head_repo = ?1 WHERE issue_id = ?2", [ | |
| 82 | "octo/lib", | |
| 83 | opened.value.id, | |
| 84 | ]); | |
| 85 | return { | |
| 86 | pull: getPull(app.db, lib.id, opened.value.number)!, | |
| 87 | head: committed.value.commitOid, | |
| 88 | }; | |
| 89 | } | |
| 90 | ||
| 91 | beforeAll(async () => { | |
| 92 | dataDir = await mkdtemp(join(tmpdir(), "forge-mcp-approve-here-")); | |
| 93 | app = createApp({ dataDir, port: 0 }); | |
| 94 | servers = await serve(app); | |
| 95 | const mk = async (username: string, first = false) => { | |
| 96 | const made = await createUser(app.db, { | |
| 97 | origin: "seed", | |
| 98 | trusted: true, | |
| 99 | username, | |
| 100 | email: `${username}@forge.local`, | |
| 101 | password: "a-good-passphrase", | |
| 102 | adminIfFirst: first, | |
| 103 | }); | |
| 104 | if (!made.ok) throw new Error(made.error); | |
| 105 | return made.value; | |
| 106 | }; | |
| 107 | alice = await mk("alice", true); | |
| 108 | carol = await mk("carol"); | |
| 109 | dave = await mk("dave"); | |
| 110 | promote(app.db, alice, carol, dave); | |
| 111 | const made = await createRepo(app, alice, { | |
| 112 | name: "lib", | |
| 113 | visibility: "public", | |
| 114 | }); | |
| 115 | if (!made.ok) throw new Error(String(made.error)); | |
| 116 | lib = made.value; | |
| 117 | await commitToBranch(app, alice, lib, { | |
| 118 | message: "seed", | |
| 119 | files: [{ path: "README.md", content: "# lib\n" }], | |
| 120 | }); | |
| 121 | const bot = await createAgent(app, alice, { username: "bot" }); | |
| 122 | if (!bot.ok) throw new Error(String(bot.error)); | |
| 123 | expect(addToCrew(app, alice, lib, "bot").ok).toBe(true); | |
| 124 | const botUser = bot.value.user; | |
| 125 | tokens = { | |
| 126 | alice: createToken(app.db, alice.id, "rw", "rw").token, | |
| 127 | dave: createToken(app.db, dave.id, "rw", "rw").token, | |
| 128 | bot: createToken(app.db, botUser.id, "rw", "rw").token, | |
| 129 | }; | |
| 130 | }, 30_000); | |
| 131 | ||
| 132 | afterAll(async () => { | |
| 133 | servers.stop(); | |
| 134 | app.close(); | |
| 135 | await rm(dataDir, { recursive: true, force: true }); | |
| 136 | }); | |
| 137 | ||
| 138 | test("it is listed with a schema", async () => { | |
| 139 | const res = await fetch(`${servers.url}/mcp`, { | |
| 140 | method: "POST", | |
| 141 | headers: { | |
| 142 | "content-type": "application/json", | |
| 143 | accept: "application/json, text/event-stream", | |
| 144 | authorization: `Bearer ${tokens["alice"]}`, | |
| 145 | }, | |
| 146 | body: JSON.stringify({ jsonrpc: "2.0", id: 999, method: "tools/list" }), | |
| 147 | }); | |
| 148 | const body = (await res.json()) as any; | |
| 149 | const t = body.result.tools.find((x: any) => x.name === "approve_here"); | |
| 150 | expect(t.inputSchema.required).toEqual(["repo", "number"]); | |
| 151 | }); | |
| 152 | ||
| 153 | test("a writer approves the head, and a later push needs approving again", async () => { | |
| 154 | const { pull, head } = await originPull(); | |
| 155 | expect(pullMayRun(app.db, lib, pull, head)).toBe(false); | |
| 156 | const done = await tool(tokens["alice"]!, { | |
| 157 | repo: "alice/lib", | |
| 158 | number: pull.number, | |
| 159 | }); | |
| 160 | expect(done.value.commit).toBe(head); | |
| 161 | expect(done.value.says).toContain(head.slice(0, 7)); | |
| 162 | expect(done.value.url).toBe(`/alice/lib/pulls/${pull.number}`); | |
| 163 | expect(pullMayRun(app.db, lib, pull, head)).toBe(true); | |
| 164 | ||
| 165 | const again = await commitToBranch(app, carol, carolFork!, { | |
| 166 | branch: pull.headBranch, | |
| 167 | message: "Again", | |
| 168 | files: [{ path: "again.md", content: "again\n" }], | |
| 169 | }); | |
| 170 | if (!again.ok) throw new Error(JSON.stringify(again.error)); | |
| 171 | expect(pullMayRun(app.db, lib, pull, again.value.commitOid)).toBe(false); | |
| 172 | }, 30_000); | |
| 173 | ||
| 174 | test("a reader, an agent and a stranger are refused as the route refuses", async () => { | |
| 175 | const { pull, head } = await originPull(); | |
| 176 | const args = { repo: "alice/lib", number: pull.number }; | |
| 177 | for (const who of ["dave", "bot"]) { | |
| 178 | const refused = await tool(tokens[who]!, args); | |
| 179 | expect(refused.error).toContain("needs write access, and a person's"); | |
| 180 | } | |
| 181 | const stranger = await tool("nope", args); | |
| 182 | expect(stranger.error).toBe("unauthorized"); | |
| 183 | expect(pullMayRun(app.db, lib, pull, head)).toBe(false); | |
| 184 | }, 30_000); | |
| 185 | ||
| 186 | test("your own pull and a closed pull are refused in their own words", async () => { | |
outdated
The title says "your own pull", but no test here opens one, so the |
||
| 187 | const mine = await originPull(); | |
| 188 | app.db.run("UPDATE issue SET author_id = ?1 WHERE id = ?2", [ | |
| 189 | alice.id, | |
| 190 | mine.pull.id, | |
| 191 | ]); | |
| 192 | const own = await tool(tokens["alice"]!, { | |
| 193 | repo: "alice/lib", | |
| 194 | number: mine.pull.number, | |
| 195 | }); | |
| 196 | expect(own.error).toContain("cannot approve your own"); | |
| 197 | expect(pullMayRun(app.db, lib, mine.pull, mine.head)).toBe(false); | |
| 198 | ||
| 199 | const closed = await originPull(); | |
| 200 | app.db.run("UPDATE issue SET state = 'closed' WHERE id = ?1", [ | |
| 201 | closed.pull.id, | |
| 202 | ]); | |
| 203 | const shut = await tool(tokens["alice"]!, { | |
| 204 | repo: "alice/lib", | |
| 205 | number: closed.pull.number, | |
| 206 | }); | |
| 207 | expect(shut.error).toContain("is closed"); | |
| 208 | }, 30_000); | |
| 209 | ||
| 210 | test("a plain pull and bad arguments are refused in a sentence", async () => { | |
| 211 | const plain = await openPlain(); | |
| 212 | const needsNone = await tool(tokens["alice"]!, { | |
| 213 | repo: "alice/lib", | |
| 214 | number: plain, | |
| 215 | }); | |
| 216 | expect(needsNone.error).toContain("needs no approval"); | |
| 217 | for (const args of [ | |
| 218 | {}, | |
| 219 | { repo: "alice/lib" }, | |
| 220 | { repo: "alice/lib", number: 0 }, | |
| 221 | { repo: "alice/lib", number: "1" }, | |
| 222 | { repo: "alice/lib", number: 9999 }, | |
| 223 | { repo: "nobody/nothing", number: 1 }, | |
| 224 | ]) { | |
| 225 | const refused = await tool(tokens["alice"]!, args); | |
| 226 | expect(refused.error).toBeString(); | |
| 227 | } | |
| 228 | }, 30_000); | |
| 229 | ||
| 230 | async function openPlain() { | |
| 231 | const made = await commitToBranch(app, alice, lib, { | |
| 232 | branch: "plain", | |
| 233 | message: "plain", | |
| 234 | files: [{ path: "plain.txt", content: "p\n" }], | |
| 235 | }); | |
| 236 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 237 | const opened = await openPull(app, alice, lib, { | |
| 238 | title: "plain", | |
| 239 | baseBranch: "main", | |
| 240 | headBranch: "plain", | |
| 241 | }); | |
| 242 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 243 | return opened.value.number; | |
| 244 | } | |
| 245 | }); |
test/mcp.test.ts +1
| @@ -246,6 +246,7 @@ describe("the forge over MCP", () => { | ||
| 246 | 246 | "limb", |
| 247 | 247 | "returns", |
| 248 | 248 | "review", |
| 249 | "approve_here", | |
| 249 | 250 | "threads", |
| 250 | 251 | "spend", |
| 251 | 252 | "usage", |
new above
offline
toBeString()passes for any refusal, so it does not show that dave and bot are refused "as the route refuses them". AsserttoContain("write access"), and add a closed-pull case fornot_open.