import { expect, test } from '@playwright/test'; import { resolve } from 'node:path'; import { readFile, writeFile } from 'node:fs/promises'; import { startLiveDecisionService } from './fixtures/decisionService'; test.use({ trace: 'off', video: 'off' }); test('显式 opt-in:主工作台 DeepSeek flash + OpenRouter Jev 真实物理回合', async ({ page, }, info) => { test.skip( process.env.LEKIWI_LIVE_API !== '1', '需明确授权 .env 两个角色与一次付费回合;不自动运行', ); const service = await startLiveDecisionService(); try { await page.goto('/'); await page .locator('input[type="file"]') .first() .setInputFiles(resolve('build/lekiwi/lekiwi-v1.zip')); const dialog = page.getByRole('dialog', { name: '配置 URDF 仿真组件' }); await expect(dialog).toBeVisible({ timeout: 30000 }); await dialog.getByLabel('URDF 机器人 profile').selectOption('lekiwi-v1'); await dialog.getByRole('button', { name: '转换并加载' }).click(); await expect(page.getByRole('button', { name: '▶ 播放' })).toBeEnabled({ timeout: 60000 }); await page.getByRole('tab', { name: '控制台', exact: true }).click(); await page.getByRole('button', { name: 'LeKiwi 智能抓放', exact: true }).click(); const panel = page.getByLabel('LeKiwi 智能抓放任务', { exact: true }); await panel.getByText('模型连接与官方订阅登录', { exact: true }).click(); await panel.getByLabel('本机模型服务', { exact: true }).fill(service.endpoint); await panel.getByLabel('本机服务令牌', { exact: true }).fill(service.token); await panel.getByRole('button', { name: '连接本机模型服务', exact: true }).click(); await expect(panel).toContainText('本机桥已连接'); await expect(panel.getByLabel('LLM 型号', { exact: true })).toHaveValue('deepseek-flash'); await expect(panel.getByLabel('JEV 型号', { exact: true })).toHaveValue('typesafe/jev-1.13'); await expect(panel.getByLabel('LLM Base URL', { exact: true })).toHaveValue( 'https://api.deepseek.com', ); await expect(panel.getByLabel('JEV Base URL', { exact: true })).toHaveValue( 'https://openrouter.ai/api/alpha/decisions', ); await panel.getByText('模型连接与官方订阅登录', { exact: true }).click(); await panel.getByLabel('智能任务决策模式').selectOption('api'); await panel.getByRole('button', { name: '开始任务(真实 API)', exact: true }).click(); const status = panel.getByTestId('agent-task-state'); await expect(status).toContainText(/物理验收成功|失败 \/ 安全停止|已取消/, { timeout: 240000 }); const pendingDownload = page.waitForEvent('download'); await panel.getByRole('button', { name: '导出任务证据', exact: true }).click(); const downloaded = await pendingDownload; const data = JSON.parse(await readFile((await downloaded.path())!, 'utf8')); const encoded = JSON.stringify(data, null, 2); if (encoded.includes(service.token)) throw new Error('任务导出包含本机令牌'); await writeFile(info.outputPath('live-physical-evidence.json'), encoded); console.log('真实 API 回合(非订阅)', { state: data.state, error: data.error, llm: data.llmCalls, jev: data.jevCalls, simTime: data.sample.time, transported: data.transported, models: [...new Set(data.receipts.map((r: { model: string }) => r.model))], }); expect(data.mode).toBe('api'); expect(data.state, data.error).toBe('succeeded'); expect(data.succeeded).toBe(true); expect(data.transported).toBeGreaterThanOrEqual(0.5); expect(data.llmCalls).toBe(1); expect(data.jevCalls).toBe(11); expect(data.receipts).toHaveLength(12); await page.screenshot({ path: info.outputPath('live-workbench.png') }); } catch (error) { // Playwright action errors may quote input values. Close before automatic DOM diagnostics. await page.close().catch(() => undefined); // eslint-disable-next-line preserve-caught-error -- The original cause may contain the private bridge token. throw new Error(String(error).replaceAll(service.token, '[redacted]')); } finally { await service.stop(); } });