import assert from'node:assert/strict';import{cpSync,mkdtempSync,readFileSync,writeFileSync,copyFileSync}from'node:fs';import{spawnSync}from'node:child_process';import{join}from'node:path';import{artifact,read}from'/scripts/os-acceptance/cpu-watchdog-artifacts.mjs'; const root=process.cwd(),basePath='reports/os-implementation/K2095-cpu-watchdog-candidate-3i89qX/report.json',base=read(basePath),directory=mkdtempSync('reports/os-implementation/K2100-service-component-preflight-'),sources=directory+'/sources',src=sources+'/kernel/src/'; cpSync(base.sourceDirectory,sources,{recursive:true,filter:p=>!p.split('/').includes('target')});let main=readFileSync(src+'main.rs','utf8');const before='if mode>210 || (144..=209).contains(&mode) {return Err("policy-probe-mode");}\n Ok(mode)',after='if mode!=210 {return Err("policy-probe-mode");}\n Ok(210)';assert.equal(main.split(before).length,2);main=main.replace(before,after);const head='fn os_k1100_product_probe_mode(boot:&BootData)';assert.equal(main.split(head).length,2);main=main.replace(head,'#[inline(always)]\n'+head);const roundCall='k2095_cpu_watchdog::run(boot,tables,&mut memory.allocator)?';assert.equal(main.split(roundCall).length,2);main=main.replace(roundCall,roundCall+';os_k2100_process_round(&mut memory.allocator,tables)?;write_line("TURKOS/OS/K2100-PROCESS-COMPONENT: ROUND=1 STALE_REFUSED=1 WAKE=1 RETIRED=2");write_line("TURKOS/OS/K2100-SERVICE-COMPONENT: IPC=2 SHELL=1 VFS=1 CHILD_REAPED=1")');main+='\ninclude!("k2100-process-round.rs");\ncore::arch::global_asm!(include_str!("k2100-process-round.S"));\n';let round=readFileSync('scripts/os-acceptance/k2100-process-round.rs','utf8');const action=' _=>Err("k2100-process-command"),';assert.equal(round.split(action).length,2);round=round.replace(action,' 3..=5=>os_k2100_service_action(table,pid,command),\n'+action);const serviceCall=' os_k2100_process_call(table,current,1)?;';assert.equal(round.split(serviceCall).length,2);round=round.replace(serviceCall,' os_k2100_service_round(table,current)?;\n'+serviceCall);writeFileSync(src+'k2100-process-round.rs',round);copyFileSync('scripts/os-acceptance/k2100-service-component.rs',src+'k2100-service-component.rs');main+='\ninclude!("k2100-service-component.rs");\n';copyFileSync('scripts/os-acceptance/k2100-process-round.S',src+'k2100-process-round.S');writeFileSync(src+'main.rs',main);writeFileSync(src+'runtime/process_table.rs',readFileSync(src+'runtime/process_table.rs','utf8')+'\n'+readFileSync('os-smp-process-wake/src/wake.rs','utf8')+'\n'+readFileSync('os-smp-process-sleep/src/sleep.rs','utf8'));writeFileSync(src+'runtime/process_guest.rs',readFileSync(src+'runtime/process_guest.rs','utf8')+'\n'+readFileSync('scripts/os-acceptance/k2100-process-owner-wait.rs','utf8'));writeFileSync(src+'runtime/smp_workload.rs',readFileSync('os-smp-workload/src/workload.rs','utf8'));writeFileSync(src+'runtime/mod.rs',readFileSync(src+'runtime/mod.rs','utf8')+'\npub mod smp_workload;\n');copyFileSync('/tmp/turkos-k2100-service-component-preflight.mjs',directory+'/harness.mjs.txt'); const env={...process.env,CARGO_TARGET_DIR:join(root,directory,'target'),RUSTFLAGS:'-C opt-level=s -C llvm-args=--enable-machine-outliner=always -C relocation-model=static -C link-arg=-T'+join(root,sources,'kernel/linker.ld')+' -C link-arg=--build-id=none -A warnings'};delete env.CARGO_ENCODED_RUSTFLAGS;const build=spawnSync('cargo',['build','--manifest-path',sources+'/kernel/Cargo.toml','--offline','--release','--target','aarch64-unknown-none','--bin','turkos-kernel','--no-default-features','--features','os-runtime-product'],{env,encoding:'utf8',timeout:600000,maxBuffer:128*1024*1024});writeFileSync(directory+'/compile.log',(build.stdout??'')+(build.stderr??''));const report={status:build.status===0?'NATIVE_MODELS_COMPILED':'NATIVE_MODELS_COMPILE_FAILED',guestAccepted:false,productAccepted:false,sourceExtensions:{processWake:artifact(src+'runtime/process_table.rs'),nativeOwners:artifact(src+'runtime/process_guest.rs'),processRound:artifact(src+'k2100-process-round.rs'),serviceComponent:artifact(src+'k2100-service-component.rs'),processAssembly:artifact(src+'k2100-process-round.S'),workload:artifact(src+'runtime/smp_workload.rs'),modules:artifact(src+'runtime/mod.rs')},scope:'Compile-only integration of current ProcessTable sleep/wake, actual Owners/ThreadTable adapters and workload monitor. One real process component and actual parent/child IPC shell-parser Tmpfs round are wired after the inherited watchdog run. No EL0 service execution is claimed. It does not satisfy combined workload or long duration. Mode helper is explicitly inlined. Exact mode 210 is validated from the same DTB; other modes are rejected. No accepted candidate or guest equivalence claim.',baseCandidate:artifact(basePath),sourceDirectory:sources,sourceMain:artifact(src+'main.rs'),harness:artifact(directory+'/harness.mjs.txt'),transform:{before,after},exitCode:build.status,log:artifact(directory+'/compile.log'),imageSpan:null};if(build.status===0){const elf=directory+'/product.elf';copyFileSync(directory+'/target/aarch64-unknown-none/release/turkos-kernel',elf);const sys=spawnSync('rustc',['--print','sysroot'],{encoding:'utf8'}).stdout.trim(),host=spawnSync('rustc',['-vV'],{encoding:'utf8'}).stdout.match(/^host: (.+)$/m)[1],bin=sys+'/lib/rustlib/'+host+'/bin/';let r=spawnSync(bin+'llvm-objcopy',['-O','binary',elf,directory+'/product.Image'],{encoding:'utf8'});assert.equal(r.status,0);r=spawnSync(bin+'llvm-nm',['-n','-S',elf],{encoding:'utf8',maxBuffer:64*1024*1024});assert.equal(r.status,0);writeFileSync(directory+'/product.nm',r.stdout);const address=n=>parseInt(r.stdout.match(new RegExp('^([a-f0-9]{16}) [a-f0-9]{16} [A-Za-z] '+n+'$','m'))[1],16);report.imageSpan={before:base.imageSpan.bytes,bytes:address('_image_end')-address('_image_start'),maximum:8388608};report.imageSpan.saved=report.imageSpan.before-report.imageSpan.bytes;report.artifacts={elf:artifact(elf),image:artifact(directory+'/product.Image'),nm:artifact(directory+'/product.nm')};} writeFileSync(directory+'/report.json',JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify({status:report.status,report:directory+'/report.json',exitCode:build.status,imageSpan:report.imageSpan}));if(build.status!==0)process.exitCode=1;