55 lines
5.0 KiB
JavaScript
55 lines
5.0 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { randomUUID, createHash } from 'node:crypto';
|
|
import { _electron } from 'playwright';
|
|
import { expect } from 'playwright/test';
|
|
import { HostController } from '../src/core/desktop/host-controller.mjs';
|
|
import { projectEnvironment } from '../src/core/process-environment.mjs';
|
|
import { publicSnapshot, compareOriginalState } from './task-control-j-state.mjs';
|
|
const read = file => JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
const deployed = read('.qa/task-control-j-formal-verify.json'); assert.equal(deployed.success, true);
|
|
const directory = path.resolve('.qa', 'task-control-j-native-' + randomUUID()); fs.mkdirSync(directory);
|
|
const before = await publicSnapshot('http://127.0.0.1:4318', deployed.dataRoot);
|
|
assert.equal(before.version, '1.20.1'); assert.equal(before.pid, 36552); assert.deepEqual(before.active, []);
|
|
const bootstrap = await (await fetch('http://127.0.0.1:4318/api/bootstrap')).json();
|
|
const history = bootstrap.sessions.find(value => value.status === 'completed' && bootstrap.projects.some(project => project.id === value.projectId)); assert.ok(history);
|
|
const controller = new HostController({ appRoot: deployed.candidate, dataRoot: deployed.dataRoot, port: 4318, nodePath: process.execPath });
|
|
const status = await controller.status(); assert.equal(status.desktopWindows.count, 0); assert.equal(status.activity.active, false);
|
|
const screenshots = [], errors = [], nativeOutput = []; let application, result;
|
|
try {
|
|
application = await _electron.launch({ executablePath: path.join(deployed.candidate, 'desktop/AgentWorkbench.exe'),
|
|
args: ['--app-root', deployed.candidate, '--data-root', deployed.dataRoot, '--port', '4318', '--hidden-window'], cwd: deployed.candidate, env: projectEnvironment(), timeout: 90000 });
|
|
for (const stream of [application.process().stdout, application.process().stderr]) stream?.on('data', bytes => nativeOutput.push(bytes));
|
|
const page = await application.firstWindow({ timeout: 60000 }); page.on('pageerror', error => errors.push(error.message));
|
|
await expect(page.locator('.connection small')).toHaveText('v1.20.1', { timeout: 30000 });
|
|
await expect(page.locator('.connection')).toContainText('本地服务已连接');
|
|
assert.equal((await controller.status()).desktopWindows.count, 1);
|
|
const projectSelector = page.getByRole('combobox', { name: '当前项目', exact: true });
|
|
if (!await projectSelector.isVisible()) await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
|
|
await projectSelector.selectOption(history.projectId); await expect(projectSelector).toHaveValue(history.projectId);
|
|
for (const [width, height] of [[1280, 900], [390, 844]]) {
|
|
await page.setViewportSize({ width, height });
|
|
await expect(page.getByRole('button', { name: '查看任务记录', exact: true })).toBeVisible();
|
|
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 });
|
|
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
|
|
const file = path.join(directory, 'native-task-' + width + '.png'); await page.screenshot({ path: file, fullPage: true });
|
|
screenshots.push({ path: file, sha256: createHash('sha256').update(fs.readFileSync(file)).digest('hex'), width, height });
|
|
if (width <= 940) await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
result = { success: true, version: before.version, pid: before.pid, directory, screenshots, errors, actualInstalledElectron: true, currentProviderPreserved: true, realModelRequests: 0 };
|
|
} catch (error) { result = { success: false, directory, screenshots, errors, error: error.stack }; process.exitCode = 1; }
|
|
finally {
|
|
await application?.close().catch(error => { result.closeError = error.message; result.success = false; process.exitCode = 1; });
|
|
const after = await publicSnapshot('http://127.0.0.1:4318', deployed.dataRoot); result.retained = compareOriginalState(before, after);
|
|
result.desktopWindowsAfter = (await controller.status()).desktopWindows.count; assert.equal(result.desktopWindowsAfter, 0);
|
|
fs.writeFileSync(path.join(directory, 'native-output.txt'), Buffer.concat(nativeOutput), { flag: 'wx' });
|
|
result.scope = 'Actual installed Electron and original formal host, desktop/390px task pane observed. No model call, user task execution, approval, configuration or project write. Window closes while the original host remains.';
|
|
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
|
|
fs.writeFileSync('.qa/task-control-j-formal-native-validation.json', JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
|
|
console.log(JSON.stringify({ success: result.success, directory, screenshots: screenshots.length, error: result.error }));
|
|
}
|