@zereight/mcp-gitlab 2.1.70 → 2.2.1

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 (158) hide show
  1. package/README.ko.md +9 -5
  2. package/README.md +15 -11
  3. package/README.pt-BR.md +9 -5
  4. package/README.zh-CN.md +9 -5
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +63 -0
  7. package/build/index.js +430 -200
  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 +232 -63
  16. package/build/tools/tool-descriptions.js +3 -3
  17. package/build/tools/tool-profile.js +66 -0
  18. package/build/utils/compact-tool-allowlist.js +14 -0
  19. package/build/utils/logger.js +34 -12
  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/credentials.test.js +0 -153
  32. package/build/test/cli/exposure.test.js +0 -104
  33. package/build/test/cli/load-config-snapshot.js +0 -5
  34. package/build/test/cli/output.test.js +0 -74
  35. package/build/test/cli/replay-command.test.js +0 -37
  36. package/build/test/cli/router.test.js +0 -183
  37. package/build/test/client-pool-test.js +0 -109
  38. package/build/test/clients/client.js +0 -34
  39. package/build/test/clients/custom-header-client.js +0 -122
  40. package/build/test/clients/sse-client.js +0 -95
  41. package/build/test/clients/stdio-client.js +0 -113
  42. package/build/test/clients/streamable-http-client.js +0 -95
  43. package/build/test/config-allowed-groups.test.js +0 -97
  44. package/build/test/create-commit-actions.test.js +0 -102
  45. package/build/test/draft-note-schema.test.js +0 -44
  46. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  47. package/build/test/dynamic-api-url-test.js +0 -304
  48. package/build/test/dynamic-routing-tests.js +0 -495
  49. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  50. package/build/test/gitlab-api-tool-errors.test.js +0 -112
  51. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  52. package/build/test/gitlab-diff-schema.test.js +0 -36
  53. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  54. package/build/test/gitlab-tag-schema.test.js +0 -51
  55. package/build/test/group-milestone-schema.test.js +0 -45
  56. package/build/test/mcp-oauth-tests.js +0 -905
  57. package/build/test/mcp-server-name.test.js +0 -87
  58. package/build/test/merge-merge-request-schema.test.js +0 -75
  59. package/build/test/multi-server-test.js +0 -190
  60. package/build/test/no-proxy-integration-test.js +0 -183
  61. package/build/test/no-proxy-test.js +0 -149
  62. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  63. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  64. package/build/test/oauth-device-flow-tests.js +0 -450
  65. package/build/test/oauth-download-url.test.js +0 -157
  66. package/build/test/oauth-startup.test.js +0 -204
  67. package/build/test/oauth-tests.js +0 -428
  68. package/build/test/path-segment-encoding.test.js +0 -98
  69. package/build/test/remote-auth-simple-test.js +0 -277
  70. package/build/test/remote-auth-tests.js +0 -314
  71. package/build/test/response-masking.test.js +0 -445
  72. package/build/test/schema-tests.js +0 -1679
  73. package/build/test/server/metrics.test.js +0 -47
  74. package/build/test/server/request-helpers.test.js +0 -48
  75. package/build/test/server/version.test.js +0 -13
  76. package/build/test/sse-auth-guard.test.js +0 -96
  77. package/build/test/sse-session-limits.test.js +0 -273
  78. package/build/test/stateless/callback-proxy.test.js +0 -510
  79. package/build/test/stateless/client-id.test.js +0 -177
  80. package/build/test/stateless/codec.test.js +0 -328
  81. package/build/test/stateless/config-ttl.test.js +0 -149
  82. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  83. package/build/test/stateless/session-id-integration.test.js +0 -675
  84. package/build/test/stateless/session-id.test.js +0 -157
  85. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  86. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  87. package/build/test/streamable-http-sse-stream.test.js +0 -350
  88. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  89. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  90. package/build/test/test-all-transport-server.js +0 -255
  91. package/build/test/test-auth-retry.js +0 -195
  92. package/build/test/test-blank-filters.js +0 -156
  93. package/build/test/test-ci-catalog.js +0 -177
  94. package/build/test/test-ci-lint.js +0 -191
  95. package/build/test/test-ci-variables.js +0 -309
  96. package/build/test/test-create-repository.js +0 -120
  97. package/build/test/test-dependency-proxy.js +0 -195
  98. package/build/test/test-deployment-tools.js +0 -463
  99. package/build/test/test-download-attachment.js +0 -190
  100. package/build/test/test-dynamic-project-scope.js +0 -524
  101. package/build/test/test-empty-toolsets.js +0 -535
  102. package/build/test/test-get-file-blame.js +0 -145
  103. package/build/test/test-get-file-contents.js +0 -128
  104. package/build/test/test-geteffectiveprojectid.js +0 -804
  105. package/build/test/test-health-check.js +0 -115
  106. package/build/test/test-issue-description-patch.js +0 -256
  107. package/build/test/test-job-artifacts.js +0 -275
  108. package/build/test/test-json-schema.js +0 -166
  109. package/build/test/test-list-group-members.js +0 -150
  110. package/build/test/test-list-group-merge-requests.js +0 -165
  111. package/build/test/test-list-issues.js +0 -170
  112. package/build/test/test-list-merge-requests.js +0 -201
  113. package/build/test/test-list-milestones.js +0 -145
  114. package/build/test/test-list-project-members.js +0 -132
  115. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  116. package/build/test/test-merge-request-approvals.js +0 -187
  117. package/build/test/test-merge-request-pipelines.js +0 -106
  118. package/build/test/test-mr-diffs-filter.js +0 -132
  119. package/build/test/test-mr-file-diffs.js +0 -251
  120. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  121. package/build/test/test-orbit.js +0 -155
  122. package/build/test/test-permission-mode.js +0 -424
  123. package/build/test/test-pipeline-schedules.js +0 -484
  124. package/build/test/test-protected-branches.js +0 -174
  125. package/build/test/test-remote-downloads.js +0 -510
  126. package/build/test/test-search-code.js +0 -275
  127. package/build/test/test-snippets.js +0 -735
  128. package/build/test/test-tags.js +0 -220
  129. package/build/test/test-todos.js +0 -195
  130. package/build/test/test-token-optimizations.js +0 -691
  131. package/build/test/test-toolset-filtering.js +0 -499
  132. package/build/test/test-update-issue-slim.js +0 -141
  133. package/build/test/test-update-project.js +0 -112
  134. package/build/test/test-upload-markdown.js +0 -206
  135. package/build/test/test-vulnerabilities.js +0 -399
  136. package/build/test/test-webhooks.js +0 -218
  137. package/build/test/tool-description-quality.test.js +0 -50
  138. package/build/test/utils/bulk-publish-options.test.js +0 -32
  139. package/build/test/utils/download-token.test.js +0 -35
  140. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  141. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  142. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  143. package/build/test/utils/graphql-query.test.js +0 -168
  144. package/build/test/utils/helpers-path.test.js +0 -104
  145. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  146. package/build/test/utils/masking.test.js +0 -384
  147. package/build/test/utils/merge-request-position.test.js +0 -57
  148. package/build/test/utils/mock-gitlab-server.js +0 -614
  149. package/build/test/utils/proxy-client-ip.test.js +0 -28
  150. package/build/test/utils/redact-sensitive.test.js +0 -32
  151. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  152. package/build/test/utils/server-launcher.js +0 -231
  153. package/build/test/utils/tool-args.test.js +0 -210
  154. package/build/test/utils/url.test.js +0 -141
  155. package/build/test/utils/version-check.test.js +0 -239
  156. package/build/test/utils/wiki-title.test.js +0 -21
  157. package/build/test-note.js +0 -54
  158. package/build/test-resolve-issue-note.js +0 -127
