Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(setup): keep a Cordis operation's own fields when uninstall empties it (#2730)
Jeremy Levartovskyba06d9ec521f
diff --git a/src/application/DshCordisPatch.ts b/src/application/DshCordisPatch.tsindex 5e0fc10ec..0e34da23e 100644--- a/src/application/DshCordisPatch.ts+++ b/src/application/DshCordisPatch.ts@@ -8,6 +8,7 @@ import { CordisExpression, DshCordisYaml } from "./DshCordisYaml.js";export const DSH_ENTRY_ID = "rea-mcp";export const DSH_CLIENT_PACKAGE = "@deepseek-ai/dsh-mcp-client";const LAUNCHER_KEYS = new Set(["serverName", "transport", "command", "args"]);+const SELECTOR_KEYS = new Set(["id", "name"]);const isRecord = (value: unknown): value is Record<string, unknown> =>typeof value === "object" &&value !== null &&@@ -295,10 +296,15 @@ export class DshCordisDocument {carried = true;return [this.#entry(desired, invalidated)] as typeof inserted.items;});- replacements.set(- op.source,- inserted.items.length === 0 ? undefined : copy,- );+ if (inserted.items.length === 0) copy.delete("insert");+ // An emptied operation keeps caller fields unless it would patch REA's row.+ const kept =+ inserted.items.length > 0 ||+ (this.#id(op.map) !== DSH_ENTRY_ID &&+ copy.items.some(+ (pair) => !SELECTOR_KEYS.has(this.#yaml.value(pair.key) as string),+ ));+ replacements.set(op.source, kept ? copy : undefined);}const output = this.#yaml.document.clone();const outputRoot = output.contents;diff --git a/tests/boundary/filesystem/dshClientConfiguration.test.ts b/tests/boundary/filesystem/dshClientConfiguration.test.tsindex c0315f67b..fd65e6b00 100644--- a/tests/boundary/filesystem/dshClientConfiguration.test.ts+++ b/tests/boundary/filesystem/dshClientConfiguration.test.ts@@ -2195,3 +2195,135 @@ describe("DeepSeek Harness caller node metadata", () => {},);});++describe("DeepSeek Harness uninstall of a shared operation", () => {+ it("keeps a group patch's own fields and comment when its only row was REA's", async () => {+ const { home, client } = await harnessClient();+ const entry = canonicalEntry();+ await writeFile(+ client.configPath,+ `- insert:+ - id: user-a+ name: plugin-a+# caller group patch+- id: tools+ config:+ sandbox: strict+ insert:+ - id: rea-mcp+ name: "${entry.name}"+ config:+ serverName: rea+ transport: stdio+ command: ${entry.config.command}+ args: ${JSON.stringify(entry.config.args)}+`,+ );++ expect((await systemUninstallHost(home).removeClient(client)).status).toBe(+ "removed",+ );+ const text = await readFile(client.configPath, "utf8");+ expect(parseYaml(text)).toEqual([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ { id: "tools", config: { sandbox: "strict" } },+ ]);+ expect(text).toContain("# caller group patch");+ });++ it("keeps an operation's own fields when setup removes a second REA row from it", async () => {+ // Setup refuses a REA row in a group patch, so the setup path meets the+ // keep rule only on an operation without a selector.+ const { home, client } = await harnessClient();+ const entry = canonicalEntry();+ const row = (launcher: string) => ` - id: rea-mcp+ name: "${entry.name}"+ config:+ serverName: rea+ transport: stdio+ command: ${launcher}+ args: [mcp]+`;+ await writeFile(+ client.configPath,+ `- insert:+${row("first-launcher")}# caller operation+- disabled: false+ insert:+${row("second-launcher")}`,+ );++ expect(+ (await configureClientConfiguration(client, {}, command)).status,+ ).toBe("configured");+ const text = await readFile(client.configPath, "utf8");+ expect(text).toContain("# caller operation");+ expect(loadedInserts(text)).toHaveLength(1);+ expect((parseYaml(text) as unknown[]).at(-1)).toEqual({ disabled: false });+ expect(await dshStatus(home)).toMatchObject({ state: "aligned" });+ });++ it("drops an emptied operation that targets REA's own row", async () => {+ const { home, client } = await harnessClient();+ await writeFile(+ client.configPath,+ stringifyYaml([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ {+ id: "rea-mcp",+ config: { serverName: "rea" },+ insert: [canonicalEntry()],+ },+ ]),+ );++ const host = systemUninstallHost(home);+ expect((await host.removeClient(client)).status).toBe("removed");+ expect(parseYaml(await readFile(client.configPath, "utf8"))).toEqual([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ ]);+ });++ it.each([+ { selector: { id: "tools" } },+ { selector: { name: "tools" } },+ { selector: { id: "tools", name: "tools" } },+ ])(+ "drops an emptied operation left with only its target selector $selector",+ async ({ selector }) => {+ const { home, client } = await harnessClient();+ await writeFile(+ client.configPath,+ stringifyYaml([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ { ...selector, insert: [canonicalEntry()] },+ ]),+ );++ expect(+ (await systemUninstallHost(home).removeClient(client)).status,+ ).toBe("removed");+ expect(parseYaml(await readFile(client.configPath, "utf8"))).toEqual([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ ]);+ },+ );++ it("still drops an insert-only operation that REA's row emptied", async () => {+ const { home, client } = await harnessClient();+ await writeFile(+ client.configPath,+ stringifyYaml([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ { insert: [canonicalEntry()] },+ ]),+ );++ expect((await systemUninstallHost(home).removeClient(client)).status).toBe(+ "removed",+ );+ expect(parseYaml(await readFile(client.configPath, "utf8"))).toEqual([+ { insert: [{ id: "user-a", name: "plugin-a" }] },+ ]);+ });+});