@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,32 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, test } from "node:test";
3
- import { buildBulkPublishDraftNotesBody, needsGitLab19_2BulkPublish, } from "../../utils/bulk-publish-options.js";
4
- describe("When buildBulkPublishDraftNotesBody runs", () => {
5
- describe("with no-op defaults", () => {
6
- test("should omit internal false and empty note", () => {
7
- assert.deepEqual(buildBulkPublishDraftNotesBody({ internal: false, note: "" }), {});
8
- });
9
- });
10
- describe("with meaningful 19.2 fields", () => {
11
- test("should keep reviewer_state, note, and internal true", () => {
12
- assert.deepEqual(buildBulkPublishDraftNotesBody({
13
- reviewer_state: "reviewed",
14
- note: "LGTM",
15
- internal: true,
16
- }), { reviewer_state: "reviewed", note: "LGTM", internal: true });
17
- });
18
- });
19
- });
20
- describe("When needsGitLab19_2BulkPublish runs", () => {
21
- describe("with an empty body", () => {
22
- test("should return false", () => {
23
- assert.equal(needsGitLab19_2BulkPublish({}), false);
24
- assert.equal(needsGitLab19_2BulkPublish(buildBulkPublishDraftNotesBody({ internal: false })), false);
25
- });
26
- });
27
- describe("with a non-empty body", () => {
28
- test("should return true", () => {
29
- assert.equal(needsGitLab19_2BulkPublish({ reviewer_state: "reviewed" }), true);
30
- });
31
- });
32
- });
@@ -1,35 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
- import { createDownloadToken, decryptDownloadToken } from "../../utils/download-token.js";
4
- describe("download token helpers", () => {
5
- test("round-trips auth, api URL, and resource binding", () => {
6
- const token = createDownloadToken("Authorization", "Bearer glpat-example-token", "https://gitlab.example.com/api/v4", {
7
- type: "attachment",
8
- params: { project_id: "group/project", secret: "abc", filename: "file.txt" },
9
- });
10
- const decrypted = decryptDownloadToken(token);
11
- assert.deepStrictEqual(decrypted, {
12
- header: "Authorization",
13
- token: "Bearer glpat-example-token",
14
- apiUrl: "https://gitlab.example.com/api/v4",
15
- resourceType: "attachment",
16
- resourceParams: { project_id: "group/project", secret: "abc", filename: "file.txt" },
17
- });
18
- });
19
- test("returns null for invalid tokens", () => {
20
- assert.strictEqual(decryptDownloadToken("not-a-valid-token"), null);
21
- });
22
- test("returns null for expired tokens", () => {
23
- const originalNow = Date.now;
24
- const issuedAt = 1_700_000_000_000;
25
- try {
26
- Date.now = () => issuedAt;
27
- const token = createDownloadToken("Private-Token", "glpat-example-token");
28
- Date.now = () => issuedAt + 301_000;
29
- assert.strictEqual(decryptDownloadToken(token), null);
30
- }
31
- finally {
32
- Date.now = originalNow;
33
- }
34
- });
35
- });
@@ -1,46 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
- import { getForwardedPublicBaseUrl, getForwardedRequestHost } from "../../utils/forwarded-public-base-url.js";
4
- function req(headers) {
5
- return { headers };
6
- }
7
- describe("getForwardedPublicBaseUrl", () => {
8
- test("returns undefined unless proxy headers are trusted", () => {
9
- assert.strictEqual(getForwardedPublicBaseUrl(req({ "x-forwarded-proto": "https", "x-forwarded-host": "gitlab.example.com" }), false), undefined);
10
- });
11
- test("builds a public base URL from forwarded headers", () => {
12
- assert.strictEqual(getForwardedPublicBaseUrl(req({
13
- "x-forwarded-proto": "https",
14
- "x-forwarded-host": "mcp.example.com",
15
- "x-forwarded-prefix": "/gitlab-mcp/",
16
- }), true), "https://mcp.example.com/gitlab-mcp");
17
- });
18
- test("uses the last comma-separated forwarded value", () => {
19
- assert.strictEqual(getForwardedPublicBaseUrl(req({
20
- "x-forwarded-proto": "http, https",
21
- "x-forwarded-host": "internal, mcp.example.com",
22
- }), true), "https://mcp.example.com");
23
- });
24
- test("parses quoted Forwarded header values", () => {
25
- assert.strictEqual(getForwardedPublicBaseUrl(req({
26
- forwarded: 'for=192.0.2.43; proto="https"; host="mcp.example.com"',
27
- "x-forwarded-prefix": "/gitlab-mcp",
28
- }), true), "https://mcp.example.com/gitlab-mcp");
29
- });
30
- test("rejects unsafe host and prefix values", () => {
31
- assert.strictEqual(getForwardedPublicBaseUrl(req({ "x-forwarded-proto": "https", "x-forwarded-host": "bad/host" }), true), undefined);
32
- assert.strictEqual(getForwardedPublicBaseUrl(req({
33
- "x-forwarded-proto": "https",
34
- "x-forwarded-host": "mcp.example.com",
35
- "x-forwarded-prefix": "//evil",
36
- }), true), "https://mcp.example.com");
37
- });
38
- });
39
- describe("getForwardedRequestHost", () => {
40
- test("returns undefined unless proxy headers are trusted", () => {
41
- assert.strictEqual(getForwardedRequestHost(req({ "x-forwarded-host": "mcp.example.com" }), false), undefined);
42
- });
43
- test("returns the forwarded host when proxy headers are trusted", () => {
44
- assert.strictEqual(getForwardedRequestHost(req({ "x-forwarded-host": "mcp.example.com" }), true), "mcp.example.com");
45
- });
46
- });
@@ -1,32 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, test } from "node:test";
3
- import { parseGitLabVersionApiResponse } from "../../utils/gitlab-instance-version.js";
4
- describe("When parseGitLabVersionApiResponse runs", () => {
5
- describe("with a full GitLab /version payload", () => {
6
- test("should return version, revision, and enterprise", () => {
7
- assert.deepEqual(parseGitLabVersionApiResponse({
8
- version: "18.3.1-ee",
9
- revision: "abc1234",
10
- enterprise: true,
11
- }), {
12
- version: "18.3.1-ee",
13
- revision: "abc1234",
14
- enterprise: true,
15
- });
16
- });
17
- });
18
- describe("with only a version field", () => {
19
- test("should return version without optional fields", () => {
20
- assert.deepEqual(parseGitLabVersionApiResponse({ version: "17.5.0" }), {
21
- version: "17.5.0",
22
- });
23
- });
24
- });
25
- describe("with invalid payloads", () => {
26
- test("should return null", () => {
27
- assert.equal(parseGitLabVersionApiResponse(null), null);
28
- assert.equal(parseGitLabVersionApiResponse({}), null);
29
- assert.equal(parseGitLabVersionApiResponse({ version: 18 }), null);
30
- });
31
- });
32
- });
@@ -1,74 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, test } from "node:test";
3
- import { assertGitLabVersionAtLeast, isGitLabVersionAtLeast, parseGitLabVersion, } from "../../utils/gitlab-version-gate.js";
4
- function versionFetcher(version) {
5
- return async () => version;
6
- }
7
- function bulkPublishRequirement() {
8
- return {
9
- major: 19,
10
- minor: 2,
11
- feature: "reviewer_state, note, and internal on bulk_publish_draft_notes",
12
- retryHint: "Omit reviewer_state, note, and internal, then retry.",
13
- };
14
- }
15
- describe("When parseGitLabVersion runs", () => {
16
- describe("with a release suffix", () => {
17
- test("should parse major.minor.patch from ee builds", () => {
18
- assert.deepEqual(parseGitLabVersion("19.2.0-ee"), {
19
- major: 19,
20
- minor: 2,
21
- patch: 0,
22
- });
23
- });
24
- });
25
- describe("with a malformed string", () => {
26
- test("should return null", () => {
27
- assert.equal(parseGitLabVersion("unknown"), null);
28
- assert.equal(parseGitLabVersion(""), null);
29
- });
30
- });
31
- });
32
- describe("When isGitLabVersionAtLeast compares versions", () => {
33
- describe("with a version at or above the floor", () => {
34
- test("should return true", () => {
35
- assert.equal(isGitLabVersionAtLeast("19.2.0-ee", 19, 2), true);
36
- assert.equal(isGitLabVersionAtLeast("19.3.1", 19, 2), true);
37
- assert.equal(isGitLabVersionAtLeast("20.0.0", 19, 2), true);
38
- });
39
- });
40
- describe("with a version below the floor", () => {
41
- test("should return false", () => {
42
- assert.equal(isGitLabVersionAtLeast("19.1.9-ee", 19, 2), false);
43
- assert.equal(isGitLabVersionAtLeast("17.5.0", 19, 2), false);
44
- });
45
- });
46
- describe("with an unparseable version", () => {
47
- test("should return null", () => {
48
- assert.equal(isGitLabVersionAtLeast("not-a-version", 19, 2), null);
49
- });
50
- });
51
- });
52
- describe("When assertGitLabVersionAtLeast runs", () => {
53
- describe("with an older instance version", () => {
54
- test("should throw a retryable error", async () => {
55
- await assert.rejects(() => assertGitLabVersionAtLeast(bulkPublishRequirement(), versionFetcher("17.5.0-ee")), (error) => {
56
- assert.ok(error instanceof Error);
57
- assert.match(error.message, /GitLab 19\.2\+/);
58
- assert.match(error.message, /17\.5\.0-ee/);
59
- assert.match(error.message, /Omit reviewer_state/);
60
- return true;
61
- });
62
- });
63
- });
64
- describe("with a new enough instance version", () => {
65
- test("should resolve without throwing", async () => {
66
- await assertGitLabVersionAtLeast(bulkPublishRequirement(), versionFetcher("19.2.0-ee"));
67
- });
68
- });
69
- describe("with an unknown instance version", () => {
70
- test("should fail open and resolve", async () => {
71
- await assertGitLabVersionAtLeast(bulkPublishRequirement(), versionFetcher(null));
72
- });
73
- });
74
- });
@@ -1,168 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, test } from "node:test";
3
- import { graphqlQueryContainsWriteOperation, graphqlQueryContainsDeleteOperation, } from "../../utils/graphql-query.js";
4
- describe("When graphqlQueryContainsWriteOperation runs", () => {
5
- describe("with read-only GraphQL documents", () => {
6
- test("should allow explicit query operations", () => {
7
- assert.equal(graphqlQueryContainsWriteOperation("query { project(fullPath: \"g/p\") { id } }"), false);
8
- });
9
- test("should allow shorthand query operations", () => {
10
- assert.equal(graphqlQueryContainsWriteOperation("{ project { id } }"), false);
11
- });
12
- test("should ignore mutation text inside comments", () => {
13
- assert.equal(graphqlQueryContainsWriteOperation("# mutation destroy\nquery { project { id } }"), false);
14
- });
15
- test("should ignore mutation text inside string literals", () => {
16
- assert.equal(graphqlQueryContainsWriteOperation('query { search(query: "mutation") { nodes { id } } }'), false);
17
- });
18
- test("should ignore escaped triple quotes inside block strings", () => {
19
- assert.equal(graphqlQueryContainsWriteOperation('query { project(fullPath: """contains \\""" not a mutation""") { id } }'), false);
20
- });
21
- test("should not treat subscription field names as write operations", () => {
22
- assert.equal(graphqlQueryContainsWriteOperation("query { project { id }, subscription { count } }"), false);
23
- });
24
- test("should allow query with operation name 'mutation'", () => {
25
- assert.equal(graphqlQueryContainsWriteOperation("query mutation { project { id } }"), false);
26
- });
27
- test("should allow query with operation name 'subscription'", () => {
28
- assert.equal(graphqlQueryContainsWriteOperation("query subscription { project { id } }"), false);
29
- });
30
- });
31
- describe("with write GraphQL documents", () => {
32
- test("should detect mutation operations", () => {
33
- assert.equal(graphqlQueryContainsWriteOperation('mutation { destroyProject(input: { projectId: "gid://gitlab/Project/1" }) { errors } }'), true);
34
- });
35
- test("should detect subscription operations", () => {
36
- assert.equal(graphqlQueryContainsWriteOperation("subscription { mergeRequestCreated { id } }"), true);
37
- });
38
- test("should detect write operations in multi-operation documents", () => {
39
- assert.equal(graphqlQueryContainsWriteOperation("query A { a } mutation B { b }"), true);
40
- });
41
- test("should detect semicolon-separated write operations", () => {
42
- assert.equal(graphqlQueryContainsWriteOperation("query A { a }; mutation B { b }"), true);
43
- });
44
- test("should detect comma-prefixed write operations", () => {
45
- assert.equal(graphqlQueryContainsWriteOperation(",mutation { destroyProject(input: { projectId: 1 }) { errors } }"), true);
46
- });
47
- test("should detect comma-separated write operations", () => {
48
- assert.equal(graphqlQueryContainsWriteOperation("query A { a }, mutation B { b }"), true);
49
- });
50
- });
51
- });
52
- describe("When graphqlQueryContainsDeleteOperation runs", () => {
53
- describe("with non-delete documents", () => {
54
- test("should allow plain queries even when they mention delete words", () => {
55
- assert.equal(graphqlQueryContainsDeleteOperation("query { project { removeSourceBranchAfterMerge } }"), false);
56
- });
57
- test("should allow non-delete mutations", () => {
58
- assert.equal(graphqlQueryContainsDeleteOperation('mutation { issueSetSeverity(input: { severity: HIGH }) { errors } }'), false);
59
- });
60
- test("should not count delete-like argument names inside parentheses", () => {
61
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { mergeRequestUpdate(input: { removeSourceBranch: true }) { errors } }"), false);
62
- });
63
- test("should not count delete-like fields nested below the mutation root", () => {
64
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { issueSetLabels(input: {}) { issue { canBeDeleted } } }"), false);
65
- });
66
- test("should ignore delete text inside comments", () => {
67
- assert.equal(graphqlQueryContainsDeleteOperation("# issueDelete\nmutation { issueSetLabels { errors } }"), false);
68
- });
69
- test("should ignore delete text inside string literals", () => {
70
- assert.equal(graphqlQueryContainsDeleteOperation('mutation { createNote(input: { body: "projectDelete" }) { errors } }'), false);
71
- });
72
- });
73
- describe("with delete documents", () => {
74
- test("should detect delete mutation fields", () => {
75
- assert.equal(graphqlQueryContainsDeleteOperation('mutation { issueDelete(input: { projectPath: "g/p", iid: "1" }) { errors } }'), true);
76
- });
77
- test("should detect destroy mutation fields", () => {
78
- assert.equal(graphqlQueryContainsDeleteOperation('mutation { destroyBoard(input: { id: "gid://gitlab/Board/1" }) { errors } }'), true);
79
- });
80
- test("should detect remove mutation fields", () => {
81
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { awardEmojiRemove(input: {}) { errors } }"), true);
82
- });
83
- test("should detect aliased delete mutation fields", () => {
84
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { a: issueDelete(input: {}) { errors } }"), true);
85
- });
86
- test("should detect delete mutations in multi-operation documents", () => {
87
- assert.equal(graphqlQueryContainsDeleteOperation("query A { project { id } } mutation B { labelDelete(input: {}) { errors } }"), true);
88
- });
89
- test("should detect delete mutations with variable definitions", () => {
90
- assert.equal(graphqlQueryContainsDeleteOperation("mutation DeleteIssue($id: IssueID!) { issueDelete(input: { id: $id }) { errors } }"), true);
91
- });
92
- test("should detect comma-prefixed delete mutations", () => {
93
- assert.equal(graphqlQueryContainsDeleteOperation(', mutation M { issueDelete(input: { iid: "1" }) { id } }'), true);
94
- });
95
- test("should detect comma-prefixed delete mutations without whitespace", () => {
96
- assert.equal(graphqlQueryContainsDeleteOperation(',mutation{issueDelete(input:{iid:"1"}){id}}'), true);
97
- });
98
- test("should detect delete mutations after a comma-separated query", () => {
99
- assert.equal(graphqlQueryContainsDeleteOperation("query HealthCheck { x }, mutation M { issueDelete(input: {}) { id } }"), true);
100
- });
101
- test("should allow comma-separated queries", () => {
102
- assert.equal(graphqlQueryContainsDeleteOperation("query A { a }, query B { b }"), false);
103
- });
104
- test("should conservatively block top-level fragment spreads in mutations", () => {
105
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { ...f } fragment f on Mutation { issueDelete(input: {}) { errors } }"), true);
106
- });
107
- });
108
- describe("with destructive mutations that are not named delete", () => {
109
- test("should detect environmentStop", () => {
110
- assert.equal(graphqlQueryContainsDeleteOperation('mutation { environmentStop(input: { environmentId: "gid://gitlab/Environment/1" }) { errors } }'), true);
111
- });
112
- test("should detect pipelineCancel", () => {
113
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { pipelineCancel(input: {}) { errors } }"), true);
114
- });
115
- test("should detect clusterAgentTokenRevoke", () => {
116
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { clusterAgentTokenRevoke(input: {}) { errors } }"), true);
117
- });
118
- test("should detect jobUnschedule", () => {
119
- // GitLab moves the scheduled job to manual and clears its scheduled state, so it
120
- // is a teardown action even though no teardown verb is part of its name.
121
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { jobUnschedule(input: {}) { errors } }"), true);
122
- });
123
- test("should detect aliased destructive mutations", () => {
124
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { s: environmentStop(input: {}) { errors } }"), true);
125
- });
126
- test("should not treat an alias as a destructive mutation field", () => {
127
- for (const query of [
128
- "mutation { stop: issueSetSeverity(input: {}) { errors } }",
129
- "mutation { revoke: issueSetSeverity(input: {}) { errors } }",
130
- "mutation { terminate: updateIssue(input: {}) { issue { id } } }",
131
- ]) {
132
- assert.equal(graphqlQueryContainsDeleteOperation(query), false, query);
133
- }
134
- });
135
- test("should not treat a spaced or comma-separated alias as a destructive field", () => {
136
- for (const query of [
137
- "mutation { stop : issueSetSeverity(input: {}) { errors } }",
138
- "mutation { revoke,: issueSetSeverity(input: {}) { errors } }",
139
- "mutation { terminate\n: updateIssue(input: {}) { issue { id } } }",
140
- ]) {
141
- assert.equal(graphqlQueryContainsDeleteOperation(query), false, query);
142
- }
143
- });
144
- test("should still detect a destructive field after a spaced alias", () => {
145
- assert.equal(graphqlQueryContainsDeleteOperation("mutation { harmless : environmentStop(input: {}) { errors } }"), true);
146
- });
147
- test("should still detect a destructive field hidden behind a harmless alias", () => {
148
- for (const query of [
149
- "mutation { harmless: environmentStop(input: {}) { errors } }",
150
- "mutation { step: pipelineCancel(input: {}) { errors } }",
151
- ]) {
152
- assert.equal(graphqlQueryContainsDeleteOperation(query), true, query);
153
- }
154
- });
155
- test("should detect destructive mutations in multi-operation documents", () => {
156
- assert.equal(graphqlQueryContainsDeleteOperation("query A { project { id } } mutation B { environmentStop(input: {}) { errors } }"), true);
157
- });
158
- test("should still allow mutations without a destructive verb", () => {
159
- for (const query of [
160
- "mutation { issueMove(input: {}) { errors } }",
161
- "mutation { mergeRequestMerge(input: {}) { errors } }",
162
- "mutation { todoMarkDone(input: {}) { errors } }",
163
- ]) {
164
- assert.equal(graphqlQueryContainsDeleteOperation(query), false, query);
165
- }
166
- });
167
- });
168
- });
@@ -1,104 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { assertSafeRelativePath, openSafeOutputWriteStream, readSafeExistingFile, resolveSafeExistingPath, resolveSafeOutputDir, resolveSafeOutputFile, } from "../../utils/helpers.js";
7
- describe("assertSafeRelativePath", () => {
8
- test("allows relative paths", () => {
9
- assert.strictEqual(assertSafeRelativePath("uploads"), "uploads");
10
- assert.strictEqual(assertSafeRelativePath("uploads/nested"), path.normalize("uploads/nested"));
11
- });
12
- test("rejects absolute paths", () => {
13
- assert.throws(() => assertSafeRelativePath("/etc/passwd", "file_path"), /traversal/);
14
- });
15
- test("rejects parent-directory traversal", () => {
16
- assert.throws(() => assertSafeRelativePath("../../../tmp", "local_path"), /traversal/);
17
- assert.throws(() => assertSafeRelativePath("foo/../../etc", "local_path"), /traversal/);
18
- });
19
- });
20
- describe("resolveSafeExistingPath / resolveSafeOutputDir", () => {
21
- let base;
22
- test("setup base dir", () => {
23
- base = fs.mkdtempSync(path.join(os.tmpdir(), "safe-path-"));
24
- });
25
- test("resolves an existing file inside the base", () => {
26
- const file = path.join(base, "ok.txt");
27
- fs.writeFileSync(file, "hello");
28
- const resolved = resolveSafeExistingPath("ok.txt", "file_path", base);
29
- assert.strictEqual(resolved, fs.realpathSync(file));
30
- });
31
- test("rejects symlink file escape on read", () => {
32
- const target = path.join(os.tmpdir(), `outside-target-${process.pid}.txt`);
33
- fs.writeFileSync(target, "secret");
34
- fs.symlinkSync(target, path.join(base, "link.txt"));
35
- try {
36
- assert.throws(() => resolveSafeExistingPath("link.txt", "file_path", base), /symbolic links|escapes/);
37
- }
38
- finally {
39
- fs.unlinkSync(target);
40
- }
41
- });
42
- test("rejects symlink directory escape on write", () => {
43
- fs.symlinkSync(os.tmpdir(), path.join(base, "escape-dir"));
44
- assert.throws(() => resolveSafeOutputDir("escape-dir", "local_path", base), /symbolic links|escapes/);
45
- });
46
- test("creates nested output dirs that stay inside the base", () => {
47
- const out = resolveSafeOutputDir(path.join("artifacts", "run-1"), "local_path", base);
48
- const baseReal = fs.realpathSync(base);
49
- const rel = path.relative(baseReal, out);
50
- assert.ok(rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel)));
51
- assert.ok(fs.statSync(out).isDirectory());
52
- });
53
- test("resolveSafeOutputFile rejects destination file symlink", () => {
54
- const outDir = path.join(base, "out");
55
- fs.mkdirSync(outDir, { recursive: true });
56
- const target = path.join(os.tmpdir(), `outside-write-${process.pid}.txt`);
57
- fs.writeFileSync(target, "before");
58
- fs.symlinkSync(target, path.join(outDir, "payload.bin"));
59
- try {
60
- assert.throws(() => resolveSafeOutputFile("payload.bin", "out", "local_path", base), /symbolic links/);
61
- }
62
- finally {
63
- fs.unlinkSync(target);
64
- }
65
- });
66
- test("resolveSafeOutputFile returns contained path for new files", () => {
67
- const dest = resolveSafeOutputFile("fresh.bin", "downloads", "local_path", base);
68
- assert.ok(dest.startsWith(fs.realpathSync(base) + path.sep));
69
- assert.ok(dest.endsWith(`${path.sep}fresh.bin`));
70
- });
71
- test("anchors to cwd snapshot when baseDir is omitted", () => {
72
- const nested = path.join(base, "anchored");
73
- fs.mkdirSync(nested, { recursive: true });
74
- const file = path.join(nested, "data.txt");
75
- fs.writeFileSync(file, "anchored");
76
- const originalCwd = process.cwd();
77
- try {
78
- process.chdir(nested);
79
- const resolved = resolveSafeExistingPath("data.txt", "file_path");
80
- assert.strictEqual(resolved, fs.realpathSync(file));
81
- }
82
- finally {
83
- process.chdir(originalCwd);
84
- }
85
- });
86
- test("readSafeExistingFile reads without returning a reusable path", () => {
87
- const file = path.join(base, "inline.txt");
88
- fs.writeFileSync(file, "payload");
89
- const { buffer, basename } = readSafeExistingFile("inline.txt", "file_path", base);
90
- assert.strictEqual(buffer.toString(), "payload");
91
- assert.strictEqual(basename, "inline.txt");
92
- });
93
- test("openSafeOutputWriteStream writes without a separate createWriteStream call", async () => {
94
- const { stream, path: dest } = openSafeOutputWriteStream("streamed.bin", "downloads", "local_path", base);
95
- await new Promise((resolve, reject) => {
96
- stream.on("error", reject);
97
- stream.end("streamed", () => resolve());
98
- });
99
- assert.strictEqual(fs.readFileSync(dest, "utf8"), "streamed");
100
- });
101
- test("cleanup base dir", () => {
102
- fs.rmSync(base, { recursive: true, force: true });
103
- });
104
- });
@@ -1,91 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, test } from "node:test";
3
- import { applyJmespathFilter, applyJmespathToToolResult, getJmespathSyntaxError, omitJmespathArgument, readJmespathExpression, shouldApplyJmespathFilter, } from "../../utils/jmespath-tool-result.js";
4
- describe("jmespath tool result helpers", () => {
5
- test("readJmespathExpression trims and rejects blank values", () => {
6
- assert.equal(readJmespathExpression({ jmespath: " [].title " }), "[].title");
7
- assert.equal(readJmespathExpression({ jmespath: " " }), undefined);
8
- assert.equal(readJmespathExpression({ jmespath: 1 }), undefined);
9
- });
10
- test("omitJmespathArgument removes MCP-only key", () => {
11
- assert.deepEqual(omitJmespathArgument({ project_id: "1", jmespath: "[].id" }), {
12
- project_id: "1",
13
- });
14
- });
15
- test("applyJmespathFilter projects array fields", () => {
16
- const data = [
17
- { title: "a", description: "long" },
18
- { title: "b", description: "longer" },
19
- ];
20
- assert.deepEqual(applyJmespathFilter(data, "[].title"), ["a", "b"]);
21
- });
22
- test("applyJmespathToToolResult filters JSON text content", () => {
23
- const result = applyJmespathToToolResult({
24
- content: [
25
- {
26
- type: "text",
27
- text: JSON.stringify([{ title: "mr-one", iid: 1 }]),
28
- },
29
- ],
30
- }, "[].title");
31
- assert.equal(result.content[0].text, JSON.stringify(["mr-one"]));
32
- });
33
- test("applyJmespathToToolResult applies maskValue before JMESPath", () => {
34
- const result = applyJmespathToToolResult({
35
- content: [
36
- {
37
- type: "text",
38
- text: JSON.stringify([{ title: "ProjectOneSecret" }]),
39
- },
40
- ],
41
- }, "[].starts_with(title, `ProjectOne`)", {
42
- maskValue: value => {
43
- if (!Array.isArray(value))
44
- return value;
45
- return value.map(entry => entry && typeof entry === "object" && "title" in entry
46
- ? { ...entry, title: "[one]" }
47
- : entry);
48
- },
49
- });
50
- assert.deepEqual(JSON.parse(result.content[0].text), [false]);
51
- });
52
- test("shouldApplyJmespathFilter is false for isError and explicit skip", () => {
53
- const errorResult = {
54
- content: [{ type: "text", text: 'Unknown category "foo"' }],
55
- isError: true,
56
- };
57
- assert.equal(shouldApplyJmespathFilter(errorResult, "[].title"), false);
58
- assert.equal(shouldApplyJmespathFilter({ content: [{ type: "text", text: "requires confirmation" }] }, "[].title", { skipJmespath: true }), false);
59
- assert.equal(shouldApplyJmespathFilter({ content: [{ type: "text", text: "[]" }] }, "[].title"), true);
60
- });
61
- test("applyJmespathToToolResult preserves isError tool results", () => {
62
- const original = {
63
- content: [{ type: "text", text: 'Unknown category "foo"' }],
64
- isError: true,
65
- };
66
- assert.deepEqual(applyJmespathToToolResult(original, "[].title"), original);
67
- });
68
- test("applyJmespathToToolResult preserves approval-style plain text when skipJmespath", () => {
69
- const original = {
70
- content: [
71
- {
72
- type: "text",
73
- text: 'Tool "create_issue" requires confirmation. Re-call with _confirmed: true to proceed.',
74
- },
75
- ],
76
- };
77
- assert.deepEqual(applyJmespathToToolResult(original, "[].title", { skipJmespath: true }), original);
78
- });
79
- test("applyJmespathToToolResult passes non-JSON success text through unchanged", () => {
80
- const original = { content: [{ type: "text", text: "Created pipeline #1 for main." }] };
81
- assert.deepEqual(applyJmespathToToolResult(original, "id"), original);
82
- });
83
- test("applyJmespathToToolResult returns the original result when evaluation fails", () => {
84
- const original = { content: [{ type: "text", text: JSON.stringify({ title: 1 }) }] };
85
- assert.deepEqual(applyJmespathToToolResult(original, "starts_with(title, `a`)"), original);
86
- });
87
- test("getJmespathSyntaxError rejects invalid expressions before execution", () => {
88
- assert.match(getJmespathSyntaxError("[[[") ?? "", /Invalid jmespath expression/);
89
- assert.equal(getJmespathSyntaxError("[].title"), undefined);
90
- });
91
- });