@@ -1,384 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import fs from "node:fs";
3
- import os from "node:os";
4
- import path from "node:path";
5
- import { describe, test } from "node:test";
6
- import { createMaskingEngine, createMaskingPolicyResolver } from "../../masking/engine.js";
7
- import { getManagedMaskingProjectIds } from "../../masking/project-scope.js";
8
- import { allTools } from "../../tools/registry.js";
9
- describe("response masking", () => {
10
- test("is a no-op and does not read a config when disabled", () => {
11
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
12
- const engine = createMaskingEngine({
13
- enabled: false,
14
- workspaceDir: workspace,
15
- configPath: "missing.json",
16
- });
17
- assert.equal(engine, undefined);
18
- });
19
- test("applies built-in rules and literal keyword rules", () => {
20
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
21
- fs.writeFileSync(path.join(workspace, ".gitlab-mcp-mask.json"), JSON.stringify({
22
- version: 1,
23
- builtins: { ipv4: { replacement: "[Address]" } },
24
- rules: [
25
- {
26
- id: "company",
27
- type: "keyword",
28
- match: "Example Corp",
29
- replacement: "Our organization",
30
- },
31
- { id: "token", type: "regex", pattern: "TOKEN-[0-9]+", replacement: "[Token]" },
32
- ],
33
- }));
34
- const engine = createMaskingEngine({ enabled: true, workspaceDir: workspace });
35
- assert.ok(engine);
36
- assert.equal(engine.maskText("Example Corp 10.20.30.40 TOKEN-123"), "Our organization [Address] [Token]");
37
- });
38
- test("masks nested tool text without recursively masking replacements", () => {
39
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
40
- fs.writeFileSync(path.join(workspace, "rules.json"), JSON.stringify({
41
- version: 1,
42
- rules: [
43
- { id: "a", type: "keyword", match: "Example Corp", replacement: "Customer Corp" },
44
- {
45
- id: "b",
46
- type: "keyword",
47
- match: "Customer Corp",
48
- replacement: "Customer organization",
49
- },
50
- ],
51
- }));
52
- const engine = createMaskingEngine({
53
- enabled: true,
54
- workspaceDir: workspace,
55
- configPath: "rules.json",
56
- });
57
- assert.ok(engine);
58
- const result = engine.maskToolResult({
59
- content: [{ type: "text", text: JSON.stringify({ description: "Example Corp" }) }],
60
- structuredContent: { nested: "Example Corp" },
61
- });
62
- assert.equal(result.content[0].text, '{"description":"Customer Corp"}');
63
- assert.deepEqual(result.structuredContent, { nested: "Customer Corp" });
64
- });
65
- test("masks plain text blocks and returned error messages", () => {
66
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
67
- const engine = createMaskingEngine({ enabled: true, workspaceDir: workspace });
68
- assert.ok(engine);
69
- const result = engine.maskToolResult({
70
- content: [{ type: "text", text: "Connect to 10.20.30.40 with glpat-abcdefghijklmnopqrst" }],
71
- });
72
- assert.equal(result.content[0].text, "Connect to [IP address] with [Token masked]");
73
- const error = engine.maskError(new Error("Failed at 10.20.30.40"));
74
- assert.equal(error instanceof Error && error.message, "Failed at [IP address]");
75
- });
76
- test("masks every documented GitLab token prefix", () => {
77
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
78
- const engine = createMaskingEngine({ enabled: true, workspaceDir: workspace });
79
- assert.ok(engine);
80
- const suffix = "abcdefghijklmnopqrst";
81
- const prefixes = [
82
- "glpat",
83
- "glrt",
84
- "glptt",
85
- "gldt",
86
- "glcbt",
87
- "glsoat",
88
- "gloas",
89
- "glagent",
90
- "glft",
91
- "glimt",
92
- ];
93
- assert.equal(engine.maskText(prefixes.map(prefix => `${prefix}-${suffix}`).join(" ")), prefixes.map(() => "[Token masked]").join(" "));
94
- });
95
- test("covers the full union of overlapping secrets without merging adjacent matches", t => {
96
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
97
- const configPath = path.join(workspace, "rules.json");
98
- t.after(() => {
99
- fs.unlinkSync(configPath);
100
- fs.rmdirSync(workspace);
101
- });
102
- fs.writeFileSync(configPath, JSON.stringify({
103
- rules: [
104
- { id: "label", type: "keyword", match: "token=glpat-", replacement: "[label]" },
105
- { id: "first", type: "keyword", match: "abc", replacement: "[first]" },
106
- { id: "second", type: "keyword", match: "cde", replacement: "[second]" },
107
- { id: "third", type: "keyword", match: "efg", replacement: "[third]" },
108
- ],
109
- }));
110
- const engine = createMaskingEngine({ enabled: true, configPath });
111
- assert.ok(engine);
112
- assert.equal(engine.maskText("token=glpat-ABCDEFGHIJKLMNOPQRST"), "[label]");
113
- assert.equal(engine.maskText("abcdefg"), "[first]");
114
- assert.equal(engine.maskText("abccde"), "[first][second]");
115
- });
116
- test("preserves plain text primitives and applies numeric keyword rules", t => {
117
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
118
- const configPath = path.join(workspace, "rules.json");
119
- t.after(() => {
120
- fs.unlinkSync(configPath);
121
- fs.rmdirSync(workspace);
122
- });
123
- fs.writeFileSync(configPath, JSON.stringify({
124
- rules: [{ id: "number", type: "keyword", match: "123456", replacement: "[number]" }],
125
- }));
126
- const engine = createMaskingEngine({ enabled: true, configPath });
127
- assert.ok(engine);
128
- const texts = ["9007199254740993\n", "123456\n", "true\n", '"ordinary text"\n'];
129
- const result = engine.maskToolResult({ content: texts.map(text => ({ type: "text", text })) });
130
- assert.deepEqual(result.content.map(block => block.text), ["9007199254740993\n", "[number]\n", "true\n", '"ordinary text"\n']);
131
- assert.equal(engine.maskToolResult({
132
- content: [{ type: "text", text: '{"123456":9007199254740993}\n' }],
133
- }, { textFormat: "plain" }).content[0].text, '{"[number]":9007199254740993}\n');
134
- });
135
- test("preserves JSON numbers and formatting while masking escaped string values", t => {
136
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
137
- t.after(() => fs.rmdirSync(workspace));
138
- const engine = createMaskingEngine({ enabled: true, workspaceDir: workspace });
139
- assert.ok(engine);
140
- const text = '{\n "id": 9007199254740993, "host": "10.20.30.\\u0034\\u0030",\n' +
141
- ' "download_url": "http://10.20.30.40/file", "nested": ["10.20.30.40"]\n}\n';
142
- assert.equal(engine.maskToolResult({ content: [{ type: "text", text }] }).content[0].text, '{\n "id": 9007199254740993, "host": "[IP address]",\n' +
143
- ' "download_url": "[Download URL masked]", "nested": ["[IP address]"]\n}\n');
144
- const unchanged = '{ "id": 9007199254740993, "value": "ordinary" }\n';
145
- assert.equal(engine.maskToolResult({ content: [{ type: "text", text: unchanged }] }).content[0].text, unchanged);
146
- });
147
- test("masks compressed IPv6 addresses", () => {
148
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
149
- const engine = createMaskingEngine({ enabled: true, workspaceDir: workspace });
150
- assert.ok(engine);
151
- assert.equal(engine.maskText("Hosts: 2001:db8::1, fe80::1234, ::1, and 2001:db8:0:0:0:0:0:1"), "Hosts: [IP address], [IP address], [IP address], and [IP address]");
152
- assert.equal(engine.maskText("Version 1:2:3 is not an IPv6 address"), "Version 1:2:3 is not an IPv6 address");
153
- });
154
- test("rejects invalid and empty-match regex rules", () => {
155
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
156
- const configPath = path.join(workspace, "bad.json");
157
- fs.writeFileSync(configPath, JSON.stringify({ rules: [{ id: "bad", type: "regex", pattern: "", replacement: "x" }] }));
158
- assert.throws(() => createMaskingEngine({ enabled: true, workspaceDir: workspace, configPath: "bad.json" }), /must not be empty/);
159
- });
160
- test("fails closed when an explicitly configured file is missing", () => {
161
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
162
- assert.throws(() => createMaskingEngine({ enabled: true, workspaceDir: workspace, configPath: "missing.json" }), /Configured masking config does not exist/);
163
- assert.throws(() => createMaskingPolicyResolver({
164
- enabled: true,
165
- workspaceDir: workspace,
166
- configPath: "missing.json",
167
- }), /Configured masking config does not exist/);
168
- });
169
- test("selects a server-owned policy by normalized GitLab instance and project", () => {
170
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
171
- const policyPath = path.join(workspace, "managed-policies.json");
172
- fs.writeFileSync(policyPath, JSON.stringify({
173
- version: 1,
174
- policyGroups: {
175
- customer: {
176
- rules: [
177
- {
178
- id: "customer",
179
- type: "keyword",
180
- match: "Customer Corp",
181
- replacement: "[customer]",
182
- },
183
- ],
184
- },
185
- },
186
- bindings: [
187
- {
188
- gitlabInstance: "https://gitlab.example.test",
189
- projectIds: [12, 13],
190
- policyGroup: "customer",
191
- },
192
- ],
193
- }));
194
- const resolver = createMaskingPolicyResolver({
195
- enabled: true,
196
- workspaceDir: workspace,
197
- policyFilePath: "managed-policies.json",
198
- });
199
- assert.ok(resolver);
200
- assert.equal(resolver
201
- .select({ gitlabInstance: "https://gitlab.example.test/api/v4", projectIds: ["12"] })
202
- .maskText("Customer Corp"), "[customer]");
203
- assert.throws(() => resolver.select({
204
- gitlabInstance: "https://another.example.test/api/v4",
205
- projectIds: [12],
206
- }), /No managed masking policy/);
207
- assert.throws(() => resolver.select({ gitlabInstance: "https://gitlab.example.test", projectIds: [14] }), /No managed masking policy/);
208
- assert.throws(() => resolver.select({ gitlabInstance: "https://gitlab.example.test", hasProjectScope: false }), /project-less tool/);
209
- });
210
- test("rejects a workspace group that conflicts with the server binding", () => {
211
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
212
- fs.writeFileSync(path.join(workspace, ".gitlab-mcp-mask.json"), JSON.stringify({ version: 2, mode: "managed", policyGroup: "one" }));
213
- fs.writeFileSync(path.join(workspace, "managed-policies.json"), JSON.stringify({
214
- version: 1,
215
- policyGroups: { one: {}, two: {} },
216
- bindings: [
217
- { gitlabInstance: "https://gitlab.example.test", projectIds: [12], policyGroup: "two" },
218
- ],
219
- }));
220
- const resolver = createMaskingPolicyResolver({
221
- enabled: true,
222
- workspaceDir: workspace,
223
- policyFilePath: "managed-policies.json",
224
- });
225
- assert.ok(resolver);
226
- assert.throws(() => resolver.select({ gitlabInstance: "https://gitlab.example.test", projectIds: [12] }), /does not match/);
227
- });
228
- test("rejects project paths and calls spanning managed policy groups", () => {
229
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
230
- const policyPath = path.join(workspace, "managed-policies.json");
231
- fs.writeFileSync(policyPath, JSON.stringify({
232
- version: 1,
233
- policyGroups: { one: {}, two: {} },
234
- bindings: [
235
- { gitlabInstance: "https://gitlab.example.test", projectIds: [12], policyGroup: "one" },
236
- { gitlabInstance: "https://gitlab.example.test", projectIds: [13], policyGroup: "two" },
237
- ],
238
- }));
239
- const resolver = createMaskingPolicyResolver({
240
- enabled: true,
241
- workspaceDir: workspace,
242
- policyFilePath: "managed-policies.json",
243
- });
244
- assert.ok(resolver);
245
- assert.throws(() => resolver.select({
246
- gitlabInstance: "https://gitlab.example.test",
247
- projectIds: ["group/project"],
248
- }), /numeric project IDs/);
249
- assert.throws(() => resolver.select({ gitlabInstance: "https://gitlab.example.test", projectIds: [12, 13] }), /span policy groups/);
250
- });
251
- test("derives managed scope only from project fields declared by the tool", () => {
252
- const globalTool = { properties: { search: { type: "string" } } };
253
- assert.deepEqual(getManagedMaskingProjectIds(globalTool, { project_id: "12", search: "example" }), { hasProjectScope: false, projectIds: [] });
254
- const projectTool = {
255
- properties: { project_id: { type: "string" }, target_project_id: { type: "string" } },
256
- };
257
- assert.deepEqual(getManagedMaskingProjectIds(projectTool, { project_id: "12", target_project_id: "13" }), { hasProjectScope: true, projectIds: ["12", "13"] });
258
- assert.deepEqual(getManagedMaskingProjectIds(projectTool, {}, () => "12"), { hasProjectScope: true, projectIds: ["12"] });
259
- });
260
- test("includes the default primary project alongside explicit and nested references", () => {
261
- const createMergeRequest = allTools.find(tool => tool.name === "create_merge_request");
262
- const updateWorkItem = allTools.find(tool => tool.name === "update_work_item");
263
- assert.ok(createMergeRequest);
264
- assert.ok(updateWorkItem);
265
- assert.deepEqual(getManagedMaskingProjectIds(createMergeRequest.inputSchema, {
266
- project_id: "",
267
- target_project_id: "13",
268
- }, () => "12"), { hasProjectScope: true, projectIds: ["12", "13"] });
269
- assert.deepEqual(getManagedMaskingProjectIds(updateWorkItem.inputSchema, {
270
- project_id: "",
271
- children_to_add: [{ project_id: "13", iid: 1 }],
272
- }, () => "12"), { hasProjectScope: true, projectIds: ["12", "13"] });
273
- });
274
- test("treats absent optional filters as unscoped and absent required projects as scoped", () => {
275
- for (const name of ["list_issues", "list_merge_requests", "list_todos"]) {
276
- const tool = allTools.find(tool => tool.name === name);
277
- assert.ok(tool, name);
278
- assert.deepEqual(getManagedMaskingProjectIds(tool.inputSchema, {}), {
279
- hasProjectScope: false,
280
- projectIds: [],
281
- });
282
- }
283
- const getIssue = allTools.find(tool => tool.name === "get_issue");
284
- assert.ok(getIssue);
285
- assert.deepEqual(getManagedMaskingProjectIds(getIssue.inputSchema, {}), {
286
- hasProjectScope: true,
287
- projectIds: [],
288
- });
289
- const groupMergeRequests = allTools.find(tool => tool.name === "list_group_merge_requests");
290
- assert.ok(groupMergeRequests);
291
- assert.deepEqual(getManagedMaskingProjectIds(groupMergeRequests.inputSchema, {
292
- group_id: "99",
293
- source_project_id: "12",
294
- }, () => "12"), { hasProjectScope: false, projectIds: [] });
295
- });
296
- test("does not use a default project for a selected group scope", () => {
297
- const webhookTool = {
298
- properties: {
299
- project_id: { type: "string" },
300
- group_id: { type: "string" },
301
- },
302
- };
303
- assert.deepEqual(getManagedMaskingProjectIds(webhookTool, { group_id: "99" }, () => "12"), { hasProjectScope: false, projectIds: [] });
304
- });
305
- test("collects nested declared project references", () => {
306
- const workItemTool = {
307
- properties: {
308
- project_id: { type: "string" },
309
- children_to_add: {
310
- type: "array",
311
- items: {
312
- type: "object",
313
- properties: { project_id: { type: "string" }, iid: { type: "number" } },
314
- },
315
- },
316
- linked_items_to_remove: {
317
- type: "array",
318
- items: {
319
- type: "object",
320
- properties: { project_id: { type: "string" }, iid: { type: "number" } },
321
- },
322
- },
323
- },
324
- };
325
- assert.deepEqual(getManagedMaskingProjectIds(workItemTool, {
326
- project_id: "12",
327
- children_to_add: [{ project_id: "13", iid: 1 }],
328
- linked_items_to_remove: [{ project_id: "14", iid: 2 }],
329
- }), { hasProjectScope: true, projectIds: ["12", "13", "14"] });
330
- });
331
- test("uses the registered work item schema to reject cross-project actions", () => {
332
- const updateWorkItem = allTools.find(tool => tool.name === "update_work_item");
333
- assert.ok(updateWorkItem);
334
- assert.deepEqual(getManagedMaskingProjectIds(updateWorkItem.inputSchema, {
335
- project_id: "12",
336
- children_to_add: [{ project_id: "13", iid: 1 }],
337
- linked_items_to_add: [{ project_id: "14", iid: 2 }],
338
- }), { hasProjectScope: true, projectIds: ["12", "13", "14"] });
339
- });
340
- test("uses the registered webhook schema without selecting a default project for a group", () => {
341
- const listWebhooks = allTools.find(tool => tool.name === "list_webhooks");
342
- assert.ok(listWebhooks);
343
- assert.deepEqual(getManagedMaskingProjectIds(listWebhooks.inputSchema, { group_id: "99" }, () => "12"), { hasProjectScope: false, projectIds: [] });
344
- });
345
- test("allows project-less tools only with the explicit built-in fallback", () => {
346
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
347
- const policyPath = path.join(workspace, "managed-policies.json");
348
- fs.writeFileSync(policyPath, JSON.stringify({
349
- version: 1,
350
- policyGroups: {},
351
- bindings: [],
352
- unboundProjectBehavior: "builtin",
353
- }));
354
- const resolver = createMaskingPolicyResolver({
355
- enabled: true,
356
- workspaceDir: workspace,
357
- policyFilePath: "managed-policies.json",
358
- });
359
- assert.ok(resolver);
360
- assert.equal(resolver
361
- .select({ gitlabInstance: "https://gitlab.example.test", hasProjectScope: false })
362
- .maskText("10.20.30.40"), "[IP address]");
363
- assert.throws(() => resolver.select({ gitlabInstance: "https://gitlab.example.test", hasProjectScope: true }), /requires a project ID/);
364
- });
365
- test("allows only explicitly designated unscoped tools to use built-in masking", () => {
366
- const workspace = fs.mkdtempSync(path.join(os.tmpdir(), "gitlab-mask-"));
367
- const policyPath = path.join(workspace, "managed-policies.json");
368
- fs.writeFileSync(policyPath, JSON.stringify({ version: 1, policyGroups: {}, bindings: [] }));
369
- const resolver = createMaskingPolicyResolver({
370
- enabled: true,
371
- workspaceDir: workspace,
372
- policyFilePath: "managed-policies.json",
373
- });
374
- assert.ok(resolver);
375
- assert.equal(resolver
376
- .select({
377
- gitlabInstance: "https://gitlab.example.test",
378
- hasProjectScope: false,
379
- allowBuiltinForUnscoped: true,
380
- })
381
- .maskText("10.20.30.40"), "[IP address]");
382
- assert.throws(() => resolver.select({ gitlabInstance: "https://gitlab.example.test", hasProjectScope: false }), /project-less tool/);
383
- });
384
- });
@@ -1,57 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, test } from "node:test";
3
- import { CreateDraftNoteSchema } from "../../schemas.js";
4
- import { omitIncompleteMergeRequestPosition } from "../../utils/merge-request-position.js";
5
- describe("When omitIncompleteMergeRequestPosition runs", () => {
6
- describe("with MCP null-injected SHAs", () => {
7
- test("should return undefined when all commit SHAs are nullish", () => {
8
- assert.equal(omitIncompleteMergeRequestPosition({
9
- base_sha: null,
10
- head_sha: null,
11
- start_sha: null,
12
- position_type: "text",
13
- }), undefined);
14
- });
15
- test("should return undefined for null and undefined", () => {
16
- assert.equal(omitIncompleteMergeRequestPosition(null), undefined);
17
- assert.equal(omitIncompleteMergeRequestPosition(undefined), undefined);
18
- });
19
- });
20
- describe("with complete position input", () => {
21
- test("should return position when all required SHAs are strings", () => {
22
- const position = {
23
- base_sha: "abc",
24
- head_sha: "def",
25
- start_sha: "ghi",
26
- position_type: "text",
27
- old_line: null,
28
- new_line: 4,
29
- };
30
- assert.deepEqual(omitIncompleteMergeRequestPosition(position), position);
31
- });
32
- });
33
- describe("with partially invalid position input", () => {
34
- test("should pass position through for schema validation to reject", () => {
35
- const position = {
36
- base_sha: "abc",
37
- head_sha: null,
38
- start_sha: "ghi",
39
- position_type: "text",
40
- };
41
- assert.deepEqual(omitIncompleteMergeRequestPosition(position), position);
42
- });
43
- test("should fail schema parse when a required SHA is missing", () => {
44
- assert.throws(() => CreateDraftNoteSchema.parse({
45
- project_id: "g/p",
46
- merge_request_iid: "1",
47
- body: "note",
48
- position: omitIncompleteMergeRequestPosition({
49
- base_sha: "abc",
50
- head_sha: null,
51
- start_sha: "ghi",
52
- position_type: "text",
53
- }),
54
- }), /expected string, received null/i);
55
- });
56
- });
57
- });