@zereight/mcp-gitlab 2.1.67 → 2.1.69
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 +8 -4
- package/README.md +14 -5
- package/README.pt-BR.md +589 -0
- package/README.zh-CN.md +8 -4
- package/build/cli/args.js +298 -0
- package/build/cli/compact-mcp-result.js +87 -0
- package/build/cli/curated.js +243 -0
- package/build/cli/exposure.js +72 -0
- package/build/cli/help.js +108 -0
- package/build/cli/output.js +65 -0
- package/build/cli/replay-command.js +53 -0
- package/build/cli/router.js +158 -0
- package/build/cli/tables.js +117 -0
- package/build/cli-boolean-flags.js +38 -0
- package/build/cli-command.js +14 -4
- package/build/config.js +30 -7
- package/build/index.js +329 -44
- package/build/oauth.js +93 -10
- package/build/schemas.js +187 -0
- package/build/scripts/generate-tool-docs.js +7 -1
- package/build/scripts/tool-coverage/coverage.js +2 -0
- package/build/test/cli/args.test.js +175 -0
- package/build/test/cli/boolean-flags.test.js +106 -0
- package/build/test/cli/compact-mcp-result.test.js +93 -0
- package/build/test/cli/exposure.test.js +104 -0
- package/build/test/cli/load-config-snapshot.js +5 -0
- package/build/test/cli/output.test.js +74 -0
- package/build/test/cli/replay-command.test.js +37 -0
- package/build/test/cli/router.test.js +183 -0
- package/build/test/oauth-device-flow-tests.js +10 -0
- package/build/test/oauth-startup.test.js +204 -0
- package/build/test/test-dynamic-project-scope.js +162 -0
- package/build/test/test-geteffectiveprojectid.js +4 -2
- package/build/test/test-permission-mode.js +87 -0
- package/build/test/test-snippets.js +735 -0
- package/build/test/test-toolset-filtering.js +3 -0
- package/build/tools/denied-regex.js +38 -0
- package/build/tools/registry.js +42 -1
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { compactMcpToolResult } from "../../cli/compact-mcp-result.js";
|
|
4
|
+
function textResult(text) {
|
|
5
|
+
return { content: [{ type: "text", text }] };
|
|
6
|
+
}
|
|
7
|
+
describe("When compactMcpToolResult wraps an MCP tool reply", () => {
|
|
8
|
+
describe("with compact mode disabled", () => {
|
|
9
|
+
it("should return the original result", () => {
|
|
10
|
+
const result = textResult("[]");
|
|
11
|
+
const compacted = compactMcpToolResult({
|
|
12
|
+
result,
|
|
13
|
+
enabled: false,
|
|
14
|
+
maxChars: 1,
|
|
15
|
+
toolName: "list_issues",
|
|
16
|
+
args: { project_id: "1" },
|
|
17
|
+
});
|
|
18
|
+
assert.equal(compacted, result);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("with a small payload", () => {
|
|
22
|
+
it("should leave the result alone", () => {
|
|
23
|
+
const result = textResult('{"iid":1}');
|
|
24
|
+
const compacted = compactMcpToolResult({
|
|
25
|
+
result,
|
|
26
|
+
enabled: true,
|
|
27
|
+
maxChars: 4000,
|
|
28
|
+
toolName: "get_issue",
|
|
29
|
+
args: { project_id: "1", issue_iid: 1 },
|
|
30
|
+
});
|
|
31
|
+
assert.equal(compacted, result);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe("with a long issue list", () => {
|
|
35
|
+
it("should keep a preview and a CLI replay command", () => {
|
|
36
|
+
const issues = Array.from({ length: 20 }, (_, index) => ({ iid: index + 1, title: "x".repeat(80) }));
|
|
37
|
+
const compacted = compactMcpToolResult({
|
|
38
|
+
result: textResult(JSON.stringify(issues)),
|
|
39
|
+
enabled: true,
|
|
40
|
+
maxChars: 200,
|
|
41
|
+
toolName: "list_issues",
|
|
42
|
+
args: { project_id: "123", state: "opened" },
|
|
43
|
+
});
|
|
44
|
+
assert.ok(isRecord(compacted));
|
|
45
|
+
assert.equal(Object.prototype.hasOwnProperty.call(compacted, "structuredContent"), false);
|
|
46
|
+
const content = compacted.content;
|
|
47
|
+
assert.ok(Array.isArray(content));
|
|
48
|
+
const block = content[0];
|
|
49
|
+
assert.ok(isRecord(block) && typeof block.text === "string");
|
|
50
|
+
const payload = JSON.parse(block.text);
|
|
51
|
+
assert.ok(isRecord(payload));
|
|
52
|
+
assert.equal(payload.compact, true);
|
|
53
|
+
assert.equal(payload.tool, "list_issues");
|
|
54
|
+
assert.equal(payload.items_total, 20);
|
|
55
|
+
assert.ok(Array.isArray(payload.preview));
|
|
56
|
+
assert.equal(payload.preview.length, 5);
|
|
57
|
+
assert.equal(payload.cli, "zereight-mcp-gitlab tool list_issues --project-id 123 --state opened");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("with structuredContent on a large payload", () => {
|
|
61
|
+
it("should drop structuredContent so the full object cannot leak", () => {
|
|
62
|
+
const issues = Array.from({ length: 20 }, (_, index) => ({ iid: index + 1, title: "x".repeat(80) }));
|
|
63
|
+
const compacted = compactMcpToolResult({
|
|
64
|
+
result: {
|
|
65
|
+
content: [{ type: "text", text: JSON.stringify(issues) }],
|
|
66
|
+
structuredContent: issues,
|
|
67
|
+
},
|
|
68
|
+
enabled: true,
|
|
69
|
+
maxChars: 200,
|
|
70
|
+
toolName: "list_issues",
|
|
71
|
+
args: { project_id: "1" },
|
|
72
|
+
});
|
|
73
|
+
assert.ok(isRecord(compacted));
|
|
74
|
+
assert.equal(Object.prototype.hasOwnProperty.call(compacted, "structuredContent"), false);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe("with an error result", () => {
|
|
78
|
+
it("should not compact", () => {
|
|
79
|
+
const result = { content: [{ type: "text", text: "boom".repeat(500) }], isError: true };
|
|
80
|
+
const compacted = compactMcpToolResult({
|
|
81
|
+
result,
|
|
82
|
+
enabled: true,
|
|
83
|
+
maxChars: 10,
|
|
84
|
+
toolName: "list_issues",
|
|
85
|
+
args: {},
|
|
86
|
+
});
|
|
87
|
+
assert.equal(compacted, result);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
function isRecord(value) {
|
|
92
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
93
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { exposureRefusalMessage, isToolExposed, parseToolNameSet } from "../../cli/exposure.js";
|
|
4
|
+
import { compileDeniedToolsRegex } from "../../tools/denied-regex.js";
|
|
5
|
+
import { parseEnabledToolsets } from "../../tools/registry.js";
|
|
6
|
+
const ISSUES = parseEnabledToolsets("issues");
|
|
7
|
+
const EMPTY = new Set();
|
|
8
|
+
function exposure(overrides) {
|
|
9
|
+
return {
|
|
10
|
+
toolName: overrides.toolName,
|
|
11
|
+
enabledToolsets: overrides.enabledToolsets ?? ISSUES,
|
|
12
|
+
individuallyEnabledTools: overrides.individuallyEnabledTools ?? EMPTY,
|
|
13
|
+
featureFlagOverrides: overrides.featureFlagOverrides ?? EMPTY,
|
|
14
|
+
deniedRegex: overrides.deniedRegex,
|
|
15
|
+
hiddenTools: overrides.hiddenTools ?? EMPTY,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
describe("When isToolExposed applies MCP filters", () => {
|
|
19
|
+
describe("with a tool in the enabled toolset", () => {
|
|
20
|
+
it("should expose list_issues", () => {
|
|
21
|
+
assert.equal(isToolExposed(exposure({ toolName: "list_issues" })), true);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe("with a tool outside the enabled toolsets", () => {
|
|
25
|
+
it("should hide list_pipelines", () => {
|
|
26
|
+
assert.equal(isToolExposed(exposure({ toolName: "list_pipelines" })), false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("with GITLAB_TOOLS", () => {
|
|
30
|
+
it("should expose an individually enabled tool", () => {
|
|
31
|
+
assert.equal(isToolExposed(exposure({
|
|
32
|
+
toolName: "list_pipelines",
|
|
33
|
+
individuallyEnabledTools: new Set(["list_pipelines"]),
|
|
34
|
+
})), true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe("with a legacy feature-flag override", () => {
|
|
38
|
+
it("should expose the overridden wiki tool", () => {
|
|
39
|
+
assert.equal(isToolExposed(exposure({
|
|
40
|
+
toolName: "list_wiki_pages",
|
|
41
|
+
featureFlagOverrides: new Set(["list_wiki_pages"]),
|
|
42
|
+
})), true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("with GITLAB_DENIED_TOOLS_REGEX", () => {
|
|
46
|
+
it("should hide a matching tool even when the toolset is enabled", () => {
|
|
47
|
+
assert.equal(isToolExposed(exposure({
|
|
48
|
+
toolName: "list_issues",
|
|
49
|
+
deniedRegex: /^list_/,
|
|
50
|
+
})), false);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe("with GITLAB_TOOL_POLICY_HIDDEN", () => {
|
|
54
|
+
it("should hide the named tool", () => {
|
|
55
|
+
assert.equal(isToolExposed(exposure({
|
|
56
|
+
toolName: "list_issues",
|
|
57
|
+
hiddenTools: new Set(["list_issues"]),
|
|
58
|
+
})), false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("When exposureRefusalMessage explains a block", () => {
|
|
63
|
+
describe("with a hidden tool", () => {
|
|
64
|
+
it("should mention GITLAB_TOOL_POLICY_HIDDEN", () => {
|
|
65
|
+
const message = exposureRefusalMessage(exposure({ toolName: "list_issues", hiddenTools: new Set(["list_issues"]) }));
|
|
66
|
+
assert.match(String(message), /GITLAB_TOOL_POLICY_HIDDEN/);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("with a denied regex", () => {
|
|
70
|
+
it("should mention GITLAB_DENIED_TOOLS_REGEX", () => {
|
|
71
|
+
const message = exposureRefusalMessage(exposure({ toolName: "list_issues", deniedRegex: /^list_/ }));
|
|
72
|
+
assert.match(String(message), /GITLAB_DENIED_TOOLS_REGEX/);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe("with a toolset miss", () => {
|
|
76
|
+
it("should mention GITLAB_TOOLSETS", () => {
|
|
77
|
+
const message = exposureRefusalMessage(exposure({ toolName: "list_pipelines" }));
|
|
78
|
+
assert.match(String(message), /GITLAB_TOOLSETS/);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("When parseToolNameSet reads a policy list", () => {
|
|
83
|
+
describe("with comma-separated names", () => {
|
|
84
|
+
it("should trim and drop empties", () => {
|
|
85
|
+
assert.deepEqual([...parseToolNameSet(" push_files, delete_issue , ")], ["push_files", "delete_issue"]);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("When compileDeniedToolsRegex validates a pattern", () => {
|
|
90
|
+
describe("with nested quantifiers", () => {
|
|
91
|
+
it("should ignore the pattern", () => {
|
|
92
|
+
const compiled = compileDeniedToolsRegex("(a+)+");
|
|
93
|
+
assert.equal(compiled.regex, undefined);
|
|
94
|
+
assert.match(String(compiled.error), /nested quantifiers/);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe("with invalid characters", () => {
|
|
98
|
+
it("should reject unsafe characters", () => {
|
|
99
|
+
const compiled = compileDeniedToolsRegex("create_; rm -rf /");
|
|
100
|
+
assert.equal(compiled.regex, undefined);
|
|
101
|
+
assert.match(String(compiled.error), /invalid characters/);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { formatCliError, formatToolOutput } from "../../cli/output.js";
|
|
4
|
+
describe("When formatToolOutput prints a tool result", () => {
|
|
5
|
+
describe("with json mode", () => {
|
|
6
|
+
it("should write the unwrapped payload as JSON", () => {
|
|
7
|
+
const formatted = formatToolOutput({
|
|
8
|
+
result: { content: [{ type: "text", text: JSON.stringify({ id: 1, username: "tao" }) }] },
|
|
9
|
+
mode: "json",
|
|
10
|
+
tableSpec: undefined,
|
|
11
|
+
});
|
|
12
|
+
assert.equal(formatted.stdout, "{\"id\":1,\"username\":\"tao\"}\n");
|
|
13
|
+
assert.equal(formatted.stderr, "");
|
|
14
|
+
assert.equal(formatted.isError, false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe("with table mode for a list", () => {
|
|
18
|
+
it("should print iid state title columns", () => {
|
|
19
|
+
const formatted = formatToolOutput({
|
|
20
|
+
result: {
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
type: "text",
|
|
24
|
+
text: JSON.stringify([
|
|
25
|
+
{ iid: 45, state: "opened", title: "fix: pipeline retry race" },
|
|
26
|
+
{ iid: 44, state: "opened", title: "chore: bump deps" },
|
|
27
|
+
]),
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
mode: "table",
|
|
32
|
+
tableSpec: { kind: "list", columns: ["iid", "state", "title"] },
|
|
33
|
+
});
|
|
34
|
+
assert.match(formatted.stdout, /IID\s+STATE\s+TITLE/);
|
|
35
|
+
assert.match(formatted.stdout, /45\s+opened\s+fix: pipeline retry race/);
|
|
36
|
+
assert.equal(formatted.stderr, "");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe("with a non-text content block first", () => {
|
|
40
|
+
it("should unwrap the first text payload", () => {
|
|
41
|
+
const formatted = formatToolOutput({
|
|
42
|
+
result: {
|
|
43
|
+
content: [
|
|
44
|
+
{ type: "image", data: "xxx" },
|
|
45
|
+
{ type: "text", text: JSON.stringify({ id: 2 }) },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
mode: "json",
|
|
49
|
+
tableSpec: undefined,
|
|
50
|
+
});
|
|
51
|
+
assert.equal(formatted.stdout, "{\"id\":2}\n");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("with an API-style error object", () => {
|
|
55
|
+
it("should mark the result as an error", () => {
|
|
56
|
+
const formatted = formatToolOutput({
|
|
57
|
+
result: { content: [{ type: "text", text: "GitLab API error: 404 Not Found" }], isError: true },
|
|
58
|
+
mode: "json",
|
|
59
|
+
tableSpec: undefined,
|
|
60
|
+
});
|
|
61
|
+
assert.equal(formatted.isError, true);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("When formatCliError prints a thrown error", () => {
|
|
66
|
+
describe("with a token in the message", () => {
|
|
67
|
+
it("should redact the token", () => {
|
|
68
|
+
const leaked = `glpat-${"notarealtokenvalue"}`;
|
|
69
|
+
const text = formatCliError(new Error(`auth failed ${leaked}`));
|
|
70
|
+
assert.match(text, /\[REDACTED\]/);
|
|
71
|
+
assert.equal(text.includes(leaked), false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { buildToolReplayCommand } from "../../cli/replay-command.js";
|
|
4
|
+
describe("When buildToolReplayCommand prints a CLI invocation", () => {
|
|
5
|
+
describe("with scalar tool arguments", () => {
|
|
6
|
+
it("should emit kebab-case flags without the token", () => {
|
|
7
|
+
const command = buildToolReplayCommand("list_issues", {
|
|
8
|
+
project_id: "123",
|
|
9
|
+
state: "opened",
|
|
10
|
+
token: "glpat-secret",
|
|
11
|
+
});
|
|
12
|
+
assert.equal(command, "zereight-mcp-gitlab tool list_issues --project-id 123 --state opened");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
describe("with a nested object", () => {
|
|
16
|
+
it("should pass it through --args-json", () => {
|
|
17
|
+
const command = buildToolReplayCommand("execute_graphql", {
|
|
18
|
+
query: "{ currentUser { id } }",
|
|
19
|
+
variables: { n: 1 },
|
|
20
|
+
});
|
|
21
|
+
assert.match(command, /tool execute_graphql/);
|
|
22
|
+
assert.match(command, /--query/);
|
|
23
|
+
assert.match(command, /--args-json/);
|
|
24
|
+
assert.equal(command.includes("glpat"), false);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("with confirmation metadata", () => {
|
|
28
|
+
it("should omit _confirmed", () => {
|
|
29
|
+
const command = buildToolReplayCommand("push_files", {
|
|
30
|
+
project_id: "1",
|
|
31
|
+
_confirmed: true,
|
|
32
|
+
});
|
|
33
|
+
assert.equal(command.includes("_confirmed"), false);
|
|
34
|
+
assert.match(command, /--project-id 1/);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { isCliInvocation, resolveCli } from "../../cli/router.js";
|
|
4
|
+
function argv(...args) {
|
|
5
|
+
return ["node", "index.js", ...args];
|
|
6
|
+
}
|
|
7
|
+
const OPEN_EXPOSURE = {
|
|
8
|
+
isExposed() {
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
11
|
+
needsConfirmation() {
|
|
12
|
+
return false;
|
|
13
|
+
},
|
|
14
|
+
exposureRefusal() {
|
|
15
|
+
return undefined;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
function resolve(args, extra = {}) {
|
|
19
|
+
return resolveCli(args, { exposure: extra.exposure ?? OPEN_EXPOSURE, permissionMode: extra.permissionMode });
|
|
20
|
+
}
|
|
21
|
+
describe("When resolveCli classifies argv", () => {
|
|
22
|
+
describe("with no positional command", () => {
|
|
23
|
+
it("should stay on the MCP server path", () => {
|
|
24
|
+
const resolved = resolve(argv("--token", "glpat-xxxxxxxxxxxxxxxxxxxx"));
|
|
25
|
+
assert.equal(resolved.kind, "server");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe("with --help", () => {
|
|
29
|
+
it("should print global help without starting the server", () => {
|
|
30
|
+
const resolved = resolve(argv("--help"));
|
|
31
|
+
assert.equal(resolved.kind, "help");
|
|
32
|
+
if (resolved.kind === "help") {
|
|
33
|
+
assert.match(resolved.text, /tool <tool-name>/);
|
|
34
|
+
assert.match(resolved.text, /auth/);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("with --help after an unknown positional", () => {
|
|
39
|
+
it("should print global help instead of starting the server", () => {
|
|
40
|
+
const resolved = resolve(argv("not-a-command", "--help"));
|
|
41
|
+
assert.equal(resolved.kind, "help");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe("with tool whoami", () => {
|
|
45
|
+
it("should run whoami with json output by default", () => {
|
|
46
|
+
const resolved = resolve(argv("tool", "whoami"));
|
|
47
|
+
assert.equal(resolved.kind, "run");
|
|
48
|
+
if (resolved.kind === "run") {
|
|
49
|
+
assert.equal(resolved.toolName, "whoami");
|
|
50
|
+
assert.equal(resolved.output, "json");
|
|
51
|
+
assert.deepEqual(resolved.args, {});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe("When a curated command is resolved", () => {
|
|
57
|
+
describe("with mr list --group-id", () => {
|
|
58
|
+
it("should call list_group_merge_requests", () => {
|
|
59
|
+
const resolved = resolve(argv("mr", "list", "--group-id", "42", "--state", "opened"));
|
|
60
|
+
assert.equal(resolved.kind, "run");
|
|
61
|
+
if (resolved.kind === "run") {
|
|
62
|
+
assert.equal(resolved.toolName, "list_group_merge_requests");
|
|
63
|
+
assert.equal(resolved.args.group_id, "42");
|
|
64
|
+
assert.equal(resolved.output, "table");
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("with issue close", () => {
|
|
69
|
+
it("should call update_issue with state_event close", () => {
|
|
70
|
+
const resolved = resolve(argv("issue", "close", "--project-id", "123", "--issue-iid", "9"));
|
|
71
|
+
assert.equal(resolved.kind, "run");
|
|
72
|
+
if (resolved.kind === "run") {
|
|
73
|
+
assert.equal(resolved.toolName, "update_issue");
|
|
74
|
+
assert.equal(resolved.args.issue_iid, "9");
|
|
75
|
+
assert.equal(resolved.args.state_event, "close");
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("with mr merge and --yes=false", () => {
|
|
80
|
+
it("should reject the inline value instead of merging", () => {
|
|
81
|
+
const resolved = resolve(argv("mr", "merge", "--project-id", "123", "--mr-iid", "45", "--yes=false"));
|
|
82
|
+
assert.equal(resolved.kind, "usage");
|
|
83
|
+
if (resolved.kind === "usage") {
|
|
84
|
+
assert.match(resolved.message, /--yes does not accept a value/);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe("with mr merge and no --yes", () => {
|
|
89
|
+
it("should refuse until --yes is passed without dumping argument values", () => {
|
|
90
|
+
const resolved = resolve(argv("mr", "merge", "--project-id", "123", "--mr-iid", "45"));
|
|
91
|
+
assert.equal(resolved.kind, "refused");
|
|
92
|
+
if (resolved.kind === "refused") {
|
|
93
|
+
assert.match(resolved.message, /--yes/);
|
|
94
|
+
assert.match(resolved.message, /merge_merge_request/);
|
|
95
|
+
assert.match(resolved.message, /project_id/);
|
|
96
|
+
assert.equal(resolved.message.includes("123"), false);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe("with variable list scoped via --args-json", () => {
|
|
101
|
+
it("should call list_group_variables when group_id is only in JSON", () => {
|
|
102
|
+
const resolved = resolve(argv("variable", "list", "--args-json", '{"group_id":"42"}'));
|
|
103
|
+
assert.equal(resolved.kind, "run");
|
|
104
|
+
if (resolved.kind === "run") {
|
|
105
|
+
assert.equal(resolved.toolName, "list_group_variables");
|
|
106
|
+
assert.equal(resolved.args.group_id, "42");
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe("When permission mode blocks a write", () => {
|
|
112
|
+
describe("with readonly mode and issue create", () => {
|
|
113
|
+
it("should refuse before dispatch", () => {
|
|
114
|
+
const resolved = resolve(argv("issue", "create", "--project-id", "123", "--title", "bug"), { permissionMode: "readonly" });
|
|
115
|
+
assert.equal(resolved.kind, "refused");
|
|
116
|
+
if (resolved.kind === "refused") {
|
|
117
|
+
assert.match(resolved.message, /read-only/);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe("When isCliInvocation inspects argv", () => {
|
|
123
|
+
describe("with a curated group", () => {
|
|
124
|
+
it("should treat it as a human CLI invocation", () => {
|
|
125
|
+
assert.equal(isCliInvocation(argv("mr", "list")), true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe("with --help", () => {
|
|
129
|
+
it("should treat it as a human CLI invocation", () => {
|
|
130
|
+
assert.equal(isCliInvocation(argv("--help")), true);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe("with only a server token flag", () => {
|
|
134
|
+
it("should stay on the MCP server path", () => {
|
|
135
|
+
assert.equal(isCliInvocation(argv("--token", "x")), false);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("When MCP exposure filters block a CLI tool", () => {
|
|
140
|
+
describe("with a denied-tools regex", () => {
|
|
141
|
+
it("should refuse before dispatch", () => {
|
|
142
|
+
const resolved = resolve(argv("tool", "whoami"), {
|
|
143
|
+
exposure: {
|
|
144
|
+
isExposed() {
|
|
145
|
+
return false;
|
|
146
|
+
},
|
|
147
|
+
needsConfirmation() {
|
|
148
|
+
return false;
|
|
149
|
+
},
|
|
150
|
+
exposureRefusal(toolName) {
|
|
151
|
+
return `${toolName} is blocked by GITLAB_DENIED_TOOLS_REGEX`;
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
assert.equal(resolved.kind, "refused");
|
|
156
|
+
if (resolved.kind === "refused") {
|
|
157
|
+
assert.match(resolved.message, /GITLAB_DENIED_TOOLS_REGEX/);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe("with GITLAB_TOOL_POLICY_APPROVE", () => {
|
|
162
|
+
it("should require --yes", () => {
|
|
163
|
+
const resolved = resolve(argv("tool", "whoami"), {
|
|
164
|
+
exposure: {
|
|
165
|
+
isExposed() {
|
|
166
|
+
return true;
|
|
167
|
+
},
|
|
168
|
+
needsConfirmation() {
|
|
169
|
+
return true;
|
|
170
|
+
},
|
|
171
|
+
exposureRefusal() {
|
|
172
|
+
return undefined;
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
assert.equal(resolved.kind, "refused");
|
|
177
|
+
if (resolved.kind === "refused") {
|
|
178
|
+
assert.match(resolved.message, /GITLAB_TOOL_POLICY_APPROVE/);
|
|
179
|
+
assert.match(resolved.message, /--yes/);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -193,6 +193,16 @@ describe("When reading the CLI command", () => {
|
|
|
193
193
|
assert.equal(getPositionalCliCommand(["node", "/usr/local/bin/tsx", "index.ts", "auth", "--help"]), "auth");
|
|
194
194
|
});
|
|
195
195
|
});
|
|
196
|
+
describe("with --use-oauth before a curated command", () => {
|
|
197
|
+
it("should still return mr instead of consuming it as the flag value", () => {
|
|
198
|
+
assert.equal(getPositionalCliCommand(["node", "index.js", "--use-oauth", "mr", "list"]), "mr");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
describe("with --read-only false before a curated command", () => {
|
|
202
|
+
it("should skip the boolean literal and return mr", () => {
|
|
203
|
+
assert.equal(getPositionalCliCommand(["node", "index.js", "--read-only", "false", "mr", "list"]), "mr");
|
|
204
|
+
});
|
|
205
|
+
});
|
|
196
206
|
describe("with space-separated --api-url before auth", () => {
|
|
197
207
|
it("should skip the URL value and return auth", () => {
|
|
198
208
|
assert.equal(getPositionalCliCommand([
|