@arii/boomtick-mcp 0.3.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import { createPullRequestHandler } from "./github.create_pull_request.js";
3
+ import * as shell from "../lib/shell.js";
4
+ vi.mock("../lib/shell.js", () => ({
5
+ runCommand: vi.fn()
6
+ }));
7
+ describe("github.create_pull_request", () => {
8
+ it("should create a pull request successfully", async () => {
9
+ const mockResponse = {
10
+ status: "success",
11
+ pr: {
12
+ number: 789,
13
+ html_url: "https://github.com/owner/repo/pull/789"
14
+ }
15
+ };
16
+ vi.mocked(shell.runCommand).mockResolvedValue({
17
+ stdout: JSON.stringify(mockResponse),
18
+ stderr: "",
19
+ exitCode: 0,
20
+ durationMs: 10,
21
+ command: "td-cli gh create-pr --title 'PR' --body 'Body' --head 'feature' --base 'main'"
22
+ });
23
+ const result = await createPullRequestHandler({
24
+ title: "PR",
25
+ body: "Body",
26
+ head: "feature",
27
+ base: "main",
28
+ draft: false
29
+ });
30
+ expect(result.success).toBe(true);
31
+ expect(result.url).toBe("https://github.com/owner/repo/pull/789");
32
+ });
33
+ it("should append --repo flag when repo parameter is provided", async () => {
34
+ const mockResponse = {
35
+ status: "success",
36
+ pr: {
37
+ number: 999,
38
+ html_url: "https://github.com/org/other-repo/pull/999"
39
+ }
40
+ };
41
+ vi.mocked(shell.runCommand).mockResolvedValue({
42
+ stdout: JSON.stringify(mockResponse),
43
+ stderr: "",
44
+ exitCode: 0,
45
+ durationMs: 10,
46
+ command: "td-cli gh create-pr --title 'PR' --body 'Body' --head 'feature' --base 'main' --repo 'org/other-repo'"
47
+ });
48
+ const result = await createPullRequestHandler({
49
+ title: "PR",
50
+ body: "Body",
51
+ head: "feature",
52
+ base: "main",
53
+ draft: false,
54
+ repo: "org/other-repo"
55
+ });
56
+ expect(shell.runCommand).toHaveBeenCalledWith("td-cli", [
57
+ "gh",
58
+ "create-pr",
59
+ "--title",
60
+ "PR",
61
+ "--body",
62
+ "Body",
63
+ "--head",
64
+ "feature",
65
+ "--base",
66
+ "main",
67
+ "--repo",
68
+ "org/other-repo"
69
+ ]);
70
+ expect(result.success).toBe(true);
71
+ expect(result.url).toBe("https://github.com/org/other-repo/pull/999");
72
+ });
73
+ it("should throw error on CLI error response", async () => {
74
+ const mockResponse = {
75
+ status: "error",
76
+ message: "Branch not found"
77
+ };
78
+ vi.mocked(shell.runCommand).mockResolvedValue({
79
+ stdout: JSON.stringify(mockResponse),
80
+ stderr: "",
81
+ exitCode: 0,
82
+ durationMs: 10,
83
+ command: "td-cli gh create-pr"
84
+ });
85
+ await expect(createPullRequestHandler({
86
+ title: "PR",
87
+ body: "Body",
88
+ head: "feature",
89
+ base: "main",
90
+ draft: false
91
+ })).rejects.toThrow("Failed to create pull request: Branch not found");
92
+ });
93
+ });
@@ -0,0 +1,58 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { parseJulesSession } from "./shared.js";
3
+ describe("jules/shared", () => {
4
+ describe("parseJulesSession", () => {
5
+ it("should strip 'sessions/' prefix from session name to form ID", () => {
6
+ const input = {
7
+ name: "sessions/12345",
8
+ state: "IN_PROGRESS",
9
+ };
10
+ const result = parseJulesSession(input);
11
+ expect(result.id).toBe("12345");
12
+ expect(result.status).toBe("IN_PROGRESS");
13
+ });
14
+ it("should use raw name as ID if 'sessions/' prefix is absent", () => {
15
+ const input = {
16
+ name: "custom-session-id",
17
+ state: "SUCCEEDED",
18
+ };
19
+ expect(parseJulesSession(input).id).toBe("custom-session-id");
20
+ });
21
+ it("should default name/id to empty string if missing", () => {
22
+ expect(parseJulesSession({}).id).toBe("");
23
+ });
24
+ it("should map states to COMPLETED, FAILED, IN_PROGRESS, or fallback PENDING", () => {
25
+ expect(parseJulesSession({ state: "SUCCEEDED" }).status).toBe("COMPLETED");
26
+ expect(parseJulesSession({ state: "COMPLETED" }).status).toBe("COMPLETED");
27
+ expect(parseJulesSession({ state: "FAILED" }).status).toBe("FAILED");
28
+ expect(parseJulesSession({ state: "CANCELLED" }).status).toBe("FAILED");
29
+ expect(parseJulesSession({ state: "TERMINATED" }).status).toBe("FAILED");
30
+ expect(parseJulesSession({ state: "IN_PROGRESS" }).status).toBe("IN_PROGRESS");
31
+ expect(parseJulesSession({ state: "UNKNOWN_STATE" }).status).toBe("PENDING");
32
+ expect(parseJulesSession({}).status).toBe("PENDING");
33
+ });
34
+ it("should extract pullRequestUrl from outputs array when present", () => {
35
+ const input = {
36
+ name: "sessions/abc",
37
+ outputs: [
38
+ { type: "text", text: "logs" },
39
+ { pullRequest: { url: "https://github.com/arii/boomtick/pull/100" } },
40
+ ],
41
+ };
42
+ const session = parseJulesSession(input);
43
+ expect(session.pullRequestUrl).toBe("https://github.com/arii/boomtick/pull/100");
44
+ });
45
+ it("should return undefined pullRequestUrl if missing or invalid outputs", () => {
46
+ expect(parseJulesSession({ outputs: [] }).pullRequestUrl).toBeUndefined();
47
+ expect(parseJulesSession({ outputs: [{ other: "data" }] }).pullRequestUrl).toBeUndefined();
48
+ expect(parseJulesSession({ outputs: "not-an-array" }).pullRequestUrl).toBeUndefined();
49
+ });
50
+ it("should parse createTime or fallback to current date", () => {
51
+ const timeStr = "2025-01-01T12:00:00Z";
52
+ const sessionWithTime = parseJulesSession({ createTime: timeStr });
53
+ expect(sessionWithTime.createdAt).toEqual(new Date(timeStr));
54
+ const sessionWithoutTime = parseJulesSession({});
55
+ expect(sessionWithoutTime.createdAt).toBeInstanceOf(Date);
56
+ });
57
+ });
58
+ });
@@ -20,6 +20,10 @@ describe("repo.get_package_scripts", () => {
20
20
  vi.mocked(fs.readFile).mockRejectedValue(new Error("File not found"));
21
21
  await expect(getPackageScriptsHandler({})).rejects.toThrow("Failed to read package.json: File not found");
22
22
  });
