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(desktop): treat non-file migration ledgers as present (fail closed)

Yuewei-LL7d5f495e822b
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
index 38265647ee..f1a4d62e43 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
@@ -734,6 +734,25 @@ describe('GhostManager · 迁移崩溃安全(in-progress 状态机)与隔离命
expect(await fs.promises.readFile(migrationLedgerPath(), 'utf8')).toBe('{ not valid json');
});
+ it.skipIf(process.platform === 'win32')(
+ '台账是非普通文件(symlink)→ 门保守关死,不迁也不重写',
+ async () => {
+ await writeLegacyInstall('aaa', goodManifest('aaa'));
+ await fs.promises.mkdir(path.join(workDir, 'ghosts-install-state'), { recursive: true });
+ const outside = path.join(workDir, 'ledger-outside.json');
+ await fs.promises.writeFile(outside, '{}', 'utf8');
+ await fs.promises.symlink(outside, migrationLedgerPath());
+
+ const outcome = await manager.migrateLegacyApprovalsOnce();
+ expect(outcome).toEqual({ migrated: [], skipped: [], failed: [], retryPending: [] });
+ expect(manager.list()[0].approval.state).toBe('legacy-unapproved');
+ // 门关死:ledger 未被重写(仍是 symlink 指向外部文件)。
+ const st = await fs.promises.lstat(migrationLedgerPath());
+ expect(st.isSymbolicLink()).toBe(true);
+ expect(await fs.promises.readFile(migrationLedgerPath(), 'utf8')).toBe('{}');
+ },
+ );
+
it.each([
['empty pendingIds', []],
['non-string pending id', [null]],
diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
index 64408e0796..0157f299c9 100644
--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
@@ -447,10 +447,13 @@ export class GhostInstallReceiptStore {
return ledger === null || ledger.state !== 'in-progress';
}
- /** 是否已跑过一轮 legacy 迁移(全局一次性门;读不动按"存在"处理,宁可不再迁)。 */
+ /** 是否已跑过一轮 legacy 迁移(全局一次性门;存在即按"已跑"处理,宁可不再迁)。 */
hasMigrationLedger(): boolean {
try {
- return fs.lstatSync(this.migrationLedgerPath()).isFile();
+ // 只要路径存在就视为已迁,不论它是普通文件还是 symlink / FIFO / 设备节点:
+ // 把非普通 ledger 判成"不存在"会让迁移门重开,允许从当前可变安装目录重铸授权。
+ fs.lstatSync(this.migrationLedgerPath());
+ return true;
} catch (error) {
// ENOENT = 从未迁过,可以迁;其它错误(权限等)= 状态未知,保守当作"已迁",
// 绝不因为读不动 ledger 就把迁移(=从可变安装目录重建授权)再放开一次。