Files
reverse-engineering-anything/tests/boundary/filesystem/vibeClientConfiguration.test.ts
T
07de725f17 feat(setup): register Mistral Vibe CLI client (#15278)
* feat(setup): register Mistral Vibe CLI client

* fix(setup): preserve inline Vibe entry order and reject non-boolean enable_mcp on read

* fix(setup): report duplicate Vibe registrations in doctor and preserve separated subtables

* docs(setup): record the Mistral Vibe 3.2.0 registration check

Mistral Vibe 3.2.0 on Linux loaded the setup registration through its
configuration schema and discovered REA's tools over stdio. After its own
`vibe mcp add` rewrote the file, setup made no change and uninstall removed
only the REA entry.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

---------

Co-authored-by: gensokyo-dev <gensokyo-dev@users.noreply.github.com>
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-12-03 12:46:21 +08:00

666 lines
22 KiB
TypeScript

import { access, mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { parseClientToml } from "../../../src/application/ClientConfigurationToml.js";
import { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
import {
configureClientConfiguration,
inspectClientConfiguration,
} from "../../../src/application/SetupClientConfiguration.js";
import { supportedClients } from "../../../src/application/SupportedClients.js";
import {
runUninstall,
systemUninstallHost,
} from "../../../src/application/Uninstall.js";
import { CURRENT_ENTRYPOINT_PATH } from "../../../src/process/CurrentEntrypointPath.js";
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
beforeEach(clearClientLocationEnvironment);
afterEach(() => vi.unstubAllEnvs());
const vibeClientFor = (
home: string,
env: Readonly<NodeJS.ProcessEnv> = {},
platform: NodeJS.Platform = process.platform,
) => {
const [client] = supportedClients(home, platform, env, {}, "vibe");
if (client === undefined) throw new Error("vibe client row is missing");
return client;
};
const currentLauncher = (): readonly [string, string, ...string[]] => {
const [command, entrypoint, ...rest] = currentClientRegistrationCommand();
if (command === undefined || entrypoint === undefined)
throw new Error("current REA launcher command is unavailable");
return [command, entrypoint, ...rest];
};
describe("Mistral Vibe CLI configuration boundary", () => {
it("resolves ~/.vibe/config.toml by default, honors VIBE_HOME, and refuses relative overrides", async () => {
const home = await createTestTempDirectory("rea-vibe-paths-");
const defaultClient = vibeClientFor(home, {}, "darwin");
expect(defaultClient.configPath).toBe(join(home, ".vibe", "config.toml"));
expect(defaultClient.markerPath).toBe(join(home, ".vibe"));
const customHome = join(home, "custom-vibe");
const customClient = vibeClientFor(
home,
{ VIBE_HOME: customHome },
"darwin",
);
expect(customClient.configPath).toBe(join(customHome, "config.toml"));
expect(customClient.markerPath).toBe(customHome);
const tildeClient = vibeClientFor(
home,
{ VIBE_HOME: "~/profiles/vibe" },
"darwin",
);
expect(tildeClient.configPath).toBe(
join(home, "profiles", "vibe", "config.toml"),
);
const relativeClient = vibeClientFor(
home,
{ VIBE_HOME: "relative/vibe" },
"darwin",
);
expect(relativeClient.configPathError).toContain("VIBE_HOME");
expect(relativeClient.configPathError).toContain("relative");
const drivelessWindows = vibeClientFor(
"C:\\Users\\analyst",
{ VIBE_HOME: "\\vibe" },
"win32",
);
expect(drivelessWindows.configPathError).toContain("VIBE_HOME");
expect(drivelessWindows.configPathError).toContain("drive");
});
it("round-trips a disposable Vibe profile through setup, doctor, idempotent rerun, and uninstall", async () => {
const home = await createTestTempDirectory("rea-vibe-roundtrip-");
const vibeHome = join(home, "disposable-vibe");
const configPath = join(vibeHome, "config.toml");
const env = { VIBE_HOME: vibeHome };
const original = [
"# User Vibe profile",
'active_model = "devstral-2"',
"",
"# Sibling stdio server",
"[[mcp_servers]]",
'name = "fetch_server"',
'transport = "stdio"',
'command = "uvx"',
'args = ["mcp-server-fetch"]',
"",
"[mcp_servers.env]",
'NO_COLOR = "1"',
"",
"[[mcp_servers]]",
'name = "mistralai"',
'transport = "streamable-http"',
'url = "https://api.mistral.ai/mcp"',
"",
].join("\n");
await mkdir(vibeHome, { recursive: true });
await writeFile(configPath, original, "utf8");
const client = vibeClientFor(home, env);
const launcher = currentLauncher();
expect(
await inspectClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toMatchObject({ status: "update" });
const configured = await configureClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
);
expect(configured.status).toBe("configured");
const afterFirst = await readFile(configPath, "utf8");
expect(afterFirst).toContain("# User Vibe profile");
expect(afterFirst).toContain("# Sibling stdio server");
expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(original);
const parsed = parseClientToml(afterFirst);
expect(parsed.active_model).toBe("devstral-2");
expect(parsed.mcp_servers).toEqual([
{
name: "fetch_server",
transport: "stdio",
command: "uvx",
args: ["mcp-server-fetch"],
env: { NO_COLOR: "1" },
},
{
name: "mistralai",
transport: "streamable-http",
url: "https://api.mistral.ai/mcp",
},
{
name: "rea",
transport: "stdio",
command: launcher[0],
args: launcher.slice(1),
},
]);
// Doctor recognizes the registration as aligned and owned
const statuses = await readClientRegistrationStatuses(
home,
CURRENT_ENTRYPOINT_PATH,
{
platform: process.platform,
environment: env,
selectedClientIds: ["vibe"],
scope: "user",
},
);
expect(statuses.find(({ client: id }) => id === "vibe")).toMatchObject({
client: "vibe",
config_path: configPath,
command: [...launcher],
command_identity: "owned",
state: "aligned",
remediation: null,
});
// Re-running setup keeps a single REA entry without rewriting
expect(
await inspectClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toEqual({ status: "already_current" });
expect(
await configureClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toEqual({ status: "unchanged" });
expect(await readFile(configPath, "utf8")).toBe(afterFirst);
// Uninstall removes only the REA-owned row and preserves siblings + unrelated TOML
const uninstall = await runUninstall(
false,
systemUninstallHost(home, undefined, env, process.platform),
);
expect(uninstall.status).toBe("complete");
expect(uninstall.items.find(({ name }) => name === "vibe")).toMatchObject({
status: "removed",
});
const afterUninstall = await readFile(configPath, "utf8");
expect(afterUninstall).toContain("# User Vibe profile");
expect(afterUninstall).toContain("# Sibling stdio server");
expect(parseClientToml(afterUninstall)).toEqual(parseClientToml(original));
});
it("reports user-owned same-name rea collisions in setup, doctor, and uninstall", async () => {
const home = await createTestTempDirectory("rea-vibe-collision-");
const vibeHome = join(home, ".vibe");
const configPath = join(vibeHome, "config.toml");
await mkdir(vibeHome, { recursive: true });
const launcher = currentLauncher();
// Case 1: user-owned stdio server named "rea"
const foreignStdio = [
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
'command = "uvx"',
'args = ["custom-rea-server"]',
"",
].join("\n");
await writeFile(configPath, foreignStdio, "utf8");
const client = vibeClientFor(home);
expect(
await inspectClientConfiguration(client, {}, launcher),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("foreign ownership"),
});
expect(
await configureClientConfiguration(client, {}, launcher),
).toMatchObject({
status: "failed",
reason: "registration_ownership",
});
expect(await readFile(configPath, "utf8")).toBe(foreignStdio);
await expect(access(`${configPath}.rea.backup`)).rejects.toMatchObject({
code: "ENOENT",
});
const doctorForeign = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: {},
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorForeign).toMatchObject({
state: "stale",
command_identity: "foreign",
remediation: expect.stringContaining("foreign ownership"),
});
const uninstallForeign = await runUninstall(
false,
systemUninstallHost(home, undefined, {}, process.platform),
);
expect(uninstallForeign.status).toBe("complete");
expect(
uninstallForeign.items.find(({ name }) => name === "vibe")?.status,
).toBe("retained");
expect(await readFile(configPath, "utf8")).toBe(foreignStdio);
// Case 2: user-owned remote streamable-http entry named "rea"
const foreignRemote = [
"[[mcp_servers]]",
'name = "rea"',
'transport = "streamable-http"',
'url = "https://example.invalid/mcp"',
"",
].join("\n");
await writeFile(configPath, foreignRemote, "utf8");
expect(
await inspectClientConfiguration(client, {}, launcher),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("unknown ownership"),
});
expect(await readFile(configPath, "utf8")).toBe(foreignRemote);
// Case 3: duplicate "rea" rows where an earlier row is foreign and last row is REA-owned
const shadowedForeign = [
foreignStdio,
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
].join("\n");
await writeFile(configPath, shadowedForeign, "utf8");
const doctorShadowedForeign = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: {},
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorShadowedForeign).toMatchObject({
state: "stale",
command_identity: "foreign",
remediation: expect.stringContaining("foreign ownership"),
});
expect(
await inspectClientConfiguration(client, {}, launcher),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("foreign ownership"),
});
const uninstallShadowed = await runUninstall(
false,
systemUninstallHost(home, undefined, {}, process.platform),
);
expect(uninstallShadowed.status).toBe("failed");
expect(
uninstallShadowed.items.find(({ name }) => name === "vibe"),
).toMatchObject({
status: "failed",
detail: expect.stringContaining("not REA-owned"),
});
expect(await readFile(configPath, "utf8")).toBe(shadowedForeign);
// Case 4: duplicate "rea" rows where an earlier row has unknown ownership (remote) and last row is REA-owned
const shadowedUnknown = [
foreignRemote,
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
].join("\n");
await writeFile(configPath, shadowedUnknown, "utf8");
const doctorShadowedUnknown = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: {},
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorShadowedUnknown).toMatchObject({
state: "unknown",
command_identity: "unknown",
remediation: expect.stringContaining("unknown ownership"),
});
// Case 5: duplicate REA-owned "rea" rows report stale in doctor and collapse cleanly on setup
const duplicateOwned = [
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
].join("\n");
await writeFile(configPath, duplicateOwned, "utf8");
const doctorDuplicateOwned = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: {},
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorDuplicateOwned).toMatchObject({
state: "stale",
command_identity: "owned",
remediation: expect.stringContaining('Multiple "rea" registrations'),
});
expect(
await configureClientConfiguration(client, {}, launcher),
).toMatchObject({ status: "configured" });
const doctorDeduplicated = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: {},
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorDeduplicated).toMatchObject({
state: "aligned",
command_identity: "owned",
remediation: null,
});
});
it("blocks setup and explains unavailability in doctor when enable_mcp = false", async () => {
const home = await createTestTempDirectory("rea-vibe-policy-");
const vibeHome = join(home, "policy-vibe");
const configPath = join(vibeHome, "config.toml");
const env = { VIBE_HOME: vibeHome };
await mkdir(vibeHome, { recursive: true });
const client = vibeClientFor(home, env);
const launcher = currentLauncher();
// Without a rea entry: setup refuses, doctor explains enable_mcp = false
const disabledWithoutRea = [
"enable_mcp = false",
'active_model = "devstral-2"',
"",
].join("\n");
await writeFile(configPath, disabledWithoutRea, "utf8");
expect(
await inspectClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("enable_mcp = false"),
});
expect(
await configureClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toMatchObject({ status: "failed", reason: "readback" });
expect(await readFile(configPath, "utf8")).toBe(disabledWithoutRea);
const doctorWithoutRea = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: env,
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorWithoutRea).toMatchObject({
state: "manual",
config_path: configPath,
remediation: expect.stringContaining("enable_mcp = false"),
});
// With an existing owned rea entry: setup STILL refuses (never reports already_current)
// and doctor reports stale with enable_mcp = false explanation.
const disabledWithRea = [
"enable_mcp = false",
"",
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
].join("\n");
await writeFile(configPath, disabledWithRea, "utf8");
expect(
await inspectClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("enable_mcp = false"),
});
const doctorWithRea = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: env,
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctorWithRea).toMatchObject({
state: "stale",
command_identity: "owned",
remediation: expect.stringContaining("enable_mcp = false"),
});
// Uninstall still cleans up the REA-owned row while preserving enable_mcp = false
const uninstall = await runUninstall(
false,
systemUninstallHost(home, undefined, env, process.platform),
);
expect(uninstall.status).toBe("complete");
expect(uninstall.items.find(({ name }) => name === "vibe")).toMatchObject({
status: "removed",
});
expect(parseClientToml(await readFile(configPath, "utf8"))).toEqual({
enable_mcp: false,
});
// VIBE_ENABLE_MCP=false environment override also blocks setup and doctor
await writeFile(configPath, 'active_model = "devstral-2"\n', "utf8");
const envDisabled = { VIBE_HOME: vibeHome, VIBE_ENABLE_MCP: "false" };
expect(
await inspectClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
envDisabled,
),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("VIBE_ENABLE_MCP"),
});
expect(
(
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: envDisabled,
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe"),
).toMatchObject({
state: "manual",
remediation: expect.stringContaining("VIBE_ENABLE_MCP"),
});
// Boolean enable_mcp = false still allows uninstall to remove an owned rea row
const disabledWithOwned = [
"enable_mcp = false",
"",
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
].join("\n");
await writeFile(configPath, disabledWithOwned, "utf8");
const uninstallDisabled = await runUninstall(
false,
systemUninstallHost(home, undefined, env, process.platform),
);
expect(uninstallDisabled.status).toBe("complete");
expect(
uninstallDisabled.items.find(({ name }) => name === "vibe"),
).toMatchObject({ status: "removed" });
expect(parseClientToml(await readFile(configPath, "utf8"))).toEqual({
enable_mcp: false,
});
// Non-boolean enable_mcp is reported as malformed in setup, doctor, and uninstall
const nonBooleanWithOwned = [
'enable_mcp = "false"',
"",
"[[mcp_servers]]",
'name = "rea"',
'transport = "stdio"',
`command = ${JSON.stringify(launcher[0])}`,
`args = ${JSON.stringify(launcher.slice(1))}`,
"",
].join("\n");
await writeFile(configPath, nonBooleanWithOwned, "utf8");
expect(
await inspectClientConfiguration(
client,
{},
launcher,
undefined,
process.platform,
env,
),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("enable_mcp"),
});
expect(
(
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: env,
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe"),
).toMatchObject({
state: "invalid",
remediation: expect.stringContaining("boolean"),
});
const uninstallNonBoolean = await runUninstall(
false,
systemUninstallHost(home, undefined, env, process.platform),
);
expect(uninstallNonBoolean.status).toBe("failed");
expect(await readFile(configPath, "utf8")).toBe(nonBooleanWithOwned);
});
it("refuses malformed config.toml in setup, doctor, and uninstall without rewriting it", async () => {
const home = await createTestTempDirectory("rea-vibe-malformed-");
const vibeHome = join(home, ".vibe");
const configPath = join(vibeHome, "config.toml");
await mkdir(vibeHome, { recursive: true });
const malformed = '[[mcp_servers]\nname = "rea"\n';
await writeFile(configPath, malformed, "utf8");
const client = vibeClientFor(home);
const launcher = currentLauncher();
expect(
await inspectClientConfiguration(client, {}, launcher),
).toMatchObject({
status: "invalid",
remediation: expect.stringContaining("malformed"),
});
expect(
await configureClientConfiguration(client, {}, launcher),
).toMatchObject({ status: "failed", reason: "readback" });
expect(await readFile(configPath, "utf8")).toBe(malformed);
const doctor = (
await readClientRegistrationStatuses(home, CURRENT_ENTRYPOINT_PATH, {
platform: process.platform,
environment: {},
selectedClientIds: ["vibe"],
scope: "user",
})
).find(({ client: id }) => id === "vibe");
expect(doctor).toMatchObject({
state: "invalid",
config_path: configPath,
});
const uninstall = await runUninstall(
false,
systemUninstallHost(home, undefined, {}, process.platform),
);
expect(uninstall.status).toBe("failed");
expect(await readFile(configPath, "utf8")).toBe(malformed);
});
});