Files
Agent-Workbench/scripts/verify-orven-desktop.mjs
2026-11-06 15:11:49 +08:00

49 lines
3.1 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { _electron } from 'playwright';
import { fixture, launchWorkbench } from '../tests/helpers.mjs';
import { projectEnvironment } from '../src/core/process-environment.mjs';
import { openWorkbenchTool } from './ui-navigation.mjs';
const disposers = [], t = { after: dispose => disposers.push(dispose) };
const f = fixture(t, { modernDefaults: true }); f.store.close();
const host = await launchWorkbench(t, f.data);
assert.notEqual(new URL(host.url).port, '4318');
const appRoot = path.resolve(process.env.AGENT_WORKBENCH_TEST_APP_ROOT ?? '.');
const output = path.resolve(process.env.ORVEN_QA_OUTPUT ?? 'output/playwright/orven'); fs.mkdirSync(output, { recursive: true });
let app;
try {
const executablePath = process.env.ORVEN_QA_ELECTRON ?? path.resolve('node_modules/electron/dist/electron.exe');
const packaged = path.resolve(executablePath) === path.join(appRoot, 'desktop/AgentWorkbench.exe');
app = await _electron.launch({ executablePath,
args: [...(packaged ? [] : [path.join(appRoot, 'dist-desktop/main.cjs')]), '--app-root', appRoot, '--data-root', f.data, '--node', process.execPath, '--port', new URL(host.url).port, '--hidden-window'],
env: projectEnvironment(), cwd: process.cwd(), timeout: 60000 });
const page = await app.firstWindow(), errors = [];
page.on('pageerror', error => errors.push(error.message));
await page.locator('.connection.connected').waitFor({ timeout: 30000 });
assert.equal(await app.evaluate(({ app }) => app.getName()), 'Orven');
assert.equal(await page.title(), 'Orven · AI 开发工作台');
const native = await app.browserWindow(page);
assert.equal(await native.evaluate(window => window.getTitle()), 'Orven · AI 开发工作台');
// A never-shown native window does not produce compositor frames on Windows.
// Show without taking focus for capture, then close this owned fixture below.
await native.evaluate(window => window.showInactive());
await page.screenshot({ path: path.join(output, 'native-desktop.png'), timeout: 10000 });
await openWorkbenchTool(page, '桌面宿主');
await page.getByRole('dialog', { name: '桌面与后台任务' }).waitFor();
await page.getByText('执行宿主正在运行', { exact: true }).waitFor();
await page.locator('.desktop-host-facts').waitFor();
await page.screenshot({ path: path.join(output, 'native-host.png') });
assert.deepEqual(errors, []);
const result = { appName: 'Orven', nativeTitle: 'Orven · AI 开发工作台', isolatedHost: true, productionTouched: false, realModelCalls: 0, errors };
fs.writeFileSync(path.join(output, 'desktop-result.json'), JSON.stringify(result, null, 2));
console.log('PASS actual Electron window: Orven application/title, rendered workspace and native host navigation');
} catch (error) {
fs.writeFileSync(path.join(output, 'desktop-failure.json'), JSON.stringify({ error: error.message, isolatedHost: true }, null, 2));
throw error;
} finally {
if (app) await app.close();
for (const dispose of disposers.reverse()) await dispose();
}