Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
67 changes: 65 additions & 2 deletions src/fixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> {
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<string, unknown> = {
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(
Expand All @@ -29,8 +89,11 @@ export class FixesClient extends McpTools {
organization_id: options.organization_id,
});
}
requestReverification(args: ReverificationRequest): Promise<KnowledgeResult> {
return this.call("request_reverification", args);
/** Invalid arguments reject with a `TypeError` and send no request. */
async requestReverification(
args: ReverificationRequest,
): Promise<KnowledgeResult> {
return this.call("request_reverification", reverificationArguments(args));
}
getReverification(
requestId: string,
Expand Down
106 changes: 106 additions & 0 deletions tests/http.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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-"));
Expand Down