import assert from 'node:assert/strict'; import {copyFileSync,cpSync,existsSync,mkdirSync,mkdtempSync,readdirSync,readFileSync,writeFileSync} from 'node:fs'; import {spawnSync} from 'node:child_process'; import {dirname,join,relative,resolve} from 'node:path'; import {frozenSnapshot,hashAt} from './boot-contract-report.mjs'; assert.equal(process.argv.length,3); const root=process.cwd(),predecessorPath=resolve(process.argv[2]),predecessor=JSON.parse(readFileSync(predecessorPath)); assert.equal(predecessor.status,'K1845_IPV4_PACKET_DEVELOPMENT_MATRIX_VALIDATED');assert.equal(predecessor.guestAccepted,true);assert.equal(predecessor.cases.length,6); const frozenBefore=frozenSnapshot(root),directory=mkdtempSync(join(root,'reports/os-implementation/K1850-ipv4-routing-local-')),source=join(directory,'source'); const artifact=path=>({path:relative(root,path),sha256:hashAt(root,relative(root,path))}); const copy=(path,target=join(source,path))=>{mkdirSync(dirname(target),{recursive:true});copyFileSync(join(root,path),target);return artifact(target);}; const sources={}; for(const[key,path]of Object.entries({offloadsModel:'reports/os-implementation/K1850-ipv4-routing-work-sources/kernel/src/runtime/net_offloads.rs',ethernetModel:'reports/os-implementation/K1850-ipv4-routing-work-sources/kernel/src/runtime/ethernet_frame.rs',model:'os-ipv4-routing/src/routing.rs',runtimeModel:'reports/os-implementation/K1850-ipv4-routing-work-sources/kernel/src/runtime/ipv4_routing.rs',rxModel:'reports/os-implementation/K1850-ipv4-routing-work-sources/kernel/src/runtime/net_rx_pool.rs',metadata:'os-frame-metadata/src/metadata.rs',runtimeMetadata:'reports/os-implementation/K1850-ipv4-routing-work-sources/kernel/src/runtime/frame_metadata.rs', routeUserBuild:'reports/os-implementation/K1850-ipv4-routing-user-build-ZYkmcM/report.json',routeUserSource:'scripts/os-acceptance/k1850-routing-user.S',routeUserBuilder:'scripts/os-acceptance/ipv4-routing-user-build.mjs',routeUserElf:'reports/os-implementation/K1850-ipv4-routing-work-sources/kernel/src/k1850-user.elf',fixture:'kernel/tests/os/ipv4_routing.rs',contract:'kernel/IPV4_ROUTING_CONTRACT.md',manifest:'os-ipv4-routing/Cargo.toml',lock:'os-ipv4-routing/Cargo.lock',noStdRoot:'os-ipv4-routing/src/lib.rs', capture:'scripts/os-acceptance/ipv4-routing-capture.mjs',proof:'scripts/os-acceptance/ipv4-routing-proof.mjs',proofTest:'scripts/os-acceptance/test-ipv4-routing-proof.mjs',physicalFixture:'kernel/tests/os/fixtures/ipv4-routing-physical-v1.bin',fixtureBuilder:'scripts/os-acceptance/ipv4-routing-physical-fixture.mjs',physicalProof:'scripts/os-acceptance/physical-checkpoint-proof.mjs',dmaNetwork:'scripts/os-acceptance/dma-network.mjs',diskFixture:'scripts/os-acceptance/file-map-disk.mjs'}))sources[key]=copy(path); sources.harness=artifact(join(root,'scripts/os-acceptance/ipv4-routing-local.mjs')); const librarySources=[],work=join(root,'reports/os-implementation/K1850-ipv4-routing-work-sources'); for(const component of readdirSync(work).filter(name=>!['bootloader','userspace'].includes(name)&&existsSync(join(work,name,'Cargo.toml')))){ cpSync(join(work,component,'src'),join(source,component,'src'),{recursive:true});copyFileSync(join(work,component,'Cargo.toml'),join(source,component,'Cargo.toml'));librarySources.push({source:component+'/Cargo.toml',...artifact(join(source,component,'Cargo.toml'))}); function walk(path){for(const entry of readdirSync(path,{withFileTypes:true})){const child=join(path,entry.name);if(entry.isDirectory())walk(child);else librarySources.push({source:relative(source,child),...artifact(child)});}}walk(join(source,component,'src')); } assert.equal(sources.runtimeModel.sha256,artifact(join(source,'kernel/src/runtime/ipv4_routing.rs')).sha256); assert.equal(readFileSync(join(root,sources.model.path),'utf8'),readFileSync(join(root,sources.runtimeModel.path),'utf8')); assert.equal(sources.runtimeMetadata.sha256,artifact(join(source,'kernel/src/runtime/frame_metadata.rs')).sha256); assert.ok(readFileSync(join(root,sources.runtimeMetadata.path),'utf8').startsWith(readFileSync(join(root,sources.metadata.path),'utf8'))); const priorCandidate=JSON.parse(readFileSync(join(root,predecessor.candidate.path)));assert.equal(hashAt(root,priorCandidate.sourceDirectory+'/kernel/src/runtime/frame_metadata.rs'),sources.runtimeMetadata.sha256);assert.equal(hashAt(root,priorCandidate.sourceDirectory+'/kernel/src/runtime/net_rx_pool.rs'),sources.rxModel.sha256); assert.equal(hashAt(root,priorCandidate.sourceDirectory+'/kernel/src/runtime/net_offloads.rs'),sources.offloadsModel.sha256);assert.equal(hashAt(root,priorCandidate.sourceDirectory+'/kernel/src/runtime/ethernet_frame.rs'),sources.ethernetModel.sha256); for(const component of ['os-frame-metadata','os-ethernet-frame']){sources['host_'+component+'_manifest']=copy(component+'/Cargo.toml');function hostTree(path){for(const entry of readdirSync(join(root,path),{withFileTypes:true})){const child=path+'/'+entry.name;if(entry.isDirectory())hostTree(child);else sources['host_'+child]=copy(child);}}hostTree(component+'/src');} const env={...process.env,CARGO_TARGET_DIR:join(directory,'target')};delete env.RUSTFLAGS;delete env.CARGO_ENCODED_RUSTFLAGS; const run=(name,args,expected,executable='cargo')=>{const r=spawnSync(executable,args,{cwd:root,env,encoding:'utf8',timeout:600000,maxBuffer:64*1024*1024});const log=join(directory,name+'.log');writeFileSync(log,(r.stdout??'')+(r.stderr??''));assert.equal(r.error,undefined);assert.equal(r.signal,null);assert.equal(r.status,expected,artifact(log).path);return{exitCode:r.status,log:artifact(log)};}; const manifest=join(source,'os-ipv4-routing/Cargo.toml'); const tests={green:run('host-tests',['test','--manifest-path',manifest,'--locked','--offline','--test','routing'],0),target:run('aarch64-kernel-check',['check','--manifest-path',join(source,'kernel/Cargo.toml'),'--offline','--bin','turkos-kernel','--target','aarch64-unknown-none','--no-default-features','--features','os-runtime-product'],0),proof:run('proof-tests',[join(source,'scripts/os-acceptance/test-ipv4-routing-proof.mjs')],0,process.execPath)}; const proof=JSON.parse(readFileSync(join(directory,'proof-tests.log')));assert.equal(proof.status,'IPV4_ROUTING_PROOF_TESTS_PASSED');assert.equal(proof.positive,1);assert.ok(proof.forgedControlsRejected>=60); const green=readFileSync(join(directory,'host-tests.log'),'utf8');for(const n of ['positive','negative'])assert.match(green,new RegExp('os_ipv4_routing_'+n+' \\.\\.\\. ok'));assert.match(green,/2 passed; 0 failed/); const mutantRoot=join(directory,'mutant');cpSync(source,mutantRoot,{recursive:true});const mutantModel=join(mutantRoot,'os-ipv4-routing/src/routing.rs'),model=readFileSync(mutantModel,'utf8'),guard='entry.prefix>u64::from(s.prefix)';assert.equal(model.split(guard).length,2);writeFileSync(mutantModel,model.replace(guard,'entry.prefix