// Source-bound K2156–K2159 local validation only. No guest or product acceptance. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync,mkdirSync} from 'node:fs'; import {dirname,join} from 'node:path'; import {createHash} from 'node:crypto'; import {frozenSnapshot} from './boot-contract-report.mjs'; import {buildOsPlan} from '../os-roadmap.mjs'; const read=p=>JSON.parse(readFileSync(p,'utf8')),hash=b=>createHash('sha256').update(b).digest('hex'); const artifact=path=>({path,sha256:hash(readFileSync(path))}); function verify(value){ if(!value||typeof value!=='object')return; if(typeof value.path==='string'&&/^[a-f0-9]{64}$/.test(value.sha256??'')){ assert.equal(artifact(value.path).sha256,value.sha256,`hash mismatch: ${value.path}`); } for(const child of Object.values(value))verify(child); } const specPath='scripts/os-acceptance/features/k2160-native-local.json',spec=read(specPath); assert.equal(spec.acceptanceScope,'local-only');assert.equal(spec.guestAdmissionEnabled,false); const paths={ model:'reports/os-implementation/K2160-reopen-preparation-nkms8wa8/report.json', native:'reports/os-implementation/K2160-native-preparation-iwfqeukw/report.json', inputs:'reports/os-implementation/K2160-runner-input-preparation-d6lh8nxu/report.json', transition:'reports/os-implementation/K2160-disk-transition-host-qVxtt9/report.json', physicalControls:'reports/os-implementation/K2160-physical-checker-host-3myx1jvu/report.json', }; const preparations=Object.fromEntries(Object.entries(paths).map(([name,path])=>{ const r=read(path);verify(r);assert.equal(r.guestAccepted,false);assert.equal(r.productAccepted,false);return [name,r]; })); const {model,native,inputs,transition,physicalControls}=preparations; assert.equal(model.status,'REOPEN_HOST_PREPARATION_PASSED');assert.equal(model.mutants.length,12); assert.ok(model.mutants.every(m=>m.rejected===true)); assert.equal(native.status,'NATIVE_REOPEN_COMPILED_HOST_PREPARATION_PASSED'); assert.equal(inputs.status,'NATIVE_REOPEN_RUNNER_INPUTS_PREPARATION_PASSED'); assert.equal(inputs.fixtureSourceAgreementSeeds,5);assert.equal(inputs.hostReaderCases,25); assert.equal(inputs.malformedCaptureOrElfControlsRejected,46); assert.equal(transition.status,'HOST_DISK_TRANSITION_PREPARATION_PASSED'); assert.equal(transition.result.positiveCases,5);assert.equal(transition.result.negativeControls,11); assert.equal(physicalControls.status,'K2160_PHYSICAL_CHECKER_HOST_PREPARATION_PASSED'); assert.equal(physicalControls.hostControls.rejectedControls,24); const candidatePath='reports/os-implementation/K2160-shutdown-native-reopen-candidate-5zQLdQ/report.json'; const candidate=read(candidatePath);verify(candidate); assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE');assert.equal(candidate.slug,'shutdown-native-reopen'); assert.ok(candidate.imageSpan.bytes>0&&candidate.imageSpan.bytes<=8*1024*1024); assert.deepEqual(candidate.frozenBefore,candidate.frozenAfter); assert.deepEqual(candidate.frozenAfter,frozenSnapshot(process.cwd())); const testedModel=model.files.find(f=>f.path.endsWith('/os-shutdown-reopen/src/lib.rs'));assert.ok(testedModel); assert.equal(candidate.sources['runtime/shutdown_io_reopen.rs'].sha256,testedModel.sha256); for(const name of ['k2160-native.rs','k2160-disk.rs','k2160-request.rs','k2160-disk-policy.rs']){ const ref=native.files.find(f=>f.path.endsWith('/'+name));assert.ok(ref,name); assert.equal(candidate.sources[name].sha256,ref.sha256,name); } const user=read(candidate.userBuild.path);verify(user);assert.equal(user.status,'USER_BUILD_PASSED'); for(const p of user.programs)assert.equal(candidate.sources[p.name+'.bin'].sha256,p.image.sha256); const moves=buildOsPlan().moves.filter(m=>['K2156','K2157','K2158','K2159'].includes(m.id)); assert.deepEqual(moves.map(m=>m.stage),['contract','implementation','positive','negative']); assert.ok(moves.every(m=>m.feature===spec.feature)); const directory=mkdtempSync('reports/os-implementation/K2160-shutdown-native-reopen-local-'),files=[]; for(const path of [specPath,'scripts/os-acceptance/k2160-native-local.mjs',...spec.contracts]){ const dst=join(directory,'sources',path);mkdirSync(dirname(dst),{recursive:true});copyFileSync(path,dst);files.push(artifact(dst)); } for(const [name,path] of Object.entries(paths)){ const dst=join(directory,name+'-preparation.json');copyFileSync(path,dst);files.push(artifact(dst)); } const report={ schema:'turkos-feature-local/v1', status:'K2156_K2159_LOCAL_VALIDATED', milestone:'K2160', feature:spec.feature, guestAccepted:false, productAccepted:false, physicalTwoGuestReadbackVerified:false, moves:moves.map(m=>({id:m.id,stage:m.stage,title:m.title})), spec:artifact(specPath), candidate:artifact(candidatePath), userBuild:candidate.userBuild, preparations:Object.fromEntries(Object.entries(paths).map(([k,p])=>[k,artifact(p)])), harness:files.find(a=>a.path.endsWith('k2160-native-local.mjs')), sources:files, commands:[...model.commands,...native.commands], tests:{ reopenHostTests:14, requestHostTests:6, diskPolicyHostTests:5, sourceMutantsRejected:30, fixtureSourceAgreementSeeds:5, hostReaderCases:25, captureOrElfControlsRejected:46, diskTransitionControlsRejected:11, physicalCheckerControlsRejected:24, actualGuestProfiles:0, scope:'Source-bound host models, mutants, disk/capture controls and native candidate compilation; no guest admission.' }, imageSpan:candidate.imageSpan, frozenBefore:frozenSnapshot(process.cwd()), scope:spec.localScope, pending:['two-boot smoke matrix (1 writer + 5 readers)','full 18-profile two-boot hardware matrix (18 writers + 90 readers)','independent K2160 matrix check'] }; report.frozenAfter=frozenSnapshot(process.cwd());assert.deepEqual(report.frozenAfter,report.frozenBefore); const path=join(directory,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:path,guestAccepted:false}));