mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 15:05:51 +00:00
fix(cli): report retained MCP registration backups on typed failures (#13268)
This commit is contained in:
1 parent
2dfe4754ac
commit
c1a1de9bfb
2 files changed
+51
-2
No files matched your search
@@ -2,14 +2,16 @@ import { registerMcpClientOnHost } from "../../tests/fixtures/mcpRegistration.js
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { afterEach, beforeEach, expect, it } from "vitest";
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { ArtifactResourceScope } from "../resources/ArtifactResourceScope.js";
|
||||
import {
|
||||
effectiveClientServer,
|
||||
parseClientConfiguration,
|
||||
} from "./ClientConfigurationDocument.js";
|
||||
import { ClientConfigurationPublication } from "./ClientConfigurationPublication.js";
|
||||
import { mergeClientConfigurationDocuments } from "./ClientConfigurationFiles.js";
|
||||
import {
|
||||
mcpClientRegistrationProfile,
|
||||
@@ -21,6 +23,7 @@ beforeEach(() => {
|
||||
resources = new ArtifactResourceScope();
|
||||
});
|
||||
afterEach(async () => {
|
||||
vi.restoreAllMocks();
|
||||
await resources.close();
|
||||
});
|
||||
const launcher = { command: "/fixture/server path", args: ["", "--mcp"] };
|
||||
@@ -135,6 +138,48 @@ it("refuses a higher Kilo file launcher before creating the lower selected targe
|
||||
});
|
||||
});
|
||||
|
||||
it("reports the retained backup when a higher layer invalidates publication", async () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-registration-layer-readback-",
|
||||
);
|
||||
const target = join(root, "project", "kilo.json");
|
||||
const higher = join(root, "higher", "kilo.json");
|
||||
const original = await write(target, { theme: "target" });
|
||||
const higherDocument = {
|
||||
mcp: { rea: { type: "local", command: ["higher-server"] } },
|
||||
};
|
||||
const publish = ClientConfigurationPublication.write;
|
||||
let higherText: string | undefined;
|
||||
vi.spyOn(ClientConfigurationPublication, "write").mockImplementation(
|
||||
async (...args) => {
|
||||
const publication = await publish(...args);
|
||||
higherText = await write(higher, higherDocument);
|
||||
return publication;
|
||||
},
|
||||
);
|
||||
const result = await registerMcpClientOnHost(
|
||||
clientFor(target, [target, higher]),
|
||||
launcher,
|
||||
undefined,
|
||||
resources,
|
||||
);
|
||||
if (result.ok)
|
||||
throw new Error("Registration should refuse the changed launcher");
|
||||
const backup = `${target}.rea.backup`;
|
||||
expect(result.error.message).toContain(
|
||||
"higher-priority configuration overrides",
|
||||
);
|
||||
expect(projectAnalysisError(result.error).details?.diagnostics).toMatchObject(
|
||||
{
|
||||
settings_path: target,
|
||||
backup_path: backup,
|
||||
},
|
||||
);
|
||||
expect(await readFile(target, "utf8")).toBe(original);
|
||||
expect(await readFile(backup, "utf8")).toBe(original);
|
||||
expect(await readFile(higher, "utf8")).toBe(higherText);
|
||||
});
|
||||
|
||||
it("refuses a conflicting KILO_CONFIG_CONTENT launcher without mutating the inline source or creating a target", async () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-registration-inline-conflict-",
|
||||
|
||||
@@ -255,7 +255,11 @@ const registrationFailure = async (
|
||||
},
|
||||
): Promise<ConfigurationError> => {
|
||||
const { backupPath, configured } = progress;
|
||||
if (cause instanceof ConfigurationError) return cause;
|
||||
if (cause instanceof ConfigurationError) {
|
||||
if (backupPath !== undefined)
|
||||
cause.retainPrimaryDiagnostics({ backup_path: backupPath });
|
||||
return cause;
|
||||
}
|
||||
const cleanup = isClientConfigurationCleanupFailure(cause)
|
||||
? await retryClientConfigurationCleanup(cause, resources)
|
||||
: undefined;
|
||||
|
||||
Reference in new issue
Block a user