mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* refactor(browser): take the host in Chromium, Electron and capture adapters chromiumSandboxEnabled and safeElectronEnvironment take a required platform. The scenario browser, native module resolver, Electron provider and capture cleanup, mitmproxy adapter and web script artifacts take an optional platform seam (default HOST_PLATFORM); Electron fuses read the host architecture from HOST_PLATFORM. Their tests inject the platform instead of redefining process.platform. src/browser no longer reads process.platform or process.arch. * refactor(pcap): take the host platform in the packet tools, native bound and batch launch (#11141) * refactor(pcap): take the host platform in the packet tools, native bound and batch launch * test(pcap): cover the selected host in batch launch and capture-host support * refactor(apktool): take the host platform in launcher selection, version probe and decode (#11164) * refactor(apktool): take the host platform in launcher selection, version probe and decode * test(apktool): cover the provider's selected host in launcher selection * refactor(hopper): give the launcher the provider's host platform * refactor(native): inject the host into the pwntools decoders and native capability defaults (#11173) * refactor(native): inject the host into the pwntools decoders and native capability defaults * fix(native): give composed pwntools services the capability host and drop empty test hooks * refactor(adb): take the host platform in binary selection and pulled file names (#11176) * refactor(adb): take the host platform in binary selection and pulled file names * refactor(cli): pass the resolved host platform through rea mcp add (#11179) * refactor(cli): pass the resolved host platform through rea mcp add * refactor(composition): default composition entry points to HOST_PLATFORM and pass it to Hopper and IDA (#11183) * refactor(kuna): require the host platform in admission and installation, and give it to the session client (#11186) * refactor(kuna): require the host platform in admission and installation, and give it to the session client * fix(kuna): pass the host platform from the JavaScript installation callers verify-real-kuna, both native oracle helpers and the command-lifetime child script call inspectKunaInstallation from dist, where TypeScript cannot see the now-required platform. They passed undefined and got unsupported_host on supported hosts. * refactor(server): give createServer a host option and pass it to session tools, sigrok and EVM (#11203) * refactor(server): give createServer a host option and pass it to session tools, sigrok and EVM createServer read process.platform and process.arch live for its capability services, and registerSessionTools read process.platform for process capture. A host option (default HOST_PLATFORM) now selects both, and composition passes the capability host to the sigrok provider and the EVM provider (execution gate, limiter probe and environment rules), as it does for pwntools. hostRestrictedAvailabilityMcp selects its host through the option instead of redefining process.platform and process.arch, and moves to the MCP boundary lane since it no longer touches process-global state. evmCleanupRetry passes SIMULATED_LINUX_X64 to the provider instead of 52 property redefinitions; the fixture moves to tests/fixtures/simulatedHost.ts. * refactor(desktop): require the host platform in build computer and secret folder paths (#11210) * refactor(desktop): require the host platform in build computer and secret folder paths buildComputerArchiveDirectory, defaultBuildComputerArchive, resolveBuildComputerEnvironment and buildSecretsDirectory defaulted to process.platform. Every caller but DesktopBuildComputers' secret folder already passed the platform; it now passes HOST_PLATFORM.platform, which it reads for the build environment. * refactor(filesystem): default caller paths and ChangeTime settling to HOST_PLATFORM (#11212) appendCallerPath, absoluteCallerPath and the ChangeTime settle seams defaulted to a live process.platform read. Their defaults now come from HOST_PLATFORM: the 59 callers that omit the platform join or settle paths they open on this host, and callers describing another host's layout already pass it. The webScriptExport case that redefined process.platform to reach the Windows settle budget moves to its own file, which selects Windows by mocking HostPlatform. * fix(server): report process capture availability for the server's host sessionAvailabilityPolicy imported platform from node:process, so with a selected host binary_session reported capture_process_scenario from the running host while planning and capture used the selected one. It takes the platform from createServer and registerSessionTools. hostRestrictedAvailabilityMcp checks discovery against a dry-run plan on win32 and linux hosts. * build(guards): count platform and arch imports from node:process and node:os as ambient host reads sessionAvailabilityPolicy's named import of platform from node:process escaped the ambient-host-platform guard. The guards now also match named platform/arch imports from node:process or node:os and os.platform()/os.arch(). The one other site, DesktopApplicationCapture's os.arch(), records the capturing host and now reads HOST_PLATFORM.architecture. * refactor(config): take the host platform in parseConfig and give debugger managers the capability host (#11237) * refactor(config): take the host platform in parseConfig and give debugger managers the capability host parseConfig read process.platform for the default Hopper launcher; it takes the platform (default HOST_PLATFORM). GdbSessionManager and RizinDebugSessionManager default their platform to HOST_PLATFORM, and composition passes the capability host that already decides their availability. GDB's /proc descriptor check reads HOST_PLATFORM explicitly: it inspects this host's /proc whatever host the manager models. * refactor(firmware): give the firmware and Wakaru providers the capability host (#11239) * refactor(firmware): give the firmware and Wakaru providers the capability host resolveFirmwareCommand and resolveWakaruCommand read process.platform (and process.arch) for their host gate. They take the platform or host as a parameter; FirmwareProvider and WakaruProvider take a host (default HOST_PLATFORM) for the gate and their environment snapshots, and composition passes the capability host that already decides their availability. The JavaScript analysis source transfer defaults to HOST_PLATFORM. artifactSelectedCommand passes SIMULATED_LINUX_X64 to both providers instead of redefining process.platform and process.arch, and the Wakaru limiter configuration cases now run on any POSIX host. * refactor(captures): give tshark the capability host and default Cutter to HOST_PLATFORM (#11240) * refactor(captures): give tshark the capability host and default Cutter to HOST_PLATFORM TsharkCaptureProvider and CutterBridgeClient defaulted their platform to process.platform. Both default to HOST_PLATFORM now, and composition passes the capability host to the packet capture service, which already decides its availability. * refactor(platform): read HOST_PLATFORM explicitly in host-only path checks (#11241) * refactor(platform): read HOST_PLATFORM explicitly in host-only path checks Electron's readlink target split, IDA's host path comparison, the inspector's reported runtime path, the server identity check and WABT's executable names all describe paths on the running host. They read HOST_PLATFORM instead of process.platform. * test(native): select the native UI verifier's host through HostPlatform (#11242) verify-native-ui.mjs reads its macOS requirement from HOST_PLATFORM, and its action test resolves the script's HostPlatform import to a simulated darwin host instead of redefining process.platform in the child preload. Simulating linux there fails the macOS requirement, so the redirect is effective. * test(mcp): check that composition forwards the selected host to execution hostRestrictedAvailabilityMcp ran execution only on darwin, where the runner's own host also refuses. The new case calls the firmware, Wakaru, tshark, sigrok and EVM tools under a darwin and a linux x64 host and requires different outcomes, so dropping a provider's host forwarding fails on any runner (checked by removing the firmware forwarding). * fix(composition): give the pcap, Apktool and ADB providers the capability host createServer's selected host decided pcap capture discovery, but the default pcap, Apktool and ADB factories built their providers with HOST_PLATFORM. The factories take the platform (default HOST_PLATFORM) and capabilityServices passes its context platform, so availability and execution follow one host. * test: import moved resources owners in host-platform fixtures * refactor(config): drop the unused host parameter from parseConfig
784 lines
28 KiB
TypeScript
784 lines
28 KiB
TypeScript
import { registerMcpClientsOnHost } from "../../fixtures/mcpRegistration.js";
|
|
import { HOST_PLATFORM } from "../../../src/platform/HostPlatform.js";
|
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
|
|
import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js";
|
|
import { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
|
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
|
import { resolveMcpRegistrationClients } from "../../../src/application/McpRegistrationCatalog.js";
|
|
import {
|
|
resolveSupportedClients,
|
|
supportedClients,
|
|
} from "../../../src/application/SupportedClients.js";
|
|
import { detectClients } from "../../../src/application/SetupHost.js";
|
|
import {
|
|
clientRefreshRefusal,
|
|
configureClientConfiguration,
|
|
inspectClientConfiguration,
|
|
} from "../../../src/application/SetupClientConfiguration.js";
|
|
import {
|
|
runUninstall,
|
|
systemUninstallHost,
|
|
} from "../../../src/application/Uninstall.js";
|
|
import { existingMaintenanceScope } from "../../../src/application/UpdateMaintenance.js";
|
|
import { ArtifactResourceScope } from "../../../src/resources/ArtifactResourceScope.js";
|
|
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
|
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
const platform = process.platform;
|
|
const command = currentClientRegistrationCommand({ platform });
|
|
|
|
beforeEach(clearClientLocationEnvironment);
|
|
afterEach(() => vi.unstubAllEnvs());
|
|
|
|
const kiloRow = async (home: string, environment: NodeJS.ProcessEnv = {}) =>
|
|
(await resolveSupportedClients(home, platform, environment)).find(
|
|
({ name }) => name === "kilo",
|
|
);
|
|
|
|
/** The user-scope file `rea mcp add --agent kilo` selects from the same layers. */
|
|
const mcpAddTarget = async (home: string, environment: NodeJS.ProcessEnv) => {
|
|
const selected = await resolveMcpRegistrationClients(
|
|
{ agents: ["kilo"], global: true, cwd: home, home, platform, environment },
|
|
new ArtifactResourceScope(),
|
|
);
|
|
if (!selected.ok) throw selected.error;
|
|
return selected.value[0]?.configPath;
|
|
};
|
|
|
|
it("writes Kilo's kilo.json in its config root until another layer exists", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-default-");
|
|
const root = join(home, ".config", "kilo");
|
|
const synchronous = supportedClients(home, platform, {}).find(
|
|
({ name }) => name === "kilo",
|
|
);
|
|
expect(synchronous).toMatchObject({
|
|
configPath: join(root, "kilo.json"),
|
|
markerPath: root,
|
|
});
|
|
expect(synchronous?.configPaths).toContain(join(home, ".kilo", "kilo.jsonc"));
|
|
expect(await kiloRow(home)).toMatchObject({
|
|
configPath: join(root, "kilo.json"),
|
|
configPaths: [join(root, "kilo.json")],
|
|
});
|
|
});
|
|
|
|
it("selects the last present Kilo layer, as rea mcp add does", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-layers-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(join(root, "config.json"), "{}");
|
|
const legacy = join(home, ".kilocode");
|
|
await mkdir(legacy);
|
|
await writeFile(join(legacy, "kilo.jsonc"), "{}");
|
|
const row = await kiloRow(home);
|
|
expect(row).toMatchObject({
|
|
configPath: join(legacy, "kilo.jsonc"),
|
|
configPaths: [join(root, "config.json"), join(legacy, "kilo.jsonc")],
|
|
});
|
|
expect(await mcpAddTarget(home, {})).toBe(row?.configPath);
|
|
// Any folder Kilo reads is evidence that setup should offer it.
|
|
await rm(root, { recursive: true });
|
|
expect(
|
|
(await detectClients(home, platform, {})).map(({ name }) => name),
|
|
).toContain("kilo");
|
|
});
|
|
|
|
it("selects an existing file in a KILO_CONFIG_DIR spelled with a dot segment", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-config-dir-dot-");
|
|
const custom = join(home, "profiles", "kilo");
|
|
await mkdir(custom, { recursive: true });
|
|
await writeFile(join(custom, "kilo.jsonc"), "{}");
|
|
const environment = { KILO_CONFIG_DIR: `${home}/profiles/./kilo` };
|
|
const row = await kiloRow(home, environment);
|
|
expect(row?.configPath).toBe(join(custom, "kilo.jsonc"));
|
|
expect(row?.configPaths).toContain(row?.configPath);
|
|
expect(await mcpAddTarget(home, environment)).toBe(row?.configPath);
|
|
});
|
|
|
|
it("plans kilo.json in an empty KILO_CONFIG_DIR", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-config-dir-");
|
|
const custom = join(home, "custom-kilo");
|
|
const environment = { KILO_CONFIG_DIR: custom };
|
|
const row = await kiloRow(home, environment);
|
|
expect(row?.configPath).toBe(join(custom, "kilo.json"));
|
|
expect(await mcpAddTarget(home, environment)).toBe(row?.configPath);
|
|
});
|
|
|
|
it("loads KILO_CONFIG above Kilo's root files and below its home folders", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-config-file-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(join(root, "kilo.json"), "{}");
|
|
const explicit = join(home, "profiles", "kilo.json");
|
|
const environment = { KILO_CONFIG: explicit };
|
|
// A selected file that does not exist yet is still Kilo's last root layer.
|
|
const planned = await kiloRow(home, environment);
|
|
expect(planned).toMatchObject({
|
|
configPath: explicit,
|
|
configPaths: [join(root, "kilo.json"), explicit],
|
|
});
|
|
expect(await mcpAddTarget(home, environment)).toBe(explicit);
|
|
// A home folder layer loads after it and becomes the write target.
|
|
await mkdir(join(home, ".kilo"));
|
|
await writeFile(join(home, ".kilo", "kilo.jsonc"), "{}");
|
|
const layered = await kiloRow(home, environment);
|
|
expect(layered).toMatchObject({
|
|
configPath: join(home, ".kilo", "kilo.jsonc"),
|
|
configPaths: [
|
|
join(root, "kilo.json"),
|
|
explicit,
|
|
join(home, ".kilo", "kilo.jsonc"),
|
|
],
|
|
});
|
|
expect(await mcpAddTarget(home, environment)).toBe(layered?.configPath);
|
|
});
|
|
|
|
it("loads ~/.kilo after the legacy ~/.kilocode folder", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-home-folders-");
|
|
for (const folder of [".kilocode", ".kilo"]) {
|
|
await mkdir(join(home, folder));
|
|
await writeFile(join(home, folder, "kilo.json"), "{}");
|
|
}
|
|
const row = await kiloRow(home);
|
|
expect(row).toMatchObject({
|
|
configPath: join(home, ".kilo", "kilo.json"),
|
|
configPaths: [
|
|
join(home, ".kilocode", "kilo.json"),
|
|
join(home, ".kilo", "kilo.json"),
|
|
],
|
|
});
|
|
expect(await mcpAddTarget(home, {})).toBe(row?.configPath);
|
|
});
|
|
|
|
it("lets doctor and setup accept REA's entry that only KILO_CONFIG_CONTENT defines", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-inline-only-");
|
|
// Kilo is installed but none of its files exists yet.
|
|
await mkdir(join(home, ".config", "kilo"), { recursive: true });
|
|
const environment = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true } },
|
|
}),
|
|
};
|
|
const statuses = await readClientRegistrationStatuses(home, command[1], {
|
|
platform,
|
|
environment,
|
|
});
|
|
expect(statuses.find(({ client }) => client === "kilo")).toMatchObject({
|
|
state: "aligned",
|
|
});
|
|
const row = await kiloRow(home, environment);
|
|
if (row === undefined) throw new Error("Kilo row is missing");
|
|
// Writing the same entry beneath it changes nothing Kilo loads, so setup
|
|
// may still record it in the file it manages.
|
|
expect(await inspectClientConfiguration(row, {}, command)).toMatchObject({
|
|
status: "create",
|
|
});
|
|
});
|
|
|
|
it("refuses a relative Kilo configuration path instead of guessing its folder", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-relative-");
|
|
for (const environment of [
|
|
{ KILO_CONFIG: "kilo.json" },
|
|
{ KILO_CONFIG_DIR: "kilo" },
|
|
{ XDG_CONFIG_HOME: "config" },
|
|
]) {
|
|
const row = supportedClients(home, platform, environment).find(
|
|
({ name }) => name === "kilo",
|
|
);
|
|
expect(row?.configPathError).toContain("is relative");
|
|
const resolved = await kiloRow(home, environment);
|
|
expect(resolved?.configPathError).toContain("is relative");
|
|
if (resolved === undefined) throw new Error("Kilo row is missing");
|
|
// Readers such as doctor's provider settings refuse it instead of reading
|
|
// a file relative to REA's own folder.
|
|
expect(
|
|
await readEffectiveClientRegistrationConfiguration(
|
|
resolved,
|
|
undefined,
|
|
HOST_PLATFORM.platform,
|
|
),
|
|
).toMatchObject({ ok: false, error: { kind: "unreadable" } });
|
|
}
|
|
});
|
|
|
|
it.each(["\\kilo.json", "/kilo.json"])(
|
|
"refuses a drive-less Windows KILO_CONFIG %s that follows Kilo's current drive",
|
|
(value) => {
|
|
const row = supportedClients("C:\\Users\\x", "win32", {
|
|
KILO_CONFIG: value,
|
|
}).find(({ name }) => name === "kilo");
|
|
expect(row?.configPathError).toContain("has no drive");
|
|
},
|
|
);
|
|
|
|
it("lets doctor and uninstall act on the Kilo layer rea mcp add wrote", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-lifecycle-");
|
|
const legacy = join(home, ".kilocode");
|
|
await mkdir(legacy);
|
|
const target = join(legacy, "kilo.jsonc");
|
|
await writeFile(target, "{}\n");
|
|
const resources = new ArtifactResourceScope();
|
|
const selected = await resolveMcpRegistrationClients(
|
|
{
|
|
agents: ["kilo"],
|
|
global: true,
|
|
cwd: home,
|
|
home,
|
|
platform,
|
|
environment: {},
|
|
},
|
|
resources,
|
|
);
|
|
if (!selected.ok) throw selected.error;
|
|
const [outcome] = await registerMcpClientsOnHost(
|
|
selected.value,
|
|
{ command: command[0] ?? "", args: command.slice(1) },
|
|
undefined,
|
|
resources,
|
|
);
|
|
expect(outcome).toMatchObject({ status: "completed" });
|
|
const statuses = await readClientRegistrationStatuses(home, command[1], {
|
|
platform,
|
|
environment: {},
|
|
});
|
|
expect(statuses.find(({ client }) => client === "kilo")).toMatchObject({
|
|
config_path: target,
|
|
state: "aligned",
|
|
});
|
|
const uninstall = await runUninstall(
|
|
false,
|
|
systemUninstallHost(home, undefined, {}, platform),
|
|
);
|
|
expect(uninstall.items).toContainEqual(
|
|
expect.objectContaining({ name: "kilo", status: "removed" }),
|
|
);
|
|
expect(await readFile(target, "utf8")).not.toContain('"rea"');
|
|
});
|
|
|
|
it("reads KILO_CONFIG_CONTENT as Kilo's top read-only layer", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-inline-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
const target = join(root, "kilo.json");
|
|
const registered = JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true } },
|
|
});
|
|
await writeFile(target, registered);
|
|
const status = async (environment: NodeJS.ProcessEnv) =>
|
|
(
|
|
await readClientRegistrationStatuses(home, command[1], {
|
|
platform,
|
|
environment,
|
|
})
|
|
).find(({ client }) => client === "kilo");
|
|
// An inline layer that leaves REA alone keeps the file registration current.
|
|
const peer = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({ mcp: { other: { command: ["x"] } } }),
|
|
};
|
|
expect(await status(peer)).toMatchObject({ state: "aligned" });
|
|
const row = await kiloRow(home, peer);
|
|
if (row === undefined) throw new Error("Kilo row is missing");
|
|
expect(await inspectClientConfiguration(row, {}, command)).toMatchObject({
|
|
status: "already_current",
|
|
});
|
|
const remediation = async (environment: NodeJS.ProcessEnv) => {
|
|
const overridden = await kiloRow(home, environment);
|
|
if (overridden === undefined) throw new Error("Kilo row is missing");
|
|
expect(overridden.configPath).toBe(target);
|
|
const inspection = await inspectClientConfiguration(
|
|
overridden,
|
|
{},
|
|
command,
|
|
);
|
|
if (inspection.status !== "invalid")
|
|
throw new Error(`Setup admitted the override: ${inspection.status}`);
|
|
return inspection.remediation;
|
|
};
|
|
// An inline launcher replaces the one setup wrote; its owner is unknown.
|
|
const launcher = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { command: ["/opt/other/rea", "mcp"] } },
|
|
}),
|
|
};
|
|
// Doctor and setup name the layer the unowned launcher may come from.
|
|
const doctor = await status(launcher);
|
|
expect(doctor?.state).not.toBe("aligned");
|
|
expect(doctor?.remediation).toContain(", KILO_CONFIG_CONTENT has unknown");
|
|
expect(await remediation(launcher)).toContain(
|
|
"has unknown ownership and was not changed",
|
|
);
|
|
expect(await remediation(launcher)).toContain("KILO_CONFIG_CONTENT");
|
|
// An inline setting overrides the registration setup would write.
|
|
const disabled = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({ mcp: { rea: { enabled: false } } }),
|
|
};
|
|
// Doctor's recovery names the layer setup cannot edit.
|
|
expect(await status(disabled)).toMatchObject({
|
|
state: "stale",
|
|
remediation: expect.stringContaining(
|
|
"KILO_CONFIG_CONTENT also sets the rea entry",
|
|
),
|
|
});
|
|
expect(await remediation(disabled)).toContain(
|
|
"KILO_CONFIG_CONTENT overrides REA's rea registration",
|
|
);
|
|
expect(await readFile(target, "utf8")).toBe(registered);
|
|
});
|
|
|
|
it("refuses a setup write that KILO_CONFIG_CONTENT would override", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-inline-write-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
const target = join(root, "kilo.json");
|
|
const environment = { HOPPER_LAUNCHER_PATH: "/opt/first/hopper" };
|
|
const registered = JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true, environment } },
|
|
});
|
|
await writeFile(target, registered);
|
|
const row = await kiloRow(home, {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({ mcp: { rea: { environment } } }),
|
|
});
|
|
if (row === undefined) throw new Error("Kilo row is missing");
|
|
// Settings chosen after inspection, such as a newly installed Hopper,
|
|
// would be written beneath the inline value that Kilo keeps loading.
|
|
const result = await configureClientConfiguration(
|
|
row,
|
|
{ HOPPER_LAUNCHER_PATH: "/opt/second/hopper" },
|
|
command,
|
|
);
|
|
expect(result).toMatchObject({
|
|
status: "failed",
|
|
reason: "read_only_override",
|
|
});
|
|
expect(await readFile(target, "utf8")).toBe(registered);
|
|
});
|
|
|
|
it("refuses Kilo's location while KILO_CONFIG_CONTENT cannot be parsed", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-inline-malformed-");
|
|
const row = await kiloRow(home, { KILO_CONFIG_CONTENT: "{" });
|
|
expect(row?.configPathError).toContain(
|
|
"KILO_CONFIG_CONTENT cannot be admitted",
|
|
);
|
|
});
|
|
|
|
it("registers Kilo through its table row in rea mcp add", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-mcp-add-row-");
|
|
const resources = new ArtifactResourceScope();
|
|
const select = (environment: NodeJS.ProcessEnv) =>
|
|
resolveMcpRegistrationClients(
|
|
{
|
|
agents: ["kilo"],
|
|
global: true,
|
|
cwd: home,
|
|
home,
|
|
platform,
|
|
environment,
|
|
},
|
|
resources,
|
|
);
|
|
// A relative path is refused as setup refuses it, not resolved from cwd.
|
|
const relative = await select({ KILO_CONFIG: "kilo.json" });
|
|
expect(relative.ok).toBe(false);
|
|
if (!relative.ok) expect(relative.error.message).toContain("is relative");
|
|
// The row's inline layer still decides what Kilo loads.
|
|
const selected = await select({
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { command: ["/opt/other/rea", "mcp"] } },
|
|
}),
|
|
});
|
|
if (!selected.ok) throw selected.error;
|
|
expect(selected.value[0]?.inlineConfiguration?.origin).toBe(
|
|
"KILO_CONFIG_CONTENT",
|
|
);
|
|
const [outcome] = await registerMcpClientsOnHost(
|
|
selected.value,
|
|
{ command: command[0] ?? "", args: command.slice(1) },
|
|
undefined,
|
|
resources,
|
|
);
|
|
if (outcome?.status !== "completed") throw new Error("Kilo did not run");
|
|
if (outcome.result.ok) throw new Error("The inline launcher was ignored");
|
|
expect(outcome.result.error.message).toContain(
|
|
"higher-priority configuration overrides",
|
|
);
|
|
});
|
|
|
|
/** Uninstall's Kilo outcome, and every action detail it reported. */
|
|
const uninstallKilo = async (home: string, environment: NodeJS.ProcessEnv) => {
|
|
const result = await runUninstall(
|
|
false,
|
|
systemUninstallHost(home, undefined, environment, platform),
|
|
);
|
|
const kilo = result.items.find(({ name }) => name === "kilo");
|
|
return {
|
|
kilo,
|
|
details: [kilo?.detail, ...(kilo?.actions ?? []).map((a) => a.detail)].join(
|
|
"\n",
|
|
),
|
|
};
|
|
};
|
|
|
|
it("refuses to uninstall when removal would expose a lower Kilo layer's unowned entry", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-uninstall-lower-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
const lower = join(root, "kilo.json");
|
|
const unowned = JSON.stringify({
|
|
mcp: { rea: { type: "local", command: ["/opt/other/rea", "mcp"] } },
|
|
});
|
|
await writeFile(lower, unowned);
|
|
await mkdir(join(home, ".kilo"));
|
|
const upper = join(home, ".kilo", "kilo.json");
|
|
const owned = JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true } },
|
|
});
|
|
await writeFile(upper, owned);
|
|
const { kilo, details } = await uninstallKilo(home, {});
|
|
expect(kilo?.status).toBe("failed");
|
|
expect(details).toContain("another Kilo configuration layer");
|
|
expect(await readFile(lower, "utf8")).toBe(unowned);
|
|
expect(await readFile(upper, "utf8")).toBe(owned);
|
|
});
|
|
|
|
it("refuses to uninstall while KILO_CONFIG_CONTENT keeps REA's entry in effect", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-uninstall-inline-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
const target = join(root, "kilo.json");
|
|
const owned = JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true } },
|
|
});
|
|
await writeFile(target, owned);
|
|
const { kilo, details } = await uninstallKilo(home, {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { type: "local", command } },
|
|
}),
|
|
});
|
|
expect(kilo?.status).toBe("failed");
|
|
expect(details).toContain("KILO_CONFIG_CONTENT, which REA does not edit");
|
|
expect(await readFile(target, "utf8")).toBe(owned);
|
|
});
|
|
|
|
it("reports REA's Kilo entry that only KILO_CONFIG_CONTENT sets instead of calling uninstall complete", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-uninstall-inline-only-");
|
|
// Kilo is installed, and both files exist without REA's entry.
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
const other = JSON.stringify({ mcp: { other: { command: ["x"] } } });
|
|
await writeFile(join(root, "kilo.json"), other);
|
|
await mkdir(join(home, ".kilo"));
|
|
await writeFile(join(home, ".kilo", "kilo.json"), other);
|
|
const { kilo, details } = await uninstallKilo(home, {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true } },
|
|
}),
|
|
});
|
|
expect(kilo?.status).toBe("failed");
|
|
expect(details).toContain("Remove the rea entry from KILO_CONFIG_CONTENT");
|
|
// One report although uninstall visits each Kilo file.
|
|
expect(details.match(/KILO_CONFIG_CONTENT sets/g)).toHaveLength(1);
|
|
expect(await readFile(join(root, "kilo.json"), "utf8")).toBe(other);
|
|
});
|
|
|
|
it("leaves a stale Kilo registration KILO_CONFIG_CONTENT pins out of update maintenance", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-update-inline-");
|
|
await mkdir(join(home, ".config", "kilo"), { recursive: true });
|
|
const environment = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: {
|
|
rea: {
|
|
type: "local",
|
|
command: [
|
|
"npx",
|
|
"-y",
|
|
`${PRODUCT_IDENTITY.packageName}@3.2.0`,
|
|
"mcp",
|
|
],
|
|
enabled: true,
|
|
},
|
|
},
|
|
}),
|
|
};
|
|
const scope = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
environment,
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
expect(scope.clients).not.toContain("kilo");
|
|
expect(scope.unresolved).toEqual([
|
|
expect.objectContaining({
|
|
client: "kilo",
|
|
state: "stale",
|
|
remediation: expect.stringContaining(
|
|
"KILO_CONFIG_CONTENT overrides REA's rea registration",
|
|
),
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("maintains a stale Kilo registration whose KILO_CONFIG_CONTENT entry setup's refresh keeps", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-update-inline-kept-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(
|
|
join(root, "kilo.json"),
|
|
JSON.stringify({
|
|
mcp: {
|
|
rea: {
|
|
type: "local",
|
|
command: [
|
|
"npx",
|
|
"-y",
|
|
`${PRODUCT_IDENTITY.packageName}@3.2.0`,
|
|
"mcp",
|
|
],
|
|
enabled: true,
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
const scope = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
{
|
|
KILO_CONFIG_CONTENT: JSON.stringify({ mcp: { rea: { enabled: true } } }),
|
|
},
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
expect(scope.clients).toContain("kilo");
|
|
expect(scope.unresolved).toBeUndefined();
|
|
});
|
|
|
|
it("leaves an aligned Kilo registration out of update maintenance when KILO_CONFIG_CONTENT adds what setup would not write", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-update-inline-aligned-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(
|
|
join(root, "kilo.json"),
|
|
JSON.stringify({ mcp: { rea: { type: "local", command, enabled: true } } }),
|
|
);
|
|
const environment = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { environment: { FOO: "bar" } } },
|
|
}),
|
|
};
|
|
const [status] = await readClientRegistrationStatuses(
|
|
home,
|
|
command[1] ?? "",
|
|
{
|
|
platform: HOST_PLATFORM.platform,
|
|
environment,
|
|
selectedClientIds: ["kilo"],
|
|
},
|
|
);
|
|
expect(status).toMatchObject({ client: "kilo", state: "aligned" });
|
|
const scope = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
environment,
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
expect(scope.clients).not.toContain("kilo");
|
|
expect(scope.unresolved).toEqual([
|
|
expect.objectContaining({
|
|
client: "kilo",
|
|
state: "aligned",
|
|
remediation: expect.stringContaining(
|
|
"KILO_CONFIG_CONTENT overrides REA's rea registration",
|
|
),
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("reports a Kilo registration whose KILO_CONFIG_CONTENT differs only in a discovered provider path as needing setup", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-update-discovered-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(
|
|
join(root, "kilo.json"),
|
|
JSON.stringify({ mcp: { rea: { type: "local", command, enabled: true } } }),
|
|
);
|
|
const inline = (environment: Record<string, string>) =>
|
|
JSON.stringify({ mcp: { rea: { environment } } });
|
|
const hopper = "/Applications/Hopper Disassembler.app/Contents/MacOS/hopper";
|
|
const scope = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
{
|
|
KILO_CONFIG_CONTENT: inline({ HOPPER_LAUNCHER_PATH: hopper }),
|
|
},
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
// Setup may discover this launcher and write the same value, so update
|
|
// can neither maintain nor refuse the client: its alignment is unknown.
|
|
expect(scope.clients).not.toContain("kilo");
|
|
expect(scope.unresolved).toEqual([
|
|
expect.objectContaining({
|
|
client: "kilo",
|
|
state: "unknown",
|
|
remediation: expect.stringMatching(
|
|
/KILO_CONFIG_CONTENT sets HOPPER_LAUNCHER_PATH .*Run rea setup to check and refresh it\.$/,
|
|
),
|
|
}),
|
|
]);
|
|
|
|
// An explicit selection or another setting is a conflict update can prove.
|
|
for (const environment of [
|
|
{
|
|
HOPPER_LAUNCHER_PATH: "/opt/hopper",
|
|
KILO_CONFIG_CONTENT: inline({ HOPPER_LAUNCHER_PATH: hopper }),
|
|
},
|
|
{
|
|
KILO_CONFIG_CONTENT: inline({ HOPPER_LAUNCHER_PATH: hopper, FOO: "bar" }),
|
|
},
|
|
]) {
|
|
const refused = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
environment,
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
expect(refused.unresolved).toEqual([
|
|
expect.objectContaining({
|
|
client: "kilo",
|
|
state: "aligned",
|
|
remediation: expect.stringContaining(
|
|
"KILO_CONFIG_CONTENT overrides REA's rea registration",
|
|
),
|
|
}),
|
|
]);
|
|
}
|
|
});
|
|
|
|
it("reports a Kilo registration whose matching KILO_CONFIG_CONTENT sets a discovered provider path as needing setup", async () => {
|
|
const home = await createTestTempDirectory(
|
|
"rea-kilo-update-discovered-match-",
|
|
);
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
const hopper = "/opt/hopper/hopper";
|
|
await writeFile(
|
|
join(root, "kilo.json"),
|
|
JSON.stringify({
|
|
mcp: {
|
|
rea: {
|
|
type: "local",
|
|
command,
|
|
enabled: true,
|
|
environment: { HOPPER_LAUNCHER_PATH: hopper },
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
const scope = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
{
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { environment: { HOPPER_LAUNCHER_PATH: hopper } } },
|
|
}),
|
|
},
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
// The entry matches today, but setup may discover another launcher that
|
|
// the inline layer would then override.
|
|
expect(scope.clients).not.toContain("kilo");
|
|
expect(scope.unresolved).toEqual([
|
|
expect.objectContaining({
|
|
client: "kilo",
|
|
state: "unknown",
|
|
remediation: expect.stringContaining(
|
|
"KILO_CONFIG_CONTENT sets HOPPER_LAUNCHER_PATH",
|
|
),
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("leaves a Kilo file whose own launcher REA does not own out of update maintenance", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-update-foreign-file-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(
|
|
join(root, "kilo.json"),
|
|
JSON.stringify({
|
|
mcp: {
|
|
rea: { type: "local", command: ["/opt/other/server"], enabled: true },
|
|
},
|
|
}),
|
|
);
|
|
const scope = await existingMaintenanceScope(
|
|
home,
|
|
command[1] ?? "",
|
|
{
|
|
KILO_CONFIG_CONTENT: JSON.stringify({ mcp: { rea: { command } } }),
|
|
},
|
|
{ platform: HOST_PLATFORM.platform },
|
|
);
|
|
// The effective entry is REA's, but setup refuses to replace the file's
|
|
// foreign launcher, so maintenance must not select Kilo.
|
|
expect(scope.clients).not.toContain("kilo");
|
|
expect(scope.unresolved).toEqual([
|
|
expect.objectContaining({ client: "kilo" }),
|
|
]);
|
|
});
|
|
|
|
it("matches a discovered setting by Windows environment identity in KILO_CONFIG_CONTENT", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-update-discovered-win-");
|
|
const root = join(home, ".config", "kilo");
|
|
await mkdir(root, { recursive: true });
|
|
await writeFile(
|
|
join(root, "kilo.json"),
|
|
JSON.stringify({ mcp: { rea: { type: "local", command, enabled: true } } }),
|
|
);
|
|
const environment = {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { environment: { Java_Home: "/opt/java" } } },
|
|
}),
|
|
};
|
|
const kilo = await kiloRow(home, environment);
|
|
if (kilo === undefined) throw new Error("Kilo row missing");
|
|
// `Java_Home` is the JAVA_HOME setup discovers on Windows, and a distinct
|
|
// name elsewhere.
|
|
expect(
|
|
await clientRefreshRefusal(kilo, {}, command, {
|
|
platform: "win32",
|
|
currentCommandPath: command[1] ?? "",
|
|
}),
|
|
).toMatchObject({
|
|
alignment: "unknown",
|
|
remediation: expect.stringContaining("KILO_CONFIG_CONTENT sets JAVA_HOME"),
|
|
});
|
|
expect(
|
|
await clientRefreshRefusal(kilo, {}, command, {
|
|
platform: "linux",
|
|
currentCommandPath: command[1] ?? "",
|
|
}),
|
|
).toMatchObject({
|
|
alignment: "refused",
|
|
});
|
|
});
|
|
|
|
it("inspects REA's Kilo entry that only KILO_CONFIG_CONTENT sets when no Kilo folder exists", async () => {
|
|
const home = await createTestTempDirectory("rea-kilo-inline-evidence-");
|
|
const statuses = await readClientRegistrationStatuses(
|
|
home,
|
|
command[1] ?? "",
|
|
{
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {
|
|
KILO_CONFIG_CONTENT: JSON.stringify({
|
|
mcp: { rea: { type: "local", command, enabled: true } },
|
|
}),
|
|
},
|
|
},
|
|
);
|
|
expect(statuses).toContainEqual(
|
|
expect.objectContaining({ client: "kilo", state: "aligned" }),
|
|
);
|
|
});
|