// K2101+ local validation record for the four contract/implementation/test // moves before a feature's guest acceptance: the preparation run (crate tests, // named positive/negative tests, aarch64 check, source mutants), the native // EL0 program build and the compiled product candidate that integrates the // exact tested model source. No guest acceptance is claimed here. import assert from 'node:assert/strict'; import {mkdtempSync,readFileSync,writeFileSync,copyFileSync} from 'node:fs'; import {join,relative,resolve} from 'node:path'; import {hashAt,frozenSnapshot} from './boot-contract-report.mjs'; import {buildOsPlan} from '../os-roadmap.mjs'; assert.equal(process.argv.length,6,'usage: node feature-local.mjs '); const root=process.cwd(),[specPath,prepPath,userPath,candidatePath]=process.argv.slice(2).map(p=>relative(root,resolve(p))); const read=p=>JSON.parse(readFileSync(p,'utf8')),artifact=p=>({path:relative(root,p),sha256:hashAt(root,relative(root,p))}); const check=item=>{assert.equal(hashAt(root,item.path),item.sha256,item.path);return item;}; const spec=read(specPath),prep=read(prepPath),user=read(userPath),candidate=read(candidatePath); assert.equal(prep.status,'STAGING_LOCAL_PASSED');assert.equal(prep.milestone,spec.milestone);assert.equal(prep.tests,spec.tests); assert.ok(prep.mutationsRejected>=spec.minimumMutants);assert.deepEqual(prep.frozenBefore,prep.frozenAfter); assert.equal(user.status,'USER_BUILD_PASSED');assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE'); assert.deepEqual(candidate.userBuild,artifact(join(root,userPath)));assert.equal(candidate.milestone,spec.milestone); for(const item of[prep.spec,prep.harness,...prep.sources,...prep.commands.map(c=>c.log),...prep.mutants.map(m=>m.source),user.harness,...user.sources,user.build.log, ...user.programs.flatMap(p=>[p.elf,p.image,p.disassembly]),candidate.spec,candidate.harness,candidate.build.log,...Object.values(candidate.artifacts),...Object.values(candidate.sources)])check(item); // The integrated runtime model is byte-identical to the crate source the preparation tested. for(const m of spec.integration.runtime){ const tested=prep.sources.find(s=>s.path.endsWith('/source/'+m.from));assert.ok(tested,`tested source ${m.from}`); assert.equal(candidate.sources['runtime/'+m.module+'.rs'].sha256,tested.sha256,'candidate model equals tested model'); } for(const p of user.programs)assert.equal(candidate.sources[p.name+'.bin'].sha256,p.image.sha256,'embedded program equals built program'); const plan=buildOsPlan(),n=Number(spec.milestone.slice(1)),moves=[n-4,n-3,n-2,n-1].map(k=>plan.moves.find(m=>m.id==='K'+k)); assert.deepEqual(moves.map(m=>m.stage),['contract','implementation','positive','negative']);assert.ok(moves.every(m=>m.feature===spec.feature)); const contractSource=prep.sources.find(s=>s.path.endsWith('/source/'+spec.contract));assert.ok(contractSource,'contract was part of the tested sources'); const directory=mkdtempSync(join(root,`reports/os-implementation/${spec.milestone}-${spec.slug}-local-`)); copyFileSync(join(root,'scripts/os-acceptance/feature-local.mjs'),join(directory,'harness.mjs.txt')); const status=`K${n-4}_K${n-1}_LOCAL_VALIDATED`; const report={schema:'turkos-feature-local/v1',status,milestone:spec.milestone,feature:spec.feature,guestAccepted:false,productAccepted:false, moves:moves.map(m=>({id:m.id,stage:m.stage,title:m.title})),spec:artifact(join(root,specPath)),preparation:artifact(join(root,prepPath)), userBuild:artifact(join(root,userPath)),candidate:artifact(join(root,candidatePath)),harness:artifact(join(directory,'harness.mjs.txt')), contract:contractSource,sources:Object.fromEntries(prep.sources.map(s=>[s.path.split('/source/')[1],s])), tests:{green:prep.commands.find(c=>c.name==='host-tests'),positive:prep.commands.find(c=>c.name==='positive'),negative:prep.commands.find(c=>c.name==='negative'), target:prep.commands.find(c=>c.name==='target'),greenCount:prep.tests,positiveName:prep.positiveName,negativeName:prep.negativeName,mutationsRejected:prep.mutationsRejected}, mutants:prep.mutants.map(m=>m.source),imageSpan:candidate.imageSpan,frozenBefore:frozenSnapshot(root), scope:readFileSync(join(root,spec.contract),'utf8')}; report.frozenAfter=frozenSnapshot(root);assert.deepEqual(report.frozenAfter,report.frozenBefore); writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status,report:relative(root,join(directory,'report.json')),tests:prep.tests,mutationsRejected:prep.mutationsRejected}));