import assert from'node:assert/strict';import{readFileSync,writeFileSync,mkdirSync,mkdtempSync,copyFileSync,cpSync,readdirSync}from'node:fs';import{dirname,join,relative}from'node:path';import{spawnSync}from'node:child_process';import{artifact}from'/scripts/os-acceptance/cpu-watchdog-artifacts.mjs'; const root=process.cwd(),directory=mkdtempSync('reports/os-implementation/K2100-process-wake-staging-'),source=directory+'/source',report={status:'RUNNING',guestAccepted:false,productAccepted:false,sources:[],commands:[],mutants:[]};copyFileSync('/tmp/turkos-k2100-process-wake-preparation.mjs',directory+'/harness.mjs.txt');report.harness=artifact(directory+'/harness.mjs.txt'); const meta=spawnSync('cargo',['metadata','--manifest-path','os-smp-process-wake/Cargo.toml','--offline','--format-version','1'],{encoding:'utf8'});assert.equal(meta.status,0);const crates=[...new Set([...JSON.parse(meta.stdout).packages.map(p=>relative(root,dirname(p.manifest_path))),'os-process-table'])];for(const crate of crates){assert.ok(crate.startsWith('os-')&&!crate.includes('..'));cpSync(crate,source+'/'+crate,{recursive:true,filter:p=>!p.split('/').includes('target')});} function walk(dir){for(const e of readdirSync(dir,{withFileTypes:true})){const p=dir+'/'+e.name;if(e.isDirectory())walk(p);else report.sources.push(artifact(p));}}walk(source); const env={...process.env,CARGO_TARGET_DIR:join(root,directory,'target')};delete env.RUSTFLAGS;delete env.CARGO_ENCODED_RUSTFLAGS; function run(name,manifest,args,expected){const r=spawnSync('cargo',[...args.slice(0,1),'--manifest-path',manifest,'--offline','--locked',...args.slice(1)],{env,encoding:'utf8',timeout:600000,maxBuffer:16*1024*1024});writeFileSync(directory+'/'+name+'.log',(r.stdout??'')+(r.stderr??''));report.commands.push({name,exitCode:r.status,log:artifact(directory+'/'+name+'.log')});assert.ifError(r.error);assert.equal(r.status,expected,name);return r.stdout;} const tests=['test','--features','host-fixture','--test','wake']; try{assert.match(run('host-tests',source+'/os-smp-process-wake/Cargo.toml',tests,0),/33 passed; 0 failed/);run('target',source+'/os-smp-process-wake/Cargo.toml',['check','--lib','--target','aarch64-unknown-none'],0); const mutants=[ ['pid-generation','os-process-table/src/process_table.rs','e.generation != id.generation || ','','old_pid_cannot_wake_reused_slot'], ['pid-table','os-process-table/src/process_table.rs','if id.table != self.identity {','if false {','foreign_pid_and_bad_context_return_identical_token'], ['sleep-state','os-smp-process-wake/src/wake.rs','if before.state!=threads::State::Sleeping {return Err(Error::State)}','','ready_process_cannot_consume_another_wait'], ['ready-postcondition','os-smp-process-wake/src/wake.rs','expected.state=threads::State::Ready;','','actual_thread_is_readied_without_resource_change'], ['success-resources','os-smp-process-wake/src/wake.rs','||after!=Ok(expected)','','false_success_or_changed_ownership_quarantines'], ['success-context','os-smp-process-wake/src/wake.rs','!context_ok||','false||','false_success_or_changed_ownership_quarantines'], ['before-boundary','os-smp-process-wake/src/wake.rs','failure.boundary==Boundary::Before&&','','uncertain_error_retains_bag_and_token'], ['before-owner-state','os-smp-process-wake/src/wake.rs','&&after==Ok(before)','','uncertain_error_retains_bag_and_token'], ['quarantine-custody','os-smp-process-wake/src/wake.rs','self.entries[index].phase=Phase::Quarantined;','','uncertain_error_retains_bag_and_token'], ]; for(const[name,file,before,after,test]of mutants){const d=directory+'/mutant-'+name;cpSync(source,d,{recursive:true});const path=d+'/'+file,s=readFileSync(path,'utf8');assert.equal(s.split(before).length,name==='quarantine-custody'?3:2,name);writeFileSync(path,s.replaceAll(before,after));report.mutants.push(artifact(path));assert.match(run(name,d+'/os-smp-process-wake/Cargo.toml',[...tests,'os_smp_process_wake_'+test,'--','--exact'],101),/os_smp_process_wake_\w+ \.\.\. FAILED/);} report.status='PROCESS_WAKE_HOST_PREPARATION_PASSED';report.tests=33;report.newWakeTests=8;report.mutationsRejected=mutants.length; }catch(e){report.status='PROCESS_WAKE_HOST_PREPARATION_FAILED';report.error=e.stack;process.exitCode=1} writeFileSync(directory+'/report.json',JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify({status:report.status,report:directory+'/report.json',tests:report.tests,mutationsRejected:report.mutationsRejected,error:report.error}));