@zereight/mcp-gitlab 2.1.69 → 2.2.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.
Files changed (155) hide show
  1. package/README.ko.md +10 -4
  2. package/README.md +238 -233
  3. package/README.pt-BR.md +4 -4
  4. package/README.zh-CN.md +6 -4
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +47 -0
  7. package/build/index.js +456 -237
  8. package/build/oauth-device-flow.js +80 -0
  9. package/build/oauth.js +135 -18
  10. package/build/schemas.js +1 -1
  11. package/build/server/remote-http-stack.js +39 -0
  12. package/build/tools/discover-activation.js +38 -0
  13. package/build/tools/exposed-tools.js +35 -0
  14. package/build/tools/listed-tools.js +76 -0
  15. package/build/tools/registry.js +226 -57
  16. package/build/tools/tool-profile.js +66 -0
  17. package/build/utils/compact-tool-allowlist.js +14 -0
  18. package/build/utils/logger.js +34 -12
  19. package/build/utils/url.js +15 -0
  20. package/package.json +3 -3
  21. package/build/scripts/check-skill-sync.js +0 -143
  22. package/build/scripts/generate-server-card.js +0 -39
  23. package/build/scripts/generate-tool-coverage.js +0 -58
  24. package/build/scripts/generate-tool-docs.js +0 -430
  25. package/build/scripts/tool-coverage/coverage.js +0 -341
  26. package/build/scripts/tool-coverage/coverage.test.js +0 -142
  27. package/build/test/callback-proxy-tests.js +0 -321
  28. package/build/test/cli/args.test.js +0 -175
  29. package/build/test/cli/boolean-flags.test.js +0 -106
  30. package/build/test/cli/compact-mcp-result.test.js +0 -93
  31. package/build/test/cli/exposure.test.js +0 -104
  32. package/build/test/cli/load-config-snapshot.js +0 -5
  33. package/build/test/cli/output.test.js +0 -74
  34. package/build/test/cli/replay-command.test.js +0 -37
  35. package/build/test/cli/router.test.js +0 -183
  36. package/build/test/client-pool-test.js +0 -109
  37. package/build/test/clients/client.js +0 -34
  38. package/build/test/clients/custom-header-client.js +0 -122
  39. package/build/test/clients/sse-client.js +0 -95
  40. package/build/test/clients/stdio-client.js +0 -113
  41. package/build/test/clients/streamable-http-client.js +0 -95
  42. package/build/test/config-allowed-groups.test.js +0 -97
  43. package/build/test/create-commit-actions.test.js +0 -102
  44. package/build/test/draft-note-schema.test.js +0 -44
  45. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  46. package/build/test/dynamic-api-url-test.js +0 -304
  47. package/build/test/dynamic-routing-tests.js +0 -495
  48. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  49. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  50. package/build/test/gitlab-diff-schema.test.js +0 -36
  51. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  52. package/build/test/gitlab-tag-schema.test.js +0 -51
  53. package/build/test/group-milestone-schema.test.js +0 -45
  54. package/build/test/mcp-oauth-tests.js +0 -905
  55. package/build/test/mcp-server-name.test.js +0 -87
  56. package/build/test/merge-merge-request-schema.test.js +0 -75
  57. package/build/test/multi-server-test.js +0 -190
  58. package/build/test/no-proxy-integration-test.js +0 -183
  59. package/build/test/no-proxy-test.js +0 -149
  60. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  61. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  62. package/build/test/oauth-device-flow-tests.js +0 -450
  63. package/build/test/oauth-startup.test.js +0 -204
  64. package/build/test/oauth-tests.js +0 -428
  65. package/build/test/path-segment-encoding.test.js +0 -98
  66. package/build/test/remote-auth-simple-test.js +0 -277
  67. package/build/test/remote-auth-tests.js +0 -314
  68. package/build/test/response-masking.test.js +0 -445
  69. package/build/test/schema-tests.js +0 -1679
  70. package/build/test/server/metrics.test.js +0 -47
  71. package/build/test/server/request-helpers.test.js +0 -48
  72. package/build/test/server/version.test.js +0 -13
  73. package/build/test/sse-auth-guard.test.js +0 -96
  74. package/build/test/sse-session-limits.test.js +0 -273
  75. package/build/test/stateless/callback-proxy.test.js +0 -510
  76. package/build/test/stateless/client-id.test.js +0 -177
  77. package/build/test/stateless/codec.test.js +0 -328
  78. package/build/test/stateless/config-ttl.test.js +0 -149
  79. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  80. package/build/test/stateless/session-id-integration.test.js +0 -675
  81. package/build/test/stateless/session-id.test.js +0 -157
  82. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  83. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  84. package/build/test/streamable-http-sse-stream.test.js +0 -350
  85. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  86. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  87. package/build/test/test-all-transport-server.js +0 -255
  88. package/build/test/test-auth-retry.js +0 -195
  89. package/build/test/test-blank-filters.js +0 -156
  90. package/build/test/test-ci-catalog.js +0 -177
  91. package/build/test/test-ci-lint.js +0 -191
  92. package/build/test/test-ci-variables.js +0 -309
  93. package/build/test/test-create-repository.js +0 -120
  94. package/build/test/test-dependency-proxy.js +0 -195
  95. package/build/test/test-deployment-tools.js +0 -463
  96. package/build/test/test-download-attachment.js +0 -190
  97. package/build/test/test-dynamic-project-scope.js +0 -524
  98. package/build/test/test-empty-toolsets.js +0 -535
  99. package/build/test/test-get-file-blame.js +0 -145
  100. package/build/test/test-get-file-contents.js +0 -128
  101. package/build/test/test-geteffectiveprojectid.js +0 -812
  102. package/build/test/test-health-check.js +0 -115
  103. package/build/test/test-issue-description-patch.js +0 -256
  104. package/build/test/test-job-artifacts.js +0 -275
  105. package/build/test/test-json-schema.js +0 -166
  106. package/build/test/test-list-group-members.js +0 -150
  107. package/build/test/test-list-group-merge-requests.js +0 -165
  108. package/build/test/test-list-issues.js +0 -170
  109. package/build/test/test-list-merge-requests.js +0 -201
  110. package/build/test/test-list-milestones.js +0 -145
  111. package/build/test/test-list-project-members.js +0 -132
  112. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  113. package/build/test/test-merge-request-approvals.js +0 -187
  114. package/build/test/test-merge-request-pipelines.js +0 -106
  115. package/build/test/test-mr-diffs-filter.js +0 -132
  116. package/build/test/test-mr-file-diffs.js +0 -251
  117. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  118. package/build/test/test-orbit.js +0 -155
  119. package/build/test/test-permission-mode.js +0 -424
  120. package/build/test/test-pipeline-schedules.js +0 -482
  121. package/build/test/test-protected-branches.js +0 -174
  122. package/build/test/test-remote-downloads.js +0 -510
  123. package/build/test/test-search-code.js +0 -275
  124. package/build/test/test-snippets.js +0 -735
  125. package/build/test/test-tags.js +0 -220
  126. package/build/test/test-todos.js +0 -195
  127. package/build/test/test-token-optimizations.js +0 -691
  128. package/build/test/test-toolset-filtering.js +0 -499
  129. package/build/test/test-update-issue-slim.js +0 -141
  130. package/build/test/test-update-project.js +0 -112
  131. package/build/test/test-upload-markdown.js +0 -206
  132. package/build/test/test-vulnerabilities.js +0 -399
  133. package/build/test/test-webhooks.js +0 -218
  134. package/build/test/tool-description-quality.test.js +0 -50
  135. package/build/test/utils/bulk-publish-options.test.js +0 -32
  136. package/build/test/utils/download-token.test.js +0 -35
  137. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  138. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  139. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  140. package/build/test/utils/graphql-query.test.js +0 -168
  141. package/build/test/utils/helpers-path.test.js +0 -104
  142. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  143. package/build/test/utils/masking.test.js +0 -384
  144. package/build/test/utils/merge-request-position.test.js +0 -57
  145. package/build/test/utils/mock-gitlab-server.js +0 -614
  146. package/build/test/utils/proxy-client-ip.test.js +0 -28
  147. package/build/test/utils/redact-sensitive.test.js +0 -32
  148. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  149. package/build/test/utils/server-launcher.js +0 -231
  150. package/build/test/utils/tool-args.test.js +0 -210
  151. package/build/test/utils/url.test.js +0 -128
  152. package/build/test/utils/version-check.test.js +0 -239
  153. package/build/test/utils/wiki-title.test.js +0 -21
  154. package/build/test-note.js +0 -54
  155. package/build/test-resolve-issue-note.js +0 -127
