fix(channel): support channel names that include numbers; legacy test names containing numbers may still appear (#796)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
Haze
2026-04-08 18:38:59 +08:00
committed by GitHub
Unverified
parent 19b3ea974b
commit c1e165d48d
6 changed files with 219 additions and 29 deletions

View File

@@ -274,6 +274,85 @@ describe('handleChannelRoutes', () => {
);
});
it('filters runtime-only stale accounts when not configured locally', async () => {
listConfiguredChannelsMock.mockResolvedValue(['feishu']);
listConfiguredChannelAccountsMock.mockResolvedValue({
feishu: {
defaultAccountId: 'default',
accountIds: ['default'],
},
});
readOpenClawConfigMock.mockResolvedValue({
channels: {
feishu: {
defaultAccount: 'default',
},
},
});
const rpc = vi.fn().mockResolvedValue({
channels: {
feishu: {
configured: true,
},
},
channelAccounts: {
feishu: [
{
accountId: 'default',
configured: true,
connected: true,
running: true,
},
{
accountId: '2',
configured: false,
connected: false,
running: false,
lastError: 'stale runtime session',
},
],
},
channelDefaultAccountId: {
feishu: 'default',
},
});
const { handleChannelRoutes } = await import('@electron/api/routes/channels');
await handleChannelRoutes(
{ method: 'GET' } as IncomingMessage,
{} as ServerResponse,
new URL('http://127.0.0.1:13210/api/channels/accounts'),
{
gatewayManager: {
rpc,
getStatus: () => ({ state: 'running' }),
debouncedReload: vi.fn(),
debouncedRestart: vi.fn(),
},
} as never,
);
expect(sendJsonMock).toHaveBeenCalledWith(
expect.anything(),
200,
expect.objectContaining({
success: true,
channels: [
expect.objectContaining({
channelType: 'feishu',
accounts: [expect.objectContaining({ accountId: 'default' })],
}),
],
}),
);
const payload = sendJsonMock.mock.calls.at(-1)?.[2] as {
channels?: Array<{ channelType: string; accounts: Array<{ accountId: string }> }>;
};
const feishu = payload.channels?.find((entry) => entry.channelType === 'feishu');
expect(feishu?.accounts.map((entry) => entry.accountId)).toEqual(['default']);
});
it('lists known QQ Bot targets for a configured account', async () => {
const knownUsersPath = join(testOpenClawConfigDir, 'qqbot', 'data');
mkdirSync(knownUsersPath, { recursive: true });