#!/usr/bin/env node /** * JesusOS isolated owned-child STOP self-test v1. * No miner, network, credentials, wallet, device enrollment or arbitrary PID lookup. * Runs ONLY with --selftest, starts ONE benign in-memory child under this process, * sends SIGTERM only to that exact ChildProcess handle, verifies exit or fails closed. * Not a continuous mining controller and never touches the original V9 process. */ import {spawn} from 'node:child_process'; const SCHEMA='jesusos.bitcoin.owned-child-stop-selftest.v1'; if(!((process.argv.length===2&&process.argv[1]==='--selftest')||(process.argv.length===3&&process.argv[2]==='--selftest'))){ console.error('Only --selftest is supported; this script cannot launch a miner.'); process.exitCode=2; }else{ const childCode="process.on('SIGTERM',()=>process.exit(0));setInterval(()=>{},1000);"; const child=spawn(process.execPath,['-e',childCode],{ stdio:['ignore','ignore','ignore'],shell:false, detached:false,windowsHide:true }); let state='started',confirmed=false,signalSent=false,reason='not-started'; const started=Date.now(); const done=new Promise(resolve=>{ child.once('error',e=>{reason='child-spawn-error';resolve(false)}); child.once('exit',(code,signal)=>{ confirmed=true; reason=signalSent?'owned-child-exit-confirmed':'child-exited-before-stop'; resolve(signalSent); }); }); const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms)); try{ await sleep(180); if(child.exitCode!==null||child.signalCode!==null||!Number.isInteger(child.pid)){ reason='child-not-running-before-stop'; }else{ state='stop-requested'; signalSent=child.kill('SIGTERM'); if(!signalSent)reason='owned-child-signal-failed'; } const outcome=await Promise.race([done,sleep(3000).then(()=>false)]); if(!outcome||!confirmed){ state='stop-unconfirmed'; // Escalation remains limited to the same directly spawned child handle. if(child.exitCode===null&&child.signalCode===null)child.kill('SIGKILL'); await Promise.race([done,sleep(1000)]); }else state='stop-confirmed'; }catch{ state='stop-unconfirmed';reason='selftest-error'; if(child.exitCode===null&&child.signalCode===null)child.kill('SIGKILL'); } const output={schema:SCHEMA,mode:'isolated-benign-selftest', miningActivated:false,networkRequests:0,walletAccess:false, existingV9Touched:false,childSpawned:1,childExitConfirmed:confirmed, state,signalSent,reason,elapsedMs:Date.now()-started}; console.log(JSON.stringify(output,null,2)); if(state!=='stop-confirmed'||!confirmed)process.exitCode=1; }