import fs from 'node:fs';import assert from 'node:assert/strict';import {Actor,fk,Environment,dls} from './core.js'; const bytes=fs.readFileSync(new URL('./actor.bin',import.meta.url));const actor=new Actor(bytes.buffer.slice(bytes.byteOffset,bytes.byteOffset+bytes.byteLength));const config=JSON.parse(fs.readFileSync(new URL('./kinematics.json',import.meta.url)));const fixtures=JSON.parse(fs.readFileSync(new URL('./runtime-fixtures.json',import.meta.url)));let maxAction=0,maxFK=0; for(const f of fixtures){const action=actor.predict(f.observation);maxAction=Math.max(maxAction,...Array.from(action,(v,i)=>Math.abs(v-f.action[i])));const p=fk(config,f.angles);maxFK=Math.max(maxFK,...p.map((v,i)=>Math.abs(v-f.position[i])));}assert(maxAction<1e-4);assert(maxFK<2e-7);const cases=JSON.parse(fs.readFileSync(new URL('./cases.json',import.meta.url)));let results=[];for(const controller of ['sac','dls']){const env=new Environment(config,cases[0].target);while(!env.done){const o=env.observation();env.step(controller==='sac'?actor.predict(o):dls(config,o));}assert(env.steps<=800);assert(Number.isFinite(env.rms));results.push({controller,steps:env.steps,success:env.success,rms:env.rms});}const report={fixture_count:fixtures.length,max_absolute_action_difference:maxAction,max_fk_difference_m:maxFK,live_runs:results};fs.writeFileSync(new URL('./runtime-validation.json',import.meta.url),JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify(report));