feat: v0.8.2 安全纵深补全 · 协议保真 · 断链修复 — 图片SSRF/根MEMORY.md保护根治 · Anthropic thinking回传+pause_turn续传 · 2523 用例全量回归 + E2E 扩充
This commit is contained in:
+39
-55
@@ -1,77 +1,36 @@
|
||||
/**
|
||||
* MetonaAI Desktop — E2E 冒烟测试(v0.8.1 P2-5)
|
||||
* MetonaAI Desktop — E2E 冒烟测试(v0.8.1 P2-5 引入,v0.8.2 P3-3 扩充)
|
||||
*
|
||||
* 端到端链路(Playwright + Electron):
|
||||
* 启动应用(隔离 userData)→ 跳过引导(种子配置)→ 新建会话 → 输入消息 →
|
||||
* 发送 → 引擎调用本地 mock LLM(SSE 流式)→ 断言回复渲染 + mock 收到合法
|
||||
* 请求体(携带「最大输出上限」设置值)→ 中断按钮恢复 idle。
|
||||
* 请求体(携带「最大输出上限」设置值)+ 多轮工具调用闭环。
|
||||
*
|
||||
* 中断链路见 interrupt.spec.ts(独立应用实例,杜绝跨用例运行态竞态)。
|
||||
*
|
||||
* 契约:不触外网(LLM 指向 127.0.0.1 随机端口 mock)、不污染真实用户数据
|
||||
* (METONA_USER_DATA_DIR 重定向)、断言的配置值即设置面板合法配置项。
|
||||
*/
|
||||
|
||||
import { expect, test, type ElectronApplication, type Page } from '@playwright/test';
|
||||
import { _electron as electron } from 'playwright';
|
||||
import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
import { startMockLLM, MOCK_REPLY, type MockLLMHandle } from './mock-llm';
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { launchApp, type AppHarness } from './app-harness';
|
||||
import { MOCK_REPLY, TOOL_REPLY } from './mock-llm';
|
||||
|
||||
let electronApp: ElectronApplication;
|
||||
let page: Page;
|
||||
let mock: MockLLMHandle;
|
||||
let userDataDir: string;
|
||||
let workspaceDir: string;
|
||||
let harness: AppHarness;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// 1. 本地 mock Provider(随机端口,仅监听 127.0.0.1)
|
||||
mock = await startMockLLM();
|
||||
|
||||
// 2. 隔离的用户数据与工作空间目录
|
||||
userDataDir = mkdtempSync(join(tmpdir(), 'metona-e2e-user-'));
|
||||
workspaceDir = join(userDataDir, 'workspace');
|
||||
mkdirSync(workspaceDir, { recursive: true });
|
||||
// workspace-config.json 指向隔离工作空间(main.ts 启动时优先读取)
|
||||
writeFileSync(
|
||||
join(userDataDir, 'workspace-config.json'),
|
||||
JSON.stringify({ workspacePath: workspaceDir }),
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
// 3. 启动 Electron(产物构建由 npm run test:e2e 的 build 步骤保证)
|
||||
electronApp = await electron.launch({
|
||||
args: ['.'],
|
||||
env: {
|
||||
...process.env,
|
||||
METONA_USER_DATA_DIR: userDataDir,
|
||||
METONA_E2E_SEED_CONFIG: '1',
|
||||
METONA_E2E_LLM_URL: mock.url,
|
||||
// 隔离冒烟环境无更新源(生产环境 updater 由 feedUrl 空值禁用,双保险)
|
||||
METONA_E2E_DISABLE_UPDATE: '1',
|
||||
} as Record<string, string>,
|
||||
});
|
||||
page = await electronApp.firstWindow();
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
harness = await launchApp();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await electronApp?.close();
|
||||
await mock?.close();
|
||||
// 调试期保留 userData(main.log 排查用);稳定后恢复清理
|
||||
if (!process.env['METONA_E2E_KEEP_USER_DATA']) {
|
||||
try {
|
||||
rmSync(userDataDir, { recursive: true, force: true });
|
||||
} catch {
|
||||
/* Windows 文件句柄释放延迟 — 清理失败不影响断言 */
|
||||
}
|
||||
}
|
||||
await harness?.cleanup();
|
||||
});
|
||||
|
||||
test('冒烟:发送消息 → mock LLM 流式回复渲染到会话', async () => {
|
||||
// 等待聊天输入框可用(配置加载 + 工具就绪后启用)
|
||||
// InputBase 把 data-chat-input 挂在根 div —— 实际可编辑元素是内部 textarea
|
||||
//(MUI 另渲染一个 readonly 隐藏 textarea 用于测量,需用 .first() 取可交互的)
|
||||
const input = page.locator('[data-chat-input] textarea').first();
|
||||
const input = harness.page.locator('[data-chat-input] textarea').first();
|
||||
await expect(input).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
// 发送一条用户消息
|
||||
@@ -80,18 +39,43 @@ test('冒烟:发送消息 → mock LLM 流式回复渲染到会话', async ()
|
||||
await input.press('Enter');
|
||||
|
||||
// mock LLM 的流式回复出现在聊天区(引擎 → SSE → 渲染层全链路)
|
||||
await expect(page.getByText(MOCK_REPLY).first()).toBeVisible({ timeout: 30_000 });
|
||||
await expect(harness.page.getByText(MOCK_REPLY).first()).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
// 用户消息持久化回显
|
||||
await expect(page.getByText('你好,请做一个冒烟回复').first()).toBeVisible();
|
||||
await expect(harness.page.getByText('你好,请做一个冒烟回复').first()).toBeVisible();
|
||||
});
|
||||
|
||||
test('冒烟:引擎请求体携带设置面板「最大输出上限」配置(2048)', async () => {
|
||||
// beforeAll 后发送的第一条消息已在 mock.requests 中(顺序执行时上一测试已完成)
|
||||
const chatRequests = mock.requests.filter((r) => 'messages' in r);
|
||||
const chatRequests = harness.mock.requests.filter((r) => 'messages' in r);
|
||||
expect(chatRequests.length).toBeGreaterThanOrEqual(1);
|
||||
// llm.maxTokens 原样透传(无任何按模型钳制)
|
||||
expect(chatRequests[0].max_tokens).toBe(2048);
|
||||
// 请求发往本地 mock(经 adapter 组装),模型名来自种子配置
|
||||
expect(chatRequests[0].model).toBe('deepseek-v4-flash');
|
||||
});
|
||||
|
||||
test('冒烟:多轮工具调用 → 工具结果回传 → 最终回答渲染', async () => {
|
||||
const input = harness.page.locator('[data-chat-input] textarea').first();
|
||||
await expect(input).toBeVisible({ timeout: 30_000 });
|
||||
await input.click();
|
||||
await input.fill('请执行 __E2E_TOOL_CALL__ 脚本');
|
||||
await input.press('Enter');
|
||||
|
||||
// 第二轮:mock 收到带 tool 消息的请求后返回最终回答(ReAct 闭环全链路)
|
||||
await expect(harness.page.getByText(TOOL_REPLY).first()).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
// 工具调用卡片(think)存在于聊天流(卡片容器可能滚动出视口,用 attached 断言)
|
||||
await expect(harness.page.getByText('think').first()).toBeAttached();
|
||||
|
||||
// mock 至少收到两条 chat 请求:首轮 tool_calls + 次轮带 tool 结果
|
||||
const chatRequests = harness.mock.requests.filter(
|
||||
(r) => 'messages' in r && (r as { messages?: unknown[] }).messages?.length,
|
||||
);
|
||||
const toolCallReq = chatRequests.find((r) => JSON.stringify(r).includes('__E2E_TOOL_CALL__'));
|
||||
const toolResultReq = chatRequests.find((r) =>
|
||||
(r as { messages?: Array<{ role?: string }> }).messages?.some((m) => m.role === 'tool'),
|
||||
);
|
||||
expect(toolCallReq).toBeDefined();
|
||||
expect(toolResultReq).toBeDefined();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user