@zereight/mcp-gitlab 2.1.63 → 2.1.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,535 @@
1
+ import { after, before, describe, it } 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-empty-toolsets";
6
+ const TEST_PROJECT_ID = "123";
7
+ const TEST_GROUP_ID = "10";
8
+ const TEST_LABEL_ID = "1";
9
+ const TEST_MILESTONE_ID = "1";
10
+ const TEST_WIKI_SLUG = "Home";
11
+ const TEST_TAG_NAME = "v1.0.0";
12
+ const TEST_ASSET_PATH = "hello-asset";
13
+ const ISO_NOW = "2026-03-13T10:00:00.000Z";
14
+ function buildUser() {
15
+ return { id: "1", username: "tester", name: "Test User" };
16
+ }
17
+ function buildLabel(overrides = {}) {
18
+ return {
19
+ id: TEST_LABEL_ID,
20
+ name: "bug",
21
+ color: "#FF0000",
22
+ text_color: "#FFFFFF",
23
+ description: "A bug",
24
+ description_html: "<p>A bug</p>",
25
+ ...overrides,
26
+ };
27
+ }
28
+ function buildWikiPage(overrides = {}) {
29
+ return {
30
+ title: "Home",
31
+ slug: TEST_WIKI_SLUG,
32
+ format: "markdown",
33
+ content: "hello wiki",
34
+ ...overrides,
35
+ };
36
+ }
37
+ function buildProjectMilestone(overrides = {}) {
38
+ return {
39
+ id: TEST_MILESTONE_ID,
40
+ iid: "1",
41
+ project_id: TEST_PROJECT_ID,
42
+ title: "v1",
43
+ description: "First milestone",
44
+ due_date: null,
45
+ start_date: null,
46
+ state: "active",
47
+ updated_at: ISO_NOW,
48
+ created_at: ISO_NOW,
49
+ expired: false,
50
+ ...overrides,
51
+ };
52
+ }
53
+ function buildGroupMilestone(overrides = {}) {
54
+ return {
55
+ id: TEST_MILESTONE_ID,
56
+ iid: "1",
57
+ group_id: TEST_GROUP_ID,
58
+ title: "v1",
59
+ description: "First group milestone",
60
+ due_date: null,
61
+ start_date: null,
62
+ state: "active",
63
+ updated_at: ISO_NOW,
64
+ created_at: ISO_NOW,
65
+ expired: false,
66
+ ...overrides,
67
+ };
68
+ }
69
+ function buildIssue(overrides = {}) {
70
+ return {
71
+ id: "1",
72
+ iid: "1",
73
+ project_id: TEST_PROJECT_ID,
74
+ title: "Issue one",
75
+ description: "",
76
+ state: "opened",
77
+ author: buildUser(),
78
+ assignees: [],
79
+ labels: [],
80
+ milestone: null,
81
+ created_at: ISO_NOW,
82
+ updated_at: ISO_NOW,
83
+ closed_at: null,
84
+ web_url: `https://gitlab.mock/project/${TEST_PROJECT_ID}/issues/1`,
85
+ ...overrides,
86
+ };
87
+ }
88
+ function buildMergeRequest(overrides = {}) {
89
+ return {
90
+ id: "1",
91
+ iid: "1",
92
+ project_id: TEST_PROJECT_ID,
93
+ title: "MR one",
94
+ description: "desc",
95
+ state: "opened",
96
+ author: buildUser(),
97
+ source_branch: "feature",
98
+ target_branch: "main",
99
+ web_url: `https://gitlab.mock/project/${TEST_PROJECT_ID}/merge_requests/1`,
100
+ created_at: ISO_NOW,
101
+ updated_at: ISO_NOW,
102
+ merged_at: null,
103
+ closed_at: null,
104
+ merge_commit_sha: null,
105
+ ...overrides,
106
+ };
107
+ }
108
+ function buildRelease(overrides = {}) {
109
+ return {
110
+ tag_name: TEST_TAG_NAME,
111
+ name: TEST_TAG_NAME,
112
+ description: "Release notes",
113
+ created_at: ISO_NOW,
114
+ ...overrides,
115
+ };
116
+ }
117
+ function buildBurndownEvent() {
118
+ return { created_at: ISO_NOW, action: "created" };
119
+ }
120
+ async function callTool(toolName, args, env) {
121
+ return new Promise((resolve, reject) => {
122
+ const proc = spawn("node", ["build/index.js"], {
123
+ stdio: ["pipe", "pipe", "pipe"],
124
+ env: {
125
+ ...process.env,
126
+ ...env,
127
+ },
128
+ });
129
+ let output = "";
130
+ let errorOutput = "";
131
+ proc.stdout?.on("data", (d) => (output += d));
132
+ proc.stderr?.on("data", (d) => (errorOutput += d));
133
+ proc.on("close", code => {
134
+ if (code !== 0) {
135
+ return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
136
+ }
137
+ const line = output.split("\n").find(l => l.startsWith("{"));
138
+ if (!line) {
139
+ return reject(new Error("No JSON output found"));
140
+ }
141
+ try {
142
+ const response = JSON.parse(line);
143
+ if (response.error) {
144
+ reject(response.error);
145
+ return;
146
+ }
147
+ const content = response.result?.content?.[0]?.text;
148
+ if (!content) {
149
+ resolve(response.result);
150
+ return;
151
+ }
152
+ try {
153
+ resolve(JSON.parse(content));
154
+ }
155
+ catch {
156
+ resolve(content);
157
+ }
158
+ }
159
+ catch (error) {
160
+ reject(error);
161
+ }
162
+ });
163
+ proc.stdin?.end(JSON.stringify({
164
+ jsonrpc: "2.0",
165
+ id: 1,
166
+ method: "tools/call",
167
+ params: { name: toolName, arguments: args },
168
+ }) + "\n");
169
+ });
170
+ }
171
+ function isRecord(value) {
172
+ return typeof value === "object" && value !== null;
173
+ }
174
+ describe("When covering labels wiki milestones releases", () => {
175
+ describe("with GITLAB_TOOLSETS labels,wiki,milestones,releases", () => {
176
+ let mockGitLab;
177
+ let mockGitLabUrl;
178
+ before(async () => {
179
+ const mockPort = await findMockServerPort();
180
+ mockGitLab = new MockGitLabServer({
181
+ port: mockPort,
182
+ validTokens: [MOCK_TOKEN],
183
+ });
184
+ const projectLabels = `/projects/${TEST_PROJECT_ID}/labels`;
185
+ const projectLabel = `${projectLabels}/${TEST_LABEL_ID}`;
186
+ const projectWikis = `/projects/${TEST_PROJECT_ID}/wikis`;
187
+ const projectWiki = `${projectWikis}/${encodeURIComponent(TEST_WIKI_SLUG)}`;
188
+ const groupWikis = `/groups/${TEST_GROUP_ID}/wikis`;
189
+ const groupWiki = `${groupWikis}/${encodeURIComponent(TEST_WIKI_SLUG)}`;
190
+ const projectMilestones = `/projects/${TEST_PROJECT_ID}/milestones`;
191
+ const projectMilestone = `${projectMilestones}/${TEST_MILESTONE_ID}`;
192
+ const groupMilestones = `/groups/${TEST_GROUP_ID}/milestones`;
193
+ const groupMilestone = `${groupMilestones}/${TEST_MILESTONE_ID}`;
194
+ const projectReleases = `/projects/${TEST_PROJECT_ID}/releases`;
195
+ const projectRelease = `${projectReleases}/${encodeURIComponent(TEST_TAG_NAME)}`;
196
+ mockGitLab.addMockHandler("get", projectLabels, (_req, res) => {
197
+ res.json([buildLabel()]);
198
+ });
199
+ mockGitLab.addMockHandler("get", projectLabel, (_req, res) => {
200
+ res.json(buildLabel());
201
+ });
202
+ mockGitLab.addMockHandler("post", projectLabels, (_req, res) => {
203
+ res.json(buildLabel());
204
+ });
205
+ mockGitLab.addMockHandler("put", projectLabel, (_req, res) => {
206
+ res.json(buildLabel({ name: "bugfix" }));
207
+ });
208
+ mockGitLab.addMockHandler("delete", projectLabel, (_req, res) => {
209
+ res.status(204).send();
210
+ });
211
+ mockGitLab.addMockHandler("get", projectWikis, (_req, res) => {
212
+ res.json([buildWikiPage()]);
213
+ });
214
+ mockGitLab.addMockHandler("get", projectWiki, (_req, res) => {
215
+ res.json(buildWikiPage());
216
+ });
217
+ mockGitLab.addMockHandler("post", projectWikis, (_req, res) => {
218
+ res.json(buildWikiPage());
219
+ });
220
+ mockGitLab.addMockHandler("put", projectWiki, (_req, res) => {
221
+ res.json(buildWikiPage({ content: "updated wiki" }));
222
+ });
223
+ mockGitLab.addMockHandler("delete", projectWiki, (_req, res) => {
224
+ res.status(204).send();
225
+ });
226
+ mockGitLab.addMockHandler("get", groupWikis, (_req, res) => {
227
+ res.json([buildWikiPage({ title: "Group Home" })]);
228
+ });
229
+ mockGitLab.addMockHandler("get", groupWiki, (_req, res) => {
230
+ res.json(buildWikiPage({ title: "Group Home" }));
231
+ });
232
+ mockGitLab.addMockHandler("post", groupWikis, (_req, res) => {
233
+ res.json(buildWikiPage({ title: "Group Home" }));
234
+ });
235
+ mockGitLab.addMockHandler("put", groupWiki, (_req, res) => {
236
+ res.json(buildWikiPage({ title: "Group Home", content: "updated group wiki" }));
237
+ });
238
+ mockGitLab.addMockHandler("delete", groupWiki, (_req, res) => {
239
+ res.status(204).send();
240
+ });
241
+ mockGitLab.addMockHandler("get", projectMilestones, (_req, res) => {
242
+ res.json([buildProjectMilestone()]);
243
+ });
244
+ mockGitLab.addMockHandler("get", projectMilestone, (_req, res) => {
245
+ res.json(buildProjectMilestone());
246
+ });
247
+ mockGitLab.addMockHandler("post", projectMilestones, (_req, res) => {
248
+ res.json(buildProjectMilestone());
249
+ });
250
+ mockGitLab.addMockHandler("put", projectMilestone, (_req, res) => {
251
+ res.json(buildProjectMilestone({ title: "v1-edited" }));
252
+ });
253
+ mockGitLab.addMockHandler("delete", projectMilestone, (_req, res) => {
254
+ res.status(204).send();
255
+ });
256
+ mockGitLab.addMockHandler("get", `${projectMilestone}/issues`, (_req, res) => {
257
+ res.json([buildIssue()]);
258
+ });
259
+ mockGitLab.addMockHandler("get", `${projectMilestone}/merge_requests`, (_req, res) => {
260
+ res.json([buildMergeRequest()]);
261
+ });
262
+ mockGitLab.addMockHandler("post", `${projectMilestone}/promote`, (_req, res) => {
263
+ res.json(buildGroupMilestone());
264
+ });
265
+ mockGitLab.addMockHandler("get", `${projectMilestone}/burndown_events`, (_req, res) => {
266
+ res.json([buildBurndownEvent()]);
267
+ });
268
+ mockGitLab.addMockHandler("get", groupMilestones, (_req, res) => {
269
+ res.json([buildGroupMilestone()]);
270
+ });
271
+ mockGitLab.addMockHandler("get", groupMilestone, (_req, res) => {
272
+ res.json(buildGroupMilestone());
273
+ });
274
+ mockGitLab.addMockHandler("post", groupMilestones, (_req, res) => {
275
+ res.json(buildGroupMilestone());
276
+ });
277
+ mockGitLab.addMockHandler("put", groupMilestone, (_req, res) => {
278
+ res.json(buildGroupMilestone({ title: "v1-group-edited" }));
279
+ });
280
+ mockGitLab.addMockHandler("delete", groupMilestone, (_req, res) => {
281
+ res.status(204).send();
282
+ });
283
+ mockGitLab.addMockHandler("get", `${groupMilestone}/issues`, (_req, res) => {
284
+ res.json([buildIssue()]);
285
+ });
286
+ mockGitLab.addMockHandler("get", `${groupMilestone}/merge_requests`, (_req, res) => {
287
+ res.json([buildMergeRequest()]);
288
+ });
289
+ mockGitLab.addMockHandler("get", `${groupMilestone}/burndown_events`, (_req, res) => {
290
+ res.json([buildBurndownEvent()]);
291
+ });
292
+ mockGitLab.addMockHandler("get", projectReleases, (_req, res) => {
293
+ res.json([buildRelease()]);
294
+ });
295
+ mockGitLab.addMockHandler("get", projectRelease, (_req, res) => {
296
+ res.json(buildRelease());
297
+ });
298
+ mockGitLab.addMockHandler("post", projectReleases, (_req, res) => {
299
+ res.json(buildRelease());
300
+ });
301
+ mockGitLab.addMockHandler("put", projectRelease, (_req, res) => {
302
+ res.json(buildRelease({ description: "updated notes" }));
303
+ });
304
+ mockGitLab.addMockHandler("delete", projectRelease, (_req, res) => {
305
+ res.json(buildRelease());
306
+ });
307
+ mockGitLab.addMockHandler("post", `${projectRelease}/evidence`, (_req, res) => {
308
+ res.status(201).send();
309
+ });
310
+ mockGitLab.addMockHandler("get", `${projectRelease}/downloads/${TEST_ASSET_PATH}`, (_req, res) => {
311
+ res.send("asset-bytes");
312
+ });
313
+ await mockGitLab.start();
314
+ mockGitLabUrl = mockGitLab.getUrl();
315
+ });
316
+ after(async () => {
317
+ await mockGitLab.stop();
318
+ });
319
+ const env = () => ({
320
+ GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
321
+ GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
322
+ GITLAB_TOOLSETS: "labels,wiki,milestones,releases",
323
+ });
324
+ it("should return a label from list_labels", async () => {
325
+ const result = await callTool("list_labels", { project_id: TEST_PROJECT_ID }, env());
326
+ assert.ok(Array.isArray(result));
327
+ assert.strictEqual(result[0].name, "bug");
328
+ });
329
+ it("should return a label from get_label", async () => {
330
+ const result = await callTool("get_label", { project_id: TEST_PROJECT_ID, label_id: TEST_LABEL_ID }, env());
331
+ assert.ok(isRecord(result));
332
+ assert.strictEqual(result.name, "bug");
333
+ });
334
+ it("should create a label with create_label", async () => {
335
+ const result = await callTool("create_label", { project_id: TEST_PROJECT_ID, name: "bug", color: "#FF0000" }, env());
336
+ assert.ok(isRecord(result));
337
+ assert.strictEqual(result.color, "#FF0000");
338
+ });
339
+ it("should update a label with update_label", async () => {
340
+ const result = await callTool("update_label", { project_id: TEST_PROJECT_ID, label_id: TEST_LABEL_ID, new_name: "bugfix" }, env());
341
+ assert.ok(isRecord(result));
342
+ assert.strictEqual(result.name, "bugfix");
343
+ });
344
+ it("should delete a label with delete_label", async () => {
345
+ const result = await callTool("delete_label", { project_id: TEST_PROJECT_ID, label_id: TEST_LABEL_ID }, env());
346
+ assert.ok(isRecord(result));
347
+ assert.strictEqual(result.status, "success");
348
+ });
349
+ it("should return wiki pages from list_wiki_pages", async () => {
350
+ const result = await callTool("list_wiki_pages", { project_id: TEST_PROJECT_ID }, env());
351
+ assert.ok(Array.isArray(result));
352
+ assert.strictEqual(result[0].slug, TEST_WIKI_SLUG);
353
+ });
354
+ it("should return a wiki page from get_wiki_page", async () => {
355
+ const result = await callTool("get_wiki_page", { project_id: TEST_PROJECT_ID, slug: TEST_WIKI_SLUG }, env());
356
+ assert.ok(isRecord(result));
357
+ assert.strictEqual(result.slug, TEST_WIKI_SLUG);
358
+ });
359
+ it("should create a wiki page with create_wiki_page", async () => {
360
+ const result = await callTool("create_wiki_page", { project_id: TEST_PROJECT_ID, title: "Home", content: "hello wiki" }, env());
361
+ assert.ok(isRecord(result));
362
+ assert.strictEqual(result.title, "Home");
363
+ });
364
+ it("should update a wiki page with update_wiki_page", async () => {
365
+ const result = await callTool("update_wiki_page", { project_id: TEST_PROJECT_ID, slug: TEST_WIKI_SLUG, content: "updated wiki" }, env());
366
+ assert.ok(isRecord(result));
367
+ assert.strictEqual(result.content, "updated wiki");
368
+ });
369
+ it("should delete a wiki page with delete_wiki_page", async () => {
370
+ const result = await callTool("delete_wiki_page", { project_id: TEST_PROJECT_ID, slug: TEST_WIKI_SLUG }, env());
371
+ assert.ok(isRecord(result));
372
+ assert.strictEqual(result.status, "success");
373
+ });
374
+ it("should return group wiki pages from list_group_wiki_pages", async () => {
375
+ const result = await callTool("list_group_wiki_pages", { group_id: TEST_GROUP_ID }, env());
376
+ assert.ok(Array.isArray(result));
377
+ assert.strictEqual(result[0].title, "Group Home");
378
+ });
379
+ it("should return a group wiki page from get_group_wiki_page", async () => {
380
+ const result = await callTool("get_group_wiki_page", { group_id: TEST_GROUP_ID, slug: TEST_WIKI_SLUG }, env());
381
+ assert.ok(isRecord(result));
382
+ assert.strictEqual(result.title, "Group Home");
383
+ });
384
+ it("should create a group wiki page with create_group_wiki_page", async () => {
385
+ const result = await callTool("create_group_wiki_page", { group_id: TEST_GROUP_ID, title: "Home", content: "hello wiki" }, env());
386
+ assert.ok(isRecord(result));
387
+ assert.strictEqual(result.title, "Group Home");
388
+ });
389
+ it("should update a group wiki page with update_group_wiki_page", async () => {
390
+ const result = await callTool("update_group_wiki_page", { group_id: TEST_GROUP_ID, slug: TEST_WIKI_SLUG, content: "updated group wiki" }, env());
391
+ assert.ok(isRecord(result));
392
+ assert.strictEqual(result.content, "updated group wiki");
393
+ });
394
+ it("should delete a group wiki page with delete_group_wiki_page", async () => {
395
+ const result = await callTool("delete_group_wiki_page", { group_id: TEST_GROUP_ID, slug: TEST_WIKI_SLUG }, env());
396
+ assert.ok(isRecord(result));
397
+ assert.strictEqual(result.status, "success");
398
+ });
399
+ it("should return milestones from list_milestones", async () => {
400
+ const result = await callTool("list_milestones", { project_id: TEST_PROJECT_ID }, env());
401
+ assert.ok(Array.isArray(result));
402
+ assert.strictEqual(result[0].title, "v1");
403
+ });
404
+ it("should return a milestone from get_milestone", async () => {
405
+ const result = await callTool("get_milestone", { project_id: TEST_PROJECT_ID, milestone_id: TEST_MILESTONE_ID }, env());
406
+ assert.ok(isRecord(result));
407
+ assert.strictEqual(result.id, TEST_MILESTONE_ID);
408
+ });
409
+ it("should create a milestone with create_milestone", async () => {
410
+ const result = await callTool("create_milestone", { project_id: TEST_PROJECT_ID, title: "v1" }, env());
411
+ assert.ok(isRecord(result));
412
+ assert.strictEqual(result.title, "v1");
413
+ });
414
+ it("should edit a milestone with edit_milestone", async () => {
415
+ const result = await callTool("edit_milestone", {
416
+ project_id: TEST_PROJECT_ID,
417
+ milestone_id: TEST_MILESTONE_ID,
418
+ title: "v1-edited",
419
+ }, env());
420
+ assert.ok(isRecord(result));
421
+ assert.strictEqual(result.title, "v1-edited");
422
+ });
423
+ it("should delete a milestone with delete_milestone", async () => {
424
+ const result = await callTool("delete_milestone", { project_id: TEST_PROJECT_ID, milestone_id: TEST_MILESTONE_ID }, env());
425
+ assert.ok(isRecord(result));
426
+ assert.strictEqual(result.status, "success");
427
+ });
428
+ it("should return issues from get_milestone_issue", async () => {
429
+ const result = await callTool("get_milestone_issue", { project_id: TEST_PROJECT_ID, milestone_id: TEST_MILESTONE_ID }, env());
430
+ assert.ok(Array.isArray(result));
431
+ assert.strictEqual(result[0].title, "Issue one");
432
+ });
433
+ it("should return merge requests from get_milestone_merge_requests", async () => {
434
+ const result = await callTool("get_milestone_merge_requests", { project_id: TEST_PROJECT_ID, milestone_id: TEST_MILESTONE_ID }, env());
435
+ assert.ok(Array.isArray(result));
436
+ assert.strictEqual(result[0].title, "MR one");
437
+ });
438
+ it("should promote a milestone with promote_milestone", async () => {
439
+ const result = await callTool("promote_milestone", { project_id: TEST_PROJECT_ID, milestone_id: TEST_MILESTONE_ID }, env());
440
+ assert.ok(isRecord(result));
441
+ assert.strictEqual(result.group_id, TEST_GROUP_ID);
442
+ });
443
+ it("should return events from get_milestone_burndown_events", async () => {
444
+ const result = await callTool("get_milestone_burndown_events", { project_id: TEST_PROJECT_ID, milestone_id: TEST_MILESTONE_ID }, env());
445
+ assert.ok(Array.isArray(result));
446
+ assert.strictEqual(result[0].action, "created");
447
+ });
448
+ it("should return group milestones from list_group_milestones", async () => {
449
+ const result = await callTool("list_group_milestones", { group_id: TEST_GROUP_ID }, env());
450
+ assert.ok(Array.isArray(result));
451
+ assert.strictEqual(result[0].group_id, TEST_GROUP_ID);
452
+ });
453
+ it("should return a group milestone from get_group_milestone", async () => {
454
+ const result = await callTool("get_group_milestone", { group_id: TEST_GROUP_ID, milestone_id: TEST_MILESTONE_ID }, env());
455
+ assert.ok(isRecord(result));
456
+ assert.strictEqual(result.group_id, TEST_GROUP_ID);
457
+ });
458
+ it("should create a group milestone with create_group_milestone", async () => {
459
+ const result = await callTool("create_group_milestone", { group_id: TEST_GROUP_ID, title: "v1" }, env());
460
+ assert.ok(isRecord(result));
461
+ assert.strictEqual(result.title, "v1");
462
+ });
463
+ it("should edit a group milestone with edit_group_milestone", async () => {
464
+ const result = await callTool("edit_group_milestone", {
465
+ group_id: TEST_GROUP_ID,
466
+ milestone_id: TEST_MILESTONE_ID,
467
+ title: "v1-group-edited",
468
+ }, env());
469
+ assert.ok(isRecord(result));
470
+ assert.strictEqual(result.title, "v1-group-edited");
471
+ });
472
+ it("should delete a group milestone with delete_group_milestone", async () => {
473
+ const result = await callTool("delete_group_milestone", { group_id: TEST_GROUP_ID, milestone_id: TEST_MILESTONE_ID }, env());
474
+ assert.ok(isRecord(result));
475
+ assert.strictEqual(result.status, "success");
476
+ });
477
+ it("should return issues from get_group_milestone_issue", async () => {
478
+ const result = await callTool("get_group_milestone_issue", { group_id: TEST_GROUP_ID, milestone_id: TEST_MILESTONE_ID }, env());
479
+ assert.ok(Array.isArray(result));
480
+ assert.strictEqual(result[0].title, "Issue one");
481
+ });
482
+ it("should return merge requests from get_group_milestone_merge_requests", async () => {
483
+ const result = await callTool("get_group_milestone_merge_requests", { group_id: TEST_GROUP_ID, milestone_id: TEST_MILESTONE_ID }, env());
484
+ assert.ok(Array.isArray(result));
485
+ assert.strictEqual(result[0].title, "MR one");
486
+ });
487
+ it("should return events from get_group_milestone_burndown_events", async () => {
488
+ const result = await callTool("get_group_milestone_burndown_events", { group_id: TEST_GROUP_ID, milestone_id: TEST_MILESTONE_ID }, env());
489
+ assert.ok(Array.isArray(result));
490
+ assert.strictEqual(result[0].action, "created");
491
+ });
492
+ it("should return releases from list_releases", async () => {
493
+ const result = await callTool("list_releases", { project_id: TEST_PROJECT_ID }, env());
494
+ assert.ok(Array.isArray(result));
495
+ assert.strictEqual(result[0].tag_name, TEST_TAG_NAME);
496
+ });
497
+ it("should return a release from get_release", async () => {
498
+ const result = await callTool("get_release", { project_id: TEST_PROJECT_ID, tag_name: TEST_TAG_NAME }, env());
499
+ assert.ok(isRecord(result));
500
+ assert.strictEqual(result.tag_name, TEST_TAG_NAME);
501
+ });
502
+ it("should create a release with create_release", async () => {
503
+ const result = await callTool("create_release", { project_id: TEST_PROJECT_ID, tag_name: TEST_TAG_NAME }, env());
504
+ assert.ok(isRecord(result));
505
+ assert.strictEqual(result.tag_name, TEST_TAG_NAME);
506
+ });
507
+ it("should update a release with update_release", async () => {
508
+ const result = await callTool("update_release", {
509
+ project_id: TEST_PROJECT_ID,
510
+ tag_name: TEST_TAG_NAME,
511
+ description: "updated notes",
512
+ }, env());
513
+ assert.ok(isRecord(result));
514
+ assert.strictEqual(result.description, "updated notes");
515
+ });
516
+ it("should delete a release with delete_release", async () => {
517
+ const result = await callTool("delete_release", { project_id: TEST_PROJECT_ID, tag_name: TEST_TAG_NAME }, env());
518
+ assert.ok(isRecord(result));
519
+ assert.strictEqual(result.status, "success");
520
+ });
521
+ it("should create evidence with create_release_evidence", async () => {
522
+ const result = await callTool("create_release_evidence", { project_id: TEST_PROJECT_ID, tag_name: TEST_TAG_NAME }, env());
523
+ assert.ok(isRecord(result));
524
+ assert.strictEqual(result.status, "success");
525
+ });
526
+ it("should download an asset with download_release_asset", async () => {
527
+ const result = await callTool("download_release_asset", {
528
+ project_id: TEST_PROJECT_ID,
529
+ tag_name: TEST_TAG_NAME,
530
+ direct_asset_path: TEST_ASSET_PATH,
531
+ }, env());
532
+ assert.strictEqual(result, "asset-bytes");
533
+ });
534
+ });
535
+ });
@@ -120,4 +120,51 @@ describe("list_issues", () => {
120
120
  mockGitLab.clearCustomHandlers();
121
121
  }
122
122
  });
