Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(wechat): cancel pending authorization when deleting companion
Chrisbc2c455ad4da
diff --git a/apps/desktop/src/main/im/wechat/WechatIM.ts b/apps/desktop/src/main/im/wechat/WechatIM.tsindex da61b38125..9220ea51eb 100644--- a/apps/desktop/src/main/im/wechat/WechatIM.ts+++ b/apps/desktop/src/main/im/wechat/WechatIM.ts@@ -202,7 +202,8 @@ export class WechatIM extends BaseIM implements RichChannelIM {return this.#queueLifecycle(async () => {const cancelPending = options.cancelPendingIf?.() ?? false;if (options.cancelPendingIf && !cancelPending) return;- if (this.#authorizationAbort || (!cancelPending && (this.#activeTasks.size || this.#pendingInteractions.size))) {+ if (cancelPending) this.cancelAuthorization();+ if (!cancelPending && (this.#authorizationAbort || this.#activeTasks.size || this.#pendingInteractions.size)) {throw new Error('WECHAT_CONNECTION_BUSY');}const epoch = this.#epoch;diff --git a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.tsindex 925c1905c9..cc1a6451d5 100644--- a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts+++ b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts@@ -437,7 +437,10 @@ describe('WechatIM host boundary', () => {expect(im.getState()).toMatchObject({ phase: 'disconnected', bound: false });});- it('drops late authorization credentials after a compatibility revision changes', async () => {+ // #6492 r4318608094, unit: existing policy-cancel coverage missed teammate+ // deletion during QR confirmation. Public lifecycle must cancel, finish cleanup,+ // and ignore a late authorization result without writing shared credentials.+ it.each(['policy', 'companion-deletion'])('drops late authorization credentials after %s cancellation', async (reason) => {const testHost = host();let resolveCredentials!: (credentials: WechatCredentials) => void;const waitAuthorization = vi.fn(@@ -459,7 +462,17 @@ describe('WechatIM host boundary', () => {await im.authorize();await vi.waitFor(() => expect(waitAuthorization).toHaveBeenCalledOnce());- await im.setCompatibilityDisabled(true);+ if (reason === 'policy') await im.setCompatibilityDisabled(true);+ else {+ const update = vi.fn();+ await expect(im.updateCompanionBinding(update)).rejects.toThrow('WECHAT_CONNECTION_BUSY');+ await im.updateCompanionBinding(update, { cancelPendingIf: () => false });+ expect(im.getState().phase).toBe('waiting_confirmation');+ expect(update).not.toHaveBeenCalled();+ await im.updateCompanionBinding(update, { cancelPendingIf: () => true });+ expect(update).toHaveBeenCalledOnce();+ expect(vi.mocked(authorizationTransport.waitAuthorization).mock.calls[0]![1].aborted).toBe(true);+ }resolveCredentials({token: 'late-token',botId: 'late-bot',@@ -470,7 +483,8 @@ describe('WechatIM host boundary', () => {expect(createTransport).toHaveBeenCalledOnce();expect(testHost.secrets.write).not.toHaveBeenCalled();- expect(im.getState()).toMatchObject({ phase: 'disabled_by_policy', bound: false });+ expect(im.getState()).toMatchObject({ phase: reason === 'policy' ? 'disabled_by_policy' : 'disconnected', bound: false });+ await im.dispose();});it('rolls back a newly activated binding when the account generation becomes stale', async () => {