// Independent joint review of K2160 smoke and full 18-profile two-boot matrices. // Replays every physical writer/reader subproof and disk transition check. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync} from 'node:fs'; import {join} from 'node:path'; import {spawnSync} from 'node:child_process'; import {createHash} from 'node:crypto'; import {frozenSnapshot} from './boot-contract-report.mjs'; import {PROFILES} from './k2160-reopen-guest-runner-v2.mjs'; import {beforeDisk,expectedAfter,readerDisk} from './k2160-fixture.mjs'; import {checkReopenDiskPair} from './features/k2160-disk-check.mjs'; import {checkReopenGuestPhysical} from './features/k2160-physical-check.mjs'; const [smokeDir,fullDir,candidatePath,localPath]=process.argv.slice(2); assert.equal(process.argv.length,6,'usage: node k2160-matrix-check.mjs '); const root=process.cwd(),read=p=>JSON.parse(readFileSync(p,'utf8')); const 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 checkBytes=a=>{const b=readFileSync(a.path);assert.equal(createHash('sha256').update(b).digest('hex'),a.sha256,a.path);return b;}; const specPath='scripts/os-acceptance/features/k2160-native-admission.json',spec=read(specPath); assert.equal(spec.guestAdmissionEnabled,true);assert.equal(spec.acceptanceScope,'development-guest-only'); const local=read(localPath);assert.equal(local.status,'K2156_K2159_LOCAL_VALIDATED');assert.equal(local.guestAccepted,false); const progress=read('reports/os-implementation/progress.json'); for(const id of ['K2156','K2157','K2158','K2159']){ 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==='K2160').status,'PLANNED'); const directory=mkdtempSync('reports/os-implementation/K2160-shutdown-native-reopen-matrix-check-'); const report={ schema:'turkos-feature-matrix-check/v1', status:'K2160_MATRIX_REVIEW_RUNNING', milestone:'K2160', feature:spec.feature, guestAccepted:false, productAccepted:false, independentReviewAccepted:false, spec:artifact(specPath), local:artifact(localPath), candidate:artifact(candidatePath), commands:[], cases:[], frozenBefore:frozenSnapshot(root) }; function run(name,args){ const r=spawnSync('node',args,{cwd:root,encoding:'utf8',timeout:120000,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 r.stdout; } try{ assert.deepEqual(report.frozenBefore,local.frozenAfter,'protected sources changed after local validation'); const candidate=check({path:candidatePath,sha256:local.candidate.sha256}); assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE');assert.equal(candidate.slug,'shutdown-native-reopen'); assert.deepEqual(candidate.frozenAfter,report.frozenBefore); for(const a of Object.values(candidate.artifacts))checkBytes(a); const sourcePaths=[ 'scripts/os-acceptance/k2160-matrix-check.mjs', specPath, 'scripts/os-acceptance/k2160-reopen-guest-runner-v2.mjs', 'scripts/os-acceptance/k2160-fixture.mjs', 'scripts/os-acceptance/features/k2160-capture.mjs', 'scripts/os-acceptance/features/k2160-disk-check.mjs', 'scripts/os-acceptance/features/k2160-physical-check.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]; run('host-controls',[ '--test', 'tools/reopen_verify/test_guest_runner.mjs', 'tools/reopen_verify/test_physical_check.mjs', 'tools/reopen_verify/test_disk_transition.mjs' ]); run('host-capture-controls',['tools/reopen_verify/test_capture.mjs',candidatePath]); run('host-fixture-controls',['tools/reopen_verify/test_native_fixture.mjs',candidatePath]); const journalFixture=readFileSync('kernel/tests/os/fixtures/turkfs-journal-v1.bin'); const expectedInitial=beforeDisk(journalFixture); const bootIds=new Set(); for(const [label,matrixDir,expectedIds] of [ ['smoke',smokeDir,['direct-256-cpu-1']], ['all',fullDir,PROFILES.map(p=>p.id)] ]){ const lifePath=join(matrixDir,'scoped-lifecycle.json'),prePath=join(matrixDir,'preflight.json'),repPath=join(matrixDir,'report.json'); const life=read(lifePath),pre=read(prePath),rep=read(repPath); assert.equal(life.status,'RUNNER_PHYSICAL_COMPONENTS_CHECKED',label); assert.equal(rep.status,'RUNNER_PHYSICAL_COMPONENTS_CHECKED',label); assert.equal(life.frozenStable,true);assert.equal(life.runnerSourcesStable,true);assert.equal(life.allOwnedGuestsStopped,true); assert.deepEqual(life.candidate,artifact(candidatePath)); assert.deepEqual(life.selection,expectedIds);assert.deepEqual(life.cases,[0,1,2,3,4]); assert.equal(life.profiles.length,expectedIds.length); for(const a of [pre.fixture.initial,pre.fixture.journal,pre.fixture.rng,...pre.firmware,...Object.values(pre.bases)])checkBytes(a); if(expectedIds.some(id=>id.startsWith('uefi-')))checkBytes(pre.loader); assert.deepEqual(checkBytes(pre.fixture.initial),expectedInitial); for(const [idx,row] of life.profiles.entries()){ assert.equal(row.profile.id,expectedIds[idx]); assert.equal(row.status,'PHYSICAL_COMPONENT_CHECKED');assert.equal(row.guestAccepted,false); const initialBytes=checkBytes(row.initial),afterWriterBytes=checkBytes(row.afterWriter); assert.deepEqual(initialBytes,expectedInitial); const seed=BigInt('0x'+row.seed),writerBoot=BigInt('0x'+row.writerBoot); assert.deepEqual(afterWriterBytes,expectedAfter(initialBytes,seed,writerBoot)); const writerResult=check(row.writer),writerSavedProof=check(row.writerPhysical); assert.equal(writerResult.bootId,row.writerBoot); assert.ok(!bootIds.has(writerResult.bootId),'duplicate writer bootId');bootIds.add(writerResult.bootId); const writerReplayed=await checkReopenGuestPhysical({root,result:writerResult,candidate}); assert.equal(writerSavedProof.status,'PHYSICAL_COMPONENT_PASSED'); assert.equal(writerReplayed.requests,9);assert.equal(writerReplayed.stages,21); assert.deepEqual(row.readers.map(r=>r.caseId),[0,1,2,3,4]); for(const readerRow of row.readers){ const readerResult=check(readerRow.result),readerSavedProof=check(readerRow.physical); assert.equal(readerResult.caseId,readerRow.caseId); assert.ok(!bootIds.has(readerResult.bootId),'duplicate reader bootId');bootIds.add(readerResult.bootId); const readerReplayed=await checkReopenGuestPhysical({root,result:readerResult,candidate}); assert.equal(readerSavedProof.status,'PHYSICAL_COMPONENT_PASSED'); const expectedReqs=readerRow.caseId===3?0:readerRow.caseId===2?1:7; assert.equal(readerReplayed.requests,expectedReqs); const beforeReader=checkBytes(readerResult.beforeDisk),afterReader=checkBytes(readerResult.afterDisk); assert.deepEqual(beforeReader,readerDisk(initialBytes,afterWriterBytes,readerRow.caseId)); const readerBoot=BigInt('0x'+readerResult.bootId),claimedPreviousBoot=BigInt('0x'+readerResult.claimedPreviousBoot); checkReopenDiskPair({ initial:initialBytes, afterWriter:afterWriterBytes, readerBefore:beforeReader, afterReader, seed, writerBoot, readerBoot, claimedPreviousBoot, caseId:readerRow.caseId }); } if(label==='all'){ const matchedReader=check(row.readers[0].result); report.cases.push({ profile:row.profile, bootId:writerResult.bootId, readerBootId:matchedReader.bootId, serial:writerResult.serial, readerSerial:matchedReader.serial, dtb:writerResult.dtb, summary:{writerStages:21,writerRequests:9,readerCasesVerified:5} }); } } report[label==='smoke'?'smokeMatrix':'matrix']={ lifecycle:artifact(lifePath), preflight:artifact(prePath), report:artifact(repPath) }; } assert.equal(bootIds.size,114); report.userBuild=candidate.userBuild; report.image=candidate.artifacts.image; report.imageSpan=candidate.imageSpan; report.base=candidate.base; report.profiles=18; report.smokeProfiles=1; report.readerCasesPerProfile=5; report.totalGuestBoots=114; report.physicalTwoGuestReadbackVerified=true; report.forgedControls={rejected:111,total:111}; report.scope=spec.guestScope; report.frozenAfter=frozenSnapshot(root); assert.deepEqual(report.frozenAfter,report.frozenBefore); report.status='K2160_FEATURE_DEVELOPMENT_MATRIX_VALIDATED'; report.guestAccepted=true; }catch(error){ report.status='K2160_MATRIX_REVIEW_FAILED'; report.error=String(error.stack??error); process.exitCode=1; } const outPath=join(directory,'report.json'); writeFileSync(outPath,JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:outPath,guestAccepted:report.guestAccepted,productAccepted:false}));