import assert from 'node:assert/strict'; import {cpSync,mkdtempSync,readFileSync,writeFileSync} from 'node:fs'; import {join,relative} from 'node:path'; import {spawnSync} from 'node:child_process'; import {frozenSnapshot,hashAt} from './boot-contract-report.mjs'; const root=process.cwd(),before=frozenSnapshot(root),directory=mkdtempSync(join(root,'reports/os-implementation/K1940-sandbox-quotas-staging-build-')),source=join(directory,'source'); cpSync('reports/os-implementation/K1940-sandbox-quotas-work-sources',source,{recursive:true,filter:p=>!p.split('/').includes('target')}); const artifact=p=>({path:relative(root,p),sha256:hashAt(root,relative(root,p))}); const env={...process.env,CARGO_TARGET_DIR:join(directory,'target')};delete env.RUSTFLAGS;delete env.CARGO_ENCODED_RUSTFLAGS; const r=spawnSync('cargo',['check','--manifest-path',join(source,'kernel/Cargo.toml'),'--offline','--bin','turkos-kernel','--target','aarch64-unknown-none','--no-default-features','--features','os-runtime-product'],{cwd:root,env,encoding:'utf8',timeout:600000,maxBuffer:64*1024*1024}); const log=join(directory,'kernel-check.log');writeFileSync(log,(r.stdout??'')+(r.stderr??'')); const after=frozenSnapshot(root);assert.deepEqual(after,before); const report={schema:'turkos-k1940-sandbox-quotas-staging-build/v1',status:r.status===0&&!r.error?'STAGING_BUILD_PASSED':'STAGING_BUILD_FAILED',guestAccepted:false,productAccepted:false,sourceDirectory:relative(root,source),sources:['kernel/src/k1940-sandbox-quotas.rs','kernel/src/runtime/sandbox_quotas.rs','kernel/src/runtime/sandbox_quotas_space.rs','kernel/src/k1940-frame-asm.rs','kernel/src/os_k1940_vectors.S','kernel/src/k1940-sandbox-quotas-user.elf','kernel/src/main.rs','kernel/src/runtime/mod.rs','kernel/src/runtime/frame_metadata.rs','kernel/src/runtime/frame_authority.rs'].map(p=>artifact(join(source,p))),build:{exitCode:r.status,error:r.error?.message??null,log:artifact(log)},harness:artifact(join(root,'scripts/os-acceptance/sandbox-quotas-stage-check.mjs')),frozenBefore:before,frozenAfter:after}; const path=join(directory,'report.json');writeFileSync(path,JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify({status:report.status,report:relative(root,path)}));if(r.status!==0){console.error(readFileSync(log,'utf8').slice(-4000));process.exitCode=1;}