diff --git a/tests/boundary/cli/packageRunnerRegistration.test.ts b/tests/boundary/cli/packageRunnerRegistration.test.ts index 91f609ac26..eb7952962e 100644 --- a/tests/boundary/cli/packageRunnerRegistration.test.ts +++ b/tests/boundary/cli/packageRunnerRegistration.test.ts @@ -1,7 +1,6 @@ import { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js"; import { mkdir, readFile, writeFile } from "node:fs/promises"; -import { delimiter, dirname, join, resolve } from "node:path"; -import { pathToFileURL } from "node:url"; +import { delimiter, join, resolve } from "node:path"; import { expect } from "vitest"; import { z } from "zod"; @@ -16,77 +15,6 @@ const ompConfigurationSchema = z.object({ }), }); -cliTest.skipIf(process.platform !== "win32")( - "mcp add blocks an implicit MSIX-private launcher before writing client files", - async ({ processes }) => { - const home = await createTestTempDirectory("rea-msix-mcp-add-"); - const environment = await registrationEnvironment(home, { - CLAUDE_CONFIG_DIR: home, - }); - const isolatedConfig = join(home, ".claude.json"); - const installed = join(home, "installed", "rea.mjs"); - const privateEntry = join( - home, - "localappdata", - "Packages", - "Fixture_123", - "LocalCache", - "rea.mjs", - ); - const original = '{"mcpServers":{"other":{"command":"unchanged"}}}\n'; - const launcher = `import ${JSON.stringify(pathToFileURL(resolve("scripts/rea.mjs")).href)};\n`; - for (const entry of [installed, privateEntry]) { - await mkdir(dirname(entry), { recursive: true }); - await writeFile(entry, launcher); - } - await writeFile(isolatedConfig, original); - const run = (entry: string, args: readonly string[] = []) => - processes.run( - process.execPath, - [entry, "mcp", "add", "--agent", "claude-code", "--json", ...args], - { - cwd: home, - env: environment, - }, - ); - - const blocked = await run(privateEntry); - expect(blocked.exitCode, blocked.stderr).toBe(1); - expect(JSON.parse(blocked.stdout)).toMatchObject({ - code: "VALIDATION_ERROR", - message: expect.stringContaining( - "inside the private storage of MSIX package Fixture_123", - ), - fieldErrors: [expect.objectContaining({ path: "command" })], - }); - expect(await readFile(isolatedConfig, "utf8")).toBe(original); - await expect( - readFile(`${isolatedConfig}.rea.backup`, "utf8"), - ).rejects.toMatchObject({ code: "ENOENT" }); - - const allowed = await run(installed); - expect(allowed.exitCode, allowed.stderr).toBe(0); - expect(JSON.parse(await readFile(isolatedConfig, "utf8"))).toMatchObject({ - mcpServers: { - rea: { command: process.execPath, args: [installed, "mcp"] }, - other: { command: "unchanged" }, - }, - }); - expect(await readFile(`${isolatedConfig}.rea.backup`, "utf8")).toBe( - original, - ); - - const explicit = await run(privateEntry, [ - "--command", - '"custom executable" mcp', - ]); - expect(explicit.exitCode, explicit.stderr).toBe(0); - expect(JSON.parse(await readFile(isolatedConfig, "utf8"))).toMatchObject({ - mcpServers: { rea: { command: "custom executable", args: ["mcp"] } }, - }); - }, -); - const controlledRunnerFixture = async (home: string) => { const bin = join(home, "bin"); const script = join(home, "runner-fixture.cjs"); diff --git a/tests/boundary/filesystem/windowsNpxRegistration.test.ts b/tests/boundary/filesystem/windowsNpxRegistration.test.ts index 87d6179c4d..7704645ea4 100644 --- a/tests/boundary/filesystem/windowsNpxRegistration.test.ts +++ b/tests/boundary/filesystem/windowsNpxRegistration.test.ts @@ -1,5 +1,6 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"; -import { join, isAbsolute } from "node:path"; +import { dirname, isAbsolute, join, resolve } from "node:path"; +import { pathToFileURL } from "node:url"; import { Client } from "@modelcontextprotocol/client"; import { StdioClientTransport, @@ -15,6 +16,8 @@ import { PRODUCT_IDENTITY } from "../../../src/identity.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { supportedClientRegistrationProfile } from "../../fixtures/clientRegistrationProfile.js"; import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; +import { registrationEnvironment } from "../../support/cli/registrationEnvironment.js"; +import { processTest } from "../../support/process/processFixture.js"; // These writer tests model setup running from REA's actual entrypoint, not Vitest's worker. vi.mock( @@ -239,3 +242,74 @@ it.skipIf(process.platform !== "win32")( } }, ); + +processTest.skipIf(process.platform !== "win32")( + "mcp add blocks an implicit MSIX-private launcher before writing client files", + async ({ processes }) => { + const home = await createTestTempDirectory("rea-msix-mcp-add-"); + const environment = await registrationEnvironment(home, { + CLAUDE_CONFIG_DIR: home, + }); + const isolatedConfig = join(home, ".claude.json"); + const installed = join(home, "installed", "rea.mjs"); + const privateEntry = join( + home, + "localappdata", + "Packages", + "Fixture_123", + "LocalCache", + "rea.mjs", + ); + const original = '{"mcpServers":{"other":{"command":"unchanged"}}}\n'; + const launcher = `import ${JSON.stringify(pathToFileURL(resolve("scripts/rea.mjs")).href)};\n`; + for (const entry of [installed, privateEntry]) { + await mkdir(dirname(entry), { recursive: true }); + await writeFile(entry, launcher); + } + await writeFile(isolatedConfig, original); + const run = (entry: string, args: readonly string[] = []) => + processes.run( + process.execPath, + [entry, "mcp", "add", "--agent", "claude-code", "--json", ...args], + { + cwd: home, + env: environment, + }, + ); + + const blocked = await run(privateEntry); + expect(blocked.exitCode, blocked.stderr).toBe(1); + expect(JSON.parse(blocked.stdout)).toMatchObject({ + code: "VALIDATION_ERROR", + message: expect.stringContaining( + "inside the private storage of MSIX package Fixture_123", + ), + fieldErrors: [expect.objectContaining({ path: "command" })], + }); + expect(await readFile(isolatedConfig, "utf8")).toBe(original); + await expect( + readFile(`${isolatedConfig}.rea.backup`, "utf8"), + ).rejects.toMatchObject({ code: "ENOENT" }); + + const allowed = await run(installed); + expect(allowed.exitCode, allowed.stderr).toBe(0); + expect(JSON.parse(await readFile(isolatedConfig, "utf8"))).toMatchObject({ + mcpServers: { + rea: { command: process.execPath, args: [installed, "mcp"] }, + other: { command: "unchanged" }, + }, + }); + expect(await readFile(`${isolatedConfig}.rea.backup`, "utf8")).toBe( + original, + ); + + const explicit = await run(privateEntry, [ + "--command", + '"custom executable" mcp', + ]); + expect(explicit.exitCode, explicit.stderr).toBe(0); + expect(JSON.parse(await readFile(isolatedConfig, "utf8"))).toMatchObject({ + mcpServers: { rea: { command: "custom executable", args: ["mcp"] } }, + }); + }, +);