Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): resolve the workbench directory path on removal like add does (#5346)

billythegodb389f7106e45
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchService.test.ts
index 80d1a26ea1..81175e4ebb 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchService.test.ts
@@ -183,3 +183,19 @@ describe('bot workbench judgments', () => {
expect(normalized?.tasks.long.next).toHaveLength(120);
});
});
+
+describe('bot workbench directory removal normalization', () => {
+ it('removes a handed-over project addressed by an equivalent, differently-spelled path', async () => {
+ // 回归:add 存 path.resolve 后的路径, remove 曾按原始串比较 —— 尾分隔符、
+ // ./、../ 等等价写法会静默漏删, 广播后 UI 里项目仍在。
+ root = await mkdtemp(path.join(os.tmpdir(), 'bot-workbench-'));
+ const proj = path.join(root, 'proj');
+ const nested = path.join(proj, 'inner');
+ await mkdir(nested, { recursive: true });
+ await addBotWorkbenchDirectory(root, 'bot-1', proj, new Date('2026-10-01T01:00:00.000Z'));
+
+ // 等价写法:inner/.. 投影回 proj, 再补一个尾分隔符。
+ await removeBotWorkbenchDirectory(root, 'bot-1', `${nested}${path.sep}..${path.sep}`);
+ expect((await readBotWorkbenchState(root, 'bot-1')).directories).toEqual([]);
+ });
+});
diff --git a/apps/desktop/src/main/maker-ipc/botWorkbenchService.ts b/apps/desktop/src/main/maker-ipc/botWorkbenchService.ts
index a70d6fb2db..42455ce504 100644
--- a/apps/desktop/src/main/maker-ipc/botWorkbenchService.ts
+++ b/apps/desktop/src/main/maker-ipc/botWorkbenchService.ts
@@ -266,8 +266,12 @@ export async function addBotWorkbenchDirectory(
}
export async function removeBotWorkbenchDirectory(userDataDir: string, botId: string, dirPath: string): Promise<void> {
+ // 与 add 同口径归一:add 存的是 path.resolve 后的路径, remove 若按原始串比较,
+ // 等价但写法不同的路径(尾分隔符、./、../ 段)会静默漏删, 且广播后 UI 里项目
+ // 仍在。resolve 后比较。
+ const resolved = path.resolve(dirPath);
await mutate(userDataDir, botId, (stored) => ({
- next: { ...stored, directories: stored.directories.filter((dir) => dir.path !== dirPath) },
+ next: { ...stored, directories: stored.directories.filter((dir) => dir.path !== resolved) },
result: undefined,
}));
}