// Source-bound local milestones only. No guest, product or milestone K2155 admission. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync,mkdirSync} from 'node:fs'; import {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)),hash=b=>createHash('sha256').update(b).digest('hex'),artifact=path=>({path,sha256:hash(readFileSync(path))}); const historicalRecoveries=[]; function verify(value,archives=[]){ if(!value||typeof value!=='object')return; if(typeof value.path==='string'&&/^[a-f0-9]{64}$/.test(value.sha256??'')&&artifact(value.path).sha256!==value.sha256){ const saved=archives.find(a=>a.sha256===value.sha256&&a.path.startsWith('reports/os-implementation/')&&artifact(a.path).sha256===value.sha256); assert.ok(saved,'hash mismatch without immutable archive: '+value.path);historicalRecoveries.push({originalPath:value.path,archived:saved}); } for(const child of Object.values(value))verify(child,archives); } const specPath='scripts/os-acceptance/features/k2155-native-local.json',spec=read(specPath); assert.equal(spec.acceptanceScope,'local-only');assert.equal(spec.guestAdmissionEnabled,false); const paths={adapter:'reports/os-implementation/K2155-lease-io-preparation-7s7xz6v0/report.json', authorization:'reports/os-implementation/K2155-native-integration-preparation-26rfmp89/report.json', positive:'reports/os-implementation/K2155-native-positive-preparation-m3tmg09v/report.json', faults:'reports/os-implementation/K2155-native-fault-preparation-_td8gurs/report.json'}; const preparations=Object.fromEntries(Object.entries(paths).map(([name,path])=>{const r=read(path);verify(r,name==='authorization'?r.files:[]);assert.equal(r.guestAccepted,false);assert.equal(r.productAccepted,false);return [name,r];})); const {adapter,authorization,positive,faults}=preparations; assert.equal(adapter.status,'DRIVER_DRAIN_ADAPTER_COMPONENT_PASSED');assert.equal(adapter.hostTests,10);assert.equal(adapter.sourceMutantsRejected,17); assert.equal(adapter.deviceFailureSchedules,26);assert.equal(adapter.identityReadbackCases,35); assert.equal(authorization.status,'NATIVE_INTEGRATION_COMPILED_HOST_CHECKED');assert.equal(authorization.hostTests,7);assert.equal(authorization.sourceMutantsRejected,10); for(const r of [adapter,authorization]){ assert.equal(r.mutants.length,r.sourceMutantsRejected);assert.ok(r.mutants.every(m=>m.rejected===true)); assert.equal(r.commands.find(c=>c.name==='host-tests').exitCode,0); for(const m of r.mutants){ const compile=r.commands.find(c=>c.name===m.name+'-compile'),test=r.commands.find(c=>[m.name+'-test',m.name+'-tests'].includes(c.name)); assert.ok(compile&&test);assert.equal(compile.exitCode,0);assert.equal(test.exitCode,101,'mutant must compile and fail its tests'); } } assert.equal(positive.status,'NATIVE_POSITIVE_EXECUTION_PREPARATION_PASSED');assert.equal(positive.syntheticCorruptionsRejected,482);assert.equal(positive.jointPositiveFixtures,4); assert.equal(faults.status,'NATIVE_FAULT_EXECUTION_PREPARATION_PASSED');assert.equal(faults.physicalCheckerHostTests.positiveFixtures,20); assert.equal(faults.physicalCheckerHostTests.rejected.length,604);assert.equal(faults.identityHostTests.rejected.length,55); for(const r of [positive,faults]){assert.equal(r.frozenStable,true);assert.ok(r.commands.every(c=>c.exitCode===0));assert.deepEqual(r.reusedAuthorizationTests,artifact(paths.authorization));} const candidate=read(positive.candidate.path),faultCandidate=read(faults.candidate.path);verify(candidate);verify(faultCandidate); const testedAdapter=adapter.sources.find(a=>a.path.endsWith('/src/lease_io.rs'));assert.ok(testedAdapter); const testedRequest=authorization.inputs.find(a=>a.path==='scripts/os-acceptance/features/k2155-shutdown-request.rs');assert.ok(testedRequest); for(const c of [candidate,faultCandidate]){ assert.equal(c.status,'COMPILED_FEATURE_CANDIDATE');assert.ok(c.imageSpan.bytes>0&&c.imageSpan.bytes<=8*1024*1024); assert.deepEqual(c.frozenBefore,c.frozenAfter);assert.deepEqual(c.frozenAfter,frozenSnapshot(process.cwd())); assert.equal(c.sources['runtime/shutdown_io_lease_io.rs'].sha256,testedAdapter.sha256); assert.equal(c.sources['k2155-shutdown-request.rs'].sha256,testedRequest.sha256); const user=read(c.userBuild.path);verify(user);assert.equal(user.status,'USER_BUILD_PASSED'); for(const p of user.programs)assert.equal(c.sources[p.name+'.bin'].sha256,p.image.sha256); } assert.equal(candidate.slug,'shutdown-native-integrated');assert.equal(faultCandidate.slug,'shutdown-native-faults'); for(const name of ['k2155-dma-reset.rs','k2155-virtio-drain.rs','k2155-gic-spi.rs','k2155-irq-native.rs','k2155-workers.rs','k2155-shutdown-request.rs','k2155-native-driver.bin','k2155-native-pid1.bin'])assert.equal(candidate.sources[name].sha256,faultCandidate.sources[name].sha256); const moves=buildOsPlan().moves.filter(m=>['K2151','K2152','K2153','K2154'].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/K2155-shutdown-native-integration-local-'),files=[]; for(const path of [specPath,'scripts/os-acceptance/k2155-native-local.mjs',...spec.contracts]){ const dst=join(directory,'sources',path);mkdirSync(dst.slice(0,dst.lastIndexOf('/')),{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 failedLog=join(directory,'historical-input-verification-failure.log');copyFileSync('/tmp/turkos-k2155-native-local-historical-input-failure.log',failedLog);files.push(artifact(failedLog)); const report={schema:'turkos-feature-local/v1',status:'K2151_K2154_LOCAL_VALIDATED',milestone:'K2155',feature:spec.feature, guestAccepted:false,productAccepted:false,physicalIntegratedShutdownVerified:false,physicalFaultRetentionVerified:false, moves:moves.map(m=>({id:m.id,stage:m.stage,title:m.title})),spec:artifact(specPath),candidate:positive.candidate,faultCandidate:faults.candidate, preparations:Object.fromEntries(Object.entries(paths).map(([k,p])=>[k,artifact(p)])),harness:files.find(a=>a.path.endsWith('k2155-native-local.mjs')), sources:files,historicalRecoveries,commands:[...adapter.commands,...authorization.commands,...positive.commands,...faults.commands], tests:{adapterHostTests:10,authorizationHostTests:7,sourceMutantsRejected:27,deviceFailureSchedules:26,identityReadbackCases:35, jointPositiveFixtures:4,faultPositiveFixtures:20,positiveSnapshotRejections:482,faultSnapshotRejections:604,metadataRejections:55, actualGuestProfiles:0,scope:'Source-bound host fixtures and native compilation; no guest admission.'}, imageSpan:candidate.imageSpan,faultImageSpan:faultCandidate.imageSpan,frozenBefore:frozenSnapshot(process.cwd()),scope:spec.localScope, pending:['standalone worker/DMA/IRQ-DMA physical matrices','integrated positive smoke and 18 profiles','five fault smoke cases and 90 profiles','joint K2155 admission review']}; 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}));