Public: anyone can read this; the crew can change it.
An MCP tool call with an argument of the wrong type or an unknown name is refused naming the argument, not answered as if it were absent #15377
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15362-an-mcp-tool-call-with-an-argument-of-the → main 0 commits fork 4 threads · 4 unresolved
77 files
changed +426
−125
docs/MCP.md +16
| @@ -223,6 +223,22 @@ reached this way only by a person who is an admin. | ||
| 223 | 223 | |
| 224 | 224 | ## Arguments, in full |
| 225 | 225 | |
| 226 | Every call is held to the tool's own `inputSchema` before anything is held, asked, recorded or | |
| 227 | run, a stranger's `explore` and `search` as well (`badArgument` in `src/http/mcp/shared.ts`). The | |
| 228 | first argument that does not fit is refused naming it, with what was expected and one corrected | |
| 229 | example; nothing runs: | |
| 230 | ||
| 231 | - a wrong type: `invalid: argument "limit" is "many"; expected integer from 1 to 100. Example: {"limit": 1}` | |
| 232 | - outside `enum`: `invalid: argument "kind" is "bogus"; expected one of "all", "issues", "repos", "code". Example: {"kind": "all"}` | |
| 233 | - outside `minimum`/`maximum`: `invalid: argument "limit" is 0; expected integer from 1 to 100. Example: {"limit": 1}` | |
| 234 | - over `maxLength`: `invalid: argument "q" is 201 characters long; expected string of at most 200 characters. Example: {"q": "text"}` (a long value is measured, never echoed; one named like a secret or token is never shown) | |
| 235 | - a name the tool does not take: `invalid: unknown argument "bogus": this tool takes q, kind, repo, … Example: {"q": "text"}` | |
| 236 | - a `required` one left out: `invalid: argument "repo" is missing; expected string. Example: {"repo": "text"}` | |
| 237 | ||
| 238 | Each is followed by the tool's usual `Next:` step. Only the top level is read; nested shapes | |
| 239 | (items of a list, keys of an object) are the tool's own to refuse, and `spawn`, whose schema says | |
| 240 | `additionalProperties: true`, takes extra keys. | |
| 241 | ||
| 226 | 242 | `tools/list` keeps every argument description to 60 bytes (`test/mcp-size.test.ts` |
| 227 | 243 | enforces it); `dryRun` reads `false to apply` on every tool that takes it. The |
| 228 | 244 | longer sentences: |
src/http/mcp.ts +20 −1
| @@ -47,7 +47,7 @@ import { CONTRIBUTE_TOKEN_HINT, CONTRIBUTE_TOKEN_WORDS, mintContributeToken } fr | ||
| 47 | 47 | import { BODY_MAX, REQUEST_MAX, TITLE_MAX } from "../core/reports.ts"; |
| 48 | 48 | import { adminRefusal, everydayOf } from "../core/everyday.ts"; |
| 49 | 49 | import { claimDone, completeWrite, dropWrite, recordWrite } from "../core/conversation_writes.ts"; |
| 50 | import { type Args, alreadyDone, notAdminTool, listable, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, destroysTo, readThrough, type ToolShape } from "./mcp/shared.ts"; | |
| 50 | import { type Args, badArgument, alreadyDone, notAdminTool, listable, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, destroysTo, readThrough, type ToolShape } from "./mcp/shared.ts"; | |
| 51 | 51 | import { CONVERSATION_BRIEF } from "../crew/conversation_brief.ts"; |
| 52 | 52 | import { readWidget as readKept, recordCard, recordWidget, shownLine } from "../core/talk_voice.ts"; |
| 53 | 53 | import { stepOf } from "../core/talk_steps.ts"; |
| @@ -290,6 +290,21 @@ function rpcOne( | ||
| 290 | 290 | ctx.auth.through === undefined || tool === undefined ? undefined : (tool.refusedToAgent?.(args) ?? destroysTo(user, tool, args)); |
| 291 | 291 | if (never !== undefined) |
| 292 | 292 | return reply({ content: [{ type: "text", text: `forbidden: ${never}` }], isError: true, hint: hintForCode("forbidden") }); |
| 293 | // Every argument is held to the tool's own schema, a read as a write, before anything is | |
| 294 | // held, asked, recorded or run: a call that does not fit is refused by name and never runs. | |
| 295 | // Only a tool this caller may see says so, and a write a read-only token may not make is | |
| 296 | // still the scope floor's to refuse below. | |
| 297 | const shapeRead = | |
| 298 | tool !== undefined && | |
| 299 | visible(tool, ctx, user) && | |
| 300 | !(tool.writes && !plansOnly(tool, args) && !scopeAllows(ctx.auth.scope ?? "ro", "rw")); | |
| 301 | const wrongArg = shapeRead ? badArgument(tool.inputSchema, args) : undefined; | |
| 302 | if (tool !== undefined && wrongArg !== undefined) | |
| 303 | return reply({ | |
| 304 | content: [{ type: "text", text: `invalid: ${withNextStep(tool, "invalid", wrongArg)}` }], | |
| 305 | isError: true, | |
| 306 | hint: hintForCode("invalid"), | |
| 307 | }); | |
| 293 | 308 | // A write the tool would refuse this person anyway is answered as refused now, in its own |
| 294 | 309 | // words, and never held for a yes that could only fail. |
| 295 | 310 | const askable = |
| @@ -477,6 +492,10 @@ async function readAnswer(ctx: Ctx, id: unknown, name: string, args: Args): Prom | ||
| 477 | 492 | id, |
| 478 | 493 | result: { content: [{ type: "text", text: t }], ...(isError ? { isError, hint: hintOfText(t) } : {}), ...extra }, |
| 479 | 494 | }); |
| 495 | // A stranger's arguments are held to the same schema as a signed-in caller's. | |
| 496 | const schema = TOOLS.find((t) => t.name === name)?.inputSchema; | |
| 497 | const wrongArg = schema === undefined ? undefined : badArgument(schema, args); | |
| 498 | if (wrongArg !== undefined) return text(`invalid: ${wrongArg}`, true); | |
| 480 | 499 | let held: ReturnType<typeof strangerCodeSearch> | undefined; |
| 481 | 500 | if (name === "search" && typeof args["q"] === "string") { |
| 482 | 501 | const kind = searchKind(typeof args["kind"] === "string" ? args["kind"] : null); |
src/http/mcp/tools/app_deploy.ts +1 −1
| @@ -9,7 +9,7 @@ export const tool: Tool = { | ||
| 9 | 9 | name: "app_deploy", |
| 10 | 10 | doc: "`{ repo, env, action }`: `redeploy` or `stop` an app's `production` or a pull's `pull-N` preview; a writer's, queued as `POST …/app/:env/redeploy` and `…/stop` are; answers `{ queued, run }` or `{ stopped }`. `{ repo, action: \"pull\" }` runs an adapter's pull now as `POST …/app/pull` does; answers `{ run }`. `{ repo, action: \"schedules\" }` lists the app's schedules (`{ items }`, as `GET …/schedules`); `run_schedule`, `pause_schedule` or `resume_schedule` with `name` steers one, a writer's, as `POST …/schedules/:name/:action` does. `jobs` lists the durable job runs (`{ items }`, as `GET …/jobs`); `cancel_job` or `retry_job` with `name` the run id steers one, as `POST …/jobs/:id/:action` does", |
| 11 | 11 | description: |
| 12 | "Redeploy or stop an env, pull, list and steer schedules and jobs.", | |
| 12 | "Redeploy or stop an env, pull, steer schedules and jobs.", | |
| 13 | 13 | inputSchema: { |
| 14 | 14 | type: "object", |
| 15 | 15 | properties: { |
src/http/mcp/tools/apps.ts +2 −2
| @@ -18,14 +18,14 @@ export const tool: Tool = { | ||
| 18 | 18 | name: "apps", |
| 19 | 19 | doc: "`{ action: \"restore\", repo? }` brings an archived app back (admin token); `{ archived? }`: your apps (`ui://forge/app` card): live or not, what is working, running `previews`, `crew` with a run now, and in migration mode `mode` and `migration {origin, done, total, state}` (`origin` is null to someone who may not see a private source). `{ repo, pulls: true, limit? }`: an adapter's pull runs, as `GET …/app/pulls` (`limit`); a reader's", |
| 20 | 20 | description: |
| 21 | "Apps you can see: live or not, where served, how each runs, what works.", | |
| 21 | "Apps you can see: live, where served, how each runs, what works.", | |
| 22 | 22 | inputSchema: { |
| 23 | 23 | type: "object", |
| 24 | 24 | properties: { |
| 25 | 25 | archived: { type: "boolean" }, |
| 26 | 26 | repo: { type: "string" }, |
| 27 | 27 | pulls: { type: "boolean" }, |
| 28 | limit: { type: "integer" }, | |
| 28 | limit: { type: "integer", minimum: 1, maximum: 100 }, | |
| 29 | 29 | action: { type: "string" }, |
| 30 | 30 | }, |
| 31 | 31 | }, |
src/http/mcp/tools/assign.ts +3 −5
| @@ -23,11 +23,9 @@ export const tool: Tool = { | ||
| 23 | 23 | run(ctx, user, args) { |
| 24 | 24 | const repo = repoArg(ctx, user, args); |
| 25 | 25 | if (isAnswer(repo)) return repo; |
| 26 | const kind = args["kind"]; | |
| 27 | if (kind !== "issue" && kind !== "pull") return bad("invalid", "kind is issue or pull"); | |
| 28 | const name = args["assignee"]; | |
| 29 | if (name !== null && typeof name !== "string") | |
| 30 | return bad("invalid_assignee", "assignee must be a username or null"); | |
| 26 | // `kind` and `assignee` were held to the schema before this runs (`badArgument`). | |
| 27 | const kind = args["kind"] as "issue" | "pull"; | |
| 28 | const name = args["assignee"] as string | null; | |
| 31 | 29 | const issue = issueArg(ctx, repo, args, "number"); |
| 32 | 30 | if ("ok" in issue) return issue; |
| 33 | 31 | if (issue.kind !== kind) return bad("no_such_issue", `no ${kind} #${issue.number}`); |
src/http/mcp/tools/backups_destination.ts +1 −1
| @@ -10,7 +10,7 @@ export const tool: Tool = { | ||
| 10 | 10 | inputSchema: { |
| 11 | 11 | type: "object", |
| 12 | 12 | properties: { |
| 13 | action: { enum: ["set", "forget"] }, | |
| 13 | action: { type: "string", enum: ["set", "forget"] }, | |
| 14 | 14 | endpoint: { type: "string" }, |
| 15 | 15 | bucket: { type: "string" }, |
| 16 | 16 | region: { type: "string" }, |
src/http/mcp/tools/boards.ts +1 −1
| @@ -16,7 +16,7 @@ export const tool: Tool = { | ||
| 16 | 16 | panel: { type: "integer", minimum: 0, maximum: 23, description: "Panel from 0." }, |
| 17 | 17 | from: { type: "string", maxLength: 64 }, |
| 18 | 18 | to: { type: "string", maxLength: 64 }, |
| 19 | step: { type: "string", maxLength: 16, description: "With panel: bucket seconds, or 5m." }, | |
| 19 | step: { type: ["string", "integer"], maxLength: 16, description: "With panel: bucket seconds, or 5m." }, | |
| 20 | 20 | }, |
| 21 | 21 | }, |
| 22 | 22 | writes: false, |
src/http/mcp/tools/events.ts +1 −1
| @@ -11,7 +11,7 @@ export const tool: Tool = { | ||
| 11 | 11 | properties: { |
| 12 | 12 | repo: REPO_ARG, |
| 13 | 13 | kind: { type: "string" }, |
| 14 | limit: { type: "integer" }, | |
| 14 | limit: { type: "integer", minimum: 1, maximum: 200 }, | |
| 15 | 15 | cursor: { type: "string" }, |
| 16 | 16 | after: { type: "string" }, |
| 17 | 17 | }, |
src/http/mcp/tools/find_tool.ts +1 −1
| @@ -4,7 +4,7 @@ import { FIND_MAX, matching, QUERY_MAX, talkLists } from "../catalog.ts"; | ||
| 4 | 4 | export const tool: Tool = { |
| 5 | 5 | name: "find_tool", |
| 6 | 6 | doc: "`{ query }`: the tools whose name, description or plain-word keywords match every word (else the most words); filler words are ignored, with their one-line description and schema; a tool found is callable at once, listed or not; Talk's own agent, which can call only what it is listed, is found only those. `tools/list` with `{\"all\": true}` is the full list", |
| 7 | description: "Find a tool by what it does; returns name, description and schema. Any tool is callable by name.", | |
| 7 | description: "Find a tool by what it does: name, description, schema. Any tool is callable by name.", | |
| 8 | 8 | inputSchema: { |
| 9 | 9 | type: "object", |
| 10 | 10 | properties: { query: { type: "string", maxLength: QUERY_MAX } }, |
src/http/mcp/tools/forges.ts +3 −4
| @@ -18,10 +18,10 @@ const sentSays = (n: number) => (n === 0 ? "This forge has sent no forges yet." | ||
| 18 | 18 | export const tool: Tool = { |
| 19 | 19 | name: "forges", |
| 20 | 20 | listedTo: "admin", |
| 21 | doc: "an admin's list of the forges sent from here: name, address, whom for, apps, claimed, stage (link not opened/opened/signed in/crew working/last tell, with stageAt; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large) or, with `plan`, grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge out of this forge's own process into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven and put back on any failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused lists the last 20 refused first asks; `kind` clients lists each client in the page's words, with runs and pulls so far, and tellAt while the crew is working; `action` resend + `forge`: previews, with `dryRun: false` replaces its link", | |
| 21 | doc: "the forges sent from here: name, address, whom for, apps, claimed, stage (link not opened/opened/signed in/crew working/last tell, with stageAt; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large); `plan` grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven, put back on failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused: the last 20 refused first asks; `kind` clients lists each client in the page's words, with runs, pulls, tellAt while working; `action` resend + `forge`: previews, with `dryRun: false` replaces its link", | |
| 22 | 22 | description: |
| 23 | "Forges sent from here (admin), clients, a forge plan or size.", | |
| 24 | inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["refused", "clients"] }, forge: { type: "string" }, plan: { type: "string" }, codes: { type: "boolean" }, code: { type: "object" }, revoke: { type: "string" }, archive: { type: ["string", "array"], items: { type: "string" } }, restore: { type: "string" }, sandbox: { type: "boolean" }, size: { type: "string" }, acknowledge: { type: "boolean" }, dryRun: { type: "boolean" } } }, | |
| 23 | "Forges sent from here (admin): clients, plans, sizes.", | |
| 24 | inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["refused", "clients"] }, action: { enum: ["resend"] }, forge: { type: "string" }, plan: { type: "string" }, codes: { type: "boolean" }, code: { type: "object" }, revoke: { type: "string" }, archive: { type: ["string", "array"], items: { type: "string" } }, restore: { type: "string" }, sandbox: { type: "boolean" }, size: { type: "string" }, acknowledge: { type: "boolean" }, dryRun: { type: "boolean" } } }, | |
| 25 | 25 | writes: true, |
| 26 | 26 | tier: "delete", |
| 27 | 27 | deletes: (args) => args["archive"] !== undefined, |
| @@ -32,7 +32,6 @@ export const tool: Tool = { | ||
| 32 | 32 | if (!user.isAdmin) |
| 33 | 33 | return bad("forbidden", "only an admin of this forge sees the forges it sent"); |
| 34 | 34 | if (args["action"] !== undefined) { |
| 35 | if (args["action"] !== "resend") return bad("invalid", "action is resend"); | |
| 36 | 35 | const name = str(args["forge"]); |
| 37 | 36 | if (args["dryRun"] !== false) { |
| 38 | 37 | const seen = await previewDoor(ctx, user, name); |
src/http/mcp/tools/hooks.ts +1 −1
| @@ -32,7 +32,7 @@ export const tool: Tool = { | ||
| 32 | 32 | secret: { type: "string", maxLength: 200 }, |
| 33 | 33 | id: { type: "string", maxLength: 64 }, |
| 34 | 34 | delivery: { type: "string", maxLength: 64 }, |
| 35 | limit: { type: "number" }, | |
| 35 | limit: { type: "integer", minimum: 1, maximum: 200 }, | |
| 36 | 36 | cursor: { type: "string" }, |
| 37 | 37 | }, |
| 38 | 38 | required: ["repo", "action"], |
src/http/mcp/tools/pinned_forge.ts +1 −1
| @@ -19,7 +19,7 @@ export const tool: Tool = { | ||
| 19 | 19 | app: { type: "string", maxLength: 140 }, |
| 20 | 20 | source: { type: "string", maxLength: 300 }, |
| 21 | 21 | version: { type: "string", maxLength: 40, description: "Commit id or tag." }, |
| 22 | place: { type: "string", maxLength: 200, description: "provider:datacenter:size, an orderable place of the account's provider; omit for the default." }, | |
| 22 | place: { type: "string", maxLength: 200, description: "provider:datacenter:size; omit for the default." }, | |
| 23 | 23 | config: { type: "object", description: "NAME: value; no secrets." }, |
| 24 | 24 | }, |
| 25 | 25 | required: ["verb"], |
src/http/mcp/tools/repo_labels.ts +1 −1
| @@ -19,7 +19,7 @@ export const tool: Tool = { | ||
| 19 | 19 | name: { type: "string" }, |
| 20 | 20 | color: { type: "string" }, |
| 21 | 21 | id: { type: "string" }, |
| 22 | limit: { type: "number" }, | |
| 22 | limit: { type: "integer", minimum: 1, maximum: 200 }, | |
| 23 | 23 | cursor: { type: "string" }, |
| 24 | 24 | }, |
| 25 | 25 | required: ["repo"], |
src/http/mcp/tools/search.ts +1 −1
| @@ -12,7 +12,7 @@ export const tool: Tool = { | ||
| 12 | 12 | properties: { |
| 13 | 13 | q: { type: "string", maxLength: MAX_QUERY_CHARS }, |
| 14 | 14 | kind: { type: "string", enum: ["all", "issues", "repos", "code"] }, |
| 15 | limit: { type: "integer" }, | |
| 15 | limit: { type: "integer", minimum: 1, maximum: 100 }, | |
| 16 | 16 | repo: { type: "string", maxLength: 140 }, |
| 17 | 17 | all: { type: "boolean" }, |
| 18 | 18 | }, |
src/http/mcp/tools/signup.ts −2
| @@ -36,8 +36,6 @@ export const tool: Tool = { | ||
| 36 | 36 | const links = readBillingLinks(ctx.app, user); |
| 37 | 37 | return links.ok ? good({ ...read.value, billingLinks: links.value }) : bad("not_found", "no such tool here"); |
| 38 | 38 | } |
| 39 | if (!(SIGNUP_MODES as readonly unknown[]).includes(args["mode"])) | |
| 40 | return bad("invalid_signup", SIGNUP_WORDS); | |
| 41 | 39 | if (args["dryRun"] !== false) |
| 42 | 40 | return good({ |
| 43 | 41 | says: `Would set signup from ${read.value.signup} to ${String(args["mode"])}. Send dryRun: false to change it.`, |
src/http/mcp/tools/spawn.ts +2
| @@ -10,6 +10,8 @@ export const tool: Tool = { | ||
| 10 | 10 | "Spawn a child forge. Plans first.", |
| 11 | 11 | inputSchema: { |
| 12 | 12 | type: "object", |
| 13 | // Open on purpose: a `modelKey` is refused in its own words, never as an unknown name. | |
| 14 | additionalProperties: true, | |
| 13 | 15 | properties: { |
| 14 | 16 | name: { |
| 15 | 17 | type: "string", |
src/http/mcp/tools/wait_for.ts −2
| @@ -19,8 +19,6 @@ export const tool: Tool = { | ||
| 19 | 19 | }, |
| 20 | 20 | writes: true, |
| 21 | 21 | run(ctx, user, args) { |
| 22 | if (args["stop"] !== undefined && typeof args["stop"] !== "boolean") | |
| 23 | return bad("invalid_stop", "stop is true or false"); | |
| 24 | 22 | const repo = planRepo(ctx, user, args); |
| 25 | 23 | if (isAnswer(repo)) return repo; |
| 26 | 24 | const issue = issueArg(ctx, repo, args, "issue"); |
test/archive-mcp.test.ts +1 −1
| @@ -105,7 +105,7 @@ test("an admin needs an admin token; then archives and wakes", async () => { | ||
| 105 | 105 | const small = await mcp(tok["founderRw"]!, { repo: "acme/svc", archived: true, dryRun: false }); |
| 106 | 106 | expect(small.error).toContain("forbidden"); |
| 107 | 107 | expect(archived()).toBe(false); |
| 108 | expect((await mcp(tok["founder"]!, { repo: "acme/svc", archived: "yes" })).error).toContain("true or false"); | |
| 108 | expect((await mcp(tok["founder"]!, { repo: "acme/svc", archived: "yes" })).error).toContain('argument "archived"'); | |
| 109 | 109 | const set = await mcp(tok["founder"]!, { repo: "acme/svc", archived: true, dryRun: false }); |
| 110 | 110 | expect(set.value).toMatchObject({ dryRun: false, archived: true, was: false }); |
| 111 | 111 | expect(archived()).toBe(true); |
test/ask-filters.test.ts +1 −1
| @@ -161,7 +161,7 @@ describe("ask filters", () => { | ||
| 161 | 161 | const done = await call({ filter: "hide_app_day", app: "alice/plain" }); |
| 162 | 162 | expect(done.value.rows).toHaveLength(1); |
| 163 | 163 | expect(done.value.filters).toEqual({ hidden: 1, line: "1 hidden by your filters" }); |
| 164 | expect((await call({ filter: "hide_kind", kind: "nope" })).error).toContain("kind is"); | |
| 164 | expect((await call({ filter: "hide_kind", kind: "nope" })).error).toContain('argument "kind" is "nope"'); | |
| 165 | 165 | expect((await call({ filter: "hide_app", app: "alice/none" })).error).toBeDefined(); |
| 166 | 166 | const cleared = await call({ filter: "clear" }); |
| 167 | 167 | expect(cleared.value.rows).toHaveLength(2); |
test/asks-mute.test.ts +1 −1
| @@ -291,7 +291,7 @@ describe("muting a repository's asks", () => { | ||
| 291 | 291 | // Bad filters are refused, not guessed at. |
| 292 | 292 | expect(((await tool(token, "asks", { hide_kinds: ["nope"] })) as any).error).toContain("hide_kinds"); |
| 293 | 293 | expect(((await tool(token, "asks", { hide_people: ["nobody"] })) as any).error).toContain("hide_people"); |
| 294 | expect(((await tool(token, "asks", { hide_kinds: "reviews" })) as any).error).toContain("lists"); | |
| 294 | expect(((await tool(token, "asks", { hide_kinds: "reviews" })) as any).error).toContain('argument "hide_kinds"'); | |
| 295 | 295 | // The manifest says so. |
| 296 | 296 | const tools = (await listAt(servers.url, token)).result.tools as any[]; |
| 297 | 297 | for (const name of ["asks", "feed"]) { |
test/attach-look.test.ts +1 −1
| @@ -256,7 +256,7 @@ describe("attaching a look to a pull", () => { | ||
| 256 | 256 | expect(dry.value.dryRun).toBe(true); |
| 257 | 257 | expect(kept().length).toBe(before); |
| 258 | 258 | const bad = await mcp(tokens["alice"]!, { ...good, width: "tablet", dryRun: false }); |
| 259 | expect(bad.error).toContain("phone or desktop"); | |
| 259 | expect(bad.error).toContain('argument "width" is "tablet"'); | |
| 260 | 260 | const done = await mcp(tokens["alice"]!, { ...good, dryRun: false }); |
| 261 | 261 | expect(done.value.dryRun).toBe(false); |
| 262 | 262 | expect(done.value.url).toContain("/alice/garden/looks/"); |
test/conversation-confirm.test.ts +2 −2
| @@ -188,7 +188,7 @@ describe("the one list of what asks first", () => { | ||
| 188 | 188 | test("an asked-first call too large to read is refused through the MCP and kept nowhere (#8230)", async () => { |
| 189 | 189 | const w = await world(alice); |
| 190 | 190 | const before = waitingFor(app.db, alice.id).length; |
| 191 | const over = await call(w.token, "archive", { repo: w.repo, archived: true, dryRun: false, pad: "z".repeat(9000) }); | |
| 191 | const over = await call(w.token, "archive", { repo: w.repo, archived: true, dryRun: false, repos: Array(1000).fill("zzzzzzzzz") }); | |
| 192 | 192 | expect(over.isError).toBe(true); |
| 193 | 193 | expect(JSON.parse(over.text).needs_confirm).toBeNull(); |
| 194 | 194 | expect(over.text).toContain("too large for the person to read"); |
| @@ -395,7 +395,7 @@ describe("the yes, reached by a person", () => { | ||
| 395 | 395 | test("Settings → Confirms folds open on the full arguments, escaped, a secret hidden (#8230)", async () => { |
| 396 | 396 | const w = await world(alice); |
| 397 | 397 | const asked = JSON.parse( |
| 398 | (await call(w.token, "secrets", { scope: "repo", ref: w.repo, action: "set", name: "K", value: "hunter2", note: "<img src=x onerror=alert(1)>" })).text, | |
| 398 | (await call(w.token, "secrets", { scope: "repo", ref: w.repo, action: "set", name: "<img src=x onerror=alert(1)>", value: "hunter2" })).text, | |
| 399 | 399 | ); |
| 400 | 400 | expect(asked.needs_confirm).toBeString(); |
| 401 | 401 | const listed = await (await page(alice, "/settings/confirms")).text(); |
test/conversation-fence.test.ts +1 −1
| @@ -258,7 +258,7 @@ describe("text read by the forge's agent is fenced as data", () => { | ||
| 258 | 258 | test("a held write too large to read is refused through the MCP and kept nowhere (#8230)", async () => { |
| 259 | 259 | const w = await world(); |
| 260 | 260 | await call(w.token, "issue", { repo: w.repo, number: 1 }); |
| 261 | const over = await call(w.token, "close", { repo: w.repo, number: 3, pad: "z".repeat(9000) }); | |
| 261 | const over = await call(w.token, "close", { repo: w.repo, number: 3, into: Array(5000).fill(1) }); | |
| 262 | 262 | expect(over.isError).toBe(true); |
| 263 | 263 | expect(JSON.parse(over.text).needs_confirm).toBeNull(); |
| 264 | 264 | expect(over.text).toContain("too large for the person to read"); |
test/crew-teams.test.ts +1 −1
| @@ -171,7 +171,7 @@ describe("crew teams", () => { | ||
| 171 | 171 | |
| 172 | 172 | test("the teams tool plans by default, changes with dryRun false, and is not for a non-admin", async () => { |
| 173 | 173 | expect(JSON.stringify(await mcp(alice, "teams", { slug: "security", dial: 101 }))).toContain( |
| 174 | "A dial is a whole number from 0 to 100.", | |
| 174 | 'argument \\"dial\\" is 101', | |
| 175 | 175 | ); |
| 176 | 176 | const dryOver = JSON.stringify(await mcp(alice, "teams", { slug: "security", dial: 90 })); |
| 177 | 177 | expect(dryOver).toContain("The dials together may not pass 100%."); |
test/decisions-by-doors.test.ts +1 −1
| @@ -182,7 +182,7 @@ describe("the standing rule over MCP", () => { | ||
| 182 | 182 | expect(rule()).toBe("me"); |
| 183 | 183 | } |
| 184 | 184 | const odd = await mcp(admin["founder"]!, "decisions_by", { repo: "acme/svc", by: "x" }); |
| 185 | expect(odd.error).toContain("me, decider or decider_tell"); | |
| 185 | expect(odd.error).toContain('argument "by" is "x"'); | |
| 186 | 186 | }); |
| 187 | 187 | |
| 188 | 188 | test("the admin needs an admin token to set it", async () => { |
test/feed-interact.test.ts +7 −3
| @@ -3,6 +3,8 @@ | ||
| 3 | 3 | * and `readInteraction` (src/feed/interact.ts) are the one rule, and the |
| 4 | 4 | * route and MCP `feed_dismiss` refuse the same inputs with the same error. |
| 5 | 5 | */ |
| 6 | import { badArgument } from "../src/http/mcp/shared.ts"; | |
| 7 | import { TOOLS } from "../src/http/mcp/tools.ts"; | |
| 6 | 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 7 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 8 | 10 | import { tmpdir } from "node:os"; |
| @@ -178,7 +180,9 @@ describe("the route and MCP feed_dismiss refuse the same things", () => { | ||
| 178 | 180 | const tool = await mcp(input); |
| 179 | 181 | expect({ input, code: web.error }).toEqual({ input, code }); |
| 180 | 182 | expect(web.status).toBe(code === "not_found" ? 404 : 422); |
| 181 | expect(tool).toEqual({ isError: true, text: expect.stringContaining(`${web.error}: ${web.message}`) }); | |
| 183 | // What the tool's schema refuses, the MCP names by argument; the rest, in the route's words. | |
| 184 | const shape = badArgument(TOOLS.find((t) => t.name === "feed_dismiss")!.inputSchema, input); | |
| 185 | expect(tool).toEqual({ isError: true, text: expect.stringContaining(shape === undefined ? `${web.error}: ${web.message}` : `invalid: ${shape}`) }); | |
| 182 | 186 | } |
| 183 | 187 | }); |
| 184 | 188 | |
| @@ -188,10 +192,10 @@ describe("the route and MCP feed_dismiss refuse the same things", () => { | ||
| 188 | 192 | const tool = await mcp(input); |
| 189 | 193 | expect(web.status).toBe(422); |
| 190 | 194 | expect(web.error).toBe("invalid_kind"); |
| 191 | expect(tool).toEqual({ isError: true, text: expect.stringContaining("invalid_kind: kind is one of dismissed, muted") }); | |
| 195 | expect(tool).toEqual({ isError: true, text: expect.stringContaining('invalid: argument "kind" is "bogus"; expected one of "dismissed", "muted"') }); | |
| 192 | 196 | // The route records every act a card reports; the tool only dismisses or mutes. |
| 193 | 197 | expect((await route({ item: openEvent, kind: "opened" })).status).toBe(201); |
| 194 | expect((await mcp({ item: openEvent, kind: "opened" })).text).toStartWith("invalid_kind:"); | |
| 198 | expect((await mcp({ item: openEvent, kind: "opened" })).text).toStartWith('invalid: argument "kind" is "opened"'); | |
| 195 | 199 | }); |
| 196 | 200 | |
| 197 | 201 | test("what one door accepts, the other does too", async () => { |
test/feed-like.test.ts +1 −1
| @@ -350,7 +350,7 @@ describe("one ledger from every door", () => { | ||
| 350 | 350 | const before = ledgerRows(secretEvent); |
| 351 | 351 | expect(String(await mcp(bobTok, { item: secretEvent, act: "like" }))).toContain("not visible"); |
| 352 | 352 | expect(ledgerRows(secretEvent)).toBe(before); |
| 353 | expect(String(await mcp(bobTok, { item: openEvent, act: "nope" }))).toContain("act is one of"); | |
| 353 | expect(String(await mcp(bobTok, { item: openEvent, act: "nope" }))).toContain('argument "act" is "nope"'); | |
| 354 | 354 | }); |
| 355 | 355 | |
| 356 | 356 | test("newest first, a page at a time, with `more` and a `before` cursor, over API and MCP", async () => { |
test/growth.test.ts +2 −2
| @@ -371,8 +371,8 @@ describe("growth and the planner switch", () => { | ||
| 371 | 371 | |
| 372 | 372 | test("until with resume, and a confirm that is not a boolean, are refused", async () => { |
| 373 | 373 | expect(((await mcp(owner, { action: "resume", until: soon() })) as any).error).toContain("until is a UTC time, for pause"); |
| 374 | expect(((await mcp(owner, { action: "pause", confirm: "yes" })) as any).error).toContain("confirm is true or false"); | |
| 375 | expect(((await mcp(owner, { action: "stop" })) as any).error).toContain("pause or resume"); | |
| 374 | expect(((await mcp(owner, { action: "pause", confirm: "yes" })) as any).error).toContain('argument "confirm"'); | |
| 375 | expect(((await mcp(owner, { action: "stop" })) as any).error).toContain('argument "action" is "stop"'); | |
| 376 | 376 | expect(pausedUntil(app.db, repo.id, new Date())).toBeNull(); |
| 377 | 377 | }); |
| 378 | 378 |
test/holds.test.ts +1 −1
| @@ -819,7 +819,7 @@ describe("a hold is set, shown and lifted", () => { | ||
| 819 | 819 | until: "red", |
| 820 | 820 | dryRun: false, |
| 821 | 821 | }); |
| 822 | expect(typo.error).toContain("bad_until"); | |
| 822 | expect(typo.error).toContain('argument "until" is "red"'); | |
| 823 | 823 | expect(getHold(f.app.db, mine.id)).toBeUndefined(); |
| 824 | 824 | holdPull(f.app, f.alice, f.repo, mine, "red alone", false, "green"); |
| 825 | 825 | const check = createRun(f.app.db, { |
test/issue-teams-doors.test.ts +1 −1
| @@ -233,7 +233,7 @@ describe("naming teams, at every door", () => { | ||
| 233 | 233 | expect((await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number })).teams).toEqual(["platform"]); |
| 234 | 234 | const many = await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number, teams: ["design", "security", "platform"] }); |
| 235 | 235 | expect(JSON.stringify(many)).toContain("at most 2"); |
| 236 | expect(JSON.stringify(await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number, teams: "design" }))).toContain("list of team slugs"); | |
| 236 | expect(JSON.stringify(await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number, teams: "design" }))).toContain("expected array"); | |
| 237 | 237 | expect(teamsOfIssue(app.db, issue.id)).toEqual(["platform"]); |
| 238 | 238 | expect(JSON.stringify(await mcp(bob, "issue_teams", { repo: "alice/garden", number: issue.number, teams: ["design"] }))).toContain("no such"); |
| 239 | 239 | }); |
test/mcp-app-deploy.test.ts +1 −1
| @@ -157,7 +157,7 @@ describe("MCP app_deploy", () => { | ||
| 157 | 157 | const before = runCount(); |
| 158 | 158 | for (const action of ["restart", "burn", "", "REDEPLOY"]) { |
| 159 | 159 | const a = await tool(aliceRw, { repo: "alice/hello", env: "production", action }); |
| 160 | expect(a.error).toContain("invalid_action"); | |
| 160 | expect(a.error).toContain('argument "action"'); | |
| 161 | 161 | } |
| 162 | 162 | expect(runCount()).toBe(before); |
| 163 | 163 | }); |
test/mcp-app-env.test.ts +2 −2
| @@ -110,9 +110,9 @@ describe("MCP app_env", () => { | ||
| 110 | 110 | const reserved = await tool(aliceAdmin, { repo: "alice/game", action: "set", name: "FORGE_X", value: SECRET }); |
| 111 | 111 | expect(reserved.error).toContain("reserved_name"); |
| 112 | 112 | const scope = await tool(aliceAdmin, { repo: "alice/game", action: "set", name: "A", value: SECRET, scope: "x" }); |
| 113 | expect(scope.error).toContain("invalid_scope"); | |
| 113 | expect(scope.error).toContain('argument "scope"'); | |
| 114 | 114 | const gone = await tool(aliceAdmin, { repo: "alice/game", action: "unset", name: "NOPE" }); |
| 115 | 115 | expect(gone.error).toContain("no_such_var"); |
| 116 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "burn" })).error).toContain("list, set or unset"); | |
| 116 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "burn" })).error).toContain('argument "action" is "burn"'); | |
| 117 | 117 | }); |
| 118 | 118 | }); |
test/mcp-args.test.ts added +146
| @@ -0,0 +1,146 @@ | ||
| 1 | /** | |
| 2 | * Every MCP argument is held to its tool's own inputSchema (#15362): a wrong type or a name the | |
| 3 | * tool does not take is refused naming the argument, never dropped as if absent. | |
| 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 { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createToken } from "../src/core/tokens.ts"; | |
| 11 | import { createUser } from "../src/core/users.ts"; | |
| 12 | import { askingOf } from "../src/perf/asking.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | import { badArgument } from "../src/http/mcp/shared.ts"; | |
| 15 | import { TOOLS } from "../src/http/mcp/tools.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | ||
| 18 | quietLogs(); | |
| 19 | ||
| 20 | /** Tools whose schema names no properties, so there is nothing to hold their arguments to. */ | |
| 21 | const SCHEMALESS = ["backups_test"]; | |
| 22 | ||
| 23 | /** Tools offered only behind a switch this forge has off (`needsSwitch`: SSH). */ | |
| 24 | const HIDDEN = ["ssh_keys"]; | |
| 25 | ||
| 26 | /** Tools whose schema says `additionalProperties: true`. */ | |
| 27 | const OPEN = ["spawn"]; | |
| 28 | ||
| 29 | test("an unknown name is refused, and the tool's own names are listed", () => { | |
| 30 | const said = badArgument({ type: "object", properties: { limit: { type: "integer" } } }, { bogus: 1 }); | |
| 31 | expect(said).toContain('unknown argument "bogus"'); | |
| 32 | expect(said).toContain("limit"); | |
| 33 | expect(badArgument({ type: "object", properties: {}, additionalProperties: true }, { bogus: 1 })).toBeUndefined(); | |
| 34 | expect(badArgument({ type: "object", properties: { limit: { type: "integer" } } }, { limit: 5 })).toBeUndefined(); | |
| 35 | expect(badArgument({ type: "object", properties: { n: { type: "number" } } }, { n: 5 })).toBeUndefined(); | |
| 36 | }); | |
| 37 | ||
| 38 | let dir: string, app: App, servers: Servers, token: string; | |
| 39 | beforeAll(async () => { | |
| 40 | dir = await mkdtemp(join(tmpdir(), "forge-mcp-args-")); | |
| 41 | app = createApp({ dataDir: dir, port: 0 }); | |
| 42 | servers = await serve(app); | |
| 43 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 44 | if (!u.ok) throw new Error("user"); | |
| 45 | token = createToken(app.db, u.value.id, "t", "admin").token; | |
| 46 | }); | |
| 47 | afterAll(async () => { | |
| 48 | askingOf(app).forget(); | |
| 49 | await servers.stop(); | |
| 50 | await rm(dir, { recursive: true, force: true }); | |
| 51 | }); | |
| 52 | ||
| 53 | const call = async (name: string, args: object) => { | |
| 54 | const res = await fetch(`${servers.url}/mcp`, { | |
| 55 | method: "POST", | |
| 56 | headers: { "content-type": "application/json", accept: "application/json", authorization: `Bearer ${token}` }, | |
| 57 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }), | |
| 58 | }); | |
| 59 | const body = (await res.json()) as any; | |
| 60 | return body.result ?? { hidden: body.error?.message }; | |
| 61 | }; | |
| 62 | ||
| 63 | test("search with limit \"many\" and explore with an unknown name are refused, not answered empty", async () => { | |
| 64 | const bad = await call("search", { q: "a", limit: "many" }); | |
| 65 | expect(bad.isError).toBe(true); | |
| 66 | expect(bad.content[0].text).toContain('invalid: argument "limit" is "many"; expected integer from 1 to 100'); | |
| 67 | const unknown = await call("explore", { bogus: 1 }); | |
| 68 | expect(unknown.isError).toBe(true); | |
| 69 | expect(unknown.content[0].text).toContain('unknown argument "bogus"'); | |
| 70 | expect((await call("explore", {})).isError).not.toBe(true); | |
| 71 | }); | |
| 72 | ||
| 73 | const WRONG: unknown[] = [{ nope: 1 }, "wrong", 12345, true, []]; | |
| 74 | /** A value the property refuses, or undefined when its schema accepts anything. */ | |
| 75 | const wrongFor = (schema: any): unknown => { | |
| 76 | const types = [schema.type].flat().filter((t) => typeof t === "string"); | |
| 77 | if (types.length === 0) return Array.isArray(schema.enum) ? { nope: 1 } : undefined; | |
| 78 | return WRONG.find((v) => { | |
| 79 | const have = v === null ? "null" : Array.isArray(v) ? "array" : Number.isInteger(v) ? "integer" : typeof v; | |
| 80 | return !types.includes(have) && !(have === "integer" && types.includes("number")); | |
| 81 | }); | |
| 82 | }; | |
| 83 | ||
| 84 | test("over /mcp, every tool refuses its first property given the wrong type, and an unknown name, naming each", async () => { | |
| 85 | const untyped: string[] = []; | |
| 86 | const open: string[] = []; | |
| 87 | const hidden: string[] = []; | |
| 88 | for (const t of TOOLS) { | |
| 89 | const schema = t.inputSchema as any; | |
| 90 | const props = schema.properties as Record<string, any> | undefined; | |
| 91 | if (props === undefined) { | |
| 92 | open.push(t.name); | |
| 93 | continue; | |
| 94 | } | |
| 95 | const first = Object.keys(props)[0]; | |
| 96 | if (first !== undefined) { | |
| 97 | const wrong = wrongFor(props[first]); | |
| 98 | if (wrong === undefined) untyped.push(t.name); | |
| 99 | else { | |
| 100 | const said = await call(t.name, { [first]: wrong }); | |
| 101 | if (said.hidden !== undefined) { | |
| 102 | hidden.push(t.name); | |
| 103 | continue; | |
| 104 | } | |
| 105 | expect(said.isError, t.name).toBe(true); | |
| 106 | expect(said.content[0].text, t.name).toContain(`invalid: argument "${first}" is `); | |
| 107 | expect(said.content[0].text, t.name).toContain("Example:"); | |
| 108 | } | |
| 109 | } | |
| 110 | if (schema.additionalProperties === true) continue; | |
| 111 | const unknown = await call(t.name, { zz_not_an_argument: 1 }); | |
| 112 | expect(unknown.isError, t.name).toBe(true); | |
| 113 | expect(unknown.content[0].text, t.name).toContain('invalid: unknown argument "zz_not_an_argument"'); | |
| 114 | } | |
| 115 | expect(open).toEqual(SCHEMALESS); | |
| 116 | // Tools this admin token is not offered answer as no such tool, the schema unread. | |
| 117 | expect(hidden).toEqual(HIDDEN); | |
| 118 | // A first property whose schema takes any value cannot be given a wrong one: named, so none is | |
| 119 | // added unseen. | |
| 120 | expect(untyped).toEqual([]); | |
| 121 | // Genuinely open: `spawn` keeps its own refusal of a `modelKey`. | |
| 122 | expect(TOOLS.filter((t) => (t.inputSchema as any).additionalProperties === true).map((t) => t.name)).toEqual(OPEN); | |
| 123 | }); | |
| 124 | ||
| 125 | test("a value of the right type outside enum, minimum, maximum or maxLength is refused naming it", async () => { | |
| 126 | const show = await call("search", { q: "a", limit: 0 }); | |
| 127 | expect(show.content[0].text).toContain('argument "limit" is 0; expected integer'); | |
| 128 | expect(badArgument({ properties: { k: { type: "string", enum: ["a", "b"] } } }, { k: "c" })).toBe( | |
| 129 | 'argument "k" is "c"; expected one of "a", "b". Example: {"k": "a"}', | |
| 130 | ); | |
| 131 | expect(badArgument({ properties: { n: { type: "integer", minimum: 1, maximum: 9 } } }, { n: 0 })).toBe( | |
| 132 | 'argument "n" is 0; expected integer from 1 to 9. Example: {"n": 1}', | |
| 133 | ); | |
| 134 | expect(badArgument({ properties: { n: { type: "integer", minimum: 1, maximum: 9 } } }, { n: 10 })).toContain('argument "n" is 10'); | |
| 135 | expect(badArgument({ properties: { q: { type: "string", maxLength: 3 } } }, { q: "abcd" })).toBe( | |
| 136 | 'argument "q" is 4 characters long; expected string of at most 3 characters. Example: {"q": "text"}', | |
| 137 | ); | |
| 138 | expect(badArgument({ properties: { secret: { type: "string", maxLength: 3 } } }, { secret: "hunter2" })).not.toContain("hunter2"); | |
| 139 | expect(badArgument({ properties: { k: { enum: ["a"] }, n: { type: "integer", minimum: 1 } } }, { k: "a", n: 1 })).toBeUndefined(); | |
| 140 | }); | |
| 141 | ||
| 142 | test("a required argument left out is refused naming it", () => { | |
| 143 | expect(badArgument({ properties: { repo: { type: "string" } }, required: ["repo"] }, {})).toBe( | |
| 144 | 'argument "repo" is missing; expected string. Example: {"repo": "text"}', | |
| 145 | ); | |
| 146 | }); |
test/mcp-asked-args.test.ts +3 −3
| @@ -110,9 +110,9 @@ describe("MCP asked arguments", () => { | ||
| 110 | 110 | }); |
| 111 | 111 | |
| 112 | 112 | test("an unknown show or order is refused", async () => { |
| 113 | expect((await call(aliceTok, { show: "everything" })).error).toContain("invalid_show"); | |
| 114 | expect((await call(aliceTok, { order: "random" })).error).toContain("invalid_order"); | |
| 115 | expect((await call(aliceTok, { show: "all", order: "random" })).error).toContain("invalid_order"); | |
| 113 | expect((await call(aliceTok, { show: "everything" })).error).toContain('argument "show"'); | |
| 114 | expect((await call(aliceTok, { order: "random" })).error).toContain('argument "order"'); | |
| 115 | expect((await call(aliceTok, { show: "all", order: "random" })).error).toContain('argument "order"'); | |
| 116 | 116 | }); |
| 117 | 117 | |
| 118 | 118 | test("a repository the caller cannot read lists nothing about it", async () => { |
test/mcp-assign.test.ts +2 −2
| @@ -134,8 +134,8 @@ describe("MCP assign", () => { | ||
| 134 | 134 | test("an unknown user, a wrong kind and a bad shape are refused", async () => { |
| 135 | 135 | expect((await call(aliceTok, args("nobody"))).error).toStartWith("no_such_user"); |
| 136 | 136 | expect((await call(aliceTok, args("bob", { kind: "pull" }))).error).toStartWith("no_such_issue"); |
| 137 | expect((await call(aliceTok, args("bob", { kind: "thing" }))).error).toStartWith("invalid"); | |
| 138 | expect((await call(aliceTok, args(5 as any))).error).toStartWith("invalid_assignee"); | |
| 137 | expect((await call(aliceTok, args("bob", { kind: "thing" }))).error).toContain('argument "kind"'); | |
| 138 | expect((await call(aliceTok, args(5 as any))).error).toContain('argument "assignee"'); | |
| 139 | 139 | expect(assigneeOf()).toBeNull(); |
| 140 | 140 | }); |
| 141 | 141 |
test/mcp-cloud-account.test.ts +1 −1
| @@ -111,7 +111,7 @@ describe("MCP cloud_account", () => { | ||
| 111 | 111 | test("verb delete is bad_verb", async () => { |
| 112 | 112 | const r = await call(adminToken, { verb: "delete" }); |
| 113 | 113 | expect(r.error).toBe(true); |
| 114 | expect(r.text).toContain("bad_verb"); | |
| 114 | expect(r.text).toContain('argument "verb"'); | |
| 115 | 115 | }); |
| 116 | 116 | |
| 117 | 117 | test("a non-admin and an rw token are refused for every verb, the account unchanged", async () => { |
test/mcp-confirm-wait.test.ts +2 −2
| @@ -150,8 +150,8 @@ describe("confirm_wait over MCP", () => { | ||
| 150 | 150 | const w = (args: Record<string, unknown>) => |
| 151 | 151 | tool(rw, "confirm_wait", { app: "alice/game", ...args }); |
| 152 | 152 | expect((await w({ issue: 1, blocker: 9999 })).error).toContain("no_such_issue"); |
| 153 | expect((await w({ issue: "1", blocker: 1 })).error).toContain("no_such_issue"); | |
| 154 | expect((await w({ issue: 1, blocker: 1.5 })).error).toContain("no_such_issue"); | |
| 153 | expect((await w({ issue: "1", blocker: 1 })).error).toContain('argument "issue"'); | |
| 154 | expect((await w({ issue: 1, blocker: 1.5 })).error).toContain('argument "blocker"'); | |
| 155 | 155 | expect((await tool(rw, "confirm_wait", { issue: 1, blocker: 1 })).error).toBeDefined(); |
| 156 | 156 | }); |
| 157 | 157 | }); |
test/mcp-flag-set.test.ts +1 −1
| @@ -122,7 +122,7 @@ describe("MCP flag_set", () => { | ||
| 122 | 122 | expect(r.error).toBe(true); |
| 123 | 123 | expect(r.text).toContain("Flags are set by a forge admin."); |
| 124 | 124 | const junk = await call(bob, { name: 7, value: 3 }); |
| 125 | expect(junk.text).toContain("Flags are set by a forge admin."); | |
| 125 | expect(junk.text).toContain('invalid: argument "name" is 7; expected string'); | |
| 126 | 126 | expect(reg.value("alpha")).toBeUndefined(); |
| 127 | 127 | }); |
| 128 | 128 |
test/mcp-fleet-act.test.ts +1 −1
| @@ -105,7 +105,7 @@ test("someone who administers none of the rows is refused each row; bad input an | ||
| 105 | 105 | expect(tried.value.rows.every((r: any) => r.outcome === "refused")).toBe(true); |
| 106 | 106 | expect(ceilings()).toEqual(before); |
| 107 | 107 | expect((await call(tok["admin"]!, { q: query, action: { verb: "nope" } })).error).toContain("bad_action"); |
| 108 | expect((await call(tok["admin"]!, { q: query, action, apply: "yes" })).error).toContain("apply is true or false"); | |
| 108 | expect((await call(tok["admin"]!, { q: query, action, apply: "yes" })).error).toContain('argument "apply"'); | |
| 109 | 109 | expect((await call(tok["admin"]!, { action })).error).toContain("needs q"); |
| 110 | 110 | expect((await call(tok["admin"]!, { q: query, apply: true })).error).toContain("needs an action"); |
| 111 | 111 | expect(ceilings()).toEqual(before); |
test/mcp-flow-why.test.ts +1 −1
| @@ -146,7 +146,7 @@ describe("MCP flow with a subject", () => { | ||
| 146 | 146 | |
| 147 | 147 | test("a reader is refused, and bad numbers are invalid", async () => { |
| 148 | 148 | expect((await call(readerTok, { repo: "alice/one", issue: 1 })).error).toContain("can write"); |
| 149 | expect((await call(ownerTok, { repo: "alice/one", issue: "x" })).error).toContain("numbers"); | |
| 149 | expect((await call(ownerTok, { repo: "alice/one", issue: "x" })).error).toContain('argument "issue"'); | |
| 150 | 150 | expect((await call(ownerTok, { repo: "alice/one", issue: 1, pull: 2 })).error).toContain("not both"); |
| 151 | 151 | expect((await call(ownerTok, { repo: "alice/one", issue: 99 })).error).toContain("no issue"); |
| 152 | 152 | }); |
test/mcp-forge-tell.test.ts +2 −2
| @@ -214,8 +214,8 @@ describe("the forge over MCP: tell", () => { | ||
| 214 | 214 | expect(closed.value).toMatchObject({ state: "closed", closeReason: "done" }); |
| 215 | 215 | |
| 216 | 216 | // The boundary: bad words are refused before the action. |
| 217 | expect((await tool(rw, "close", { repo: "alice/game", number: own.number, state: "x" })).error).toContain("invalid_state"); | |
| 218 | expect((await tool(rw, "close", { repo: "alice/game", number: own.number, reason: "x" })).error).toContain("invalid_reason"); | |
| 217 | expect((await tool(rw, "close", { repo: "alice/game", number: own.number, state: "x" })).error).toContain('argument "state"'); | |
| 218 | expect((await tool(rw, "close", { repo: "alice/game", number: own.number, reason: "x" })).error).toContain('argument "reason"'); | |
| 219 | 219 | expect((await tool(rw, "close", { repo: "alice/game", number: own.number, into: [0] })).error).toContain("invalid_reason"); |
| 220 | 220 | expect((await tool(ro, "close", { repo: "alice/game", number: own.number })).error).toContain(READ_ONLY_REFUSAL); |
| 221 | 221 | }); |
test/mcp-hook-deliveries.test.ts +1 −1
| @@ -96,6 +96,6 @@ describe("MCP hook deliveries", () => { | ||
| 96 | 96 | expect((await tool(bobAdmin, { repo: "alice/game", action: "deliveries", id: hookId })).error).toContain("not_found"); |
| 97 | 97 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: otherHookId })).error).toContain("not_found"); |
| 98 | 98 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: "nope" })).error).toContain("not_found"); |
| 99 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: "i".repeat(65) })).error).toContain("id is text"); | |
| 99 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: "i".repeat(65) })).error).toContain('argument "id" is 65 characters long'); | |
| 100 | 100 | }); |
| 101 | 101 | }); |
test/mcp-hooks.test.ts +6 −6
| @@ -100,7 +100,7 @@ describe("MCP hooks", () => { | ||
| 100 | 100 | expect(second.value.items.map((h: any) => h.id)).toEqual([ids[2]]); |
| 101 | 101 | expect(second.value.next_cursor).toBeNull(); |
| 102 | 102 | for (const limit of [0, 201, 1.5, "5"]) |
| 103 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "list", limit })).error).toContain("invalid_limit"); | |
| 103 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "list", limit })).error).toContain('argument "limit"'); | |
| 104 | 104 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "list", cursor: "gone" })).error).toContain("invalid_cursor"); |
| 105 | 105 | for (const id of ids) await tool(aliceAdmin, { repo: "alice/game", action: "remove", id }); |
| 106 | 106 | }); |
| @@ -117,17 +117,17 @@ describe("MCP hooks", () => { | ||
| 117 | 117 | test("an invalid URL is refused with the API's error", async () => { |
| 118 | 118 | for (const url of ["http://example.com/h", "nonsense", ""]) |
| 119 | 119 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "add", url, secret: "0123456789abcdef" })).error).toContain("invalid_url"); |
| 120 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "nope" })).error).toContain("action is list"); | |
| 120 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "nope" })).error).toContain('argument "action" is "nope"'); | |
| 121 | 121 | }); |
| 122 | 122 | |
| 123 | 123 | test("lengths are enforced, and a secret of 16 or more is required", async () => { |
| 124 | 124 | const base = { repo: "alice/game", action: "add", secret: "0123456789abcdef" }; |
| 125 | 125 | const long = await tool(aliceAdmin, { ...base, url: "https://example.com/" + "a".repeat(2048) }); |
| 126 | expect(long.error).toContain("url is text of at most 2048"); | |
| 126 | expect(long.error).toContain('argument "url" is 2068 characters long'); | |
| 127 | 127 | const kinds = await tool(aliceAdmin, { ...base, url: "https://example.com/h", kinds: "k".repeat(201) }); |
| 128 | expect(kinds.error).toContain("kinds is text of at most 200"); | |
| 129 | expect((await tool(aliceAdmin, { ...base, url: "https://example.com/h", secret: "x".repeat(201) })).error).toContain("secret is text"); | |
| 130 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "remove", id: "i".repeat(65) })).error).toContain("id is text"); | |
| 128 | expect(kinds.error).toContain('argument "kinds" is 201 characters long'); | |
| 129 | expect((await tool(aliceAdmin, { ...base, url: "https://example.com/h", secret: "x".repeat(201) })).error).toContain('argument "secret" is not accepted; expected string of at most 200 characters'); | |
| 130 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "remove", id: "i".repeat(65) })).error).toContain('argument "id" is 65 characters long'); | |
| 131 | 131 | for (const secret of [undefined, "short"]) |
| 132 | 132 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "add", url: "https://example.com/h", secret })).error).toContain("secret is required"); |
| 133 | 133 | expect((await tool(aliceAdmin, { repo: "alice/game", action: "list" })).value).toEqual({ items: [], next_cursor: null }); |
test/mcp-issue.test.ts +4 −1
| @@ -156,7 +156,10 @@ describe("MCP issue", () => { | ||
| 156 | 156 | test("a bad number is refused", async () => { |
| 157 | 157 | for (const n of [0, -1, 1.5, "1", null, 999]) { |
| 158 | 158 | const r = await tool(aliceTok, { repo: "alice/game", number: n }); |
| 159 | expect(r.error).toContain("no issue"); | |
| 159 | // Anything the schema refuses (a wrong type, below its minimum) is refused naming the | |
| 160 | // argument; a whole number that fits but names no issue reaches the tool. | |
| 161 | if (n === 999) expect(r.error).toContain("no issue"); | |
| 162 | else expect(r.error).toContain('argument "number"'); | |
| 160 | 163 | } |
| 161 | 164 | }); |
| 162 | 165 | }); |
test/mcp-labels.test.ts +4 −3
| @@ -131,16 +131,17 @@ describe("MCP labels", () => { | ||
| 131 | 131 | const removed = await tool(aliceRw, { repo: "alice/game", number, labels: ["FLOW"], action: "remove" }); |
| 132 | 132 | expect(removed.value.labels).toEqual(["ui"]); |
| 133 | 133 | expect((await tool(aliceRw, { repo: "alice/game", number, labels: [], action: "toggle" })).error).toContain( |
| 134 | "action is set, add or remove", | |
| 134 | 'argument "action"', | |
| 135 | 135 | ); |
| 136 | 136 | }); |
| 137 | 137 | |
| 138 | 138 | test("bad input stops at the boundary", async () => { |
| 139 | 139 | for (const labels of ["bug", [1], [{}], null, Array(51).fill("a"), ["x".repeat(65)]]) { |
| 140 | 140 | const r = await tool(aliceRw, { repo: "alice/game", number, labels }); |
| 141 | expect(r.error).toContain("labels is a list"); | |
| 141 | // A wrong type is the schema's to refuse; a list whose items or size are wrong, the tool's. | |
| 142 | expect(r.error).toContain(typeof labels === "string" || labels === null ? 'argument "labels"' : "labels is a list"); | |
| 142 | 143 | } |
| 143 | 144 | expect((await tool(aliceRw, { repo: "alice/game", number: 999, labels: [] })).error).toContain("no issue #999"); |
| 144 | expect((await tool(aliceRw, { repo: "alice/game", number: "1", labels: [] })).error).toContain("no issue"); | |
| 145 | expect((await tool(aliceRw, { repo: "alice/game", number: "1", labels: [] })).error).toContain('argument "number"'); | |
| 145 | 146 | }); |
| 146 | 147 | }); |
test/mcp-limit.test.ts +3 −3
| @@ -65,7 +65,7 @@ const maxOf = (name: string): number => { | ||
| 65 | 65 | }; |
| 66 | 66 | |
| 67 | 67 | for (const name of ["pulls", "commits", "issues", "queue_gates"]) { |
| 68 | test(`${name}: the schema's maximum passes; outside it is invalid_limit naming it`, async () => { | |
| 68 | test(`${name}: the schema's maximum passes; outside it is refused naming limit`, async () => { | |
| 69 | 69 | const max = maxOf(name); |
| 70 | 70 | const base = { repo: "ada/svc" }; |
| 71 | 71 | // An empty repository has no commits to list: that is a refusal of a different kind, not of the |
| @@ -74,8 +74,8 @@ for (const name of ["pulls", "commits", "issues", "queue_gates"]) { | ||
| 74 | 74 | for (const limit of [max + 1, 0, 1.5, "7"]) { |
| 75 | 75 | const r = await call(name, { ...base, limit }); |
| 76 | 76 | expect(r.ok).toBe(false); |
| 77 | expect(r.error).toContain("invalid_limit"); | |
| 78 | expect(r.error).toContain(`limit is a whole number from 1 to ${max}`); | |
| 77 | // The boundary refuses every one by name, with the schema's own bounds. | |
| 78 | expect(r.error).toContain(`argument "limit" is ${JSON.stringify(limit)}; expected integer from 1 to ${max}`); | |
| 79 | 79 | } |
| 80 | 80 | }); |
| 81 | 81 | } |
test/mcp-limits.test.ts +1 −1
| @@ -124,7 +124,7 @@ describe("MCP limits", () => { | ||
| 124 | 124 | for (const dryRun of [true, false]) { |
| 125 | 125 | const res = await call(adaAdmin, { key: "no_such_thing", value: "5", dryRun }); |
| 126 | 126 | expect(res.error).toBe(true); |
| 127 | expect(res.text).toContain("no_such_limit"); | |
| 127 | expect(res.text).toContain('argument "key"'); | |
| 128 | 128 | expect(res.text).toContain("no_such_thing"); |
| 129 | 129 | } |
| 130 | 130 | }); |
test/mcp-merge.test.ts +2 −2
| @@ -199,10 +199,10 @@ describe("the merge tool over MCP", () => { | ||
| 199 | 199 | const pull = await pullOf("bad-input"); |
| 200 | 200 | const base = { repo: "alice/game", number: pull.number, dryRun: false }; |
| 201 | 201 | expect((await tool(aliceRw, { ...base, strategy: "rebase" })).error).toContain( |
| 202 | "strategy is merge or squash", | |
| 202 | 'argument "strategy"', | |
| 203 | 203 | ); |
| 204 | 204 | expect((await tool(aliceRw, { ...base, number: 9999 })).error).toContain("no pull #9999"); |
| 205 | expect((await tool(aliceRw, { ...base, number: "1" })).error).toContain("no_such_pull"); | |
| 205 | expect((await tool(aliceRw, { ...base, number: "1" })).error).toContain('argument "number"'); | |
| 206 | 206 | expect((await tool(aliceRw, { ...base, repo: "nope" })).error).toStartWith("not_found:"); |
| 207 | 207 | expect(getPull(app.db, repo.id, pull.number)!.mergedAt).toBeNull(); |
| 208 | 208 | }); |
test/mcp-open-explore.test.ts +1 −1
| @@ -117,7 +117,7 @@ describe("open explore and search over MCP", () => { | ||
| 117 | 117 | for (const key of ["q", "query", "cursor"]) { |
| 118 | 118 | for (const token of [null, aliceRw]) { |
| 119 | 119 | const r = await call(token, "explore", { [key]: "x".repeat(201) }); |
| 120 | expect(r.error).toContain(`\`${key}\` is a string of at most 200 characters`); | |
| 120 | expect(r.error).toContain(`argument "${key}" is 201 characters long; expected string of at most 200 characters`); | |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | }); |
test/mcp-orgteams.test.ts +1 −1
| @@ -99,7 +99,7 @@ describe("MCP org_teams", () => { | ||
| 99 | 99 | await tool(owner, { org: "acme", action: "add_member", team: "crew", user: "carol", role: "reviewer" }); |
| 100 | 100 | const bad = await tool(owner, { org: "acme", action: "remove_member", team: "crew", user: "carol", role: "boss" }); |
| 101 | 101 | expect(bad.isError).toBe(true); |
| 102 | expect(bad.text).toContain("bad_role"); | |
| 102 | expect(bad.text).toContain('argument "role"'); | |
| 103 | 103 | const off = await tool(owner, { org: "acme", action: "remove_member", team: "crew", user: "carol", role: "reviewer" }); |
| 104 | 104 | expect(off.isError).toBe(false); |
| 105 | 105 | const kept = JSON.parse((await tool(owner, { org: "acme", action: "members", team: "crew" })).text); |
test/mcp-origins.test.ts +1 −1
| @@ -125,7 +125,7 @@ describe("MCP origins", () => { | ||
| 125 | 125 | (await tool(aliceAdmin, { action: "repos", id: "nope" })).error, |
| 126 | 126 | ).toContain("not_found"); |
| 127 | 127 | expect((await tool(aliceAdmin, { action: "sync" })).error).toContain("invalid"); |
| 128 | expect((await tool(aliceAdmin, { action: "x" })).error).toContain("bad_action"); | |
| 128 | expect((await tool(aliceAdmin, { action: "x" })).error).toContain('argument "action"'); | |
| 129 | 129 | }); |
| 130 | 130 | |
| 131 | 131 | test("a token short of admin is refused", async () => { |
test/mcp-passkeys.test.ts +1 −1
| @@ -88,6 +88,6 @@ describe("MCP whoami_can kind passkeys", () => { | ||
| 88 | 88 | expect(r.items).toBeUndefined(); |
| 89 | 89 | const bad = await call(alice, { kind: "teapots" }); |
| 90 | 90 | expect(bad.error).toBe(true); |
| 91 | expect(bad.text).toContain("role, passkeys"); | |
| 91 | expect(bad.text).toContain('one of "role", "passkeys"'); | |
| 92 | 92 | }); |
| 93 | 93 | }); |
test/mcp-person.test.ts +1 −3
| @@ -105,9 +105,7 @@ describe("MCP person", () => { | ||
| 105 | 105 | |
| 106 | 106 | test("a limit outside 1 to 200 is refused, 1 and 200 pass", async () => { |
| 107 | 107 | for (const bad of [0, -5, 9999, 201, 1.5, "x"]) |
| 108 | expect((await tool(bobRo, { username: "guild", limit: bad })).error).toContain( | |
| 109 | "invalid_limit", | |
| 110 | ); | |
| 108 | expect((await tool(bobRo, { username: "guild", limit: bad })).error).toContain('argument "limit"'); | |
| 111 | 109 | expect((await tool(bobRo, { username: "guild", limit: 1 })).value.repos.items).toHaveLength(1); |
| 112 | 110 | expect((await tool(bobRo, { username: "guild", limit: 200 })).value).toBeDefined(); |
| 113 | 111 | }); |
test/mcp-pins.test.ts +3 −3
| @@ -131,9 +131,9 @@ describe("MCP pins", () => { | ||
| 131 | 131 | const second = (await tool(bobRw, { limit: 2, cursor: first.next_cursor })).value; |
| 132 | 132 | expect(second.pins.map((p: any) => p.repo)).toContain("alice/pc"); |
| 133 | 133 | expect(second.next_cursor).toBeNull(); |
| 134 | expect((await tool(bobRw, { limit: "x" })).error).toContain("invalid"); | |
| 134 | expect((await tool(bobRw, { limit: "x" })).error).toContain('argument "limit" is "x"'); | |
| 135 | 135 | for (const bad of [0, -5, 9999, 201, 1.5, "x"]) |
| 136 | expect((await tool(bobRw, { limit: bad })).error).toContain("invalid_limit"); | |
| 136 | expect((await tool(bobRw, { limit: bad })).error).toContain('argument "limit"'); | |
| 137 | 137 | expect((await tool(bobRw, { limit: 1 })).value.pins).toHaveLength(1); |
| 138 | 138 | expect((await tool(bobRw, { limit: 200 })).value.pins.length).toBeGreaterThan(0); |
| 139 | 139 | for (const n of ["pa", "pb", "pc"]) await tool(bobRw, { action: "unpin", repo: `alice/${n}` }); |
| @@ -143,6 +143,6 @@ describe("MCP pins", () => { | ||
| 143 | 143 | expect(await listed(bobRo)).toEqual([]); |
| 144 | 144 | expect((await tool(bobRo, { action: "pin", repo: "alice/open" })).error).toContain("forbidden"); |
| 145 | 145 | expect((await tool(bobRo, { action: "unpin", repo: "alice/open" })).error).toContain("forbidden"); |
| 146 | expect((await tool(bobRw, { action: "nuke", repo: "alice/open" })).error).toContain("invalid"); | |
| 146 | expect((await tool(bobRw, { action: "nuke", repo: "alice/open" })).error).toContain('argument "action" is "nuke"'); | |
| 147 | 147 | }); |
| 148 | 148 | }); |
test/mcp-prompts.test.ts +1 −1
| @@ -127,7 +127,7 @@ describe("MCP prompts", () => { | ||
| 127 | 127 | test("an unknown kind is refused with the API's error, and the token is not echoed", async () => { |
| 128 | 128 | const r = await tool(admin, { repo: "alice/game", action: "add", kind: "tiktok", token: TOKEN, at: "15:00" }); |
| 129 | 129 | expect(r.error).toBe(true); |
| 130 | expect(r.text).toContain("invalid_kind"); | |
| 130 | expect(r.text).toContain('argument "kind"'); | |
| 131 | 131 | expect(r.text).not.toContain(TOKEN); |
| 132 | 132 | expect((await tool(admin, { repo: "alice/game", action: "nope" })).error).toBe(true); |
| 133 | 133 | }); |
test/mcp-repo-labels.test.ts +1 −1
| @@ -116,7 +116,7 @@ describe("MCP repo_labels", () => { | ||
| 116 | 116 | expect(second.value.items.map((l: any) => l.name)).toEqual(["pc", "ui"]); |
| 117 | 117 | expect(second.value.next_cursor).toBeNull(); |
| 118 | 118 | for (const limit of [0, 201, 1.5, "5"]) |
| 119 | expect((await call(admin, { repo: R, action: "list", limit })).error).toContain("invalid_limit"); | |
| 119 | expect((await call(admin, { repo: R, action: "list", limit })).error).toContain('argument "limit"'); | |
| 120 | 120 | expect((await call(admin, { repo: R, action: "list", cursor: "gone" })).error).toContain("invalid_cursor"); |
| 121 | 121 | for (const l of (await call(admin, { repo: R, action: "list" })).value.items) |
| 122 | 122 | await call(admin, { repo: R, action: "remove", id: l.id }); |
test/mcp-reposet.test.ts +1 −1
| @@ -86,7 +86,7 @@ describe("MCP repo_settings", () => { | ||
| 86 | 86 | test("an invalid visibility is refused", async () => { |
| 87 | 87 | const set = await call(admin, "repo_settings", { repo: "acme/game", visibility: "secret" }); |
| 88 | 88 | expect(set.isError).toBe(true); |
| 89 | expect(set.text).toContain("visibility is public or private"); | |
| 89 | expect(set.text).toContain('argument "visibility"'); | |
| 90 | 90 | }); |
| 91 | 91 | |
| 92 | 92 | test("newOwner moves a repository; a non-admin and a missing owner are refused", async () => { |
test/mcp-restore-drill.test.ts +1 −1
| @@ -152,7 +152,7 @@ describe("MCP restore_drill", () => { | ||
| 152 | 152 | }); |
| 153 | 153 | test("an unknown action is refused", async () => { |
| 154 | 154 | const r = await call(token("alice"), "bogus"); |
| 155 | expect(r.text).toContain("action is start or status"); | |
| 155 | expect(r.text).toContain('argument "action"'); | |
| 156 | 156 | }); |
| 157 | 157 | test("an admin's read-only token is refused and nothing runs", async () => { |
| 158 | 158 | const r = await call(token("alice", "ro")); |
test/mcp-review.test.ts +2 −2
| @@ -162,7 +162,7 @@ describe("the review tool over MCP", () => { | ||
| 162 | 162 | const pull = await pullBy("four", bob); |
| 163 | 163 | const base = { repo: "alice/game", number: pull.number }; |
| 164 | 164 | expect((await tool(aliceRw, { ...base, verdict: "lgtm" })).error).toContain( |
| 165 | "verdict is approve or changes", | |
| 165 | 'argument "verdict"', | |
| 166 | 166 | ); |
| 167 | 167 | expect( |
| 168 | 168 | (await tool(aliceRw, { ...base, verdict: "changes", reason: " " })).error, |
| @@ -172,7 +172,7 @@ describe("the review tool over MCP", () => { | ||
| 172 | 172 | ).toContain("no pull #9999"); |
| 173 | 173 | expect( |
| 174 | 174 | (await tool(aliceRw, { ...base, number: "1", verdict: "approve" })).error, |
| 175 | ).toContain("no pull"); | |
| 175 | ).toContain('argument "number"'); | |
| 176 | 176 | expect( |
| 177 | 177 | (await tool(aliceRw, { repo: "nope", number: 1, verdict: "approve" })).error, |
| 178 | 178 | ).toContain("not_found"); |
test/mcp-search.test.ts +3 −4
| @@ -111,12 +111,11 @@ describe("MCP search", () => { | ||
| 111 | 111 | }); |
| 112 | 112 | |
| 113 | 113 | test("an unknown kind or a bad limit is refused in the API's words; every kind answers", async () => { |
| 114 | expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain("invalid_kind"); | |
| 115 | expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain("all, repos, issues or code"); | |
| 114 | expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain('argument "kind" is "bogus"'); | |
| 115 | expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain('one of "all", "issues", "repos", "code"'); | |
| 116 | 116 | for (const limit of [0, 101, 1.5, "5"]) { |
| 117 | 117 | const r = await tool(aliceRo, { q: "a", limit }); |
| 118 | expect(r.error).toContain("invalid_limit"); | |
| 119 | expect(r.error).toContain("1 to 100"); | |
| 118 | expect(r.error).toContain(`argument "limit" is ${JSON.stringify(limit)}; expected integer from 1 to 100`); | |
| 120 | 119 | } |
| 121 | 120 | for (const kind of ["all", "repos", "issues", "code"]) expect((await tool(aliceRo, { q: "a", kind, limit: 5 })).error).toBeUndefined(); |
| 122 | 121 | }); |
test/mcp-signup.test.ts +2 −2
| @@ -115,11 +115,11 @@ describe("MCP signup", () => { | ||
| 115 | 115 | setSignup(app.db, "open", "system"); |
| 116 | 116 | }); |
| 117 | 117 | |
| 118 | test("an unknown mode is invalid_signup", async () => { | |
| 118 | test("an unknown mode is refused naming mode", async () => { | |
| 119 | 119 | for (const mode of ["public", 3, ""]) { |
| 120 | 120 | const res = await call(adminToken, { mode, dryRun: false }); |
| 121 | 121 | expect(res.error).toBe(true); |
| 122 | expect(res.text).toContain("invalid_signup"); | |
| 122 | expect(res.text).toContain('argument "mode"'); | |
| 123 | 123 | } |
| 124 | 124 | expect(getSignup(app.db)).toBe("open"); |
| 125 | 125 | }); |
test/mcp-ssh-keys.test.ts +1 −1
| @@ -136,7 +136,7 @@ describe("MCP ssh_keys", () => { | ||
| 136 | 136 | }); |
| 137 | 137 | |
| 138 | 138 | test("an unknown action is invalid_action", async () => { |
| 139 | expect((await tool(aliceRw, { action: "rotate" })).error).toStartWith("invalid_action"); | |
| 139 | expect((await tool(aliceRw, { action: "rotate" })).error).toContain('argument "action"'); | |
| 140 | 140 | }); |
| 141 | 141 | |
| 142 | 142 | test("malformed key lines are invalid_key and store nothing", async () => { |
test/mcp-tags.test.ts +1 −1
| @@ -100,6 +100,6 @@ test("kind tags with name or action, and an unknown kind, are refused", async () | ||
| 100 | 100 | const w = tok["owner"]!; |
| 101 | 101 | expect((await mcp(w, { repo: "ada/svc", kind: "tags", name: "v1" })).error).toContain("only lists"); |
| 102 | 102 | expect((await mcp(w, { repo: "ada/svc", kind: "tags", action: "delete" })).error).toContain("only lists"); |
| 103 | expect((await mcp(w, { repo: "ada/svc", kind: "refs" })).error).toContain("branches or tags"); | |
| 103 | expect((await mcp(w, { repo: "ada/svc", kind: "refs" })).error).toContain('argument "kind"'); | |
| 104 | 104 | expect((await mcp(w, { repo: "ada/svc", kind: "branches" })).value.branches[0].name).toBe("main"); |
| 105 | 105 | }); |
test/mcp-take-back.test.ts +1 −3
| @@ -118,9 +118,7 @@ test("a pull the caller cannot see, or no pull at all, is not found", async () = | ||
| 118 | 118 | expect((await takeBack(tok["sam"]!, { repo: "ada/svc", number: shipped.number })).error).toStartWith("not_found:"); |
| 119 | 119 | const none = await takeBack(tok["ada"]!, { repo: "ada/svc", number: 999 }); |
| 120 | 120 | expect(none.error).toStartWith(`not_found: That could not be taken back: ${takeBackWords("not_found")}.`); |
| 121 | expect((await takeBack(tok["ada"]!, { repo: "ada/svc", number: "1" })).error).toStartWith( | |
| 122 | `not_found: That could not be taken back: ${takeBackWords("not_found")}.`, | |
| 123 | ); | |
| 121 | expect((await takeBack(tok["ada"]!, { repo: "ada/svc", number: "1" })).error).toContain('argument "number"'); | |
| 124 | 122 | }); |
| 125 | 123 | |
| 126 | 124 | test("a shipped pull opens the pull that undoes it; a second call is already taken back", async () => { |
test/mcp-talk-tools.test.ts +1
| @@ -247,6 +247,7 @@ describe("a newly listed write is held as before", () => { | ||
| 247 | 247 | await call("assign", { |
| 248 | 248 | repo: "alice/held", |
| 249 | 249 | number: 1, |
| 250 | kind: "issue", | |
| 250 | 251 | assignee: "mallory", |
| 251 | 252 | }), |
| 252 | 253 | ).toContain("needs_confirm"); |
test/mcp-teams.test.ts +1 −1
| @@ -118,7 +118,7 @@ describe("MCP teams", () => { | ||
| 118 | 118 | expect(r.isError).toBe(true); |
| 119 | 119 | expect(team()).toEqual(before); |
| 120 | 120 | } |
| 121 | expect((await tool(admin, { slug, dial: "50" })).text).toContain("invalid_body"); | |
| 121 | expect((await tool(admin, { slug, dial: "50" })).text).toContain('argument "dial"'); | |
| 122 | 122 | expect((await tool(admin, { slug: "nope", dial: 5 })).isError).toBe(true); |
| 123 | 123 | }); |
| 124 | 124 |
test/mcp-tell.test.ts +9 −5
| @@ -9,7 +9,7 @@ import { tmpdir } from "node:os"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { createApp, type App } from "../src/app.ts"; |
| 11 | 11 | import { newApp } from "../src/actions/apps.ts"; |
| 12 | import { refusalWords, tellAnswer } from "../src/actions/tell_answer.ts"; | |
| 12 | import { refusalWords } from "../src/actions/tell_answer.ts"; | |
| 13 | 13 | import { SAY_SOMETHING_WORDS } from "../src/actions/tell_words.ts"; |
| 14 | 14 | import { listIssues } from "../src/core/issues.ts"; |
| 15 | 15 | import { getRepo } from "../src/core/repos.ts"; |
| @@ -79,11 +79,13 @@ describe("MCP tell refusals", () => { | ||
| 79 | 79 | expect(bad.error).toBe(true); |
| 80 | 80 | }); |
| 81 | 81 | |
| 82 | test("an over-long tell is refused in the words the terminal and the page say", async () => { | |
| 82 | test("an over-long tell is refused naming the argument, with the schema's limit", async () => { | |
| 83 | 83 | const body = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000); |
| 84 | 84 | const r = await call({ repo: "alice/notes", text: body }); |
| 85 | 85 | expect(r.error).toBe(true); |
| 86 | expect(r.text).toContain(tellAnswer({ ok: false, error: "body_too_long" }, body).text); | |
| 86 | // Held to the schema's maxLength before the tool runs: named, measured, never echoed. | |
| 87 | expect(r.text).toContain('argument "text" is 68002 characters long; expected string of at most 4000 characters'); | |
| 88 | expect(r.text).not.toContain("xxxx"); | |
| 87 | 89 | }); |
| 88 | 90 | |
| 89 | 91 | /** The feed composer's own action (the studio's POST /:owner/:name/tell), asked for JSON. */ |
| @@ -98,7 +100,7 @@ describe("MCP tell refusals", () => { | ||
| 98 | 100 | return ((await res.json()) as { error: string }).error; |
| 99 | 101 | }; |
| 100 | 102 | |
| 101 | test("the composer and the MCP refuse the same input in the same words", async () => { | |
| 103 | test("the composer and the MCP refuse an empty tell in the same words; an over-long one names the argument", async () => { | |
| 102 | 104 | const long = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000); |
| 103 | 105 | for (const [text, said] of [ |
| 104 | 106 | [" ", refusalWords("empty", "")], |
| @@ -106,7 +108,9 @@ describe("MCP tell refusals", () => { | ||
| 106 | 108 | ] as const) { |
| 107 | 109 | const web = await composer(text); |
| 108 | 110 | expect(web).toBe(said); |
| 109 | expect((await call({ repo: "alice/notes", text })).text).toContain(web); | |
| 111 | const mcp = (await call({ repo: "alice/notes", text })).text; | |
| 112 | // An over-long text is the schema's to refuse on the MCP door, naming the argument. | |
| 113 | expect(mcp).toContain(text === long ? 'argument "text"' : web); | |
| 110 | 114 | } |
| 111 | 115 | app.db.query("UPDATE email_check SET verified_at = NULL").run(); |
| 112 | 116 | try { |
test/mcp-threads.test.ts +1 −1
| @@ -165,6 +165,6 @@ describe("the threads tool over MCP", () => { | ||
| 165 | 165 | expect((await tool(aliceRw, { ...base, anchor: 5 })).error).toStartWith("invalid:"); |
| 166 | 166 | expect((await tool(aliceRw, { ...base, resolved: true })).error).toStartWith("invalid:"); |
| 167 | 167 | expect((await tool(aliceRw, { repo: "alice/game", number: 9999 })).error).toStartWith("no_such_pull:"); |
| 168 | expect((await tool(aliceRw, { repo: "alice/game", number: "1" })).error).toStartWith("no_such_pull:"); | |
| 168 | expect((await tool(aliceRw, { repo: "alice/game", number: "1" })).error).toContain('argument "number"'); | |
| 169 | 169 | }); |
| 170 | 170 | }); |
test/mcp-variant.test.ts +1 −1
| @@ -154,7 +154,7 @@ describe("MCP variant", () => { | ||
| 154 | 154 | for (const answer of ["meh", "", "LIKE"]) { |
| 155 | 155 | const r = await call(cyToken, { repo: "cy/lib", number: target.number, answer }); |
| 156 | 156 | expect(r.error).toBe(true); |
| 157 | expect(r.text).toContain("invalid_answer"); | |
| 157 | expect(r.text).toContain('argument "answer"'); | |
| 158 | 158 | } |
| 159 | 159 | expect(votes(pub, target.id)).toHaveLength(0); |
| 160 | 160 | expect(getPull(app.db, pub.id, target.number)!.state).toBe("open"); |
test/mcp-wait-for.test.ts +3 −3
| @@ -127,9 +127,9 @@ describe("wait_for over MCP", () => { | ||
| 127 | 127 | tool(rw, "wait_for", { app: "alice/game", ...args }); |
| 128 | 128 | expect((await w({ issue: a, blockedBy: a })).error).toContain("itself"); |
| 129 | 129 | expect((await w({ issue: a, blockedBy: 9999 })).error).toContain("no_such_issue"); |
| 130 | expect((await w({ issue: "1", blockedBy: a })).error).toContain("no_such_issue"); | |
| 131 | expect((await w({ issue: a, blockedBy: a + 0.5 })).error).toContain("no_such_issue"); | |
| 132 | expect((await w({ issue: a, blockedBy: 1, stop: "yes" })).error).toContain("invalid_stop"); | |
| 130 | expect((await w({ issue: "1", blockedBy: a })).error).toContain('argument "issue"'); | |
| 131 | expect((await w({ issue: a, blockedBy: a + 0.5 })).error).toContain('argument "blockedBy"'); | |
| 132 | expect((await w({ issue: a, blockedBy: 1, stop: "yes" })).error).toContain('argument "stop"'); | |
| 133 | 133 | expect((await tool(rw, "wait_for", { issue: a, blockedBy: 1 })).error).toBeDefined(); |
| 134 | 134 | }); |
| 135 | 135 | }); |
test/planner-pause-chapter.test.ts +3 −1
| @@ -167,7 +167,9 @@ describe("the page and MCP", () => { | ||
| 167 | 167 | expect(done.value.says).toBe("The planner is paused until the open chapter closes."); |
| 168 | 168 | expect(pausedUntil(app.db, repo.id, new Date())).not.toBeNull(); |
| 169 | 169 | for (const bad of [{ action: "resume", chapter: true }, { action: "pause", chapter: true, until: "2099-01-01T00:00:00Z" }, { action: "pause", chapter: false }, { action: "pause", chapter: "yes" }]) |
| 170 | expect(((await mcp(bad)) as any).error).toContain("chapter is true"); | |
| 170 | // A chapter that is not a boolean is the schema's to refuse; a boolean in the wrong place, | |
| 171 | // the tool's. | |
| 172 | expect(((await mcp(bad)) as any).error).toContain(typeof bad.chapter === "boolean" ? "chapter is true" : 'argument "chapter"'); | |
| 171 | 173 | await mcp({ action: "resume", confirm: true }); |
| 172 | 174 | closeChapter("v4.0.0"); |
| 173 | 175 | }); |
test/repo-template-flag.test.ts +4 −3
| @@ -163,15 +163,16 @@ describe("the template mark", () => { | ||
| 163 | 163 | }); |
| 164 | 164 | |
| 165 | 165 | describe("the same words over the API and the MCP tool", () => { |
| 166 | test("junk is bad_template in both, with one sentence", async () => { | |
| 166 | test("junk is refused in both, the API as bad_template and the tool naming the argument", async () => { | |
| 167 | 167 | const api = await patch(tok["maker"]!, "starter", { template: "yes" }); |
| 168 | 168 | const said = (await api.json()) as { error: { code: string; message: string } | string; code?: string; message?: string }; |
| 169 | 169 | const text = JSON.stringify(said); |
| 170 | 170 | expect(text).toContain("bad_template"); |
| 171 | 171 | expect(text).toContain("template is true or false"); |
| 172 | 172 | const via = await mcp(tok["maker"]!, { repo: "maker/starter", template: "yes" }); |
| 173 | expect(via.error).toContain("bad_template"); | |
| 174 | expect(via.error).toContain("template is true or false"); | |
| 173 | // The MCP boundary refuses the wrong type first, naming the argument (#15362). | |
| 174 | expect(via.error).toContain('argument "template"'); | |
| 175 | expect(via.error).toContain("expected boolean"); | |
| 175 | 176 | }); |
| 176 | 177 | }); |
| 177 | 178 |
test/spawn-api.test.ts +1 −1
| @@ -86,7 +86,7 @@ describe("spawn over the API and MCP", () => { | ||
| 86 | 86 | expect(((await bad.json()) as any).message).toContain("size:"); |
| 87 | 87 | const viaMcp = await mcp(rw, { name: "kid", apps: ["alice/notes"], size: "huge" }); |
| 88 | 88 | expect(viaMcp.error).toBe(true); |
| 89 | expect(viaMcp.text).toContain("size:"); | |
| 89 | expect(viaMcp.text).toContain('argument "size" is "huge"'); | |
| 90 | 90 | }); |
| 91 | 91 | |
| 92 | 92 | test("dry-run is the default: the plan comes back and nothing is made", async () => { |
test/spend-words.test.ts +6 −5
| @@ -63,32 +63,33 @@ afterAll(async () => { | ||
| 63 | 63 | await rm(dir, { recursive: true, force: true }); |
| 64 | 64 | }); |
| 65 | 65 | |
| 66 | test("a grant out of range answers the module's sentence from the API and MCP", async () => { | |
| 66 | test("a grant out of range answers the module's sentence from the API and names days over MCP", async () => { | |
| 67 | 67 | const viaApi = await api("/api/v1/admin/accounts/bob/model-grant", { usdPerMonth: 20000 }); |
| 68 | 68 | expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.usdPerMonth } }); |
| 69 | 69 | const viaMcp = await tool("model_grant", { username: "bob", usdPerMonth: 20000, dryRun: false }); |
| 70 | 70 | expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.usdPerMonth}`) }); |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | test("a role's allowance out of range answers the module's sentence from the API and MCP", async () => { | |
| 73 | test("a role's allowance out of range answers the module's sentence from the API and names days over MCP", async () => { | |
| 74 | 74 | const viaApi = await api("/api/v1/admin/accounts/bob/role", { role: "member", usdPerMonth: 20000 }); |
| 75 | 75 | expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.usdPerMonth } }); |
| 76 | 76 | const viaMcp = await tool("account_role", { username: "bob", role: "member", usdPerMonth: 20000, dryRun: false }); |
| 77 | 77 | expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.usdPerMonth}`) }); |
| 78 | 78 | }); |
| 79 | 79 | |
| 80 | test("a ceiling out of range answers the module's sentence from the API and MCP", async () => { | |
| 80 | test("a ceiling out of range answers the module's sentence from the API and names days over MCP", async () => { | |
| 81 | 81 | const viaApi = await api("/api/v1/admin/accounts/bob/ceiling", { dailyUsd: 20000, perRunUsd: 1 }); |
| 82 | 82 | expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.ceilings } }); |
| 83 | 83 | const viaMcp = await tool("model_ceiling", { username: "bob", dailyUsd: 20000, perRunUsd: 1, dryRun: false }); |
| 84 | 84 | expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.ceilings}`) }); |
| 85 | 85 | }); |
| 86 | 86 | |
| 87 | test("an invite's days out of range answers the module's sentence from the API and MCP", async () => { | |
| 87 | test("an invite's days out of range answers the module's sentence from the API and names days over MCP", async () => { | |
| 88 | 88 | const viaApi = await api("/api/v1/admin/invites", { days: 31 }); |
| 89 | 89 | expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.inviteDays } }); |
| 90 | 90 | const viaMcp = await tool("mint_invite", { days: 31 }); |
| 91 | expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.inviteDays}`) }); | |
| 91 | // The MCP holds `days` to its schema's 1 to 30 before the tool runs, naming the argument. | |
| 92 | expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining('invalid: argument "days" is 31; expected integer from 1 to 30') }); | |
| 92 | 93 | }); |
| 93 | 94 | |
| 94 | 95 | test("no file under src/ but the module types the sentences out", async () => { |
test/teams-crew.test.ts +1 −1
| @@ -265,7 +265,7 @@ describe("teams drive the crew", () => { | ||
| 265 | 265 | test("MCP org_teams takes a role on add_member, refuses a bad one, and lists members with roles", async () => { |
| 266 | 266 | const bad = await mcp(rw, { org: "acme", action: "add_member", team: "Crew", user: "mason", role: "king" }); |
| 267 | 267 | expect(bad.isError).toBe(true); |
| 268 | expect(bad.text).toContain("bad_role"); | |
| 268 | expect(bad.text).toContain('argument "role" is "king"'); | |
| 269 | 269 | const added = await mcp(rw, { org: "acme", action: "add_member", team: "Crew", user: "mason", role: "builder" }); |
| 270 | 270 | expect(added.isError).toBe(false); |
| 271 | 271 | expect(JSON.parse(added.text)).toEqual({ added: true, role: "builder" }); |
test/usage.test.ts +1 −1
| @@ -498,6 +498,6 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW | ||
| 498 | 498 | expect(no.result.isError).toBe(true); |
| 499 | 499 | expect(no.result.content[0].text).toContain("forbidden"); |
| 500 | 500 | const odd = await mcp(owner, { repo: "alice/garden", days: "7" }); |
| 501 | expect(odd.result.content[0].text).toContain("invalid_days"); | |
| 501 | expect(odd.result.content[0].text).toContain('argument "days"'); | |
| 502 | 502 | }, 60_000); |
| 503 | 503 | }); |
new above
offline
This doc comment documents
badArgumentbut sits abovetype Schema. It also says enum and range are not read here, which contradicts box 1. Read them (enum, minimum, maximum, maxLength) in the loop and drop this caveat. Then remove the now-unreachable per-tool checks.