import assert from 'node:assert/strict'; import {mkdtempSync,mkdirSync,writeFileSync,readFileSync} from 'node:fs'; import {spawnSync} from 'node:child_process'; import {dirname,join,relative} from 'node:path'; import {runqueueGuestServicesSources,runqueueGuestServicesInputs} from './runqueue-guest-services-sources.mjs'; import {hashAt,frozenSnapshot} from './boot-contract-report.mjs'; import {filesIn} from './entry-extension.mjs'; const root=process.cwd();assert.equal(process.argv.length,2);const inputsBefore=runqueueGuestServicesInputs(root),protectedBefore=frozenSnapshot(root),directory=mkdtempSync(join(root,'reports/os-implementation/K1060-services-build-')),sourcesDirectory=join(directory,'sources');const clean=s=>s.split(root).join(''),artifact=path=>({path:relative(root,path),sha256:hashAt(root,relative(root,path))});const sources=[]; function write(originalPath,bytes){const path=join(sourcesDirectory,originalPath);mkdirSync(dirname(path),{recursive:true});writeFileSync(path,bytes);sources.push({originalPath,...artifact(path)});} for(const[p,s]of runqueueGuestServicesSources(root))write('os-runqueue-guest-services/'+p,s); for(const dep of['os-threads','os-exceptions'])for(const p of filesIn(root,dep))write(p,readFileSync(join(root,p))); write('.cargo/config.toml',readFileSync(join(root,'.cargo/config.toml'))); const commands=[];function command(id,argv,executable='cargo'){const env={...process.env,CARGO_TARGET_DIR:join(directory,'target')};delete env.RUSTFLAGS;delete env.CARGO_ENCODED_RUSTFLAGS;const r=spawnSync(executable,argv,{cwd:root,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});assert.equal(r.error,undefined);const path=join(directory,id+'.log');writeFileSync(path,clean((r.stdout??'')+(r.stderr??'')));const receipt={id,executable,argv:argv.map(clean),exitCode:r.status,log:artifact(path)};commands.push(receipt);assert.equal(r.status,0,path);} const manifest=join(sourcesDirectory,'os-runqueue-guest-services/Cargo.toml');command('lock',['generate-lockfile','--manifest-path',manifest,'--offline']);sources.push({originalPath:'os-runqueue-guest-services/Cargo.lock',...artifact(join(dirname(manifest),'Cargo.lock'))});command('arm64-check',['check','--manifest-path',manifest,'--locked','--offline','--lib','--target','aarch64-unknown-none']);command('host-check',['check','--manifest-path',manifest,'--locked','--offline','--lib','--target','aarch64-apple-darwin']);command('format',['--config','skip_children=true','--edition','2024','--check',join(root,'scripts/os-acceptance/k1060-runqueue-context-services.rs'),join(root,'scripts/os-acceptance/k1060-runqueue-backend.rs')],'rustfmt'); const report={schema:'turkos-runqueue-guest-services-compile/v1',status:'COMPILED_ONLY',guestAccepted:false,kernelElfBound:false,actualCpuMeasured:false,arm64Status:'CHECK_ONLY',pending:[1045,1050,1055,1060],boundary:'Generic3-member Queue backend and gated private Context/Tick bridge only. No concrete three-root kernel backend, assembly, kernel Image/ELF, actual timer or VM is accepted; final source adaptation waits canonical frozen K1040.',runDirectory:relative(root,directory),sources,commands,inputsBefore,inputsAfter:runqueueGuestServicesInputs(root),protectedBefore,protectedAfter:frozenSnapshot(root)};assert.deepEqual(report.inputsBefore,report.inputsAfter);assert.deepEqual(report.protectedBefore,report.protectedAfter);const path=join(directory,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n');console.log(`RUNQUEUE GUEST SERVICES COMPILED_ONLY ${relative(root,path)}`);