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。

test(desktop): fork 用例把未登录态 temp 路径也隔离到每例临时目录(#4598)

Zhang Yunjina9c713f1a18a
diff --git a/apps/desktop/src/main/__tests__/fork.test.ts b/apps/desktop/src/main/__tests__/fork.test.ts
index bf22a25378..4fa4ebf857 100644
--- a/apps/desktop/src/main/__tests__/fork.test.ts
+++ b/apps/desktop/src/main/__tests__/fork.test.ts
@@ -60,7 +60,13 @@ vi.mock('electron', () => ({
// app.getPath('userData');mock 必须暴露 app,否则报「No "app" export is defined
// on the electron mock」。指向 beforeEach 建的临时目录(userDataDirRef),随
// tempDirs 生命周期一起清理,绝不碰真实 userData。
- app: { getPath: (name: string) => (name === 'userData' ? userDataDirRef.current : `/tmp/cindy-fork-test/${name}`) },
+ // `temp` 也要一起隔离:未登录时 ownerScopedUserDataPath 退到 app.getPath('temp'),
+ // 固定路径会让同一进程内的用例共享同一份偏好文件(Greptile P2,2026-10-24)。
+ app: {
+ getPath: (name: string) => (
+ name === 'userData' || name === 'temp' ? userDataDirRef.current : `/tmp/cindy-fork-test/${name}`
+ ),
+ },
}));
vi.mock('../localDb/ipc/sessionCreatedBroadcast.js', () => ({
emitSessionCreated: sessionCreatedMock,
@@ -150,10 +156,9 @@ beforeEach(async () => {
selectQueue.length = 0;
txCalls.length = 0;
// 预算文件的 userData 隔离:每个用例一个新的临时目录(electron mock 的 app.getPath 指向它)。
- fs.mkdtemp(path.join(os.tmpdir(), 'cindy-fork-userdata-')).then((dir) => {
- userDataDirRef.current = dir;
- tempDirs.push(dir);
- });
+ // 必须 await:否则用例可能在目录建好之前就写偏好,落到上一个用例的目录里。
+ userDataDirRef.current = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-fork-userdata-'));
+ tempDirs.push(userDataDirRef.current);
txMock.mockClear();
queryOneMock.mockReset();
queryOneMock.mockResolvedValue(null);