import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,existsSync,mkdtempSync,copyFileSync,renameSync}from'node:fs'; import {createHash}from'node:crypto'; import {join,resolve}from'node:path'; import {fileURLToPath}from'node:url'; import {setTimeout as delay}from'node:timers/promises'; // Consolidation only: this never marks K2100 or a roadmap row accepted. const args=process.argv.slice(2),watch=args[0]==='--watch';if(watch)args.shift(); const[sequencePath,indexPath]=args;assert.ok(sequencePath&&indexPath&&args.length===2); const artifact=path=>({path,sha256:createHash('sha256').update(readFileSync(path)).digest('hex')}); const read=path=>JSON.parse(readFileSync(path)); const cache=new Map(); const checked=a=>{const path=resolve(a.path);if(!cache.has(path))cache.set(path,artifact(a.path).sha256);assert.equal(cache.get(path),a.sha256,a.path);return readFileSync(a.path);}; function verifyNested(v){if(Array.isArray(v)){for(const x of v)verifyNested(x);return;}if(!v||typeof v!=='object')return;if(typeof v.path==='string'&&typeof v.sha256==='string')checked(v);for(const x of Object.values(v))verifyNested(x);} const words=b=>{assert.equal(b.length%8,0);return Array.from({length:b.length/8},(_,i)=>b.readBigUInt64LE(i*8));}; const nativeIndex=read(indexPath);assert.equal(nativeIndex.status,'COMPILED_AND_SHORT_PHYSICAL_COMPONENT_INDEX_VERIFIED');assert.equal(nativeIndex.guestAccepted,false); const originalIndex=artifact(indexPath),initialSequence=read(sequencePath),candidateArtifact=initialSequence.candidate; const candidate=JSON.parse(checked(candidateArtifact));assert.equal(candidate.status,'COMPILED_K2100_DURATION_LONG_CANDIDATE');assert.deepEqual(candidate.artifacts.image,nativeIndex.image); console.log(JSON.stringify({status:'MATRIX_VALIDATOR_READY',sequence:sequencePath,nativeIndex:indexPath})); let sequence=initialSequence; if(watch){ let previous=-1; while(sequence.status==='PROFILE_COLLECTION_ACTIVE'){ assert.deepEqual(sequence.candidate,candidateArtifact); if(sequence.completed.length!==previous){previous=sequence.completed.length;console.log(JSON.stringify({completedProfiles:previous,requiredProfiles:18}));} await delay(30000);sequence=read(sequencePath); } } const directory=mkdtempSync('reports/os-implementation/K2100-long-matrix-proof-');copyFileSync(fileURLToPath(import.meta.url),join(directory,'harness.mjs.txt')); try{ assert.equal(sequence.status,'LONG_WORKLOAD_PROFILE_COMPONENTS_PASSED');assert.equal(sequence.completed.length,18);assert.equal(sequence.active,null); assert.deepEqual(artifact(indexPath),originalIndex);verifyNested(nativeIndex); for(const c of Object.values(nativeIndex.components))verifyNested(JSON.parse(checked(c.report))); verifyNested(JSON.parse(checked(nativeIndex.hostControlCorrection))); verifyNested(sequence.pins);assert.deepEqual(sequence.sameImage,nativeIndex.image);verifyNested(candidate.artifacts); const required=new Set();for(const route of['direct','uefi'])for(const ram of[256,512,1024])for(const cpus of[1,2,4])required.add(`${route}-${ram}-cpu-${cpus}`); const seen=new Set(),matrices=new Set(),profiles=[]; for(const entry of sequence.completed){ const p=entry.profile,id=`${p.route}-${p.memoryMiB}-cpu-${p.cpuCount}`;assert.equal(p.id,id);assert.ok(required.has(id));assert.ok(!seen.has(id));seen.add(id); const review=JSON.parse(checked(entry.review)),proof=JSON.parse(checked(entry.proof)); assert.equal(review.status,'LONG_WORKLOAD_GUEST_RETURNED');assert.equal(proof.status,'DURATION_WINDOW_PHYSICAL_COMPONENT_PASSED');assert.equal(proof.longInput,true); for(const key of['cpuCount','memoryMiB','route'])assert.equal(review[key],p[key]); assert.equal(proof.cpuCount,p.cpuCount);assert.equal(proof.memoryMiB,p.memoryMiB);assert.deepEqual(review.candidate,candidateArtifact);assert.deepEqual(proof.image,nativeIndex.image); assert.deepEqual(proof.review,entry.review);assert.deepEqual(proof.physical,review.physical); assert.equal(review.guestAccepted,false);assert.equal(review.productAccepted,false);assert.equal(proof.guestAccepted,false);assert.equal(proof.productAccepted,false); assert.deepEqual(review.sourceBefore,review.sourceAfter);verifyNested(review);verifyNested(proof); if (review.runner.path.endsWith('/.k2100-duration-long-continuity-generated.mjs')) { assert.ok(review.hostContinuity && review.continuityHarness); const continuity = JSON.parse(checked(review.hostContinuity)); assert.equal(continuity.status, 'HOST_EXECUTION_CONTINUITY_PASSED'); assert.equal(continuity.failure, null); assert.equal(continuity.maximumGapMilliseconds, 30000); assert.ok(continuity.samples > 0 && continuity.largestMonotonicGap <= 30000 && continuity.largestWallGap <= 30000); assert.deepEqual(continuity.harness, review.continuityHarness); } if (review.runner.path.endsWith('/.k2100-duration-long-continuous-clock-generated.mjs')) { assert.ok(review.hostContinuity && review.continuityHarness && review.nativeClock && review.nativeClockSource); const continuity = JSON.parse(checked(review.hostContinuity)); assert.equal(continuity.schema, 'turkos-host-continuity/v2'); assert.equal(continuity.clockSource, 'mach_continuous_time'); assert.equal(continuity.status, 'HOST_EXECUTION_CONTINUITY_PASSED'); assert.equal(continuity.failure, null); assert.equal(continuity.maximumGapMilliseconds, 30000); assert.ok(continuity.samples > 0 && continuity.largestMonotonicGap <= 30000); assert.ok(continuity.continuousSamples > 0 && continuity.largestContinuousGap > 0 && continuity.largestContinuousGap <= 30000); assert.equal(continuity.lastContinuous.sequence, continuity.continuousSamples); assert.deepEqual(continuity.harness, review.continuityHarness); assert.deepEqual(continuity.nativeClock, review.nativeClock); assert.deepEqual(continuity.nativeClockSource, review.nativeClockSource); } const lifecycle=JSON.parse(checked(review.lifecycle));assert.equal(lifecycle.status,'RUNNER_PASSED');assert.equal(lifecycle.allOwnedGuestsStopped,true);assert.equal(lifecycle.sourceInputsStable,true); assert.ok(!matrices.has(resolve(review.lifecycle.path)));matrices.add(resolve(review.lifecycle.path)); const physical=JSON.parse(checked(review.physical));assert.equal(physical.status,'LONG_WORKLOAD_GUEST_RETURNED');verifyNested(physical); const clock=physical.workloadMeasurement;assert.equal(clock.durationMet,true);assert.equal(clock.minimumRunningMilliseconds,7200000); let running=0,priorEnd=-1;for(const s of clock.segments){assert.ok(s.start>=priorEnd&&s.end>s.start);assert.ok(Math.abs(s.milliseconds-(s.end-s.start))<0.001);running+=s.milliseconds;priorEnd=s.end;} assert.ok(Math.abs(running-clock.runningMilliseconds)<0.001);assert.ok(running>=7200000);assert.equal(proof.hostRunningMilliseconds,clock.runningMilliseconds);assert.equal(entry.hostRunningMilliseconds,clock.runningMilliseconds); assert.equal(physical.windowCheckpoints.length,proof.windows.length);assert.equal(entry.windows,proof.windows.length); const final=physical.checkpoints[1];assert.ok(final&&final.dumps); const monitor=words(checked(final.dumps.OS_K2100_WORKLOAD_MONITOR)),summary=words(checked(final.dumps.OS_K2100_WORKLOAD_SUMMARY)); assert.equal(monitor[2],BigInt(p.cpuCount));assert.equal(monitor[49],BigInt(entry.windows));assert.equal(monitor[52],1n);assert.equal(summary[12],1n); assert.equal(summary[4],summary[2]+summary[3]*7200n);assert.ok(summary[8]>0n&&summary[8]=summary[4]&&summary[9]0n); const guestElapsedSeconds=Number(monitor[4]-monitor[3])/Number(monitor[1]);assert.ok(guestElapsedSeconds>=7200);assert.equal(proof.guestElapsedSeconds,guestElapsedSeconds);assert.equal(entry.guestElapsedSeconds,guestElapsedSeconds); assert.equal(entry.actualRequests,p.cpuCount*entry.windows);assert.equal(entry.actualReplies,2*entry.actualRequests); const storage=JSON.parse(checked(entry.storage));assert.equal(storage.status,'IMMUTABLE_EVIDENCE_DEDUPLICATED_AND_VERIFIED');assert.equal(storage.pathsPreserved,true); const published=JSON.parse(checked(entry.publication));assert.equal(published.status,'PUBLISHED_AND_PRODUCTION_VERIFIED');assert.equal(published.productionVerified,true); profiles.push({id,review:entry.review,physical:review.physical,proof:entry.proof,publication:entry.publication,windows:entry.windows,hostRunningMilliseconds:running,guestElapsedSeconds,actualRequests:entry.actualRequests,actualReplies:entry.actualReplies}); } assert.deepEqual(seen,required); const report={status:'LONG_PROFILE_MATRIX_COMPONENT_PASSED',guestAccepted:false,productAccepted:false, scope:'All eighteen distinct CPU/RAM/boot long profile components are tied to one actual Image and the selected compiled proof index. Every referenced capture, source and proof artifact was hash checked; actual terminal Monitor/summary and independently accumulated host segments satisfy the two-hour, late refusal and subsequent window constraints. Formal consolidated native/physical acceptance review and roadmap publication remain separate.', sequence:artifact(sequencePath),nativeIndex:originalIndex,candidate:candidateArtifact,image:nativeIndex.image,profiles,verifiedArtifacts:cache.size, minimumHostRunningMilliseconds:Math.min(...profiles.map(p=>p.hostRunningMilliseconds)),minimumGuestElapsedSeconds:Math.min(...profiles.map(p=>p.guestElapsedSeconds)), harness:artifact(join(directory,'harness.mjs.txt'))}; const path=join(directory,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n'); const statePath='reports/os-implementation/active-development-continuation.json',state=read(statePath);state.K2100.longMatrixProof=path;state.K2100.longMatrixIndependentlyVerified=true;state.updatedAt=new Date().toISOString();const tmp=statePath+'.matrix-tmp';writeFileSync(tmp,JSON.stringify(state,null,2)+'\n');renameSync(tmp,statePath); console.log(JSON.stringify({status:report.status,report:path,profiles:profiles.length,verifiedArtifacts:cache.size})); }catch(error){writeFileSync(join(directory,'report.json'),JSON.stringify({status:'LONG_PROFILE_MATRIX_COMPONENT_FAILED',guestAccepted:false,productAccepted:false,error:error.stack},null,2)+'\n');console.error(join(directory,'report.json'));throw error;}