mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 19:09:21 +00:00
* fix(setup): do not persist versioned launcher paths A command saved from nvm, Volta, Homebrew Cellar, mise, or a package cache stops launching after an upgrade or prune, and doctor then treats that registration as foreign. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(setup): recognize default nvm installation layouts The usual POSIX install is ~/.nvm/versions/node, and nvm-windows stores each release in nvm\v<version>. Both were still saved, and the launcher guide still told setup to keep a cache path. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(setup): keep durable Windows and mise launcher paths Default Windows Volta and pnpm dlx stores were still persisted, and mise's stable latest alias was dropped before the Aube launcher could use it. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(setup): keep a mise shim when Node itself is versioned A versioned running runtime was rejected before a durable Node alias could be selected, and fnm's installed tree was still saved. Doctor now tells version-manager and package-cache paths apart from a session directory. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(setup): reject versioned aube store targets and align install routes Reject version-tagged node_modules/.mise store targets beneath mise latest aliases (while keeping verified outer Aube shims), reject asdf/nodenv/nvs/nix/snap versioned paths, fix the nvm-sensitive Windows runtime assertion in setupLauncherAlias tests, and align installation docs, install.sh, and getting-started guidance with durable-path registration. * fix(setup): recognize custom manager env roots and align onboarding docs Pass environment through versionedLauncherPath and transientLauncherRemediation so custom version-manager env roots are classified accurately while preserving fnm_multishells as a session path; fix Windows PowerShell rea.cmd and Linux PATH persistence in get-started; align remaining setup quick starts and affected setup acceptance/boundary tests. * fix(setup): reject session paths and configured package caches Windows fnm session directories and custom npm or Bun cache roots were still eligible for client registration. Quick starts now require a durable Node install, and the website setup copy no longer uses a PowerShell-invalid command chain. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(setup): resolve configured launcher roots * docs(setup): align persistent launcher prerequisites * docs(setup): persist paths in Bash login profiles * fix(setup): name the missing saved launcher path * fix(setup): reject Bunx execution-cache launchers * docs(setup): add writable npm prefix prerequisite * style(website): format prefix prerequisites * chore(website): format setup introduction --------- Co-authored-by: Ambuj Agrawal <aseachambuj@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
248 lines
7.6 KiB
TypeScript
248 lines
7.6 KiB
TypeScript
import {
|
|
access,
|
|
mkdir,
|
|
readFile,
|
|
rename,
|
|
symlink,
|
|
writeFile,
|
|
} from "node:fs/promises";
|
|
import { dirname, delimiter, join, resolve } from "node:path";
|
|
import { Client } from "@modelcontextprotocol/client";
|
|
import {
|
|
StdioClientTransport,
|
|
getDefaultEnvironment,
|
|
} from "@modelcontextprotocol/client/stdio";
|
|
import { expect } from "vitest";
|
|
import { z } from "zod";
|
|
import { npmInvocation } from "../../../scripts/lib/npm-invocation.mjs";
|
|
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
|
import type { TestProcesses } from "../../support/process/processFixture.js";
|
|
|
|
const registrationSchema = z.object({
|
|
mcpServers: z.object({
|
|
rea: z.object({ command: z.string(), args: z.array(z.string()) }),
|
|
}),
|
|
});
|
|
|
|
const installGlobalPackageOffline = async (
|
|
processes: TestProcesses,
|
|
root: string,
|
|
cwd: string,
|
|
environment: NodeJS.ProcessEnv,
|
|
): Promise<string> => {
|
|
const installEnvironment = {
|
|
...environment,
|
|
PATH: [dirname(process.execPath), process.env.PATH ?? ""].join(delimiter),
|
|
};
|
|
const npm = npmInvocation(
|
|
[
|
|
"install",
|
|
"--offline",
|
|
"--global",
|
|
"--ignore-scripts",
|
|
`file:${resolve(".")}`,
|
|
],
|
|
installEnvironment,
|
|
);
|
|
const install = await processes.run(npm.command, npm.arguments, {
|
|
cwd,
|
|
env: installEnvironment,
|
|
});
|
|
expect(install.exitCode, install.stderr).toBe(0);
|
|
return join(root, "prefix", "bin", "rea");
|
|
};
|
|
|
|
cliTest.skipIf(process.platform === "win32")(
|
|
"real offline npm setup binds an installation across project starts and cache restoration",
|
|
async ({ processes }) => {
|
|
const root = await createTestTempDirectory("rea-real-npm-binding-");
|
|
const home = join(root, "home"),
|
|
trusted = join(root, "trusted"),
|
|
project = join(root, "project");
|
|
for (const path of [
|
|
home,
|
|
trusted,
|
|
join(project, "node_modules", ".bin"),
|
|
join(project, "node_modules", PRODUCT_IDENTITY.packageName),
|
|
])
|
|
await mkdir(path, { recursive: true });
|
|
const environment = {
|
|
...process.env,
|
|
HOME: home,
|
|
USERPROFILE: home,
|
|
npm_config_cache: join(root, "cache"),
|
|
npm_config_prefix: join(root, "prefix"),
|
|
npm_config_userconfig: join(root, "user.npmrc"),
|
|
npm_config_globalconfig: join(root, "global.npmrc"),
|
|
npm_config_update_notifier: "false",
|
|
};
|
|
const installedBin = await installGlobalPackageOffline(
|
|
processes,
|
|
root,
|
|
trusted,
|
|
environment,
|
|
);
|
|
const setup = await processes.run(
|
|
process.execPath,
|
|
[
|
|
installedBin,
|
|
"setup",
|
|
"--client",
|
|
"omp",
|
|
"--no-skill",
|
|
"--yes",
|
|
"--json",
|
|
],
|
|
{ cwd: trusted, env: environment },
|
|
);
|
|
expect(setup.exitCode, setup.stderr).toBe(0);
|
|
const configPath = join(home, ".omp", "agent", "mcp.json");
|
|
const original = await readFile(configPath, "utf8");
|
|
const registration = registrationSchema.parse(JSON.parse(original))
|
|
.mcpServers.rea;
|
|
const alias = registration.args[0];
|
|
expect(alias).toBeDefined();
|
|
if (alias === undefined) throw new Error("Missing registered entrypoint");
|
|
// Only remove an alias in this test's owned prefix, never the source installation.
|
|
expect(alias.startsWith(join(root, "prefix") + "/")).toBe(true);
|
|
expect(registration.args.slice(1)).toEqual(["mcp"]);
|
|
const marker = join(root, "project-candidate-called");
|
|
const candidate = join(
|
|
project,
|
|
"node_modules",
|
|
PRODUCT_IDENTITY.packageName,
|
|
);
|
|
await writeFile(
|
|
join(project, "package.json"),
|
|
JSON.stringify({
|
|
name: "owned-registration-project",
|
|
version: "1.0.0",
|
|
dependencies: {
|
|
[PRODUCT_IDENTITY.packageName]: PRODUCT_IDENTITY.packageVersion,
|
|
},
|
|
}),
|
|
);
|
|
await writeFile(
|
|
join(candidate, "package.json"),
|
|
JSON.stringify({
|
|
name: PRODUCT_IDENTITY.packageName,
|
|
version: PRODUCT_IDENTITY.packageVersion,
|
|
bin: { rea: "candidate.cjs" },
|
|
}),
|
|
);
|
|
await writeFile(
|
|
join(candidate, "candidate.cjs"),
|
|
`#!${process.execPath}\nrequire('node:fs').writeFileSync(${JSON.stringify(marker)}, 'unexpected');\n`,
|
|
{ mode: 0o700 },
|
|
);
|
|
await symlink(
|
|
`../${PRODUCT_IDENTITY.packageName}/candidate.cjs`,
|
|
join(project, "node_modules", ".bin", "rea"),
|
|
);
|
|
await writeFile(join(project, ".npmrc"), "registry=http://127.0.0.1:9/\n");
|
|
const clientEnvironment = {
|
|
...getDefaultEnvironment(),
|
|
HOME: home,
|
|
PATH: [
|
|
join(project, "node_modules", ".bin"),
|
|
process.env.PATH ?? "",
|
|
].join(delimiter),
|
|
};
|
|
const connect = async () => {
|
|
const transport = new StdioClientTransport({
|
|
...registration,
|
|
cwd: project,
|
|
env: clientEnvironment,
|
|
stderr: "pipe",
|
|
});
|
|
const client = new Client(
|
|
{
|
|
name: "real-npm-registration",
|
|
version: "1",
|
|
},
|
|
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
|
);
|
|
try {
|
|
await client.connect(transport);
|
|
expect(client.getServerVersion()?.version).toBe(
|
|
PRODUCT_IDENTITY.packageVersion,
|
|
);
|
|
const status = await client.callTool({
|
|
name: "binary_session",
|
|
arguments: {},
|
|
});
|
|
expect(status.isError).not.toBe(true);
|
|
expect(status.structuredContent).toMatchObject({
|
|
result: { open: false },
|
|
});
|
|
} finally {
|
|
await client.close();
|
|
await transport.close();
|
|
}
|
|
};
|
|
await connect();
|
|
await rename(alias, `${alias}.removed`);
|
|
try {
|
|
const missing = await processes.run(
|
|
registration.command,
|
|
registration.args,
|
|
{ cwd: project, env: clientEnvironment },
|
|
);
|
|
expect(missing.exitCode).not.toBe(0);
|
|
await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });
|
|
} finally {
|
|
await rename(`${alias}.removed`, alias);
|
|
}
|
|
await connect();
|
|
expect(await readFile(configPath, "utf8")).toBe(original);
|
|
await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });
|
|
},
|
|
);
|
|
|
|
cliTest.skipIf(process.platform === "win32")(
|
|
"mcp add preserves a selected entrypoint with spaces and both quote characters",
|
|
async ({ processes }) => {
|
|
const home = await createTestTempDirectory("rea-amp-command-");
|
|
const bin = join(home, `bin 'quoted' "double"`);
|
|
await mkdir(bin);
|
|
const alias = join(bin, "rea");
|
|
await symlink(resolve("scripts/rea.mjs"), alias);
|
|
const result = await processes.run(
|
|
process.execPath,
|
|
[alias, "mcp", "add", "--agent", "amp"],
|
|
{
|
|
cwd: home,
|
|
env: {
|
|
...process.env,
|
|
HOME: home,
|
|
USERPROFILE: home,
|
|
PATH: [bin, process.env.PATH ?? ""].join(delimiter),
|
|
},
|
|
},
|
|
);
|
|
expect(result.exitCode, result.stderr).toBe(0);
|
|
const settings = z
|
|
.object({
|
|
"amp.mcpServers": z.object({
|
|
rea: z.object({ command: z.string(), args: z.array(z.string()) }),
|
|
}),
|
|
})
|
|
.parse(
|
|
JSON.parse(
|
|
await readFile(join(home, ".config", "amp", "settings.json"), "utf8"),
|
|
),
|
|
);
|
|
expect(settings["amp.mcpServers"].rea.args).toEqual([alias, "mcp"]);
|
|
const start = await processes.run(
|
|
settings["amp.mcpServers"].rea.command,
|
|
[alias, "--version"],
|
|
{ cwd: home },
|
|
);
|
|
expect(start.exitCode, start.stderr).toBe(0);
|
|
expect(start.stdout).toContain(PRODUCT_IDENTITY.packageVersion);
|
|
},
|
|
);
|