test(setup): isolate client fixtures across host platforms

This commit is contained in:
morluto
2026-10-05 23:13:56 +08:00
parent 348323dd23
commit f73bb0fe11
3 changed files with 44 additions and 17 deletions
+12 -1
View File
@@ -1,5 +1,6 @@
import { chmod, mkdir, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { supportedClients } from "../dist/application/SupportedClients.js";
/** Create an isolated prefix, fake PATH, client configs, and environment. */
export async function verifyPackageEnvironment({
@@ -48,7 +49,11 @@ export async function verifyPackageEnvironment({
chmod(hopper, 0o755),
chmod(npx, 0o755),
]);
const claudeDir = join(home, "Library/Application Support/Claude");
const claudeDir = supportedClients(home, process.platform, {}).find(
({ name }) => name === "claude_desktop",
)?.markerPath;
if (claudeDir === undefined)
throw new Error("Claude Desktop fixture has no configuration directory");
const codexDir = join(home, ".codex");
const cursorDir = join(home, ".cursor");
await Promise.all([
@@ -69,6 +74,12 @@ export async function verifyPackageEnvironment({
const environment = {
...process.env,
HOME: home,
USERPROFILE: home,
APPDATA: join(home, "AppData", "Roaming"),
CLAUDE_CONFIG_DIR: home,
CODEX_HOME: codexDir,
COPILOT_HOME: join(home, ".copilot"),
OPENCODE_CONFIG: undefined,
XDG_CONFIG_HOME: join(home, ".config"),
PATH: `${fakeBin}:${process.env.PATH ?? ""}`,
REA_ANALYSIS_PROVIDER: "auto",
@@ -1,7 +1,7 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { parse as parseJsonc, type ParseError } from "jsonc-parser";
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
@@ -19,6 +19,20 @@ const command = [
"mcp",
] as const;
beforeEach(() => {
for (const name of [
"APPDATA",
"CLAUDE_CONFIG_DIR",
"CODEX_HOME",
"COPILOT_HOME",
"OPENCODE_CONFIG",
"XDG_CONFIG_HOME",
])
vi.stubEnv(name, undefined);
});
afterEach(() => vi.unstubAllEnvs());
const getClients = (home: string) =>
supportedClients(home).filter(({ name }) =>
["opencode", "antigravity", "copilot_cli", "vscode", "devin"].includes(
@@ -9,9 +9,10 @@ import {
writeFile,
} from "node:fs/promises";
import { dirname, join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { supportedClients } from "../../../src/application/SupportedClients.js";
import {
configureTomlClient,
@@ -24,7 +25,19 @@ import {
} from "../../../src/application/Uninstall.js";
const roots: string[] = [];
beforeEach(() => {
for (const name of [
"APPDATA",
"CLAUDE_CONFIG_DIR",
"CODEX_HOME",
"COPILOT_HOME",
"OPENCODE_CONFIG",
"XDG_CONFIG_HOME",
])
vi.stubEnv(name, undefined);
});
afterEach(async () => {
vi.unstubAllEnvs();
await Promise.all(
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
);
@@ -34,20 +47,9 @@ describe("client configuration filesystem lifecycle", () => {
it("detects every supported client and skips absent clients", async () => {
const home = await createTestTempDirectory("rea-detect-");
roots.push(home);
for (const marker of [
".claude",
"Library/Application Support/Claude",
".codex",
".cursor",
".gemini",
".codeium/windsurf",
".config/devin",
".config/opencode",
".gemini/config",
".copilot",
"Library/Application Support/Code/User",
])
await mkdir(join(home, marker), { recursive: true });
for (const client of supportedClients(home))
if (client.markerPath !== undefined)
await mkdir(client.markerPath, { recursive: true });
const detected = await detectClients(home);
expect(detected.map(({ name }) => name)).toEqual([
"claude_code",