From b7127956fd0a4e68a4fa72295d416a14c43b6ddf Mon Sep 17 00:00:00 2001 From: Gavin Morgan Date: Fri, 4 Dec 2026 02:20:14 -0800 Subject: [PATCH] Refuse a re-verification request the tool would refuse `requestReverification` forwarded the caller's arguments to `request_reverification` without checking them. Every other local refusal in the SDK happens before a request: `readCoverageFiles` refuses a malformed commit SHA, a report count outside 1 to 50, duplicate names and an oversized body, and the transport refuses an MCP body over 8,192 bytes. The documented arguments of `request_reverification` are checkable without a round trip: `commit_sha` matches `^[0-9a-fA-F]{40}$`, `finding_ids` holds 1 to 20 distinct findings of one review, and an optional `note` holds 1 to 2,000 characters. Sending a request that fails one of them costs the three-request MCP handshake, and `request_reverification` is a write whose allowance the server keeps per finding and per pull request. A write that is refused after the server records it is also not proof that nothing happened, so a request the server would refuse on its arguments alone is never worth sending. Build the tool arguments through a checked helper. The note's limit counts characters, so count code points rather than the two UTF-16 units a surrogate pair spends; a note of 1,500 astral characters is within the limit even though its `length` is 3,000. The commit accepts either case, unlike the lowercase `tested_sha` a coverage upload takes. An omitted note or organization stays absent rather than arriving as null, and the forwarded finding list is a copy of the caller's. `requestReverification` becomes `async` so an invalid request rejects with a `TypeError` rather than throwing synchronously, matching `uploadCoverageFiles`. --- README.md | 2 +- src/fixes.ts | 67 +++++++++++++++++++++++++++- tests/http.test.mjs | 106 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b7d11dc..4e9c0ce 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ const result = await client.fixes.requestReverification({ if (result.isError) throw new Error("Re-verification was refused."); ``` -The commit must be the live pushed head, which the server confirms. Each request accepts 1 to 20 distinct findings from one review and an optional note of 1 to 2,000 characters. Reads require `reviews:read`; requesting re-verification also requires `reviews:request` and repository write access. Calls never retry. Results retain untrusted-text wrappers, availability, assessment gaps, and `isError`. `PENDING` and `NOT_VERIFIED` do not establish a fix, and a tool request never records a human disposition. +The commit must be the live pushed head, which the server confirms. Each request accepts 1 to 20 distinct findings from one review and an optional note of 1 to 2,000 characters. `requestReverification` refuses locally what the tool would refuse, so a malformed request rejects with a `TypeError` and sends nothing: a `commit_sha` that is not a full 40-character hexadecimal SHA in either case, a `finding_ids` list outside 1 to 20 distinct nonempty IDs, an empty `review_id`, or a note outside 1 to 2,000 characters. The note's limit counts characters, so a note of astral characters is measured by code point rather than by UTF-16 unit. Reads require `reviews:read`; requesting re-verification also requires `reviews:request` and repository write access. Calls never retry. Results retain untrusted-text wrappers, availability, assessment gaps, and `isError`. `PENDING` and `NOT_VERIFIED` do not establish a fix, and a tool request never records a human disposition. ## Contributing and development diff --git a/src/fixes.ts b/src/fixes.ts index 8ce6367..92470dc 100644 --- a/src/fixes.ts +++ b/src/fixes.ts @@ -7,6 +7,66 @@ export interface ReverificationRequest extends McpTarget { note?: string; } +const MAX_FINDINGS = 20; +const MAX_NOTE_CHARACTERS = 2_000; +// The tool takes a full commit in either case, unlike the lowercase tested_sha +// a coverage upload takes. +const COMMIT_SHA = /^[0-9a-fA-F]{40}$/; + +function identity(value: unknown, name: string): string { + if (typeof value !== "string" || value === "") + throw new TypeError(`${name} must be a nonempty string`); + return value; +} + +/** + * Builds the tool arguments, refusing locally what the tool would refuse: a + * commit that is not a full 40-character hexadecimal SHA, a finding list + * outside 1 to 20 distinct IDs, or a note outside 1 to 2,000 characters. The + * server keeps a request allowance per finding and per pull request, and a + * write it cannot confirm is not proof that nothing was recorded, so a request + * it would refuse on its arguments alone is never worth sending. + */ +function reverificationArguments( + request: ReverificationRequest, +): Record { + const reviewId = identity(request.review_id, "review_id"); + const ids = request.finding_ids; + if (!Array.isArray(ids) || ids.length < 1 || ids.length > MAX_FINDINGS) + throw new TypeError( + `finding_ids must name 1 to ${MAX_FINDINGS} findings of one review`, + ); + // A copy, so the list sent is the list this call was given. + const findings = ids.map((id, index) => + identity(id, `finding_ids[${index}]`), + ); + if (new Set(findings).size !== findings.length) + throw new TypeError("finding_ids must name distinct findings"); + if (!COMMIT_SHA.test(request.commit_sha)) + throw new TypeError( + "commit_sha must be a full 40-character hexadecimal commit SHA", + ); + const note = request.note; + const sent: Record = { + review_id: reviewId, + finding_ids: findings, + commit_sha: request.commit_sha, + }; + if (note !== undefined && note !== null) { + // The limit counts characters, so count code points rather than the two + // UTF-16 units a surrogate pair spends. + const characters = typeof note === "string" ? [...note].length : 0; + if (characters < 1 || characters > MAX_NOTE_CHARACTERS) + throw new TypeError( + `note must be 1 to ${MAX_NOTE_CHARACTERS} characters`, + ); + sent.note = note; + } + if (request.organization_id !== undefined) + sent.organization_id = request.organization_id; + return sent; +} + /** Fix context and pushed-head verification. Tool refusals retain isError. */ export class FixesClient extends McpTools { listOpenFindings( @@ -29,8 +89,11 @@ export class FixesClient extends McpTools { organization_id: options.organization_id, }); } - requestReverification(args: ReverificationRequest): Promise { - return this.call("request_reverification", args); + /** Invalid arguments reject with a `TypeError` and send no request. */ + async requestReverification( + args: ReverificationRequest, + ): Promise { + return this.call("request_reverification", reverificationArguments(args)); } getReverification( requestId: string, diff --git a/tests/http.test.mjs b/tests/http.test.mjs index 0a189be..818523c 100644 --- a/tests/http.test.mjs +++ b/tests/http.test.mjs @@ -2118,6 +2118,112 @@ test("fix helpers preserve unavailable context and never retry a verification re assert.equal(observed.length, 5); }); +test("a re-verification request refuses locally what the tool would refuse", async (t) => { + const observed = []; + const result = { content: [{ type: "text", text: "receipt" }] }; + const { baseUrl, calls } = await server(t, (_, response, seen) => { + const body = JSON.parse(seen.at(-1).body); + if (body.method === "initialize") + return json(response, 200, { + jsonrpc: "2.0", + id: 1, + result: { protocolVersion: "2025-11-25" }, + }); + if (body.method === "notifications/initialized") { + response.writeHead(202); + return response.end(); + } + observed.push(body.params.arguments); + return json(response, 200, { jsonrpc: "2.0", id: 2, result }); + }); + const client = new ProoflineClient({ baseUrl, token }); + const findings = Array.from( + { length: 20 }, + (_, n) => `00000000-0000-7000-8000-${String(n + 10).padStart(12, "0")}`, + ); + const sha = "A1b2C3d4".repeat(5); + + // The tool takes a full commit in either case, 20 findings, and a note of + // 2,000 characters, so none of those is refused here. + assert.deepEqual( + await client.fixes.requestReverification({ + review_id: reviewId, + finding_ids: findings, + commit_sha: sha, + note: "n".repeat(2000), + organization_id: orgId, + }), + result, + ); + assert.deepEqual(observed.at(-1), { + review_id: reviewId, + finding_ids: findings, + commit_sha: sha, + note: "n".repeat(2000), + organization_id: orgId, + }); + + // The limit counts characters. A note of 1,500 astral characters spends + // 3,000 UTF-16 units and stays within it. + const astral = "\u{1F600}".repeat(1500); + assert.equal(astral.length, 3000); + await client.fixes.requestReverification({ + review_id: reviewId, + finding_ids: [findingId], + commit_sha: sha, + note: astral, + }); + assert.equal(observed.at(-1).note, astral); + + // An omitted note and organization stay absent rather than arriving as null. + await client.fixes.requestReverification({ + review_id: reviewId, + finding_ids: [findingId], + commit_sha: sha, + }); + assert.deepEqual(observed.at(-1), { + review_id: reviewId, + finding_ids: [findingId], + commit_sha: sha, + }); + + const sent = calls.length; + const valid = { + review_id: reviewId, + finding_ids: [findingId], + commit_sha: sha, + }; + for (const [reason, args] of [ + ["no findings", { ...valid, finding_ids: [] }], + ["21 findings", { ...valid, finding_ids: [...findings, findingId] }], + ["a repeated finding", { ...valid, finding_ids: [findingId, findingId] }], + ["an empty finding", { ...valid, finding_ids: [""] }], + ["an unnamed finding", { ...valid, finding_ids: [undefined] }], + ["findings that are not a list", { ...valid, finding_ids: findingId }], + ["a short commit", { ...valid, commit_sha: sha.slice(1) }], + [ + "a commit that is not hexadecimal", + { ...valid, commit_sha: `g${sha.slice(1)}` }, + ], + ["an empty review", { ...valid, review_id: "" }], + ["an empty note", { ...valid, note: "" }], + ["a note of 2,001 characters", { ...valid, note: "n".repeat(2001) }], + ]) { + // Rejecting rather than throwing keeps the refusal on the promise, as an + // invalid coverage upload is. Passing the call's promise to assert.rejects + // would itself fail if the method threw synchronously. + await assert.rejects( + client.fixes.requestReverification(args), + TypeError, + reason, + ); + } + // None of them spent an MCP handshake or one of the server's per-finding and + // per-pull-request request allowances. + assert.equal(calls.length, sent); + assert.equal(observed.length, 3); +}); + test("a new public operation generates a callable typed client method", async (t) => { const root = fileURLToPath(new URL("../", import.meta.url)); const work = await mkdtemp(join(tmpdir(), "sdk-operation-"));