Files

55 lines
1.5 KiB
JavaScript

// Start an isolated server, then exercise its separate stdio MCP through the real SDK.
// --binary is the server; --mcp-binary selects the independent MCP executable.
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import path from "node:path";
import { harness, options, root } from "./server-harness.mjs";
const opts = options();
opts.port ??= "4002";
opts.binary ??= path.join(root, "target/release/shacraft-server");
const mcpBinary = path.resolve(
opts["mcp-binary"] ||
path.join(path.dirname(path.resolve(opts.binary)), "shacraft-mcp"),
);
const h = await harness(opts);
try {
const script = path.join(root, "crates/shacraft-mcp/tests/sdk-smoke.mjs");
const args = [
script,
"--binary",
mcpBinary,
"--server",
h.url,
"--data",
h.data,
];
if (opts.sdk) args.push("--sdk", opts.sdk);
const { stdout, stderr } = await promisify(execFile)(process.execPath, args, {
cwd: root,
env: process.env,
timeout: 120000,
maxBuffer: 8 * 1024 * 1024,
});
if (stderr.trim()) throw Error(`SDK smoke stderr: ${stderr.trim()}`);
const sdk = JSON.parse(stdout);
await h.report({
passed: true,
server_binary: h.binary,
mcp_binary: mcpBinary,
...sdk,
});
} catch (error) {
await h.report({
passed: false,
server_binary: h.binary,
mcp_binary: mcpBinary,
error: error.stack,
stdout: error.stdout,
stderr: error.stderr,
server_logs: h.logs(),
});
throw error;
} finally {
await h.stop();
}