Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): normalize download storage roots and receipt errors
Dash4c7253a57a73
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.tsindex cef4247856..0dc74d894f 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/downloadSlot.test.ts@@ -92,6 +92,9 @@ it('cancel reaches only the matching active request', async () => {it('hands opaque receipts only to the owning Node call and preserves legacy params', async () => {const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'plugin-receipt-test-')));+ const alias = root + '-alias';+ const outside = root + '-outside';+ await fs.symlink(root, alias, process.platform === 'win32' ? 'junction' : 'dir');let scope = 'a';const ghost = {enabled: true,@@ -99,7 +102,7 @@ it('hands opaque receipts only to the owning Node call and preserves legacy paramanifest: { node: {}, network: { hosts: ['github.com'] } },} as unknown as InstalledGhost;const slot = new PluginDownloadSlot({- root: (id) => path.join(root, id),+ root: (id) => path.join(alias, id),scope: () => scope,getGhost: () => ghost,send: () => {},@@ -138,14 +141,20 @@ it('hands opaque receipts only to the owning Node call and preserves legacy paradownloadTokens: { archive: result.token },params: {},};- expect(await slot.withNodeDownloads('other', payload, run)).toMatchObject({ ok: false });+ expect(await slot.withNodeDownloads('other', payload, run)).toMatchObject({+ ok: false,+ errorCode: 'INVALID_REQUEST',+ });expect(await slot.withNodeDownloads('p', payload, run)).toEqual({ ok: true });expect(called).toBe(1);expect(await slot.withNodeDownloads('p', { ...payload, params: { downloads: {} } }, run),).toMatchObject({ ok: false });scope = 'b';- expect(await slot.withNodeDownloads('p', payload, run)).toMatchObject({ ok: false });+ expect(await slot.withNodeDownloads('p', payload, run)).toMatchObject({+ ok: false,+ errorCode: 'INVALID_REQUEST',+ });scope = 'a';ghost.approval = { ...ghost.approval, revision: 'b' } as InstalledGhost['approval'];expect(await slot.withNodeDownloads('p', payload, run)).toMatchObject({ ok: false });@@ -153,7 +162,17 @@ it('hands opaque receipts only to the owning Node call and preserves legacy paraexpect(await slot.withNodeDownloads('p', legacy, async (p) => p)).toBe(legacy);await slot.removePlugin('p');await expect(fs.stat(path.join(root, 'p'))).rejects.toMatchObject({ code: 'ENOENT' });+ scope = 'a';+ await fs.mkdir(outside);+ await fs.symlink(+ outside,+ path.join(root, 'p'),+ process.platform === 'win32' ? 'junction' : 'dir',+ );+ expect(await slot.handle('p', req)).toMatchObject({ ok: false });} finally {+ await fs.unlink(alias);await fs.rm(root, { recursive: true, force: true });+ await fs.rm(outside, { recursive: true, force: true });}});diff --git a/apps/desktop/src/main/cindy-brain/downloadSlot.ts b/apps/desktop/src/main/cindy-brain/downloadSlot.tsindex f119857cef..97c2856e6d 100644--- a/apps/desktop/src/main/cindy-brain/downloadSlot.ts+++ b/apps/desktop/src/main/cindy-brain/downloadSlot.ts@@ -31,7 +31,12 @@ export class PluginDownloadSlot {});for (const [, item] of work) item.controller.abort();await Promise.allSettled(work.map(([, item]) => item.promise));- await this.cache.removePlugin(root);+ try {+ const parent = await fs.realpath(path.dirname(root));+ await this.cache.removePlugin(path.join(parent, path.basename(root)));+ } catch (error) {+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;+ }}async withNodeDownloads(id: string,@@ -85,7 +90,11 @@ export class PluginDownloadSlot {params: { ...((payload.params as object) ?? {}), downloads },});} catch {- return { ok: false, message: '下载凭据已失效,请重新获取文件后重试' };+ return {+ ok: false,+ errorCode: 'INVALID_REQUEST',+ message: '下载凭据已失效,请重新获取文件后重试',+ };} finally {for (const release of releases) release();}@@ -163,7 +172,14 @@ export class PluginDownloadSlot {};const promise = (async () => {// Distinct operations cannot share the first caller's signal or progress callback.- const root = this.deps.root(id),+ const suppliedRoot = this.deps.root(id);+ // Host-selected ancestors may use aliases (e.g. /var on macOS). Resolve+ // only that trusted parent; plugin/artifact entries still reject symlinks.+ await fs.mkdir(path.dirname(suppliedRoot), { recursive: true });+ const root = path.join(+ await fs.realpath(path.dirname(suppliedRoot)),+ path.basename(suppliedRoot),+ ),dir = path.join(root,createHash('sha256')