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

41 lines
3.3 KiB
JavaScript

import fs from 'node:fs';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
const write = (file, code) => {
fs.writeFileSync(file, code, { flag: 'wx' });
execFileSync(process.execPath, ['--check', file], { windowsHide: true, stdio: 'pipe' });
};
let edge = fs.readFileSync('.qa/verify-reproducible-env-formal-ui.mjs', 'utf8')
.replaceAll('reproducible-env', 'embedded-browser').replaceAll('1.21.0', '1.22.0');
const edgeAnchor = " const plan = page.getByLabel('执行计划', { exact: true }); await expect(plan).toBeVisible();";
assert.ok(edge.includes(edgeAnchor));
edge = edge.replace(edgeAnchor, ` 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();
` + edgeAnchor);
edge = edge.replace('console.log(JSON.stringify({ width, passedPanels: 13 }));', 'console.log(JSON.stringify({ width, passedPanels: results.filter(row => row.width === width).length }));');
write('.qa/verify-embedded-browser-formal-ui.mjs', edge);
let native = fs.readFileSync('.qa/verify-reproducible-env-native-ui.mjs', 'utf8')
.replaceAll('reproducible-env', 'embedded-browser').replaceAll('1.21.0', '1.22.0');
const nativeAnchor = " await capture(page,label+'-environment-entry');";
assert.ok(native.includes(nativeAnchor));
native = native.replace(nativeAnchor, nativeAnchor + `
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();
if (label.startsWith('electron-')) await expect(browsing).not.toContainText('桌面浏览器未连接');
else await expect(browsing).toContainText('桌面浏览器未连接');
await expect(browsing.getByRole('button', { name: '打开目标', exact: true })).toBeEnabled();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
await capture(page, label + '-browser-entry');
await browsing.getByRole('button', { name: '返回任务', exact: true }).click();
`);
native = native.replace('saveFullyReachable: true, submitted: false', "saveFullyReachable: true, browserEntryObserved: true, desktopBrowserConnected: label.startsWith('electron-'), submitted: false");
write('.qa/verify-embedded-browser-native-ui.mjs', native);
console.log(JSON.stringify({ success: true, scripts: ['.qa/verify-embedded-browser-formal-ui.mjs', '.qa/verify-embedded-browser-native-ui.mjs'], executedFormalHost: false }));