// Joint acceptance of actual, completed matrices. Replays each raw physical // proof; no QEMU launch, inferred completion or product acceptance. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync} from 'node:fs'; import {dirname,join} from 'node:path'; import {spawnSync} from 'node:child_process'; import {createHash} from 'node:crypto'; import {frozenSnapshot} from './boot-contract-report.mjs'; import {requirements,checkAdmissionManifest} from './features/k2155-native-admission-manifest.mjs'; const [localPath]=process.argv.slice(2);assert.equal(process.argv.length,3); const read=p=>JSON.parse(readFileSync(p)),artifact=path=>({path,sha256:createHash('sha256').update(readFileSync(path)).digest('hex')}); const check=a=>{assert.equal(artifact(a.path).sha256,a.sha256,a.path);return read(a.path);}; const specPath='scripts/os-acceptance/features/k2155-native-admission.json',spec=read(specPath),local=read(localPath); assert.equal(spec.guestAdmissionEnabled,true);assert.equal(spec.acceptanceScope,'development-guest-only'); assert.equal(local.status,'K2151_K2154_LOCAL_VALIDATED');assert.equal(local.guestAccepted,false); const progress=read('reports/os-implementation/progress.json'); for(const id of ['K2151','K2152','K2153','K2154']){const move=progress.moves.find(m=>m.id===id);assert.equal(move.status,'LOCAL_VALIDATED');assert.deepEqual(move.evidence,artifact(localPath));} assert.equal(progress.moves.find(m=>m.id==='K2155').status,'PLANNED'); const directory=mkdtempSync('reports/os-implementation/K2155-shutdown-native-integration-matrix-check-'); const report={schema:'turkos-feature-matrix-check/v1',status:'K2155_NATIVE_REVIEW_RUNNING',milestone:'K2155',feature:spec.feature, guestAccepted:false,productAccepted:false,independentReviewAccepted:false,spec:artifact(specPath),local:artifact(localPath),reviews:[],commands:[],cases:[],frozenBefore:frozenSnapshot(process.cwd())}; function run(name,args){ const r=spawnSync('node',args,{encoding:'utf8',timeout:600000,maxBuffer:8*1024*1024}); const path=join(directory,name+'.log');writeFileSync(path,(r.stdout??'')+(r.stderr??''));report.commands.push({name,args,exitCode:r.status,log:artifact(path)}); assert.ifError(r.error);assert.equal(r.status,0,name);return JSON.parse(r.stdout.trim().split('\n').at(-1)); } function chosen(path,name){const r=spawnSync('fdtget',['-t','x',path,'/chosen',name],{encoding:'utf8',timeout:30000});assert.ifError(r.error);assert.equal(r.status,0,r.stderr);return r.stdout.trim().split(/\s+/).map(x=>BigInt('0x'+x));} try{ assert.deepEqual(report.frozenBefore,local.frozenAfter,'protected sources changed after local validation'); for(const ref of [local.candidate,local.faultCandidate]){const c=check(ref);assert.deepEqual(c.frozenAfter,report.frozenBefore);} const sourcePaths=['scripts/os-acceptance/k2155-native-admission.mjs',specPath,'scripts/os-acceptance/features/k2155-native-admission-manifest.mjs','tools/k2155_irq/test_native_admission_manifest.mjs']; report.sources=sourcePaths.map((p,i)=>{const out=join(directory,i+'-'+p.split('/').at(-1)+'.txt');copyFileSync(p,out);return artifact(out);});report.harness=report.sources[0]; const host=run('manifest-host-tests',['tools/k2155_irq/test_native_admission_manifest.mjs']);assert.equal(host.status,'NATIVE_ADMISSION_MANIFEST_HOST_TESTS_PASSED');assert.equal(host.rejected.length,47); const rows=[],bootIds=new Set();let rejected=0; for(const req of requirements){ const queuePath='reports/os-implementation/'+req.queue+'/report.json',queue=read(queuePath);assert.equal(queue.status,req.status,'prerequisite incomplete: '+req.name); for(const pin of queue.pins)assert.equal(artifact(pin.path).sha256,pin.sha256,pin.path); const candidate=check(queue.candidate),execution=check(queue.execution);assert.equal(execution.status,req.sequence);assert.deepEqual(execution.candidate,queue.candidate); if(req.name==='native-positive')assert.deepEqual(queue.candidate,local.candidate); if(req.name==='native-faults')assert.deepEqual(queue.candidate,local.faultCandidate); const proofs=[];assert.deepEqual(execution.steps.map(s=>s.name),['smoke-guest','smoke-proof','all-guest','all-proof']); for(const selection of ['smoke','all']){ const step=execution.steps.find(s=>s.name===selection+'-proof'),old=check(step.proof),life=check(old.lifecycle); assert.equal(old.status,req.proof);assert.equal(life.selection,selection);assert.deepEqual(life.candidate,queue.candidate); const matrix=dirname(old.lifecycle.path),replay=run(req.name+'-'+selection+'-replay',['scripts/os-acceptance/'+req.checker,matrix,queue.candidate.path]); assert.equal(replay.status,req.proof);const proof=read(replay.report);assert.equal(proof.status,old.status);assert.deepEqual(proof.candidate,queue.candidate); proofs.push({selection,proof}); report.reviews.push({name:req.name,selection,queue:artifact(queuePath),execution:queue.execution,previous:step.proof,replayed:artifact(replay.report)}); rejected+=(proof.negativeControls?.length??0)+proof.profiles.reduce((n,p)=>n+(p.negativeControls?.length??0),0); const preflight=check(proof.preflight); for(const a of [preflight.fixtures.rng,preflight.fixtures.block,preflight.fixtures.journal,...preflight.firmware,...Object.values(preflight.bases)])assert.equal(artifact(a.path).sha256,a.sha256,a.path); for(const row of life.profiles){ const result=check(proof.profiles.find(p=>p.profile.id===row.profile.id).result);assert.deepEqual(result,row); const {profile,bootId}=result;assert.match(bootId,/^[0-9a-f]{16}$/);assert.ok(!bootIds.has(bootId),'reused boot identity');bootIds.add(bootId); assert.equal(artifact(result.dtb.path).sha256,result.dtb.sha256); const get=(...args)=>{const r=spawnSync('fdtget',args,{encoding:'utf8',timeout:30000});assert.ifError(r.error);assert.equal(r.status,0,r.stderr);return r.stdout.trim();}; const cpus=get('-l',result.dtb.path,'/cpus').split('\n').filter(v=>/^cpu@/.test(v));assert.equal(cpus.length,profile.cpuCount); const memory=get('-t','x',result.dtb.path,'/memory@40000000','reg').split(/\s+/).map(v=>BigInt('0x'+v));assert.equal(memory.length,4); assert.deepEqual(memory,[0n,0x40000000n,0n,BigInt(profile.memoryMiB)*1048576n]); assert.deepEqual(chosen(result.dtb.path,'turkos,feature-experiment'),[2155n]);assert.deepEqual(chosen(result.dtb.path,'turkos,policy-probe-mode'),[0n]); assert.deepEqual(chosen(result.dtb.path,'turkos,boot-id'),[BigInt('0x'+bootId.slice(0,8)),BigInt('0x'+bootId.slice(8))]); const cmd=read(join(matrix,profile.id,'qemu-command.json'));assert.deepEqual(cmd.profile,profile);assert.equal(cmd.bootId,bootId);assert.equal(cmd.executable,'qemu-system-aarch64'); for(const [option,value]of [['-m',String(profile.memoryMiB)],['-smp',String(profile.cpuCount)],['-accel','hvf'],['-cpu','host']]){assert.equal(cmd.argv.filter(a=>a===option).length,1);assert.equal(cmd.argv[cmd.argv.indexOf(option)+1],value);} if(profile.route==='direct'){assert.equal(cmd.argv.filter(a=>a==='-kernel').length,1);assert.equal(cmd.argv[cmd.argv.indexOf('-kernel')+1],candidate.artifacts.image.path);assert.ok(!cmd.argv.some(a=>a.startsWith('if=pflash')));} else{assert.ok(!cmd.argv.includes('-kernel'));assert.ok(cmd.argv.some(a=>a.startsWith('if=pflash')));assert.equal(preflight.loader.imageSha256,candidate.artifacts.image.sha256);assert.equal(artifact(preflight.loader.path).sha256,preflight.loader.sha256);} if(req.name==='native-positive'&&selection==='all')report.cases.push({profile,bootId,serial:result.serial,dtb:result.dtb,summary:proof.profiles.find(p=>p.profile.id===profile.id).verified}); } } rows.push({name:req.name,queue,execution,proofs}); } report.coverage=checkAdmissionManifest(rows);assert.equal(bootIds.size,171); report.candidate=local.candidate;report.faultCandidate=local.faultCandidate;const candidate=check(local.candidate);report.image=candidate.artifacts.image;report.imageSpan=candidate.imageSpan;report.base=candidate.base; report.profiles=18;report.faultProfiles=90;report.componentProfiles=54;report.forgedControls={rejected,total:rejected};assert.ok(rejected>=1062); report.scope=spec.guestScope;report.frozenAfter=frozenSnapshot(process.cwd());assert.deepEqual(report.frozenAfter,report.frozenBefore); report.status='K2155_FEATURE_DEVELOPMENT_MATRIX_VALIDATED';report.guestAccepted=true; }catch(error){report.status='K2155_NATIVE_REVIEW_FAILED';report.error=String(error.stack??error);process.exitCode=1;} const path=join(directory,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify({status:report.status,report:path,guestAccepted:report.guestAccepted,productAccepted:false}));