@drak-marketing/mcp-test-harness 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +1,67 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import path from "path";
2
+ import { importDistModule } from "../helpers/dist-module.js";
3
+ import { probeStdioOnce, probedTools } from "../helpers/stdio-probe.js";
4
+ import { STDOUT_PURITY_TEST_TIMEOUT_MS } from "./stdout-purity.js";
3
5
  export function mcpProtocolSuite(config) {
4
6
  describe("MCP protocol conformance", () => {
5
7
  let tools = [];
6
- it("can import tools from dist/tools.js", async () => {
7
- try {
8
- const toolsModule = await import(path.join(config.repoRoot, "dist", "tools.js"));
9
- tools = toolsModule.tools ?? toolsModule.TOOLS ?? toolsModule.default ?? [];
10
- expect(Array.isArray(tools), "tools export should be an array").toBe(true);
8
+ // The list comes from dist/tools.js when it exports one, otherwise from
9
+ // the running server's tools/list answer (started with fake credentials).
10
+ // Before 0.3.0 a repo without an importable tools.js skipped every check
11
+ // below by returning early, so they passed without testing anything.
12
+ it("gets the tool list from dist/tools.js or the running server", async () => {
13
+ const toolsModule = await importDistModule(config, "tools");
14
+ const exported = toolsModule
15
+ ? (toolsModule.tools ?? toolsModule.TOOLS ?? toolsModule.default)
16
+ : undefined;
17
+ let source = "dist/tools.js";
18
+ let stderr = "";
19
+ if (Array.isArray(exported) && exported.length > 0) {
20
+ tools = exported;
11
21
  }
12
- catch (err) {
13
- // Some repos export tools differently (e.g., inline in index.ts)
14
- // This is acceptable -- skip remaining protocol tests
15
- tools = [];
22
+ else {
23
+ source = "tools/list on the running server";
24
+ const probe = await probeStdioOnce(config);
25
+ stderr = probe.stderr.split("\n").slice(-10).join("\n");
26
+ tools = probedTools(probe);
16
27
  }
17
- });
18
- it(`has at least ${config.minTools} tools`, () => {
28
+ expect(tools.length, `no tools from ${source}. dist/tools.js exports no tools array and the server did not ` +
29
+ `answer tools/list; see the stdout purity failure.\nserver stderr:\n${stderr}`).toBeGreaterThan(0);
30
+ }, STDOUT_PURITY_TEST_TIMEOUT_MS);
31
+ it(`has at least ${config.minTools} tools`, (ctx) => {
19
32
  if (tools.length === 0)
20
- return; // tools not importable separately
33
+ return ctx.skip(); // the list test above already failed
21
34
  expect(tools.length).toBeGreaterThanOrEqual(config.minTools);
22
35
  });
23
- it("all required tools are present", () => {
36
+ it("all required tools are present", (ctx) => {
24
37
  if (tools.length === 0)
25
- return;
38
+ return ctx.skip();
26
39
  const names = new Set(tools.map((t) => t.name));
27
40
  for (const required of config.requiredTools) {
28
41
  expect(names.has(required), `required tool "${required}" not found`).toBe(true);
29
42
  }
30
43
  });
31
- it(`all tool names start with "${config.toolPrefix}"`, () => {
44
+ it(`all tool names start with "${config.toolPrefix}"`, (ctx) => {
32
45
  if (tools.length === 0)
33
- return;
46
+ return ctx.skip();
34
47
  const bad = tools.filter((t) => !t.name.startsWith(config.toolPrefix));
35
48
  expect(bad.map((t) => t.name), `tools missing prefix "${config.toolPrefix}"`).toEqual([]);
36
49
  });
37
- it("all tools have non-empty descriptions", () => {
50
+ it("all tools have non-empty descriptions", (ctx) => {
38
51
  if (tools.length === 0)
39
- return;
52
+ return ctx.skip();
40
53
  const bad = tools.filter((t) => !t.description || t.description.length < 10);
41
54
  expect(bad.map((t) => t.name), "tools with missing/short descriptions").toEqual([]);
42
55
  });
43
- it("all tool inputSchemas have type: object", () => {
56
+ it("all tool inputSchemas have type: object", (ctx) => {
44
57
  if (tools.length === 0)
45
- return;
58
+ return ctx.skip();
46
59
  const bad = tools.filter((t) => t.inputSchema && t.inputSchema.type !== "object");
47
60
  expect(bad.map((t) => t.name), "tools with non-object inputSchema").toEqual([]);
48
61
  });
49
- it("all required fields exist in properties", () => {
62
+ it("all required fields exist in properties", (ctx) => {
50
63
  if (tools.length === 0)
51
- return;
64
+ return ctx.skip();
52
65
  const bad = [];
53
66
  for (const tool of tools) {
54
67
  const required = tool.inputSchema?.required ?? [];
@@ -1,49 +1,32 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import path from "path";
2
+ import { importDistModule, pickFn } from "../helpers/dist-module.js";
3
3
  export function networkFailuresSuite(config) {
4
4
  describe("network failure handling", () => {
5
- it("resilience module classifies auth errors as non-retryable", async () => {
6
- try {
7
- const mod = await import(path.join(config.repoRoot, "dist", "errors.js"));
8
- const classify = mod.classifyError;
9
- if (!classify)
10
- return;
11
- // 401 should be classified as auth error
12
- const authErr = classify({ status: 401, message: "Unauthorized" });
13
- expect(authErr.name).toMatch(/auth/i);
14
- // 403 should be classified as auth error
15
- const forbidErr = classify({ status: 403, message: "Forbidden" });
16
- expect(forbidErr.name).toMatch(/auth/i);
17
- }
18
- catch {
19
- // Module may not export classifyError
20
- }
5
+ // Skipped (visibly) when dist/errors.js or classifyError does not exist;
6
+ // a failing expectation is never swallowed.
7
+ const classifier = async () => pickFn(await importDistModule(config, "errors"), "classifyError");
8
+ it("resilience module classifies auth errors as non-retryable", async (ctx) => {
9
+ const classify = await classifier();
10
+ if (!classify)
11
+ return ctx.skip();
12
+ const authErr = classify({ status: 401, message: "Unauthorized" });
13
+ expect(authErr.name).toMatch(/auth/i);
14
+ const forbidErr = classify({ status: 403, message: "Forbidden" });
15
+ expect(forbidErr.name).toMatch(/auth/i);
21
16
  });
22
- it("resilience module classifies rate limits correctly", async () => {
23
- try {
24
- const mod = await import(path.join(config.repoRoot, "dist", "errors.js"));
25
- const classify = mod.classifyError;
26
- if (!classify)
27
- return;
28
- const rateLimitErr = classify({ status: 429, message: "Too Many Requests" });
29
- expect(rateLimitErr.name).toMatch(/rate/i);
30
- }
31
- catch {
32
- // skip
33
- }
17
+ it("resilience module classifies rate limits correctly", async (ctx) => {
18
+ const classify = await classifier();
19
+ if (!classify)
20
+ return ctx.skip();
21
+ const rateLimitErr = classify({ status: 429, message: "Too Many Requests" });
22
+ expect(rateLimitErr.name).toMatch(/rate/i);
34
23
  });
35
- it("resilience module classifies server errors as transient", async () => {
36
- try {
37
- const mod = await import(path.join(config.repoRoot, "dist", "errors.js"));
38
- const classify = mod.classifyError;
39
- if (!classify)
40
- return;
41
- const serverErr = classify({ status: 500, message: "Internal Server Error" });
42
- expect(serverErr.name).toMatch(/service|server/i);
43
- }
44
- catch {
45
- // skip
46
- }
24
+ it("resilience module classifies server errors as transient", async (ctx) => {
25
+ const classify = await classifier();
26
+ if (!classify)
27
+ return ctx.skip();
28
+ const serverErr = classify({ status: 500, message: "Internal Server Error" });
29
+ expect(serverErr.name).toMatch(/service|server/i);
47
30
  });
48
31
  });
49
32
  }
@@ -3,7 +3,6 @@
3
3
  * "I'm in danger!" -- tests for the dumbest possible user behavior.
4
4
  */
5
5
  import { describe, it, expect } from "vitest";
6
- import { spawnSync } from "child_process";
7
6
  import path from "path";
8
7
  import { existsSync, readFileSync } from "fs";
9
8
  import { spawnCli } from "../helpers/spawn.js";
@@ -60,11 +59,10 @@ export function ralphChaosSuite(config) {
60
59
  // Double-invocation: bin entry run twice rapidly
61
60
  // ----------------------------------------------------------------
62
61
  it("rapid double --help invocation doesn't crash", () => {
63
- const fullPath = path.resolve(config.repoRoot, entry);
64
- const r1 = spawnSync("node", [fullPath, "--help"], { timeout: 5000, cwd: config.repoRoot });
65
- const r2 = spawnSync("node", [fullPath, "--help"], { timeout: 5000, cwd: config.repoRoot });
66
- expect(r1.status).toBe(0);
67
- expect(r2.status).toBe(0);
62
+ const r1 = spawnCli(config, entry, ["--help"], undefined, 5_000);
63
+ const r2 = spawnCli(config, entry, ["--help"], undefined, 5_000);
64
+ expect(r1.exitCode).toBe(0);
65
+ expect(r2.exitCode).toBe(0);
68
66
  });
69
67
  // ----------------------------------------------------------------
70
68
  // Stale npx cache detection
@@ -1,5 +1,7 @@
1
1
  import { describe, it, expect } from "vitest";
2
2
  import { spawnCli } from "../helpers/spawn.js";
3
+ import { probeStdioOnce, startupProblems, STARTUP_TEST_TITLE } from "../helpers/stdio-probe.js";
4
+ import { STDOUT_PURITY_TEST_TIMEOUT_MS } from "./stdout-purity.js";
3
5
  export function smokeSuite(config) {
4
6
  describe("smoke tests", () => {
5
7
  const entry = config.serverEntry ?? "dist/index.js";
@@ -16,6 +18,16 @@ export function smokeSuite(config) {
16
18
  const output = result.stdout + result.stderr;
17
19
  expect(output).toMatch(/\d+\.\d+\.\d+/);
18
20
  });
21
+ // The server is started the way an MCP client starts it (piped stdio),
22
+ // with a fake value for every requiredEnvVars entry plus startupEnv, in
23
+ // the hermetic, jailed env. Every other spawn-based check (stdout purity,
24
+ // tools/list, graceful shutdown) depends on this: a server that exits at
25
+ // credential validation would otherwise pass them without being tested.
26
+ it(STARTUP_TEST_TITLE, async () => {
27
+ const problems = startupProblems(await probeStdioOnce(config), config);
28
+ if (problems.length > 0)
29
+ throw new Error(problems.join("\n"));
30
+ }, STDOUT_PURITY_TEST_TIMEOUT_MS);
19
31
  if (config.hasAuthCli && config.authCliBin) {
20
32
  it("auth-cli --help exits 0 and produces output", () => {
21
33
  const result = spawnCli(config, config.authCliBin, ["--help"]);
@@ -1,3 +1,11 @@
1
1
  import type { McpServerConfig } from "../types.js";
2
+ /**
3
+ * The probe can legitimately take its whole response deadline (startup), then
4
+ * the flush and the kill grace. The test timeout has to cover all three plus
5
+ * spawn overhead, or a slow-but-healthy server is killed by vitest instead of
6
+ * judged (mcp-bing-ads failed at 10.32s against an earlier 10s ceiling).
7
+ * tests/stdout-purity-timeout.test.ts pins the relationship.
8
+ */
9
+ export declare const STDOUT_PURITY_TEST_TIMEOUT_MS: number;
2
10
  export declare function stdoutPuritySuite(config: McpServerConfig): void;
3
11
  //# sourceMappingURL=stdout-purity.d.ts.map
@@ -8,121 +8,32 @@
8
8
  * client's schema validator to reject frames, typically with an
9
9
  * "unrecognized_keys: level, time, pid, hostname, msg" error.
10
10
  *
11
- * This suite spawns the real server as a subprocess with stdio piped
12
- * (non-TTY, matching how Claude Desktop launches it), sends a minimal
13
- * initialize + tools/list handshake, waits for activity, then inspects
14
- * stdout line by line. Every non-empty line must parse as JSON and have
15
- * `jsonrpc: "2.0"` set; no pino keys may appear at the top level.
11
+ * The server is started with fake credentials in a jailed env (see
12
+ * helpers/stdio-probe.ts), and an empty stdout FAILS: before 0.3.0 it passed,
13
+ * so for every consumer whose server exits at credential validation the
14
+ * check tested nothing.
16
15
  *
17
16
  * Why this suite exists: Mark's 2026-04-17 production incident, where
18
17
  * mcp-google-ads and mcp-ga4 both shipped with a logger gated on
19
18
  * `process.stderr.isTTY`. In Claude Desktop's non-TTY subprocess, pino
20
19
  * silently fell back to stdout and every MCP request failed.
21
20
  */
22
- import { spawn } from "child_process";
23
- import path from "path";
24
- import { describe, expect, it } from "vitest";
25
- const PINO_KEYS = ["level", "time", "pid", "hostname", "msg"];
21
+ import { describe, it } from "vitest";
22
+ import { probeStdioOnce, purityFailure, PROBE_RESPONSE_DEADLINE_MS, PROBE_FLUSH_MS, PROBE_KILL_GRACE_MS, } from "../helpers/stdio-probe.js";
23
+ /**
24
+ * The probe can legitimately take its whole response deadline (startup), then
25
+ * the flush and the kill grace. The test timeout has to cover all three plus
26
+ * spawn overhead, or a slow-but-healthy server is killed by vitest instead of
27
+ * judged (mcp-bing-ads failed at 10.32s against an earlier 10s ceiling).
28
+ * tests/stdout-purity-timeout.test.ts pins the relationship.
29
+ */
30
+ export const STDOUT_PURITY_TEST_TIMEOUT_MS = PROBE_RESPONSE_DEADLINE_MS + PROBE_FLUSH_MS + PROBE_KILL_GRACE_MS + 11_000;
26
31
  export function stdoutPuritySuite(config) {
27
32
  describe("stdout purity (MCP JSON-RPC channel)", () => {
28
33
  it("does not emit pino log fields on stdout under non-TTY stdio", async () => {
29
- const entry = config.serverEntry ?? "dist/index.js";
30
- const fullPath = path.resolve(config.repoRoot, entry);
31
- // Spawn exactly as Claude Desktop would: all three fds piped, not a TTY.
32
- // Pass startupEnv if defined so the server doesn't exit(1) on missing
33
- // creds before we get to exercise the logger.
34
- const proc = spawn("node", [fullPath], {
35
- cwd: config.repoRoot,
36
- stdio: ["pipe", "pipe", "pipe"],
37
- env: { ...process.env, ...(config.startupEnv ?? {}), LOG_LEVEL: "debug" },
38
- });
39
- let stdout = "";
40
- let stderr = "";
41
- proc.stdout?.on("data", (chunk) => { stdout += chunk.toString("utf8"); });
42
- proc.stderr?.on("data", (chunk) => { stderr += chunk.toString("utf8"); });
43
- // Send a minimal MCP initialize + tools/list so the server exercises
44
- // its request-handling code paths (which typically log something).
45
- const send = (msg) => proc.stdin?.write(JSON.stringify(msg) + "\n");
46
- send({
47
- jsonrpc: "2.0",
48
- id: 1,
49
- method: "initialize",
50
- params: {
51
- protocolVersion: "2024-11-05",
52
- capabilities: {},
53
- clientInfo: { name: "mcp-test-harness", version: "1.0.0" },
54
- },
55
- });
56
- send({ jsonrpc: "2.0", id: 2, method: "tools/list" });
57
- // Give the server time to respond and any background init logs to flush.
58
- // 2s is enough for local spawn + handshake; longer for slow credential
59
- // auth paths but we don't need to wait for those — we just need any
60
- // activity that would tickle the logger.
61
- await new Promise((r) => setTimeout(r, 2000));
62
- proc.kill("SIGTERM");
63
- await new Promise((r) => {
64
- const kill = setTimeout(() => { proc.kill("SIGKILL"); r(); }, 3000);
65
- proc.on("exit", () => { clearTimeout(kill); r(); });
66
- });
67
- // Empty stdout is fine — means server crashed or didn't respond. That's
68
- // a separate test's problem (smoke, mcp-protocol). We're only checking
69
- // that whatever IS on stdout is valid JSON-RPC, not pino pollution.
70
- const lines = stdout.split("\n").filter((l) => l.trim().length > 0);
71
- const offenders = [];
72
- for (const line of lines) {
73
- let parsed;
74
- try {
75
- parsed = JSON.parse(line);
76
- }
77
- catch {
78
- offenders.push(`non-JSON on stdout: ${line.slice(0, 200)}`);
79
- continue;
80
- }
81
- if (parsed.jsonrpc !== "2.0") {
82
- const keys = Object.keys(parsed).join(",");
83
- offenders.push(`stdout line missing jsonrpc:"2.0" (keys: ${keys}): ${line.slice(0, 200)}`);
84
- continue;
85
- }
86
- for (const k of PINO_KEYS) {
87
- if (k in parsed) {
88
- offenders.push(`stdout line has top-level pino key "${k}": ${line.slice(0, 200)}`);
89
- }
90
- }
91
- }
92
- if (offenders.length > 0) {
93
- const preview = offenders.slice(0, 5).join("\n - ");
94
- const more = offenders.length > 5 ? `\n ... and ${offenders.length - 5} more` : "";
95
- const hint = "\n\nFix: in your logger module, pass `pino.destination(2)` as the " +
96
- "SECOND argument to `pino(...)` unconditionally. Do not gate it on " +
97
- "`process.stderr.isTTY` — Claude Desktop spawns the server with pipes, " +
98
- "not a TTY, and pino will silently default to stdout when no " +
99
- "destination is specified.";
100
- throw new Error(`stdout contains non-JSON-RPC output (${offenders.length} offending line${offenders.length === 1 ? "" : "s"}):\n - ${preview}${more}` +
101
- `\n\nstderr tail (for context):\n${stderr.split("\n").slice(-10).join("\n")}` +
102
- hint);
103
- }
104
- // Weak positive assertion: at least confirm the server actually handled
105
- // the initialize (otherwise the test is vacuously passing). If stdout
106
- // is empty the server is probably crashing at startup — note that but
107
- // don't fail here; smoke suite owns startup correctness.
108
- if (lines.length === 0) {
109
- process.stderr.write("[stdout-purity] note: server produced no stdout output. Check smoke suite for startup failures.\n");
110
- }
111
- else {
112
- // If we got any output, at least one line should be an initialize response
113
- expect(lines.some((l) => l.includes('"id":1') || l.includes('"id": 1'))).toBe(true);
114
- }
115
- // This test spends 5s waiting on purpose (2s flush sleep + up to 3s for
116
- // the process to exit before SIGKILL). Everything left over is the budget
117
- // for spawning node, loading the server's modules, and whatever the
118
- // server does at startup — which for any server that validates
119
- // credentials before connecting its transport includes a network
120
- // round-trip. The previous 10s ceiling left only 5s for all of that, and
121
- // mcp-bing-ads failed at 10.32s in isolation (not parallel-load
122
- // contention) on exactly that margin.
123
- //
124
- // 30s leaves 25s of headroom. tests/stdout-purity-timeout.test.ts pins
125
- // the ceiling against the hardcoded waits so the two cannot drift apart.
126
- }, 30_000);
34
+ const failure = purityFailure(await probeStdioOnce(config));
35
+ if (failure)
36
+ throw new Error(failure);
37
+ }, STDOUT_PURITY_TEST_TIMEOUT_MS);
127
38
  });
128
39
  }
@@ -2,58 +2,44 @@ import { describe, it, expect } from "vitest";
2
2
  import path from "path";
3
3
  import os from "os";
4
4
  import { existsSync, readFileSync, writeFileSync, unlinkSync } from "fs";
5
+ import { importDistModule, pickFn } from "../helpers/dist-module.js";
5
6
  export function tokenLifecycleSuite(config) {
6
7
  describe("token lifecycle", () => {
7
- it("credentials.ts handles missing file gracefully", async () => {
8
- try {
9
- const mod = await import(path.join(config.repoRoot, "dist", "credentials.js"));
10
- const readFn = mod.readStoredCredentials ?? mod.readCredentials;
11
- if (!readFn)
12
- return;
13
- const result = readFn("/nonexistent/path/credentials.json");
14
- expect(result).toBeNull();
15
- }
16
- catch {
17
- // Module may not export this function -- skip
18
- }
8
+ // Skipped (visibly) when dist/credentials.js has no reader. A reader that
9
+ // throws, or returns anything but null for a bad file, fails. Messages
10
+ // report only null / not-null, never the value read.
11
+ const reader = async () => pickFn(await importDistModule(config, "credentials"), "readStoredCredentials", "readCredentials");
12
+ const expectNullFor = async (ctx, filePath, what) => {
13
+ const readFn = await reader();
14
+ if (!readFn)
15
+ return ctx.skip();
16
+ const result = readFn(filePath);
17
+ expect(result === null, `readStoredCredentials should return null for ${what}`).toBe(true);
18
+ };
19
+ it("credentials.ts handles missing file gracefully", async (ctx) => {
20
+ await expectNullFor(ctx, path.join(os.tmpdir(), `mcp-test-missing-${Date.now()}`, "credentials.json"), "a missing file");
19
21
  });
20
- it("credentials.ts handles corrupt JSON gracefully", async () => {
22
+ it("credentials.ts handles corrupt JSON gracefully", async (ctx) => {
21
23
  const tmpFile = path.join(os.tmpdir(), `mcp-test-corrupt-${Date.now()}.json`);
22
24
  writeFileSync(tmpFile, "{{{not json}}}");
23
25
  try {
24
- const mod = await import(path.join(config.repoRoot, "dist", "credentials.js"));
25
- const readFn = mod.readStoredCredentials ?? mod.readCredentials;
26
- if (!readFn)
27
- return;
28
- const result = readFn(tmpFile);
29
- expect(result).toBeNull();
30
- }
31
- catch (err) {
32
- // If it throws, that's a bug -- but some implementations may not have this function
26
+ await expectNullFor(ctx, tmpFile, "corrupt JSON");
33
27
  }
34
28
  finally {
35
29
  unlinkSync(tmpFile);
36
30
  }
37
31
  });
38
- it("credentials.ts handles wrong version field gracefully", async () => {
32
+ it("credentials.ts handles wrong version field gracefully", async (ctx) => {
39
33
  const tmpFile = path.join(os.tmpdir(), `mcp-test-version-${Date.now()}.json`);
40
34
  writeFileSync(tmpFile, JSON.stringify({ version: 999, refresh_token: "fake" }));
41
35
  try {
42
- const mod = await import(path.join(config.repoRoot, "dist", "credentials.js"));
43
- const readFn = mod.readStoredCredentials ?? mod.readCredentials;
44
- if (!readFn)
45
- return;
46
- const result = readFn(tmpFile);
47
- expect(result).toBeNull();
48
- }
49
- catch {
50
- // skip
36
+ await expectNullFor(ctx, tmpFile, "an unknown version field");
51
37
  }
52
38
  finally {
53
39
  unlinkSync(tmpFile);
54
40
  }
55
41
  });
56
- it("credential write sets restrictive file permissions", async () => {
42
+ it("credential write sets restrictive file permissions", () => {
57
43
  const credPath = path.join(config.repoRoot, config.srcDir ?? "src", "credentials.ts");
58
44
  if (!existsSync(credPath))
59
45
  return;
package/dist/types.d.ts CHANGED
@@ -25,7 +25,12 @@ export interface McpServerConfig {
25
25
  hasResilience: boolean;
26
26
  /** Does this server have platform.ts (cross-platform helpers)? */
27
27
  hasPlatform: boolean;
28
- /** Environment variable names the server checks for at startup */
28
+ /** Environment variable names the server checks for at startup.
29
+ * Every server the harness spawns gets a fake value for each one
30
+ * ("fake-<name>"), so list every var whose absence makes it exit.
31
+ * The smoke test "server starts with fake credentials and answers
32
+ * initialize and tools/list" fails if these are not enough; see the
33
+ * README section "Starting the server with fake credentials". */
29
34
  requiredEnvVars: string[];
30
35
  /** Env var prefix, e.g. "GOOGLE_ADS_" -- used for credential leak detection */
31
36
  envPrefix: string;
@@ -35,8 +40,11 @@ export interface McpServerConfig {
35
40
  srcDir?: string;
36
41
  /** Entry point for the MCP server relative to repo root (default: "dist/index.js") */
37
42
  serverEntry?: string;
38
- /** Env vars to set when spawning the server for smoke/shutdown tests.
39
- * Set dummy values so the server doesn't exit(1) on missing creds. */
43
+ /** Extra fake env for spawned servers, laid over the requiredEnvVars fakes:
44
+ * values whose format the server checks (a numeric customer id), vars it
45
+ * needs but does not list, or a skip flag. Never put a real secret here:
46
+ * spawned servers run in a hermetic env (no inherited env, throwaway HOME)
47
+ * with outbound network and the macOS `security` CLI blocked. */
40
48
  startupEnv?: Record<string, string>;
41
49
  /** Patterns to skip in source-lint (e.g. files that legitimately use platform APIs) */
42
50
  sourceLintIgnore?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drak-marketing/mcp-test-harness",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Shared test harness for MCP server repos. Parameterized test suites for build integrity, smoke tests, protocol conformance, security, and more.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,10 +15,12 @@
15
15
  "dist/**/*.js",
16
16
  "dist/**/*.d.ts",
17
17
  "README.md",
18
+ "CHANGELOG.md",
18
19
  "LICENSE"
19
20
  ],
20
21
  "scripts": {
21
22
  "build": "tsc",
23
+ "pretest": "npm run build",
22
24
  "test": "vitest run",
23
25
  "typecheck": "tsc --noEmit",
24
26
  "prepublishOnly": "npm run build"
@@ -1,3 +0,0 @@
1
- import type { McpServerConfig } from "../types.js";
2
- export declare function concurrentSuite(config: McpServerConfig): void;
3
- //# sourceMappingURL=concurrent.d.ts.map
@@ -1,25 +0,0 @@
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
- }