@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,201 +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
- // Helper to run the MCP tool
8
- async function callListMergeRequests(args = {}, env) {
9
- return new Promise((resolve, reject) => {
10
- const proc = spawn('node', ['build/index.js'], {
11
- stdio: ['pipe', 'pipe', 'pipe'],
12
- env: {
13
- ...process.env,
14
- ...env,
15
- GITLAB_READ_ONLY_MODE: 'true'
16
- }
17
- });
18
- let output = '';
19
- let errorOutput = '';
20
- proc.stdout?.on('data', d => output += d);
21
- proc.stderr?.on('data', d => errorOutput += d);
22
- proc.on('close', (code) => {
23
- if (code !== 0)
24
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
25
- // Find the JSON line in stdout
26
- const line = output.split('\n').find(l => l.startsWith('{'));
27
- if (!line)
28
- return reject(new Error('No JSON output found'));
29
- try {
30
- const response = JSON.parse(line);
31
- if (response.error) {
32
- reject(response.error);
33
- }
34
- else {
35
- // Parse the tool result content
36
- const content = response.result?.content?.[0]?.text;
37
- if (content) {
38
- try {
39
- resolve(JSON.parse(content));
40
- }
41
- catch (e) {
42
- reject(new Error(`Failed to parse tool output JSON: ${content}`));
43
- }
44
- }
45
- else {
46
- // Fallback for direct result (if changed in future) or empty
47
- resolve(response.result);
48
- }
49
- }
50
- }
51
- catch (e) {
52
- reject(e);
53
- }
54
- });
55
- proc.stdin?.end(JSON.stringify({
56
- jsonrpc: "2.0", id: 1, method: "tools/call",
57
- params: { name: "list_merge_requests", arguments: args }
58
- }) + '\n');
59
- });
60
- }
61
- describe('list_merge_requests', () => {
62
- let mockGitLab;
63
- let mockGitLabUrl;
64
- before(async () => {
65
- const mockPort = await findMockServerPort();
66
- mockGitLab = new MockGitLabServer({
67
- port: mockPort,
68
- validTokens: [MOCK_TOKEN]
69
- });
70
- await mockGitLab.start();
71
- mockGitLabUrl = mockGitLab.getUrl();
72
- });
73
- after(async () => {
74
- await mockGitLab.stop();
75
- });
76
- test('lists global merge requests (no project_id)', async () => {
77
- const mrs = await callListMergeRequests({}, {
78
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
79
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
80
- });
81
- assert.ok(Array.isArray(mrs), 'Response should be an array');
82
- assert.strictEqual(mrs.length, 2, 'Should return 2 mock MRs');
83
- // Schema coerces project_id to string
84
- assert.strictEqual(String(mrs[0].project_id), '123', 'MR should have correct project_id');
85
- });
86
- test('lists project-specific merge requests', async () => {
87
- const mrs = await callListMergeRequests({ project_id: TEST_PROJECT_ID }, {
88
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
89
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
90
- });
91
- assert.ok(Array.isArray(mrs), 'Response should be an array');
92
- assert.strictEqual(mrs.length, 2, 'Should return 2 mock MRs');
93
- assert.strictEqual(mrs[0].title, 'Test MR 1');
94
- });
95
- test('filters global merge requests', async () => {
96
- // Note: The mock server returns static data, so filtering won't actually filter the results
97
- // unless we implement filtering logic in the mock.
98
- // But we can verify the call succeeds.
99
- const mrs = await callListMergeRequests({ state: 'opened' }, {
100
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
101
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
102
- });
103
- assert.ok(Array.isArray(mrs), 'Response should be an array');
104
- assert.strictEqual(mrs.length, 2, 'Should return 2 mock MRs');
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
- });
142
- test('forwards approved_by_usernames in bracket-array form', async () => {
143
- let capturedUrl;
144
- mockGitLab.addMockHandler('get', '/merge_requests', (req, res) => {
145
- capturedUrl = req.originalUrl;
146
- res.json([]);
147
- });
148
- try {
149
- await callListMergeRequests({ approved_by_usernames: ['alice', 'bob'] }, {
150
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
151
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
152
- });
153
- assert.ok(capturedUrl, 'Mock handler should have received a request');
154
- assert.match(capturedUrl, /approved_by_usernames%5B%5D=alice/, 'Request URL should contain approved_by_usernames[]=alice (URL-encoded)');
155
- assert.match(capturedUrl, /approved_by_usernames%5B%5D=bob/, 'Request URL should contain approved_by_usernames[]=bob (URL-encoded)');
156
- }
157
- finally {
158
- mockGitLab.clearCustomHandlers();
159
- }
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
- });
201
- });
@@ -1,145 +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_GROUP_ID = "my-group";
8
- // Milestone tools live in the non-default "milestones" toolset
9
- const TOOLSET_ENV = { GITLAB_TOOLSETS: "milestones" };
10
- // Helper to run an MCP tool through the stdio server
11
- async function callTool(toolName, args, env) {
12
- return new Promise((resolve, reject) => {
13
- const proc = spawn("node", ["build/index.js"], {
14
- stdio: ["pipe", "pipe", "pipe"],
15
- env: {
16
- ...process.env,
17
- ...TOOLSET_ENV,
18
- ...env,
19
- GITLAB_READ_ONLY_MODE: "true",
20
- },
21
- });
22
- let output = "";
23
- let errorOutput = "";
24
- proc.stdout?.on("data", d => (output += d));
25
- proc.stderr?.on("data", d => (errorOutput += d));
26
- proc.on("close", code => {
27
- if (code !== 0)
28
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
29
- const line = output.split("\n").find(l => l.startsWith("{"));
30
- if (!line)
31
- return reject(new Error("No JSON output found"));
32
- try {
33
- const response = JSON.parse(line);
34
- if (response.error) {
35
- reject(new Error(JSON.stringify(response.error)));
36
- return;
37
- }
38
- const content = response.result?.content?.[0]?.text;
39
- if (content) {
40
- try {
41
- resolve(JSON.parse(content));
42
- }
43
- catch {
44
- reject(new Error(`Failed to parse tool output JSON: ${content}`));
45
- }
46
- }
47
- else {
48
- resolve(response.result);
49
- }
50
- }
51
- catch (e) {
52
- reject(e);
53
- }
54
- });
55
- proc.stdin?.end(JSON.stringify({
56
- jsonrpc: "2.0",
57
- id: 1,
58
- method: "tools/call",
59
- params: { name: toolName, arguments: args },
60
- }) + "\n");
61
- });
62
- }
63
- describe("milestone list iids filters", () => {
64
- let mockGitLab;
65
- let mockGitLabUrl;
66
- before(async () => {
67
- const mockPort = await findMockServerPort();
68
- mockGitLab = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
69
- await mockGitLab.start();
70
- mockGitLabUrl = mockGitLab.getUrl();
71
- });
72
- after(async () => {
73
- await mockGitLab.stop();
74
- });
75
- const env = () => ({
76
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
77
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
78
- });
79
- test("omits an empty iids filter for list_milestones", async () => {
80
- let capturedUrl;
81
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/milestones`, (req, res) => {
82
- capturedUrl = req.originalUrl;
83
- res.json([]);
84
- });
85
- try {
86
- const milestones = await callTool("list_milestones", { project_id: TEST_PROJECT_ID, iids: [] }, env());
87
- assert.deepStrictEqual(milestones, []);
88
- assert.ok(capturedUrl, "Mock handler should have received a request");
89
- assert.strictEqual(new URL(capturedUrl, "http://localhost").search, "", "An empty iids array should not be serialized as `iids=`");
90
- }
91
- finally {
92
- mockGitLab.clearCustomHandlers();
93
- }
94
- });
95
- test("forwards non-empty iids in bracket-array form", async () => {
96
- let capturedUrl;
97
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/milestones`, (req, res) => {
98
- capturedUrl = req.originalUrl;
99
- res.json([]);
100
- });
101
- try {
102
- await callTool("list_milestones", { project_id: TEST_PROJECT_ID, iids: [1, 2] }, env());
103
- assert.ok(capturedUrl, "Mock handler should have received a request");
104
- const params = new URL(capturedUrl, "http://localhost").searchParams;
105
- assert.deepStrictEqual(params.getAll("iids[]"), ["1", "2"]);
106
- }
107
- finally {
108
- mockGitLab.clearCustomHandlers();
109
- }
110
- });
111
- test("omits blank milestone filters", async () => {
112
- let capturedUrl;
113
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/milestones`, (req, res) => {
114
- capturedUrl = req.originalUrl;
115
- res.json([]);
116
- });
117
- try {
118
- await callTool("list_milestones", { project_id: TEST_PROJECT_ID, iids: [], title: " ", search: "" }, env());
119
- assert.ok(capturedUrl, "Mock handler should have received a request");
120
- assert.strictEqual(new URL(capturedUrl, "http://localhost").search, "", "Blank milestone filters should not be serialized");
121
- }
122
- finally {
123
- mockGitLab.clearCustomHandlers();
124
- }
125
- });
126
- test("omits an empty iids filter for list_group_milestones", async () => {
127
- let capturedUrl;
128
- mockGitLab.addMockHandler("get", `/groups/${TEST_GROUP_ID}/milestones`, (req, res) => {
129
- capturedUrl = req.originalUrl;
130
- res.json([]);
131
- });
132
- try {
133
- const milestones = await callTool("list_group_milestones", { group_id: TEST_GROUP_ID, iids: [], state: "active" }, env());
134
- assert.deepStrictEqual(milestones, []);
135
- assert.ok(capturedUrl, "Mock handler should have received a request");
136
- const params = new URL(capturedUrl, "http://localhost").searchParams;
137
- assert.equal(params.has("iids"), false, "An empty iids array should not be serialized as `iids=`");
138
- assert.deepStrictEqual(params.getAll("iids[]"), []);
139
- assert.deepStrictEqual(params.getAll("state"), ["active"]);
140
- }
141
- finally {
142
- mockGitLab.clearCustomHandlers();
143
- }
144
- });
145
- });
@@ -1,132 +0,0 @@
1
- import { describe, test, before, after, beforeEach } 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 directMembers = [
8
- {
9
- id: 1,
10
- username: 'direct-user',
11
- name: 'Direct User',
12
- state: 'active',
13
- avatar_url: null,
14
- web_url: 'https://gitlab.mock/users/1',
15
- access_level: 30,
16
- created_at: '2024-01-01T00:00:00Z'
17
- }
18
- ];
19
- const inheritedMembers = [
20
- {
21
- id: 2,
22
- username: 'inherited-user',
23
- name: 'Inherited User',
24
- state: 'active',
25
- avatar_url: null,
26
- web_url: 'https://gitlab.mock/users/2',
27
- access_level: 20,
28
- created_at: '2024-01-02T00:00:00Z'
29
- }
30
- ];
31
- async function callListProjectMembers(args, env) {
32
- return new Promise((resolve, reject) => {
33
- const proc = spawn('node', ['build/index.js'], {
34
- stdio: ['pipe', 'pipe', 'pipe'],
35
- env: {
36
- ...process.env,
37
- ...env,
38
- GITLAB_READ_ONLY_MODE: 'true'
39
- }
40
- });
41
- let output = '';
42
- let errorOutput = '';
43
- proc.stdout?.on('data', d => output += d);
44
- proc.stderr?.on('data', d => errorOutput += d);
45
- proc.on('close', (code) => {
46
- if (code !== 0)
47
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
48
- const line = output.split('\n').find(l => l.startsWith('{'));
49
- if (!line)
50
- return reject(new Error('No JSON output found'));
51
- try {
52
- const response = JSON.parse(line);
53
- if (response.error) {
54
- reject(response.error);
55
- }
56
- else {
57
- const content = response.result?.content?.[0]?.text;
58
- if (content) {
59
- try {
60
- resolve(JSON.parse(content));
61
- }
62
- catch (e) {
63
- reject(new Error(`Failed to parse tool output JSON: ${content}`));
64
- }
65
- }
66
- else {
67
- resolve(response.result);
68
- }
69
- }
70
- }
71
- catch (e) {
72
- reject(e);
73
- }
74
- });
75
- proc.stdin?.end(JSON.stringify({
76
- jsonrpc: "2.0", id: 1, method: "tools/call",
77
- params: { name: "list_project_members", arguments: args }
78
- }) + '\n');
79
- });
80
- }
81
- describe('list_project_members', () => {
82
- let mockGitLab;
83
- let mockGitLabUrl;
84
- let directEndpointHit = false;
85
- let inheritedEndpointHit = false;
86
- before(async () => {
87
- const mockPort = await findMockServerPort();
88
- mockGitLab = new MockGitLabServer({
89
- port: mockPort,
90
- validTokens: [MOCK_TOKEN]
91
- });
92
- await mockGitLab.start();
93
- mockGitLabUrl = mockGitLab.getUrl();
94
- mockGitLab.addMockHandler('get', `/projects/${TEST_PROJECT_ID}/members`, (req, res) => {
95
- directEndpointHit = true;
96
- res.json(directMembers);
97
- });
98
- mockGitLab.addMockHandler('get', `/projects/${TEST_PROJECT_ID}/members/all`, (req, res) => {
99
- inheritedEndpointHit = true;
100
- res.json([...directMembers, ...inheritedMembers]);
101
- });
102
- });
103
- beforeEach(() => {
104
- directEndpointHit = false;
105
- inheritedEndpointHit = false;
106
- });
107
- after(async () => {
108
- await mockGitLab.stop();
109
- });
110
- test('lists direct project members', async () => {
111
- const members = await callListProjectMembers({ project_id: TEST_PROJECT_ID }, {
112
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
113
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
114
- });
115
- assert.ok(Array.isArray(members), 'Response should be an array');
116
- assert.strictEqual(members.length, 1, 'Should return direct members');
117
- assert.strictEqual(members[0].username, 'direct-user');
118
- assert.strictEqual(directEndpointHit, true, 'Direct members endpoint should be called');
119
- assert.strictEqual(inheritedEndpointHit, false, 'Inherited members endpoint should not be called');
120
- });
121
- test('lists project members including inheritance', async () => {
122
- const members = await callListProjectMembers({ project_id: TEST_PROJECT_ID, include_inheritance: true }, {
123
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
124
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
125
- });
126
- assert.ok(Array.isArray(members), 'Response should be an array');
127
- assert.strictEqual(members.length, 2, 'Should return inherited members');
128
- assert.strictEqual(members[1].username, 'inherited-user');
129
- assert.strictEqual(inheritedEndpointHit, true, 'Inherited members endpoint should be called');
130
- assert.strictEqual(directEndpointHit, false, 'Direct members endpoint should not be called');
131
- });
132
- });