Files
NODEDC_MISSION_CORE/apps/control-station/test/vescConfigurationDelivery.test.mjs
DCCONSTRUCTIONS f32c7b400b feat(vesc): extend motor diagnostics, configuration and transport recovery
Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
2026-10-29 09:09:59 +03:00

64 lines
4.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {build} from 'esbuild';
const bundled=await build({stdin:{contents:`export {useVescRead} from '../../plugins/vesc/frontend/src/useVescRead';
export {useVescEditor} from '../../plugins/vesc/frontend/src/useVescEditor';`,resolveDir:process.cwd(),loader:'ts'},
bundle:true,write:false,platform:'node',format:'esm',plugins:[{name:'react-fixture',setup(b){
b.onResolve({filter:/^react$/},()=>({path:'react',namespace:'fixture'}));
b.onLoad({filter:/.*/,namespace:'fixture'},()=>({contents:`export const useRef=v=>({current:v});
export const useEffect=f=>f();export const useState=v=>{const i=globalThis.vescFixture.index++;
return [i===0&&globalThis.vescFixture.preview?globalThis.vescFixture.preview:v,
next=>globalThis.vescFixture.writes.push(next)];};`}));
}}]});
const {useVescRead,useVescEditor}=await import('data:text/javascript;base64,'+Buffer.from(bundled.outputFiles[0].contents).toString('base64'));
async function fixture(run,{delay=45000,outcome='complete',preview=null}={}){
const oldNow=Date.now,oldTimeout=globalThis.setTimeout,oldFixture=globalThis.vescFixture;
let now=1000000;Date.now=()=>now;globalThis.setTimeout=f=>{now+=1000;queueMicrotask(f);return 0;};
const state={index:0,writes:[],preview};globalThis.vescFixture=state;
const submitted=[],polled=[],errors=[],result={verified:true,preview_id:'cfg_synthetic'};
const props={enabled:true,blocked:false,onBusyChange:()=>{},failure:e=>{if(e)errors.push(e);},refresh:async()=>{},
device:{id:'synthetic',online:true,verified:true,snapshot:{context:{session_id:'attachment'}},
vesc_status:{readable:true,configuration_edit_supported:true}},
transport:{submit:async c=>{submitted.push(c);now+=delay;return {state:'queued'};},
operation:async id=>{polled.push(id);return {state:outcome,result};}}};
try{await run({props,submitted,polled,errors,state,result});}
finally{Date.now=oldNow;globalThis.setTimeout=oldTimeout;
if(oldFixture===undefined)delete globalThis.vescFixture;else globalThis.vescFixture=oldFixture;}
}
test('configuration read survives a paced delivery longer than the former 30 second budget',async()=>fixture(async f=>{
await useVescRead(f.props,'vesc.configuration.read').read();
assert.deepEqual(f.errors,[]);assert.ok(f.state.writes.includes(f.result));
assert.equal(f.submitted.length,1);assert.deepEqual(f.polled,[f.submitted[0].operation_id]);
assert.equal(Date.parse(f.submitted[0].deadline_at)-Date.parse(f.submitted[0].requested_at),180000);
}));
test('ordinary telemetry reads retain their short budget',async()=>fixture(async f=>{
await useVescRead(f.props,'vesc.telemetry.read').read();
assert.equal(f.submitted.length,1);assert.equal(f.errors.length,1);assert.deepEqual(f.polled,[]);
assert.equal(Date.parse(f.submitted[0].deadline_at)-Date.parse(f.submitted[0].requested_at),30000);
}));
test('preview and reconciliation use the configuration delivery budget',async()=>{
for(const method of ['prepare','reconcile'])await fixture(async f=>{
await useVescEditor(f.props)[method]({kind:'motor',changes:{l_current_max:100}});
assert.deepEqual(f.errors,[]);assert.equal(f.submitted.length,1);assert.ok(f.state.writes.includes(f.result));
});
});
test('apply waits for its own late receipt without resending a write',async()=>fixture(async f=>{
await useVescEditor(f.props).apply();
assert.deepEqual(f.errors,[]);assert.equal(f.submitted.length,1);
assert.equal(f.submitted[0].action_id,'vesc.configuration.apply');
assert.deepEqual(f.submitted[0].parameters,{preview_id:'cfg_synthetic',rig_clear:true,inputs_isolated:true});
assert.deepEqual(f.polled,[f.submitted[0].operation_id]);assert.ok(f.state.writes.includes(f.result));
},{delay:75000,preview:{preview_id:'cfg_synthetic'}}));
test('unknown apply result stays unconfirmed and never resubmits the write',async()=>fixture(async f=>{
await useVescEditor(f.props).apply();
assert.equal(f.errors.length,1);assert.equal(f.submitted.length,1);
assert.equal(f.state.writes.includes(f.result),false);
},{outcome:'unknown',preview:{preview_id:'cfg_synthetic'}}));
test('configuration wait is bounded',async()=>fixture(async f=>{
await useVescRead(f.props,'vesc.configuration.read').read();
assert.equal(f.errors.length,1);assert.equal(f.submitted.length,1);assert.deepEqual(f.polled,[]);
},{delay:191000}));