From 94153f1c757e07a6d092e00903aa8b125d4a0afa Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:38:04 +0800 Subject: [PATCH] fix(uninstall): label YAML configuration syntax failures correctly Report malformed Hermes and DeepSeek Harness documents as YAML. Carry the compiled setup/uninstall diagnostics coverage from #2153 onto the existing validation from #2157, including unchanged files and no backup writes. Add malformed YAML scenarios for both clients. Validation: 174 focused tests, npm run check, test discovery, package verification, and npm pack --dry-run. Co-authored-by: Jax367 <239124526+Jax367@users.noreply.github.com> --- src/application/Uninstall.ts | 2 +- .../clientConfigurationDiagnosticsCli.test.ts | 154 ++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/setup/clientConfigurationDiagnosticsCli.test.ts diff --git a/src/application/Uninstall.ts b/src/application/Uninstall.ts index 570b5589e..c410280bc 100644 --- a/src/application/Uninstall.ts +++ b/src/application/Uninstall.ts @@ -289,7 +289,7 @@ const readClientConfiguration = async ( "failed", cause instanceof ClientConfigurationShapeError ? `Configuration was not changed: ${cause.message}. Repair it, then rerun uninstall.` - : `Configuration is not valid ${client.format === "toml" || client.format === "grok" ? "TOML" : client.format === "opencode" ? "JSONC" : "JSON"} and was not changed. Repair it, then rerun uninstall.`, + : `Configuration is not valid ${client.format === "toml" || client.format === "grok" ? "TOML" : client.format === "opencode" ? "JSONC" : client.format === "hermes" || client.format === "dsh" ? "YAML" : "JSON"} and was not changed. Repair it, then rerun uninstall.`, ), ); } diff --git a/tests/acceptance/setup/clientConfigurationDiagnosticsCli.test.ts b/tests/acceptance/setup/clientConfigurationDiagnosticsCli.test.ts new file mode 100644 index 000000000..d9363988f --- /dev/null +++ b/tests/acceptance/setup/clientConfigurationDiagnosticsCli.test.ts @@ -0,0 +1,154 @@ +import { mkdir, readFile, readdir, writeFile } from "node:fs/promises"; +import { dirname, join } from "node:path"; +import { expect } from "vitest"; + +import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { cliTest } from "../../support/cli/cliFixture.js"; + +const cases = [ + { + client: "cursor", + path: ".cursor/mcp.json", + text: "[]", + diagnostic: "The configuration root must be an object", + }, + { + client: "cursor", + path: ".cursor/mcp.json", + text: "null", + diagnostic: "The configuration root must be an object", + }, + { + client: "cursor", + path: ".cursor/mcp.json", + text: '{"mcpServers":null,"keep":1}', + diagnostic: '"mcpServers" must be an object', + }, + { + client: "cursor", + path: ".cursor/mcp.json", + text: '{"mcpServers":"x","keep":1}', + diagnostic: '"mcpServers" must be an object', + }, + { + client: "pi", + path: ".pi/agent/mcp.json", + text: '{"mcpServers":[]}', + diagnostic: '"mcpServers" must be an object', + }, + { + client: "codex", + path: ".codex/config.toml", + text: 'mcp_servers = "x"\n', + diagnostic: '"mcp_servers" must be an object', + }, + { + client: "opencode", + path: ".config/opencode/opencode.json", + text: '{"mcp":{"servers":null}}', + diagnostic: '"mcp.servers" must be an object', + }, + { + client: "hermes", + path: ".hermes/config.yaml", + text: "- item\n", + diagnostic: "The configuration root must be an object", + }, + { + client: "hermes", + path: ".hermes/config.yaml", + text: "mcp_servers: null\nkeep: 1\n", + diagnostic: '"mcp_servers" must be an object', + }, + { + client: "cursor", + path: ".cursor/mcp.json", + text: "not-json", + diagnostic: "Configuration is not valid JSON", + syntax: "JSON", + }, + { + client: "hermes", + path: ".hermes/config.yaml", + text: "mcp_servers: [\n", + diagnostic: "Configuration is not valid YAML", + syntax: "YAML", + }, + { + client: "dsh", + path: ".dsh/cordis.patch.yml", + text: "- insert: [\n", + diagnostic: "Configuration is not valid YAML", + syntax: "YAML", + }, +] as const; + +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 config = join(home, scenario.path); + await mkdir(dirname(config), { recursive: true }); + await writeFile(config, scenario.text); + const environment = { + HOME: home, + USERPROFILE: home, + XDG_CONFIG_HOME: join(home, ".config"), + HERMES_HOME: join(home, ".hermes"), + DSH_HOME: join(home, ".dsh"), + }; + const setup = await cli.run({ + arguments: [ + "setup", + "--client", + scenario.client, + "--skill=false", + "--yes", + "--json", + ], + cwd: home, + environment, + }); + expect(setup.exitCode).toBe(1); + expect(setup.json).toMatchObject({ + status: "needs_human", + plannedActions: [], + appliedActions: [], + }); + if ("syntax" in scenario) { + expect(setup.json).toMatchObject({ remediation: expect.any(String) }); + if (scenario.syntax === "JSON") + expect(setup.stdout).toContain("Invalid JSON/JSONC"); + } else { + expect(setup.json).toMatchObject({ + remediation: expect.stringContaining(scenario.diagnostic), + }); + expect(setup.stdout).not.toContain("invalid_type"); + } + const uninstall = await cli.run({ + arguments: ["uninstall", "--json"], + cwd: home, + environment, + }); + expect(uninstall.exitCode).toBe(1); + expect(uninstall.json).toMatchObject({ + status: "failed", + items: expect.arrayContaining([ + expect.objectContaining({ + name: scenario.client, + status: "failed", + detail: expect.stringContaining(scenario.diagnostic), + }), + ]), + }); + if (!("syntax" in scenario)) + expect(uninstall.stdout).not.toContain("not valid JSON"); + expect(await readFile(config, "utf8")).toBe(scenario.text); + expect(await readdir(dirname(config))).toEqual([ + scenario.path.split("/").at(-1), + ]); + }, + );