23
+ it("should throw error when package.json is malformed", async () => {
24
+ vi.mocked(fs.readFile).mockResolvedValue("{ invalid json ");
25
+ await expect(getPackageScriptsHandler({})).rejects.toThrow(/Failed to read package.json: Malformed package.json:/);
26
+ });
23
27
  it("should filter scripts by pattern", async () => {
24
28
  const mockPkg = {
25
29
  scripts: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arii/boomtick-mcp",
3
- "version": "0.3.7",
3
+ "version": "0.4.0",
4
4
  "description": "Boomtick MCP Guide: PR Rescue + Merge Conflict Agent",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { execSync } from "child_process";
3
+
4
+ vi.mock("child_process", () => ({
5
+ execSync: vi.fn(),
6
+ }));
7
+
8
+ describe("config", () => {
9
+ const originalEnv = process.env;
10
+
11
+ beforeEach(() => {
12
+ vi.resetModules();
13
+ process.env = { ...originalEnv };
14
+ vi.mocked(execSync).mockReset();
15
+ vi.mocked(execSync).mockReturnValue("{}");
16
+ });
17
+
18
+ afterEach(() => {
19
+ process.env = originalEnv;
20
+ });
21
+
22
+ describe("initializeConfig", () => {
23
+ it("should load dynamic config from td-cli config view", async () => {
24
+ const mockConfig = { github_repo: "owner/repo", base_branch: "origin/main", vite_base_path: "/app/" };
25
+ vi.mocked(execSync).mockReturnValue(JSON.stringify(mockConfig));
26
+
27
+ const { initializeConfig } = await import("./config.js");
28
+ const result = initializeConfig();
29
+
30
+ expect(execSync).toHaveBeenCalledWith("td-cli config view", expect.anything());
31
+ expect(result).toEqual(mockConfig);
32
+ });
33
+
34
+ it("should return cached dynamic config on subsequent calls", async () => {
35
+ const mockConfig = { github_repo: "owner/repo" };
36
+ vi.mocked(execSync).mockReturnValue(JSON.stringify(mockConfig));
37
+
38
+ const { initializeConfig } = await import("./config.js");
39
+ const result1 = initializeConfig();
40
+ const result2 = initializeConfig();
41
+
42
+ expect(result1).toBe(result2);
43
+ expect(execSync).toHaveBeenCalledTimes(1);
44
+ });
45
+
46
+ it("should throw critical error when execSync fails in development or CI", async () => {
47
+ process.env.NODE_ENV = "development";
48
+ vi.mocked(execSync).mockImplementation(() => {
49
+ throw new Error("Command failed");
50
+ });
51
+
52
+ const { initializeConfig } = await import("./config.js");
53
+ expect(() => initializeConfig()).toThrow(/CRITICAL: Failed to load dynamic config/);
54
+ });
55
+
56
+ it("should log warning and set empty config when execSync fails in production", async () => {
57
+ process.env.NODE_ENV = "production";
58
+ process.env.CI = "false";
59
+ const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
60
+
61
+ vi.mocked(execSync).mockImplementation(() => {
62
+ throw new Error("Command failed");
63
+ });
64
+
65
+ const { initializeConfig } = await import("./config.js");
66
+ const result = initializeConfig();
67
+
68
+ expect(result).toEqual({});
69
+ expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining("CRITICAL: Failed to load dynamic config"));
70
+ consoleWarnSpy.mockRestore();
71
+ });
72
+ });
73
+
74
+ describe("config object getters", () => {
75
+ it("should resolve githubToken from process.env or gh CLI fallback", async () => {
76
+ process.env.GITHUB_TOKEN = "env-token-123";
77
+ const { config } = await import("./config.js");
78
+ expect(config.githubToken).toBe("env-token-123");
79
+
80
+ delete process.env.GITHUB_TOKEN;
81
+ vi.mocked(execSync).mockReturnValue("gh-cli-token\n");
82
+ expect(config.githubToken).toBe("gh-cli-token");
83
+
84
+ vi.mocked(execSync).mockImplementation(() => {
85
+ throw new Error("gh not found");
86
+ });
87
+ expect(config.githubToken).toBeUndefined();
88
+ });
89
+
90
+ it("should resolve githubOwner and githubRepo from env or cached config", async () => {
91
+ process.env.GITHUB_OWNER = "custom-owner";
92
+ process.env.GITHUB_REPO = "custom-repo";
93
+ const { config } = await import("./config.js");
94
+
95
+ expect(config.githubOwner).toBe("custom-owner");
96
+ expect(config.githubRepo).toBe("custom-repo");
97
+ });
98
+
99
+ it("should throw when githubOwner / githubRepo cannot be determined", async () => {
100
+ delete process.env.GITHUB_OWNER;
101
+ delete process.env.GITHUB_REPO;
102
+ vi.mocked(execSync).mockImplementation(() => {
103
+ throw new Error("td-cli failed");
104
+ });
105
+
106
+ process.env.NODE_ENV = "production";
107
+ process.env.CI = "false";
108
+ vi.spyOn(console, "warn").mockImplementation(() => {});
109
+
110
+ const { config, initializeConfig } = await import("./config.js");
111
+ initializeConfig();
112
+
113
+ expect(() => config.githubOwner).toThrow("GITHUB_OWNER must be set via environment variable or project_config.json");
114
+ expect(() => config.githubRepo).toThrow("GITHUB_REPO must be set via environment variable or project_config.json");
115
+ });
116
+
117
+ it("should resolve repoPath from BOOMTICK_REPO_PATH or findRepoRoot fallback", async () => {
118
+ process.env.BOOMTICK_REPO_PATH = "/custom/repo/path";
119
+ const { config } = await import("./config.js");
120
+ expect(config.repoPath).toBe("/custom/repo/path");
121
+ });
122
+
123
+ it("should resolve defaultBaseBranch, viteBasePath, and ghPath", async () => {
124
+ process.env.DEFAULT_BASE_BRANCH = "develop";
125
+ process.env.VITE_BASE_PATH = "/base/";
126
+ process.env.GH_PATH = "/usr/bin/gh";
127
+
128
+ const { config } = await import("./config.js");
129
+ expect(config.defaultBaseBranch).toBe("develop");
130
+ expect(config.viteBasePath).toBe("/base/");
131
+ expect(config.ghPath).toBe("/usr/bin/gh");
132
+ });
133
+
134
+ it("should throw when viteBasePath is missing", async () => {
135
+ delete process.env.VITE_BASE_PATH;
136
+ process.env.NODE_ENV = "production";
137
+ process.env.CI = "false";
138
+ vi.spyOn(console, "warn").mockImplementation(() => {});
139
+
140
+ const { config, initializeConfig } = await import("./config.js");
141
+ initializeConfig();
142
+
143
+ expect(() => config.viteBasePath).toThrow("VITE_BASE_PATH must be set via environment variable or project_config.json");
144
+ });
145
+ });
146
+ });
@@ -0,0 +1,27 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { sanitizeError } from "./error_utils.js";
3
+
4
+ describe("error_utils", () => {
5
+ describe("sanitizeError", () => {
6
+ it("should return 'Unknown error' when stderr is empty", () => {
7
+ expect(sanitizeError("")).toBe("Unknown error");
8
+ });
9
+
10
+ it("should return only the first line of stderr", () => {
11
+ const stderr = "Error: Something failed\n at StackTrace.line1\n at StackTrace.line2";
12
+ expect(sanitizeError(stderr)).toBe("Error: Something failed");
13
+ });
14
+
15
+ it("should truncate lines exceeding 200 characters", () => {
16
+ const longLine = "A".repeat(250);
17
+ const result = sanitizeError(longLine);
18
+ expect(result.length).toBe(200);
19
+ expect(result).toBe("A".repeat(200));
20
+ });
21
+
22
+ it("should preserve first line if under 200 characters", () => {
23
+ const line = "Fatal error: unexpected token near line 5";
24
+ expect(sanitizeError(line)).toBe(line);
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { createSuccessResult, createErrorResult } from "./result.js";
3
+
4
+ describe("result utils", () => {
5
+ describe("createSuccessResult", () => {
6
+ it("should format string data directly without JSON stringifying", () => {
7
+ const result = createSuccessResult("simple string message");
8
+ expect(result).toEqual({
9
+ content: [
10
+ {
11
+ type: "text",
12
+ text: "simple string message",
13
+ },
14
+ ],
15
+ });
16
+ expect(result.isError).toBeUndefined();
17
+ });
18
+
19
+ it("should format object data as pretty-printed JSON string", () => {
20
+ const objData = { foo: "bar", count: 42 };
21
+ const result = createSuccessResult(objData);
22
+ expect(result).toEqual({
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: JSON.stringify(objData, null, 2),
27
+ },
28
+ ],
29
+ });
30
+ expect(result.isError).toBeUndefined();
31
+ });
32
+ });
33
+
34
+ describe("createErrorResult", () => {
35
+ it("should format error result with message and isError set to true", () => {
36
+ const result = createErrorResult("Something went wrong");
37
+ expect(result).toEqual({
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: "Something went wrong",
42
+ },
43
+ ],
44
+ isError: true,
45
+ });
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,273 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { BoomtickMCPServer } from "./server.js";
3
+ import { config } from "../config.js";
4
+ import fs from "fs/promises";
5
+ import * as healthModule from "./tools.js";
6
+ import * as routeMapModule from "../tools/repo.get_route_map.js";
7
+ import * as prDiffModule from "../tools/github.get_pr_diff.js";
8
+ import * as ciLogsModule from "../tools/repo.read_ci_logs.js";
9
+ import * as lighthouseModule from "../tools/repo.run_lighthouse.js";
10
+ import * as playwrightModule from "../tools/repo.run_playwright.js";
11
+
12
+ vi.mock("fs/promises");
13
+ vi.mock("../config.js", () => ({
14
+ config: {
15
+ repoPath: "/mock/repo",
16
+ },
17
+ }));
18
+
19
+ describe("BoomtickMCPServer", () => {
20
+ let mcpServer: BoomtickMCPServer;
21
+ let serverInstance: any;
22
+ let requestHandlers: Map<string, Function>;
23
+
24
+ beforeEach(() => {
25
+ vi.resetAllMocks();
26
+ requestHandlers = new Map();
27
+
28
+ mcpServer = new BoomtickMCPServer();
29
+ serverInstance = (mcpServer as any).server;
30
+
31
+ // Retrieve registered request handlers from SDK Server instance
32
+ // SDK Server stores request handlers in server._requestHandlers or server.requestHandlers
33
+ const handlers = serverInstance._requestHandlers || serverInstance.requestHandlers;
34
+ if (handlers) {
35
+ for (const [key, handler] of handlers.entries()) {
36
+ requestHandlers.set(key, handler);
37
+ }
38
+ }
39
+ });
40
+
41
+ it("should instantiate server with correct name and capabilities", () => {
42
+ expect(serverInstance).toBeDefined();
43
+ });
44
+
45
+ describe("ListPrompts", () => {
46
+ it("should return prompts list", async () => {
47
+ const handler = requestHandlers.get("prompts/list");
48
+ expect(handler).toBeDefined();
49
+ const result = await handler!({ method: "prompts/list" });
50
+ expect(result.prompts).toBeDefined();
51
+ expect(Array.isArray(result.prompts)).toBe(true);
52
+ });
53
+ });
54
+
55
+ describe("GetPrompt", () => {
56
+ it("should read prompt file and return message", async () => {
57
+ const handler = requestHandlers.get("prompts/get");
58
+ expect(handler).toBeDefined();
59
+
60
+ vi.mocked(fs.readFile).mockResolvedValue("You are a helpful agent.");
61
+
62
+ const result = await handler!({
63
+ method: "prompts/get",
64
+ params: { name: "test-agent" },
65
+ });
66
+
67
+ expect(fs.readFile).toHaveBeenCalledWith("/mock/repo/mcp/src/agents/test-agent.prompt.md", "utf-8");
68
+ expect(result).toEqual({
69
+ messages: [
70
+ {
71
+ role: "user",
72
+ content: { type: "text", text: "You are a helpful agent." },
73
+ },
74
+ ],
75
+ });
76
+ });
77
+
78
+ it("should prevent path traversal attacks", async () => {
79
+ const handler = requestHandlers.get("prompts/get");
80
+
81
+ await expect(
82
+ handler!({
83
+ method: "prompts/get",
84
+ params: { name: "../../../etc/passwd" },
85
+ })
86
+ ).rejects.toThrow("Path traversal detected");
87
+ });
88
+
89
+ it("should throw when prompt file does not exist", async () => {
90
+ const handler = requestHandlers.get("prompts/get");
91
+ vi.mocked(fs.readFile).mockRejectedValue(new Error("File not found"));
92
+
93
+ await expect(
94
+ handler!({
95
+ method: "prompts/get",
96
+ params: { name: "nonexistent" },
97
+ })
98
+ ).rejects.toThrow("Prompt not found: nonexistent");
99
+ });
100
+ });
101
+
102
+ describe("ListResources", () => {
103
+ it("should return resources list", async () => {
104
+ const handler = requestHandlers.get("resources/list");
105
+ expect(handler).toBeDefined();
106
+ const result = await handler!({ method: "resources/list" });
107
+ expect(result.resources).toBeDefined();
108
+ expect(Array.isArray(result.resources)).toBe(true);
109
+ });
110
+ });
111
+
112
+ describe("ReadResource", () => {
113
+ it("should handle repo://package-json", async () => {
114
+ const handler = requestHandlers.get("resources/read");
115
+ vi.mocked(fs.readFile).mockResolvedValue('{"name": "test"}');
116
+
117
+ const result = await handler!({
118
+ method: "resources/read",
119
+ params: { uri: "repo://package-json" },
120
+ });
121
+
122
+ expect(result).toEqual({
123
+ contents: [{ uri: "repo://package-json", mimeType: "application/json", text: '{"name": "test"}' }],
124
+ });
125
+ });
126
+
127
+ it("should handle repo://routes", async () => {
128
+ const handler = requestHandlers.get("resources/read");
129
+ vi.spyOn(routeMapModule, "getRouteMapHandler").mockResolvedValue({ routes: ["/"] } as any);
130
+
131
+ const result = await handler!({
132
+ method: "resources/read",
133
+ params: { uri: "repo://routes" },
134
+ });
135
+
136
+ expect(result.contents[0].uri).toBe("repo://routes");
137
+ expect(JSON.parse(result.contents[0].text)).toEqual({ routes: ["/"] });
138
+ });
139
+
140
+ it("should handle repo://design-tokens", async () => {
141
+ const handler = requestHandlers.get("resources/read");
142
+ vi.mocked(fs.readFile).mockResolvedValue("export const tokens = {};");
143
+
144
+ const result = await handler!({
145
+ method: "resources/read",
146
+ params: { uri: "repo://design-tokens" },
147
+ });
148
+
149
+ expect(result).toEqual({
150
+ contents: [{ uri: "repo://design-tokens", mimeType: "text/typescript", text: "export const tokens = {};" }],
151
+ });
152
+ });
153
+
154
+ it("should handle repo://diff/:prNumber", async () => {
155
+ const handler = requestHandlers.get("resources/read");
156
+ vi.spyOn(prDiffModule, "getPrDiffHandler").mockResolvedValue({ diffText: "diff --git a b" } as any);
157
+
158
+ const result = await handler!({
159
+ method: "resources/read",
160
+ params: { uri: "repo://diff/42" },
161
+ });
162
+
163
+ expect(result).toEqual({
164
+ contents: [{ uri: "repo://diff/42", mimeType: "text/plain", text: "diff --git a b" }],
165
+ });
166
+ });
167
+
168
+ it("should handle repo://ci/:prNumber", async () => {
169
+ const handler = requestHandlers.get("resources/read");
170
+ vi.spyOn(ciLogsModule, "readCiLogsHandler").mockResolvedValue({ status: "success" } as any);
171
+
172
+ const result = await handler!({
173
+ method: "resources/read",
174
+ params: { uri: "repo://ci/42" },
175
+ });
176
+
177
+ expect(result.contents[0].uri).toBe("repo://ci/42");
178
+ expect(JSON.parse(result.contents[0].text)).toEqual({ status: "success" });
179
+ });
180
+
181
+ it("should handle repo://lighthouse/:branch", async () => {
182
+ const handler = requestHandlers.get("resources/read");
183
+ vi.spyOn(lighthouseModule, "runLighthouseHandler").mockResolvedValue({ score: 100 } as any);
184
+
185
+ const result = await handler!({
186
+ method: "resources/read",
187
+ params: { uri: "repo://lighthouse/feature-x" },
188
+ });
189
+
190
+ expect(result.contents[0].uri).toBe("repo://lighthouse/feature-x");
191
+ expect(JSON.parse(result.contents[0].text)).toEqual({ score: 100 });
192
+ });
193
+
194
+ it("should handle repo://playwright/:branch", async () => {
195
+ const handler = requestHandlers.get("resources/read");
196
+ vi.spyOn(playwrightModule, "runPlaywrightHandler").mockResolvedValue({ passed: true } as any);
197
+
198
+ const result = await handler!({
199
+ method: "resources/read",
200
+ params: { uri: "repo://playwright/feature-x" },
201
+ });
202
+
203
+ expect(result.contents[0].uri).toBe("repo://playwright/feature-x");
204
+ expect(JSON.parse(result.contents[0].text)).toEqual({ passed: true });
205
+ });
206
+
207
+ it("should throw when resource is unknown", async () => {
208
+ const handler = requestHandlers.get("resources/read");
209
+
210
+ await expect(
211
+ handler!({
212
+ method: "resources/read",
213
+ params: { uri: "repo://unknown" },
214
+ })
215
+ ).rejects.toThrow("Resource not found: repo://unknown");
216
+ });
217
+ });
218
+
219
+ describe("ListTools", () => {
220
+ it("should return tools list", async () => {
221
+ const handler = requestHandlers.get("tools/list");
222
+ expect(handler).toBeDefined();
223
+ const result = await handler!({ method: "tools/list" });
224
+ expect(result.tools).toBeDefined();
225
+ expect(Array.isArray(result.tools)).toBe(true);
226
+ });
227
+ });
228
+
229
+ describe("CallTool", () => {
230
+ it("should execute registered tool handler successfully", async () => {
231
+ const handler = requestHandlers.get("tools/call");
232
+ vi.spyOn(healthModule, "healthHandler").mockResolvedValue({ status: "ok" } as any);
233
+
234
+ const result = await handler!({
235
+ method: "tools/call",
236
+ params: { name: "boomtick.health", arguments: {} },
237
+ });
238
+
239
+ expect(result).toEqual({
240
+ content: [{ type: "text", text: JSON.stringify({ status: "ok" }, null, 2) }],
241
+ });
242
+ });
243
+
244
+ it("should return error result for unknown tool", async () => {
245
+ const handler = requestHandlers.get("tools/call");
246
+
247
+ const result = await handler!({
248
+ method: "tools/call",
249
+ params: { name: "nonexistent.tool", arguments: {} },
250
+ });
251
+
252
+ expect(result).toEqual({
253
+ content: [{ type: "text", text: "Tool not found: nonexistent.tool" }],
254
+ isError: true,
255
+ });
256
+ });
257
+
258
+ it("should return error result when tool execution throws error", async () => {
259
+ const handler = requestHandlers.get("tools/call");
260
+ vi.spyOn(healthModule, "healthHandler").mockRejectedValue(new Error("Health check failed"));
261
+
262
+ const result = await handler!({
263
+ method: "tools/call",
264
+ params: { name: "boomtick.health", arguments: {} },
265
+ });
266
+
267
+ expect(result).toEqual({
268
+ content: [{ type: "text", text: "Health check failed" }],
269
+ isError: true,
270
+ });
271
+ });
272
+ });
273
+ });