fix(setup): register a stable launcher when run through bunx (#1731)
Setup run through bunx or bun x registered the bin inside bun's temporary package cache. Detect bun's package-runner launch from npm_command=exec with a bun user agent and register the pinned bunx launcher, wrapped in cmd.exe on Windows like the npx launcher. Doctor, update maintenance and uninstall recognize it as REA-owned, and setup's printed commands name the runner that launched it. Read the runner variables case-insensitively on Windows, where the CLI environment snapshot upper-cases variable names and setup run through npx also fell back to the cache path. Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -216,11 +216,20 @@ describe("interactive setup journey", () => {
|
||||
|
||||
describe("interactive setup completion", () => {
|
||||
it.each([
|
||||
{ npmCommand: "", launcher: "rea" },
|
||||
{ npmCommand: "exec", launcher: "npx rea-agents" },
|
||||
{ npmCommand: "", userAgent: "", launcher: "rea" },
|
||||
{
|
||||
npmCommand: "exec",
|
||||
userAgent: "npm/10.9.0 node/v24.11.0 linux x64",
|
||||
launcher: "npx rea-agents",
|
||||
},
|
||||
{
|
||||
npmCommand: "exec",
|
||||
userAgent: "bun/1.4.2 npm/? node/v26.3.0 linux x64",
|
||||
launcher: "bunx rea-agents",
|
||||
},
|
||||
])(
|
||||
"prints an available next command for $launcher invocation",
|
||||
async ({ npmCommand, launcher }) => {
|
||||
async ({ npmCommand, userAgent, launcher }) => {
|
||||
const { stderr } = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
@@ -246,7 +255,12 @@ describe("interactive setup completion", () => {
|
||||
],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: { ...process.env, npm_command: npmCommand, NO_COLOR: "1" },
|
||||
env: {
|
||||
...process.env,
|
||||
npm_command: npmCommand,
|
||||
npm_config_user_agent: userAgent,
|
||||
NO_COLOR: "1",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { packageRunnerRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.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()) }),
|
||||
}),
|
||||
});
|
||||
|
||||
// Package runners set these variables for the bin they launch from a temporary cache.
|
||||
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 run = (arguments_: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: arguments_,
|
||||
cwd: home,
|
||||
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" });
|
||||
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: [] });
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -486,6 +486,16 @@ describe("platform-aware client config paths", () => {
|
||||
expect(
|
||||
isOwnedClientRegistrationCommand(["npx", "-y", "another-package", "mcp"]),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isOwnedClientRegistrationCommand([
|
||||
"bunx",
|
||||
`${PRODUCT_IDENTITY.packageName}@3.2.0`,
|
||||
"mcp",
|
||||
]),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isOwnedClientRegistrationCommand(["bunx", "another-package", "mcp"]),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isOwnedClientRegistrationCommand(
|
||||
[process.execPath, "/packaged/rea.mjs", "mcp"],
|
||||
|
||||
@@ -56,7 +56,7 @@ it.each([
|
||||
expect.objectContaining({ client: "claude_code", state: "stale" }),
|
||||
);
|
||||
const client = { name: "claude_code", configPath, format: "json" } as const;
|
||||
const command = setupRegistrationCommand("win32", true);
|
||||
const command = setupRegistrationCommand("win32", "npx");
|
||||
expect(
|
||||
await configureClientConfiguration(client, {}, command),
|
||||
).toMatchObject({ status: "configured" });
|
||||
@@ -83,35 +83,38 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the Windows launcher aligned through Codex TOML setup and removal", async () => {
|
||||
const home = await createTestTempDirectory("rea-windows-codex-");
|
||||
await mkdir(join(home, ".codex"));
|
||||
const configPath = join(home, ".codex", "config.toml");
|
||||
const original =
|
||||
'\uFEFF# Keep this explanation.\nnotify = ["a", "b"]\nliteral = \'C:\\demo\\path\'\ndisabled_mcp_servers = ["rea"]\n\n[mcp_servers.other]\ncommand = "another-server"\n';
|
||||
await writeFile(configPath, original);
|
||||
const client = { name: "codex", configPath, format: "toml" } as const;
|
||||
const command = setupRegistrationCommand("win32", true);
|
||||
expect(await configureClientConfiguration(client, {}, command)).toMatchObject(
|
||||
{ status: "configured" },
|
||||
);
|
||||
expect(
|
||||
await readClientRegistrationStatuses(home, undefined, {
|
||||
platform: "win32",
|
||||
environment: {},
|
||||
}),
|
||||
).toContainEqual(
|
||||
expect.objectContaining({ client: "codex", state: "aligned" }),
|
||||
);
|
||||
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
||||
status: "unchanged",
|
||||
});
|
||||
expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(original);
|
||||
expect(await systemUninstallHost(home).removeClient(client)).toMatchObject({
|
||||
status: "removed",
|
||||
});
|
||||
expect(await readFile(configPath, "utf8")).toBe(original);
|
||||
});
|
||||
it.each(["npx", "bunx"] as const)(
|
||||
"keeps the Windows %s launcher aligned through Codex TOML setup and removal",
|
||||
async (runner) => {
|
||||
const home = await createTestTempDirectory("rea-windows-codex-");
|
||||
await mkdir(join(home, ".codex"));
|
||||
const configPath = join(home, ".codex", "config.toml");
|
||||
const original =
|
||||
'\uFEFF# Keep this explanation.\nnotify = ["a", "b"]\nliteral = \'C:\\demo\\path\'\ndisabled_mcp_servers = ["rea"]\n\n[mcp_servers.other]\ncommand = "another-server"\n';
|
||||
await writeFile(configPath, original);
|
||||
const client = { name: "codex", configPath, format: "toml" } as const;
|
||||
const command = setupRegistrationCommand("win32", runner);
|
||||
expect(
|
||||
await configureClientConfiguration(client, {}, command),
|
||||
).toMatchObject({ status: "configured" });
|
||||
expect(
|
||||
await readClientRegistrationStatuses(home, undefined, {
|
||||
platform: "win32",
|
||||
environment: {},
|
||||
}),
|
||||
).toContainEqual(
|
||||
expect.objectContaining({ client: "codex", state: "aligned" }),
|
||||
);
|
||||
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
||||
status: "unchanged",
|
||||
});
|
||||
expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(original);
|
||||
expect(await systemUninstallHost(home).removeClient(client)).toMatchObject({
|
||||
status: "removed",
|
||||
});
|
||||
expect(await readFile(configPath, "utf8")).toBe(original);
|
||||
},
|
||||
);
|
||||
|
||||
it("retains rea-named custom shell registrations without writing a backup", async () => {
|
||||
const home = await createTestTempDirectory("rea-custom-shell-registration-");
|
||||
@@ -124,6 +127,9 @@ it("retains rea-named custom shell registrations without writing a backup", asyn
|
||||
["cmd.exe", "/c", "npx", "-y", "another-package", "mcp"],
|
||||
["cmd.exe", "/c", "npx", "-y", "rea-agents@5.0.0", "mcp", "&", "other"],
|
||||
["cmd.exe", "/c", "npx", "-y", "rea-agents@5.0.0 & other", "mcp"],
|
||||
["cmd.exe", "/c", "bunx", "another-package", "mcp"],
|
||||
["cmd.exe", "/c", "bunx", "-y", "rea-agents@5.0.0", "mcp"],
|
||||
["cmd.exe", "/c", "bunx", "rea-agents@5.0.0", "mcp", "&", "other"],
|
||||
]) {
|
||||
const original = JSON.stringify({
|
||||
mcpServers: { rea: { command: command[0], args: command.slice(1) } },
|
||||
@@ -139,9 +145,12 @@ it("retains rea-named custom shell registrations without writing a backup", asyn
|
||||
}
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"starts the written Windows registration through a native npx.cmd shim",
|
||||
async () => {
|
||||
it.skipIf(process.platform !== "win32").each([
|
||||
["npx", ["-y", PRODUCT_IDENTITY.registrationPackageSpecifier, "mcp"]],
|
||||
["bunx", [PRODUCT_IDENTITY.registrationPackageSpecifier, "mcp"]],
|
||||
] as const)(
|
||||
"starts the written Windows registration through a native %s.cmd shim",
|
||||
async (runner, shimArguments) => {
|
||||
const root = await createTestTempDirectory("rea-windows-mcp-");
|
||||
const home = join(root, "home with spaces");
|
||||
await mkdir(home);
|
||||
@@ -151,26 +160,29 @@ it.skipIf(process.platform !== "win32")(
|
||||
configPath,
|
||||
format: "json",
|
||||
} as const;
|
||||
const command = setupRegistrationCommand("win32", runner);
|
||||
// The default writer and npm-run setup must produce the same native launcher.
|
||||
expect(await configureClientConfiguration(setupClient)).toMatchObject({
|
||||
status: "configured",
|
||||
});
|
||||
expect(
|
||||
await (runner === "npx"
|
||||
? configureClientConfiguration(setupClient)
|
||||
: configureClientConfiguration(setupClient, {}, command)),
|
||||
).toMatchObject({ status: "configured" });
|
||||
const decoded: unknown = JSON.parse(await readFile(configPath, "utf8"));
|
||||
const registration = configurationSchema.parse(decoded).mcpServers.rea;
|
||||
expect([registration.command, ...registration.args]).toEqual(
|
||||
setupRegistrationCommand("win32", true),
|
||||
);
|
||||
expect([registration.command, ...registration.args]).toEqual(command);
|
||||
const entry = fileURLToPath(
|
||||
new URL("../../../scripts/rea.mjs", import.meta.url),
|
||||
);
|
||||
// Exercise the actual batch-shim boundary without registry access or package installation.
|
||||
await writeFile(
|
||||
join(home, "npx.cmd"),
|
||||
join(home, `${runner}.cmd`),
|
||||
[
|
||||
"@echo off",
|
||||
'if not "%~1"=="-y" exit /b 11',
|
||||
`if not "%~2"=="${PRODUCT_IDENTITY.registrationPackageSpecifier}" exit /b 12`,
|
||||
'if not "%~3"=="mcp" exit /b 13',
|
||||
...shimArguments.map(
|
||||
(argument, index) =>
|
||||
`if not "%~${String(index + 1)}"=="${argument}" exit /b ${String(11 + index)}`,
|
||||
),
|
||||
`if not "%~${String(shimArguments.length + 1)}"=="" exit /b 19`,
|
||||
`"${process.execPath}" "${entry}" mcp`,
|
||||
"",
|
||||
].join("\r\n"),
|
||||
|
||||
Reference in New Issue
Block a user