Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(wechat): remove released files when deleting companion
Chris9cb8ff616428
diff --git a/apps/desktop/src/main/im/wechat/WechatIM.ts b/apps/desktop/src/main/im/wechat/WechatIM.tsindex 0b4c69e623..f1c7748fe9 100644--- a/apps/desktop/src/main/im/wechat/WechatIM.ts+++ b/apps/desktop/src/main/im/wechat/WechatIM.ts@@ -219,10 +219,20 @@ export class WechatIM extends BaseIM implements RichChannelIM {if (cancelPending) {if (!options.cancelPendingIf?.()) throw new Error('WECHAT_BINDING_CHANGED');// Deletion must also settle a disabled/offline connection's durable inbox.- if (binding) await db.tx('wechatStopAll', {- bindingEpoch: binding.bindingEpoch, now: this.#now(),- errorCode: 'COMPANION_DELETED', cancelPending: true,- });+ if (binding) {+ await db.tx('wechatStopAll', {+ bindingEpoch: binding.bindingEpoch, now: this.#now(),+ errorCode: 'COMPANION_DELETED', cancelPending: true,+ });+ // Retaining task history must not retain cancelled inbox files.+ // Promoted attachments belong to that history and stay untouched.+ const released = await db.query<{ absPath: string }>(+ `SELECT abs_path AS absPath FROM wechat_file_attachments+ WHERE binding_epoch = ? AND status = 'released'`,+ [binding.bindingEpoch],+ );+ await removeReleasedWechatFiles(released.map(({ absPath }) => absPath));+ }}// A poll already in flight may have persisted a message while we drained it.if (!cancelPending && binding && await countQueuedWechatTasks(db, binding.bindingEpoch)) {diff --git a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.tsindex ece5d4654f..7590217b07 100644--- a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts+++ b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts@@ -620,9 +620,20 @@ describe('WechatIM host boundary', () => {// #6492 unit regression: deletion must include the late poll batch in its// cancellation, preserve authorization, and never restart after settlement failure.+ // r4318071189: one released file must reach the bounded file cleanup before+ // ownership changes; the previous regression only checked database settlement.it.each([false, true])('settles deletion after poll drain (failure=%s)', async (fail) => {const { im, transport, db, testHost } = restoredConnection(() => 1);const order: string[] = [];+ const released = '/isolated/im-attachments/wechat/sessions/companion-owner/queued.pdf';+ vi.mocked(db.query).mockImplementation(async (sql, params) => {+ if (!sql.includes('FROM wechat_file_attachments')) return [];+ expect(order).toContain('cancel');+ expect(sql).toContain("status = 'released'");+ expect(params).toEqual(['epoch']);+ return [{ absPath: released }];+ });+ if (!fail) mediaMocks.removeReleasedWechatFiles.mockImplementationOnce(async () => { order.push('files'); });im.attachTurnRuntime({ runner: { companionBotIdFor: () => 'cindy',resolveRouteTarget: async () => ({ row: { id: 'companion-owner' } }) },repo: {}, config: {}, resetSessionToDefaults: vi.fn() } as never);@@ -648,7 +659,9 @@ describe('WechatIM host boundary', () => {const changing = im.updateCompanionBinding(update, { cancelPendingIf: () => true });if (fail) await expect(changing).rejects.toThrow('DRAIN_FAILED');else await changing;- expect(order).toEqual(fail ? ['batch', 'cancel'] : ['batch', 'cancel', 'update']);+ expect(order).toEqual(fail ? ['batch', 'cancel'] : ['batch', 'cancel', 'files', 'update']);+ if (fail) expect(mediaMocks.removeReleasedWechatFiles).not.toHaveBeenCalled();+ else expect(mediaMocks.removeReleasedWechatFiles).toHaveBeenCalledWith([released]);expect(transport.notifyStart).toHaveBeenCalledTimes(fail ? 1 : 2);expect(testHost.secrets.write).not.toHaveBeenCalled();expect(testHost.secrets.remove).not.toHaveBeenCalled();