import { join, resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; import { closeElectronApp, expect, getStableWindow, installIpcMocks, test, } from './fixtures/electron'; const repoRoot = resolve(process.cwd()); const rendererEntry = pathToFileURL(join(repoRoot, 'dist/index.html')).toString(); function hostJson(json: unknown) { return { ok: true, data: { status: 200, ok: true, json, }, }; } function hostKey(path: string, method = 'GET') { return JSON.stringify([path, method]); } test.describe('Zhinian delivery smoke', () => { test('covers setup, login, chat, quick tasks, history, workspace pages, and NianxxPlay shell', async ({ launchElectronApp }) => { const app = await launchElectronApp(); await installIpcMocks(app, { gatewayStatus: { state: 'running', port: 18789, pid: 12345, }, hostApi: { [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: [] }), }, }); try { const page = await getStableWindow(app); await page.setViewportSize({ width: 1280, height: 800 }); await expect(page.getByTestId('setup-page')).toBeVisible(); await page.getByTestId('setup-skip-button').click(); await expect(page.getByTestId('yinian-login-page')).toBeVisible(); await page.evaluate(() => { 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, })); }); await page.goto(`${rendererEntry}#/login`); 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('today-page')).toBeVisible(); await page.getByTestId('sidebar-new-chat').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 page.goto(`${rendererEntry}#/knowledge`); await expect(page.getByTestId('knowledge-page')).toBeVisible(); await page.goto(`${rendererEntry}#/cron`); await expect(page.getByTestId('cron-page')).toBeVisible(); await page.goto(`${rendererEntry}#/settings/skills`); await expect(page.getByTestId('settings-page')).toBeVisible(); await expect(page.getByTestId('yinian-skills-page')).toBeVisible(); await expect(page.getByTestId('yinian-skills-tab-quickTasks')).toBeVisible(); await page.getByTestId('sidebar-nav-app-center').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); } }); });