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-sleep-staging-'),source=directory+'/source',report={status:'RUNNING',guestAccepted:false,productAccepted:false,sources:[],commands:[],mutants:[]};copyFileSync('/tmp/turkos-k2100-process-sleep-preparation.mjs',directory+'/harness.mjs.txt');report.harness=artifact(directory+'/harness.mjs.txt'); const meta=spawnSync('cargo',['metadata','--manifest-path','os-smp-process-sleep/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','os-smp-process-wake'])];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','sleep']; try{assert.match(run('host-tests',source+'/os-smp-process-sleep/Cargo.toml',tests,0),/40 passed; 0 failed/);run('target',source+'/os-smp-process-sleep/Cargo.toml',['check','--lib','--target','aarch64-unknown-none'],0); const mutants=[["bootstrap", "os-smp-process-sleep/src/sleep.rs", "if execution.kernel_bootstrap { return Err(Error::Context); }", "", "bootstrap_or_absent_current_never_enters_backend"], ["running-state", "os-smp-process-sleep/src/sleep.rs", "if before.state != threads::State::Running { return Err(Error::State); }", "", "ready_state_is_not_current_running_authority"], ["sleep-state", "os-smp-process-sleep/src/sleep.rs", "expected.state = threads::State::Sleeping;", "", "retains_real_wait_and_all_resource_owners"], ["departed-identity", "os-smp-process-sleep/src/sleep.rs", "departed.current = None;", "", "retains_real_wait_and_all_resource_owners"], ["success-context", "os-smp-process-sleep/src/sleep.rs", "context != departed || ", "", "uncertain_success_or_error_retains_actual_wait"], ["success-resource", "os-smp-process-sleep/src/sleep.rs", " || after != Ok(expected)", "", "uncertain_success_or_error_retains_actual_wait"], ["before-resources", "os-smp-process-sleep/src/sleep.rs", " && after == Ok(before)", "", "changed_before_error_quarantines_actual_bag"], ["before-context", "os-smp-process-sleep/src/sleep.rs", "context == execution && ", "", "changed_before_error_quarantines_actual_bag"], ["quarantine-custody", "os-smp-process-sleep/src/sleep.rs", "self.entries[index].phase = Phase::Quarantined;", "", "uncertain_success_or_error_retains_actual_wait"]]; 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-sleep/Cargo.toml',[...tests,'os_smp_process_sleep_'+test,'--','--exact'],101),/os_smp_process_sleep_\w+ \.\.\. FAILED/);} report.status='PROCESS_SLEEP_HOST_PREPARATION_PASSED';report.tests=40;report.newSleepTests=7;report.mutationsRejected=mutants.length; }catch(e){report.status='PROCESS_SLEEP_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}));