feat(channel): support weichat channel (#620)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user