// Strict component proof. This cannot admit the full K2155 native device drain. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync} from 'node:fs'; import {join} from 'node:path'; import {createHash} from 'node:crypto'; import {checkWorkerSnapshots,WORKER_STAGES} from './features/k2155-worker-check.mjs'; import {checkCaptureProtocol} from './features/k2155-worker-capture-check.mjs'; const [matrix,candidatePath]=process.argv.slice(2);assert.equal(process.argv.length,4); const hash=b=>createHash('sha256').update(b).digest('hex'),artifact=path=>({path,sha256:hash(readFileSync(path))}); function bytes(item){const value=readFileSync(item.path);assert.equal(hash(value),item.sha256,item.path);return value;} const read=p=>JSON.parse(readFileSync(p)); const c=read(candidatePath),life=read(join(matrix,'scoped-lifecycle.json')),preflight=read(join(matrix,'preflight.json')); assert.equal(c.status,'COMPILED_FEATURE_CANDIDATE');assert.equal(c.slug,'shutdown-worker-component'); assert.deepEqual(c.frozenAfter,c.frozenBefore);assert.ok(c.imageSpan.bytes>0&&c.imageSpan.bytes<=8*1024*1024); assert.deepEqual(preflight.harness,artifact('scripts/os-acceptance/k2155-worker-guest-runner.mjs')); const spec=JSON.parse(bytes(c.spec));assert.equal(spec.componentOnly,true);assert.equal(spec.guestAccepted,false); assert.equal(life.status,'RUNNER_PASSED');assert.equal(life.frozenStable,true);assert.deepEqual(life.candidate,artifact(candidatePath)); const image=bytes(c.artifacts.image),nm=bytes(c.artifacts.nm).toString(),symbols={}; for(const line of nm.split('\n')){const m=line.match(/^([a-f0-9]{16}) (?:([a-f0-9]{16}) )?[A-Za-z] (\S+)$/);if(m)symbols[m[3]]={address:parseInt(m[1],16),size:m[2]?parseInt(m[2],16):0};} const compiled={};for(const name of ['OS_K2155_THREAD_LAYOUT','OS_K1000_AUTHORITY_LAYOUT_EXPECTED']){ const s=symbols[name];assert.ok(s&&s.size);const at=s.address-c.imageSpan.start;assert.ok(at>=0&&at+s.size<=image.length);compiled[name]=image.subarray(at,at+s.size); } const selected=life.selection==='all'?['direct','uefi'].flatMap(route=>[256,512,1024].flatMap(memoryMiB=>[1,2,4].map(cpuCount=>`${route}-${memoryMiB}-cpu-${cpuCount}`))) :life.selection==='smoke'?['direct-256-cpu-1']:life.selection.split(','); assert.equal(new Set(selected).size,selected.length);assert.deepEqual(life.profiles.map(r=>r.profile.id),selected); assert.equal(new Set(c.captures).size,c.captures.length); const directory=mkdtempSync('reports/os-implementation/K2155-worker-matrix-check-'); const sources=['scripts/os-acceptance/k2155-worker-matrix-check.mjs','scripts/os-acceptance/k2155-worker-guest-runner.mjs','scripts/os-acceptance/features/k2155-worker-check.mjs','scripts/os-acceptance/features/k2155-worker-capture-check.mjs']; const report={status:'RUNNING',guestAccepted:false,productAccepted:false,componentOnly:true,candidate:artifact(candidatePath),lifecycle:artifact(join(matrix,'scoped-lifecycle.json')),preflight:artifact(join(matrix,'preflight.json')),profiles:[],negativeControls:[]}; report.sources=sources.map((p,i)=>{const out=join(directory,`${i}-${p.split('/').at(-1)}.txt`);copyFileSync(p,out);return artifact(out);}); try{ for(const profile of life.profiles){ assert.equal(profile.status,'GUEST_RETURNED');assert.equal(profile.allOwnedGuestsStopped,true); const path=join(matrix,profile.profile.id,'result.json'),r=read(path);assert.deepEqual(r,profile); assert.deepEqual(r.experimentStages.map(s=>s.stage),WORKER_STAGES); assert.equal(r.exit.code,0);assert.equal(r.exit.signal,null); const command=read(join(matrix,r.profile.id,'qemu-command.json'));assert.deepEqual(command.profile,r.profile);assert.equal(command.bootId,r.bootId); const serial=bytes(r.serial).toString();assert.ok(serial.includes('TURKOS/OS/K2155-WORKERS:'));assert.ok(serial.includes('TURKOS/OS/K2155: PASS'));assert.ok(!/PANIC|REJECTED|FATAL/.test(serial)); const protocol=checkCaptureProtocol({audit:JSON.parse(bytes(r.captureAudit)),qmp:JSON.parse(bytes(r.qmpTranscript)),stages:r.experimentStages,serial}); const snapshots=[]; for(const stage of r.experimentStages){ const data={};assert.deepEqual(stage.captures.map(x=>x.symbol),c.captures); for(const span of stage.captures){assert.equal(span.address,symbols[span.symbol].address);assert.equal(span.size,symbols[span.symbol].size);const b=bytes(span);assert.equal(b.length,span.size);data[span.symbol]=b;} const meta=Array.from({length:10},(_,i)=>Number(data.OS_K2155_THREAD_TABLE.readBigUInt64LE(i*8))); assert.equal(new Set(stage.physical.map(p=>p.name)).size,stage.physical.length); const ramEnd=0x40000000+r.profile.memoryMiB*1048576; for(const span of stage.physical){assert.ok(!data[span.name]);assert.ok(Number.isSafeInteger(span.address)&&Number.isSafeInteger(span.size)&&span.address>=0x40000000&&span.address+span.size<=ramEnd&&span.address%8===0&&span.size>0&&span.size<=65536);const b=bytes(span);assert.equal(b.length,span.size);data[span.name]=b;} for(const [name,address,size]of [['authority',meta[4],meta[5]],['root-page',meta[7],4096],...(stage.stage!==4?[['thread-table',meta[0],meta[1]]]:[])]){ const row=stage.physical.find(p=>p.name===name);assert.ok(row,name);assert.equal(row.address,address);assert.equal(row.size,size); } for(const span of stage.physical){ if(/^l[23]-/.test(span.name)){assert.equal(span.address,parseInt(span.name.slice(3),16));assert.equal(span.size,4096);} const m=span.name.match(/^(guard|stack|low-canary|high-canary)-([01])$/);if(m){const i=Number(m[2]);const at={guard:1,stack:0,'low-canary':3,'high-canary':4}[m[1]];assert.equal(span.address,Number(data.OS_K2155_THREAD_GUARDS.readBigUInt64LE((i*6+at)*8)));assert.equal(span.size,m[1]==='stack'?20480:8);} } const spans=[...stage.captures,...stage.physical];assert.equal(stage.confirmations.length,spans.length); for(const [i,confirmation]of stage.confirmations.entries())assert.deepEqual(bytes(confirmation),bytes(spans[i])); snapshots.push(data); } for(const item of r.final)assert.deepEqual(bytes(item),snapshots.at(-1)[item.symbol]); const input={snapshots,compiled,symbols,memoryMiB:r.profile.memoryMiB}; const verified=checkWorkerSnapshots(input); // Mutate real captured bytes, not guest-provided booleans. Every listed // forgery must be rejected by the exact independent semantic checker. const controls=[ ['fake-clean-free-count',8,'OS_K2155_EVIDENCE',12*8], ['hide-work-after-stop',6,'OS_K2155_EVIDENCE',11*8], ['fake-work-checksum',1,'OS_K2155_EVIDENCE',8*8], ['fake-running-sp',1,'OS_K2155_THREAD_RECORDS',6*8], ['hide-current-stack-refusal',4,'OS_K2155_THREAD_RECORDS',26*8], ['fake-stopped-page-count',6,'OS_K2155_EVIDENCE',7*8], ['alter-stack-canary',2,'low-canary-1',0], ['nonzero-reclaimed-page',7,'stack-0',4096], ['forged-guard-descriptor',2,'guard-0',0], ['forged-compiler-layout',0,'OS_K2155_THREAD_LAYOUT',0], ['early-allocator-mutation',3,'authority',0], ['late-allocator-mutation',7,'authority',0], ]; for(const [name,step,key,offset]of controls){const altered=snapshots.map(s=>({...s}));altered[step][key]=Buffer.from(altered[step][key]);altered[step][key][offset]^=1;assert.throws(()=>checkWorkerSnapshots({...input,snapshots:altered}),name);} const rawLayout=Array.from({length:16},(_,i)=>Number(compiled.OS_K2155_THREAD_LAYOUT.readBigUInt64LE(i*8))); for(const [name,step,offset]of [['forged-running-state',1,rawLayout[3]+rawLayout[7]],['forged-native-stack-base',1,rawLayout[3]+rawLayout[9]+rawLayout[10]],['forged-thread-generation',3,rawLayout[3]+rawLayout[5]]]){ const altered=snapshots.map(s=>({...s}));altered[step]['thread-table']=Buffer.from(altered[step]['thread-table']);altered[step]['thread-table'][offset]^=1;assert.throws(()=>checkWorkerSnapshots({...input,snapshots:altered}),name);controls.push([name,step,'thread-table',offset]); } report.negativeControls.push({profile:r.profile.id,rejected:controls.map(x=>x[0])}); report.profiles.push({profile:r.profile,result:artifact(path),verified,protocol}); } report.status='K2155_WORKER_COMPONENT_MATRIX_VALIDATED';report.physicalWorkersVerified=true; report.fullHardwareMatrix=report.profiles.length===18&&life.selection==='all'; report.scope='Actual cooperative CPU0 worker execution and stop/reap component only. Network/disk DMA, IRQ integration, device reset, EL0 shutdown request and full K2155 roadmap admission remain required.'; }catch(error){report.status='K2155_WORKER_COMPONENT_MATRIX_FAILED';report.error=error.stack;process.exitCode=1;} writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:join(directory,'report.json'),profiles:report.profiles.length}));