mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 14:01:00 +00:00
test(setup): reuse project registration fixtures (#15476)
This commit is contained in:
1 parent
14b006a517
commit
93cc3d357a
6 files changed
+85
-120
No files matched your search
@@ -1,29 +1,21 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
effectiveClientServer,
|
||||
type ClientConfigurationDocument,
|
||||
} from "../../../src/application/ClientConfigurationDocument.js";
|
||||
import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js";
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import {
|
||||
readProjectRegistration,
|
||||
projectServer as serverNamed,
|
||||
writeProjectConfiguration,
|
||||
} from "../../fixtures/projectRegistration.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const writeSettings = async (path: string, servers: unknown) => {
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, JSON.stringify({ "amp.mcpServers": servers }));
|
||||
};
|
||||
const writeSettings = (path: string, servers: unknown) =>
|
||||
writeProjectConfiguration(path, { "amp.mcpServers": servers });
|
||||
|
||||
const server = (command: string) => ({ command, args: ["mcp"] });
|
||||
|
||||
const serverNamed = (
|
||||
document: ClientConfigurationDocument | undefined,
|
||||
name: string,
|
||||
) =>
|
||||
document === undefined ? undefined : effectiveClientServer(document, name);
|
||||
|
||||
const fixture = async ({ repository = true } = {}) => {
|
||||
const root = await createTestTempDirectory("rea-amp-workspace-");
|
||||
const home = join(root, "home");
|
||||
@@ -46,13 +38,7 @@ const fixture = async ({ repository = true } = {}) => {
|
||||
userSettings: client.configPath,
|
||||
workspace,
|
||||
projectDirectory,
|
||||
read: () =>
|
||||
readEffectiveClientRegistrationConfiguration(
|
||||
client,
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory },
|
||||
),
|
||||
read: () => readProjectRegistration(client, projectDirectory),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -5,36 +5,27 @@ import {
|
||||
readFile,
|
||||
symlink,
|
||||
unlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
effectiveClientServer,
|
||||
type ClientConfigurationDocument,
|
||||
} from "../../../src/application/ClientConfigurationDocument.js";
|
||||
import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js";
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { resolveMcpRegistrationClients } from "../../../src/application/McpRegistrationCatalog.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import { ArtifactResourceScope } from "../../../src/resources/ArtifactResourceScope.js";
|
||||
import { registerMcpClientOnHost } from "../../fixtures/mcpRegistration.js";
|
||||
import {
|
||||
readProjectRegistration,
|
||||
projectServer as readReaServer,
|
||||
writeProjectConfiguration as writeConfiguration,
|
||||
} from "../../fixtures/projectRegistration.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const writeConfiguration = async (path: string, configuration: unknown) => {
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, JSON.stringify(configuration));
|
||||
};
|
||||
|
||||
const server = (command: string) => ({
|
||||
command,
|
||||
args: ["mcp"],
|
||||
});
|
||||
|
||||
const readReaServer = (document: ClientConfigurationDocument | undefined) =>
|
||||
document === undefined ? undefined : effectiveClientServer(document, "rea");
|
||||
|
||||
const fixture = async (git = true) => {
|
||||
const root = await createTestTempDirectory("rea-antigravity-project-layout-");
|
||||
const home = join(root, "home");
|
||||
@@ -53,13 +44,7 @@ const fixture = async (git = true) => {
|
||||
root,
|
||||
repository,
|
||||
projectDirectory,
|
||||
read: () =>
|
||||
readEffectiveClientRegistrationConfiguration(
|
||||
client,
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory },
|
||||
),
|
||||
read: () => readProjectRegistration(client, projectDirectory),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -88,11 +73,9 @@ it("treats workspace .agents/mcp_config.json rea over the global file without le
|
||||
// A workspace server replaces the global entry whole rather than inheriting
|
||||
// global env fields, while unrelated global servers remain visible.
|
||||
expect(readReaServer(result.value.document)).toEqual(server("/project/node"));
|
||||
expect(
|
||||
result.value.document === undefined
|
||||
? undefined
|
||||
: effectiveClientServer(result.value.document, "peer"),
|
||||
).toEqual(server("/user/peer"));
|
||||
expect(readReaServer(result.value.document, "peer")).toEqual(
|
||||
server("/user/peer"),
|
||||
);
|
||||
});
|
||||
|
||||
it("loads .agents/mcp_config.json from the working directory up to the repository root", async () => {
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import { chmod, mkdir, symlink, unlink, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { chmod, mkdir, symlink, unlink } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import { effectiveClientServer } from "../../../src/application/ClientConfigurationDocument.js";
|
||||
import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js";
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { clientProjectConfigurationPaths } from "../../../src/application/SupportedClientLocations.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import {
|
||||
readProjectRegistration,
|
||||
writeProjectConfiguration as writeConfiguration,
|
||||
} from "../../fixtures/projectRegistration.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const writeConfiguration = async (path: string, configuration: unknown) => {
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, JSON.stringify(configuration));
|
||||
};
|
||||
|
||||
const server = (command: string, env?: Record<string, string>) => ({
|
||||
command,
|
||||
args: ["mcp"],
|
||||
@@ -44,13 +42,7 @@ const fixture = async (marker: ".git" | ".jj" | "none" = ".git") => {
|
||||
local: devin(projectDirectory, "mcp_config.local.json"),
|
||||
rootShared: devin(repository, "mcp_config.json"),
|
||||
rootLocal: devin(repository, "mcp_config.local.json"),
|
||||
read: () =>
|
||||
readEffectiveClientRegistrationConfiguration(
|
||||
client,
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory },
|
||||
),
|
||||
read: () => readProjectRegistration(client, projectDirectory),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@ import { mkdir, readFile, rm, unlink, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
effectiveClientServer,
|
||||
type ClientConfigurationDocument,
|
||||
} from "../../../src/application/ClientConfigurationDocument.js";
|
||||
import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js";
|
||||
import {
|
||||
configureClientConfiguration,
|
||||
@@ -15,6 +11,11 @@ import { clientProjectConfigurationPaths } from "../../../src/application/Suppor
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import { systemUninstallHost } from "../../../src/application/Uninstall.js";
|
||||
import { uninstallConfigPaths } from "../../../src/application/UninstallClientConfiguration.js";
|
||||
import {
|
||||
readProjectRegistration,
|
||||
projectServer as reaServer,
|
||||
writeProjectConfiguration as writeJson,
|
||||
} from "../../fixtures/projectRegistration.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const writeText = async (path: string, text: string) => {
|
||||
@@ -22,16 +23,6 @@ const writeText = async (path: string, text: string) => {
|
||||
await writeFile(path, text);
|
||||
};
|
||||
|
||||
const writeJson = async (path: string, value: unknown) => {
|
||||
await writeText(path, JSON.stringify(value));
|
||||
};
|
||||
|
||||
const reaServer = (
|
||||
document: ClientConfigurationDocument | undefined,
|
||||
name = "rea",
|
||||
) =>
|
||||
document === undefined ? undefined : effectiveClientServer(document, name);
|
||||
|
||||
const copilotServer = (
|
||||
command: string,
|
||||
extra: Record<string, unknown> = {},
|
||||
@@ -67,13 +58,7 @@ const layout = async (git = true) => {
|
||||
name: string,
|
||||
directory = projectDirectory,
|
||||
env: NodeJS.ProcessEnv = {},
|
||||
) =>
|
||||
readEffectiveClientRegistrationConfiguration(
|
||||
clientFor(name, env),
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory: directory },
|
||||
);
|
||||
) => readProjectRegistration(clientFor(name, env), directory);
|
||||
return { root, home, repository, projectDirectory, clientFor, read };
|
||||
};
|
||||
|
||||
@@ -144,11 +129,10 @@ it("uses the nearest Copilot project rea server and keeps unrelated user servers
|
||||
copilotServer("/user/peer"),
|
||||
);
|
||||
|
||||
const owned = await readEffectiveClientRegistrationConfiguration(
|
||||
const owned = await readProjectRegistration(
|
||||
client,
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory, mode: "ownership" },
|
||||
projectDirectory,
|
||||
"ownership",
|
||||
);
|
||||
if (!owned.ok) throw new Error(owned.error.detail);
|
||||
expect(
|
||||
@@ -222,11 +206,10 @@ it("keeps the Codex user registration when the project directory is not trusted"
|
||||
expect(reaServer(untrusted.value.document, "rea")).toMatchObject({
|
||||
command: "/user/node",
|
||||
});
|
||||
const owned = await readEffectiveClientRegistrationConfiguration(
|
||||
const owned = await readProjectRegistration(
|
||||
clientFor("codex"),
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory, mode: "ownership" },
|
||||
projectDirectory,
|
||||
"ownership",
|
||||
);
|
||||
if (!owned.ok) throw new Error(owned.error.detail);
|
||||
expect(owned.value.projectSources ?? []).toEqual([]);
|
||||
@@ -349,11 +332,10 @@ it("names every Kiro agent file that defines rea instead of choosing one", async
|
||||
expect(result.error.detail).toContain(first);
|
||||
expect(result.error.detail).toContain(second);
|
||||
|
||||
const owned = await readEffectiveClientRegistrationConfiguration(
|
||||
const owned = await readProjectRegistration(
|
||||
clientFor("kiro"),
|
||||
undefined,
|
||||
process.platform,
|
||||
{ projectDirectory, mode: "ownership" },
|
||||
projectDirectory,
|
||||
"ownership",
|
||||
);
|
||||
if (!owned.ok) throw new Error(owned.error.detail);
|
||||
expect(
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
import { mkdir, unlink, writeFile } from "node:fs/promises";
|
||||
import { mkdir, unlink } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
effectiveClientServer,
|
||||
type ClientConfigurationDocument,
|
||||
} from "../../../src/application/ClientConfigurationDocument.js";
|
||||
import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js";
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import {
|
||||
readProjectRegistration,
|
||||
projectServer as readReaServer,
|
||||
writeProjectConfiguration as writeConfiguration,
|
||||
} from "../../fixtures/projectRegistration.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const writeConfiguration = async (path: string, configuration: unknown) => {
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, JSON.stringify(configuration));
|
||||
};
|
||||
|
||||
const localServer = (command: string) => ({
|
||||
type: "local",
|
||||
command: [command, "mcp"],
|
||||
});
|
||||
|
||||
const readReaServer = (document: ClientConfigurationDocument | undefined) =>
|
||||
document === undefined ? undefined : effectiveClientServer(document, "rea");
|
||||
|
||||
const fixture = async (selection?: "file" | "directory", name = "child") => {
|
||||
const root = await createTestTempDirectory("rea-opencode-project-layout-");
|
||||
const home = join(root, "home");
|
||||
@@ -48,15 +40,7 @@ const fixture = async (selection?: "file" | "directory", name = "child") => {
|
||||
root,
|
||||
projectDirectory,
|
||||
read: (mode?: "ownership") =>
|
||||
readEffectiveClientRegistrationConfiguration(
|
||||
client,
|
||||
undefined,
|
||||
process.platform,
|
||||
{
|
||||
projectDirectory,
|
||||
...(mode === undefined ? {} : { mode }),
|
||||
},
|
||||
),
|
||||
readProjectRegistration(client, projectDirectory, mode),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
|
||||
import {
|
||||
effectiveClientServer,
|
||||
type ClientConfigurationDocument,
|
||||
} from "../../src/application/ClientConfigurationDocument.js";
|
||||
import { readEffectiveClientRegistrationConfiguration } from "../../src/application/ClientConfigurationFiles.js";
|
||||
import type { SetupClient } from "../../src/application/SupportedClients.js";
|
||||
|
||||
export const writeProjectConfiguration = async (
|
||||
path: string,
|
||||
configuration: unknown,
|
||||
) => {
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, JSON.stringify(configuration));
|
||||
};
|
||||
|
||||
export const projectServer = (
|
||||
document: ClientConfigurationDocument | undefined,
|
||||
name = "rea",
|
||||
) =>
|
||||
document === undefined ? undefined : effectiveClientServer(document, name);
|
||||
|
||||
export const readProjectRegistration = (
|
||||
client: SetupClient,
|
||||
projectDirectory: string,
|
||||
mode?: "ownership",
|
||||
) =>
|
||||
readEffectiveClientRegistrationConfiguration(
|
||||
client,
|
||||
undefined,
|
||||
process.platform,
|
||||
{
|
||||
projectDirectory,
|
||||
...(mode === undefined ? {} : { mode }),
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user