fix(ci): observe the owned listener during desktop cleanup

This commit is contained in:
Agent Workbench Dev
2026-11-07 22:59:31 +08:00
parent 880c88c7fc
commit 50d799c6b4
5 changed files with 33 additions and 4 deletions
+5 -3
View File
@@ -10,7 +10,7 @@ import { desktopExecutableIdentity } from '../src/core/desktop/app-installation.
import { projectEnvironment } from '../src/core/process-environment.mjs';
import { browserInstallation } from '../src/core/browser/browser-driver.mjs';
import { openWorkbenchTool } from './ui-navigation.mjs';
import { fileDigest, writeNewJson } from './ci-utils.mjs';
import { fileDigest, writeNewJson, loopbackPortStatus } from './ci-utils.mjs';
const args=process.argv.slice(2);
if(args.includes('--help')) {console.log('node scripts/ci-desktop-smoke.mjs --evidence NEW_DIRECTORY — actual product Microsoft Edge and hidden Electron through locked Playwright against an owned new host/project. No model, external project, formal configuration or installation.');process.exit(0);}
@@ -25,7 +25,8 @@ const controller=new HostController({appRoot,dataRoot,port,nodePath:process.exec
const report={schemaVersion:1,passed:false,startedAt:new Date().toISOString(),ownedRoot,port,groups:[],screenshots:[],pageErrors:[],externalRequests:[],scope:'Actual isolated product Microsoft Edge/Electron through locked Playwright and owned source/data only; no model or formal installation.'};
let browser,application,electronPid,hostIdentity,stage='host-start';
const record=(name,detail={})=>report.groups.push({name,passed:true,...detail});
const watch=(page)=>{page.on('pageerror',error=>report.pageErrors.push(error.message));page.on('request',request=>{const url=new URL(request.url());if(['http:','https:'].includes(url.protocol) && !(url.hostname==='127.0.0.1' && Number(url.port)===port))report.externalRequests.push(request.url());});};
const watched=new WeakSet();
const watch=(page)=>{if(watched.has(page))return;watched.add(page);page.on('pageerror',error=>report.pageErrors.push(error.message));page.on('request',request=>{const url=new URL(request.url());if(['http:','https:'].includes(url.protocol) && !(url.hostname==='127.0.0.1' && Number(url.port)===port))report.externalRequests.push(request.url());});};
async function capture(page,mode,width,height){
const id=mode+'-'+width,file=path.join(evidence,id+'.png');
if(mode==='electron'){
@@ -72,7 +73,8 @@ finally{
if(await controller.health())report.hostStop=await controller.stop();
const deadline=Date.now()+15000;while(electronPid && observeWindowsProcess(electronPid) && Date.now()<deadline)await new Promise(resolve=>setTimeout(resolve,100));
assert.equal(electronPid?!!observeWindowsProcess(electronPid):false,false,'Owned Electron did not exit');assert.equal(await controller.health(),null,'Owned port still responds');
report.cleanup={hostExited:hostIdentity?observeWindowsProcess(hostIdentity.pid)===null:true,electronExited:electronPid?observeWindowsProcess(electronPid)===null:true,portClosed:true};
report.portObservation=await loopbackPortStatus(port);assert.equal(report.portObservation.status,'refused','Recorded CI port still accepts TCP connections');
report.cleanup={hostExited:hostIdentity?observeWindowsProcess(hostIdentity.pid)===null:true,electronExited:electronPid?observeWindowsProcess(electronPid)===null:true,portClosed:report.portObservation.status==='refused'};
assert.equal(report.cleanup.hostExited,true);
}catch(error){report.passed=false;report.cleanupFailure={message:error.message,stack:error.stack};process.exitCode=1;}
report.finishedAt=new Date().toISOString();writeNewJson(path.join(evidence,'result.json'),report);console.log(JSON.stringify({passed:report.passed,groups:report.groups.length,screenshots:report.screenshots.length,report:path.join(evidence,'result.json'),failure:report.failure?.message,cleanupFailure:report.cleanupFailure?.message}));
+16
View File
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import net from 'node:net';
import { createHash, randomUUID } from 'node:crypto';
import { spawn } from 'node:child_process';
import { readSourceZip } from './package-source.mjs';
@@ -14,6 +15,21 @@ export function binaryMirror(value) {
assert.ok(url.protocol === 'https:' && !url.username && !url.password && !url.search && !url.hash && url.pathname.endsWith('/'), 'Binary mirror must be an explicit HTTPS directory without credentials.');
return url.href;
}
export async function loopbackPortStatus(port) {
assert.ok(Number.isSafeInteger(port) && port > 0 && port <= 65535, 'Recorded CI port required');
return new Promise((resolve, reject) => {
const socket = net.createConnection({ host: '127.0.0.1', port });
let settled = false;
const finish = (error, status) => {
if (settled) return; settled = true; clearTimeout(timer); socket.destroy();
if (error) reject(error); else resolve({ host: '127.0.0.1', port, status });
};
const timer = setTimeout(() => finish(new Error('Recorded CI port observation timed out')), 5000);
socket.once('connect', () => finish(null, 'accepting'));
socket.once('error', error => error.code === 'ECONNREFUSED' ? finish(null, 'refused') : finish(error));
});
}
export function createCiRun(outputRoot, profile) {
assert.ok(['contract', 'windows'].includes(profile), 'Unknown CI profile');
const root = path.resolve(outputRoot), run = path.join(root, `run-${profile}-${Date.now().toString(36)}-${randomUUID().slice(0,8)}`);