Add portable shared WireGuard profiles while retaining Tailscale and Worker boundaries. Bound rover command/telemetry delivery, recovery and diagnostic capture across Core and Node.
22 lines
1.7 KiB
JavaScript
22 lines
1.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {build} from 'esbuild';
|
|
const compiled=await build({entryPoints:[new URL('../src/core/fleet/roverRecovery.ts',import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'esm'});
|
|
const {RoverRecovery}=await import('data:text/javascript;base64,'+Buffer.from(compiled.outputFiles[0].contents).toString('base64'));
|
|
const settings={currentA:30,speed:70,mode:'duty'};
|
|
const initial={fresh:true,controlling:false,snapshot:{supported:true,control_modes:['rpm','duty'],instance:'stable-driver',state:'stopped',release_confirmed:true,session_id:null,profile:{layout:'1x1',bindings:{}},devices:['left','right'].map(uuid=>({uuid,session_id:'usb-'+uuid,age_ms:10,values:{erpm:0,fault_code:0}}))}};
|
|
|
|
test('ten consecutive network stops keep one operator request and never rearm before settled release',()=>{
|
|
const r=new RoverRecovery();r.remember(settings,initial);
|
|
for(let run=0;run<10;run++){
|
|
const id='session-'+run,at=run*20000;
|
|
r.started(id);r.connected(at);assert.equal(r.interrupt(at+100,id),true);
|
|
const stopping={...initial,snapshot:{...initial.snapshot,session_id:id,state:'stopping',release_confirmed:false,last_stop:{session_id:id,state:'stopping',message:'Release not yet observed'}}};
|
|
for(let t=at+200;t<at+10000;t+=200){assert.equal(r.blocker(stopping),null);assert.equal(r.next(stopping,t,true),null);assert.equal(r.waiting,true);}
|
|
const settled={...stopping,snapshot:{...stopping.snapshot,state:'stopped',release_confirmed:true,last_stop:{...stopping.snapshot.last_stop,recovered_at:'observed'}}};
|
|
assert.equal(r.next(settled,at+10000,true),null);
|
|
assert.deepEqual(r.next(settled,at+10600,true),settings);
|
|
}
|
|
r.clear();assert.equal(r.next(initial,1e6,true),null);
|
|
});
|