@drak-marketing/mcp-test-harness 0.2.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/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/helpers/pack.d.ts +9 -0
- package/dist/helpers/pack.js +57 -0
- package/dist/helpers/source-lint.d.ts +17 -0
- package/dist/helpers/source-lint.js +61 -0
- package/dist/helpers/spawn.d.ts +21 -0
- package/dist/helpers/spawn.js +44 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +65 -0
- package/dist/suites/backward-compat.d.ts +3 -0
- package/dist/suites/backward-compat.js +28 -0
- package/dist/suites/build-integrity.d.ts +3 -0
- package/dist/suites/build-integrity.js +43 -0
- package/dist/suites/concurrent.d.ts +3 -0
- package/dist/suites/concurrent.js +25 -0
- package/dist/suites/config-loading.d.ts +3 -0
- package/dist/suites/config-loading.js +38 -0
- package/dist/suites/credential-security.d.ts +3 -0
- package/dist/suites/credential-security.js +36 -0
- package/dist/suites/cross-platform.d.ts +3 -0
- package/dist/suites/cross-platform.js +43 -0
- package/dist/suites/dependency-health.d.ts +3 -0
- package/dist/suites/dependency-health.js +45 -0
- package/dist/suites/ender-strategic.d.ts +3 -0
- package/dist/suites/ender-strategic.js +155 -0
- package/dist/suites/graceful-shutdown.d.ts +3 -0
- package/dist/suites/graceful-shutdown.js +31 -0
- package/dist/suites/input-sanitization.d.ts +3 -0
- package/dist/suites/input-sanitization.js +26 -0
- package/dist/suites/mayhem-adversarial.d.ts +3 -0
- package/dist/suites/mayhem-adversarial.js +175 -0
- package/dist/suites/mcp-protocol.d.ts +3 -0
- package/dist/suites/mcp-protocol.js +65 -0
- package/dist/suites/network-failures.d.ts +3 -0
- package/dist/suites/network-failures.js +49 -0
- package/dist/suites/observability.d.ts +3 -0
- package/dist/suites/observability.js +33 -0
- package/dist/suites/output-contract.d.ts +3 -0
- package/dist/suites/output-contract.js +34 -0
- package/dist/suites/ralph-chaos.d.ts +3 -0
- package/dist/suites/ralph-chaos.js +122 -0
- package/dist/suites/smoke.d.ts +3 -0
- package/dist/suites/smoke.js +50 -0
- package/dist/suites/stdout-purity.d.ts +3 -0
- package/dist/suites/stdout-purity.js +128 -0
- package/dist/suites/token-lifecycle.d.ts +3 -0
- package/dist/suites/token-lifecycle.js +64 -0
- package/dist/suites/version-publish.d.ts +3 -0
- package/dist/suites/version-publish.js +34 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.js +15 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 drak-marketing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @drak-marketing/mcp-test-harness
|
|
2
|
+
|
|
3
|
+
Shared test harness for MCP server repos. One call registers 40+ parameterized
|
|
4
|
+
tests covering build integrity, smoke, protocol conformance, credential
|
|
5
|
+
security, resilience, and adversarial inputs.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save-dev @drak-marketing/mcp-test-harness vitest
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`vitest` is a peer dependency — your repo supplies its own version.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Add a single test file (e.g. `src/harness.test.ts`) to your MCP server repo:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { registerMcpTests } from "@drak-marketing/mcp-test-harness";
|
|
21
|
+
import { fileURLToPath } from "url";
|
|
22
|
+
import path from "path";
|
|
23
|
+
|
|
24
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
|
|
26
|
+
registerMcpTests({
|
|
27
|
+
name: "mcp-example",
|
|
28
|
+
repoRoot: path.resolve(__dirname, ".."),
|
|
29
|
+
toolPrefix: "example_",
|
|
30
|
+
minTools: 10,
|
|
31
|
+
requiredTools: ["example_get_context", "example_list_items"],
|
|
32
|
+
binEntries: { "mcp-example": "dist/index.js" },
|
|
33
|
+
hasAuthCli: false,
|
|
34
|
+
hasCredentials: true,
|
|
35
|
+
hasResilience: true,
|
|
36
|
+
hasPlatform: true,
|
|
37
|
+
requiredEnvVars: ["EXAMPLE_API_KEY"],
|
|
38
|
+
envPrefix: "EXAMPLE_",
|
|
39
|
+
startupEnv: { EXAMPLE_API_KEY: "fake-key" },
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Run with your normal vitest command:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm test
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## What you get
|
|
50
|
+
|
|
51
|
+
Suites are selected based on the capabilities you declare in the config:
|
|
52
|
+
|
|
53
|
+
- **Always on:** build integrity, smoke, cross-platform, MCP protocol,
|
|
54
|
+
dependency health, version/publish checks, observability, input
|
|
55
|
+
sanitization, output contract, concurrency, adversarial (Ralph/Ender/Mayhem)
|
|
56
|
+
- **`hasCredentials: true`** → credential security, token lifecycle,
|
|
57
|
+
backward-compat
|
|
58
|
+
- **`hasResilience: true`** → network failure scenarios
|
|
59
|
+
- **`requiredEnvVars.length > 0`** → config loading
|
|
60
|
+
- **`startupEnv` provided** → graceful shutdown
|
|
61
|
+
|
|
62
|
+
See [`src/types.ts`](src/types.ts) for the full config shape.
|
|
63
|
+
|
|
64
|
+
## Publishing
|
|
65
|
+
|
|
66
|
+
Publishing happens in CI via npm **Trusted Publishing** (OIDC). **There is no npm
|
|
67
|
+
token to create, store, or rotate** — `.github/workflows/publish.yml` authenticates
|
|
68
|
+
with a short-lived credential npm issues in exchange for the workflow's OIDC token,
|
|
69
|
+
matched against the Trusted Publisher registered for this package on npmjs.com
|
|
70
|
+
(GitHub Actions; owner `mharnett`, repo `mcp-test-harness`, workflow `publish.yml`).
|
|
71
|
+
|
|
72
|
+
To publish a new version:
|
|
73
|
+
|
|
74
|
+
1. Bump `version` in `package.json` and merge that to `main`.
|
|
75
|
+
2. Cut a GitHub Release on the matching tag — that fires `publish.yml`:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
gh release create v0.2.2 --repo mharnett/mcp-test-harness --generate-notes
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
3. Watch the run: `gh run list --repo mharnett/mcp-test-harness --workflow publish.yml`
|
|
82
|
+
|
|
83
|
+
If a Release is created by automation rather than by hand, GitHub suppresses the
|
|
84
|
+
downstream `release` trigger and the publish silently never runs. Use the manual
|
|
85
|
+
fallback in that case:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
gh workflow run publish.yml --repo mharnett/mcp-test-harness -f ref=v0.2.2
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Two pins in `publish.yml` are load-bearing and documented inline — `npm@11`
|
|
92
|
+
(Trusted Publishing needs npm ≥ 11.5, but npm@12 drops Node 20), and the
|
|
93
|
+
deliberate absence of `--provenance` (attestation requires a public source repo;
|
|
94
|
+
this one is private). Read the comments before changing either.
|
|
95
|
+
|
|
96
|
+
Do not add `NPM_TOKEN` or `NODE_AUTH_TOKEN` to this repo. If publishing fails,
|
|
97
|
+
the OIDC trust is what needs fixing.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface PackFile {
|
|
2
|
+
path: string;
|
|
3
|
+
size: number;
|
|
4
|
+
}
|
|
5
|
+
/** Run npm pack --dry-run and return the list of files that would be included */
|
|
6
|
+
export declare function getPackFiles(repoRoot: string): string[];
|
|
7
|
+
/** Check if any packed file matches a forbidden pattern */
|
|
8
|
+
export declare function findForbiddenPackFiles(packedFiles: string[], forbiddenPatterns: string[]): string[];
|
|
9
|
+
//# sourceMappingURL=pack.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* npm pack inspection helpers.
|
|
3
|
+
*/
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import path from "path";
|
|
6
|
+
/** Run npm pack --dry-run and return the list of files that would be included */
|
|
7
|
+
export function getPackFiles(repoRoot) {
|
|
8
|
+
try {
|
|
9
|
+
const result = execSync("npm pack --dry-run --json 2>/dev/null", {
|
|
10
|
+
cwd: repoRoot,
|
|
11
|
+
encoding: "utf-8",
|
|
12
|
+
timeout: 30_000,
|
|
13
|
+
});
|
|
14
|
+
const parsed = JSON.parse(result);
|
|
15
|
+
// npm pack --json returns [{ files: [{path, size, mode}...] }]
|
|
16
|
+
const files = parsed[0]?.files ?? [];
|
|
17
|
+
return files.map((f) => f.path);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Fallback: npm pack --dry-run without --json (older npm)
|
|
21
|
+
try {
|
|
22
|
+
const result = execSync("npm pack --dry-run 2>&1", {
|
|
23
|
+
cwd: repoRoot,
|
|
24
|
+
encoding: "utf-8",
|
|
25
|
+
timeout: 30_000,
|
|
26
|
+
});
|
|
27
|
+
return result
|
|
28
|
+
.split("\n")
|
|
29
|
+
.map((l) => l.replace(/^npm notice \d+\.\d+[kMG]?B\s+/, "").trim())
|
|
30
|
+
.filter((l) => l && !l.startsWith("npm") && l.includes("/"));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Check if any packed file matches a forbidden pattern */
|
|
38
|
+
export function findForbiddenPackFiles(packedFiles, forbiddenPatterns) {
|
|
39
|
+
const violations = [];
|
|
40
|
+
for (const file of packedFiles) {
|
|
41
|
+
const basename = path.basename(file);
|
|
42
|
+
for (const pattern of forbiddenPatterns) {
|
|
43
|
+
if (pattern.startsWith("*.")) {
|
|
44
|
+
// Extension match
|
|
45
|
+
const ext = pattern.slice(1);
|
|
46
|
+
if (basename.endsWith(ext))
|
|
47
|
+
violations.push(file);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Exact basename or substring match
|
|
51
|
+
if (basename === pattern || file.includes(pattern))
|
|
52
|
+
violations.push(file);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return violations;
|
|
57
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function walk(dir: string): string[];
|
|
2
|
+
export declare function isTest(filePath: string): boolean;
|
|
3
|
+
export declare function stripComments(src: string): string;
|
|
4
|
+
export interface Violation {
|
|
5
|
+
file: string;
|
|
6
|
+
line: number;
|
|
7
|
+
snippet: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function findMatches(files: string[], pattern: RegExp, opts: {
|
|
10
|
+
baseDir: string;
|
|
11
|
+
exempt?: Set<string>;
|
|
12
|
+
skipTests?: boolean;
|
|
13
|
+
transform?: (src: string) => string;
|
|
14
|
+
ignorePatterns?: string[];
|
|
15
|
+
}): Violation[];
|
|
16
|
+
export declare function formatViolations(rule: string, items: Violation[]): string;
|
|
17
|
+
//# sourceMappingURL=source-lint.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source-level lint helpers. Walks .ts files and runs regex rules.
|
|
3
|
+
* Extracted from mcp-google-ads/src/portability.test.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync, readdirSync, statSync } from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
export function walk(dir) {
|
|
8
|
+
const results = [];
|
|
9
|
+
for (const entry of readdirSync(dir)) {
|
|
10
|
+
const full = path.join(dir, entry);
|
|
11
|
+
const st = statSync(full);
|
|
12
|
+
if (st.isDirectory() && entry !== "node_modules" && entry !== "dist") {
|
|
13
|
+
results.push(...walk(full));
|
|
14
|
+
}
|
|
15
|
+
else if ((entry.endsWith(".ts") || entry.endsWith(".mjs") || entry.endsWith(".cjs")) &&
|
|
16
|
+
!entry.endsWith(".d.ts")) {
|
|
17
|
+
results.push(full);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
export function isTest(filePath) {
|
|
23
|
+
return filePath.endsWith(".test.ts") || filePath.endsWith(".test.mjs") || filePath.endsWith(".spec.ts");
|
|
24
|
+
}
|
|
25
|
+
export function stripComments(src) {
|
|
26
|
+
return src
|
|
27
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
28
|
+
.replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
29
|
+
}
|
|
30
|
+
export function findMatches(files, pattern, opts) {
|
|
31
|
+
const { baseDir, exempt = new Set(), skipTests = true, transform = stripComments, ignorePatterns = [], } = opts;
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
const rel = path.relative(baseDir, file);
|
|
35
|
+
if (exempt.has(rel) || exempt.has(path.basename(file)))
|
|
36
|
+
continue;
|
|
37
|
+
if (skipTests && isTest(file))
|
|
38
|
+
continue;
|
|
39
|
+
if (ignorePatterns.some((p) => rel.includes(p)))
|
|
40
|
+
continue;
|
|
41
|
+
const src = transform(readFileSync(file, "utf-8"));
|
|
42
|
+
const lines = src.split("\n");
|
|
43
|
+
lines.forEach((line, i) => {
|
|
44
|
+
const re = new RegExp(pattern.source, pattern.flags);
|
|
45
|
+
if (re.test(line)) {
|
|
46
|
+
out.push({ file: rel, line: i + 1, snippet: line });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
export function formatViolations(rule, items) {
|
|
53
|
+
if (items.length === 0)
|
|
54
|
+
return "";
|
|
55
|
+
const lines = [`Rule violated: ${rule}`, ""];
|
|
56
|
+
for (const v of items) {
|
|
57
|
+
lines.push(` ${v.file}:${v.line}`);
|
|
58
|
+
lines.push(` ${v.snippet.trim()}`);
|
|
59
|
+
}
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process spawning helpers for smoke, shutdown, and protocol tests.
|
|
3
|
+
*/
|
|
4
|
+
import { type ChildProcess } from "child_process";
|
|
5
|
+
import type { McpServerConfig } from "../types.js";
|
|
6
|
+
export interface SpawnResult {
|
|
7
|
+
stdout: string;
|
|
8
|
+
stderr: string;
|
|
9
|
+
exitCode: number | null;
|
|
10
|
+
signal: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** Spawn a process synchronously and capture all output */
|
|
13
|
+
export declare function spawnCli(config: McpServerConfig, binPath: string, args?: string[], env?: Record<string, string>, timeoutMs?: number): SpawnResult;
|
|
14
|
+
/** Spawn a server process, wait for it to emit something on stderr, then return handle */
|
|
15
|
+
export declare function spawnServer(config: McpServerConfig, env?: Record<string, string>): ChildProcess;
|
|
16
|
+
/** Send a signal to a process and wait for exit within timeout */
|
|
17
|
+
export declare function sendSignalAndWait(proc: ChildProcess, signal: NodeJS.Signals, timeoutMs?: number): Promise<{
|
|
18
|
+
exitCode: number | null;
|
|
19
|
+
signal: string | null;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process spawning helpers for smoke, shutdown, and protocol tests.
|
|
3
|
+
*/
|
|
4
|
+
import { spawnSync, spawn } from "child_process";
|
|
5
|
+
import path from "path";
|
|
6
|
+
/** Spawn a process synchronously and capture all output */
|
|
7
|
+
export function spawnCli(config, binPath, args = [], env, timeoutMs = 10_000) {
|
|
8
|
+
const fullPath = path.resolve(config.repoRoot, binPath);
|
|
9
|
+
const result = spawnSync("node", [fullPath, ...args], {
|
|
10
|
+
timeout: timeoutMs,
|
|
11
|
+
env: { ...process.env, ...env },
|
|
12
|
+
cwd: config.repoRoot,
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
stdout: result.stdout?.toString("utf-8") ?? "",
|
|
16
|
+
stderr: result.stderr?.toString("utf-8") ?? "",
|
|
17
|
+
exitCode: result.status,
|
|
18
|
+
signal: result.signal,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Spawn a server process, wait for it to emit something on stderr, then return handle */
|
|
22
|
+
export function spawnServer(config, env) {
|
|
23
|
+
const entry = config.serverEntry ?? "dist/index.js";
|
|
24
|
+
const fullPath = path.resolve(config.repoRoot, entry);
|
|
25
|
+
return spawn("node", [fullPath], {
|
|
26
|
+
env: { ...process.env, ...env },
|
|
27
|
+
cwd: config.repoRoot,
|
|
28
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Send a signal to a process and wait for exit within timeout */
|
|
32
|
+
export function sendSignalAndWait(proc, signal, timeoutMs = 3000) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
const timer = setTimeout(() => {
|
|
35
|
+
proc.kill("SIGKILL");
|
|
36
|
+
resolve({ exitCode: null, signal: "TIMEOUT" });
|
|
37
|
+
}, timeoutMs);
|
|
38
|
+
proc.on("exit", (code, sig) => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
resolve({ exitCode: code, signal: sig });
|
|
41
|
+
});
|
|
42
|
+
proc.kill(signal);
|
|
43
|
+
});
|
|
44
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @drak-marketing/mcp-test-harness
|
|
3
|
+
*
|
|
4
|
+
* Shared test harness for MCP server repos. Call registerMcpTests(config)
|
|
5
|
+
* from a single test file in each repo to get 40+ parameterized tests
|
|
6
|
+
* covering build integrity, smoke tests, protocol conformance, security,
|
|
7
|
+
* portability, and more.
|
|
8
|
+
*/
|
|
9
|
+
export type { McpServerConfig } from "./types.js";
|
|
10
|
+
export { CONFIG_DEFAULTS } from "./types.js";
|
|
11
|
+
import type { McpServerConfig } from "./types.js";
|
|
12
|
+
export declare function registerMcpTests(config: McpServerConfig): void;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @drak-marketing/mcp-test-harness
|
|
3
|
+
*
|
|
4
|
+
* Shared test harness for MCP server repos. Call registerMcpTests(config)
|
|
5
|
+
* from a single test file in each repo to get 40+ parameterized tests
|
|
6
|
+
* covering build integrity, smoke tests, protocol conformance, security,
|
|
7
|
+
* portability, and more.
|
|
8
|
+
*/
|
|
9
|
+
export { CONFIG_DEFAULTS } from "./types.js";
|
|
10
|
+
import { describe } from "vitest";
|
|
11
|
+
import { buildIntegritySuite } from "./suites/build-integrity.js";
|
|
12
|
+
import { smokeSuite } from "./suites/smoke.js";
|
|
13
|
+
import { crossPlatformSuite } from "./suites/cross-platform.js";
|
|
14
|
+
import { mcpProtocolSuite } from "./suites/mcp-protocol.js";
|
|
15
|
+
import { credentialSecuritySuite } from "./suites/credential-security.js";
|
|
16
|
+
import { gracefulShutdownSuite } from "./suites/graceful-shutdown.js";
|
|
17
|
+
import { dependencyHealthSuite } from "./suites/dependency-health.js";
|
|
18
|
+
import { versionPublishSuite } from "./suites/version-publish.js";
|
|
19
|
+
import { observabilitySuite } from "./suites/observability.js";
|
|
20
|
+
import { inputSanitizationSuite } from "./suites/input-sanitization.js";
|
|
21
|
+
import { configLoadingSuite } from "./suites/config-loading.js";
|
|
22
|
+
import { tokenLifecycleSuite } from "./suites/token-lifecycle.js";
|
|
23
|
+
import { outputContractSuite } from "./suites/output-contract.js";
|
|
24
|
+
import { stdoutPuritySuite } from "./suites/stdout-purity.js";
|
|
25
|
+
import { concurrentSuite } from "./suites/concurrent.js";
|
|
26
|
+
import { networkFailuresSuite } from "./suites/network-failures.js";
|
|
27
|
+
import { backwardCompatSuite } from "./suites/backward-compat.js";
|
|
28
|
+
import { ralphChaosSuite } from "./suites/ralph-chaos.js";
|
|
29
|
+
import { enderStrategicSuite } from "./suites/ender-strategic.js";
|
|
30
|
+
import { mayhemAdversarialSuite } from "./suites/mayhem-adversarial.js";
|
|
31
|
+
export function registerMcpTests(config) {
|
|
32
|
+
describe(`${config.name} shared harness`, () => {
|
|
33
|
+
// Always run
|
|
34
|
+
buildIntegritySuite(config);
|
|
35
|
+
smokeSuite(config);
|
|
36
|
+
crossPlatformSuite(config);
|
|
37
|
+
mcpProtocolSuite(config);
|
|
38
|
+
dependencyHealthSuite(config);
|
|
39
|
+
versionPublishSuite(config);
|
|
40
|
+
observabilitySuite(config);
|
|
41
|
+
inputSanitizationSuite(config);
|
|
42
|
+
outputContractSuite(config);
|
|
43
|
+
stdoutPuritySuite(config);
|
|
44
|
+
concurrentSuite(config);
|
|
45
|
+
// Character suites (always run)
|
|
46
|
+
ralphChaosSuite(config);
|
|
47
|
+
enderStrategicSuite(config);
|
|
48
|
+
mayhemAdversarialSuite(config);
|
|
49
|
+
// Conditional on capabilities
|
|
50
|
+
if (config.hasCredentials) {
|
|
51
|
+
credentialSecuritySuite(config);
|
|
52
|
+
tokenLifecycleSuite(config);
|
|
53
|
+
backwardCompatSuite(config);
|
|
54
|
+
}
|
|
55
|
+
if (config.hasResilience) {
|
|
56
|
+
networkFailuresSuite(config);
|
|
57
|
+
}
|
|
58
|
+
if (config.requiredEnvVars.length > 0) {
|
|
59
|
+
configLoadingSuite(config);
|
|
60
|
+
}
|
|
61
|
+
if (config.startupEnv) {
|
|
62
|
+
gracefulShutdownSuite(config);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { existsSync, readFileSync } from "fs";
|
|
4
|
+
export function backwardCompatSuite(config) {
|
|
5
|
+
describe("backward compatibility", () => {
|
|
6
|
+
it("credentials.ts checks version field before parsing", () => {
|
|
7
|
+
const credPath = path.join(config.repoRoot, config.srcDir ?? "src", "credentials.ts");
|
|
8
|
+
if (!existsSync(credPath))
|
|
9
|
+
return;
|
|
10
|
+
const src = readFileSync(credPath, "utf-8");
|
|
11
|
+
const checksVersion = src.includes("CREDENTIALS_FILE_VERSION") ||
|
|
12
|
+
src.includes(".version") ||
|
|
13
|
+
src.includes("version:");
|
|
14
|
+
expect(checksVersion, "credentials should validate version field for forward compat").toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it("config.example.json exists if config.json is used", () => {
|
|
17
|
+
const configJsonIgnored = (() => {
|
|
18
|
+
const giPath = path.join(config.repoRoot, ".gitignore");
|
|
19
|
+
if (!existsSync(giPath))
|
|
20
|
+
return false;
|
|
21
|
+
return readFileSync(giPath, "utf-8").includes("config.json");
|
|
22
|
+
})();
|
|
23
|
+
if (configJsonIgnored) {
|
|
24
|
+
expect(existsSync(path.join(config.repoRoot, "config.example.json")), "config.json is gitignored but no config.example.json exists for reference").toBe(true);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { CONFIG_DEFAULTS } from "../types.js";
|
|
5
|
+
import { getPackFiles, findForbiddenPackFiles } from "../helpers/pack.js";
|
|
6
|
+
export function buildIntegritySuite(config) {
|
|
7
|
+
describe("build integrity", () => {
|
|
8
|
+
const pkgPath = path.join(config.repoRoot, "package.json");
|
|
9
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
10
|
+
it("package.json has type: module", () => {
|
|
11
|
+
expect(pkg.type).toBe("module");
|
|
12
|
+
});
|
|
13
|
+
it("all bin entries point to files that exist", () => {
|
|
14
|
+
for (const [name, relPath] of Object.entries(config.binEntries)) {
|
|
15
|
+
const fullPath = path.resolve(config.repoRoot, relPath);
|
|
16
|
+
expect(existsSync(fullPath), `bin "${name}" -> "${relPath}" does not exist`).toBe(true);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
it("bin entry files have shebang line", () => {
|
|
20
|
+
for (const [name, relPath] of Object.entries(config.binEntries)) {
|
|
21
|
+
const fullPath = path.resolve(config.repoRoot, relPath);
|
|
22
|
+
if (!existsSync(fullPath))
|
|
23
|
+
return;
|
|
24
|
+
const firstLine = readFileSync(fullPath, "utf-8").split("\n")[0];
|
|
25
|
+
expect(firstLine?.startsWith("#!/"), `bin "${name}" (${relPath}) is missing shebang line, got: "${firstLine?.slice(0, 40)}"`).toBe(true);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
it("dist/ directory exists", () => {
|
|
29
|
+
expect(existsSync(path.join(config.repoRoot, "dist")), "dist/ not found -- run npm run build").toBe(true);
|
|
30
|
+
});
|
|
31
|
+
it("npm pack excludes sensitive files", () => {
|
|
32
|
+
const packed = getPackFiles(config.repoRoot);
|
|
33
|
+
if (packed.length === 0)
|
|
34
|
+
return; // couldn't run npm pack
|
|
35
|
+
const excludes = config.packExcludes ?? CONFIG_DEFAULTS.packExcludes;
|
|
36
|
+
const forbidden = findForbiddenPackFiles(packed, [...excludes]);
|
|
37
|
+
expect(forbidden, `Sensitive files would be included in npm package: ${forbidden.join(", ")}`).toEqual([]);
|
|
38
|
+
});
|
|
39
|
+
it("package.json version is valid semver", () => {
|
|
40
|
+
expect(pkg.version).toMatch(/^\d+\.\d+\.\d+/);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { readFileSync, existsSync } from "fs";
|
|
4
|
+
export function concurrentSuite(config) {
|
|
5
|
+
describe("concurrency safety", () => {
|
|
6
|
+
it("no global mutable state in tool handlers", () => {
|
|
7
|
+
const entryPath = path.join(config.repoRoot, config.serverEntry ?? "dist/index.js");
|
|
8
|
+
if (!existsSync(entryPath))
|
|
9
|
+
return;
|
|
10
|
+
const src = readFileSync(entryPath, "utf-8");
|
|
11
|
+
// Check for obvious global mutable state patterns
|
|
12
|
+
// This is a heuristic -- not exhaustive
|
|
13
|
+
const hasGlobalLet = /^(?:let|var)\s+\w+\s*=/m.test(src);
|
|
14
|
+
if (hasGlobalLet) {
|
|
15
|
+
// Check if the global vars are used inside request handlers
|
|
16
|
+
const hasGlobalInHandler = /setRequestHandler[\s\S]*?\b(let|var)\b/.test(src);
|
|
17
|
+
if (hasGlobalInHandler) {
|
|
18
|
+
process.stderr.write("[info] mutable state detected near request handlers -- verify thread safety\n");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// This test is advisory, not a hard fail
|
|
22
|
+
expect(true).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { spawnCli } from "../helpers/spawn.js";
|
|
3
|
+
export function configLoadingSuite(config) {
|
|
4
|
+
describe("config loading", () => {
|
|
5
|
+
const entry = config.serverEntry ?? "dist/index.js";
|
|
6
|
+
it("missing all env vars produces actionable error (not stack trace)", () => {
|
|
7
|
+
const cleanEnv = {
|
|
8
|
+
PATH: process.env.PATH ?? "",
|
|
9
|
+
HOME: process.env.HOME ?? "",
|
|
10
|
+
NODE_PATH: process.env.NODE_PATH ?? "",
|
|
11
|
+
};
|
|
12
|
+
const result = spawnCli(config, entry, [], cleanEnv, 10_000);
|
|
13
|
+
const output = result.stdout + result.stderr;
|
|
14
|
+
if (result.exitCode !== 0) {
|
|
15
|
+
// Should mention what's missing, not dump a raw stack
|
|
16
|
+
const hasGuidance = /credential|token|auth|config|env|missing|required|set|run/i.test(output);
|
|
17
|
+
const isRawStack = output.includes("at Object.") && !hasGuidance;
|
|
18
|
+
expect(isRawStack, "error should be user-friendly, not a raw stack trace").toBe(false);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
it("missing credentials mentions the auth CLI or env var to set", () => {
|
|
22
|
+
const cleanEnv = {
|
|
23
|
+
PATH: process.env.PATH ?? "",
|
|
24
|
+
HOME: process.env.HOME ?? "",
|
|
25
|
+
NODE_PATH: process.env.NODE_PATH ?? "",
|
|
26
|
+
};
|
|
27
|
+
const result = spawnCli(config, entry, [], cleanEnv, 10_000);
|
|
28
|
+
const output = result.stdout + result.stderr;
|
|
29
|
+
if (result.exitCode !== 0 && output.length > 0) {
|
|
30
|
+
// Error should reference either an env var name or an auth command
|
|
31
|
+
const hasSpecificGuidance = config.requiredEnvVars.some((v) => output.includes(v)) ||
|
|
32
|
+
output.includes("npx") ||
|
|
33
|
+
output.includes("auth");
|
|
34
|
+
expect(hasSpecificGuidance, `error should mention specific env vars or auth command, got: ${output.slice(0, 200)}`).toBe(true);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import { walk, findMatches, formatViolations } from "../helpers/source-lint.js";
|
|
5
|
+
export function credentialSecuritySuite(config) {
|
|
6
|
+
describe("credential security", () => {
|
|
7
|
+
const srcDir = path.join(config.repoRoot, config.srcDir ?? "src");
|
|
8
|
+
const files = walk(srcDir);
|
|
9
|
+
const opts = { baseDir: srcDir, ignorePatterns: config.sourceLintIgnore ?? [] };
|
|
10
|
+
it("credential files use 0o600 permissions", () => {
|
|
11
|
+
const credFiles = files.filter((f) => path.basename(f) === "credentials.ts" || path.basename(f) === "credentials.js");
|
|
12
|
+
if (credFiles.length === 0)
|
|
13
|
+
return;
|
|
14
|
+
let found0600 = false;
|
|
15
|
+
for (const file of credFiles) {
|
|
16
|
+
const src = readFileSync(file, "utf-8");
|
|
17
|
+
if (src.includes("0o600") || src.includes("0600")) {
|
|
18
|
+
found0600 = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
expect(found0600, "credentials file should chmod 0o600").toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it("error messages don't include raw token values", () => {
|
|
24
|
+
// Check that error/throw statements don't template-interpolate token variables
|
|
25
|
+
const tokenVarPattern = /\b(access_?token|refresh_?token|api_?key|secret|password)\b/i;
|
|
26
|
+
const throwPattern = /(?:throw|Error|reject)\s*\([^)]*\$\{[^}]*(?:token|secret|key|password)/i;
|
|
27
|
+
const v = findMatches(files, throwPattern, opts);
|
|
28
|
+
expect(v, formatViolations("error messages may leak secrets", v)).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
it("no secrets written to stdout (only stderr)", () => {
|
|
31
|
+
// console.log or process.stdout.write near token/secret variables
|
|
32
|
+
const v = findMatches(files, /(?:console\.log|process\.stdout\.write)\s*\([^)]*(?:token|secret|key|password|credential)/i, opts);
|
|
33
|
+
expect(v, formatViolations("secrets may leak to stdout", v)).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|