@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,463 +0,0 @@
1
- import { describe, test, before, after } from "node:test";
2
- import assert from "node:assert";
3
- import { spawn } from "child_process";
4
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
- const MOCK_TOKEN = "glpat-mock-token-12345";
6
- const TEST_PROJECT_ID = "123";
7
- const TEST_DEPLOYMENT_ID = "777";
8
- const TEST_ENVIRONMENT_ID = "42";
9
- const TEST_MERGE_REQUEST_IID = "88";
10
- const TEST_MERGE_REQUEST_SHA = "merge-sha-6870";
11
- const TEST_DIVERGED_COMMITS_COUNT = 35;
12
- const TEST_SOURCE_COMMITS_COUNT = 6;
13
- const TEST_APPROVER_USERNAME = "sergey.kravchenya";
14
- const TEST_APPROVER_NAME = "Sergey Kravchenya";
15
- const mrDeploymentsByCreatedAtAsc = Array.from({ length: 12 }, (_, index) => {
16
- const sequence = index + 1;
17
- const day = String(sequence).padStart(2, "0");
18
- return {
19
- id: `mr-deploy-${sequence}`,
20
- status: "success",
21
- ref: "main",
22
- sha: TEST_MERGE_REQUEST_SHA,
23
- created_at: `2026-02-${day}T10:00:00.000Z`,
24
- updated_at: `2026-02-${day}T10:05:00.000Z`,
25
- environment: {
26
- id: `mr-env-${sequence}`,
27
- name: sequence % 2 === 0 ? "prod" : "stage",
28
- external_url: sequence % 2 === 0 ? "https://api.prod.example.com" : "https://api.stage.example.com",
29
- },
30
- deployable: {
31
- id: `mr-job-${sequence}`,
32
- name: `Deploy ${sequence}`,
33
- status: "success",
34
- stage: "deploy",
35
- pipeline: {
36
- id: `mr-pipeline-${sequence}`,
37
- status: "success",
38
- ref: "main",
39
- sha: TEST_MERGE_REQUEST_SHA,
40
- },
41
- },
42
- };
43
- });
44
- const mrDeploymentsUnsorted = [
45
- mrDeploymentsByCreatedAtAsc[4],
46
- mrDeploymentsByCreatedAtAsc[0],
47
- mrDeploymentsByCreatedAtAsc[10],
48
- mrDeploymentsByCreatedAtAsc[2],
49
- mrDeploymentsByCreatedAtAsc[11],
50
- mrDeploymentsByCreatedAtAsc[7],
51
- mrDeploymentsByCreatedAtAsc[1],
52
- mrDeploymentsByCreatedAtAsc[9],
53
- mrDeploymentsByCreatedAtAsc[3],
54
- mrDeploymentsByCreatedAtAsc[6],
55
- mrDeploymentsByCreatedAtAsc[8],
56
- mrDeploymentsByCreatedAtAsc[5],
57
- ];
58
- async function callTool(toolName, args, env) {
59
- return new Promise((resolve, reject) => {
60
- const proc = spawn("node", ["build/index.js"], {
61
- stdio: ["pipe", "pipe", "pipe"],
62
- env: {
63
- ...process.env,
64
- ...env,
65
- GITLAB_READ_ONLY_MODE: env.GITLAB_READ_ONLY_MODE ?? "true",
66
- USE_PIPELINE: "true",
67
- },
68
- });
69
- let output = "";
70
- let errorOutput = "";
71
- proc.stdout?.on("data", (d) => (output += d));
72
- proc.stderr?.on("data", (d) => (errorOutput += d));
73
- proc.on("close", (code) => {
74
- if (code !== 0) {
75
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
76
- }
77
- const line = output.split("\n").find((l) => l.startsWith("{"));
78
- if (!line) {
79
- return reject(new Error("No JSON output found"));
80
- }
81
- try {
82
- const response = JSON.parse(line);
83
- if (response.error) {
84
- reject(response.error);
85
- }
86
- else {
87
- const content = response.result?.content?.[0]?.text;
88
- if (content) {
89
- try {
90
- resolve(JSON.parse(content));
91
- }
92
- catch {
93
- resolve(content);
94
- }
95
- }
96
- else {
97
- resolve(response.result);
98
- }
99
- }
100
- }
101
- catch (e) {
102
- reject(e);
103
- }
104
- });
105
- proc.stdin?.end(JSON.stringify({
106
- jsonrpc: "2.0",
107
- id: 1,
108
- method: "tools/call",
109
- params: { name: toolName, arguments: args },
110
- }) + "\n");
111
- });
112
- }
113
- describe("deployment and environment tools", () => {
114
- let mockGitLab;
115
- let mockGitLabUrl;
116
- before(async () => {
117
- const mockPort = await findMockServerPort();
118
- mockGitLab = new MockGitLabServer({
119
- port: mockPort,
120
- validTokens: [MOCK_TOKEN],
121
- });
122
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/deployments`, (req, res) => {
123
- const querySha = Array.isArray(req.query.sha) ? req.query.sha[0] : req.query.sha;
124
- if (querySha === TEST_MERGE_REQUEST_SHA) {
125
- res.json(mrDeploymentsUnsorted);
126
- return;
127
- }
128
- res.json([
129
- {
130
- id: TEST_DEPLOYMENT_ID,
131
- status: "success",
132
- ref: "master",
133
- sha: "abc123",
134
- created_at: "2026-02-20T16:27:59.348Z",
135
- updated_at: "2026-02-20T16:32:38.235Z",
136
- environment: { id: TEST_ENVIRONMENT_ID, name: "stage" },
137
- deployable: {
138
- id: "11",
139
- name: "Stage deploy",
140
- status: "success",
141
- stage: "deploy",
142
- pipeline: { id: "190349", status: "success", ref: "master", sha: "abc123" },
143
- },
144
- },
145
- ]);
146
- });
147
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MERGE_REQUEST_IID}`, (req, res) => {
148
- res.json({
149
- id: TEST_MERGE_REQUEST_IID,
150
- iid: TEST_MERGE_REQUEST_IID,
151
- project_id: TEST_PROJECT_ID,
152
- title: "Deployment summary test MR",
153
- description: "MR used by tests to validate deployment summary enrichment",
154
- state: "merged",
155
- author: {
156
- id: "1",
157
- username: "test-user",
158
- name: "Test User",
159
- },
160
- source_branch: "feature/deploy-summary",
161
- target_branch: "main",
162
- web_url: "https://gitlab.mock/project/123/merge_requests/88",
163
- created_at: "2026-02-01T10:00:00.000Z",
164
- updated_at: "2026-02-20T11:00:00.000Z",
165
- merged_at: "2026-02-20T11:05:00.000Z",
166
- closed_at: null,
167
- merge_commit_sha: TEST_MERGE_REQUEST_SHA,
168
- diverged_commits_count: TEST_DIVERGED_COMMITS_COUNT,
169
- rebase_in_progress: false,
170
- });
171
- });
172
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MERGE_REQUEST_IID}/commits`, (req, res) => {
173
- const page = Number.parseInt((Array.isArray(req.query.page) ? req.query.page[0] : req.query.page)?.toString() ?? "1", 10);
174
- if (page > 1) {
175
- res.set("x-next-page", "");
176
- res.json([]);
177
- return;
178
- }
179
- res.set("x-next-page", "");
180
- res.json(Array.from({ length: TEST_SOURCE_COMMITS_COUNT }, (_, index) => ({
181
- id: `commit-${index + 1}`,
182
- short_id: `${index + 1}`,
183
- title: `Commit ${index + 1}`,
184
- author_name: "Test Author",
185
- author_email: "author@example.com",
186
- authored_date: "2026-02-20T10:00:00.000Z",
187
- committer_name: "Test Committer",
188
- committer_email: "committer@example.com",
189
- committed_date: "2026-02-20T10:00:00.000Z",
190
- web_url: `https://gitlab.mock/project/123/-/commit/${index + 1}`,
191
- parent_ids: [],
192
- })));
193
- });
194
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MERGE_REQUEST_IID}/approval_state`, (_req, res) => {
195
- res.json({
196
- approval_rules_overwritten: false,
197
- rules: [
198
- {
199
- id: "101",
200
- name: "Default rule",
201
- rule_type: "regular",
202
- approvals_required: 1,
203
- approved: true,
204
- approved_by: [
205
- {
206
- id: "35",
207
- username: TEST_APPROVER_USERNAME,
208
- name: TEST_APPROVER_NAME,
209
- state: "active",
210
- avatar_url: "https://gitlab.mock/uploads/avatar.png",
211
- web_url: "https://gitlab.mock/sergey.kravchenya",
212
- },
213
- ],
214
- },
215
- ],
216
- });
217
- });
218
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}`, (req, res) => {
219
- res.json({
220
- id: TEST_PROJECT_ID,
221
- path_with_namespace: "test-group/test-project",
222
- merge_method: "merge",
223
- });
224
- });
225
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/deployments/${TEST_DEPLOYMENT_ID}`, (req, res) => {
226
- res.json({
227
- id: TEST_DEPLOYMENT_ID,
228
- status: "success",
229
- ref: "master",
230
- sha: "abc123",
231
- created_at: "2026-02-20T16:27:59.348Z",
232
- updated_at: "2026-02-20T16:32:38.235Z",
233
- environment: { id: TEST_ENVIRONMENT_ID, name: "stage" },
234
- deployable: {
235
- id: "11",
236
- name: "Stage deploy",
237
- status: "success",
238
- stage: "deploy",
239
- pipeline: { id: "190349", status: "success", ref: "master", sha: "abc123" },
240
- },
241
- pending_approval_count: 1,
242
- approvals: [
243
- {
244
- user: {
245
- id: "100",
246
- username: "security-user-1",
247
- name: "Security User",
248
- state: "active",
249
- web_url: "https://gitlab.example.com/security-user-1",
250
- },
251
- status: "approved",
252
- created_at: "2026-02-20T16:33:00.000Z",
253
- comment: "Looks good to me",
254
- },
255
- ],
256
- approval_summary: {
257
- rules: [
258
- {
259
- group_id: "134",
260
- access_level: null,
261
- access_level_description: "security-group",
262
- required_approvals: 2,
263
- deployment_approvals: [
264
- {
265
- user: {
266
- id: "100",
267
- username: "security-user-1",
268
- name: "Security User",
269
- state: "active",
270
- web_url: "https://gitlab.example.com/security-user-1",
271
- },
272
- status: "approved",
273
- created_at: "2026-02-20T16:33:00.000Z",
274
- comment: "Looks good to me",
275
- },
276
- ],
277
- },
278
- ],
279
- },
280
- });
281
- });
282
- mockGitLab.addMockHandler("post", `/projects/${TEST_PROJECT_ID}/deployments`, (_req, res) => {
283
- res.status(201).json({ id: "created-deployment", status: "created" });
284
- });
285
- mockGitLab.addMockHandler("put", `/projects/${TEST_PROJECT_ID}/deployments/${TEST_DEPLOYMENT_ID}`, (_req, res) => {
286
- res.json({ id: TEST_DEPLOYMENT_ID, status: "success" });
287
- });
288
- mockGitLab.addMockHandler("delete", `/projects/${TEST_PROJECT_ID}/deployments/${TEST_DEPLOYMENT_ID}`, (_req, res) => {
289
- res.status(204).send();
290
- });
291
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/deployments/${TEST_DEPLOYMENT_ID}/merge_requests`, (_req, res) => {
292
- res.json([{ iid: TEST_MERGE_REQUEST_IID, title: "Shipped change" }]);
293
- });
294
- mockGitLab.addMockHandler("post", `/projects/${TEST_PROJECT_ID}/deployments/${TEST_DEPLOYMENT_ID}/approval`, (_req, res) => {
295
- res.json({ id: TEST_DEPLOYMENT_ID, status: "approved" });
296
- });
297
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/environments`, (req, res) => {
298
- res.json([
299
- {
300
- id: TEST_ENVIRONMENT_ID,
301
- name: "stage",
302
- slug: "stage",
303
- state: "available",
304
- external_url: "https://api.stage.example.com",
305
- last_deployment: {
306
- id: TEST_DEPLOYMENT_ID,
307
- status: "success",
308
- ref: "master",
309
- sha: "abc123",
310
- created_at: "2026-02-20T16:27:59.348Z",
311
- },
312
- },
313
- ]);
314
- });
315
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/environments/${TEST_ENVIRONMENT_ID}`, (req, res) => {
316
- res.json({
317
- id: TEST_ENVIRONMENT_ID,
318
- name: "stage",
319
- slug: "stage",
320
- state: "available",
321
- external_url: "https://api.stage.example.com",
322
- last_deployment: {
323
- id: TEST_DEPLOYMENT_ID,
324
- status: "success",
325
- ref: "master",
326
- sha: "abc123",
327
- created_at: "2026-02-20T16:27:59.348Z",
328
- },
329
- });
330
- });
331
- await mockGitLab.start();
332
- mockGitLabUrl = mockGitLab.getUrl();
333
- });
334
- after(async () => {
335
- await mockGitLab.stop();
336
- });
337
- test("list_deployments returns deployment list", async () => {
338
- const result = await callTool("list_deployments", { project_id: TEST_PROJECT_ID, environment: "stage" }, {
339
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
340
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
341
- });
342
- assert.ok(Array.isArray(result), "Response should be an array");
343
- assert.strictEqual(result.length, 1, "Should return one deployment");
344
- assert.strictEqual(result[0].id, TEST_DEPLOYMENT_ID);
345
- assert.strictEqual(result[0].environment.name, "stage");
346
- });
347
- test("get_deployment returns one deployment", async () => {
348
- const result = await callTool("get_deployment", { project_id: TEST_PROJECT_ID, deployment_id: TEST_DEPLOYMENT_ID }, {
349
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
350
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
351
- });
352
- assert.strictEqual(result.id, TEST_DEPLOYMENT_ID);
353
- assert.strictEqual(result.ref, "master");
354
- assert.strictEqual(result.status, "success");
355
- assert.strictEqual(result.pending_approval_count, 1);
356
- assert.strictEqual(result.approvals[0].status, "approved");
357
- assert.strictEqual(result.approvals[0].user.username, "security-user-1");
358
- assert.strictEqual(result.approval_summary.rules[0].group_id, "134");
359
- assert.strictEqual(result.approval_summary.rules[0].deployment_approvals[0].comment, "Looks good to me");
360
- });
361
- test("supports deployment lifecycle and approval operations", async () => {
362
- const env = {
363
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
364
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
365
- GITLAB_READ_ONLY_MODE: "false",
366
- };
367
- const created = await callTool("create_deployment", {
368
- project_id: TEST_PROJECT_ID,
369
- environment: "stage",
370
- sha: "abc123",
371
- ref: "master",
372
- tag: false,
373
- status: "running",
374
- }, env);
375
- assert.strictEqual(created.id, "created-deployment");
376
- const updated = await callTool("update_deployment", { project_id: TEST_PROJECT_ID, deployment_id: TEST_DEPLOYMENT_ID, status: "success" }, env);
377
- assert.strictEqual(updated.status, "success");
378
- const mergeRequests = await callTool("list_deployment_merge_requests", { project_id: TEST_PROJECT_ID, deployment_id: TEST_DEPLOYMENT_ID }, env);
379
- assert.strictEqual(mergeRequests[0].iid, TEST_MERGE_REQUEST_IID);
380
- const approval = await callTool("approve_deployment", { project_id: TEST_PROJECT_ID, deployment_id: TEST_DEPLOYMENT_ID, status: "approved" }, env);
381
- assert.strictEqual(approval.status, "approved");
382
- const deleted = await callTool("delete_deployment", { project_id: TEST_PROJECT_ID, deployment_id: TEST_DEPLOYMENT_ID }, env);
383
- assert.deepStrictEqual(deleted, { success: true });
384
- });
385
- test("list_environments returns environment list", async () => {
386
- const result = await callTool("list_environments", { project_id: TEST_PROJECT_ID }, {
387
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
388
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
389
- });
390
- assert.ok(Array.isArray(result), "Response should be an array");
391
- assert.strictEqual(result.length, 1, "Should return one environment");
392
- assert.strictEqual(result[0].id, TEST_ENVIRONMENT_ID);
393
- assert.strictEqual(result[0].name, "stage");
394
- });
395
- test("get_environment returns one environment", async () => {
396
- const result = await callTool("get_environment", { project_id: TEST_PROJECT_ID, environment_id: TEST_ENVIRONMENT_ID }, {
397
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
398
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
399
- });
400
- assert.strictEqual(result.id, TEST_ENVIRONMENT_ID);
401
- assert.strictEqual(result.name, "stage");
402
- assert.strictEqual(result.state, "available");
403
- });
404
- test("get_merge_request omits summaries by default", async () => {
405
- const result = await callTool("get_merge_request", { project_id: TEST_PROJECT_ID, merge_request_iid: TEST_MERGE_REQUEST_IID }, {
406
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
407
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
408
- });
409
- assert.strictEqual(result.iid, TEST_MERGE_REQUEST_IID);
410
- assert.strictEqual(result.deployment_summary, undefined, "deployment_summary should be omitted by default");
411
- assert.strictEqual(result.commit_addition_summary, undefined, "commit_addition_summary should be omitted by default");
412
- assert.strictEqual(result.approval_summary, undefined, "approval_summary should be omitted by default");
413
- });
414
- test("get_merge_request returns compact deployment summary sorted by created_at desc", async () => {
415
- const result = await callTool("get_merge_request", {
416
- project_id: TEST_PROJECT_ID,
417
- merge_request_iid: TEST_MERGE_REQUEST_IID,
418
- include_summaries: true,
419
- }, {
420
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
421
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
422
- });
423
- assert.ok(result.deployment_summary, "deployment_summary should be present");
424
- assert.strictEqual(result.diverged_commits_count, TEST_DIVERGED_COMMITS_COUNT, "diverged_commits_count should be requested and returned by default");
425
- assert.strictEqual(result.deployment_summary.lookup_sha, TEST_MERGE_REQUEST_SHA);
426
- assert.ok(result.commit_addition_summary, "commit_addition_summary should be present");
427
- assert.strictEqual(result.commit_addition_summary.source_commits_count, TEST_SOURCE_COMMITS_COUNT);
428
- assert.strictEqual(result.commit_addition_summary.merge_method, "merge");
429
- assert.strictEqual(result.commit_addition_summary.merge_commit_count, 1);
430
- assert.strictEqual(result.commit_addition_summary.summary, "6 commits and 1 merge commit will be added to main.");
431
- assert.ok(result.approval_summary, "approval_summary should be present");
432
- assert.strictEqual(result.approval_summary.source_endpoint, "approval_state");
433
- assert.strictEqual(result.approval_summary.approved, true);
434
- assert.deepStrictEqual(result.approval_summary.approved_by_usernames, [TEST_APPROVER_USERNAME]);
435
- assert.strictEqual(result.approval_summary.approved_by.length, 1);
436
- assert.strictEqual(result.approval_summary.approved_by[0].name, TEST_APPROVER_NAME);
437
- assert.strictEqual(result.deployment_summary.sort, "created_at_desc");
438
- assert.strictEqual(result.deployment_summary.limit, 10);
439
- assert.strictEqual(result.deployment_summary.total_count, 12);
440
- assert.strictEqual(result.deployment_summary.returned_count, 10);
441
- assert.ok(Array.isArray(result.deployment_summary.records), "records should be an array");
442
- assert.strictEqual(result.deployment_summary.records.length, 10);
443
- assert.ok(result.deployment_summary.records.every((record) => record.sha === TEST_MERGE_REQUEST_SHA), "all summary records should match MR sha");
444
- for (let i = 1; i < result.deployment_summary.records.length; i++) {
445
- const previousCreatedAt = Date.parse(result.deployment_summary.records[i - 1].created_at);
446
- const currentCreatedAt = Date.parse(result.deployment_summary.records[i].created_at);
447
- assert.ok(previousCreatedAt >= currentCreatedAt, "records should be sorted by created_at descending");
448
- }
449
- assert.strictEqual(result.deployment_summary.records[0].id, "mr-deploy-12", "latest deployment should be first");
450
- assert.ok(!result.deployment_summary.records.some((record) => record.id === "mr-deploy-1"), "oldest deployment should be truncated");
451
- assert.ok(!result.deployment_summary.records.some((record) => record.id === "mr-deploy-2"), "second oldest deployment should be truncated");
452
- });
453
- test("get_merge_request always requests diverged_commits_count", async () => {
454
- const result = await callTool("get_merge_request", {
455
- project_id: TEST_PROJECT_ID,
456
- merge_request_iid: TEST_MERGE_REQUEST_IID,
457
- }, {
458
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
459
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
460
- });
461
- assert.strictEqual(result.diverged_commits_count, TEST_DIVERGED_COMMITS_COUNT, "diverged_commits_count should always be included in get_merge_request response");
462
- });
463
- });
@@ -1,190 +0,0 @@
1
- import { describe, test, before, after } from 'node:test';
2
- import assert from 'node:assert';
3
- import { spawn } from 'node:child_process';
4
- import fs from 'node:fs';
5
- import os from 'node:os';
6
- import { MockGitLabServer, findMockServerPort } from './utils/mock-gitlab-server.js';
7
- const MOCK_TOKEN = 'glpat-mock-token-12345';
8
- const TEST_PROJECT_ID = '123';
9
- const TEST_SECRET = 'testsecret123';
10
- // Minimum valid 1x1 transparent PNG
11
- const MINIMAL_PNG_BUF = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', 'base64');
12
- // Unique suffix per test run to avoid conflicts on concurrent executions
13
- const RUN_ID = Math.random().toString(36).slice(2, 8);
14
- /**
15
- * Spawn build/index.js, send a single download_attachment JSON-RPC call, and
16
- * return the raw parsed JSON-RPC response (either {result:...} or {error:...}).
17
- */
18
- function callDownloadAttachment(args, env, timeoutMs = 15_000) {
19
- return new Promise((resolve, reject) => {
20
- const proc = spawn('node', ['build/index.js'], {
21
- stdio: ['pipe', 'pipe', 'pipe'],
22
- env: { ...process.env, ...env, GITLAB_READ_ONLY_MODE: 'true' },
23
- });
24
- const timer = setTimeout(() => {
25
- proc.kill();
26
- reject(new Error(`Process timed out after ${timeoutMs}ms`));
27
- }, timeoutMs);
28
- let stdout = '';
29
- let stderr = '';
30
- proc.stdout?.on('data', (d) => (stdout += d.toString()));
31
- proc.stderr?.on('data', (d) => (stderr += d.toString()));
32
- proc.on('error', (err) => {
33
- clearTimeout(timer);
34
- reject(new Error(`Failed to spawn process: ${err.message}`));
35
- });
36
- proc.on('close', () => {
37
- clearTimeout(timer);
38
- // Find the JSON-RPC response line matching our request id
39
- const lines = stdout.split('\n').filter(l => l.trim().startsWith('{'));
40
- for (const line of lines) {
41
- try {
42
- const parsed = JSON.parse(line);
43
- if (parsed.id === 1) {
44
- resolve(parsed);
45
- return;
46
- }
47
- }
48
- catch { /* try next line */ }
49
- }
50
- reject(new Error(`No matching JSON-RPC response found.\nstderr: ${stderr}`));
51
- });
52
- proc.stdin?.end(JSON.stringify({
53
- jsonrpc: '2.0',
54
- id: 1,
55
- method: 'tools/call',
56
- params: { name: 'download_attachment', arguments: args },
57
- }) + '\n');
58
- });
59
- }
60
- describe('download_attachment', () => {
61
- let mockGitLab;
62
- let env;
63
- before(async () => {
64
- const port = await findMockServerPort();
65
- mockGitLab = new MockGitLabServer({ port, validTokens: [MOCK_TOKEN] });
66
- await mockGitLab.start();
67
- env = {
68
- GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
69
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
70
- };
71
- // PNG upload endpoint
72
- mockGitLab.addMockHandler('get', `/projects/${TEST_PROJECT_ID}/uploads/${TEST_SECRET}/image.png`, (_req, res) => { res.set('Content-Type', 'image/png').send(MINIMAL_PNG_BUF); });
73
- // Plain-text upload endpoint
74
- mockGitLab.addMockHandler('get', `/projects/${TEST_PROJECT_ID}/uploads/${TEST_SECRET}/document.txt`, (_req, res) => { res.set('Content-Type', 'text/plain').send('hello world'); });
75
- // GitLab redirects uploads to its object storage, so the hop after this response
76
- // leaves the origin. The destination is a non-public address here.
77
- mockGitLab.addMockHandler('get', `/projects/${TEST_PROJECT_ID}/uploads/${TEST_SECRET}/redirected.txt`, (_req, res) => { res.redirect('http://169.254.169.254/latest/meta-data/'); });
78
- });
79
- after(async () => {
80
- await mockGitLab.stop();
81
- });
82
- test('image file without local_path returns base64 image content block', async () => {
83
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'image.png' }, env);
84
- const content = raw.result?.content;
85
- assert.ok(Array.isArray(content), 'result.content should be an array');
86
- const imageBlock = content.find(c => c.type === 'image');
87
- assert.ok(imageBlock, 'Should contain an image content block');
88
- assert.strictEqual(imageBlock.mimeType, 'image/png', 'mimeType should be image/png');
89
- assert.ok(typeof imageBlock.data === 'string' && imageBlock.data.length > 0, 'Image block should have non-empty base64 data');
90
- });
91
- test('non-image file is saved to disk and returns file_path', async () => {
92
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'document.txt' }, env);
93
- const text = raw.result?.content?.[0]?.text;
94
- assert.ok(text, 'Should have text content');
95
- const parsed = JSON.parse(text);
96
- try {
97
- assert.strictEqual(parsed.success, true, 'success should be true');
98
- assert.ok(typeof parsed.file_path === 'string', 'file_path should be a string');
99
- assert.ok(parsed.file_path.endsWith('document.txt'), 'file_path should end with document.txt');
100
- }
101
- finally {
102
- if (parsed.file_path && fs.existsSync(parsed.file_path)) {
103
- fs.unlinkSync(parsed.file_path);
104
- }
105
- }
106
- });
107
- test('image file with local_path is saved to disk and returns file_path', async () => {
108
- // Must be a relative path – the implementation rejects absolute paths as traversal
109
- const localPath = `omc-test-save-${RUN_ID}`;
110
- try {
111
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'image.png', local_path: localPath }, env);
112
- const text = raw.result?.content?.[0]?.text;
113
- assert.ok(text, 'Should have text content');
114
- const parsed = JSON.parse(text);
115
- assert.strictEqual(parsed.success, true, 'success should be true');
116
- assert.ok(typeof parsed.file_path === 'string', 'file_path should be a string');
117
- assert.ok(parsed.file_path.includes('image.png'), 'file_path should include image.png');
118
- }
119
- finally {
120
- fs.rmSync(localPath, { recursive: true, force: true });
121
- }
122
- });
123
- test('local_path with ".." returns path traversal error', async () => {
124
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'image.png', local_path: '../../../tmp' }, env);
125
- // MCP SDK may return a JSON-RPC error or an isError content block; both must mention "traversal"
126
- const isRpcError = typeof raw.error?.message === 'string' &&
127
- raw.error.message.toLowerCase().includes('traversal');
128
- const isContentError = Array.isArray(raw.result?.content) &&
129
- raw.result.content.some(c => typeof c.text === 'string' && c.text.toLowerCase().includes('traversal'));
130
- assert.ok(isRpcError || isContentError, 'Should return an error mentioning directory traversal');
131
- });
132
- test('a redirect to a non-public address is refused', async () => {
133
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'redirected.txt' }, env);
134
- const mentionsRefusal = (text) => text.toLowerCase().includes('non-public address');
135
- const isRpcError = typeof raw.error?.message === 'string' && mentionsRefusal(raw.error.message);
136
- const isContentError = Array.isArray(raw.result?.content) &&
137
- raw.result.content.some(c => typeof c.text === 'string' && mentionsRefusal(c.text));
138
- assert.ok(isRpcError || isContentError, `Should refuse the redirect instead of following it, got ${JSON.stringify(raw)}`);
139
- });
140
- test('local_path through a symlink directory is rejected', async () => {
141
- const linkDir = `omc-test-symlink-${RUN_ID}`;
142
- fs.rmSync(linkDir, { recursive: true, force: true });
143
- fs.symlinkSync(os.tmpdir(), linkDir);
144
- try {
145
- const raw = await callDownloadAttachment({
146
- project_id: TEST_PROJECT_ID,
147
- secret: TEST_SECRET,
148
- filename: 'image.png',
149
- local_path: linkDir,
150
- }, env);
151
- const msg = (typeof raw.error?.message === 'string' ? raw.error.message : '') +
152
- (Array.isArray(raw.result?.content)
153
- ? raw.result.content.map(c => c.text || '').join(' ')
154
- : '');
155
- const lower = msg.toLowerCase();
156
- assert.ok(lower.includes('symbolic') ||
157
- lower.includes('symlink') ||
158
- lower.includes('escapes') ||
159
- lower.includes('traversal') ||
160
- lower.includes('invalid'), `Expected symlink rejection, got: ${msg}`);
161
- }
162
- finally {
163
- fs.rmSync(linkDir, { recursive: true, force: true });
164
- }
165
- });
166
- test('filename with directory traversal is rejected before writing to disk', async () => {
167
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'image.png#../../owned.txt' }, env);
168
- const isRpcError = typeof raw.error?.message === 'string' &&
169
- raw.error.message.toLowerCase().includes('filename');
170
- const isContentError = Array.isArray(raw.result?.content) &&
171
- raw.result.content.some(c => typeof c.text === 'string' && c.text.toLowerCase().includes('filename'));
172
- assert.ok(isRpcError || isContentError, 'Should return an error mentioning filename validation');
173
- });
174
- test('non-existent local_path directory is auto-created before saving', async () => {
175
- const baseDir = `omc-test-newdir-${RUN_ID}`;
176
- const localPath = `${baseDir}/subdir`;
177
- fs.rmSync(baseDir, { recursive: true, force: true });
178
- try {
179
- const raw = await callDownloadAttachment({ project_id: TEST_PROJECT_ID, secret: TEST_SECRET, filename: 'document.txt', local_path: localPath }, env);
180
- const text = raw.result?.content?.[0]?.text;
181
- assert.ok(text, 'Should have text content');
182
- const parsed = JSON.parse(text);
183
- assert.strictEqual(parsed.success, true, 'success should be true');
184
- assert.ok(fs.existsSync(parsed.file_path), 'Saved file should exist on disk');
185
- }
186
- finally {
187
- fs.rmSync(baseDir, { recursive: true, force: true });
188
- }
189
- });
190
- });