import{writeFile}from'node:fs/promises';import{resolve}from'node:path';const root='/mnt/data/home/bench-saves/mtuci-vp-remaining-20261115/lab6';function run(args:string[],allowed=[0]){const r=Bun.spawnSync(args,{stdout:'pipe',stderr:'pipe'});if(!allowed.includes(r.exitCode))throw Error('Read-only teardown verification failed');return new TextDecoder().decode(r.stdout)}const containers=run(['docker','ps','--format','{{.ID}} {{.Names}}']).trim().split('\n').filter(Boolean).map(l=>{const[id,name]=l.split(' ');return{id,name}}).filter(c=>c.name.startsWith('mtuci-vp6-')||c.name.startsWith('vp6-'));const ports=new Set([28206,28306,28406,28706,28806,28906,29506,29606]),listeners=run(['ss','-ltnH']).trim().split('\n').filter(Boolean).map(l=>l.trim().split(/\s+/)[3]).filter(address=>ports.has(Number(address?.split(':').at(-1))));const browser=run(['pgrep','-af','[c]hromium.*--user-data-dir=/tmp/vp6-browser-31251471/'],[0,1]).trim().split('\n').filter(Boolean);const result={checkedAt:new Date().toISOString(),ownRunningContainers:containers,ownListeningEndpoints:listeners,ownBrowserProcessCount:browser.length,preserved:'All existing/current/fresh volumes, private receipts, encrypted identities and verified caches retained; shared7/runner untouched',passed:!containers.length&&!listeners.length&&!browser.length};const out=resolve(root,'.local/final-stop-'+crypto.randomUUID()+'.json');await writeFile(out,JSON.stringify(result,null,2)+'\n',{flag:'wx',mode:0o600});console.log(JSON.stringify({receipt:out,...result}));if(!result.passed)process.exitCode=1;
