Files
Agent-Workbench/docs/task-control-j-release-evidence/0006-diagnose-task-control-installed-restart.mjs
T
2026-11-01 16:35:58 +08:00

31 lines
2.5 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { _electron } from 'playwright';
import { HostController } from '../src/core/desktop/host-controller.mjs';
import { projectEnvironment } from '../src/core/process-environment.mjs';
const location = JSON.parse(fs.readFileSync('.qa/task-control-f-install-location.json', 'utf8'));
const failed = JSON.parse(fs.readFileSync(location.result, 'utf8')); assert.equal(failed.success, false);
const info = JSON.parse(fs.readFileSync(path.join(failed.dataRoot, 'service-info.json'), 'utf8'));
assert.ok(failed.dataRoot.startsWith('C:\\AWQATC\\i-')); assert.notEqual(info.port, 4318);
const appRoot = info.appRoot, dataRoot = failed.dataRoot, port = info.port;
const controller = new HostController({ appRoot, dataRoot, port, nodePath: path.join(appRoot, 'runtime/node.exe') });
let application, result; const lines = [];
try {
application = await _electron.launch({ executablePath: path.join(appRoot, 'desktop/AgentWorkbench.exe'),
args: ['--app-root', appRoot, '--data-root', dataRoot, '--port', String(port), '--hidden-window'],
cwd: appRoot, env: projectEnvironment(), timeout: 120000 });
application.process().stdout?.on('data', data => lines.push(data)); application.process().stderr?.on('data', data => lines.push(data));
const page = await application.firstWindow({ timeout: 120000 }); await page.locator('.connection.connected').waitFor({ timeout: 30000 });
const status = await controller.status(); assert.equal(status.desktopWindows.count, 1);
result = { success: true, identity: status.identity, window: status.desktopWindows.entries[0],
scope: 'Diagnostic direct shipped Electron launch on the failed isolated QA installation, original profile/data and runtime. No model request; does not replace the failed native-bootstrap restart result.' };
} catch (error) { result = { success: false, error: error.stack }; process.exitCode = 1; }
finally {
await application?.close().catch(() => {});
try { if (await controller.connect()) { const status = await controller.status(); if (!status.desktopWindows.count && !status.activity.active) await controller.stop(); } } catch (error) { result.cleanupError = error.message; }
fs.writeFileSync('.qa/task-control-f-installed-restart-diagnostic.log', Buffer.concat(lines), { flag: 'wx' });
fs.writeFileSync('.qa/task-control-f-installed-restart-diagnostic.json', JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
console.log(JSON.stringify(result));
}