diff --git a/src/application/McpClientRegistration.formats.test.ts b/src/application/McpClientRegistration.formats.test.ts index 747cf38996f..9e2539fbeb2 100644 --- a/src/application/McpClientRegistration.formats.test.ts +++ b/src/application/McpClientRegistration.formats.test.ts @@ -1,4 +1,7 @@ -import { registerMcpClientOnHost } from "../../tests/fixtures/mcpRegistration.js"; +import { + globalClient, + registerMcpClientOnHost, +} from "../../tests/fixtures/mcpRegistration.js"; import { chmod, readFile, stat, symlink, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { basename, dirname, join } from "node:path"; @@ -9,10 +12,6 @@ import { ArtifactResourceScope } from "../resources/ArtifactResourceScope.js"; import { registerMcpClient } from "./McpClientRegistration.js"; import { parseGooseConfigurationYaml } from "./GooseConfigurationYaml.js"; import { clientConfigurationRecordSchema } from "./ClientConfigurationValues.js"; -import { - mcpClientRegistrationProfile, - type McpRegistrationClient, -} from "./McpRegistrationCatalog.js"; let resources: ArtifactResourceScope; beforeEach(() => { @@ -25,18 +24,6 @@ const launcher = { command: "/fixture/server path", args: ["", "a'b", "--mcp"], }; -const clientFor = ( - path: string, - format: McpRegistrationClient["format"], - id: McpRegistrationClient["id"], -): Extract => ({ - id, - displayName: id, - registrationProfile: mcpClientRegistrationProfile(id), - configPath: path, - format, - scope: "global", -}); const settingsFixture = async (original: string) => { const directory = await createTestTempDirectory("rea-native-registration-"); const path = join(directory, "settings.json"); @@ -97,7 +84,7 @@ it.each([ async ({ format, id, text, expected }) => { const { path } = await settingsFixture(text); const result = await registerMcpClientOnHost( - clientFor(path, format, id), + globalClient(path, format, id), launcher, undefined, resources, @@ -131,7 +118,7 @@ it.skipIf(process.platform === "win32")( await chmod(directory, 0o755); await chmod(path, 0o644); const client = { - ...clientFor(path, "fx", "fx"), + ...globalClient(path, "fx", "fx"), privateProfile: { home: tmpdir() }, } as const; const result = await registerMcpClientOnHost( @@ -196,7 +183,7 @@ it.each([ async ({ text, native, ...control }) => { const { path } = await settingsFixture(text); const result = await registerMcpClientOnHost( - clientFor(path, "opencode", "opencode"), + globalClient(path, "opencode", "opencode"), launcher, undefined, resources, @@ -240,7 +227,7 @@ it.each([ ); expect( await registerMcpClientOnHost( - clientFor(path, "goose", "goose"), + globalClient(path, "goose", "goose"), launcher, undefined, resources, @@ -269,7 +256,7 @@ it.runIf(process.platform === "win32")( async () => { const { path } = await settingsFixture("{}"); const client = { - ...clientFor(path, "fx", "fx"), + ...globalClient(path, "fx", "fx"), privateProfile: { home: tmpdir() }, } as const; const result = await registerMcpClientOnHost( @@ -319,7 +306,7 @@ it.each([ }; const original = `{\n// retained settings need native strict JSON\n"mcpServers":{"rea":${JSON.stringify(entry)},},\n}\n`; const { path, directory } = await settingsFixture(original); - const registration = clientFor(path, format, "github-copilot-cli"); + const registration = globalClient(path, format, "github-copilot-cli"); const client = scope === "project" ? { @@ -357,7 +344,10 @@ it.skipIf(process.platform === "win32")( await symlink(dirname(directory), join(links, "parent")); const linked = join(links, "parent", basename(directory), basename(path)); const result = await registerMcpClientOnHost( - { ...clientFor(linked, "fx", "fx"), privateProfile: { home: directory } }, + { + ...globalClient(linked, "fx", "fx"), + privateProfile: { home: directory }, + }, launcher, undefined, resources, @@ -377,7 +367,7 @@ it.skipIf(process.platform === "win32")( async () => { const { path } = await settingsFixture("{}"); const client = { - ...clientFor(path, "fx", "fx"), + ...globalClient(path, "fx", "fx"), privateProfile: { home: tmpdir() }, } as const; expect( @@ -431,7 +421,7 @@ it.each(["mcp", "mcpServers"])( }; const { path } = await settingsFixture(JSON.stringify(original)); const result = await registerMcpClientOnHost( - clientFor(path, "fx", "fx"), + globalClient(path, "fx", "fx"), launcher, undefined, resources, @@ -457,7 +447,7 @@ it.each(["mcp", "mcpServers"])( const before = await stat(path); expect( await registerMcpClientOnHost( - clientFor(path, "fx", "fx"), + globalClient(path, "fx", "fx"), launcher, undefined, resources, @@ -471,7 +461,7 @@ it("creates Fx registrations in the native writer's mcpServers profile table", a const { path } = await settingsFixture("{}"); expect( await registerMcpClientOnHost( - clientFor(path, "fx", "fx"), + globalClient(path, "fx", "fx"), launcher, undefined, resources, @@ -500,7 +490,7 @@ it.each([ const original = JSON.stringify(document); const { path } = await settingsFixture(original); const result = await registerMcpClientOnHost( - clientFor(path, "fx", "fx"), + globalClient(path, "fx", "fx"), launcher, undefined, resources, @@ -528,7 +518,7 @@ it.each(["mcp", "mcpServers"])( }; const original = `{\n// retained source needs strict Fx JSON\n"${key}":{"rea":${JSON.stringify(entry)},"peer":{"command":"peer"},},\n"theme":"dark",\n}\n`; const { path } = await settingsFixture(original); - const client = clientFor(path, "fx", "fx"); + const client = globalClient(path, "fx", "fx"); expect( await registerMcpClientOnHost(client, launcher, undefined, resources), ).toMatchObject({ ok: true, value: { status: "configured" } }); diff --git a/src/application/McpClientRegistration.nativeFields.test.ts b/src/application/McpClientRegistration.nativeFields.test.ts index f8e296c3a18..1c351291673 100644 --- a/src/application/McpClientRegistration.nativeFields.test.ts +++ b/src/application/McpClientRegistration.nativeFields.test.ts @@ -1,4 +1,7 @@ -import { registerMcpClientOnHost } from "../../tests/fixtures/mcpRegistration.js"; +import { + globalClient, + registerMcpClientOnHost, +} from "../../tests/fixtures/mcpRegistration.js"; import { readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { beforeEach, afterEach, expect, it } from "vitest"; @@ -6,10 +9,6 @@ import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory import { ArtifactResourceScope } from "../resources/ArtifactResourceScope.js"; import { clientConfigurationRecordSchema } from "./ClientConfigurationValues.js"; import { parseGooseConfigurationYaml } from "./GooseConfigurationYaml.js"; -import { - mcpClientRegistrationProfile, - type McpRegistrationClient, -} from "./McpRegistrationCatalog.js"; let resources: ArtifactResourceScope; beforeEach(() => { resources = new ArtifactResourceScope(); @@ -18,18 +17,6 @@ afterEach(async () => { await resources.close(); }); const launcher = { command: "/fixture/server path", args: ["", "--mcp"] }; -const clientFor = ( - path: string, - format: McpRegistrationClient["format"], - id: McpRegistrationClient["id"], -): McpRegistrationClient => ({ - id, - displayName: id, - configPath: path, - scope: "global", - format, - registrationProfile: mcpClientRegistrationProfile(id), -}); const settingsFixture = async (original: string) => { const directory = await createTestTempDirectory("rea-native-fields-"); const path = join(directory, "settings.json"); @@ -63,7 +50,7 @@ it.each([ async ({ format, id, text, key, metadata }) => { const { path } = await settingsFixture(text); const result = await registerMcpClientOnHost( - clientFor(path, format, id), + globalClient(path, format, id), launcher, undefined, resources, @@ -133,7 +120,7 @@ it.each([ const { path } = await settingsFixture(original); expect( await registerMcpClientOnHost( - clientFor(path, "json", id), + globalClient(path, "json", id), launcher, undefined, resources, @@ -198,7 +185,7 @@ it.each([ const { path } = await settingsFixture(original); expect( await registerMcpClientOnHost( - clientFor(path, "json", id), + globalClient(path, "json", id), launcher, undefined, resources, diff --git a/src/application/McpClientRegistration.test.ts b/src/application/McpClientRegistration.test.ts index dfedd414944..2253f957cea 100644 --- a/src/application/McpClientRegistration.test.ts +++ b/src/application/McpClientRegistration.test.ts @@ -1,4 +1,5 @@ import { + globalClient, registerMcpClientOnHost, registerMcpClientsOnHost, } from "../../tests/fixtures/mcpRegistration.js"; @@ -25,30 +26,14 @@ beforeEach(() => { }); import { OwnedStagedOutput } from "../filesystem/OwnedStagedOutput.js"; import { mcpClientRegistrationWritten } from "./McpClientRegistration.js"; -import { - mcpClientRegistrationProfile, - resolveMcpRegistrationClients, - type McpRegistrationClient, -} from "./McpRegistrationCatalog.js"; +import { resolveMcpRegistrationClients } from "./McpRegistrationCatalog.js"; import { withClientConfigurationTransaction } from "./ClientConfigurationTransaction.js"; -const clientFor = ( - path: string, - format: McpRegistrationClient["format"] = "amp", - id: McpRegistrationClient["id"] = "amp", -): McpRegistrationClient => ({ - id, - registrationProfile: mcpClientRegistrationProfile(id), - displayName: id, - configPath: path, - format, - scope: "global", -}); const register = ( path: string, launcher: { command: string; args: readonly string[] }, signal?: AbortSignal, -) => registerMcpClientOnHost(clientFor(path), launcher, signal, resources); +) => registerMcpClientOnHost(globalClient(path), launcher, signal, resources); import { ClientConfigurationPublication } from "./ClientConfigurationPublication.js"; import * as regularReads from "../process/RegularFileRead.js"; @@ -593,7 +578,7 @@ describe("Registration cancellation with independent failures", () => { }, ); const outcomes = await registerMcpClientsOnHost( - [clientFor(first.path), clientFor(second.path)], + [globalClient(first.path), globalClient(second.path)], launcher, controller.signal, resources, @@ -629,7 +614,7 @@ describe("Registration cancellation with independent failures", () => { throw new Error("Unexpected staging owner"); }); const outcomes = await registerMcpClientsOnHost( - [clientFor(first.path), clientFor(second.path)], + [globalClient(first.path), globalClient(second.path)], launcher, controller.signal, resources, @@ -685,8 +670,8 @@ describe("Registration cancellation and sibling outcomes", () => { const bad = await settingsFixture("null"); const good = await settingsFixture("{}"); const clients = [ - clientFor(bad.path), - clientFor(good.path, "json", "cursor"), + globalClient(bad.path), + globalClient(good.path, "json", "cursor"), ]; const outcomes = await registerMcpClientsOnHost( clients, @@ -826,9 +811,9 @@ describe("Client registration publication recovery", () => { let projected: readonly string[]; { const clients = [ - clientFor(first.path), + globalClient(first.path), { - ...clientFor(second.path, "kilo", "kilo-code"), + ...globalClient(second.path, "kilo", "kilo-code"), configPaths: [lower, second.path], }, ]; diff --git a/tests/fixtures/mcpRegistration.ts b/tests/fixtures/mcpRegistration.ts index 05250062e23..4d70858bca2 100644 --- a/tests/fixtures/mcpRegistration.ts +++ b/tests/fixtures/mcpRegistration.ts @@ -4,9 +4,25 @@ import { registerMcpClient, registerMcpClients, } from "../../src/application/McpClientRegistration.js"; -import type { McpRegistrationClient } from "../../src/application/McpRegistrationCatalog.js"; +import { + mcpClientRegistrationProfile, + type McpRegistrationClient, +} from "../../src/application/McpRegistrationCatalog.js"; import { HOST_PLATFORM } from "../../src/platform/HostPlatform.js"; +export const globalClient = ( + configPath: string, + format: McpRegistrationClient["format"] = "amp", + id: McpRegistrationClient["id"] = "amp", +): Extract => ({ + id, + displayName: id, + registrationProfile: mcpClientRegistrationProfile(id), + configPath, + format, + scope: "global", +}); + /** * `rea mcp add` for clients resolved for the running host, as the CLI runs it. * Tests that resolve clients for another platform call the owner directly.