Files
reverse-engineering-anything/tests/acceptance/providers/jebConfigurationIsolation.test.ts
T
ShuaixinHuang d67d895c26 fix(jeb): isolate invalid timeout from shared startup (#3964)
Keep malformed JEB-only timeouts isolated from shared CLI/MCP startup while strict registration and JEB configuration checks remain authoritative. Cover built CLI discovery and the production stdio MCP refusal and peer requests.

Original contribution by @ShuaixinHuang.

Co-authored-by: ShuaixinHuang <1836656514@qq.com>
2026-10-16 01:03:39 +08:00

97 lines
3.1 KiB
TypeScript

import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { resolve } from "node:path";
import { expect } from "vitest";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { workspaceCliTest as test } from "../../support/cli/workspaceCliFixture.js";
import type { TestWorkspace } from "../../support/workspace/workspaceFixture.js";
const isolatedEnvironment = (workspace: TestWorkspace) => ({
PATH: "",
HOME: workspace.home,
USERPROFILE: workspace.home,
APPDATA: workspace.path("appdata"),
LOCALAPPDATA: workspace.path("localappdata"),
XDG_CONFIG_HOME: workspace.path("config"),
XDG_CACHE_HOME: workspace.path("cache"),
TEMP: workspace.root,
TMP: workspace.root,
...(process.platform === "win32"
? { SystemRoot: process.env.SystemRoot ?? "" }
: {}),
HOPPER_LAUNCHER_PATH: workspace.path("missing-hopper"),
REA_LOG_LEVEL: "silent",
REA_JEB_MCP_TIMEOUT_MS: "1.5",
});
test("keeps compiled CLI discovery usable while JEB rejects its malformed timeout", async ({
cli,
workspace,
}) => {
const environment = isolatedEnvironment(workspace);
for (const command of ["capabilities", "providers"]) {
const result = await cli.run({
arguments: [command, "--json"],
environment,
});
expect(result.exitCode, result.stderr).toBe(0);
expect(result.json).toMatchObject({
capabilities: expect.arrayContaining([
expect.objectContaining({
provider: expect.objectContaining({ id: "rea-artifact-graph" }),
}),
]),
});
}
const refusal = await cli.run({
arguments: ["inspect-jeb-client", "--json"],
environment,
});
expect(refusal.exitCode, refusal.stderr).toBe(1);
expect(refusal.json).toMatchObject({
code: "configuration_invalid",
details: { settings: [{ setting: "REA_JEB_MCP_TIMEOUT_MS" }] },
});
});
test("starts production stdio MCP and retains peer requests around a JEB configuration refusal", async ({
workspace,
}) => {
const transport = new StdioClientTransport({
command: process.execPath,
args: [resolve("scripts/rea.mjs"), "mcp"],
cwd: workspace.root,
env: isolatedEnvironment(workspace),
stderr: "pipe",
});
const client = new Client({ name: "jeb-isolation-acceptance", version: "1" });
let stderr = "";
transport.stderr?.on("data", (chunk: Buffer) => {
stderr += chunk.toString("utf8");
});
try {
await client.connect(transport);
await client.ping();
const definition = (await client.listTools()).tools.find(
({ name }) => name === "inspect_jeb_client",
);
if (definition === undefined)
throw new Error(`Production MCP omitted inspect_jeb_client: ${stderr}`);
const refusal = parseMcpToolError(
await client.callTool(
{ name: "inspect_jeb_client", arguments: {} },
{ toolDefinition: definition },
),
);
expect(refusal.error).toMatchObject({
code: "configuration_invalid",
details: { settings: [{ setting: "REA_JEB_MCP_TIMEOUT_MS" }] },
});
await client.ping();
} finally {
await client.close();
await transport.close();
}
});