123
+ test("drops blank entries inside array filters", async () => {
124
+ let capturedUrl;
125
+ mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/issues`, (req, res) => {
126
+ capturedUrl = req.originalUrl;
127
+ res.json([]);
128
+ });
129
+ try {
130
+ await callListIssues({
131
+ project_id: TEST_PROJECT_ID,
132
+ labels: ["", " ", "bug"],
133
+ assignee_username: ["", "alice"],
134
+ }, {
135
+ GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
136
+ GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
137
+ });
138
+ assert.ok(capturedUrl, "Mock handler should have received a request");
139
+ const params = new URL(capturedUrl, "http://localhost").searchParams;
140
+ assert.deepStrictEqual(params.getAll("labels[]"), ["bug"], "Blank label entries should be dropped while non-blank ones are kept");
141
+ assert.deepStrictEqual(params.getAll("assignee_username[]"), ["alice"], "Blank assignee_username entries should be dropped while non-blank ones are kept");
142
+ }
143
+ finally {
144
+ mockGitLab.clearCustomHandlers();
145
+ }
146
+ });
147
+ test("omits array filters whose entries are all blank", async () => {
148
+ let capturedUrl;
149
+ mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/issues`, (req, res) => {
150
+ capturedUrl = req.originalUrl;
151
+ res.json([]);
152
+ });
153
+ try {
154
+ const issues = await callListIssues({
155
+ project_id: TEST_PROJECT_ID,
156
+ labels: ["", " "],
157
+ assignee_username: [""],
158
+ }, {
159
+ GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
160
+ GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
161
+ });
162
+ assert.deepStrictEqual(issues, []);
163
+ assert.ok(capturedUrl, "Mock handler should have received a request");
164
+ assert.strictEqual(new URL(capturedUrl, "http://localhost").search, "", "Array filters with only blank entries should not be serialized");
165
+ }
166
+ finally {
167
+ mockGitLab.clearCustomHandlers();
168
+ }
169
+ });
123
170
  });
