Files
Agent-Workbench/docs/live-original-purge-e-evidence/drivers/audit-retest-e.mjs
T
2026-11-02 23:13:19 +08:00

15 lines
1.6 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import net from 'node:net';
import {batch,control} from './retest-e-common.mjs';
import {observeWindowsProcess} from '../src/core/desktop/process-identity.mjs';
const rows=JSON.parse(fs.readFileSync(path.join(batch,'owned-records.json'))),jobs=rows.filter(r=>r.kind==='engine_run').map(r=>JSON.parse(r.payload));
const processes=jobs.map(j=>{const pid=j.native?.process?.pid??j.native?.process?.rootPid??j.native?.cleanup?.pid??j.native?.cleanup?.rootPid??j.pid;
const cleanup=j.native?.cleanup;assert.equal(cleanup?.treeConfirmed,true,j.id);assert.equal(cleanup?.rootExited,true,j.id);
return {jobId:j.id,pid:pid??null,rootExited:cleanup.rootExited,treeConfirmed:cleanup.treeConfirmed,...(pid?{currentlyExists:!!observeWindowsProcess(pid)}:{})};});
assert.ok(processes.every(p=>p.currentlyExists!==true));
const inspectorClosed=await new Promise((resolve,reject)=>{const s=net.createConnection({host:'127.0.0.1',port:9229});s.setTimeout(1000);s.once('connect',()=>{s.destroy();reject(Error('Inspector open'));});s.once('timeout',()=>{s.destroy();reject(Error('Inspector unknown'));});s.once('error',e=>{s.destroy();e.code==='ECONNREFUSED'?resolve(true):reject(e);});});
const host=await control('/host/status');assert.equal(host.activity.active,false);
const receipt={passed:true,processes,inspectorClosed,hostActive:false,pid:host.identity.pid};fs.writeFileSync(path.join(batch,'process-audit.json'),JSON.stringify(receipt,null,2)+'\n',{flag:'wx'});console.log(JSON.stringify(receipt));