import test from 'node:test'; import assert from 'node:assert/strict'; import {build} from 'esbuild'; const result=await build({entryPoints:[new URL('../src/core/simulation/plannerActions.ts',import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'esm'}); const {plannerActions}=await import('data:text/javascript;base64,'+Buffer.from(result.outputFiles[0].contents).toString('base64')); const points=[{id:'start',position:[0,0,0]},{id:'finish',position:[3,1,0]}]; const route={sha256:'route-v1'}; const plan={points,editor_cache_key:'scene-v1',robot_sha256:'robot-v1',prepared_route:route}; const input={draft:{cache:{key:'scene-v1'},points},robot:{sha256:'robot-v1'},plan:undefined,routeRequired:true, route:null,routeKey:null,busy:false,runtimeAvailable:true,inferenceReady:true,activeRun:false}; const state=changes=>plannerActions({...input,...changes}); const none={save:false,prepare:false,launch:false}; test('no draft, robot, start or finish means no route actions, even for legacy scenes',()=>{ assert.deepEqual(state({draft:null}),none); assert.deepEqual(state({robot:undefined}),none); for(const points of [[],input.draft.points.slice(0,1)])for(const routeRequired of [true,false]) assert.deepEqual(state({draft:{...input.draft,points},routeRequired}),none); }); test('two points offer calculation; an admitted route offers save and launch',()=>{ assert.deepEqual(state({}),{save:false,prepare:true,launch:false}); assert.deepEqual(state({route,routeKey:'key'}),{save:true,prepare:false,launch:true}); assert.equal(state({route,routeKey:null}).launch,false); }); test('loading, saving and undoing to the saved task hide save without hiding launch',()=>{ const saved={route,routeKey:'key',plan}; assert.deepEqual(state(saved),{save:false,prepare:false,launch:true}); const changed=structuredClone(points);changed[1].position[2]=.2; assert.deepEqual(state({...saved,draft:{...input.draft,points:changed},route:null,routeKey:null}),{save:false,prepare:true,launch:false}); assert.equal(state(saved).save,false); assert.equal(state({...saved,route:{sha256:'route-v2'}}).save,true); }); test('busy commands hide other actions; offline or occupied Worker prevents launch',()=>{ assert.deepEqual(state({route,routeKey:'key',busy:true}),none); assert.deepEqual(state({runtimeAvailable:false}),none); for(const condition of [{runtimeAvailable:false},{inferenceReady:false},{activeRun:true}]) assert.deepEqual(state({route,routeKey:'key',...condition}),{save:true,prepare:false,launch:false}); });