import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync,mkdirSync} from 'node:fs'; import {spawnSync} from 'node:child_process'; import {join} from 'node:path'; import {sourceBytes,inodeBytes,journalBytes,beforeDisk,expectedAfter,readerDisk,LOGICAL_BYTES,CASES,sha256} from '../../scripts/os-acceptance/k2160-fixture.mjs'; const [candidatePath]=process.argv.slice(2);assert.equal(process.argv.length,3); const read=p=>JSON.parse(readFileSync(p)),art=path=>({path,sha256:sha256(readFileSync(path))}); const candidate=read(candidatePath);assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE'); const probe=candidate.sources['k2160-native.rs'];assert.deepEqual(art(probe.path),probe); const text=readFileSync(probe.path,'utf8'),out=mkdtempSync('reports/os-implementation/K2160-native-fixture-check-'); const files=[],commands=[]; const report={status:'NATIVE_FIXTURE_HOST_RUNNING',guestAccepted:false,productAccepted:false,candidate:art(candidatePath),probe,files,commands}; function run(name,command,args,expected=0){ const r=spawnSync(command,args,{encoding:'utf8',timeout:30000,maxBuffer:4*1024*1024}),path=join(out,name+'.log'); writeFileSync(path,(r.stdout??'')+(r.stderr??''));files.push(art(path));commands.push({name,command,args,exitCode:r.status,log:art(path)}); assert.ifError(r.error);assert.equal(r.status,expected,name);return r.stdout; } try{ const functions=[]; // These four pure function bodies are copied verbatim from the compiled // candidate's archived source, then run on the host. This is source-level // payload agreement, not execution of AArch64 instructions or a disk device. for(const name of ['put64','put32','source','metadata']){ const start=text.indexOf('fn '+name+'(');assert.ok(start>=0);let at=text.indexOf('{',start),depth=1;assert.ok(at>start); const opening=at;while(depth){at++;assert.ok(atf.bytes).join('\n')+` fn hex(b:&[u8])->String{b.iter().map(|v|format!("{v:02x}")).collect()} fn main(){let args:Vec=std::env::args().collect();let seed=u64::from_str_radix(&args[1],16).unwrap();println!("{}",hex(&source(seed)));println!("{}",hex(&metadata()));} `);files.push(art(exported));report.functionRanges=functions.map(({bytes,...f})=>f); const binary=join(out,'payload-export');run('compile-payload-export','rustc',['--edition=2024',exported,'-o',binary]); const reader='reports/os-implementation/K2160-reopen-preparation-nkms8wa8/reopen-host-reader';report.hostReader=art(reader); const fixture=readFileSync('kernel/tests/os/fixtures/turkfs-journal-v1.bin');report.journalFixture=art('kernel/tests/os/fixtures/turkfs-journal-v1.bin'); const seeds=[1n,0x0123456789abcdefn,0x8000000000000000n,0xffffffffffffffffn,0x2160000112345678n]; report.cases=[]; for(const [index,seed]of seeds.entries()){ const bytes=sourceBytes(seed),lines=run('payload-'+index,binary,[seed.toString(16)]).trim().split('\n');assert.equal(lines.length,2); assert.deepEqual(Buffer.from(lines[0],'hex'),bytes);assert.deepEqual(Buffer.from(lines[1],'hex'),inodeBytes()); assert.ok(bytes.subarray(LOGICAL_BYTES).equals(Buffer.alloc(511,0xe7))); const boot=0x2160000100000000n+BigInt(index),before=beforeDisk(fixture),original=Buffer.from(before),after=expectedAfter(before,seed,boot); assert.deepEqual(before,original);assert.notEqual(sha256(before),sha256(after));assert.throws(()=>expectedAfter(after,seed,boot)); const changed=[];for(let lba=0;lba<2048;lba++)if(!before.subarray(lba*512,lba*512+512).equals(after.subarray(lba*512,lba*512+512)))changed.push(lba); assert.deepEqual(changed,[18,120,128,129,130,131]); assert.deepEqual(after.subarray(30*512,33*512),before.subarray(30*512,33*512)); assert.deepEqual(after.subarray(111*512,112*512),before.subarray(111*512,112*512)); const journal=journalBytes(seed,boot);assert.equal(journal.subarray(0,8).toString(),'K2160FS1');assert.equal(journal.readBigUInt64LE(8),seed);assert.equal(journal.readBigUInt64LE(16),boot); const digest=sha256(bytes.subarray(0,LOGICAL_BYTES));assert.equal(journal.subarray(24,56).toString('hex'),digest); const d=join(out,'seed-'+index);mkdirSync(d);const source=join(d,'source.bin');writeFileSync(source,bytes.subarray(0,LOGICAL_BYTES)); for(const c of CASES){ const disk=join(d,c.name+'.img'),input=readerDisk(before,after,c.id);writeFileSync(disk,input); const args=[disk,source,'persisted.txt',String(boot),String(c.id===3?boot:boot+100n),'12345',candidate.artifacts.image.sha256]; const log=run('seed-'+index+'-'+c.name,reader,args,c.id===0?0:2); if(c.id===0){const r=JSON.parse(log);assert.equal(r.sha256,digest);assert.equal(r.bytes,1537);assert.equal(r.reads,7);assert.equal(r.guestAccepted,false);} else assert.match(readFileSync(commands.at(-1).log.path,'utf8'),new RegExp(c.error)); assert.deepEqual(readFileSync(disk),input);report.cases.push({seed:seed.toString(16),case:c.name,expectedError:c.error,hostOnly:true}); } } for(const seed of [0n,-1n,1n<<64n,1])assert.throws(()=>sourceBytes(seed)); assert.throws(()=>beforeDisk(Buffer.alloc(127)));assert.throws(()=>readerDisk(Buffer.alloc(2),Buffer.alloc(2),0)); assert.throws(()=>readerDisk(Buffer.alloc(1024*1024),Buffer.alloc(1024*1024),5)); for(const p of ['scripts/os-acceptance/k2160-fixture.mjs','tools/reopen_verify/test_native_fixture.mjs']){ const dst=join(out,p.split('/').at(-1)+'.txt');copyFileSync(p,dst);files.push(art(dst)); } report.status='NATIVE_FIXTURE_HOST_PASSED';report.sourceAgreementSeeds=5;report.readerHostCases=25;report.positiveReaderCases=5;report.expectedRefusalCases=20; report.scope='Five nonce seeds match pure Rust function bodies copied verbatim from the archived compiled candidate. Twenty-five separate host reader invocations check generated initial/written/corrupted disks. Disk byte differences are exactly the six intended write sectors. This does not launch QEMU, execute AArch64 code, prove guest shutdown or admit any roadmap move.'; }catch(error){report.status='NATIVE_FIXTURE_HOST_FAILED';report.error=String(error.stack??error);process.exitCode=1;} const path=join(out,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify({status:report.status,report:path}));