Files
PaperClipAI/server/src/services/tool-access/github-access-errors.test.ts
T
Devin FoleyandPaperclip 2a4a001d37 Preserve GitHub access repair guidance for MCP callers (#19655)
Return GitHub permission denials as failed MCP tool results with trusted,
connection-specific recovery guidance. Explain the personal-account and
organization App installation boundary without replaying writes or bypassing
provider-content checks. Align the repair steps with the Permissions UI.

Cover enabled model checks and malicious provider failures across direct
calls, connection tests and stored approvals. Repair the CI-exposed synthetic
onboarding environment fixture without weakening cancellation assertions.

Verified 311 targeted tests, six onboarding Playwright tests, server
typecheck, module boundaries, full CI and Apex 5/5 with all threads resolved.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-11-06 16:32:27 -08:00

63 lines
3.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { githubAccessDeniedInstructions, githubAccessError, projectGitHubActionResult } from "./github-access-errors.js";
describe("GitHub tool access failures", () => {
it.each(["integration", "personal access token"])("classifies GitHub's %s permission denial", kind => {
expect(githubAccessError("github", `GET https://api.github.com/repos/example/private: 403 Resource not accessible by ${kind} []`))
.toEqual({ errorCode: "github_access_denied" });
});
it("does not confuse rate limits, missing resources or another provider with a GitHub access denial", () => {
for (const message of ["403 API rate limit exceeded", "404 Not Found", "Repository created successfully", "Bad credentials",
"403 ".repeat(10_000), "x".repeat(4000) + "403 Resource not accessible by integration"])
expect(githubAccessError("github", message)).toBeNull();
expect(githubAccessError("notion", "403 Resource not accessible by integration")).toBeNull();
});
it("keeps unrelated saved decisions and provider errors unchanged", () => {
const result = { version: 1 as const, outcome: "accepted" as const, toolAction: {
version: 1 as const, status: "failed" as const, errorCode: "tool_error",
errorMessage: "403 Resource not accessible by integration", updatedAt: new Date().toISOString(),
} };
expect(projectGitHubActionResult("notion", result)).toBe(result);
expect(projectGitHubActionResult(undefined, result)).toBe(result);
expect(projectGitHubActionResult("github", null)).toBeNull();
});
it.each(["tool_error", "tool_execution_failed"])("projects historical %s errors using verified provider identity", errorCode => {
const result = { version: 1 as const, outcome: "accepted" as const, toolAction: {
version: 1 as const, status: "failed" as const, errorCode,
errorMessage: "403 Resource not accessible by integration", updatedAt: new Date().toISOString(),
} };
expect(projectGitHubActionResult("github", result)).toMatchObject({ toolAction: { errorCode: "github_access_denied" } });
});
it("gives repository-create recovery steps for both GitHub tool name spellings", () => {
for (const toolName of ["mcp.github:create-repository", "mcp.github:create_repository"]) {
const text = githubAccessDeniedInstructions(toolName, "managed");
expect(text).toMatch(/Do not retry/);
expect(text).toMatch(/until GitHub access is repaired/);
expect(text).toContain("https://github.com/new");
expect(text).toContain("Refresh access");
expect(text).toContain("Add More Repos on GitHub");
expect(text).toMatch(/personal account/i);
expect(text).toMatch(/organization argument/i);
expect(text).toMatch(/does not.*personal account/i);
expect(text).not.toMatch(/replace.*token|Administration|classic token/i);
}
const other = githubAccessDeniedInstructions("mcp.github:create_issue", "managed");
expect(other).toMatch(/Do not retry/);
expect(other).not.toContain("github.com/new");
});
it("gives token and unknown connections their own repair steps", () => {
const token = githubAccessDeniedInstructions("mcp.github:create_repository", "mcp-key");
expect(token).toMatch(/token.*permissions/i);
expect(token).toMatch(/replace.*token/i);
expect(token).not.toMatch(/GitHub App|Refresh access|github\.com\/new/);
const unknown = githubAccessDeniedInstructions("mcp.github:create_repository");
expect(unknown).toMatch(/authentication method/);
expect(unknown).not.toMatch(/GitHub App|Refresh access/);
});
});