Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: address review — 扩权基线复核移进安装锁内、落位前重算
Chrise34378166424
diff --git a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts b/apps/desktop/src/main/plugin-market/__tests__/service.test.tsindex a3484e13f4..3641e18b07 100644--- a/apps/desktop/src/main/plugin-market/__tests__/service.test.ts+++ b/apps/desktop/src/main/plugin-market/__tests__/service.test.ts@@ -795,6 +795,45 @@ describe('PluginMarketService migration and defaultInstall', () => {expect(runtime.install).toHaveBeenCalledTimes(1);});+ it('re-checks the baseline inside the install lock when the download window is raced', async () => {+ const item = summary({+ currentRelease: { ...summary().currentRelease, id: 'release-2', version: '2.0.0' },+ });+ // 审阅时已装 notify+fs:相对目标包没有新增权限,批准是"空头"批准。+ const reviewedInstalled = manifest('cindy-test', '1.0.0', ['notify', 'fs']);+ runtime.ghosts = [+ { manifest: reviewedInstalled, dir: '/userData/cindy-brain/cindy-test', enabled: true },+ ];+ runtime.install.mockResolvedValue({+ manifest: manifest('cindy-test', '2.0.0', ['notify', 'fs']),+ dir: '/userData/cindy-brain/cindy-test',+ enabled: true,+ });+ // 下载窗口期(锁外复核已通过之后)本地 ghosts:update 把已装换成只有 notify+ // 的包——此刻目标包相对当前已装多出 fs,而这条从没被审阅过。+ const downloadMock = vi.mocked(+ (await import('../download.js')).downloadVerifiedPlugin,+ );+ downloadMock.mockImplementationOnce(async () => {+ runtime.ghosts = [+ { manifest: manifest(), dir: '/userData/cindy-brain/cindy-test', enabled: true },+ ];+ });+ const h = harness([item]);+ h.ledger.upsertInstallation({ ...recordForTest(item), releaseId: 'release-1', version: '1.0.0' });+ h.api.detail.mockResolvedValue(detail(item, ['notify', 'fs']));++ await expect(+ h.service.install(item.id, {+ expectedReleaseId: item.currentRelease.id,+ allowPermissionExpansion: true,+ reviewedBaseline: ghostPermissionBaselineKey(reviewedInstalled),+ }),+ ).rejects.toThrow('[PRECONDITION_FAILED]');+ // 锁内复核发生在落位之前:并发替换绕不过旧批准。+ expect(runtime.install).not.toHaveBeenCalled();+ });+it('rejects an update when the installed target disappears during download', async () => {const item = summary({ currentRelease: { ...summary().currentRelease, version: '2.0.0' } });const h = harness([item]);diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.tsindex 575282a933..c763a1ae63 100644--- a/apps/desktop/src/main/plugin-market/service.ts+++ b/apps/desktop/src/main/plugin-market/service.ts@@ -1111,15 +1111,23 @@ export class PluginMarketService {if (!compatible.ok) {throwIpcError('GHOST_FILE_INVALID', 'This Plugin manifest is not supported');}- if (- existing &&- diffGhostPermissionItems(existing.manifest, compatible.manifest).added.length > 0- ) {+ /**+ * 扩权闸门:按**传入时刻的**已装 manifest 判定。下面调用两次——+ * 1. 锁外一次:快速失败,不为注定被拒的更新白下载几十 MB;+ * 2. 落位前在 withGhostInstallLock 内再一次(权威):下载可能持续数分钟,+ * 期间本地 `ghosts:update` 能整体替换已装 manifest。只在锁外判定的话,+ * 旧的 reviewedBaseline 会放行相对**新** manifest 多出来的权限——+ * 那些权限用户从没审过。锁内这次才是不可绕过的那道。+ */+ const assertExpansionApproved = (installedNow: GhostManifest | null): void => {+ if (!installedNow) return;+ if (diffGhostPermissionItems(installedNow, compatible.manifest).added.length === 0) return;if (options.allowPermissionExpansion !== true) {throwIpcError('PRECONDITION_FAILED', 'Plugin permissions changed and require review');}- assertReviewedBaselineFresh(existing.manifest, options.reviewedBaseline);- }+ assertReviewedBaselineFresh(installedNow, options.reviewedBaseline);+ };+ assertExpansionApproved(existing?.manifest ?? null);const download = await this.api.download(plugin.id, plugin.currentRelease.id);requireSameMarketOwner(owner);if (@@ -1167,6 +1175,14 @@ export class PluginMarketService {// 改动 Ghost 运行时之前的最后一道:跨来源 ghostId 所有权按当前事实重算。await options.recheckOwnership?.();requireSameMarketOwner(owner);+ // 权限扩权的**权威**判定点:锁内按当前已装 manifest 重算。锁外那次+ // 只是快速失败;下载窗口期本地装入/更新若换掉了已装包,旧批准在这里+ // 被基线比对拦下,并发替换绕不过去(落位就在下面几行)。+ assertExpansionApproved(+ getGhostManager()+ .list()+ .find((ghost) => ghost.manifest.id === plugin.ghostId)?.manifest ?? null,+ );// 市场首装一律装完即开(2026-07-26 定案,见 installOrUpdateMarketGhostPackage);// 已装过则走原位更新,唤醒/沉睡状态延续当前值。const installed = await installOrUpdateMarketGhostPackage(tempPath, {