70 lines
5.4 KiB
JavaScript
70 lines
5.4 KiB
JavaScript
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', 'milestone-audit-deployed-ui-' + randomUUID());
|
|
fs.mkdirSync(directory);
|
|
const health = await (await fetch(base + '/api/health')).json();
|
|
const deployed = JSON.parse(fs.readFileSync('docs/milestone-audit-upgrade-live-validation.json', 'utf8'));
|
|
assert.equal(deployed.success, true); assert.equal(health.version, '1.12.1'); assert.equal(health.pid, deployed.pid);
|
|
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.12.1', { waitUntil: 'domcontentloaded' })]);
|
|
await expect(page.locator('.connection small')).toHaveText('v1.12.1');
|
|
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);
|
|
}
|
|
console.log(JSON.stringify({ width, passedPanels: 4 }));
|
|
} 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/milestone-audit-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 }));
|
|
}
|