From 50d799c6b494cb9a02cf3f8148485f480ed465b7 Mon Sep 17 00:00:00 2001 From: Agent Workbench Dev Date: Sat, 7 Nov 2026 22:59:31 +0800 Subject: [PATCH] fix(ci): observe the owned listener during desktop cleanup --- docs/M2-CI-PLAN.md | 1 + progress.md | 2 ++ scripts/ci-desktop-smoke.mjs | 8 +++++--- scripts/ci-utils.mjs | 16 ++++++++++++++++ tests/ci-pipeline.test.mjs | 10 +++++++++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/M2-CI-PLAN.md b/docs/M2-CI-PLAN.md index 8e511e5f..1874e430 100644 --- a/docs/M2-CI-PLAN.md +++ b/docs/M2-CI-PLAN.md @@ -36,3 +36,4 @@ - 全套另暴露engine-context测试在模块加载时依赖源码包故意排除的历史档案;静态核对还有model-reservation和original-purge同类包外输入。下一只将必要的解析子树/公开锁定源码整理为带原SHA/Git blob的测试夹具,保留历史全集,不扩大源码包到项目/会话/凭据或证据档案,不删套件或加skip改绿。 - 最小回放准备实读112份已提交来源并核当前字节与Git blob一致;生成65份2452465字节(四engine子树、一R原证明/六回执/请求子树、60锁定公开Purge源码)。INDEX逐SHA/字段来源及公开源码原license/NOTICE保持,原来源前后不变;三个套件保留所有断言,仅改为本地声明输入。新CI前置核全部夹具,漂移/缺失/逃逸反例待专项验证,不将JSON投影冒称完整原会话字节。 - 四engine新/旧原生输入、模型配置、工具回执子树和实际engineContextView输出逐项一致;R原证明/六回执/请求一致,112原来源再次核SHA通过。原三个回归套件加CI负向边界专项35/35(39303ms),未知文件/同长度SHA变化/缺文件/路径逃逸均不能通过;未新增真实模型或实际Harness派发。旧全套仍持续收集,尚不记CI全绿。 +- 冒烟清理复核发现原`portClosed:true`仅由HTTP health不可取和PID退出推导,未直接核监听。增加仅针对本次记录127.0.0.1端口的TCP接收/拒绝观察;缺health但仍监听不能通过,异常/超时保持失败,不结束外来进程。同页watch去重避免把一次浏览器事件记两次。首次直接工具专项8/8(没有独立磁盘原日志),规范最终文本后另用记录器核最终输入;实际Edge/Electron仍待最终Windows run。 diff --git a/progress.md b/progress.md index a6c61d04..2726faf9 100644 --- a/progress.md +++ b/progress.md @@ -1,5 +1,7 @@ # 统一执行进度 +880c88c7已提交最小回放,独立contract已真npm ci73.3s/build18.1s、来源/工作流通过且14指定回归运行中;原Windows全套仍在大记录/Python等阶段。复核冒烟清理从health缺失误推端口关闭,已补真实TCP监听观察和同页事件去重,直接工具8/8,最终记录器专项和实际两端尚待;不提前代签全套/远端。Mnemo最终七原件SHA及五组离线摘要匹配,只读反馈补充,未接通服务或联合验收。 + CI最小回放夹具65份2452465字节完成:112原来源/Git blob前后一致,四engine投影和R原证明/六回执/请求与旧输入相同。三原套件加CI漂移/缺失/逃逸边界35/35,源码包仍排除完整历史档案/会话/凭据;新CI导出后先核夹具。原e75a6427全套正在大记录/Python等阶段,首失败照存;最终干净安装仍待,不以专项或本机结果称远端job通过。 CI首四个旧断言已核对:Messages原生块整组保留且完整往返、Orven标题、input/context容量分开、目录绑定实际请求/凭据修订;三文件专项41/41,原e75a6427全套继续收集。engine-context另因包外历史输入加载失败,model-reservation/original-purge同类依赖将改成最小带来源夹具;不删测试、不复制用户数据、不改原历史或正式服务。Mnemo新增规范先登记只读,不扩大本轮权限。 diff --git a/scripts/ci-desktop-smoke.mjs b/scripts/ci-desktop-smoke.mjs index 15e2adb4..6dcb7ec5 100644 --- a/scripts/ci-desktop-smoke.mjs +++ b/scripts/ci-desktop-smoke.mjs @@ -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()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})); diff --git a/scripts/ci-utils.mjs b/scripts/ci-utils.mjs index 19e34a2e..a002cc5c 100644 --- a/scripts/ci-utils.mjs +++ b/scripts/ci-utils.mjs @@ -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)}`); diff --git a/tests/ci-pipeline.test.mjs b/tests/ci-pipeline.test.mjs index dfb8e368..2621e4de 100644 --- a/tests/ci-pipeline.test.mjs +++ b/tests/ci-pipeline.test.mjs @@ -3,10 +3,11 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; +import net from 'node:net'; import { execFileSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; import YAML from 'yaml'; -import { createCiRun, ciEnvironment, loggedCommand, tapTotals, requireCompleteTests, unpackVerifiedSource, fileDigest, binaryMirror } from '../scripts/ci-utils.mjs'; +import { createCiRun, ciEnvironment, loggedCommand, tapTotals, requireCompleteTests, unpackVerifiedSource, fileDigest, binaryMirror, loopbackPortStatus } from '../scripts/ci-utils.mjs'; import { packageSource } from '../scripts/package-source.mjs'; import { verifyCiWorkflow } from '../scripts/verify-ci-workflow.mjs'; import { verifyReplayFixtures, replayFixtureJson } from '../scripts/verify-replay-fixtures.mjs'; @@ -29,6 +30,13 @@ test('a download mirror is an explicit public HTTPS directory and cannot carry c for(const value of ['http://example.invalid/electron/','https://owned:credential@example.invalid/','https://example.invalid/?token=owned','https://example.invalid/electron/#owned','https://example.invalid/file.zip'])assert.throws(()=>binaryMirror(value)); }); +test('CI cleanup observes the recorded TCP listener instead of treating a missing health response as a closed port',async t=>{ + const server=net.createServer(socket=>socket.destroy());t.after(()=>{if(server.listening)return new Promise(resolve=>server.close(resolve));}); + await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));const port=server.address().port; + assert.deepEqual(await loopbackPortStatus(port),{host:'127.0.0.1',port,status:'accepting'}); + await new Promise(resolve=>server.close(resolve));assert.deepEqual(await loopbackPortStatus(port),{host:'127.0.0.1',port,status:'refused'}); +}); + test('actual nonzero command, original stdout/stderr and spawn failure survive without replay or log overwrite',async t=>{ const run=createCiRun(owned(t),'contract'),env=ciEnvironment(run); const result=await loggedCommand({id:'original-failure',executable:process.execPath,args:['-e',"process.stdout.write('original\\n');process.stderr.write('failure\\n');process.exitCode=7"],cwd:run.source,env,evidence:run.evidence,check:false});