@mcp-guardian/cli 4.1.2
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/.turbo/turbo-build.log +9 -0
- package/.turbo/turbo-test.log +49 -0
- package/README.md +586 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +140 -0
- package/dist/tui/app.d.ts +1 -0
- package/dist/tui/app.js +430 -0
- package/dist/tui/data-fetcher.d.ts +144 -0
- package/dist/tui/data-fetcher.js +268 -0
- package/package.json +20 -0
- package/package.json.prepack-backup +28 -0
- package/src/index.ts +156 -0
- package/tests/index.test.ts +122 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI package tests — validates argument parsing, report formatting,
|
|
3
|
+
* and exit code behavior per the v2 blueprint.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from "vitest";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
|
|
8
|
+
describe("CLI — argument parsing", () => {
|
|
9
|
+
it("should support --fail-on-critical flag", () => {
|
|
10
|
+
const { values } = parseArgs({
|
|
11
|
+
args: ["--fail-on-critical"],
|
|
12
|
+
options: {
|
|
13
|
+
"fail-on-critical": { type: "boolean", default: false },
|
|
14
|
+
},
|
|
15
|
+
allowPositionals: true,
|
|
16
|
+
});
|
|
17
|
+
expect(values["fail-on-critical"]).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should support --json flag", () => {
|
|
21
|
+
const { values } = parseArgs({
|
|
22
|
+
args: ["--json"],
|
|
23
|
+
options: {
|
|
24
|
+
json: { type: "boolean", default: false },
|
|
25
|
+
},
|
|
26
|
+
allowPositionals: true,
|
|
27
|
+
});
|
|
28
|
+
expect(values.json).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should support --skip-semantic flag", () => {
|
|
32
|
+
const { values } = parseArgs({
|
|
33
|
+
args: ["--skip-semantic"],
|
|
34
|
+
options: {
|
|
35
|
+
"skip-semantic": { type: "boolean", default: false },
|
|
36
|
+
},
|
|
37
|
+
allowPositionals: true,
|
|
38
|
+
});
|
|
39
|
+
expect(values["skip-semantic"]).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should support --verbose shorthand -v", () => {
|
|
43
|
+
const { values } = parseArgs({
|
|
44
|
+
args: ["-v"],
|
|
45
|
+
options: {
|
|
46
|
+
verbose: { type: "boolean", short: "v", default: false },
|
|
47
|
+
},
|
|
48
|
+
allowPositionals: true,
|
|
49
|
+
});
|
|
50
|
+
expect(values.verbose).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should accept a positional config path", () => {
|
|
54
|
+
const { positionals } = parseArgs({
|
|
55
|
+
args: ["~/my-config.json"],
|
|
56
|
+
options: { json: { type: "boolean", default: false } },
|
|
57
|
+
allowPositionals: true,
|
|
58
|
+
});
|
|
59
|
+
expect(positionals[0]).toBe("~/my-config.json");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should default all flags to false", () => {
|
|
63
|
+
const { values } = parseArgs({
|
|
64
|
+
args: [],
|
|
65
|
+
options: {
|
|
66
|
+
"fail-on-critical": { type: "boolean", default: false },
|
|
67
|
+
"fail-on-warning": { type: "boolean", default: false },
|
|
68
|
+
json: { type: "boolean", default: false },
|
|
69
|
+
"skip-semantic": { type: "boolean", default: false },
|
|
70
|
+
},
|
|
71
|
+
allowPositionals: true,
|
|
72
|
+
});
|
|
73
|
+
expect(values["fail-on-critical"]).toBe(false);
|
|
74
|
+
expect(values["fail-on-warning"]).toBe(false);
|
|
75
|
+
expect(values.json).toBe(false);
|
|
76
|
+
expect(values["skip-semantic"]).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("CLI — report formatting", () => {
|
|
81
|
+
it("should format a clean server result", () => {
|
|
82
|
+
const server = {
|
|
83
|
+
serverName: "test-server",
|
|
84
|
+
transport: "stdio" as const,
|
|
85
|
+
status: "clean" as const,
|
|
86
|
+
tools: [],
|
|
87
|
+
summary: { total: 3, clean: 3, warnings: 0, critical: 0 },
|
|
88
|
+
scannedAt: new Date().toISOString(),
|
|
89
|
+
};
|
|
90
|
+
expect(server.status).toBe("clean");
|
|
91
|
+
expect(server.summary.clean).toBe(3);
|
|
92
|
+
expect(server.summary.critical).toBe(0);
|
|
93
|
+
expect(server.transport).toBe("stdio");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should identify critical status", () => {
|
|
97
|
+
const server = {
|
|
98
|
+
serverName: "critical-server",
|
|
99
|
+
transport: "http" as const,
|
|
100
|
+
status: "critical" as const,
|
|
101
|
+
tools: [],
|
|
102
|
+
summary: { total: 5, clean: 2, warnings: 1, critical: 2 },
|
|
103
|
+
scannedAt: new Date().toISOString(),
|
|
104
|
+
};
|
|
105
|
+
expect(server.status).toBe("critical");
|
|
106
|
+
expect(server.summary.critical).toBeGreaterThan(0);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should identify warning status", () => {
|
|
110
|
+
const server = {
|
|
111
|
+
serverName: "warning-server",
|
|
112
|
+
transport: "sse" as const,
|
|
113
|
+
status: "warning" as const,
|
|
114
|
+
tools: [],
|
|
115
|
+
summary: { total: 4, clean: 3, warnings: 1, critical: 0 },
|
|
116
|
+
scannedAt: new Date().toISOString(),
|
|
117
|
+
};
|
|
118
|
+
expect(server.status).toBe("warning");
|
|
119
|
+
expect(server.summary.warnings).toBeGreaterThan(0);
|
|
120
|
+
expect(server.summary.critical).toBe(0);
|
|
121
|
+
});
|
|
122
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "./dist",
|
|
9
|
+
"rootDir": "./src",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"types": ["node"],
|
|
13
|
+
"forceConsistentCasingInFileNames": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts"],
|
|
16
|
+
"exclude": ["node_modules", "dist"]
|
|
17
|
+
}
|