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): reuse verified Linux fallback after cached install failure

MagicLizi14937422f227
diff --git a/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts b/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts
index 59d4dbe1ff..8ab120308c 100644
--- a/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts
+++ b/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts
@@ -297,6 +297,35 @@ describe('explicit Pi selection on startup', () => {
});
describe('Linux local discovery before any update download', () => {
+ // Independent review of #7435: a valid private CLI can differ from the new app's
+ // bundled pin. A corrupt optional cache must not route it through pin-only repair.
+ it('keeps an already usable private Linux Claude when a newer prepared archive is corrupt', async () => {
+ await reloadBinaries('linux');
+ const current = newerStableVersion(PINNED_CLAUDE_VERSION);
+ const target = newerStableVersion(current);
+ const runtimeRoot = path.join(mocks.userDataDir, 'agent-runtime', 'claude-code');
+ const localPath = writeExecutable(path.join(runtimeRoot, 'bin', 'claude'), `${current} (Claude Code)`);
+ fs.writeFileSync(path.join(runtimeRoot, '.version'), current);
+ const archive = gzipSync(Buffer.from(target));
+ const sha256 = createHash('sha256').update(archive).digest('hex');
+ mocks.remoteManifest = { app: { version: '2.0.0' }, claudeCode: {
+ version: target, file: `claude-code/${target}/linux-x64/claude.gz`, sha256, size: archive.length,
+ } };
+ mocks.backgroundDownload.mockImplementation(async ({ targetPath }: { targetPath: string }) => {
+ fs.writeFileSync(targetPath, archive);
+ return { path: targetPath, sha256, size: archive.length };
+ });
+ await expect(binaries.prefetch('claude-code', { manifest: mocks.remoteManifest })).resolves.toBe(true);
+ const altered = Buffer.from(archive);
+ altered[0] ^= 1;
+ fs.writeFileSync(path.join(mocks.userDataDir, 'agent-binary-downloads', 'claude', sha256, 'archive'), altered);
+ mocks.download.mockRejectedValue(new Error('unexpected network fallback'));
+ const result = await binaries.prepare('claude-code', quiet);
+ expect.soft(result).toMatchObject({ ready: true, path: localPath });
+ expect.soft(mocks.download).not.toHaveBeenCalled();
+ expect(fs.readFileSync(localPath, 'utf8')).toBe(`${current} (Claude Code)`);
+ });
+
// #7435: a completed cache must not silently downgrade a user-managed Claude.
// Public prefetch -> prepare, one newer system CLI and one older archive. Unit.
it('keeps a newer Linux system Claude when an older background download is complete', async () => {
diff --git a/apps/desktop/src/main/agent-binaries/index.ts b/apps/desktop/src/main/agent-binaries/index.ts
index 9f45caafef..76b6ea30b0 100644
--- a/apps/desktop/src/main/agent-binaries/index.ts
+++ b/apps/desktop/src/main/agent-binaries/index.ts
@@ -440,6 +440,7 @@ export async function prepare(
// 可能已拉取并缓存)→ 清标记走 CDN,CDN 资产可用时不该被旧标记跳过。
if (getCachedManifest()) skipCdnUntilNextProbeSuccess = false;
const cdnSkipped = skipCdnUntilNextProbeSuccess;
+ let usableLocalFallbackPath: string | undefined;
if (opts.checkForUpdates === false) {
const hasLocalCdnRuntime = getCachedManifest() && !await getBase(kind).peekNeedsDownload(opts);
if (!hasLocalCdnRuntime) {
@@ -462,6 +463,7 @@ export async function prepare(
}
// Try the completed cache first. A corrupt or locked cache falls back
// to the working system/private runtime without starting network IO.
+ usableLocalFallbackPath = localPath;
opts = { ...opts, allowDownload: false };
}
}
@@ -483,6 +485,10 @@ export async function prepare(
}
}
if (cdnResult.ready) return cdnResult;
+ if (usableLocalFallbackPath) {
+ lastReadyPath.set(kind, usableLocalFallbackPath);
+ return { ready: true, path: usableLocalFallbackPath, downloaded: false };
+ }
if (broadcastProgress) {
broadcastBinaryDownloadProgress({