@@ -1,341 +0,0 @@
1
- /**
2
- * Portable pure logic for MCP `tools/call` coverage detection.
3
- *
4
- * A tool counts as invoked when test source sends that name through MCP, in one
5
- * of these syntax-scoped positions only:
6
- *
7
- * - `callTool("name")`, `callToolJson("name")`, `client.callTool("name")`,
8
- * `callTool(envOrUrl, "name")` — the name is a string literal directly in the
9
- * argument list of a `callTool*` callee (identifier or property access).
10
- * - `client.callTool({ name: "name", arguments })` — SDK shape: the name is the
11
- * `name` property of an object literal passed as the FIRST argument.
12
- * - `{ method: "tools/call", params: { name: "name" } }` — the `name` property of
13
- * a `params` object inside the SAME object literal that carries the method.
14
- * - `send(proc, "tools/call", { name: "name" })` — the `name` property of an
15
- * object literal passed as the argument right after a `"tools/call"` method
16
- * argument (request-helper shape, any callee).
17
- *
18
- * Deliberately not counted:
19
- *
20
- * - `callTool(toolName, { name: "other" })` — object past the first argument is
21
- * tool input, not the invoked name.
22
- * - `name: "tool"` properties outside a `tools/call` payload (fixtures, `tools/list`
23
- * mocks, tool arguments) in files that merely mention `tools/call`.
24
- * - variable names (`callTool(env, toolName)`) — not statically resolvable.
25
- *
26
- * No filesystem or registry access here; the caller supplies file texts and the
27
- * tool-name set. The only dependency is the TypeScript parser (devDependency).
28
- */
29
- import ts from "typescript";
30
- export const SKIP_FILES = new Set(["tool-description-quality.test.ts"]);
31
- export const GROUP_ORDER = [
32
- "projects",
33
- "repositories",
34
- "branches",
35
- "groups",
36
- "merge_requests",
37
- "issues",
38
- "labels",
39
- "workitems",
40
- "ci",
41
- "pipelines",
42
- "milestones",
43
- "wiki",
44
- "releases",
45
- "tags",
46
- "users",
47
- "variables",
48
- "webhooks",
49
- "search",
50
- "dependency_proxy",
51
- "vulnerabilities",
52
- "orbit",
53
- "snippets",
54
- ];
55
- export const GROUP_TITLE = {
56
- merge_requests: "Merge Requests",
57
- issues: "Issues",
58
- repositories: "Projects & Files",
59
- branches: "Branches & Commits",
60
- projects: "Projects & Namespaces",
61
- labels: "Labels",
62
- ci: "CI Lint",
63
- groups: "Groups",
64
- pipelines: "Pipelines, Jobs & Deployments",
65
- milestones: "Milestones",
66
- wiki: "Wiki",
67
- releases: "Releases",
68
- tags: "Tags",
69
- users: "Users & Events",
70
- workitems: "Work Items",
71
- webhooks: "Webhooks",
72
- search: "Search",
73
- variables: "Variables",
74
- dependency_proxy: "Dependency Proxy",
75
- vulnerabilities: "Vulnerabilities",
76
- orbit: "GitLab Orbit",
77
- snippets: "Snippets",
78
- meta: "Meta & GraphQL",
79
- };
80
- export const CANARY_INVOKED = [
81
- "list_project_variables",
82
- "orbit_query",
83
- "list_pipeline_schedules",
84
- "search_code",
85
- ];
86
- export const MIN_INVOKED = 146;
87
- const CALL_TOOL_CALLEE = /^callTool[A-Za-z]*$/;
88
- function unwrap(expression) {
89
- let current = expression;
90
- while (ts.isAsExpression(current) ||
91
- ts.isSatisfiesExpression(current) ||
92
- ts.isParenthesizedExpression(current) ||
93
- ts.isNonNullExpression(current)) {
94
- current = current.expression;
95
- }
96
- return current;
97
- }
98
- function stringValue(expression) {
99
- const inner = unwrap(expression);
100
- if (ts.isStringLiteral(inner) || ts.isNoSubstitutionTemplateLiteral(inner)) {
101
- return inner.text;
102
- }
103
- return undefined;
104
- }
105
- function propertyKey(prop) {
106
- const key = prop.name;
107
- if (ts.isIdentifier(key) || ts.isStringLiteral(key)) {
108
- return key.text;
109
- }
110
- return undefined;
111
- }
112
- function namePropertyOf(object) {
113
- for (const prop of object.properties) {
114
- if (!ts.isPropertyAssignment(prop)) {
115
- continue;
116
- }
117
- if (propertyKey(prop) !== "name") {
118
- continue;
119
- }
120
- return stringValue(prop.initializer);
121
- }
122
- return undefined;
123
- }
124
- function callToolCalleeName(callee) {
125
- if (ts.isIdentifier(callee)) {
126
- return callee.text;
127
- }
128
- if (ts.isPropertyAccessExpression(callee)) {
129
- return callee.name.text;
130
- }
131
- return undefined;
132
- }
133
- function collectCallHits(node, toolNames) {
134
- const calleeName = callToolCalleeName(node.expression);
135
- if (!calleeName || !CALL_TOOL_CALLEE.test(calleeName)) {
136
- return [];
137
- }
138
- const hits = [];
139
- node.arguments.forEach((arg, index) => {
140
- const direct = stringValue(arg);
141
- if (direct && toolNames.has(direct)) {
142
- hits.push(direct);
143
- return;
144
- }
145
- // SDK shape only: client.callTool({ name, arguments }) — the object must be
146
- // the first argument. Objects in later positions are tool input.
147
- if (index === 0 && ts.isObjectLiteralExpression(unwrap(arg))) {
148
- const named = namePropertyOf(unwrap(arg));
149
- if (named && toolNames.has(named)) {
150
- hits.push(named);
151
- }
152
- }
153
- });
154
- return hits;
155
- }
156
- function collectMethodArgHit(node, toolNames) {
157
- const args = node.arguments;
158
- for (let index = 0; index + 1 < args.length; index++) {
159
- if (stringValue(args[index]) !== "tools/call") {
160
- continue;
161
- }
162
- const params = unwrap(args[index + 1]);
163
- if (!ts.isObjectLiteralExpression(params)) {
164
- continue;
165
- }
166
- const named = namePropertyOf(params);
167
- if (named && toolNames.has(named)) {
168
- return named;
169
- }
170
- }
171
- return undefined;
172
- }
173
- function collectPayloadHit(node, toolNames) {
174
- let isToolsCall = false;
175
- let paramsName;
176
- for (const prop of node.properties) {
177
- if (!ts.isPropertyAssignment(prop)) {
178
- continue;
179
- }
180
- const key = propertyKey(prop);
181
- if (key === "method" && stringValue(prop.initializer) === "tools/call") {
182
- isToolsCall = true;
183
- }
184
- if (key === "params") {
185
- const params = unwrap(prop.initializer);
186
- if (ts.isObjectLiteralExpression(params)) {
187
- paramsName = namePropertyOf(params);
188
- }
189
- }
190
- }
191
- if (isToolsCall && paramsName && toolNames.has(paramsName)) {
192
- return paramsName;
193
- }
194
- return undefined;
195
- }
196
- /**
197
- * Scan one source text and return the invoked tool names found in supported
198
- * call positions. `fileName` selects the TS/JS grammar; unknown extensions
199
- * parse as TypeScript.
200
- */
201
- export function scanSourceForInvocations(sourceText, fileName, toolNames) {
202
- const hits = new Set();
203
- const scriptKind = fileName.endsWith(".js") ? ts.ScriptKind.JS : ts.ScriptKind.TS;
204
- const sourceFile = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest, false, scriptKind);
205
- function visit(node) {
206
- if (ts.isCallExpression(node)) {
207
- for (const hit of collectCallHits(node, toolNames)) {
208
- hits.add(hit);
209
- }
210
- const methodHit = collectMethodArgHit(node, toolNames);
211
- if (methodHit) {
212
- hits.add(methodHit);
213
- }
214
- }
215
- if (ts.isObjectLiteralExpression(node)) {
216
- const hit = collectPayloadHit(node, toolNames);
217
- if (hit) {
218
- hits.add(hit);
219
- }
220
- }
221
- ts.forEachChild(node, visit);
222
- }
223
- visit(sourceFile);
224
- return hits;
225
- }
226
- /**
227
- * Aggregate per-file scan results into tool -> sorted file list. Every known
228
- * tool gets an entry so uncovered tools render as `- [ ]`.
229
- */
230
- export function collectInvocations(files, toolNames) {
231
- const hits = new Map();
232
- for (const name of toolNames) {
233
- hits.set(name, []);
234
- }
235
- for (const file of files) {
236
- for (const name of scanSourceForInvocations(file.text, file.path, toolNames)) {
237
- const list = hits.get(name);
238
- if (list && !list.includes(file.path)) {
239
- list.push(file.path);
240
- }
241
- }
242
- }
243
- for (const list of hits.values()) {
244
- list.sort();
245
- }
246
- return hits;
247
- }
248
- export function countInvoked(toolNames, hits) {
249
- return toolNames.filter(name => (hits.get(name) ?? []).length > 0).length;
250
- }
251
- export function groupToolsByToolset(toolNames, definitions) {
252
- const categorized = new Set();
253
- const grouped = [];
254
- for (const id of GROUP_ORDER) {
255
- const definition = definitions.find(item => item.id === id);
256
- if (!definition) {
257
- throw new Error(`GROUP_ORDER lists '${id}' but TOOLSET_DEFINITIONS does not`);
258
- }
259
- const tools = [...definition.tools];
260
- for (const name of tools) {
261
- categorized.add(name);
262
- }
263
- grouped.push({ id, tools });
264
- }
265
- const meta = toolNames.filter(name => !categorized.has(name));
266
- if (meta.length > 0) {
267
- grouped.push({ id: "meta", tools: meta });
268
- }
269
- return grouped;
270
- }
271
- export function percent(invoked, total) {
272
- if (total === 0) {
273
- return "0.0%";
274
- }
275
- return `${((invoked / total) * 100).toFixed(1)}%`;
276
- }
277
- export function toolDocsHref(groupId, toolName) {
278
- const slug = groupId.replace(/_/g, "-");
279
- return `../tools/${slug}.md#${toolName}`;
280
- }
281
- export function formatFiles(files) {
282
- return files.map(file => `\`${file}\``).join(", ");
283
- }
284
- export function buildCoverageMarkdown(toolNames, hits, grouped) {
285
- const invokedCount = countInvoked(toolNames, hits);
286
- const lines = [
287
- "# Tool invocation coverage",
288
- "",
289
- "<!-- Generated by scripts/generate-tool-coverage.ts. Do not edit. -->",
290
- "",
291
- "This is **MCP `tools/call` coverage**, not GitLab REST coverage and not line coverage.",
292
- "",
293
- 'A tool counts as invoked when a test sends that name through MCP (`callTool` / `callToolJson` / `callToolAsync` / `client.callTool`, or a `tools/call` payload with `name: "…"`). Listing a name in a toolset filter or description-quality test does not count. `test:live` (`test/validate-api.js`) is a REST smoke check and is not included.',
294
- "",
295
- "| | |",
296
- "| --- | ---: |",
297
- `| Tools | ${toolNames.length} |`,
298
- `| Invoked | ${invokedCount} |`,
299
- `| Coverage | ${percent(invokedCount, toolNames.length)} |`,
300
- "",
301
- "## By toolset",
302
- "",
303
- "| Toolset | Invoked | Total | Coverage |",
304
- "| --- | ---: | ---: | ---: |",
305
- ];
306
- for (const group of grouped) {
307
- const invoked = countInvoked(group.tools, hits);
308
- const title = GROUP_TITLE[group.id] ?? group.id;
309
- lines.push(`| [${title}](#${group.id}) | ${invoked} | ${group.tools.length} | ${percent(invoked, group.tools.length)} |`);
310
- }
311
- lines.push("");
312
- for (const group of grouped) {
313
- const title = GROUP_TITLE[group.id] ?? group.id;
314
- lines.push(`## ${title}`);
315
- lines.push("");
316
- lines.push(`<a id="${group.id}"></a>`);
317
- lines.push("");
318
- for (const name of group.tools) {
319
- const files = hits.get(name) ?? [];
320
- const link = `[\`${name}\`](${toolDocsHref(group.id, name)})`;
321
- if (files.length > 0) {
322
- lines.push(`- [x] ${link} — ${formatFiles(files)}`);
323
- }
324
- else {
325
- lines.push(`- [ ] ${link}`);
326
- }
327
- }
328
- lines.push("");
329
- }
330
- return `${lines.join("\n").trimEnd()}\n`;
331
- }
332
- export function assertDetectorHealthy(hits, invokedCount) {
333
- if (invokedCount < MIN_INVOKED) {
334
- throw new Error(`scanner found ${invokedCount} invoked tools; expected at least ${MIN_INVOKED} (detector probably broken)`);
335
- }
336
- for (const name of CANARY_INVOKED) {
337
- if ((hits.get(name) ?? []).length === 0) {
338
- throw new Error(`canary tool ${name} was not detected as invoked (detector probably broken)`);
339
- }
340
- }
341
- }
@@ -1,142 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
- import { assertDetectorHealthy, buildCoverageMarkdown, CANARY_INVOKED, collectInvocations, countInvoked, formatFiles, GROUP_ORDER, groupToolsByToolset, MIN_INVOKED, percent, scanSourceForInvocations, toolDocsHref, } from "./coverage.js";
4
- const TOOLS = new Set(["list_issues", "get_project", "orbit_query"]);
5
- function scan(source) {
6
- return scanSourceForInvocations(source, "probe.ts", TOOLS);
7
- }
8
- describe("scanSourceForInvocations", () => {
9
- test("counts a string literal directly in the argument list", () => {
10
- assert.deepStrictEqual(scan(`await callTool("list_issues", { project_id: "1" });`), new Set(["list_issues"]));
11
- });
12
- test("counts the name in second position after env", () => {
13
- assert.deepStrictEqual(scan(`await callToolAsync(baseEnv(url), "orbit_query", { query });`), new Set(["orbit_query"]));
14
- });
15
- test("counts property-access callees", () => {
16
- assert.deepStrictEqual(scan(`await client.callTool("get_project", { project_id: "1" });`), new Set(["get_project"]));
17
- });
18
- test("counts the SDK object shape when it is the first argument", () => {
19
- assert.deepStrictEqual(scan(`await client.callTool({ name: "list_issues", arguments: {} });`), new Set(["list_issues"]));
20
- });
21
- test("ignores a name object past the first argument (tool input, not invocation)", () => {
22
- assert.deepStrictEqual(scan(`await callTool(toolName, { name: "get_project" });`), new Set([]));
23
- });
24
- test("ignores literals after the call expression closes", () => {
25
- assert.deepStrictEqual(scan(`await callTool(env, toolName, args);\nconst label = "get_project";`), new Set([]));
26
- });
27
- test("ignores variable names", () => {
28
- assert.deepStrictEqual(scan(`await callTool(env, toolName, args);`), new Set([]));
29
- });
30
- test("ignores callees that are not callTool*", () => {
31
- assert.deepStrictEqual(scan(`await callListIssues({ project_id: "1" }, env);\nnotify("get_project");`), new Set([]));
32
- });
33
- test("counts a name inside the same literal as method tools/call", () => {
34
- assert.deepStrictEqual(scan(`JSON.stringify({
35
- jsonrpc: "2.0",
36
- id: 1,
37
- method: "tools/call",
38
- params: { name: "list_issues", arguments: args },
39
- });`), new Set(["list_issues"]));
40
- });
41
- test("ignores name properties outside the tools/call payload", () => {
42
- assert.deepStrictEqual(scan(`
43
- const listing = { tools: [{ name: "orbit_query", description: "q" }] };
44
- JSON.stringify({ method: "tools/call", params: { name: "list_issues", arguments: {} } });
45
- `), new Set(["list_issues"]));
46
- });
47
- test("ignores a variable name in the payload", () => {
48
- assert.deepStrictEqual(scan(`JSON.stringify({ method: "tools/call", params: { name: toolName } });`), new Set([]));
49
- });
50
- test("counts a request-helper call with method and params arguments", () => {
51
- assert.deepStrictEqual(scan(`await sendMcpRequest(proc, "tools/call", { name: "get_project", arguments: {} });`), new Set(["get_project"]));
52
- });
53
- test("ignores request-helper calls for other methods", () => {
54
- assert.deepStrictEqual(scan(`await sendMcpRequest(proc, "initialize", { name: "get_project" });`), new Set([]));
55
- });
56
- test("ignores request-helper calls with non-object params", () => {
57
- assert.deepStrictEqual(scan(`await sendMcpRequest(proc, "tools/call", params);`), new Set([]));
58
- });
59
- test("ignores tools/call when params is not an inline object", () => {
60
- assert.deepStrictEqual(scan(`JSON.stringify({ method: "tools/call", params });`), new Set([]));
61
- });
62
- test("accepts quoted property keys and single quotes", () => {
63
- assert.deepStrictEqual(scan(`JSON.stringify({ "method": 'tools/call', "params": { "name": 'get_project' } });`), new Set(["get_project"]));
64
- });
65
- test("unwraps as expressions around the name", () => {
66
- assert.deepStrictEqual(scan(`await callTool("list_issues" as string);`), new Set(["list_issues"]));
67
- });
68
- test("ignores names outside the known tool set", () => {
69
- assert.deepStrictEqual(scan(`await callTool("no_such_tool", {});`), new Set([]));
70
- });
71
- test("parses .js sources", () => {
72
- const hits = scanSourceForInvocations(`await callTool("get_project", {});`, "probe.js", TOOLS);
73
- assert.deepStrictEqual(hits, new Set(["get_project"]));
74
- });
75
- });
76
- describe("collectInvocations", () => {
77
- test("aggregates per-file hits into sorted file lists", () => {
78
- const hits = collectInvocations([
79
- { path: "test/b.ts", text: `callTool("get_project", {});` },
80
- { path: "test/a.ts", text: `callTool("get_project", {}); callTool("list_issues", {});` },
81
- { path: "test/a.ts", text: `callTool("get_project", {});` },
82
- ], TOOLS);
83
- assert.deepStrictEqual(hits.get("get_project"), ["test/a.ts", "test/b.ts"]);
84
- assert.deepStrictEqual(hits.get("list_issues"), ["test/a.ts"]);
85
- assert.deepStrictEqual(hits.get("orbit_query"), []);
86
- });
87
- });
88
- describe("groupToolsByToolset", () => {
89
- test("groups known toolsets and buckets the rest as meta", () => {
90
- const definitions = GROUP_ORDER.map(id => ({
91
- id,
92
- tools: id === "issues" ? ["list_issues"] : [],
93
- }));
94
- const grouped = groupToolsByToolset(["list_issues", "stray_tool"], definitions);
95
- assert.strictEqual(grouped.find(g => g.id === "issues")?.tools.join(","), "list_issues");
96
- assert.strictEqual(grouped.at(-1)?.id, "meta");
97
- assert.deepStrictEqual(grouped.at(-1)?.tools, ["stray_tool"]);
98
- });
99
- test("throws when GROUP_ORDER names a missing toolset", () => {
100
- assert.throws(() => groupToolsByToolset([], []), /GROUP_ORDER lists 'projects'/);
101
- });
102
- });
103
- describe("markdown helpers", () => {
104
- test("percent handles zero totals", () => {
105
- assert.strictEqual(percent(1, 2), "50.0%");
106
- assert.strictEqual(percent(0, 0), "0.0%");
107
- });
108
- test("toolDocsHref slugifies the group id", () => {
109
- assert.strictEqual(toolDocsHref("merge_requests", "list_issues"), "../tools/merge-requests.md#list_issues");
110
- });
111
- test("formatFiles wraps paths in code spans", () => {
112
- assert.strictEqual(formatFiles(["test/a.ts", "test/b.ts"]), "`test/a.ts`, `test/b.ts`");
113
- });
114
- test("countInvoked counts tools with at least one file", () => {
115
- const hits = new Map([
116
- ["list_issues", ["test/a.ts"]],
117
- ["get_project", []],
118
- ]);
119
- assert.strictEqual(countInvoked(["list_issues", "get_project"], hits), 1);
120
- });
121
- test("buildCoverageMarkdown renders checked and unchecked rows", () => {
122
- const markdown = buildCoverageMarkdown(["list_issues", "get_project"], new Map([
123
- ["list_issues", ["test/a.ts"]],
124
- ["get_project", []],
125
- ]), [{ id: "issues", tools: ["list_issues", "get_project"] }]);
126
- assert.match(markdown, /\| Invoked \| 1 \|/);
127
- assert.match(markdown, /- \[x\] \[`list_issues`\].*`test\/a\.ts`/);
128
- assert.match(markdown, /- \[ \] \[`get_project`\]/);
129
- });
130
- });
131
- describe("assertDetectorHealthy", () => {
132
- test("passes at the floor with all canaries present", () => {
133
- const hits = new Map(CANARY_INVOKED.map(name => [name, ["test/a.ts"]]));
134
- assert.doesNotThrow(() => assertDetectorHealthy(hits, MIN_INVOKED));
135
- });
136
- test("throws below the floor", () => {
137
- assert.throws(() => assertDetectorHealthy(new Map(), MIN_INVOKED - 1), /expected at least/);
138
- });
139
- test("throws when a canary is missing", () => {
140
- assert.throws(() => assertDetectorHealthy(new Map(), MIN_INVOKED + 10), /canary tool/);
141
- });
142
- });