import { closeElectronApp, expect, getStableWindow, installIpcMocks, test, } from './fixtures/electron'; function hostJson(json: unknown) { return { ok: true, data: { status: 200, ok: true, json, }, }; } function hostKey(path: string, method = 'GET') { return JSON.stringify([path, method]); } function stableStringify(value: unknown): string { if (value == null || typeof value !== 'object') return JSON.stringify(value); if (Array.isArray(value)) return `[${value.map((item) => stableStringify(item)).join(',')}]`; const entries = Object.entries(value as Record) .sort(([left], [right]) => left.localeCompare(right)) .map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`); return `{${entries.join(',')}}`; } test.describe('Zhinian delivery smoke', () => { test('covers setup, login, chat quick capabilities, history, workspace pages, Travel Resource Ordering, and Quick Video Creation shell', async ({ launchElectronApp }) => { const app = await launchElectronApp(); await installIpcMocks(app, { gatewayStatus: { state: 'running', port: 18789, pid: 12345, }, gatewayRpc: { [stableStringify(['sessions.list', {}])]: { success: true, result: { sessions: [{ key: 'agent:main:main', displayName: '桌面对话', updatedAt: Date.now() }], }, }, [stableStringify(['chat.history', { sessionKey: 'agent:main:main', limit: 200 }])]: { success: true, result: { messages: [] }, }, [stableStringify(['chat.history', { sessionKey: 'agent:main:main', limit: 1000 }])]: { success: true, result: { messages: [] }, }, }, hostApi: { [hostKey('/api/gateway/status')]: hostJson({ state: 'running', port: 18789, pid: 12345, }), [hostKey('/api/apps/nianxx-play/status')]: hostJson({ success: true, running: true, starting: false, managed: true, baseUrl: 'http://127.0.0.1:3000', port: 3000, }), [hostKey('/api/apps/nianxx-play/start', 'POST')]: hostJson({ success: true, running: true, starting: false, managed: true, baseUrl: 'http://127.0.0.1:3000', port: 3000, }), [hostKey('/api/channels/accounts')]: hostJson({ success: true, channels: [] }), [hostKey('/api/cron/jobs')]: hostJson({ jobs: [{ id: 'cron-daily', name: '每日经营日报', message: '使用日报生成助手 skill 生成日报', schedule: '0 9 * * *', delivery: { mode: 'none' }, enabled: true, createdAt: '2026-05-13T00:00:00.000Z', updatedAt: '2026-05-13T00:00:00.000Z', agentId: 'main', }], }), [hostKey('/api/cron/trigger', 'POST')]: hostJson({ success: true }), }, }); try { const page = await getStableWindow(app); await page.setViewportSize({ width: 1280, height: 800 }); await page.addInitScript(() => { window.localStorage.setItem('yinian:quick-tasks', JSON.stringify({ state: { tasks: [ { id: 'qt-docx', name: 'word', description: '调用文档能力生成内容', skills: [{ id: 'docx', name: 'docx' }], enabled: true, showInComposer: true, updatedAt: Date.now(), }, { id: 'qt-design', name: '设计', description: '调用设计能力优化表达', skills: [{ id: 'design', name: 'design' }], enabled: true, showInComposer: true, updatedAt: Date.now(), }, ], }, version: 3, })); window.localStorage.setItem('yinian:pinned-task-ids', JSON.stringify(['cron-daily'])); }); await page.reload(); await expect(page.getByTestId('setup-page')).toBeVisible(); await page.getByTestId('setup-skip-button').click(); await expect(page.getByTestId('yinian-login-page')).toBeVisible(); await expect(page.getByTestId('yinian-login-page')).toBeVisible(); await page.locator('#account').fill('admin'); await page.locator('#password').fill('123456'); const captchaInput = page.locator('#captcha-code'); if (await captchaInput.count()) { await captchaInput.fill('5678'); } await page.locator('form button[type="submit"]').click(); await expect(page.getByTestId('chat-composer-input')).toBeVisible(); await expect(page.getByTestId('chat-quick-task-qt-docx')).toBeVisible(); await expect(page.getByTestId('chat-quick-task-qt-docx')).toBeEnabled({ timeout: 60_000 }); await page.getByTestId('chat-quick-task-qt-docx').click(); await expect(page.getByText('使用docx skill')).toBeVisible(); await page.getByTestId('chat-quick-task-qt-design').click(); await expect(page.getByText('使用design skill')).toBeVisible(); await expect(page.getByText('使用docx skill')).toHaveCount(0); await page.getByTestId('sidebar-chat-history').click(); await expect(page.getByTestId('sidebar-chat-history-panel')).toBeVisible(); await expect(page.getByTestId('sidebar-pinned-task-cron-daily')).toBeVisible(); await page.getByTestId('sidebar-pinned-task-cron-daily').click(); await page.getByTestId('sidebar-nav-knowledge').click(); await expect(page.getByTestId('knowledge-page')).toBeVisible(); await page.getByTestId('sidebar-nav-tasks').click(); await expect(page.getByTestId('tasks-page')).toBeVisible(); await expect(page.getByTestId('tasks-tab-scheduled')).toBeVisible(); await expect(page.getByTestId('tasks-tab-quick')).toHaveCount(0); await page.evaluate(() => { window.location.hash = '#/cron'; }); await expect(page.getByTestId('tasks-page')).toBeVisible(); await expect(page.getByTestId('tasks-tab-scheduled')).toBeVisible(); await page.evaluate(() => { window.location.hash = '#/settings/skills'; }); await expect(page.getByTestId('settings-page')).toBeVisible(); await expect(page.getByTestId('yinian-skills-page')).toBeVisible(); await expect(page.getByTestId('yinian-skills-tab-server')).toBeVisible(); await expect(page.getByTestId('yinian-skills-tab-local')).toBeVisible(); await page.getByTestId('sidebar-nav-app-center').click(); await expect(page.getByTestId('app-center-page')).toBeVisible(); await expect(page.getByTestId('app-center-item-product-center')).toBeVisible(); await page.getByTestId('app-center-item-product-center').click(); await expect(page.getByTestId('product-center-page')).toBeVisible(); await expect(page.getByTestId('product-center-frame')).toHaveAttribute('src', /https:\/\/ticket\.nianxx\.cn\/.*zhinianEmbed=1/); await expect(page.getByTestId('product-center-frame')).toHaveAttribute('partition', 'persist:yinian-travel-resource-ordering'); await page.getByTestId('product-center-back').click(); await expect(page.getByTestId('app-center-page')).toBeVisible(); await expect(page.getByTestId('app-center-item-nianxx-play')).toBeVisible(); await page.getByTestId('app-center-item-nianxx-play').click(); await expect(page.getByTestId('nianxx-play-page')).toBeVisible(); await page.getByTestId('nianxx-play-nav-planning').click(); await expect(page.getByTestId('nianxx-play-page')).toBeVisible(); await page.getByTestId('nianxx-play-back').click(); await expect(page.getByTestId('app-center-page')).toBeVisible(); } finally { await closeElectronApp(app); } }); });