test(credentials): verify restart recovery through the packaged desktop entry

This commit is contained in:
Agent Workbench Dev
2026-11-12 09:40:17 +08:00
parent 41e5976897
commit 0415e9d5ea
3 changed files with 12 additions and 4 deletions
+7 -2
View File
@@ -8,6 +8,8 @@ import { DatabaseSync } from 'node:sqlite';
import { chromium, _electron } from 'playwright';
import { expect } from 'playwright/test';
import { fixture, compatibleFixture, until } from '../tests/helpers.mjs';
import { desktopLaunchCommand } from './desktop-launch.mjs';
import { projectEnvironment } from '../src/core/process-environment.mjs';
const args = process.argv.slice(2);
if (args.includes('--help')) {
@@ -201,12 +203,15 @@ try {
if (options.desktop) {
const executable = path.join(appRoot, 'desktop/AgentWorkbench.exe'); assert.ok(fs.existsSync(executable));
const cleanEnv = { ...process.env }; delete cleanEnv.AGENT_WORKBENCH_API_KEY;
electron = await _electron.launch({ executablePath: executable, args: [path.join(appRoot, 'dist-desktop/main.cjs'), '--hidden-window', '--app-root', appRoot, '--data-root', f.data, '--node', nodePath, '--port', new URL(second.url).port], cwd: appRoot, env: cleanEnv, timeout: 60000 });
electron = await _electron.launch({ ...desktopLaunchCommand(appRoot, ['--hidden-window', '--app-root', appRoot,
'--data-root', f.data, '--node', nodePath, '--port', new URL(second.url).port]), cwd: appRoot, env: projectEnvironment(), timeout: 60000 });
const desktop = await electron.firstWindow(); await desktop.waitForLoadState('networkidle');
const nativeDialog = await openModels(desktop);
await expect(nativeDialog.locator('.mc-connection').filter({ hasText: 'owned-manual-edited' })).toContainText('重启自动恢复');
const visible = await electron.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows().some(window => window.isVisible())); assert.equal(visible, false);
// Windows needs compositor frames for screenshots. Show this owned fixture
// without taking focus after proving the hidden startup, then close below.
const nativeWindow = await electron.browserWindow(desktop); await nativeWindow.evaluate(window => window.showInactive());
await desktop.setViewportSize({ width: 1440, height: 1000 });
await nativeDialog.locator('.mc-connection').filter({ hasText: 'owned-manual-edited' }).scrollIntoViewIfNeeded();
await picture(desktop, 'electron-desktop-restored');