@@ -103,6 +103,42 @@ describe('list_merge_requests', () => {
103
103
  assert.ok(Array.isArray(mrs), 'Response should be an array');
104
104
  assert.strictEqual(mrs.length, 2, 'Should return 2 mock MRs');
105
105
  });
106
+ test('omits empty optional filters instead of sending mutually exclusive query parameters', async () => {
107
+ let capturedUrl;
108
+ mockGitLab.addMockHandler('get', '/merge_requests', (req, res) => {
109
+ capturedUrl = req.originalUrl;
110
+ const hasEmptyFilter = Object.values(req.query).some(value => value === '');
111
+ if (hasEmptyFilter) {
112
+ res.status(400).json({ message: 'empty filters are invalid' });
113
+ return;
114
+ }
115
+ res.json([]);
116
+ });
117
+ try {
118
+ const mrs = await callListMergeRequests({
119
+ assignee_id: '',
120
+ assignee_username: '',
121
+ author_id: '',
122
+ author_username: '',
123
+ reviewer_id: '',
124
+ reviewer_username: '',
125
+ milestone: ' ',
126
+ search: '\t',
127
+ target_branch: ' ',
128
+ source_branch: '\n',
129
+ labels: [],
130
+ approved_by_usernames: [],
131
+ }, {
132
+ GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
133
+ GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
134
+ });
135
+ assert.deepStrictEqual(mrs, []);
136
+ assert.strictEqual(capturedUrl, '/api/v4/merge_requests');
137
+ }
138
+ finally {
139
+ mockGitLab.clearCustomHandlers();
140
+ }
141
+ });
106
142
  test('forwards approved_by_usernames in bracket-array form', async () => {
107
143
  let capturedUrl;
108
144
  mockGitLab.addMockHandler('get', '/merge_requests', (req, res) => {
@@ -122,4 +158,44 @@ describe('list_merge_requests', () => {
122
158
  mockGitLab.clearCustomHandlers();
123
159
  }
124
160
  });
161
+ test('drops blank entries inside array filters', async () => {
162
+ let capturedUrl;
163
+ mockGitLab.addMockHandler('get', '/merge_requests', (req, res) => {
164
+ capturedUrl = req.originalUrl;
165
+ res.json([]);
166
+ });
167
+ try {
168
+ await callListMergeRequests({ labels: ['', ' ', 'bug'], approved_by_usernames: ['alice', ''] }, {
169
+ GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
170
+ GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
171
+ });
172
+ assert.ok(capturedUrl, 'Mock handler should have received a request');
173
+ // Parse the query so the assertion does not depend on parameter order
174
+ const params = new URL(capturedUrl, 'http://localhost').searchParams;
175
+ assert.deepStrictEqual(params.getAll('labels'), ['bug'], 'Blank array entries should be dropped while non-blank ones are kept');
176
+ assert.deepStrictEqual(params.getAll('approved_by_usernames[]'), ['alice'], 'Blank array entries should be dropped while non-blank ones are kept');
177
+ }
178
+ finally {
179
+ mockGitLab.clearCustomHandlers();
180
+ }
181
+ });
182
+ test('omits array filters whose entries are all blank', async () => {
183
+ let capturedUrl;
184
+ mockGitLab.addMockHandler('get', '/merge_requests', (req, res) => {
185
+ capturedUrl = req.originalUrl;
186
+ res.json([]);
187
+ });
188
+ try {
189
+ const mrs = await callListMergeRequests({ labels: ['', ' '], approved_by_usernames: [''] }, {
190
+ GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
191
+ GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
192
+ });
193
+ assert.deepStrictEqual(mrs, []);
194
+ assert.ok(capturedUrl, 'Mock handler should have received a request');
195
+ assert.strictEqual(new URL(capturedUrl, 'http://localhost').search, '', 'Array filters with only blank entries should not be serialized');
196
+ }
197
+ finally {
198
+ mockGitLab.clearCustomHandlers();
199
+ }
200
+ });
125
201
  });