import assert from'node:assert/strict'; import{copyFileSync,cpSync,readdirSync,mkdirSync,mkdtempSync,readFileSync,writeFileSync}from'node:fs'; import{join,dirname,relative}from'node:path'; import{spawnSync}from'node:child_process'; import{hashAt,frozenSnapshot}from'./boot-contract-report.mjs'; const root=process.cwd(),directory=mkdtempSync('reports/os-implementation/K2065-tlb-shootdown-staging-local-'),source=join(directory,'source'),artifact=p=>({path:relative(root,p),sha256:hashAt(root,relative(root,p))}),report={schema:'turkos-k2065-tlb-shootdown-preparation/v1',status:'RUNNING',guestAccepted:false,productAccepted:false,sources:[],commands:[],mutants:[],frozenBefore:frozenSnapshot(root)}; function copy(path){const to=join(source,path);mkdirSync(dirname(to),{recursive:true});copyFileSync(path,to);report.sources.push(artifact(to));} function walk(path){for(const e of readdirSync(path,{withFileTypes:true})){const child=join(path,e.name);if(e.isDirectory())walk(child);else{assert.ok(e.isFile());copy(child);}}} copyFileSync('scripts/os-acceptance/tlb-shootdown-preparation.mjs',directory+'/harness.mjs.txt');report.harness=artifact(directory+'/harness.mjs.txt'); for(const p of['os-tlb-shootdown/Cargo.toml','os-tlb-shootdown/Cargo.lock','kernel/TLB_SHOOTDOWN_CONTRACT.md'])copy(p);walk('os-tlb-shootdown/src');walk('os-tlb-shootdown/tests'); const env={...process.env,CARGO_TARGET_DIR:join(root,directory,'target')};delete env.RUSTFLAGS;delete env.CARGO_ENCODED_RUSTFLAGS; function run(name,args,expected){const r=spawnSync('cargo',args,{cwd:root,env,encoding:'utf8',timeout:600000,maxBuffer:16*1024*1024}),log=join(directory,name+'.log');writeFileSync(log,(r.stdout??'')+(r.stderr??''));report.commands.push({name,args,exitCode:r.status,log:artifact(log)});assert.ifError(r.error);assert.equal(r.signal,null);assert.equal(r.status,expected,name);return readFileSync(log,'utf8');} try{ const manifest=join(source,'os-tlb-shootdown/Cargo.toml');assert.match(run('host-tests',['test','--manifest-path',manifest,'--locked','--offline','--test','shootdown'],0),/9 passed; 0 failed/);run('target',['check','--manifest-path',manifest,'--locked','--offline','--lib','--target','aarch64-unknown-none'],0); for(const[name,before,after,count]of[ ['target-binding','request.target!=self.binding||','',1], ['issuer','request.issuer!=self.issuer||','',1], ['request-va','request.va!=self.va||','',1], ['request-slot','request.slot!=self.slot','false',1], ['sequence','self.completed.checked_add(1)!=Some(request.sequence)','false',1], ['receiver-cpu','e.cpu!=self.binding.cpu||','',1], ['receiver-root','e.root!=self.root||','',1], ['receiver-mask','||!e.masked','',2], ['invalid-leaf','if hardware.descriptor(self.slot)!=0','if false',2], ['actual-invalidation','hardware.invalidate(self.va)?;','',1], ['coordinator-view','self.mapping.view()!=expected','false',1], ['source-context','e.cpu!=0||','',1], ['unique-completion','self.acknowledged&(1<