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: address review — 缺失 manifest 不算审阅有效 + 批准补 owner 校验

Chris5a438bfaeff7
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts
index eaca1cdcb6..8098208dd4 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts
@@ -704,6 +704,68 @@ describe('updateAllController', () => {
expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');
});
+ it('never treats a missing expectedManifest as a valid review for custom sources', async () => {
+ const reviewed = manifest({ network: { hosts: ['api.example.com'] } });
+ stubDetail({ manifest: reviewed, sourceType: 'git-market' });
+ startUpdateAllBatch([marketItem({ sourceType: 'git-market' })]);
+ await waitForSettledBatch();
+
+ // 第一次批准被 Main 拒 → 行被清成 expectedManifest: undefined + staleReview。
+ installMock.mockRejectedValueOnce(
+ Object.assign(new Error('precondition'), {
+ message: 'Error invoking remote method: Error: [PRECONDITION_FAILED] manifest changed',
+ }),
+ );
+ await approveUpdateExpansion('plugin-a');
+ expect(getUpdateAllBatchState().rows?.[0]?.expectedManifest).toBeUndefined();
+
+ // 重新审阅 → 再批准,全程必须带上当前 expectedManifest。缺失被短路成
+ // 「审阅仍有效」的话,这里会不带该字段安装,主进程直接 INVALID_PARAMS。
+ await approveUpdateExpansion('plugin-a');
+ await approveUpdateExpansion('plugin-a');
+
+ expect(installMock).toHaveBeenLastCalledWith(
+ 'plugin-a',
+ expect.objectContaining({ expectedManifest: reviewed }),
+ );
+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');
+ });
+
+ it('voids an approval whose detail returned after the account switched', async () => {
+ stubDetail({
+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),
+ sourceType: 'server',
+ });
+ startUpdateAllBatch([marketItem({})]);
+ await waitForSettledBatch();
+
+ // 详情请求停在半空,期间切到账号 B(页面的作废 effect 还没跑,代际未变)。
+ let releaseDetail: (() => void) | undefined;
+ detailMock.mockImplementation(
+ () =>
+ new Promise((resolve) => {
+ releaseDetail = () => {
+ setDataOwnerGeneration('owner-b');
+ resolve({
+ ...marketItem({}),
+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),
+ readme: null,
+ } as unknown as PluginMarketDetail);
+ };
+ }),
+ );
+ const approval = approveUpdateExpansion('plugin-a');
+ await vi.waitFor(() => expect(releaseDetail).toBeDefined());
+
+ // 账号 B 装着同 id 的插件:旧批准绝不能读它的 manifest、更不能装它。
+ installedGhosts = [{ manifest: manifest({ version: '2.0.0' }) }];
+ releaseDetail?.();
+ await approval;
+
+ expect(installMock).not.toHaveBeenCalled();
+ expect(getUpdateAllBatchState().rows).toBeNull();
+ });
+
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.ts
index a6804b329f..c12e4e01f6 100644
--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts
+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts
@@ -409,7 +409,14 @@ async function runApprovalBody(pluginId: string, generation: number): Promise<vo
// 3. 当前 manifest —— 与已装 manifest 重算权限差异。
const detail = await window.electronAPI.pluginMarket.detail(pluginId);
// detail 往返期间批次可能已被作废/接管:此后一律不再写状态、不再安装。
+ // 与 runQueue 同一套**双重**校验:代际管「同账号内换批次」,owner 管
+ // 「账号刚切走但页面的作废 effect 还没跑」那个窗口——只看代际的话,
+ // 这段时间里旧批准会读到新账号的已装 manifest 并安装新账号的同 id 插件。
if (batchGeneration !== generation) return;
+ if (!batchOwnerCurrent()) {
+ voidStaleBatch();
+ return;
+ }
// **detail 之后重读已装 manifest**:这段往返里「从文件更新」等路径可能整体
// 换掉它,拿 await 之前的快照判断 = 拿过期事实做安全决策。
const installed = installedManifestOf(row.ghostId);
@@ -443,14 +450,22 @@ async function runApprovalBody(pluginId: string, generation: number): Promise<vo
// 整体替换 manifest**,同版本换入更宽的声明时版本比较完全看不出来;
// - 目标 release 变化:市场在等待期间发了新版,审的不是这一版。
// - 目标 manifest 变化:自定义市场源可以在**同一 releaseId 下**改 manifest,
- // 只比 releaseId 看不出来;审阅时留存的 expectedManifest 与当前详情不一致
- // 就说明审的不是这一份包(server 源无此字段,由 releaseId 兜住)。
+ // 只比 releaseId 看不出来。
+ // 非 server 源**必须**留有 expectedManifest 且与当前详情逐份一致才算有效:
+ // 缺失不能短路成「有效」——那样下一次批准会不带 expectedManifest 去装,
+ // 主进程对这类来源直接 INVALID_PARAMS,行落成 failed(前一轮把被拒的行
+ // 清成 expectedManifest: undefined,正好会踩中)。server 源无此字段,
+ // 由 releaseId 兜住。
+ const manifestStillMatches =
+ detail.sourceType === 'server'
+ ? true
+ : row.expectedManifest !== undefined &&
+ JSON.stringify(row.expectedManifest) === JSON.stringify(detail.manifest);
const reviewStillValid =
row.staleReview !== true &&
ghostPermissionBaselineKey(installed) === row.reviewedBaseline &&
detail.releaseId === row.releaseId &&
- (row.expectedManifest === undefined ||
- JSON.stringify(row.expectedManifest) === JSON.stringify(detail.manifest));
+ manifestStillMatches;
/**
* 安装并接住「前置条件失败」。Main 的 PRECONDITION_FAILED 覆盖一组
* **并发事实变化**:安装锁内的基线复核否决、release 变了、自定义市场源