import assert from 'node:assert/strict'; import {copyFileSync,mkdirSync,mkdtempSync,readdirSync,readFileSync,writeFileSync,cpSync} from 'node:fs'; import {dirname,join,relative} from 'node:path'; import {spawnSync} from 'node:child_process'; import {frozenSnapshot,hashAt} from './boot-contract-report.mjs'; const root=process.cwd(),directory=mkdtempSync(join(root,'reports/os-implementation/K1875-udp-buffering-staging-local-')); const before=frozenSnapshot(root),source=join(directory,'source'),sources=[]; const artifact=p=>({path:relative(root,p),sha256:hashAt(root,relative(root,p))}); const copy=path=>{const target=join(source,path);mkdirSync(dirname(target),{recursive:true});copyFileSync(join(root,path),target);sources.push(artifact(target));}; function tree(path){for(const entry of readdirSync(join(root,path),{withFileTypes:true})){const child=path+'/'+entry.name;if(entry.isDirectory())tree(child);else copy(child);}} for(const component of ['os-udp-buffering','os-udp-datagrams','os-udp-binding','os-ipv4-fragments','os-ipv4-packet','os-ethernet-frame']){copy(component+'/Cargo.toml');tree(component+'/src');} for(const path of ['os-udp-buffering/Cargo.lock','kernel/tests/os/udp_buffering.rs','kernel/UDP_BUFFERING_CONTRACT.md','scripts/os-acceptance/udp-buffering-prepare.mjs','scripts/os-acceptance/udp-buffering-source.mjs'])copy(path); const env={...process.env,CARGO_TARGET_DIR:join(directory,'target')};delete env.RUSTFLAGS;delete env.CARGO_ENCODED_RUSTFLAGS; const report={schema:'turkos-k1875-udp-buffering-staging/v1',status:'RUNNING',guestAccepted:false,productAccepted:false,sources,tests:{},frozenBefore:before,scope:'Fixed owned FIFO, whole datagram retention on short capacity, fourth-arrival drop accounting, zeroed consumed slots, and stale/foreign binding refusal. Host preparation only.'}; const run=(name,args,expected)=>{const result=spawnSync('cargo',args,{env,cwd:root,encoding:'utf8',timeout:600000,maxBuffer:64*1024*1024});const log=join(directory,name+'.log');writeFileSync(log,(result.stdout??'')+(result.stderr??''));report.tests[name]={exitCode:result.status,log:artifact(log)};assert.equal(result.error,undefined);assert.equal(result.signal,null);assert.equal(result.status,expected,name);return readFileSync(log,'utf8');}; try{ const manifest=join(source,'os-udp-buffering/Cargo.toml'); const green=run('host',['test','--manifest-path',manifest,'--offline','--locked','--test','udp_buffering'],0);assert.match(green,/2 passed; 0 failed/); run('aarch64',['check','--manifest-path',manifest,'--offline','--locked','--lib','--target','aarch64-unknown-none'],0); const mutant=join(directory,'mutant');cpSync(source,mutant,{recursive:true}); const model=join(mutant,'os-udp-buffering/src/buffering.rs'),text=readFileSync(model,'utf8'); const old='if capacity