@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.
- package/README.ko.md +10 -4
- package/README.md +238 -233
- package/README.pt-BR.md +4 -4
- package/README.zh-CN.md +6 -4
- package/build/config.js +12 -4
- package/build/deprecated-env.js +47 -0
- package/build/index.js +456 -237
- package/build/oauth-device-flow.js +80 -0
- package/build/oauth.js +135 -18
- package/build/schemas.js +1 -1
- package/build/server/remote-http-stack.js +39 -0
- package/build/tools/discover-activation.js +38 -0
- package/build/tools/exposed-tools.js +35 -0
- package/build/tools/listed-tools.js +76 -0
- package/build/tools/registry.js +226 -57
- package/build/tools/tool-profile.js +66 -0
- package/build/utils/compact-tool-allowlist.js +14 -0
- package/build/utils/logger.js +34 -12
- package/build/utils/url.js +15 -0
- package/package.json +3 -3
- package/build/scripts/check-skill-sync.js +0 -143
- package/build/scripts/generate-server-card.js +0 -39
- package/build/scripts/generate-tool-coverage.js +0 -58
- package/build/scripts/generate-tool-docs.js +0 -430
- package/build/scripts/tool-coverage/coverage.js +0 -341
- package/build/scripts/tool-coverage/coverage.test.js +0 -142
- package/build/test/callback-proxy-tests.js +0 -321
- package/build/test/cli/args.test.js +0 -175
- package/build/test/cli/boolean-flags.test.js +0 -106
- package/build/test/cli/compact-mcp-result.test.js +0 -93
- package/build/test/cli/exposure.test.js +0 -104
- package/build/test/cli/load-config-snapshot.js +0 -5
- package/build/test/cli/output.test.js +0 -74
- package/build/test/cli/replay-command.test.js +0 -37
- package/build/test/cli/router.test.js +0 -183
- package/build/test/client-pool-test.js +0 -109
- package/build/test/clients/client.js +0 -34
- package/build/test/clients/custom-header-client.js +0 -122
- package/build/test/clients/sse-client.js +0 -95
- package/build/test/clients/stdio-client.js +0 -113
- package/build/test/clients/streamable-http-client.js +0 -95
- package/build/test/config-allowed-groups.test.js +0 -97
- package/build/test/create-commit-actions.test.js +0 -102
- package/build/test/draft-note-schema.test.js +0 -44
- package/build/test/dynamic-api-url-allowlist.test.js +0 -121
- package/build/test/dynamic-api-url-test.js +0 -304
- package/build/test/dynamic-routing-tests.js +0 -495
- package/build/test/get-merge-request-discussion-schema.test.js +0 -30
- package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
- package/build/test/gitlab-diff-schema.test.js +0 -36
- package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
- package/build/test/gitlab-tag-schema.test.js +0 -51
- package/build/test/group-milestone-schema.test.js +0 -45
- package/build/test/mcp-oauth-tests.js +0 -905
- package/build/test/mcp-server-name.test.js +0 -87
- package/build/test/merge-merge-request-schema.test.js +0 -75
- package/build/test/multi-server-test.js +0 -190
- package/build/test/no-proxy-integration-test.js +0 -183
- package/build/test/no-proxy-test.js +0 -149
- package/build/test/nullable-gitlab-response-fields.test.js +0 -37
- package/build/test/nullish-tool-arguments-schema.test.js +0 -118
- package/build/test/oauth-device-flow-tests.js +0 -450
- package/build/test/oauth-startup.test.js +0 -204
- package/build/test/oauth-tests.js +0 -428
- package/build/test/path-segment-encoding.test.js +0 -98
- package/build/test/remote-auth-simple-test.js +0 -277
- package/build/test/remote-auth-tests.js +0 -314
- package/build/test/response-masking.test.js +0 -445
- package/build/test/schema-tests.js +0 -1679
- package/build/test/server/metrics.test.js +0 -47
- package/build/test/server/request-helpers.test.js +0 -48
- package/build/test/server/version.test.js +0 -13
- package/build/test/sse-auth-guard.test.js +0 -96
- package/build/test/sse-session-limits.test.js +0 -273
- package/build/test/stateless/callback-proxy.test.js +0 -510
- package/build/test/stateless/client-id.test.js +0 -177
- package/build/test/stateless/codec.test.js +0 -328
- package/build/test/stateless/config-ttl.test.js +0 -149
- package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
- package/build/test/stateless/session-id-integration.test.js +0 -675
- package/build/test/stateless/session-id.test.js +0 -157
- package/build/test/streamable-http-concurrent-session.test.js +0 -171
- package/build/test/streamable-http-dns-rebinding.test.js +0 -185
- package/build/test/streamable-http-sse-stream.test.js +0 -350
- package/build/test/streamable-http-static-token-auth.test.js +0 -157
- package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
- package/build/test/test-all-transport-server.js +0 -255
- package/build/test/test-auth-retry.js +0 -195
- package/build/test/test-blank-filters.js +0 -156
- package/build/test/test-ci-catalog.js +0 -177
- package/build/test/test-ci-lint.js +0 -191
- package/build/test/test-ci-variables.js +0 -309
- package/build/test/test-create-repository.js +0 -120
- package/build/test/test-dependency-proxy.js +0 -195
- package/build/test/test-deployment-tools.js +0 -463
- package/build/test/test-download-attachment.js +0 -190
- package/build/test/test-dynamic-project-scope.js +0 -524
- package/build/test/test-empty-toolsets.js +0 -535
- package/build/test/test-get-file-blame.js +0 -145
- package/build/test/test-get-file-contents.js +0 -128
- package/build/test/test-geteffectiveprojectid.js +0 -812
- package/build/test/test-health-check.js +0 -115
- package/build/test/test-issue-description-patch.js +0 -256
- package/build/test/test-job-artifacts.js +0 -275
- package/build/test/test-json-schema.js +0 -166
- package/build/test/test-list-group-members.js +0 -150
- package/build/test/test-list-group-merge-requests.js +0 -165
- package/build/test/test-list-issues.js +0 -170
- package/build/test/test-list-merge-requests.js +0 -201
- package/build/test/test-list-milestones.js +0 -145
- package/build/test/test-list-project-members.js +0 -132
- package/build/test/test-merge-request-approval-state-tools.js +0 -213
- package/build/test/test-merge-request-approvals.js +0 -187
- package/build/test/test-merge-request-pipelines.js +0 -106
- package/build/test/test-mr-diffs-filter.js +0 -132
- package/build/test/test-mr-file-diffs.js +0 -251
- package/build/test/test-oauth-proxy-rate-limit.js +0 -133
- package/build/test/test-orbit.js +0 -155
- package/build/test/test-permission-mode.js +0 -424
- package/build/test/test-pipeline-schedules.js +0 -482
- package/build/test/test-protected-branches.js +0 -174
- package/build/test/test-remote-downloads.js +0 -510
- package/build/test/test-search-code.js +0 -275
- package/build/test/test-snippets.js +0 -735
- package/build/test/test-tags.js +0 -220
- package/build/test/test-todos.js +0 -195
- package/build/test/test-token-optimizations.js +0 -691
- package/build/test/test-toolset-filtering.js +0 -499
- package/build/test/test-update-issue-slim.js +0 -141
- package/build/test/test-update-project.js +0 -112
- package/build/test/test-upload-markdown.js +0 -206
- package/build/test/test-vulnerabilities.js +0 -399
- package/build/test/test-webhooks.js +0 -218
- package/build/test/tool-description-quality.test.js +0 -50
- package/build/test/utils/bulk-publish-options.test.js +0 -32
- package/build/test/utils/download-token.test.js +0 -35
- package/build/test/utils/forwarded-public-base-url.test.js +0 -46
- package/build/test/utils/gitlab-instance-version.test.js +0 -32
- package/build/test/utils/gitlab-version-gate.test.js +0 -74
- package/build/test/utils/graphql-query.test.js +0 -168
- package/build/test/utils/helpers-path.test.js +0 -104
- package/build/test/utils/jmespath-tool-result.test.js +0 -91
- package/build/test/utils/masking.test.js +0 -384
- package/build/test/utils/merge-request-position.test.js +0 -57
- package/build/test/utils/mock-gitlab-server.js +0 -614
- package/build/test/utils/proxy-client-ip.test.js +0 -28
- package/build/test/utils/redact-sensitive.test.js +0 -32
- package/build/test/utils/safe-redirect-fetch.test.js +0 -463
- package/build/test/utils/server-launcher.js +0 -231
- package/build/test/utils/tool-args.test.js +0 -210
- package/build/test/utils/url.test.js +0 -128
- package/build/test/utils/version-check.test.js +0 -239
- package/build/test/utils/wiki-title.test.js +0 -21
- package/build/test-note.js +0 -54
- package/build/test-resolve-issue-note.js +0 -127
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, test, before, after, afterEach } 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
|
-
// Cases below cover tools outside the default toolsets, so every toolset is enabled.
|
|
8
|
-
const TOOLSET_ENV = { GITLAB_TOOLSETS: "all" };
|
|
9
|
-
// Helper to run an MCP tool through the stdio server
|
|
10
|
-
async function callTool(toolName, args, env) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const proc = spawn("node", ["build/index.js"], {
|
|
13
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
14
|
-
env: {
|
|
15
|
-
...process.env,
|
|
16
|
-
...TOOLSET_ENV,
|
|
17
|
-
...env,
|
|
18
|
-
GITLAB_READ_ONLY_MODE: "true",
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
let output = "";
|
|
22
|
-
let errorOutput = "";
|
|
23
|
-
proc.stdout?.on("data", d => (output += d));
|
|
24
|
-
proc.stderr?.on("data", d => (errorOutput += d));
|
|
25
|
-
proc.on("close", code => {
|
|
26
|
-
if (code !== 0)
|
|
27
|
-
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
28
|
-
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
29
|
-
if (!line)
|
|
30
|
-
return reject(new Error("No JSON output found"));
|
|
31
|
-
try {
|
|
32
|
-
const response = JSON.parse(line);
|
|
33
|
-
if (response.error) {
|
|
34
|
-
reject(new Error(JSON.stringify(response.error)));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const content = response.result?.content?.[0]?.text;
|
|
38
|
-
if (content) {
|
|
39
|
-
try {
|
|
40
|
-
resolve(JSON.parse(content));
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
reject(new Error(`Failed to parse tool output JSON: ${content}`));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
resolve(response.result);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
reject(e);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
proc.stdin?.end(JSON.stringify({
|
|
55
|
-
jsonrpc: "2.0",
|
|
56
|
-
id: 1,
|
|
57
|
-
method: "tools/call",
|
|
58
|
-
params: { name: toolName, arguments: args },
|
|
59
|
-
}) + "\n");
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
describe("blank query filters", () => {
|
|
63
|
-
let mockGitLab;
|
|
64
|
-
let mockGitLabUrl;
|
|
65
|
-
before(async () => {
|
|
66
|
-
const mockPort = await findMockServerPort();
|
|
67
|
-
mockGitLab = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
|
|
68
|
-
await mockGitLab.start();
|
|
69
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
70
|
-
});
|
|
71
|
-
after(async () => {
|
|
72
|
-
await mockGitLab.stop();
|
|
73
|
-
});
|
|
74
|
-
afterEach(() => {
|
|
75
|
-
mockGitLab.clearCustomHandlers();
|
|
76
|
-
});
|
|
77
|
-
const env = () => ({
|
|
78
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
79
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
80
|
-
});
|
|
81
|
-
// Registers a handler that captures the request URL and answers with an empty list
|
|
82
|
-
function captureRequest(path) {
|
|
83
|
-
let capturedUrl;
|
|
84
|
-
mockGitLab.addMockHandler("get", path, (req, res) => {
|
|
85
|
-
capturedUrl = req.originalUrl;
|
|
86
|
-
res.json([]);
|
|
87
|
-
});
|
|
88
|
-
return () => {
|
|
89
|
-
assert.ok(capturedUrl, "Mock handler should have received a request");
|
|
90
|
-
return capturedUrl;
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function searchOf(capturedUrl) {
|
|
94
|
-
return new URL(capturedUrl, "http://localhost").search;
|
|
95
|
-
}
|
|
96
|
-
test("list_labels omits blank filters", async () => {
|
|
97
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/labels`);
|
|
98
|
-
const labels = await callTool("list_labels", { project_id: TEST_PROJECT_ID, search: "" }, env());
|
|
99
|
-
assert.deepStrictEqual(labels, []);
|
|
100
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
101
|
-
});
|
|
102
|
-
test("list_tags omits blank filters", async () => {
|
|
103
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/repository/tags`);
|
|
104
|
-
const tags = await callTool("list_tags", { project_id: TEST_PROJECT_ID, search: " " }, env());
|
|
105
|
-
assert.deepStrictEqual(tags, []);
|
|
106
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
107
|
-
});
|
|
108
|
-
test("list_pipelines omits blank filters", async () => {
|
|
109
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/pipelines`);
|
|
110
|
-
const pipelines = await callTool("list_pipelines", { project_id: TEST_PROJECT_ID, ref: "" }, env());
|
|
111
|
-
assert.deepStrictEqual(pipelines, []);
|
|
112
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
113
|
-
});
|
|
114
|
-
test("list_deployments omits blank filters", async () => {
|
|
115
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/deployments`);
|
|
116
|
-
const deployments = await callTool("list_deployments", { project_id: TEST_PROJECT_ID, environment: "", ref: "\t" }, env());
|
|
117
|
-
assert.deepStrictEqual(deployments, []);
|
|
118
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
119
|
-
});
|
|
120
|
-
test("list_environments omits blank filters", async () => {
|
|
121
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/environments`);
|
|
122
|
-
const environments = await callTool("list_environments", { project_id: TEST_PROJECT_ID, name: " ", search: "" }, env());
|
|
123
|
-
assert.deepStrictEqual(environments, []);
|
|
124
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
125
|
-
});
|
|
126
|
-
test("list_job_artifacts omits blank filters", async () => {
|
|
127
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/jobs/7/artifacts/tree`);
|
|
128
|
-
const artifacts = await callTool("list_job_artifacts", { project_id: TEST_PROJECT_ID, job_id: "7", path: "" }, env());
|
|
129
|
-
assert.deepStrictEqual(artifacts, []);
|
|
130
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
131
|
-
});
|
|
132
|
-
test("list_events omits blank filters", async () => {
|
|
133
|
-
const capturedUrl = captureRequest("/events");
|
|
134
|
-
const events = await callTool("list_events", { action: "", scope: " \t" }, env());
|
|
135
|
-
assert.deepStrictEqual(events, []);
|
|
136
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
137
|
-
});
|
|
138
|
-
test("list_project_variables omits blank nested filters", async () => {
|
|
139
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/variables`);
|
|
140
|
-
const variables = await callTool("list_project_variables", { project_id: TEST_PROJECT_ID, filter: { environment_scope: " " } }, env());
|
|
141
|
-
assert.deepStrictEqual(variables, []);
|
|
142
|
-
assert.strictEqual(searchOf(capturedUrl()), "");
|
|
143
|
-
});
|
|
144
|
-
test("list_labels keeps a non-blank filter", async () => {
|
|
145
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/labels`);
|
|
146
|
-
await callTool("list_labels", { project_id: TEST_PROJECT_ID, search: "bug" }, env());
|
|
147
|
-
const params = new URL(capturedUrl(), "http://localhost").searchParams;
|
|
148
|
-
assert.deepStrictEqual(params.getAll("search"), ["bug"]);
|
|
149
|
-
});
|
|
150
|
-
test("list_project_variables keeps a non-blank nested filter", async () => {
|
|
151
|
-
const capturedUrl = captureRequest(`/projects/${TEST_PROJECT_ID}/variables`);
|
|
152
|
-
await callTool("list_project_variables", { project_id: TEST_PROJECT_ID, filter: { environment_scope: "production" } }, env());
|
|
153
|
-
const params = new URL(capturedUrl(), "http://localhost").searchParams;
|
|
154
|
-
assert.deepStrictEqual(params.getAll("filter[environment_scope]"), ["production"]);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { after, before, describe, test } 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 = "mock-ci-catalog-token";
|
|
6
|
-
async function callTool(toolName, args, env) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const proc = spawn("node", ["build/index.js"], {
|
|
9
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
10
|
-
env: {
|
|
11
|
-
...process.env,
|
|
12
|
-
...env,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
proc.on("error", reject);
|
|
16
|
-
let output = "";
|
|
17
|
-
let errorOutput = "";
|
|
18
|
-
proc.stdout?.on("data", (d) => (output += d));
|
|
19
|
-
proc.stderr?.on("data", (d) => (errorOutput += d));
|
|
20
|
-
proc.on("close", code => {
|
|
21
|
-
if (code !== 0) {
|
|
22
|
-
reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
27
|
-
if (!line) {
|
|
28
|
-
reject(new Error("No JSON output found"));
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const response = JSON.parse(line);
|
|
32
|
-
if (response.error) {
|
|
33
|
-
reject(new Error(response.error.message ?? JSON.stringify(response.error)));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const content = response.result?.content?.[0]?.text;
|
|
37
|
-
resolve(content ? JSON.parse(content) : response.result);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
reject(error);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
proc.stdin?.end(JSON.stringify({
|
|
44
|
-
jsonrpc: "2.0",
|
|
45
|
-
id: 1,
|
|
46
|
-
method: "tools/call",
|
|
47
|
-
params: { name: toolName, arguments: args },
|
|
48
|
-
}) + "\n");
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
describe("CI/CD Catalog tools", () => {
|
|
52
|
-
let mockGitLab;
|
|
53
|
-
let mockGitLabUrl;
|
|
54
|
-
const env = () => ({
|
|
55
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
56
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
57
|
-
});
|
|
58
|
-
before(async () => {
|
|
59
|
-
const port = await findMockServerPort();
|
|
60
|
-
mockGitLab = new MockGitLabServer({ port, validTokens: [MOCK_TOKEN] });
|
|
61
|
-
mockGitLab.addRootHandler("post", "/api/graphql", (req, res) => {
|
|
62
|
-
if (req.body.query.includes("ListCiCatalogResources")) {
|
|
63
|
-
assert.strictEqual(req.body.variables.search, "docker");
|
|
64
|
-
res.json({
|
|
65
|
-
data: {
|
|
66
|
-
ciCatalogResources: {
|
|
67
|
-
nodes: [
|
|
68
|
-
{
|
|
69
|
-
id: "gid://gitlab/Ci::Catalog::Resource/1",
|
|
70
|
-
name: "Docker",
|
|
71
|
-
description: "Build Docker images",
|
|
72
|
-
fullPath: "components/docker",
|
|
73
|
-
icon: null,
|
|
74
|
-
starCount: 3,
|
|
75
|
-
topics: ["ci"],
|
|
76
|
-
verificationLevel: "UNVERIFIED",
|
|
77
|
-
visibilityLevel: "public",
|
|
78
|
-
webPath: "/components/docker",
|
|
79
|
-
latestReleasedAt: "2026-01-01T00:00:00Z",
|
|
80
|
-
last30DayUsageCount: 7,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
res.json({
|
|
90
|
-
data: {
|
|
91
|
-
ciCatalogResource: {
|
|
92
|
-
id: "gid://gitlab/Ci::Catalog::Resource/1",
|
|
93
|
-
name: "Docker",
|
|
94
|
-
description: "Build Docker images",
|
|
95
|
-
fullPath: "components/docker",
|
|
96
|
-
icon: null,
|
|
97
|
-
starCount: 3,
|
|
98
|
-
topics: ["ci"],
|
|
99
|
-
verificationLevel: "UNVERIFIED",
|
|
100
|
-
visibilityLevel: "public",
|
|
101
|
-
webPath: "/components/docker",
|
|
102
|
-
latestReleasedAt: "2026-01-01T00:00:00Z",
|
|
103
|
-
last30DayUsageCount: 7,
|
|
104
|
-
versions: {
|
|
105
|
-
nodes: [
|
|
106
|
-
{
|
|
107
|
-
id: "gid://gitlab/Ci::Catalog::Resources::Version/1",
|
|
108
|
-
name: "1.0.0",
|
|
109
|
-
path: "/components/docker/-/releases/1.0.0",
|
|
110
|
-
createdAt: "2026-01-01T00:00:00Z",
|
|
111
|
-
releasedAt: "2026-01-01T00:00:00Z",
|
|
112
|
-
semver: { major: 1, minor: 0, patch: 0 },
|
|
113
|
-
components: {
|
|
114
|
-
nodes: [
|
|
115
|
-
{
|
|
116
|
-
id: "gid://gitlab/Ci::Catalog::Resources::Component/1",
|
|
117
|
-
name: "build",
|
|
118
|
-
description: "Build an image",
|
|
119
|
-
includePath: "components/docker/build@1.0.0",
|
|
120
|
-
last30DayUsageCount: 4,
|
|
121
|
-
inputs: [
|
|
122
|
-
{
|
|
123
|
-
name: "image",
|
|
124
|
-
description: "Image name",
|
|
125
|
-
type: "STRING",
|
|
126
|
-
required: true,
|
|
127
|
-
default: null,
|
|
128
|
-
options: null,
|
|
129
|
-
regex: null,
|
|
130
|
-
},
|
|
131
|
-
],
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
id: "gid://gitlab/Ci::Catalog::Resources::Component/2",
|
|
135
|
-
name: "scan",
|
|
136
|
-
description: "Scan an image",
|
|
137
|
-
includePath: "components/docker/scan@1.0.0",
|
|
138
|
-
last30DayUsageCount: 2,
|
|
139
|
-
inputs: [],
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
pageInfo: { hasNextPage: false, endCursor: null },
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
await mockGitLab.start();
|
|
153
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
154
|
-
});
|
|
155
|
-
after(async () => {
|
|
156
|
-
await mockGitLab.stop();
|
|
157
|
-
});
|
|
158
|
-
test("list_ci_catalog_resources calls GitLab GraphQL", async () => {
|
|
159
|
-
const result = await callTool("list_ci_catalog_resources", { search: "docker" }, env());
|
|
160
|
-
const resource = result.data.ciCatalogResources.nodes[0];
|
|
161
|
-
assert.strictEqual(resource.name, "Docker");
|
|
162
|
-
assert.strictEqual(resource.fullPath, "components/docker");
|
|
163
|
-
});
|
|
164
|
-
test("get_ci_catalog_resource can filter returned components by name", async () => {
|
|
165
|
-
const result = await callTool("get_ci_catalog_resource", { full_path: "components/docker", component_name: "build" }, env());
|
|
166
|
-
const components = result.data.ciCatalogResource.versions.nodes[0].components.nodes;
|
|
167
|
-
assert.strictEqual(components.length, 1);
|
|
168
|
-
assert.strictEqual(components[0].name, "build");
|
|
169
|
-
assert.strictEqual(components[0].inputs[0].name, "image");
|
|
170
|
-
});
|
|
171
|
-
test("get_ci_catalog_resource rejects empty identity values", async () => {
|
|
172
|
-
await assert.rejects(() => callTool("get_ci_catalog_resource", { full_path: "" }, env()), /full_path|Too small|minLength|invalid/i);
|
|
173
|
-
});
|
|
174
|
-
test("get_ci_catalog_resource rejects multiple identity values", async () => {
|
|
175
|
-
await assert.rejects(() => callTool("get_ci_catalog_resource", { id: "gid://gitlab/Ci::Catalog::Resource/1", full_path: "components/docker" }, env()), /exactly one|id|full_path/i);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,191 +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-ci-lint-test-token";
|
|
6
|
-
const TEST_PROJECT_ID = "123";
|
|
7
|
-
async function callTool(toolName, args, env) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const proc = spawn("node", ["build/index.js"], {
|
|
10
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
11
|
-
env: {
|
|
12
|
-
...process.env,
|
|
13
|
-
...env,
|
|
14
|
-
USE_PIPELINE: "true",
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
let output = "";
|
|
18
|
-
let errorOutput = "";
|
|
19
|
-
proc.stdout?.on("data", (d) => (output += d));
|
|
20
|
-
proc.stderr?.on("data", (d) => (errorOutput += d));
|
|
21
|
-
proc.on("close", code => {
|
|
22
|
-
if (code !== 0) {
|
|
23
|
-
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
24
|
-
}
|
|
25
|
-
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
26
|
-
if (!line)
|
|
27
|
-
return reject(new Error("No JSON output found"));
|
|
28
|
-
try {
|
|
29
|
-
const response = JSON.parse(line);
|
|
30
|
-
if (response.error) {
|
|
31
|
-
reject(response.error);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const content = response.result?.content?.[0]?.text;
|
|
35
|
-
resolve(content ? JSON.parse(content) : response.result);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
proc.stdin?.end(JSON.stringify({
|
|
43
|
-
jsonrpc: "2.0",
|
|
44
|
-
id: 1,
|
|
45
|
-
method: "tools/call",
|
|
46
|
-
params: { name: toolName, arguments: args },
|
|
47
|
-
}) + "\n");
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async function listToolNames(env) {
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
const proc = spawn("node", ["build/index.js"], {
|
|
53
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
54
|
-
env: {
|
|
55
|
-
...process.env,
|
|
56
|
-
...env,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
let output = "";
|
|
60
|
-
let errorOutput = "";
|
|
61
|
-
proc.stdout?.on("data", (d) => (output += d));
|
|
62
|
-
proc.stderr?.on("data", (d) => (errorOutput += d));
|
|
63
|
-
proc.on("close", code => {
|
|
64
|
-
if (code !== 0) {
|
|
65
|
-
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
66
|
-
}
|
|
67
|
-
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
68
|
-
if (!line)
|
|
69
|
-
return reject(new Error("No JSON output found"));
|
|
70
|
-
try {
|
|
71
|
-
const response = JSON.parse(line);
|
|
72
|
-
if (response.error) {
|
|
73
|
-
reject(response.error);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
resolve(response.result.tools.map((tool) => tool.name));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
reject(e);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
proc.stdin?.end(JSON.stringify({
|
|
84
|
-
jsonrpc: "2.0",
|
|
85
|
-
id: 1,
|
|
86
|
-
method: "tools/list",
|
|
87
|
-
params: {},
|
|
88
|
-
}) + "\n");
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
describe("GitLab CI lint tools", () => {
|
|
92
|
-
let mockGitLab;
|
|
93
|
-
let mockGitLabUrl;
|
|
94
|
-
before(async () => {
|
|
95
|
-
const mockPort = await findMockServerPort();
|
|
96
|
-
mockGitLab = new MockGitLabServer({
|
|
97
|
-
port: mockPort,
|
|
98
|
-
validTokens: [MOCK_TOKEN],
|
|
99
|
-
});
|
|
100
|
-
mockGitLab.addMockHandler("post", `/projects/${TEST_PROJECT_ID}/ci/lint`, (req, res) => {
|
|
101
|
-
assert.strictEqual(req.body.content, "stages: [test]\ntest:\n script: echo ok");
|
|
102
|
-
assert.strictEqual(req.body.dry_run, true);
|
|
103
|
-
assert.strictEqual(req.body.include_jobs, true);
|
|
104
|
-
assert.strictEqual(req.body.ref, "main");
|
|
105
|
-
res.json({
|
|
106
|
-
valid: true,
|
|
107
|
-
errors: [],
|
|
108
|
-
warnings: [],
|
|
109
|
-
merged_yaml: "test:\n script: echo ok\n",
|
|
110
|
-
includes: [],
|
|
111
|
-
jobs: [{ name: "test", stage: "test" }],
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/ci/lint`, (req, res) => {
|
|
115
|
-
assert.strictEqual(req.query.content_ref, "feature/test");
|
|
116
|
-
assert.strictEqual(req.query.dry_run, "true");
|
|
117
|
-
assert.strictEqual(req.query.dry_run_ref, "main");
|
|
118
|
-
assert.strictEqual(req.query.include_jobs, "true");
|
|
119
|
-
res.json({
|
|
120
|
-
valid: true,
|
|
121
|
-
errors: [],
|
|
122
|
-
warnings: [],
|
|
123
|
-
merged_yaml: "include-job:\n script: echo included\n",
|
|
124
|
-
includes: [{ type: "local", location: "include.yml" }],
|
|
125
|
-
jobs: [{ name: "include-job", stage: "test" }],
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
await mockGitLab.start();
|
|
129
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
130
|
-
});
|
|
131
|
-
after(async () => {
|
|
132
|
-
await mockGitLab.stop();
|
|
133
|
-
});
|
|
134
|
-
test("validate_ci_lint posts CI YAML content and returns lint result", async () => {
|
|
135
|
-
const result = await callTool("validate_ci_lint", {
|
|
136
|
-
project_id: TEST_PROJECT_ID,
|
|
137
|
-
content: "stages: [test]\ntest:\n script: echo ok",
|
|
138
|
-
dry_run: true,
|
|
139
|
-
include_jobs: true,
|
|
140
|
-
ref: "main",
|
|
141
|
-
}, {
|
|
142
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
143
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
144
|
-
});
|
|
145
|
-
assert.strictEqual(result.valid, true);
|
|
146
|
-
assert.deepStrictEqual(result.errors, []);
|
|
147
|
-
assert.strictEqual(result.jobs[0].name, "test");
|
|
148
|
-
});
|
|
149
|
-
test("validate_ci_lint surfaces invalid lint responses", async () => {
|
|
150
|
-
mockGitLab.addMockHandler("post", `/projects/999/ci/lint`, (req, res) => {
|
|
151
|
-
res.json({
|
|
152
|
-
valid: false,
|
|
153
|
-
errors: ["jobs config should contain at least one visible job"],
|
|
154
|
-
warnings: [],
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
const result = await callTool("validate_ci_lint", {
|
|
158
|
-
project_id: "999",
|
|
159
|
-
content: ".hidden:\n script: echo hidden",
|
|
160
|
-
}, {
|
|
161
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
162
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
163
|
-
});
|
|
164
|
-
assert.strictEqual(result.valid, false);
|
|
165
|
-
assert.deepStrictEqual(result.errors, ["jobs config should contain at least one visible job"]);
|
|
166
|
-
});
|
|
167
|
-
test("validate_project_ci_lint sends GET query parameters", async () => {
|
|
168
|
-
const result = await callTool("validate_project_ci_lint", {
|
|
169
|
-
project_id: TEST_PROJECT_ID,
|
|
170
|
-
content_ref: "feature/test",
|
|
171
|
-
dry_run: true,
|
|
172
|
-
dry_run_ref: "main",
|
|
173
|
-
include_jobs: true,
|
|
174
|
-
}, {
|
|
175
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
176
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
177
|
-
});
|
|
178
|
-
assert.strictEqual(result.valid, true);
|
|
179
|
-
assert.strictEqual(result.includes[0].location, "include.yml");
|
|
180
|
-
assert.strictEqual(result.jobs[0].name, "include-job");
|
|
181
|
-
});
|
|
182
|
-
test("CI lint tools are visible by default in read-only mode", async () => {
|
|
183
|
-
const tools = await listToolNames({
|
|
184
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
185
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
186
|
-
GITLAB_READ_ONLY_MODE: "true",
|
|
187
|
-
});
|
|
188
|
-
assert.ok(tools.includes("validate_ci_lint"));
|
|
189
|
-
assert.ok(tools.includes("validate_project_ci_lint"));
|
|
190
|
-
});
|
|
191
|
-
});
|