feat(channel): support weichat channel (#620)

This commit is contained in:
Haze
2026-03-22 17:08:02 +08:00
committed by GitHub
Unverified
parent f12f4a74df
commit 1e7b40a486
32 changed files with 1610 additions and 156 deletions

View File

@@ -1,4 +1,5 @@
import { readFile, rm } from 'fs/promises';
import { existsSync } from 'fs';
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
import { join } from 'path';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -158,3 +159,38 @@ describe('WeCom plugin configuration', () => {
expect(plugins.entries['wecom'].enabled).toBe(true);
});
});
describe('WeChat dangling plugin cleanup', () => {
beforeEach(async () => {
vi.resetAllMocks();
vi.resetModules();
await rm(testHome, { recursive: true, force: true });
await rm(testUserData, { recursive: true, force: true });
});
it('removes dangling openclaw-weixin plugin registration and state when no channel config exists', async () => {
const { cleanupDanglingWeChatPluginState, writeOpenClawConfig } = await import('@electron/utils/channel-config');
await writeOpenClawConfig({
plugins: {
enabled: true,
allow: ['openclaw-weixin'],
entries: {
'openclaw-weixin': { enabled: true },
},
},
});
const staleStateDir = join(testHome, '.openclaw', 'openclaw-weixin', 'accounts');
await mkdir(staleStateDir, { recursive: true });
await writeFile(join(staleStateDir, 'bot-im-bot.json'), JSON.stringify({ token: 'stale-token' }), 'utf8');
await writeFile(join(testHome, '.openclaw', 'openclaw-weixin', 'accounts.json'), JSON.stringify(['bot-im-bot']), 'utf8');
const result = await cleanupDanglingWeChatPluginState();
expect(result.cleanedDanglingState).toBe(true);
const config = await readOpenClawJson();
expect(config.plugins).toBeUndefined();
expect(existsSync(join(testHome, '.openclaw', 'openclaw-weixin'))).toBe(false);
});
});