test(setup): share configuration transaction fixtures (#17414)

This commit is contained in:
Vincent Koc
2026-12-06 14:21:19 +08:00
committed by GitHub
parent e0234f6e1e
commit c10a94bea7
@@ -35,6 +35,22 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { ClientConfigurationPublication } from "../../../src/application/ClientConfigurationPublication.js";
import { supportedClientRegistrationProfile } from "../../fixtures/clientRegistrationProfile.js";
const cursorClientAt = (configPath: string) =>
({
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath,
}) as const;
const codexClientAt = (configPath: string) =>
({
name: "codex",
registrationProfile: supportedClientRegistrationProfile("codex"),
format: "toml",
configPath,
}) as const;
it
.skipIf(process.platform === "win32")
.each(["direct", "parent", "lexical-parent"] as const)(
@@ -81,12 +97,7 @@ it.skipIf(process.platform === "win32")(
await writeFile(existing, original);
await chmod(existing, 0o640);
const client = {
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath: existing,
} as const;
const client = cursorClientAt(existing);
expect(
await configureClientConfiguration(client, {}, ownedPackageCommand),
).toMatchObject({ status: "configured" });
@@ -113,12 +124,7 @@ const editedSinceSetup = async (prefix: string) => {
const root = await createTestTempDirectory(prefix);
const configPath = join(root, ".cursor", "mcp.json");
await mkdir(dirname(configPath), { recursive: true });
const client = {
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath,
} as const;
const client = cursorClientAt(configPath);
const beforeSetup = '{"keep":"before setup"}\n';
await writeFile(configPath, beforeSetup);
expect(
@@ -300,12 +306,7 @@ it("accepts a literal UTF-8 replacement character without changing its value", a
]);
await writeFile(configPath, original);
const result = await configureClientConfiguration(
{
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath,
},
cursorClientAt(configPath),
{},
ownedPackageCommand,
);
@@ -383,12 +384,7 @@ it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
await chmod(root, 0o500);
try {
expect(
await configureClientConfiguration({
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath,
}),
await configureClientConfiguration(cursorClientAt(configPath)),
).toMatchObject({
status: "failed",
reason: "write",
@@ -415,12 +411,7 @@ describe("TOML client configuration comparison", () => {
const configPath = join(root, "config.toml");
const original = `unrelated = ${value}\n[mcp_servers.rea]\ncommand = "npx"\nargs = ["-y", "rea-agents@6.1.0", "mcp"]\nstartup_timeout_sec = ${value}\n`;
await writeFile(configPath, original);
const client = {
name: "codex",
registrationProfile: supportedClientRegistrationProfile("codex"),
format: "toml",
configPath,
} as const;
const client = codexClientAt(configPath);
expect(
await configureClientConfiguration(client, {}, ownedPackageCommand),
).toEqual({
@@ -492,12 +483,7 @@ describe("Codex configuration text preservation", () => {
async ({ original, preserved }) => {
const root = await createTestTempDirectory("rea-codex-preserve-");
const configPath = join(root, "config.toml");
const client = {
name: "codex",
registrationProfile: supportedClientRegistrationProfile("codex"),
format: "toml",
configPath,
} as const;
const client = codexClientAt(configPath);
await writeFile(configPath, original);
expect(
@@ -529,12 +515,7 @@ describe("Codex configuration text preservation", () => {
it("preserves a comments-only file and its first backup through uninstall and setup again", async () => {
const root = await createTestTempDirectory("rea-codex-backup-");
const configPath = join(root, "config.toml");
const client = {
name: "codex",
registrationProfile: supportedClientRegistrationProfile("codex"),
format: "toml",
configPath,
} as const;
const client = codexClientAt(configPath);
const original =
"# Keep this explanation.\n# And this trailing comment.\n\n";
const backup = `${configPath}.rea.backup`;
@@ -568,12 +549,7 @@ describe("Codex configuration text preservation", () => {
it("refuses malformed Codex TOML unchanged without creating a backup", async () => {
const root = await createTestTempDirectory("rea-codex-malformed-");
const configPath = join(root, "config.toml");
const client = {
name: "codex",
registrationProfile: supportedClientRegistrationProfile("codex"),
format: "toml",
configPath,
} as const;
const client = codexClientAt(configPath);
const original =
"# Keep this explanation.\n[mcp_servers.rea]\ncommand = [broken\n";
await writeFile(configPath, original);
@@ -604,16 +580,9 @@ it
await chmod(configPath, mode);
const host = systemUninstallHost(root);
try {
expect(
(
await host.removeClient({
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath,
})
).status,
).toBe("removed");
expect((await host.removeClient(cursorClientAt(configPath))).status).toBe(
"removed",
);
expect((await lstat(configPath)).mode & 0o777).toBe(mode);
expect(JSON.parse(await readFile(configPath, "utf8"))).toEqual({
mcpServers: {},