Files
Agent-Workbench/scripts/verify-orven-ui.mjs

201 lines
13 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { chromium, expect } from 'playwright/test';
import { fixture, compatibleFixture, completion, call, launchWorkbench } from '../tests/helpers.mjs';
// Real browser + real isolated host + local protocol fixture. No real model or user project.
const palette = process.env.ORVEN_QA_PALETTE ?? 'green';
assert.ok(['green', 'blue', 'purple'].includes(palette));
const output = path.resolve(process.env.ORVEN_QA_OUTPUT ?? ('output/playwright/' + (palette === 'green' ? 'orven' : 'orven-' + palette)));
fs.mkdirSync(output, { recursive: true });
const disposers = [], t = { after: dispose => disposers.push(dispose) };
const f = fixture(t, { modernDefaults: true });
fs.writeFileSync(path.join(f.projectRoot, 'README.md'), '# Orven UI fixture\n\n用于独立界面验证的项目。\n');
let modelCalls = 0;
const model = await compatibleFixture(t, (url, input) => {
assert.equal(url, '/v1/chat/completions');
assert.equal(input.model, 'orven-ui-fixture');
modelCalls++;
if (modelCalls === 1) return completion([call('orven-read', 'read_file', { path: 'README.md' })]);
if (modelCalls === 2) return completion([call('orven-write', 'propose_file', { path: 'ORVEN-NOTES.md', content: '# Orven 验证\n\n已读取项目,完成本机受控接口验证。\n', reason: '只用于本次独立 UI 验证' })]);
return completion([], '已读取 README.md,并写入 ORVEN-NOTES.md。本次使用本机协议夹具,没有调用真实模型。');
});
f.store.close();
const host = await launchWorkbench(t, f.data);
assert.notEqual(new URL(host.url).port, '4318');
const browser = await chromium.launch({ channel: 'msedge', headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 960 }, deviceScaleFactor: 1 });
await page.addInitScript(palette => localStorage.setItem('orven-palette', palette), palette);
page.setDefaultTimeout(12000);
const errors = [], checks = [];
page.on('pageerror', error => errors.push(error.message));
const mark = value => { checks.push(value); console.log('PASS ' + value); };
const shot = async name => page.screenshot({ path: path.join(output, name + '.png'), fullPage: true });
const tool = async name => {
await page.keyboard.press('Escape');
await page.getByRole('button', { name: '打开工具箱', exact: true }).click();
const dialog = page.getByRole('dialog', { name: '工具箱', exact: true });
await dialog.getByLabel('搜索工作台工具').fill(name);
await dialog.getByRole('button', { name, exact: true }).click();
};
const bounds = async () => {
const value = await page.evaluate(() => {
const footer = document.querySelector('.composer-wrap').getBoundingClientRect();
return { width: innerWidth, height: innerHeight, scrollWidth: document.documentElement.scrollWidth, scrollHeight: document.documentElement.scrollHeight, footer: footer.bottom };
});
assert.ok(value.scrollWidth <= value.width + 1 && value.scrollHeight <= value.height + 1, JSON.stringify(value));
assert.ok(value.footer <= value.height + 1, JSON.stringify(value));
};
try {
await page.goto(host.url);
await page.locator('.connection.connected').waitFor();
await expect(page.locator('html')).toHaveAttribute('data-palette', palette);
await expect(page).toHaveTitle('Orven · AI 开发工作台');
await expect(page.getByRole('heading', { name: '今天,想实现什么?' })).toBeVisible();
await expect(page.locator('.inspector')).not.toBeVisible();
await bounds(); await shot('desktop');
mark('Orven identity, actual project context and focused new-task surface');
const before = (await host.api('/bootstrap')).sessions.length;
await page.locator('.starter-prompts button').filter({ hasText: '读懂项目' }).click();
const draft = await page.getByLabel('任务内容').inputValue();
assert.match(draft, /了解这个项目/);
assert.equal((await host.api('/bootstrap')).sessions.length, before);
await page.getByRole('button', { name: '发送任务', exact: true }).click();
const center = page.getByRole('dialog', { name: '模型中心', exact: true });
await expect(center).toBeVisible(); assert.equal(modelCalls, 0);
await page.keyboard.press('Escape');
await expect(page.getByLabel('任务内容')).toHaveValue(draft);
mark('starter prompts do not execute; missing model preserves input and opens connection setup');
await page.keyboard.press('Control+k');
await expect(page.getByLabel('搜索工作台工具')).toBeFocused();
await page.getByLabel('搜索工作台工具').fill('a-tool-that-does-not-exist');
await expect(page.locator('.tools-empty')).toContainText('没有找到');
await page.getByRole('button', { name: '清除搜索' }).click();
await page.getByLabel('搜索工作台工具').fill('项目文件');
await page.getByLabel('搜索工作台工具').press('ArrowDown');
await expect(page.getByRole('button', { name: '项目文件', exact: true })).toBeFocused();
await page.keyboard.press('Enter');
await expect(page.getByRole('tab', { name: /^文件/ })).toHaveAttribute('aria-selected', 'true');
await expect(page.getByLabel('筛选文件')).toBeFocused();
await page.getByLabel('筛选文件').fill('missing-orven-file');
await expect(page.locator('.sidebar-hint')).toContainText('没有匹配');
await page.getByLabel('筛选文件').fill('README');
await page.locator('.tree-row[title="README.md"]').click();
await expect(page.locator('.code-view')).toContainText('Orven UI fixture');
await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
await expect(page.getByLabel('任务内容')).toHaveValue(draft);
mark('tool search, no-result recovery, keyboard selection and real file preview preserve the draft');
await page.getByRole('button', { name: '切换当前模型', exact: true }).click();
await center.getByRole('button', { name: '手动填写(兼容)', exact: true }).click();
const editor = center.getByRole('form', { name: '编辑模型连接' });
await editor.getByLabel('连接名称', { exact: true }).fill('Orven 本机验证');
await editor.getByLabel('接口根地址', { exact: true }).fill(model.baseUrl);
await editor.getByLabel('请求模型名称', { exact: true }).fill('orven-ui-fixture');
await editor.getByLabel('服务需要 API Key', { exact: true }).uncheck();
await editor.getByRole('button', { name: '保存模型连接', exact: true }).click();
const connection = center.locator('.mc-connection').filter({ hasText: 'Orven 本机验证' });
await connection.getByRole('button', { name: '用于新任务', exact: true }).click();
await expect(center.locator('.mc-current')).toContainText('Orven 本机验证');
await center.getByRole('button', { name: '请求账本', exact: true }).click();
await expect(center.getByLabel('默认模型选择')).not.toBeVisible();
await center.getByRole('button', { name: '模型连接', exact: true }).click();
await shot('models'); await page.keyboard.press('Escape');
await page.reload(); await page.locator('.connection.connected').waitFor();
await expect(page.getByRole('button', { name: '切换当前模型', exact: true })).toContainText('Orven 本机验证');
assert.equal(modelCalls, 0);
mark('model creation and selection persist across refresh; setup emits no model requests');
await page.getByLabel('任务内容').fill('只读取 README.md,并写一个 ORVEN-NOTES.md 说明。无需检查,无需 Git。');
await page.getByRole('button', { name: '发送任务', exact: true }).click();
await expect(page.locator('.message-assistant')).toContainText('本机协议夹具', { timeout: 20000 });
assert.equal(modelCalls, 3);
assert.match(fs.readFileSync(path.join(f.projectRoot, 'ORVEN-NOTES.md'), 'utf8'), /已读取项目/);
await expect(page.locator('.composer textarea')).toBeEmpty();
await tool('查看改动');
await expect(page.locator('.diff-view')).toContainText('已读取项目');
await shot('task-results');
await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
await page.reload(); await page.locator('.connection.connected').waitFor();
await expect(page.locator('.message-assistant')).toContainText('本机协议夹具');
mark('real three-request local protocol flow reads and writes the owned project; diff and conversation survive refresh');
await page.getByLabel('操作权限').selectOption('auto');
await expect.poll(async () => (await host.api('/bootstrap')).config.approvalMode).toBe('auto');
await page.reload(); await page.locator('.connection.connected').waitFor();
await expect(page.getByLabel('操作权限')).toHaveValue('auto');
mark('permission choice is saved and restored rather than shown as a cosmetic selection');
await page.keyboard.press('Control+p');
await page.getByLabel('筛选文件').fill('README');
await page.locator('.tree-row[title="README.md"]').click();
await expect(page.locator('.code-view')).toContainText('Orven UI fixture');
await page.getByRole('button', { name: '编辑文件', exact: true }).click();
const original = await page.getByLabel('编辑文件内容').inputValue();
await page.getByLabel('编辑文件内容').fill(original + '\n本次编辑应保留到冲突处理。\n');
fs.writeFileSync(path.join(f.projectRoot, 'README.md'), original + '\n外部已更新。\n');
await page.getByRole('button', { name: '保存为提案', exact: true }).click();
await expect(page.locator('.toast')).toBeVisible();
assert.match(fs.readFileSync(path.join(f.projectRoot, 'README.md'), 'utf8'), /外部已更新/);
assert.ok(!fs.readFileSync(path.join(f.projectRoot, 'README.md'), 'utf8').includes('本次编辑应保留'));
await expect(page.getByLabel('编辑文件内容')).toHaveValue(original + '\n本次编辑应保留到冲突处理。\n');
await shot('file-conflict');
mark('external file conflict preserves external bytes and unsaved editor input, with a visible recovery message');
await page.getByRole('button', { name: '取消编辑', exact: true }).click();
await page.locator('.tree-row[title="README.md"]').click();
await expect(page.locator('.code-view')).toContainText('外部已更新');
const toastClose = page.getByRole('button', { name: '关闭提示', exact: true });
if (await toastClose.isVisible()) await toastClose.click();
await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
for (const width of [1280, 1024, 768, 390]) {
await page.setViewportSize({ width, height: width === 390 ? 844 : 800 });
await bounds();
}
await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
await page.getByRole('tab', { name: /^会话/ }).click();
await expect(page.locator('.session-list')).toContainText('只读取');
await page.getByRole('button', { name: '关闭侧边面板', exact: true }).click({ position: { x: 380, y: 350 } });
await page.getByRole('button', { name: '文件与成果', exact: true }).click();
await expect(page.getByRole('button', { name: '关闭检视区', exact: true })).toBeVisible();
await shot('mobile-results');
await page.keyboard.press('Escape');
await expect(page.getByRole('button', { name: '发送任务', exact: true })).toBeVisible();
await shot('mobile-conversation');
mark('1280/1024/768/390 layouts keep the document contained; mobile navigation and result drawer work');
await page.setViewportSize({ width: 1440, height: 960 });
await tool('项目技能');
await expect(page.getByRole('dialog', { name: '项目技能', exact: true })).toBeVisible();
await shot('skills'); await page.keyboard.press('Escape');
await tool('项目 MCP 工具');
await expect(page.getByRole('dialog', { name: '项目 MCP 工具', exact: true })).toBeVisible();
await shot('mcp'); await page.keyboard.press('Escape');
await tool('运行诊断');
await expect(page.getByRole('dialog', { name: '运行诊断', exact: true })).toBeVisible();
await page.locator('.diagnostic-panel').waitFor();
await shot('diagnostics'); await page.keyboard.press('Escape');
mark('skills, MCP and diagnostics remain connected through the new tool navigation');
await page.goto(host.url + '/brand.html');
await expect(page.getByRole('heading', { level: 1 })).toContainText('运行中的作品');
await page.getByRole('button', { name: '查看深色背景', exact: true }).click();
await expect(page.locator('#specimen')).toHaveAttribute('data-dark', 'true');
await page.getByRole('button', { name: '查看品牌色背景', exact: true }).click();
await shot('brand');
for (const asset of ['/brand/orven-symbol.svg', '/brand/orven-wordmark.svg', '/workbench-icon.png', '/workbench-icon.ico']) assert.equal((await fetch(host.url + asset)).status, 200);
assert.deepEqual(errors, []);
mark('brand page, interactive mark backgrounds and downloadable SVG/PNG/ICO assets render without browser errors');
fs.writeFileSync(path.join(output, 'result.json'), JSON.stringify({ palette, checks, errors, modelCalls, realModelCalls: 0, fixtureOnly: true, userDataAccessed: false }, null, 2));
} catch (error) {
await shot('failure').catch(() => {});
fs.writeFileSync(path.join(output, 'failure.json'), JSON.stringify({ checks, errors, modelCalls, message: error.message }, null, 2));
throw error;
} finally {
await browser.close();
for (const dispose of disposers.reverse()) await dispose();
}