fix(uninstall): keep emptied DSH inserts from applying overrides (#13036)

* test(uninstall): reproduce DSH inserts becoming active overrides

* fix(uninstall): preserve the mode of emptied DSH insert operations
This commit is contained in:
Kaoru0822 authored and GitHub committed 2026-11-21 00:23:02 -08:00
1 parent 270c3a6b28
commit 76da8fd8ba
2 files changed
+40 -18

No files matched your search

+4 -4
View File
@@ -11,7 +11,7 @@ import { isRecord } from "../kernel/isRecord.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 PATCH_ROUTING_KEYS = new Set(["id", "name", "insert"]);
const isPatchRecord = (value: unknown): value is Record<string, unknown> =>
isRecord(value) && !(value instanceof CordisExpression);
@@ -329,13 +329,13 @@ export class DshCordisDocument {
this.#entry(edit.desired, edit.platform, invalidated),
] as typeof inserted.items;
});
if (inserted.items.length === 0) copy.delete("insert");
// An emptied operation keeps caller fields unless it would patch REA's row.
// Cordis still treats an empty insert list as an insert operation.
// Dropping the list would activate the other fields as direct overrides.
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),
(pair) => !PATCH_ROUTING_KEYS.has(this.#yaml.key(pair.key)),
));
replacements.set(op.source, kept ? copy : undefined);
}
@@ -2748,14 +2748,19 @@ 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 () => {
it("keeps a group insert from activating its ignored overrides on uninstall", async () => {
const { home, client } = await harnessClient();
const entry = canonicalEntry();
await writeFile(
client.configPath,
`- insert:
- id: user-a
name: plugin-a
const initial = `- insert:
- id: tools
name: "@deepseek-ai/cordis-plugin-group"
group: true
config:
- id: user-a
name: plugin-a
- id: user-a
config:
sandbox: permissive
# caller group patch
- id: tools
config:
@@ -2768,18 +2773,32 @@ describe("DeepSeek Harness uninstall of a shared operation", () => {
transport: stdio
command: ${entry.config.command}
args: ${JSON.stringify(entry.config.args)}
`,
);
`;
await writeFile(client.configPath, initial);
expect((await systemUninstallHost(home).removeClient(client)).status).toBe(
"removed",
);
const host = systemUninstallHost(home);
expect((await host.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" } },
{
insert: [
{
id: "tools",
name: "@deepseek-ai/cordis-plugin-group",
group: true,
config: [{ id: "user-a", name: "plugin-a" }],
},
],
},
{ id: "user-a", config: { sandbox: "permissive" } },
{ id: "tools", config: { sandbox: "strict" }, insert: [] },
]);
expect(text).toContain("# caller group patch");
expect((await host.removeClient(client)).status).toBe("skipped");
expect(await readFile(client.configPath, "utf8")).toBe(text);
expect(await readFile(`${client.configPath}.rea.backup`, "utf8")).toBe(
initial,
);
});
it("keeps an operation's own fields when setup removes a second REA row from it", async () => {
@@ -2810,7 +2829,10 @@ ${row("second-launcher")}`,
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((parseYaml(text) as unknown[]).at(-1)).toEqual({
disabled: false,
insert: [],
});
expect(await dshStatus(home)).toMatchObject({ state: "aligned" });
});