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 — 批准被拒后丢弃过期详情,审阅有效性覆盖 manifest 基线
Chrisc29d06a32a23
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.tsindex 29e9a55688..eaca1cdcb6 100644--- a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts+++ b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts@@ -405,8 +405,11 @@ describe('updateAllController', () => {await approveUpdateExpansion('plugin-a');const row = getUpdateAllBatchState().rows?.[0];// 「事实已变,请重新审阅」而不是「更新失败」——终态失败会让用户失去入口。+ // 手里的 detail 已被 Main 否决,不能拿它出确认内容:丢弃旧差异 + 标记过期,+ // 下次批准重新取详情。expect(row?.status).toBe('needs-confirm');- expect(row?.permissionDiff?.added.length).toBeGreaterThan(0);+ expect(row?.staleReview).toBe(true);+ expect(row?.permissionDiff).toBeUndefined();expect(row?.errorText).toBeUndefined();});@@ -647,6 +650,60 @@ describe('updateAllController', () => {expect(row?.errorText).toBeUndefined();});+ it('drops the stale detail when a same-release manifest swap rejects the approval', async () => {+ const reviewedManifest = manifest({ network: { hosts: ['api.example.com'] } });+ stubDetail({ manifest: reviewedManifest, sourceType: 'git-market' });+ startUpdateAllBatch([marketItem({ sourceType: 'git-market' })]);+ await waitForSettledBatch();+ expect(getUpdateAllBatchState().rows?.[0]).toMatchObject({+ status: 'needs-confirm',+ expectedManifest: reviewedManifest,+ });++ // 竞态:detail() 返回的仍是审阅时那份(所以 renderer 侧判定审阅有效),+ // 但在 install 到达 Main 之前,自定义源在**同一 releaseId 下**换了 manifest,+ // Main 因 expectedManifest 对不上拒绝。此刻手里这份 detail 已经不对了。+ const swappedManifest = manifest({+ network: { hosts: ['api.example.com', 'evil.example.com'] },+ });+ installMock.mockRejectedValueOnce(+ Object.assign(new Error('precondition'), {+ message: 'Error invoking remote method: Error: [PRECONDITION_FAILED] manifest changed',+ }),+ );++ await approveUpdateExpansion('plugin-a');++ const held = getUpdateAllBatchState().rows?.[0];+ // 旧差异与旧 manifest 必须丢弃并标记过期,否则下次批准会再提交同一份+ // 过期的 expectedManifest,循环失败。+ expect(held).toMatchObject({ status: 'needs-confirm', staleReview: true });+ expect(held?.permissionDiff).toBeUndefined();+ expect(held?.expectedManifest).toBeUndefined();++ // 再次批准:此时详情已能取到源上的新 manifest → 相对当前已装仍是扩权 →+ // 用**新** manifest 重新出确认内容。+ detailMock.mockResolvedValue({+ ...marketItem({ sourceType: 'git-market' }),+ manifest: swappedManifest,+ readme: null,+ } as unknown as PluginMarketDetail);+ await approveUpdateExpansion('plugin-a');+ const rereviewed = getUpdateAllBatchState().rows?.[0];+ expect(rereviewed).toMatchObject({ status: 'needs-confirm', staleReview: false });+ expect(rereviewed?.expectedManifest).toBe(swappedManifest);++ // 用户同意新差异 → 带新 manifest 装上,推进到完成,不再循环。+ await approveUpdateExpansion('plugin-a');+ expect(installMock).toHaveBeenLastCalledWith('plugin-a', {+ expectedReleaseId: 'release-2',+ expectedManifest: swappedManifest,+ allowPermissionExpansion: true,+ reviewedBaseline: expect.any(String),+ });+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');+ });+it('does not make a new generation approval wait behind the previous one', async () => {const expanding = manifest({ network: { hosts: ['api.example.com'] } });detailMock.mockImplementation(async (pluginId) =>diff --git a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.tsindex 56349ba275..a6804b329f 100644--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts@@ -442,10 +442,15 @@ async function runApprovalBody(pluginId: string, generation: number): Promise<vo// - 权限指纹变化(以刚重读的 installed 为准):ghosts.update() 允许**同版本// 整体替换 manifest**,同版本换入更宽的声明时版本比较完全看不出来;// - 目标 release 变化:市场在等待期间发了新版,审的不是这一版。+ // - 目标 manifest 变化:自定义市场源可以在**同一 releaseId 下**改 manifest,+ // 只比 releaseId 看不出来;审阅时留存的 expectedManifest 与当前详情不一致+ // 就说明审的不是这一份包(server 源无此字段,由 releaseId 兜住)。const reviewStillValid =row.staleReview !== true &&ghostPermissionBaselineKey(installed) === row.reviewedBaseline &&- detail.releaseId === row.releaseId;+ detail.releaseId === row.releaseId &&+ (row.expectedManifest === undefined ||+ JSON.stringify(row.expectedManifest) === JSON.stringify(detail.manifest));/*** 安装并接住「前置条件失败」。Main 的 PRECONDITION_FAILED 覆盖一组* **并发事实变化**:安装锁内的基线复核否决、release 变了、自定义市场源@@ -463,7 +468,17 @@ async function runApprovalBody(pluginId: string, generation: number): Promise<vo} catch (error) {if (batchGeneration !== generation) return false;if (extractIpcError(error)?.code === 'PRECONDITION_FAILED') {- holdForReReview();+ // 注意**不能**用 holdForReReview():那会拿手里这份 detail 重算差异并+ // 把 staleReview 置 false。可安装被拒恰恰说明这份 detail 已经不对了+ // (典型是自定义源在同 releaseId 下换了 manifest),照它生成确认内容,+ // 下次批准还会提交同一份过期的 expectedManifest,陷入循环失败。+ // 丢掉旧差异、标记过期,等下次批准重新取详情。+ holdRowForReReview(generation, pluginId, {+ releaseId: detail.releaseId,+ toVersion: detail.version,+ fromVersion: installed.version,+ expectedManifest: undefined,+ });return false;}throw error;