import assert from 'node:assert/strict'; import {mkdtempSync,readFileSync,writeFileSync} from 'node:fs'; import {join,relative,resolve} from 'node:path'; import {frozenSnapshot,hashAt} from './boot-contract-report.mjs'; const root=process.cwd(),progressPath='reports/os-implementation/progress.json'; const json=path=>JSON.parse(readFileSync(join(root,path),'utf8')); const artifact=path=>({path,sha256:hashAt(root,path)}); const seen=new Map(); function check(item) { assert.ok(item&&typeof item.path==='string'&&/^[0-9a-f]{64}$/.test(item.sha256)); assert.ok(resolve(root,item.path).startsWith(root+'/')); const actual=seen.get(item.path)??hashAt(root,item.path);seen.set(item.path,actual); assert.equal(actual,item.sha256,item.path); } function references(value) { if(!value||typeof value!=='object')return; if(typeof value.path==='string'&&typeof value.sha256==='string')check(value); for(const child of Object.values(value))references(child); } if(process.argv[2]==='--apply') { assert.equal(process.argv.length,4); const auditPath=relative(root,resolve(process.argv[3])),audit=json(auditPath); assert.equal(audit.status,'K1141_K1179_HISTORICAL_LOCAL_EVIDENCE_VERIFIED'); assert.equal(audit.newTestExecutions,0); assert.equal(audit.groups.length,8);assert.equal(audit.moves.length,32); references(audit); const before=readFileSync(join(root,progressPath),'utf8'),progress=JSON.parse(before); // Reconcile at the completed K1680 boundary so an active updater cannot // observe an unexpected counter change halfway through its matrix. assert.equal(progress.lastAcceptedGuest,'K1680'); assert.equal(progress.nextImplementation,'K1681'); assert.equal(progress.counts.locallyValidated,832); assert.equal(progress.counts.developmentGuestAccepted,215); const evidence=artifact(auditPath); for(const group of audit.groups) { const guest=progress.moves.find(row=>row.id===group.guestId); assert.equal(guest.status,'DEVELOPMENT_GUEST_ACCEPTED'); assert.deepEqual(guest.evidence,group.guest); for(const id of group.moves) { const move=progress.moves.find(row=>row.id===id); assert.equal(move.status,'PLANNED');assert.equal(move.evidence,null); move.status='LOCAL_VALIDATED';move.evidence=evidence;move.productAccepted=false; move.scope='historical-spawn-rights-local-evidence-reconciled'; } } const count=status=>progress.moves.filter(row=>row.status===status).length; progress.counts.locallyValidated=count('LOCAL_VALIDATED'); progress.counts.developmentGuestAccepted=count('DEVELOPMENT_GUEST_ACCEPTED'); progress.counts.notAccepted=progress.moves.length-progress.counts.locallyValidated-progress.counts.developmentGuestAccepted; assert.equal(progress.counts.locallyValidated,864); assert.equal(progress.counts.developmentGuestAccepted,215); assert.equal(progress.counts.notAccepted,821); assert.equal(progress.counts.productAccepted,0); progress.generatedAt=new Date().toISOString(); const directory=mkdtempSync(join(root,'reports/os-implementation/K1141-K1179-local-reconciliation-update-')); writeFileSync(join(directory,'previous-progress.json'),before); writeFileSync(join(root,progressPath),JSON.stringify(progress,null,2)+'\n'); const report={schema:'turkos-spawn-rights-local-reconciliation-update/v1', status:'K1141_K1179_LOCAL_EVIDENCE_RECONCILED',audit:evidence, previous:artifact(relative(root,join(directory,'previous-progress.json'))), current:artifact(progressPath),counts:progress.counts,newTestExecutions:0, scope:'32 local entries now reference hash-verified historical source, positive/negative host results and ARM64 checks. Guest acceptance, product acceptance and the next implementation stay unchanged.'}; writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:relative(root,join(directory,'report.json')),counts:report.counts})); } else { assert.equal(process.argv.length,2,'usage: node spawn-rights-local-reconciliation.mjs [--apply audit-report.json]'); const progress=json(progressPath),plan=json('site/K601-K2500-plan.json'),protectedNow=frozenSnapshot(root); const groups=[],moves=[];let historicalTestExecutions=0,namedTestExecutions=0; for(let number=1145;number<=1180;number+=5) { const guestId='K'+number,move=progress.moves.find(row=>row.id===guestId); assert.equal(move.status,'DEVELOPMENT_GUEST_ACCEPTED');check(move.evidence); const guest=json(move.evidence.path);references(guest); assert.equal(guest.status,guestId+'_DEVELOPMENT_GUEST_ACCEPTED'); assert.equal(guest.guestAccepted,true);assert.equal(guest.productAccepted,false);assert.equal(guest.profiles,6); const host=json(guest.host.path);references(host); assert.equal(host.guestAccepted,false);assert.equal(host.productAccepted,false); assert.deepEqual(host.candidate,guest.candidate); assert.deepEqual(host.protectedBefore,protectedNow); const feature=plan.moves.find(row=>row.number===number); const logs=host.commands.map(command=>{ assert.equal(command.exitCode,0);check(command.log); return readFileSync(join(root,command.log.path),'utf8'); }); const text=logs.join('\n'); for(const name of [feature.testPlan.positiveName,feature.testPlan.negativeName]) assert.ok(text.includes('test '+name+' ... ok'),guestId+': '+name); assert.ok(host.commands.some(command=>command.argv.includes('aarch64-unknown-none'))); const executed=logs.reduce((sum,log)=>sum+[...log.matchAll(/test result: ok\. (\d+) passed; 0 failed/g)].reduce((n,m)=>n+Number(m[1]),0),0); assert.equal(executed,guest.executedHostTests);assert.ok(executed>0); assert.equal(host.namedTests,number<1165?2:4); const localMoves=Array.from({length:4},(_,i)=>'K'+(number-4+i)); for(const id of localMoves) { const local=progress.moves.find(row=>row.id===id); assert.equal(local.status,'PLANNED');assert.equal(local.evidence,null); } groups.push({guestId,moves:localMoves,feature:feature.feature, positiveName:feature.testPlan.positiveName,negativeName:feature.testPlan.negativeName, guest:move.evidence,host:guest.host,candidate:guest.candidate, namedTestExecutions:host.namedTests,historicalTestExecutions:executed, scope:host.scope}); moves.push(...localMoves);historicalTestExecutions+=executed;namedTestExecutions+=host.namedTests; } assert.equal(historicalTestExecutions,176);assert.equal(namedTestExecutions,24); const directory=mkdtempSync(join(root,'reports/os-implementation/K1141-K1179-local-reconciliation-audit-')); const report={schema:'turkos-spawn-rights-local-reconciliation-audit/v1', status:'K1141_K1179_HISTORICAL_LOCAL_EVIDENCE_VERIFIED',guestAccepted:false,productAccepted:false, generatedAt:new Date().toISOString(),newTestExecutions:0,historicalTestExecutions,namedTestExecutions, hashedArtifacts:seen.size,groups,moves, plan:artifact('site/K601-K2500-plan.json'), contract:artifact('kernel/SPAWN_RIGHTS_LOCAL_EVIDENCE_CONTRACT.md'), originalSpawnContract:artifact('os-spawn-transaction/CONTRACT.md'), harness:artifact('scripts/os-acceptance/spawn-rights-local-reconciliation.mjs'), scope:'Audit only: eight existing accepted development guests already bind 176 host-test executions, including 24 named tests, and ARM64 checks. Their 32 local plan entries remain unchanged until an explicit application at the completed K1680 boundary. This audit runs no tests and grants no new guest or product acceptance.'}; writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:relative(root,join(directory,'report.json')), historicalTestExecutions,namedTestExecutions,newTestExecutions:0,hashedArtifacts:seen.size})); }