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(wechat): clear teammate assignment during deletion

Chrisec4ef3d18acf
diff --git a/apps/desktop/src/main/im/shared/__tests__/botImConnectionRuntime.test.ts b/apps/desktop/src/main/im/shared/__tests__/botImConnectionRuntime.test.ts
index b444c1b88b..1e1089f60d 100644
--- a/apps/desktop/src/main/im/shared/__tests__/botImConnectionRuntime.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/botImConnectionRuntime.test.ts
@@ -91,6 +91,7 @@ import {
__testing,
} from '../botImConnectionRuntime';
import { listBotImConnections, secretKeyPrefixFor } from '../botImConnectionStore';
+import { readWechatChannelSettings, writeWechatCompanionBinding, writeWechatWorkingDir } from '../../wechat/channelSettings';
import {
adoptPersonalBot,
configureBotImPersonalAdoption,
@@ -438,6 +439,25 @@ describe('bot im connection runtime', () => {
expect(removed.connections).toEqual([]);
});
+ // Regression #6492: a WeChat-only teammate has no connection-store records.
+ // unit tier: real deletion cleanup and settings store; keep shared auth and unrelated owners.
+ it('clears only the deleted teammate’s WeChat assignment and broadcasts without removing authorization', async () => {
+ writeWechatWorkingDir(h.root);
+ writeWechatCompanionBinding('bot-mia');
+ h.secrets.set('wechat_credentials_test', 'retained-test-credential');
+ h.secrets.set('wechat_data_key_v1', 'retained-test-key');
+ const before = readWechatChannelSettings();
+ const secrets = new Map(h.secrets);
+ await removeBotImConnectionsForBot('bot-other');
+ expect(readWechatChannelSettings()).toEqual(before);
+ expect(h.sent).toEqual([]);
+
+ await removeBotImConnectionsForBot('bot-mia');
+ expect(readWechatChannelSettings()).toEqual({ version: 1, workingDir: before.workingDir, workingDirAvailable: true });
+ expect(h.secrets).toEqual(secrets);
+ expect(h.sent).toEqual([{ channel: 'wechatBot:channel-settings-changed', payload: readWechatChannelSettings() }]);
+ });
+
it('starts recorded connections on login, keeps records across stop, and drops them with the teammate', async () => {
const a = await addBotImConnection({ botId: 'bot-mia', channel: 'telegram', token: '1:ABCDEFGHIJKLMNOPQRSTUVWXYZ', ownerUserId: '4242' });
await stopBotImConnections();
diff --git a/apps/desktop/src/main/im/shared/botImConnectionRuntime.ts b/apps/desktop/src/main/im/shared/botImConnectionRuntime.ts
index 459f274900..41c93cad48 100644
--- a/apps/desktop/src/main/im/shared/botImConnectionRuntime.ts
+++ b/apps/desktop/src/main/im/shared/botImConnectionRuntime.ts
@@ -26,6 +26,7 @@ import { botProfiles } from '../../localDb/schema';
import { assertTrustedAppRendererEvent } from '../../security/trustedAppRenderer';
import { throwIpcError } from '../../utils/ipcValidate';
import { ownerScopedImSecrets } from '../ownerScopedStorage';
+import { readWechatChannelSettings, writeWechatCompanionBinding } from '../wechat/channelSettings';
import {
BOT_IM_CONNECTION_CHANGED_EVENT,
type BotImChannel,
@@ -627,6 +628,14 @@ export async function removeBotImConnection(id: string): Promise<BotImConnection
/** 伙伴被删除 / 归档时带走它的全部连接。 */
export async function removeBotImConnectionsForBot(botId: string): Promise<void> {
+ // WeChat shares the personal transport: remove only the teammate assignment,
+ // even when there are no dedicated connections. Keep its authorization intact.
+ if (readWechatChannelSettings().companionBotId === botId) {
+ const settings = writeWechatCompanionBinding(null);
+ for (const window of BrowserWindow.getAllWindows()) {
+ if (!window.isDestroyed()) window.webContents.send('wechatBot:channel-settings-changed', settings);
+ }
+ }
for (const record of listBotImConnectionsForBot(botId)) {
try {
await removeBotImConnection(record.id);