fix(setup): keep a Cordis operation's own fields when uninstall empties it (#2730)

Squash merge of https://github.com/morluto/rea/pull/2730.

Co-authored-by: JayOfTheKeyboard <140487034+JayOfTheKeyboard@users.noreply.github.com>
This commit is contained in:
Jeremy Levartovsky
2026-10-13 23:46:46 +08:00
committed by GitHub
parent af7638fa9d
commit ba06d9ec52
2 changed files with 142 additions and 4 deletions
@@ -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" }] },
]);
});
});