import assert from 'node:assert/strict'; import {nativeFaultFixture} from './native_fault_fixture.mjs'; import {checkNativeFault} from '../../scripts/os-acceptance/features/k2155-native-fault-check.mjs'; import {faultStageOrder} from '../../scripts/os-acceptance/features/k2155-native-fault-stages.mjs'; import {collectNativeFaultPhysical} from '../../scripts/os-acceptance/features/k2155-native-fault-capture.mjs'; const rejected=[];let positiveFixtures=0,collectorGates=0,physicalSpans=0; for(const id of [1,2,3,4,5])for(const first of [100,110])for(const tco of [0n,1n<<25n]){ const input=nativeFaultFixture(id,first,tco),result=checkNativeFault(input);assert.equal(result.cleanReceipt,false);assert.equal(result.case.id,id);positiveFixtures++; const plan={}; for(const s of input.snapshots){const stage=Number(s.OS_K2155_EVIDENCE.readBigUInt64LE(8)); await collectNativeFaultPhysical({stage,data:s,symbols:input.symbols,plan,take:async(name,address,size,mmio)=>{ assert.ok(Number.isSafeInteger(address)&&Number.isSafeInteger(size)&&size>0&&size<=65536); if(mmio)assert.ok(address>=0x8000000&&address+size<=0xa004000);else assert.ok(address>=0x40000000&&address+size<=0x50000000); assert.ok(s[name],name);assert.equal(s[name].length,size,name);physicalSpans++;return s[name]; }});collectorGates++; } const l=Array.from({length:24},(_,i)=>Number(input.compiled.OS_K1000_AUTHORITY_LAYOUT_EXPECTED.readBigUInt64LE(i*8))); for(const[name,key,offset]of [ ['wrong-case','OS_K2155_FAULT_STATE',8],['wrong-failure-phase','OS_K2155_FAULT_STATE',16],['wrong-failure-error','OS_K2155_FAULT_STATE',24], ['attempt-not-recorded','OS_K2155_FAULT_STATE',32],['false-clean-outcome','OS_K2155_FAULT_STATE',40],['fabricated-held-count','OS_K2155_FAULT_STATE',48], ['stale-observation-marked-current','OS_K2155_FAULT_STATE',56],['wrong-physical-free','OS_K2155_FAULT_STATE',88],['wrong-native-phase','OS_K2155_FAULT_STATE',96], ['changed-deadline','OS_K2155_FAULT_STATE',104],['wrong-release-attempt','OS_K2155_FAULT_STATE',112],['false-release','OS_K2155_FAULT_STATE',120], ['wrong-worker-liveness','OS_K2155_FAULT_STATE',128],['wrong-mask','OS_K2155_FAULT_STATE',136],['live-handler','OS_K2155_FAULT_STATE',144], ['retry-accepted','OS_K2155_FAULT_STATE',152],['retry-backend-access','OS_K2155_FAULT_STATE',168],['authorization-still-pending','OS_K2155_FAULT_STATE',176], ['authorization-reused','OS_K2155_FAULT_STATE',184],['user-roots-released','OS_K2155_FAULT_STATE',192],['unproved-refusal','OS_K2155_FAULT_STATE',200], ['wrong-interface-call-count','OS_K2155_FAULT_IO_CALLS',0],['clean-receipt-fabricated','OS_K2155_EVIDENCE',120],['wrong-retained-user-root','user-0-root',0], ['wrong-retained-dma-buffer','dma-1-0-3',0],['dma-lease-freed','authority',l[5]+23*l[6]+l[9]],['kernel-root-changed','OS_K2155_CPU_STATE',0], ['device-status-forged','mmio-0-status',0],['worker-stack-corrupted','stack-1',20472], ]){ const snapshots=input.snapshots.map(s=>({...s})),s=snapshots.at(-1);s[key]=Buffer.from(s[key]);s[key][offset]^=1; assert.throws(()=>checkNativeFault({...input,snapshots}),name);rejected.push(id+':'+first+':'+tco+':'+name); } if(id===3){const snapshots=input.snapshots.map(s=>({...s})),s=snapshots.at(-1);s['stack-0']=Buffer.from(s['stack-0']);s['stack-0'].writeBigUInt64LE(0x4b313032304c4f57n,4096);assert.throws(()=>checkNativeFault({...input,snapshots}),'canary-fault-not-present');rejected.push(id+':'+first+':'+tco+':canary-fault-not-present');} const traffic={...input.traffic,sent:[...input.traffic.sent,'00'.repeat(60)],sentCount:input.traffic.sentCount+1};assert.throws(()=>checkNativeFault({...input,traffic}),'unexpected-host-injection');rejected.push(id+':'+first+':'+tco+':unexpected-host-injection'); assert.throws(()=>faultStageOrder(input.snapshots.slice(0,-1).map(s=>Number(s.OS_K2155_EVIDENCE.readBigUInt64LE(8))),id),'missing-refusal-gate'); } console.log(JSON.stringify({status:'NATIVE_FAULT_HOST_TESTS_PASSED',syntheticFixture:true,positiveFixtures,cases:5,collectorGates,physicalSpans,rejected,guestAccepted:false,productAccepted:false,physicalFaultRetentionVerified:false}));