import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync} from 'node:fs'; import {join,basename} from 'node:path'; import {createHash} from 'node:crypto'; import {fileURLToPath} from 'node:url'; import {frozenSnapshot} from './boot-contract-report.mjs'; import {buildOsPlan} from '../os-roadmap.mjs'; const [specPath,modelPath,adapterPath,sessionPath,userPath,candidatePath,controlsPath]=process.argv.slice(2); assert.equal(process.argv.length,9); const read=p=>JSON.parse(readFileSync(p)),artifact=path=>({path,sha256:createHash('sha256').update(readFileSync(path)).digest('hex')}); const verified=new Set(); function verify(value){if(!value||typeof value!=='object')return;if(value.path&&value.sha256){assert.equal(artifact(value.path).sha256,value.sha256,value.path);verified.add(value.path);}for(const v of Object.values(value))verify(v);} const spec=read(specPath),model=read(modelPath),adapter=read(adapterPath),session=read(sessionPath),user=read(userPath),candidate=read(candidatePath),controls=read(controlsPath); assert.equal(spec.milestone,'K2150');assert.equal(spec.slug,'shutdown-el0-storage'); assert.equal(model.status,'STAGING_LOCAL_PASSED');assert.equal(model.tests,4);assert.ok(model.mutationsRejected>=20); assert.equal(adapter.status,'STORAGE_FLUSH_ADAPTER_COMPONENT_PASSED');assert.equal(adapter.adapterTests,4);assert.equal(adapter.sourceMutantsRejected,9); assert.equal(session.status,'FLUSH_SESSION_COMPONENT_TESTS_PASSED');assert.equal(session.tests,4);assert.equal(session.mutants.length,7);assert.ok(session.mutants.every(x=>x.rejected)); assert.equal(controls.status,'EL0_STORAGE_CHECKER_HOST_CONTROLS_PASSED');assert.equal(controls.semanticForgeriesRejected,732);assert.equal(controls.guestExecuted,false); assert.equal(user.status,'USER_BUILD_PASSED');assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE'); assert.deepEqual(candidate.spec,artifact(specPath));assert.deepEqual(candidate.userBuild,artifact(userPath)); for(const report of [model,adapter,session,user,candidate])verify(report); assert.deepEqual(candidate.frozenBefore,candidate.frozenAfter);assert.deepEqual(frozenSnapshot(process.cwd()),candidate.frozenAfter); const bindings=[]; for(const runtime of spec.integration.runtime){ const tested=[...model.sources,...adapter.sources,...session.sources].filter(s=>s.path.includes('/src/')&&basename(s.path)===basename(runtime.from)); assert.ok(tested.length>0,'tested '+runtime.from); const integrated=candidate.sources['runtime/'+runtime.module+'.rs'];assert.ok(integrated); for(const source of tested)assert.equal(source.sha256,integrated.sha256,'byte-identical tested '+runtime.from); bindings.push({source:integrated,tested}); } const quiesce=artifact(join(candidate.sourceDirectory,'kernel/src/runtime/shutdown_io_quiesce.rs')); assert.equal(quiesce.sha256,session.sources.find(s=>s.path.endsWith('/src/quiesce.rs')).sha256); for(const p of user.programs)assert.equal(candidate.sources[p.name+'.bin'].sha256,p.image.sha256); const directory=mkdtempSync('reports/os-implementation/K2150-shutdown-el0-storage-local-'); copyFileSync(fileURLToPath(import.meta.url),join(directory,'harness.mjs.txt')); copyFileSync(spec.contract,join(directory,'contract.md')); const moves=buildOsPlan().moves.filter(m=>['K2146','K2147','K2148','K2149'].includes(m.id));assert.deepEqual(moves.map(m=>m.stage),['contract','implementation','positive','negative']); const report={schema:'turkos-feature-local/v1',status:'K2146_K2149_LOCAL_VALIDATED',milestone:'K2150',feature:'shutdown_io.flush',guestAccepted:false,productAccepted:false, scope:'Source-bound model, storage adapter and PID1 session host controls plus native EL0 and kernel compilation. All physical storage/EL0 profiles remain required.', moves:moves.map(m=>({id:m.id,stage:m.stage,title:m.title})),spec:artifact(specPath),candidate:artifact(candidatePath),userBuild:artifact(userPath), components:{model:artifact(modelPath),adapter:artifact(adapterPath),session:artifact(sessionPath)},checkerControls:artifact(controlsPath), sources:Object.fromEntries(bindings.map(b=>[b.source.path,b.source])),bindings,quiesce,contract:artifact(join(directory,'contract.md')), tests:{greenCount:12,mutationsRejected:36,semanticForgeriesRejected:732,model:artifact(modelPath),adapter:artifact(adapterPath),session:artifact(sessionPath)}, imageSpan:candidate.imageSpan,verifiedArtifacts:verified.size,harness:artifact(join(directory,'harness.mjs.txt')), frozenBefore:candidate.frozenBefore,frozenAfter:candidate.frozenAfter}; const path=join(directory,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:path,hostTests:12,sourceMutantsRejected:36,verifiedArtifacts:verified.size}));