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', 'controlled-engine-deployed-ui-' + randomUUID()); fs.mkdirSync(directory); const health = await (await fetch(base + '/api/health')).json(); const deployed = JSON.parse(fs.readFileSync('docs/controlled-engine-upgrade-live-validation.json', 'utf8')); assert.equal(deployed.success, true); assert.equal(health.version, '1.14.0'); assert.equal(health.pid, deployed.pid); const bootstrap = await (await fetch(base + '/api/bootstrap')).json(); 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, 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.14.0', { waitUntil: 'domcontentloaded' })]); await expect(page.locator('.connection small')).toHaveText('v1.14.0'); await expect(page.locator('.connection')).toContainText('本地服务已连接'); await page.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') }); 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(); console.log(JSON.stringify({ width, passedPanels: 7 })); } 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, no task/tool/model/configuration/project writes.' }); fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(record, null, 2) + '\n'); fs.writeFileSync('.qa/controlled-engine-deployed-ui-validation.json', 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 })); }