// K2101+ guest acceptance check: the 18-profile matrix (direct and UEFI, // 256/512/1024 MiB, 1/2/4 vCPUs) of one compiled candidate. Every file is // re-hashed, every boot DTB is re-read, the per-feature semantic checker is // run over the captured physical evidence and its forged controls must all be // rejected. This is development guest acceptance only, never product release. import assert from 'node:assert/strict'; import {copyFileSync,mkdtempSync,readFileSync,writeFileSync} from 'node:fs'; import {join,relative,resolve} from 'node:path'; import {spawnSync} from 'node:child_process'; import {pathToFileURL} from 'node:url'; import {hashAt,frozenSnapshot} from './boot-contract-report.mjs'; import {FEATURE_PROFILES} from './feature-guest-runner.mjs'; assert.equal(process.argv.length,6,'usage: node feature-matrix-check.mjs '); const root=process.cwd(),[specPath,candidatePath,matrixPath,localPath]=process.argv.slice(2).map(p=>relative(root,resolve(p))); const read=p=>JSON.parse(readFileSync(p,'utf8')),artifact=p=>({path:relative(root,p),sha256:hashAt(root,relative(root,p))}); const check=item=>{assert.equal(hashAt(root,item.path),item.sha256,item.path);return item;}; const spec=read(specPath),candidate=read(candidatePath),local=read(localPath),lifecycle=read(join(matrixPath,'scoped-lifecycle.json')),preflight=read(join(matrixPath,'preflight.json')); const n=Number(spec.milestone.slice(1)); assert.match(matrixPath,new RegExp(`^reports/os-implementation/${spec.milestone}-${spec.slug}-matrix-[A-Za-z0-9_-]+$`)); assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE');assert.equal(candidate.experiment,n); for(const item of[candidate.spec,candidate.harness,candidate.build.log,...Object.values(candidate.artifacts),...Object.values(candidate.sources)])check(item); assert.equal(local.status,`K${n-4}_K${n-1}_LOCAL_VALIDATED`);assert.deepEqual(local.candidate,artifact(join(root,candidatePath))); assert.equal(lifecycle.status,'RUNNER_PASSED');assert.equal(lifecycle.selection,'all');assert.equal(lifecycle.frozenStable,true); assert.deepEqual(lifecycle.candidate,artifact(join(root,candidatePath))); for(const item of[preflight.harness,preflight.fixtures.rng,preflight.fixtures.block,preflight.fixtures.journal,...preflight.firmware,...Object.values(preflight.bases),preflight.loader,preflight.loader.log])check(item); assert.equal(preflight.loader.imageSha256,candidate.artifacts.image.sha256,'UEFI loader is bound to this Image'); assert.equal(lifecycle.profiles.length,18);assert.deepEqual(lifecycle.profiles.map(p=>p.profile.id),FEATURE_PROFILES.map(p=>p.id)); const checker=await import(pathToFileURL(join(root,spec.integration.checker)).href); const fdtget=(...args)=>{const r=spawnSync('fdtget',args,{encoding:'utf8'});assert.equal(r.status,0,r.stderr);return r.stdout.trim();}; const cases=[],forged={rejected:0,total:0};let inherited=null; for(const result of lifecycle.profiles){ const {profile}=result,dir=join(matrixPath,profile.id); assert.equal(result.status,'GUEST_RETURNED');assert.deepEqual(read(join(dir,'result.json')),result,'lifecycle row equals the profile result file'); for(const item of[result.serial,result.dtb,...result.experimentStages.flatMap(s=>s.captures),...result.final])check(item); const command=read(join(dir,'qemu-command.json'));const argv=command.argv; assert.equal(argv[argv.indexOf('-smp')+1],String(profile.cpuCount));assert.equal(argv[argv.indexOf('-m')+1],String(profile.memoryMiB)); if(profile.route==='direct')assert.ok(argv.includes('-kernel')&&!argv.some(a=>a.startsWith('if=pflash')));else assert.ok(!argv.includes('-kernel')&&argv.some(a=>a.startsWith('if=pflash'))&&argv.includes('-boot')); const dtb=join(root,result.dtb.path); assert.equal(Number(fdtget('-t','u',dtb,'/chosen','turkos,feature-experiment')),n,'DTB selects this experiment'); assert.equal(Number(fdtget('-t','u',dtb,'/chosen','turkos,policy-probe-mode')),0,'product-control boot'); const cpus=fdtget('-l',dtb,'/cpus').split('\n').filter(x=>/^cpu@/.test(x));assert.equal(cpus.length,profile.cpuCount,'DTB CPU topology'); const memory=fdtget('-t','x',dtb,'/memory@40000000','reg').split(/\s+/).map(h=>BigInt('0x'+h)); assert.equal((memory[2]<<32n)|memory[3],BigInt(profile.memoryMiB)*1048576n,'DTB memory size'); const bootId=fdtget('-t','x',dtb,'/chosen','turkos,boot-id').split(/\s+/).map(h=>h.padStart(8,'0')).join('');assert.equal(bootId,result.bootId); const gates=result.gates.map(g=>g.milestone+':'+g.stage);inherited??=gates;assert.deepEqual(gates,inherited,'same inherited product-boot gates in every profile'); const input={stages:result.experimentStages.map(s=>({stage:s.stage,bytes:readFileSync(join(root,s.captures[0].path))})), final:readFileSync(join(root,result.final[0].path)),serial:readFileSync(join(root,result.serial.path),'latin1')}; const summary=checker.checkProfile(input),controls=checker.forgedControls(input); assert.equal(controls.rejected,controls.total,`forged evidence accepted in ${profile.id}: ${JSON.stringify(controls.survivors)}`); forged.rejected+=controls.rejected;forged.total+=controls.total; cases.push({profile,bootId:result.bootId,elapsedMs:result.elapsedMs,serial:result.serial,dtb:result.dtb,summary,forged:controls, stages:result.experimentStages.map(s=>({stage:s.stage,captures:s.captures})),final:result.final}); } const directory=mkdtempSync(join(root,`reports/os-implementation/${spec.milestone}-${spec.slug}-matrix-check-`)); copyFileSync(join(root,'scripts/os-acceptance/feature-matrix-check.mjs'),join(directory,'harness.mjs.txt')); const report={schema:'turkos-feature-matrix-check/v1',status:`${spec.milestone}_FEATURE_DEVELOPMENT_MATRIX_VALIDATED`,milestone:spec.milestone,feature:spec.feature, guestAccepted:true,productAccepted:false,independentReviewAccepted:false,spec:artifact(join(root,specPath)),candidate:artifact(join(root,candidatePath)), local:artifact(join(root,localPath)),matrix:artifact(join(root,matrixPath,'scoped-lifecycle.json')),preflight:artifact(join(root,matrixPath,'preflight.json')), checker:artifact(join(root,spec.integration.checker)),runner:preflight.harness,harness:artifact(join(directory,'harness.mjs.txt')), image:candidate.artifacts.image,imageSpan:candidate.imageSpan,base:candidate.base,inheritedGates:inherited,profiles:18,forgedControls:forged,cases, scope:spec.guestScope,frozenBefore:frozenSnapshot(root)}; report.frozenAfter=frozenSnapshot(root);assert.deepEqual(report.frozenAfter,report.frozenBefore); writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:relative(root,join(directory,'report.json')),profiles:cases.length,forged}));