feat(agents): 支持个人微信发布与渠道会话
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
2026-09-13 16:22:36 +08:00
parent 03774d0625
commit 2e710db0fb
28 changed files with 2678 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, expect, it, vi } from 'vitest';
import { CloudChannelEnableConfirmation } from '@/pages/CloudAgents/CloudChannelEnableConfirmation';
const api = vi.hoisted(() => ({ call: vi.fn() }));
vi.mock('@/lib/cloud-agents-api', () => ({ cloudAgentsApi: api }));
afterEach(() => { cleanup(); vi.resetAllMocks(); });
const binding = { id: 'wechat', address: 'wechat:creator', display_name: '创作微信', target_agent_address: 'yuxi:makelore:agent',
route_revision: 1, provider_generation: 'generation', binding_id: 'binding', enabled: false, status: 'bound', worker_online: true, access_mode: 'self_only' };
it('shows actual budget values and published audience before enabling, including a zero limit', async () => {
api.call.mockResolvedValue({ request_limit_points: '0.00', daily_limit_points: null });
const enable = vi.fn();
render(<CloudChannelEnableConfirmation slug="agent" binding={binding} publishedVersion={2} busy={false} onEnable={enable} onCancel={() => undefined} />);
expect(screen.getByRole('button', { name: '确认启用', exact: true })).toBeDisabled();
await screen.findByText('每次任务上限:0.00 词元点数');
expect(screen.getByText('每日上限:不设额外上限')).toBeVisible();
expect(screen.getByRole('dialog')).toHaveTextContent('当前发布版本 v2,允许仅本人');
fireEvent.click(screen.getByRole('button', { name: '确认启用', exact: true }));
expect(enable).toHaveBeenCalledOnce();
});
it('keeps enable unavailable until a failed budget read can be retried', async () => {
api.call.mockRejectedValueOnce(new Error('费用服务暂不可用')).mockResolvedValueOnce({ request_limit_points: '2.00', daily_limit_points: '10.00' });
render(<CloudChannelEnableConfirmation slug="agent" binding={binding} publishedVersion={2} busy={false} onEnable={() => undefined} onCancel={() => undefined} />);
await screen.findByRole('alert');
expect(screen.getByRole('button', { name: '确认启用', exact: true })).toBeDisabled();
fireEvent.click(screen.getByRole('button', { name: '重新读取上限' }));
await screen.findByText('每日上限:10.00 词元点数');
expect(screen.getByRole('button', { name: '确认启用', exact: true })).toBeEnabled();
});