Files
Agent-Workbench/docs/embedded-browser-release-evidence/verifiers/verify-embedded-browser-d-formal-ui.mjs
T

154 lines
15 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash, randomUUID } from 'node:crypto';
import { chromium, expect } from 'playwright/test';
const base = 'http://127.0.0.1:4318', directory = path.resolve('.qa', 'embedded-browser-formal-ui-' + randomUUID());
fs.mkdirSync(directory);
const health = await (await fetch(base + '/api/health')).json();
const deployed = JSON.parse(fs.readFileSync(process.argv[2] ?? '.qa/embedded-browser-d-formal-activate.json', 'utf8'));
const output = process.argv[3] ?? '.qa/embedded-browser-d-formal-ui-validation.json';
assert.equal(deployed.success, true); assert.equal(health.version, '1.22.0'); assert.equal(health.pid, deployed.identity.pid);
const bootstrap = await (await fetch(base + '/api/bootstrap')).json();
const existingSession = bootstrap.sessions.find(value => value.status === 'completed' && bootstrap.projects.some(project => project.id === value.projectId));
assert.ok(existingSession, 'Read-only history inspection requires an existing completed session.');
const readApi = async route => { const response = await fetch(base + '/api' + route, { headers: { 'X-Workbench-Token': bootstrap.token, Connection: 'close' }, signal: AbortSignal.timeout(10000) }); assert.equal(response.ok, true); return response.json(); };
const controlledAvailability = await readApi('/engines/deepseek/controlled-availability'), purgeSource = await readApi('/engines/purge/source');
assert.equal(controlledAvailability.controlledStatus, 'available'); assert.equal(purgeSource.status, 'available'); assert.equal(purgeSource.defaultEnabled, false);
const pageErrors = [], requestFailures = [], httpErrors = [], blockedWrites = [], results = [];
const record = { success: false, version: health.version, pid: health.pid, directory,
selectedHistory: { projectId: existingSession.projectId, sessionId: existingSession.id, selection: 'Actual current-project selector; no task created.' }, results };
const browser = await chromium.launch({ channel: 'msedge', headless: true });
const screenshot = async (page, filename) => {
const file = path.join(directory, filename); await page.screenshot({ path: file, fullPage: true });
return { screenshot: file, screenshotSha256: createHash('sha256').update(fs.readFileSync(file)).digest('hex') };
};
try {
for (const [width, height] of [[1280, 900], [390, 844]]) {
const context = await browser.newContext({ viewport: { width, height }, reducedMotion: 'reduce' });
let closing = false;
try {
const page = await context.newPage();
page.on('pageerror', error => pageErrors.push(error.message));
page.on('requestfailed', request => { if (!closing) requestFailures.push({ url: request.url(), error: request.failure()?.errorText }); });
page.on('response', response => { if (response.status() >= 400) httpErrors.push({ url: response.url(), status: response.status() }); });
await page.route('**/api/**', route => {
if (!['GET', 'HEAD', 'OPTIONS'].includes(route.request().method())) {
blockedWrites.push({ method: route.request().method(), url: route.request().url() }); return route.abort();
}
return route.continue();
});
await Promise.all([page.waitForResponse(response => response.url().endsWith('/api/bootstrap') && response.status() === 200),
page.goto(base + '/?release=1.22.0', { waitUntil: 'domcontentloaded' })]);
await expect(page.locator('.connection small')).toHaveText('v1.22.0');
await expect(page.locator('.connection')).toContainText('本地服务已连接');
const projectSelector = page.getByRole('combobox', { name: '当前项目', exact: true });
if (!await projectSelector.isVisible()) await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
await projectSelector.selectOption(existingSession.projectId);
if (!await projectSelector.isVisible()) await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
await expect(projectSelector).toHaveValue(existingSession.projectId);
if (width <= 940) await page.getByRole('button', { name: '收起项目栏', exact: true }).click();
await expect(page.getByRole('button', { name: '隔离协作', exact: true })).toBeEnabled();
await page.getByRole('button', { name: '查看任务记录', exact: true }).click();
await expect(page.getByRole('region',{name:'工程环境与依赖',exact:true})).toBeVisible();
results.push({width,height,panel:'工程环境与依赖入口(未执行诊断)',readOnly:true,...await screenshot(page,'environment-entry-'+width+'.png')});
await page.locator('.inspector-tabs').getByRole('button', { name: '浏览', exact: true }).click();
const browsing = page.getByRole('region', { name: '内置浏览器', exact: true });
await expect(browsing.getByRole('heading', { name: '在任务旁核对真实页面', exact: true })).toBeVisible();
await expect(browsing).toContainText('桌面浏览器未连接');
await expect(browsing.getByRole('button', { name: '打开目标', exact: true })).toBeEnabled();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '内置浏览器网页只读入口及桌面连接提示', readOnly: true, ...await screenshot(page, 'browser-entry-' + width + '.png') });
await browsing.getByRole('button', { name: '返回任务', exact: true }).click();
const plan = page.getByLabel('执行计划', { exact: true }); await expect(plan).toBeVisible();
await expect(plan).not.toHaveAttribute('aria-busy', 'true', { timeout: 15000 });
await expect(plan).not.toContainText('正在核对任务计划', { timeout: 15000 });
await expect(plan.getByRole('heading', { name: '执行计划', exact: true })).toBeVisible();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '执行计划', readOnly: true, ...await screenshot(page, 'plan-' + width + '.png') });
if (width <= 940) await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
for (const [launcher, title, suffix] of [['打开模型中心', '模型中心', '/api/model-center'], ['项目技能', '项目技能', '/skills'], ['项目MCP工具', '项目 MCP 工具', '/mcp']]) {
await Promise.all([page.waitForResponse(response => response.url().endsWith(suffix) && response.status() === 200),
page.getByRole('button', { name: launcher, exact: true }).click()]);
const dialog = page.getByRole('dialog', { name: title, exact: true }); await expect(dialog).toBeVisible();
await expect(dialog.getByRole('heading', { name: title, exact: true })).toBeVisible();
for (const loading of ['正在读取实际连接状态', '正在核对已登记技能', '正在读取项目注册']) await expect(dialog).not.toContainText(loading);
const bounds = await dialog.boundingBox(); assert.ok(bounds.x >= 0 && bounds.x + bounds.width <= width + 1);
results.push({ width, height, panel: title, readOnly: true, ...await screenshot(page, suffix.split('/').at(-1) + '-' + width + '.png') });
if (title === '模型中心') {
await Promise.all([page.waitForResponse(response => response.url().endsWith('/api/model-center/credentials') && response.status() === 200),
dialog.getByRole('button', { name: '凭据保存', exact: true }).click()]);
await expect(dialog.getByRole('heading', { name: '本机加密凭据', exact: true })).toBeVisible();
await expect(dialog).not.toContainText('正在核对本机保存状态');
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '本机加密凭据只读状态', readOnly: true, ...await screenshot(page, 'credentials-' + width + '.png') });
await dialog.getByRole('button', { name: '运行巡检', exact: true }).click();
await Promise.all([page.waitForResponse(response => response.url().includes('/api/operations') && response.status() === 200),
dialog.getByRole('button', { name: '开始本地巡检', exact: true }).click()]);
await expect(dialog.getByLabel('历史工件巡检分页', { exact: true })).toBeVisible();
await expect(dialog.getByRole('checkbox', { name: '在此页面每30秒检查,离开即停止', exact: true })).not.toBeChecked();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '运行巡检及实际覆盖范围', readOnly: true, ...await screenshot(page, 'operations-' + width + '.png') });
}
await dialog.getByRole('button', { name: '关闭窗口', exact: true }).click(); await expect(dialog).toHaveCount(0);
}
await page.getByRole('button', { name: '隔离协作', exact: true }).click();
const workers = page.getByRole('dialog', { name: '隔离协作', exact: true }); await expect(workers).toBeVisible();
await expect(workers.getByRole('heading', { name: '隔离协作', exact: true })).toBeVisible();
await expect(workers.getByLabel('父目标', { exact: true })).toBeVisible();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '隔离协作', readOnly: true, ...await screenshot(page, 'controlled-engine-' + width + '.png') });
await workers.getByLabel('执行方式', { exact: true }).selectOption('deepseek');
await workers.getByLabel('Harness 安装目录', { exact: true }).fill(controlledAvailability.root);
await workers.getByRole('button', { name: '检测受控安装', exact: true }).click(); await expect(workers).toContainText('受控安装可用');
const experiment = workers.getByLabel('Purge 提示实验', { exact: true }), toggle = experiment.getByRole('checkbox', { name: '启用 Purge 提示实验', exact: true });
await expect(toggle).not.toBeChecked(); assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '受控引擎安装与默认关闭策略', readOnly: true, ...await screenshot(page, 'controlled-native-' + width + '.png') });
await toggle.check(); await experiment.getByLabel('Purge 源码目录', { exact: true }).fill(purgeSource.root);
await experiment.getByRole('button', { name: '检测 Purge 来源', exact: true }).click(); await expect(experiment).toContainText('已核对 Purge ' + purgeSource.version);
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: 'Purge来源只读核对', readOnly: true, ...await screenshot(page, 'controlled-purge-' + width + '.png') });
await toggle.uncheck(); await workers.getByRole('button', { name: '关闭窗口', exact: true }).click();
await page.getByRole('button', { name: '工程评测', exact: true }).click();
const evaluations = page.getByRole('dialog', { name: '工程质量评测', exact: true }); await expect(evaluations).toBeVisible();
await expect(evaluations.getByLabel('工程评测控制台', { exact: true })).toBeVisible(); await expect(evaluations).toContainText('每批 1–3 个样本');
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '工程评测固定样本入口', readOnly: true, ...await screenshot(page, 'evaluations-' + width + '.png') });
await evaluations.getByRole('button', { name: '关闭窗口', exact: true }).click();
await page.getByRole('button', { name: '手机连接', exact: true }).click();
const companion = page.getByRole('dialog', { name: '手机连接', exact: true }); await expect(companion).toBeVisible();
await expect(companion).toContainText('默认关闭');
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '默认关闭的手机网关与设备管理', readOnly: true, ...await screenshot(page, 'companion-' + width + '.png') });
await companion.getByRole('button', { name: '关闭窗口', exact: true }).click();
if (width <= 940) await page.getByRole('button', { name: '查看文件', exact: true }).click();
await page.locator('.inspector-tabs').getByRole('button', { name: '索引', exact: true }).click();
const index = page.getByLabel('工程索引', { exact: true });
await expect(index.locator('.index-cache')).toBeVisible({ timeout: 30000 });
await index.locator('.index-cache summary').click();
await expect(index).toContainText('2 轮 SHA 核对');
await expect(index.getByRole('switch', { name: '启用本机解析缓存', exact: true })).toBeChecked();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
results.push({ width, height, panel: '工程解析缓存及本次来源核对', readOnly: true, derivedIndexRead: true, ...await screenshot(page, 'engineering-evals-' + width + '.png') });
if (width <= 940) await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
await page.getByRole('button', { name: '运行诊断', exact: true }).last().click();
const diagnostics = page.getByRole('dialog', { name: '运行诊断', exact: true });
await expect(diagnostics.getByLabel('解析缓存诊断')).toContainText('32 MiB');
results.push({ width, height, panel: '解析缓存诊断与当前工程', readOnly: true, ...await screenshot(page, 'cache-diagnostics-' + width + '.png') });
await diagnostics.getByRole('button', { name: '关闭窗口', exact: true }).click();
console.log(JSON.stringify({ width, passedPanels: results.filter(row => row.width === width).length }));
} finally { closing = true; await context.close(); }
}
assert.deepEqual(pageErrors, []); assert.deepEqual(requestFailures, []); assert.deepEqual(httpErrors, []); assert.deepEqual(blockedWrites, []);
record.success = true;
} catch (error) { record.error = error.stack; throw error; }
finally {
await browser.close();
Object.assign(record, { testedAt: new Date().toISOString(), pageErrors, requestFailures, httpErrors, blockedWrites, modelRequests: 0,
scope: 'Read-only smoke of deployed host in actual Edge desktop/390px; API mutations are blocked. Opening the source index may create derived parsing cache only; no task/tool/model/configuration/project writes.' });
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(record, null, 2) + '\n');
fs.writeFileSync(output, JSON.stringify(record, null, 2) + '\n');
console.log(JSON.stringify({ success: record.success, directory, panels: results.length, pageErrors: pageErrors.length, requestFailures: requestFailures.length, blockedWrites: blockedWrites.length }));
}