mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 10:27:42 +00:00
* fix(setup): read Devin project MCP configuration Devin loads .devin/mcp_config.json and .devin/mcp_config.local.json from the working directory up to the nearest .git or .jj, above the user file. A local file outranks every shared file, and a nested directory outranks its ancestors. REA only read the user file, so doctor judged it while Devin ran a project entry, and project uninstall skipped Devin. Return Devin's project candidates in that order, evaluate them with whole-definition replacement, and include Devin in project uninstall. Setup still writes only the user file. Fixes #15041 * fix(setup): apply Devin precedence by directory --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
217 lines
7.7 KiB
TypeScript
217 lines
7.7 KiB
TypeScript
import { chmod, mkdir, symlink, unlink, writeFile } from "node:fs/promises";
|
||
import { dirname, 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 { 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"],
|
||
...(env === undefined ? {} : { env }),
|
||
});
|
||
|
||
const fixture = async (marker: ".git" | ".jj" | "none" = ".git") => {
|
||
const root = await createTestTempDirectory("rea-devin-project-");
|
||
const home = join(root, "home");
|
||
const repository = join(root, "repository");
|
||
const projectDirectory = join(repository, "child");
|
||
await mkdir(projectDirectory, { recursive: true });
|
||
if (marker !== "none")
|
||
await mkdir(join(repository, marker), { recursive: true });
|
||
const client = supportedClients(home, process.platform, {}).find(
|
||
({ name }) => name === "devin",
|
||
);
|
||
if (client === undefined)
|
||
throw new Error("Devin is missing from the client table");
|
||
const devin = (directory: string, name: string) =>
|
||
join(directory, ".devin", name);
|
||
return {
|
||
client,
|
||
home,
|
||
repository,
|
||
projectDirectory,
|
||
shared: devin(projectDirectory, "mcp_config.json"),
|
||
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 },
|
||
),
|
||
};
|
||
};
|
||
|
||
it.each([".git", ".jj"] as const)(
|
||
"orders Devin project files from the %s root, shared before local and ancestors before the working directory",
|
||
async (marker) => {
|
||
const { client, projectDirectory, shared, local, rootShared, rootLocal } =
|
||
await fixture(marker);
|
||
expect(
|
||
clientProjectConfigurationPaths(
|
||
client,
|
||
projectDirectory,
|
||
process.platform,
|
||
),
|
||
).toEqual({ ok: true, value: [rootShared, rootLocal, shared, local] });
|
||
},
|
||
);
|
||
|
||
it("reads only the working directory's Devin files outside a project", async () => {
|
||
const { client, projectDirectory, shared, local } = await fixture("none");
|
||
expect(
|
||
clientProjectConfigurationPaths(client, projectDirectory, process.platform),
|
||
).toEqual({ ok: true, value: [shared, local] });
|
||
});
|
||
|
||
it("selects the highest Devin file and replaces the whole server definition (#15041)", async () => {
|
||
const { client, shared, local, rootLocal, read } = await fixture();
|
||
await writeConfiguration(client.configPath, {
|
||
mcpServers: { rea: server("user", { FROM_USER: "1" }) },
|
||
});
|
||
|
||
const userOnly = await read();
|
||
if (!userOnly.ok) throw Error(userOnly.error.detail);
|
||
expect(userOnly.value.configPath).toBe(client.configPath);
|
||
|
||
await writeConfiguration(shared, { mcpServers: { rea: server("shared") } });
|
||
const sharedResult = await read();
|
||
if (!sharedResult.ok) throw Error(sharedResult.error.detail);
|
||
expect(sharedResult.value).toMatchObject({
|
||
scope: "project",
|
||
configPath: shared,
|
||
launcherConfigPath: shared,
|
||
});
|
||
expect(effectiveClientServer(sharedResult.value.document!, "rea")).toEqual(
|
||
server("shared"),
|
||
);
|
||
|
||
// The nested shared file outranks the repository root’s local file.
|
||
await writeConfiguration(rootLocal, {
|
||
mcpServers: { rea: server("root-local") },
|
||
});
|
||
const rootLocalResult = await read();
|
||
if (!rootLocalResult.ok) throw Error(rootLocalResult.error.detail);
|
||
expect(rootLocalResult.value.configPath).toBe(shared);
|
||
await unlink(shared);
|
||
const rootOnly = await read();
|
||
if (!rootOnly.ok) throw Error(rootOnly.error.detail);
|
||
expect(rootOnly.value.configPath).toBe(rootLocal);
|
||
|
||
await writeConfiguration(local, { mcpServers: { rea: server("local") } });
|
||
const localResult = await read();
|
||
if (!localResult.ok) throw Error(localResult.error.detail);
|
||
expect(localResult.value).toMatchObject({
|
||
scope: "project",
|
||
configPath: local,
|
||
});
|
||
expect(effectiveClientServer(localResult.value.document!, "rea")).toEqual(
|
||
server("local"),
|
||
);
|
||
|
||
await unlink(local);
|
||
await unlink(rootLocal);
|
||
const restored = await read();
|
||
if (!restored.ok) throw Error(restored.error.detail);
|
||
expect(restored.value.configPath).toBe(client.configPath);
|
||
});
|
||
|
||
it("keeps the user Devin registration when project files define only other servers", async () => {
|
||
const { client, shared, read } = await fixture();
|
||
await writeConfiguration(client.configPath, {
|
||
mcpServers: { rea: server("user") },
|
||
});
|
||
await writeConfiguration(shared, { mcpServers: { peer: server("peer") } });
|
||
const result = await read();
|
||
if (!result.ok) throw Error(result.error.detail);
|
||
expect(result.value).toMatchObject({
|
||
scope: "user",
|
||
configPath: client.configPath,
|
||
});
|
||
expect(effectiveClientServer(result.value.document!, "rea")).toEqual(
|
||
server("user"),
|
||
);
|
||
});
|
||
|
||
it("reports Devin's project registration and Windsurf's shared user registration in doctor", async () => {
|
||
const { client, home, projectDirectory, local } = await fixture();
|
||
await writeConfiguration(client.configPath, {
|
||
mcpServers: { rea: server("user") },
|
||
});
|
||
await writeConfiguration(local, { mcpServers: { rea: server("unrelated") } });
|
||
const cwd = vi.spyOn(process, "cwd").mockReturnValue(projectDirectory);
|
||
try {
|
||
const statuses = await readClientRegistrationStatuses(home, undefined, {
|
||
platform: process.platform,
|
||
environment: {},
|
||
selectedClientIds: ["devin", "windsurf"],
|
||
});
|
||
expect(statuses.find(({ client: name }) => name === "devin")).toMatchObject(
|
||
{ scope: "project", config_path: local },
|
||
);
|
||
expect(
|
||
statuses.find(({ client: name }) => name === "windsurf"),
|
||
).toMatchObject({
|
||
config_path: client.configPath,
|
||
command: ["user", "mcp"],
|
||
});
|
||
} finally {
|
||
cwd.mockRestore();
|
||
}
|
||
});
|
||
|
||
it.skipIf(process.platform === "win32")(
|
||
"replays a user file reached through a higher Devin project alias",
|
||
async () => {
|
||
const { client, shared, local, read } = await fixture();
|
||
await writeConfiguration(client.configPath, {
|
||
mcpServers: { rea: server("user") },
|
||
});
|
||
await writeConfiguration(shared, { mcpServers: { rea: server("shared") } });
|
||
await symlink(client.configPath, local);
|
||
const result = await read();
|
||
if (!result.ok) throw Error(result.error.detail);
|
||
expect(result.value).toMatchObject({
|
||
scope: "project",
|
||
launcherConfigPath: local,
|
||
});
|
||
expect(effectiveClientServer(result.value.document!, "rea")).toEqual(
|
||
server("user"),
|
||
);
|
||
},
|
||
);
|
||
|
||
it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||
"preserves an unreadable Devin project boundary instead of treating it as absent",
|
||
async () => {
|
||
const { client, projectDirectory } = await fixture();
|
||
await chmod(projectDirectory, 0o000);
|
||
try {
|
||
expect(
|
||
clientProjectConfigurationPaths(
|
||
client,
|
||
projectDirectory,
|
||
process.platform,
|
||
),
|
||
).toMatchObject({
|
||
ok: false,
|
||
error: { path: join(projectDirectory, ".git") },
|
||
});
|
||
} finally {
|
||
await chmod(projectDirectory, 0o700);
|
||
}
|
||
},
|
||
);
|