mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 11:01:11 +00:00
* fix(config): validate target and loader options before printing MCP registrations
* Preserve executable mode of MCP configuration helper
* Format MCP config CLI and its validation tests
* Run MCP configuration printer regressions in the process boundary suite
Move the config printer's valid, invalid and help cases into the registered MCP launcher Vitest suite. Run the real script with the test-scoped process fixture so CI owns each child and checks its output and exit code.
* test: align verification fixtures with current public contracts
Keep the production changes from upstream and update the verification consumers that still asserted their retired contracts:
- assert unknown workflow identity structurally and retain the bounded provider caveats;
- observe the process capture's partial-error delivery while preserving live cleanup ownership assertions;
- use the package's declared imports in the isolated release controller;
- refresh the replay card digest after the Evidence subject identity migration;
- use the supported compact Kimi profile while testing case-insensitive environment keys;
- assert each public interface's own capture issue path.
These are shared test and verifier compatibility repairs. The evidence summary pagination and config-printer feature changes remain separate.
* test(mcp): observe Kuna close failures at the session owner
Read the original session.close promise result when checking cleanup retry guidance. This keeps the real typed error and all retry assertions while avoiding the retired delivery path after upstream #11647.
* test(mcp): assert DOL snapshots through target identity
Follow the upstream target identity migration in ff017625 (#11551). Preserve the exact DOL format, architecture and entry-point assertions together with the snapshot replay and provider-call checks.
* test: align CLI and progress fixtures with shared owners
Reuse the core registrar for decompile-all instead of registering it twice
after upstream #11680. Assert the outer MCP start/completion notifications
separately from provider cleanup progress introduced by #11637, retaining
cleanup, rate, timeout, cancellation, and evidence assertions.
---------
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
230 lines
7.1 KiB
TypeScript
230 lines
7.1 KiB
TypeScript
import { spawn } from "node:child_process";
|
|
import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { expect, it, onTestFinished } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { processTest } from "../../support/process/processFixture.js";
|
|
|
|
const launcher = fileURLToPath(
|
|
new URL("../../../scripts/plugin-mcp-launcher.mjs", import.meta.url),
|
|
);
|
|
|
|
const pluginFixture = async (runtime: string) => {
|
|
const workspace = await createTestTempDirectory("rea-plugin-");
|
|
const root = join(workspace, "plugin with spaces");
|
|
await mkdir(root);
|
|
await mkdir(join(root, "scripts"));
|
|
await mkdir(join(root, "dist/mcp"), { recursive: true });
|
|
const entry = join(root, "scripts/plugin-mcp-launcher.mjs");
|
|
await copyFile(launcher, entry);
|
|
await writeFile(
|
|
join(root, "package.json"),
|
|
JSON.stringify({ name: "rea-agents", version: "6.8.0", type: "module" }),
|
|
);
|
|
await writeFile(join(root, "dist/mcp/main.js"), "");
|
|
await writeFile(join(root, "scripts/rea.mjs"), runtime);
|
|
return { root, entry };
|
|
};
|
|
|
|
const start = (entry: string, cwd: string, args = ["6.8.0"]) => {
|
|
const child = spawn(process.execPath, [entry, ...args], {
|
|
cwd,
|
|
stdio: "pipe",
|
|
});
|
|
let stdout = "";
|
|
let stderr = "";
|
|
child.stdout.on("data", (bytes: Buffer) => {
|
|
stdout += bytes.toString();
|
|
});
|
|
child.stderr.on("data", (bytes: Buffer) => {
|
|
stderr += bytes.toString();
|
|
});
|
|
const closed = new Promise<{
|
|
code: number | null;
|
|
stdout: string;
|
|
stderr: string;
|
|
}>((resolve, reject) => {
|
|
child.once("error", reject);
|
|
child.once("close", (code) => resolve({ code, stdout, stderr }));
|
|
});
|
|
onTestFinished(async () => {
|
|
if (child.exitCode === null && child.signalCode === null)
|
|
child.kill("SIGKILL");
|
|
await closed;
|
|
});
|
|
return { child, closed };
|
|
};
|
|
|
|
it("runs the matching runtime in-process and preserves cwd, stdio, and exit status", async () => {
|
|
const { root, entry } = await pluginFixture(`
|
|
process.stderr.write(JSON.stringify({ pid: process.pid, args: process.argv.slice(2), cwd: process.cwd() }));
|
|
process.stdin.pipe(process.stdout);
|
|
process.stdin.on("end", () => { process.exitCode = 7; });
|
|
`);
|
|
const caller = await createTestTempDirectory("rea-plugin-caller-");
|
|
const cwd = join(caller, "caller with spaces");
|
|
await mkdir(cwd);
|
|
// Built source plugins and npm artifacts use the same runtime owner.
|
|
await writeFile(join(root, ".git"), "gitdir: /fixture/worktree");
|
|
const { child, closed } = start(entry, cwd);
|
|
child.stdin.end('{"jsonrpc":"2.0","id":1}\n');
|
|
const result = await closed;
|
|
expect(result).toMatchObject({
|
|
code: 7,
|
|
stdout: '{"jsonrpc":"2.0","id":1}\n',
|
|
});
|
|
expect(JSON.parse(result.stderr)).toEqual({
|
|
pid: child.pid,
|
|
args: ["mcp"],
|
|
cwd,
|
|
});
|
|
});
|
|
|
|
it.each([["latest"], ["6.8.0&echo wrong"], ["6.8.0", "extra"], []])(
|
|
"rejects a non-exact or extra version argument: %j",
|
|
async (...args) => {
|
|
const { root, entry } = await pluginFixture(
|
|
'process.stdout.write("unexpected");',
|
|
);
|
|
const { child, closed } = start(entry, root, args);
|
|
child.stdin.end();
|
|
expect(await closed).toEqual({
|
|
code: 1,
|
|
stdout: "",
|
|
stderr: "REA plugin requires one exact rea-agents@VERSION pin.\n",
|
|
});
|
|
},
|
|
);
|
|
|
|
it("rejects a mismatched runtime instead of downloading another package", async () => {
|
|
const { root, entry } = await pluginFixture(
|
|
'process.stdout.write("unexpected");',
|
|
);
|
|
const { child, closed } = start(entry, root, ["6.7.0"]);
|
|
child.stdin.end();
|
|
expect(await closed).toEqual({
|
|
code: 1,
|
|
stdout: "",
|
|
stderr:
|
|
"REA plugin version pin does not match its installed rea-agents package; reinstall the plugin.\n",
|
|
});
|
|
});
|
|
|
|
it("reports how to repair an incomplete artifact or unbuilt source checkout", async () => {
|
|
const { root, entry } = await pluginFixture(
|
|
'process.stdout.write("unexpected");',
|
|
);
|
|
await rm(join(root, "dist"), { recursive: true });
|
|
const { child, closed } = start(entry, root);
|
|
child.stdin.end();
|
|
expect(await closed).toEqual({
|
|
code: 1,
|
|
stdout: "",
|
|
stderr:
|
|
"REA plugin runtime is missing; reinstall the plugin, or run npm ci && npm run build:cached in a source checkout.\n",
|
|
});
|
|
});
|
|
|
|
it("preserves runtime startup failures", async () => {
|
|
const { root, entry } = await pluginFixture(
|
|
'throw new Error("runtime failed");',
|
|
);
|
|
const { child, closed } = start(entry, root);
|
|
child.stdin.end();
|
|
const result = await closed;
|
|
expect(result.code).toBe(1);
|
|
expect(result.stdout).toBe("");
|
|
expect(result.stderr).toContain("runtime failed");
|
|
});
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"leaves signal cleanup with the running REA runtime",
|
|
async () => {
|
|
const { root, entry } = await pluginFixture(`
|
|
process.on("SIGTERM", () => { process.stderr.write("cleaned"); process.exit(0); });
|
|
process.stdin.resume();
|
|
process.stdout.write("ready");
|
|
`);
|
|
const { child, closed } = start(entry, root);
|
|
await new Promise<void>((resolve, reject) => {
|
|
child.stdout.once("data", () => resolve());
|
|
child.once("error", reject);
|
|
child.once("exit", () =>
|
|
reject(new Error("runtime exited before readiness")),
|
|
);
|
|
});
|
|
child.kill("SIGTERM");
|
|
expect(await closed).toEqual({
|
|
code: 0,
|
|
stdout: "ready",
|
|
stderr: "cleaned",
|
|
});
|
|
},
|
|
);
|
|
|
|
const configPrinter = fileURLToPath(
|
|
new URL("../../../scripts/print-mcp-config.mjs", import.meta.url),
|
|
);
|
|
|
|
processTest(
|
|
"prints a startup config with explicit loader arguments",
|
|
async ({ processes }) => {
|
|
const result = await processes.run(process.execPath, [
|
|
configPrinter,
|
|
"--kind",
|
|
"database",
|
|
"example",
|
|
"--loader-args",
|
|
'["-l","a b"]',
|
|
]);
|
|
expect(result.exitCode, result.stderr).toBe(0);
|
|
const { env } = JSON.parse(result.stdout).mcpServers.rea;
|
|
expect(env.HOPPER_TARGET_KIND).toBe("database");
|
|
expect(JSON.parse(env.HOPPER_LOADER_ARGS_JSON)).toEqual(["-l", "a b"]);
|
|
},
|
|
);
|
|
|
|
processTest(
|
|
"invalid config invocations cannot print an apparently usable registration",
|
|
async ({ processes }) => {
|
|
for (const args of [
|
|
[],
|
|
["a", "b"],
|
|
["target", "--knid", "database"],
|
|
["target", "--kind"],
|
|
["target", "--kind", "unknown"],
|
|
["target", "--kind", "database", "--kind", "executable"],
|
|
["target", "--loader-args", "invalid"],
|
|
["target", "--loader-args", "[1]"],
|
|
["target", "--loader-args", '["a\\u0000b"]'],
|
|
]) {
|
|
const result = await processes.run(process.execPath, [
|
|
configPrinter,
|
|
...args,
|
|
]);
|
|
expect(result, JSON.stringify(args)).toMatchObject({
|
|
exitCode: 1,
|
|
stdout: "",
|
|
stderr: expect.stringMatching(/Usage:/),
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
processTest(
|
|
"config help describes the generator without emitting a registration",
|
|
async ({ processes }) => {
|
|
const result = await processes.run(process.execPath, [
|
|
configPrinter,
|
|
"--help",
|
|
]);
|
|
expect(result).toMatchObject({
|
|
exitCode: 0,
|
|
stdout: expect.stringMatching(/^Usage:/),
|
|
stderr: "",
|
|
});
|
|
},
|
|
);
|