mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 07:16:13 +00:00
Use one typed-checker worker by default without changing semantic scope or caller overrides. Reuse the bounded CLI worker for pure argument validation while retaining fresh-process coverage and all upstream cases. Keep registration tests independent of real package-runner downloads while asserting the actual prewarm command and startup context. Pass the advertised binary_session definition by name to package verification, retaining default SDK validation and complete catalog/contract checks while avoiding compilation of unrelated tool outputs. Preserve all four installed-tarball scenarios and existing deadlines. Strengthen Hermes preview operation/backup assertions and clarify physical-path routing documentation. Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
134 lines
4.3 KiB
TypeScript
134 lines
4.3 KiB
TypeScript
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
import { delimiter, join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { z } from "zod";
|
|
import { packageRunnerRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
|
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const ompConfigurationSchema = z.object({
|
|
mcpServers: z.object({
|
|
rea: z.object({ command: z.string(), args: z.array(z.string()) }),
|
|
}),
|
|
});
|
|
|
|
const controlledRunnerFixture = async (home: string) => {
|
|
const bin = join(home, "bin");
|
|
const script = join(home, "runner-fixture.cjs");
|
|
const log = join(home, "runner-calls.jsonl");
|
|
await mkdir(bin);
|
|
await writeFile(log, "");
|
|
await writeFile(
|
|
script,
|
|
`const { appendFileSync } = require("node:fs");
|
|
appendFileSync(process.env.REA_TEST_RUNNER_LOG, JSON.stringify({
|
|
runner: process.argv[2],
|
|
arguments: process.argv.slice(3),
|
|
home: process.env.HOME,
|
|
npm_command: process.env.npm_command,
|
|
user_agent: process.env.npm_config_user_agent,
|
|
}) + "\\n");
|
|
console.log("controlled runner fixture");
|
|
`,
|
|
);
|
|
for (const runner of ["npx", "bunx"]) {
|
|
await writeFile(
|
|
join(bin, process.platform === "win32" ? `${runner}.cmd` : runner),
|
|
process.platform === "win32"
|
|
? `@echo off\r\n"%REA_TEST_NODE%" "%REA_TEST_RUNNER_SCRIPT%" ${runner} %*\r\n`
|
|
: `#!/bin/sh\nexec "$REA_TEST_NODE" "$REA_TEST_RUNNER_SCRIPT" ${runner} "$@"\n`,
|
|
{ mode: 0o700 },
|
|
);
|
|
}
|
|
return {
|
|
log,
|
|
environment: {
|
|
PATH: [bin, process.env.PATH ?? ""].join(delimiter),
|
|
REA_TEST_NODE: process.execPath,
|
|
REA_TEST_RUNNER_SCRIPT: script,
|
|
REA_TEST_RUNNER_LOG: log,
|
|
},
|
|
};
|
|
};
|
|
|
|
// Package runners set these variables for the bin they launch from a temporary cache.
|
|
// Only the prewarm child is controlled; each CLI still starts with its runner identity.
|
|
for (const { runner, userAgent } of [
|
|
{ runner: "npx", userAgent: "npm/10.9.0 node/v24.11.0 linux x64" },
|
|
{ runner: "bunx", userAgent: "bun/1.4.2 npm/? node/v26.3.0 linux x64" },
|
|
] as const) {
|
|
cliTest(
|
|
`${runner} setup registers the pinned ${runner} launcher instead of its cache`,
|
|
async ({ cli }) => {
|
|
const home = await createTestTempDirectory("rea-package-runner-");
|
|
const controlledRunner = await controlledRunnerFixture(home);
|
|
const run = (arguments_: readonly string[]) =>
|
|
cli.run({
|
|
arguments: arguments_,
|
|
cwd: home,
|
|
environment: {
|
|
...controlledRunner.environment,
|
|
HOME: home,
|
|
USERPROFILE: home,
|
|
npm_command: "exec",
|
|
npm_config_user_agent: userAgent,
|
|
},
|
|
timeoutMs: 20_000,
|
|
});
|
|
const setup = await run([
|
|
"setup",
|
|
"--client",
|
|
"omp",
|
|
"--no-skill",
|
|
"--yes",
|
|
"--json",
|
|
]);
|
|
expect(setup.exitCode).toBe(0);
|
|
expect(setup.json).toMatchObject({
|
|
status: "ready",
|
|
prewarm: { status: "warmed" },
|
|
});
|
|
const configuration = ompConfigurationSchema.parse(
|
|
JSON.parse(
|
|
await readFile(join(home, ".omp", "agent", "mcp.json"), "utf8"),
|
|
),
|
|
);
|
|
const { command, args } = configuration.mcpServers.rea;
|
|
expect([command, ...args]).toEqual(
|
|
packageRunnerRegistrationCommand(runner, process.platform),
|
|
);
|
|
const doctor = await run(["doctor", "--client", "omp", "--json"]);
|
|
expect(doctor.json).toMatchObject({
|
|
identity: { registrations: [{ client: "omp", state: "aligned" }] },
|
|
});
|
|
const repeat = await run([
|
|
"setup",
|
|
"--client",
|
|
"omp",
|
|
"--no-skill",
|
|
"--dry-run",
|
|
"--json",
|
|
]);
|
|
expect(repeat.json).toMatchObject({ plannedActions: [] });
|
|
const calls = (await readFile(controlledRunner.log, "utf8"))
|
|
.trim()
|
|
.split("\n")
|
|
.map((line) => JSON.parse(line));
|
|
expect(calls).toEqual([
|
|
{
|
|
runner,
|
|
arguments: [
|
|
...(runner === "npx" ? ["-y"] : []),
|
|
PRODUCT_IDENTITY.registrationPackageSpecifier,
|
|
"--version",
|
|
],
|
|
home,
|
|
npm_command: "exec",
|
|
user_agent: userAgent,
|
|
},
|
|
]);
|
|
},
|
|
);
|
|
}
|