Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): reject agent updates before unsupported apply paths
Cindy305b28dee260
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.tsindex d96cf59e84..fdcf877c13 100644--- a/apps/desktop/src/main/__tests__/updateService.test.ts+++ b/apps/desktop/src/main/__tests__/updateService.test.ts@@ -357,6 +357,43 @@ describe('agent-triggered managed app update', () => {}});+ it('rejects a staged patch after the macOS app moves into a translocated location', async () => {+ readAutoUpdateSettings.mockReturnValue({ autoRelaunchOnIdle: false });+ fetchManifest.mockResolvedValue(updateManifest());+ download.mockImplementation(async ({ targetPath }: { targetPath: string }) => {+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });+ fs.writeFileSync(targetPath, 'update');+ return { path: targetPath, size: 123 };+ });+ const service = await freshUpdateService('darwin');+ expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'ready' });+ appIsInApplicationsFolder.mockReturnValue(false);+ expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });+ expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });+ await vi.advanceTimersByTimeAsync(5_000);+ expect(spawnProcess).not.toHaveBeenCalled();+ service.stopUpdateService();+ });++ it('reports an unsupported Linux installation before fetching an update', async () => {+ const service = await freshUpdateService('linux');+ expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });+ expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });+ expect(fetchManifest).not.toHaveBeenCalled();+ checkDebianManagedInstallation.mockReturnValue({ status: 'managed' });+ expect(await service.checkAppUpdateForAgent()).not.toMatchObject({ status: 'unsupported' });+ service.stopUpdateService();+ });++ it('reports missing Windows updater prerequisites before fetching an update', async () => {+ const service = await freshUpdateService('win32');+ checkWindowsUpdaterPrerequisites.mockReturnValue({ satisfied: false, missingFiles: ['vcruntime140.dll'] });+ expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });+ expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });+ expect(fetchManifest).not.toHaveBeenCalled();+ service.stopUpdateService();+ });+it('does not schedule an update from a development build or a current version', async () => {const service = await freshUpdateService('darwin');isDev.mockReturnValue(true);diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.tsindex b868420e90..7333125f2f 100644--- a/apps/desktop/src/main/updateService.ts+++ b/apps/desktop/src/main/updateService.ts@@ -2073,6 +2073,34 @@ async function executeRelaunchUnguarded(theme: 'light' | 'dark'): Promise<void>// ── Public API ─────────────────────────────────────────────────────────────+/** Report known platform apply blockers before telling the agent an update can be scheduled. */+function agentUpdateApplyBlockReason(): string | null {+ if (process.platform !== 'win32' && process.platform !== 'darwin' && process.platform !== 'linux') {+ return '当前平台不支持应用内更新。';+ }+ if (isMacAppTranslocated()) return '请先将 Cindy 移入「应用程序」文件夹,再安装更新。';+ if (process.platform === 'win32' && !checkWindowsUpdaterPrerequisites(undefined, process.resourcesPath).satisfied) {+ return 'Windows 更新器运行环境不可用;已下载的更新将保留。';+ }+ if (process.platform === 'linux') {+ const exePath = app.getPath('exe');+ const installation = findLinuxUserInstallation(exePath, os.homedir(), process.getuid?.() ?? -1);+ if (installation) {+ if (installation.region !== CURRENT_CINDY_REGION || missingLinuxUserInstallTools().length > 0) {+ return '当前 Linux 用户安装环境不支持应用内更新。';+ }+ } else {+ const debianCheck = checkDebianManagedInstallation(exePath);+ if (debianCheck.status !== 'managed') {+ return debianCheck.status === 'error'+ ? '暂时无法验证 Linux 安装来源,请稍后重试。'+ : '当前 Linux 安装方式不支持应用内更新;请使用安装说明或系统包管理器。';+ }+ }+ }+ return null;+}+export async function checkAppUpdateForAgent(): Promise<{status: string;currentVersion: string;@@ -2083,6 +2111,8 @@ export async function checkAppUpdateForAgent(): Promise<{if (!app.isPackaged || isDev() || isCindyPersonalRuntime() || isVersionlessAppVersion(currentVersion)) {return { status: 'unsupported', currentVersion, reason: '此构建不支持应用内更新。' };}+ const platformBlock = agentUpdateApplyBlockReason();+ if (platformBlock) return { status: 'unsupported', currentVersion, reason: platformBlock };if (currentStatus === 'downloading' || currentStatus === 'superseding') {return { status: 'downloading', currentVersion, targetVersion: readyVersion };}@@ -2107,6 +2137,8 @@ export function installAppUpdateForAgent(): {if (!app.isPackaged || isDev() || isCindyPersonalRuntime() || isVersionlessAppVersion(currentVersion)) {return { accepted: false, currentVersion, reason: '此构建不支持应用内更新。' };}+ const platformBlock = agentUpdateApplyBlockReason();+ if (platformBlock) return { accepted: false, currentVersion, reason: platformBlock };if (agentRelaunchScheduled || isRelaunching || autoRelaunchInProgress) {return { accepted: false, currentVersion, reason: '更新重启已在进行中。' };}