mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 04:34:13 +00:00
perf(tests): share isolated homes per environment across setup and profile CLI suites
This commit is contained in:
1 parent
5c1f58e24f
commit
de12494939
4 files changed
+325
-218
No files matched your search
@@ -3,14 +3,42 @@ import {
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
import { afterAll, beforeAll, beforeEach, expect } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../support/workspace/workspaceFixture.js";
|
||||
|
||||
let sharedDiagnosticHome = "";
|
||||
|
||||
beforeAll(async () => {
|
||||
sharedDiagnosticHome = (
|
||||
await createTestWorkspace("rea-client-config-diagnostic-")
|
||||
).root;
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
for (const entry of await readdir(sharedDiagnosticHome)) {
|
||||
await rm(join(sharedDiagnosticHome, entry), {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (sharedDiagnosticHome !== "") {
|
||||
await removeTestWorkspace(sharedDiagnosticHome);
|
||||
}
|
||||
});
|
||||
|
||||
const cases = [
|
||||
{
|
||||
@@ -120,9 +148,7 @@ for (const scenario of cases)
|
||||
cliTest(
|
||||
`setup and uninstall explain ${scenario.client} configuration ${scenario.text}`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory(
|
||||
"rea-client-config-diagnostic-",
|
||||
);
|
||||
const home = sharedDiagnosticHome;
|
||||
const config = join(home, scenario.path);
|
||||
await mkdir(dirname(config), { recursive: true });
|
||||
const original =
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
import { artifactMcpCall } from "../../../scripts/lib/artifact-e2e.mjs";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { expect } from "vitest";
|
||||
import { afterAll, beforeAll, beforeEach, expect } from "vitest";
|
||||
import { parse } from "yaml";
|
||||
import { z } from "zod";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../support/workspace/workspaceFixture.js";
|
||||
|
||||
let sharedDshHome = "";
|
||||
|
||||
beforeAll(async () => {
|
||||
sharedDshHome = (await createTestWorkspace("rea-dsh-shared-")).root;
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
for (const entry of await readdir(sharedDshHome)) {
|
||||
await rm(join(sharedDshHome, entry), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (sharedDshHome !== "") {
|
||||
await removeTestWorkspace(sharedDshHome);
|
||||
}
|
||||
});
|
||||
|
||||
cliTest.for(["setup", "uninstall"] as const)(
|
||||
"DSH CLI %s refuses a multi-document patch without losing caller content",
|
||||
async (operation, { cli }) => {
|
||||
const home = await createTestTempDirectory("rea-dsh-multiple-documents-");
|
||||
const home = sharedDshHome;
|
||||
const profile = join(home, ".dsh");
|
||||
const config = join(profile, "cordis.patch.yml");
|
||||
await mkdir(profile);
|
||||
@@ -341,7 +363,7 @@ async function verifyGeneratedLauncher(
|
||||
cliTest.for(["null", "caller-value", "[caller-value]"])(
|
||||
"DSH CLI refuses to edit config %s and plain uninstall removes its owned row",
|
||||
async (configValue, { cli }) => {
|
||||
const home = await createTestTempDirectory("rea-dsh-malformed-config-");
|
||||
const home = sharedDshHome;
|
||||
const profile = join(home, ".dsh");
|
||||
const config = join(profile, "cordis.patch.yml");
|
||||
await mkdir(profile);
|
||||
@@ -411,7 +433,7 @@ cliTest.for([
|
||||
])(
|
||||
"DSH CLI rejects setup and preserves ownership for $label",
|
||||
async ({ patch, remediation, removal }, { cli }) => {
|
||||
const home = await createTestTempDirectory("rea-dsh-ownership-");
|
||||
const home = sharedDshHome;
|
||||
const profile = join(home, ".dsh");
|
||||
const config = join(profile, "cordis.patch.yml");
|
||||
await mkdir(profile);
|
||||
|
||||
@@ -1,11 +1,40 @@
|
||||
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import {
|
||||
access,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { parse, stringify } from "yaml";
|
||||
import { expect } from "vitest";
|
||||
import { afterAll, beforeAll, beforeEach, expect } from "vitest";
|
||||
|
||||
import { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../support/workspace/workspaceFixture.js";
|
||||
|
||||
let sharedHermesHome = "";
|
||||
|
||||
beforeAll(async () => {
|
||||
sharedHermesHome = (await createTestWorkspace("rea-hermes-alias-shared-"))
|
||||
.root;
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
for (const entry of await readdir(sharedHermesHome)) {
|
||||
await rm(join(sharedHermesHome, entry), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (sharedHermesHome !== "") {
|
||||
await removeTestWorkspace(sharedHermesHome);
|
||||
}
|
||||
});
|
||||
|
||||
const configuration = (
|
||||
version: "1.1" | "1.2",
|
||||
@@ -31,39 +60,11 @@ const configuration = (
|
||||
};
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} uninstall preserves an aliased table without REA`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory(
|
||||
"rea-hermes-absent-uninstall-",
|
||||
);
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original = configuration(version, false).text;
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original);
|
||||
const removed = await cli.run({
|
||||
arguments: ["uninstall", "--json"],
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
});
|
||||
expect(removed.exitCode).toBe(0);
|
||||
expect(await readFile(config, "utf8")).toBe(original);
|
||||
await expect(access(`${config}.rea.backup`)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
for (const existing of [false, true]) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} ${existing ? "refreshes" : "adds"} REA in an aliased table without changing its source`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-table-alias-");
|
||||
const home = sharedHermesHome;
|
||||
const ghidra = join(home, "missing-ghidra");
|
||||
const java = join(home, "missing-java");
|
||||
const profile = join(home, "profile");
|
||||
@@ -142,8 +143,36 @@ for (const version of ["1.1", "1.2"] as const) {
|
||||
}
|
||||
}
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} uninstall preserves an aliased table without REA`,
|
||||
async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original = configuration(version, false).text;
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original);
|
||||
const removed = await cli.run({
|
||||
arguments: ["uninstall", "--json"],
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
});
|
||||
expect(removed.exitCode).toBe(0);
|
||||
expect(await readFile(config, "utf8")).toBe(original);
|
||||
await expect(access(`${config}.rea.backup`)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
cliTest("Hermes still registers into an explicit table", async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-explicit-table-");
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original = configuration("1.1", false, false);
|
||||
@@ -179,7 +208,7 @@ for (const version of ["1.1", "1.2"] as const) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} preserves shadowed alias bindings`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-shadowed-anchor-");
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original =
|
||||
@@ -220,7 +249,7 @@ for (const version of ["1.1", "1.2"] as const) {
|
||||
cliTest(
|
||||
"Hermes uninstall detaches an aliased table before deleting REA",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-aliased-uninstall-");
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
await mkdir(profile);
|
||||
@@ -291,7 +320,7 @@ for (const original of [
|
||||
cliTest(
|
||||
`Hermes refuses an invalid aliased table: ${original.trim()}`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-invalid-alias-");
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
await mkdir(profile);
|
||||
|
||||
@@ -1,11 +1,41 @@
|
||||
import { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||
import { access, mkdir, readFile, writeFile, rm } from "node:fs/promises";
|
||||
import {
|
||||
access,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
import { afterAll, beforeAll, beforeEach, expect } from "vitest";
|
||||
import { parse } from "jsonc-parser";
|
||||
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../support/workspace/workspaceFixture.js";
|
||||
|
||||
let sharedProfileHome = "";
|
||||
|
||||
beforeAll(async () => {
|
||||
sharedProfileHome = (await createTestWorkspace("rea-client-profiles-shared-"))
|
||||
.root;
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
for (const entry of await readdir(sharedProfileHome)) {
|
||||
await rm(join(sharedProfileHome, entry), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (sharedProfileHome !== "") {
|
||||
await removeTestWorkspace(sharedProfileHome);
|
||||
}
|
||||
});
|
||||
|
||||
cliTest(
|
||||
"Claude Code routes an empty config directory to its home registration",
|
||||
@@ -132,7 +162,7 @@ for (const policy of [{ excluded: ["rea"] }, { allowed: ["other"] }]) {
|
||||
cliTest(
|
||||
`Gemini refuses a registration blocked by ${Object.keys(policy)[0]}`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-policy-");
|
||||
const home = sharedProfileHome;
|
||||
const config = join(home, ".gemini/settings.json");
|
||||
const original = JSON.stringify({
|
||||
mcp: policy,
|
||||
@@ -190,7 +220,7 @@ for (const policy of [{ excluded: ["rea"] }, { allowed: ["other"] }]) {
|
||||
cliTest(
|
||||
"OpenCode diagnoses merged JSON/JSONC and removes owned entries from both files",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-opencode-layers-");
|
||||
const home = sharedProfileHome;
|
||||
const directory = join(home, ".config/opencode");
|
||||
await mkdir(directory, { recursive: true });
|
||||
const lower = join(directory, "opencode.json");
|
||||
@@ -268,7 +298,7 @@ cliTest(
|
||||
cliTest(
|
||||
"malformed lower-priority OpenCode config blocks setup before any writes",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-opencode-invalid-layer-");
|
||||
const home = sharedProfileHome;
|
||||
const directory = join(home, ".config/opencode");
|
||||
await mkdir(directory, { recursive: true });
|
||||
const lower = join(directory, "opencode.json");
|
||||
@@ -297,8 +327,8 @@ cliTest(
|
||||
cliTest(
|
||||
"Gemini system policy blocks a new registration without modifying managed files",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-managed-");
|
||||
const policy = join(home, "managed.json");
|
||||
const home = sharedProfileHome;
|
||||
const policy = join(home, "system.json");
|
||||
const original = JSON.stringify({
|
||||
mcp: { excluded: ["rea"] },
|
||||
unrelated: true,
|
||||
@@ -335,7 +365,7 @@ cliTest(
|
||||
cliTest(
|
||||
"Gemini intersects system/default/user allowlists and accepts an empty effective allowlist",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-allowlists-");
|
||||
const home = sharedProfileHome;
|
||||
const system = join(home, "system.json");
|
||||
const defaults = join(home, "defaults.json");
|
||||
const user = join(home, ".gemini/settings.json");
|
||||
@@ -385,7 +415,7 @@ cliTest(
|
||||
cliTest(
|
||||
"Gemini matches allowlist spellings independently of their policy order",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-case-");
|
||||
const home = sharedProfileHome;
|
||||
const system = join(home, "system.json");
|
||||
const defaults = join(home, "defaults.json");
|
||||
const environment = {
|
||||
@@ -429,7 +459,7 @@ cliTest(
|
||||
cliTest(
|
||||
"Gemini compares exclusions and padded allowlist entries through one normalization",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-normalized-");
|
||||
const home = sharedProfileHome;
|
||||
const system = join(home, "system.json");
|
||||
const defaults = join(home, "defaults.json");
|
||||
const environment = {
|
||||
@@ -466,130 +496,10 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"OpenCode doctor sees a global registration when the custom directory is absent",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-opencode-absent-custom-");
|
||||
const global = join(home, ".config/opencode/opencode.json");
|
||||
const custom = join(home, "missing-custom");
|
||||
await mkdir(dirname(global), { recursive: true });
|
||||
await writeFile(
|
||||
global,
|
||||
JSON.stringify({
|
||||
mcp: {
|
||||
rea: {
|
||||
type: "local",
|
||||
command: currentClientRegistrationCommand({
|
||||
entrypointPath: resolve("scripts/rea.mjs"),
|
||||
}),
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const run = (args: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: args,
|
||||
cwd: home,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
OPENCODE_CONFIG_DIR: custom,
|
||||
},
|
||||
});
|
||||
const doctor = await run(["doctor", "--client", "opencode", "--json"]);
|
||||
expect(doctor.exitCode).toBe(0);
|
||||
expect(doctor.json).toMatchObject({
|
||||
identity: {
|
||||
registrations: expect.arrayContaining([
|
||||
expect.objectContaining({ client: "opencode", state: "aligned" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
const planned = await run([
|
||||
"setup",
|
||||
"--client",
|
||||
"opencode",
|
||||
"--dry-run",
|
||||
"--json",
|
||||
]);
|
||||
expect(planned.json).toMatchObject({
|
||||
clientStates: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
client: expect.objectContaining({ name: "opencode" }),
|
||||
detected: true,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
await expect(access(custom)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"OpenCode retains the XDG global layer when a custom directory is selected",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-opencode-global-custom-");
|
||||
const global = join(home, ".config/opencode/opencode.json");
|
||||
const custom = join(home, "custom/opencode.jsonc");
|
||||
await mkdir(dirname(global), { recursive: true });
|
||||
await mkdir(dirname(custom), { recursive: true });
|
||||
const owned = {
|
||||
type: "local",
|
||||
command: currentClientRegistrationCommand({
|
||||
entrypointPath: resolve("scripts/rea.mjs"),
|
||||
}),
|
||||
enabled: true,
|
||||
};
|
||||
const original = JSON.stringify({
|
||||
mcp: { rea: owned, other: { type: "local", command: ["other"] } },
|
||||
});
|
||||
await writeFile(global, original);
|
||||
await writeFile(custom, "{}");
|
||||
const run = (args: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: args,
|
||||
cwd: home,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
OPENCODE_CONFIG_DIR: dirname(custom),
|
||||
},
|
||||
});
|
||||
const doctor = await run(["doctor", "--client", "opencode", "--json"]);
|
||||
expect(doctor.json).toMatchObject({
|
||||
identity: {
|
||||
registrations: expect.arrayContaining([
|
||||
expect.objectContaining({ client: "opencode", state: "aligned" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
await writeFile(global, "malformed");
|
||||
expect(
|
||||
(await run(["setup", "--client", "opencode", "--yes", "--json"])).json,
|
||||
).toMatchObject({
|
||||
status: "needs_human",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
remediation: expect.stringContaining(global),
|
||||
});
|
||||
expect(await readFile(custom, "utf8")).toBe("{}");
|
||||
await writeFile(global, original);
|
||||
expect(
|
||||
(await run(["setup", "--client", "opencode", "--yes", "--json"]))
|
||||
.exitCode,
|
||||
).toBe(0);
|
||||
expect((await run(["uninstall", "--json"])).exitCode).toBe(0);
|
||||
expect(parse(await readFile(global, "utf8"))).toEqual({
|
||||
mcp: { other: { type: "local", command: ["other"] } },
|
||||
});
|
||||
expect(parse(await readFile(custom, "utf8"))).toEqual({ mcp: {} });
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"Gemini blocks a conflicting system definition and accepts an identical managed entry",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-managed-server-");
|
||||
const home = sharedProfileHome;
|
||||
const user = join(home, ".gemini/settings.json");
|
||||
const system = join(home, "system.json");
|
||||
const defaults = join(home, "defaults.json");
|
||||
@@ -658,6 +568,168 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"Gemini validates trust configuration and honors a disabled folder trust feature",
|
||||
async ({ cli }) => {
|
||||
const home = sharedProfileHome;
|
||||
const project = join(home, "project");
|
||||
const workspace = join(project, ".gemini/settings.json");
|
||||
const user = join(home, ".gemini/settings.json");
|
||||
const trust = join(home, ".gemini/trustedFolders.json");
|
||||
await mkdir(dirname(workspace), { recursive: true });
|
||||
await mkdir(dirname(user), { recursive: true });
|
||||
await writeFile(workspace, JSON.stringify({ mcp: { excluded: ["rea"] } }));
|
||||
await writeFile(trust, JSON.stringify({ [project]: "INVALID" }));
|
||||
const run = () =>
|
||||
cli.run({
|
||||
arguments: ["setup", "--client", "gemini_cli", "--yes", "--json"],
|
||||
cwd: project,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
GEMINI_CLI_SYSTEM_SETTINGS_PATH: join(home, "system.json"),
|
||||
GEMINI_CLI_SYSTEM_DEFAULTS_PATH: join(home, "defaults.json"),
|
||||
},
|
||||
});
|
||||
expect((await run()).json).toMatchObject({
|
||||
status: "needs_human",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
remediation: expect.stringContaining(trust),
|
||||
});
|
||||
await expect(access(user)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await rm(trust);
|
||||
await writeFile(
|
||||
user,
|
||||
JSON.stringify({ security: { folderTrust: { enabled: false } } }),
|
||||
);
|
||||
expect((await run()).json).toMatchObject({
|
||||
status: "needs_human",
|
||||
remediation: expect.stringContaining("mcp.excluded"),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"OpenCode doctor sees a global registration when the custom directory is absent",
|
||||
async ({ cli }) => {
|
||||
const home = sharedProfileHome;
|
||||
const global = join(home, ".config/opencode/opencode.json");
|
||||
const custom = join(home, "custom");
|
||||
await mkdir(dirname(global), { recursive: true });
|
||||
await writeFile(
|
||||
global,
|
||||
JSON.stringify({
|
||||
mcp: {
|
||||
rea: {
|
||||
type: "local",
|
||||
command: currentClientRegistrationCommand({
|
||||
entrypointPath: resolve("scripts/rea.mjs"),
|
||||
}),
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const run = (args: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: args,
|
||||
cwd: home,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
OPENCODE_CONFIG_DIR: custom,
|
||||
},
|
||||
});
|
||||
const doctor = await run(["doctor", "--client", "opencode", "--json"]);
|
||||
expect(doctor.exitCode).toBe(0);
|
||||
expect(doctor.json).toMatchObject({
|
||||
identity: {
|
||||
registrations: expect.arrayContaining([
|
||||
expect.objectContaining({ client: "opencode", state: "aligned" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
const planned = await run([
|
||||
"setup",
|
||||
"--client",
|
||||
"opencode",
|
||||
"--dry-run",
|
||||
"--json",
|
||||
]);
|
||||
expect(planned.json).toMatchObject({
|
||||
clientStates: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
client: expect.objectContaining({ name: "opencode" }),
|
||||
detected: true,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
await expect(access(custom)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"OpenCode retains the XDG global layer when a custom directory is selected",
|
||||
async ({ cli }) => {
|
||||
const home = sharedProfileHome;
|
||||
const global = join(home, ".config/opencode/opencode.json");
|
||||
const custom = join(home, "custom/opencode.jsonc");
|
||||
await mkdir(dirname(global), { recursive: true });
|
||||
await mkdir(dirname(custom), { recursive: true });
|
||||
const owned = {
|
||||
type: "local",
|
||||
command: currentClientRegistrationCommand({
|
||||
entrypointPath: resolve("scripts/rea.mjs"),
|
||||
}),
|
||||
enabled: true,
|
||||
};
|
||||
const original = JSON.stringify({
|
||||
mcp: { rea: owned, other: { type: "local", command: ["other"] } },
|
||||
});
|
||||
await writeFile(global, original);
|
||||
await writeFile(custom, "{}");
|
||||
const run = (args: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: args,
|
||||
cwd: home,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
OPENCODE_CONFIG_DIR: dirname(custom),
|
||||
},
|
||||
});
|
||||
const doctor = await run(["doctor", "--client", "opencode", "--json"]);
|
||||
expect(doctor.json).toMatchObject({
|
||||
identity: {
|
||||
registrations: expect.arrayContaining([
|
||||
expect.objectContaining({ client: "opencode", state: "aligned" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
await writeFile(global, "malformed");
|
||||
expect(
|
||||
(await run(["setup", "--client", "opencode", "--yes", "--json"])).json,
|
||||
).toMatchObject({
|
||||
status: "needs_human",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
remediation: expect.stringContaining(global),
|
||||
});
|
||||
expect(await readFile(custom, "utf8")).toBe("{}");
|
||||
await writeFile(global, original);
|
||||
expect(
|
||||
(await run(["setup", "--client", "opencode", "--yes", "--json"]))
|
||||
.exitCode,
|
||||
).toBe(0);
|
||||
expect((await run(["uninstall", "--json"])).exitCode).toBe(0);
|
||||
expect(parse(await readFile(global, "utf8"))).toEqual({
|
||||
mcp: { other: { type: "local", command: ["other"] } },
|
||||
});
|
||||
expect(parse(await readFile(custom, "utf8"))).toEqual({ mcp: {} });
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"Gemini workspace policy follows persisted trust and explicit trust overrides",
|
||||
async ({ cli }) => {
|
||||
@@ -785,45 +857,3 @@ cliTest(
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"Gemini validates trust configuration and honors a disabled folder trust feature",
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-gemini-trust-invalid-");
|
||||
const project = join(home, "project");
|
||||
const workspace = join(project, ".gemini/settings.json");
|
||||
const user = join(home, ".gemini/settings.json");
|
||||
const trust = join(home, ".gemini/trustedFolders.json");
|
||||
await mkdir(dirname(workspace), { recursive: true });
|
||||
await mkdir(dirname(user), { recursive: true });
|
||||
await writeFile(workspace, JSON.stringify({ mcp: { excluded: ["rea"] } }));
|
||||
await writeFile(trust, JSON.stringify({ [project]: "INVALID" }));
|
||||
const run = () =>
|
||||
cli.run({
|
||||
arguments: ["setup", "--client", "gemini_cli", "--yes", "--json"],
|
||||
cwd: project,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
GEMINI_CLI_SYSTEM_SETTINGS_PATH: join(home, "system.json"),
|
||||
GEMINI_CLI_SYSTEM_DEFAULTS_PATH: join(home, "defaults.json"),
|
||||
},
|
||||
});
|
||||
expect((await run()).json).toMatchObject({
|
||||
status: "needs_human",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
remediation: expect.stringContaining(trust),
|
||||
});
|
||||
await expect(access(user)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await rm(trust);
|
||||
await writeFile(
|
||||
user,
|
||||
JSON.stringify({ security: { folderTrust: { enabled: false } } }),
|
||||
);
|
||||
expect((await run()).json).toMatchObject({
|
||||
status: "needs_human",
|
||||
remediation: expect.stringContaining("mcp.excluded"),
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user