feat(router): confirm DexaFlow modes and expose the paired admin interface
This commit is contained in:
@@ -4,9 +4,10 @@ import {createServer} from './support/vite-server.mjs';
|
||||
import {createElement} from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
|
||||
let server,routerMode,RouterOverview,ClientRouterControls;
|
||||
let server,routerMode,RouterOverview,ClientRouterControls,RouterObservation;
|
||||
before(async()=>{
|
||||
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
|
||||
({RouterObservation}=await server.ssrLoadModule('/src/components/network/RouterObservation.tsx'));
|
||||
({routerMode}=await server.ssrLoadModule('../../packages/router-ui/src/mode.ts'));
|
||||
({RouterOverview}=await server.ssrLoadModule('../../packages/router-ui/src/RouterOverview.tsx'));
|
||||
({ClientRouterControls}=await server.ssrLoadModule('../../packages/router-ui/src/ClientRouterControls.tsx'));
|
||||
@@ -29,10 +30,10 @@ test('configured aggregation with three online SIMs remains a direct fallback ob
|
||||
const d=device(),m=routerMode(d,true);
|
||||
assert.equal(m.configured,'Агрегация');assert.equal(m.current,'Прямой выход · SIM3');
|
||||
assert.equal(m.activeSlot,1);assert.equal(m.fallback,true);assert.equal(m.mismatch,true);
|
||||
assert.match(m.message,/Агрегация сейчас не используется/);
|
||||
assert.match(m.message,/Агрегация задана, но сейчас выход идёт через SIM3/);
|
||||
const html=overview(d),form=controls(d);
|
||||
assert.match(html,/Сейчас: Прямой выход · SIM3/);assert.match(html,/Задано: Агрегация/);
|
||||
assert.match(form,/Сейчас: Прямой выход · SIM3/);assert.match(form,/Сохранённый режим/);
|
||||
assert.match(form,/Текущий режим: Прямой выход · SIM3/);assert.match(form,/Сохранённый режим/);
|
||||
assert.ok(form.includes(m.message));assert.ok(html.includes(m.message));
|
||||
assert.equal((html.match(/текущий выход/g)||[]).length,1);
|
||||
assert.doesNotMatch(html,/· выбран|Одна SIM-карта/);
|
||||
@@ -66,7 +67,7 @@ test('pending, stale and strategy states do not masquerade as failed or active a
|
||||
assert.equal(stale.current,'Нет свежих данных');assert.equal(stale.activeSlot,null);
|
||||
assert.equal(stale.fallback,false);assert.equal(stale.pending,false);
|
||||
const html=overview(d,false),form=controls(d,false);
|
||||
for(const x of [html,form])assert.match(x,/Сейчас: Нет свежих данных/);
|
||||
assert.match(html,/Сейчас: Нет свежих данных/);assert.match(form,/Текущий режим: Нет свежих данных/);
|
||||
assert.doesNotMatch(html,/текущий выход|Сейчас: Прямой выход/);
|
||||
for(const configured of ['whitelist','auto']){
|
||||
const m=routerMode({...d,selected_mode:configured,client_api:{...d.client_api,details:{pending:false,fallback:false}}},true);
|
||||
@@ -79,3 +80,28 @@ test('legacy adapters preserve explicit current WAN without claiming fallback',(
|
||||
assert.equal(routerMode(d,true).fallback,false);
|
||||
assert.equal(routerMode({...d,active_wan:''},true).activeSlot,null);
|
||||
});
|
||||
|
||||
test('aggregation fallback names the observed SIM and reported reason',()=>{const d=device();d.client_api.details.fallback_reason='preferred_path_unavailable_observed_other_default_route';const m=routerMode(d,true);assert.match(m.message,/Агрегация задана, но сейчас выход идёт через SIM3/);assert.match(m.message,/путь агрегации недоступен/);});
|
||||
|
||||
test('observation viewport renders three compact scales and only the effective exit',()=>{
|
||||
const d={...device(),state:'ready',attached:true,observed_at:Date.now()/1000};
|
||||
const html=renderToStaticMarkup(createElement(RouterObservation,{device:d,value:{available:true,fresh:true}}));
|
||||
assert.equal((html.match(/router-signal-scale/g)||[]).length,3);
|
||||
assert.equal((html.match(/aria-label="SIM3 · Активный канал"/g)||[]).length,1);
|
||||
assert.doesNotMatch(html,/router-scale-labels|router-metric-line/);
|
||||
assert.match(html,/Прямой выход · SIM3/);
|
||||
assert.ok(html.indexOf('SIM1')<html.indexOf('SIM2'));
|
||||
const stale=renderToStaticMarkup(createElement(RouterObservation,{device:d,value:{available:true,fresh:false}}));
|
||||
assert.doesNotMatch(stale,/Активный канал|Прямой выход/);
|
||||
assert.match(stale,/Нет свежих данных/);
|
||||
});
|
||||
|
||||
test('compact router view retains three SIM rows without scales or summary',()=>{
|
||||
const d={...device(),state:'ready',attached:true,observed_at:Date.now()/1000};
|
||||
const html=renderToStaticMarkup(createElement(RouterObservation,{device:d,value:{available:true,fresh:true},compact:true}));
|
||||
assert.equal((html.match(/<section /g)||[]).length,3);
|
||||
assert.doesNotMatch(html,/router-signal-scale|Прямой выход/);
|
||||
assert.match(html,/aria-label="SIM3 · Активный канал"/);
|
||||
assert.equal((html.match(/data-variant="indicator"/g)||[]).length,3);
|
||||
assert.ok(html.indexOf('SIM1')<html.indexOf('SIM2')&&html.indexOf('SIM2')<html.indexOf('SIM3'));
|
||||
});
|
||||
|
||||
@@ -91,8 +91,8 @@ test('physical SIM labels are a profile projection, never array order or model-n
|
||||
assert.deepEqual(simChannels(device).map(x=>x.slot),[2,3,1]);assert.equal(simLabel(device,2),'SIM1');
|
||||
assert.equal(simChannels({...device,slot_map:null})[0].label,'Канал 1');
|
||||
assert.equal(routerName({...device,name:'My uplink'}),'My uplink');
|
||||
const connected={id:'a',attached:true,state:'ready'},saved={id:'b',attached:false,state:'unreachable'};
|
||||
assert.deepEqual(visibleRouters([saved,connected]),[connected]);
|
||||
const connected={id:'a',attached:true,state:'ready',observed_at:100},saved={id:'b',attached:false,state:'unreachable',observed_at:100};
|
||||
assert.deepEqual(visibleRouters({available:true,items:[saved,connected]},110000),[connected]);
|
||||
});
|
||||
test('Client API controls sort physical SIMs and preserve wire identifiers',async()=>{
|
||||
const {ClientRouterControls}=await server.ssrLoadModule('../../packages/router-ui/src/ClientRouterControls.tsx');
|
||||
@@ -135,3 +135,76 @@ test('signal scale exposes four keyboard targets, an honest current level and no
|
||||
const missing=renderToStaticMarkup(createElement(RouterSignal,{rsrp:null}));
|
||||
assert.doesNotMatch(missing,/class="router-signal-marker"/);assert.match(missing,/Уровень сигнала неизвестен/);
|
||||
});
|
||||
|
||||
|
||||
test('reopened controls retain the policy refusal above timers, despite newer inspections',async()=>{
|
||||
const {ClientRouterControls}=await server.ssrLoadModule('../../packages/router-ui/src/ClientRouterControls.tsx');
|
||||
const d={id:'x',state:'ready',active_mode:'direct',modems:[],client_api:{boot_id:'boot',revision:'r',rights:['policy','recovery'],policy:{mode:'aggregation',fail_seconds:60,recover_seconds:60,min_vpn_seconds:120},checks:[]}};
|
||||
const results=[{operation_id:'inspect',device_id:'x',action:'inspect',state:'complete',at:102},{operation_id:'policy',device_id:'x',action:'policy',state:'error',error:'router_busy',at:101}];
|
||||
const render=()=>renderToStaticMarkup(createElement(ClientRouterControls,{device:d,value:{control_version:1,runtime_id:'r',results},transport:{},ready:true}));
|
||||
for(const html of [render(),render()]){
|
||||
assert.match(html,/busy/);assert.match(html,/Сохранённый режим/);assert.doesNotMatch(html,/Не применён|Политика сохранена и применена/);
|
||||
assert.ok(html.indexOf('(busy)')<html.indexOf('Ожидание отказа, с'));
|
||||
assert.ok(html.indexOf('(busy)')<html.indexOf('Восстановление соединения'));
|
||||
}
|
||||
});
|
||||
|
||||
test('policy progress follows receipts and never turns missing or fallback routes into success',async()=>{
|
||||
const {policyFeedback}=await server.ssrLoadModule('../../packages/router-ui/src/control.ts');
|
||||
const device={selected_mode:'aggregation',active_mode:'aggregation',modems:[],client_api:{policy:{mode:'aggregation'},details:{pending:false}}};
|
||||
const receipt={operation_id:'one',device_id:'x',action:'policy',state:'queued'};
|
||||
assert.match(policyFeedback(device,true,receipt).label,/Команда отправлена/);
|
||||
assert.equal(policyFeedback(device,true,receipt).busy,true);
|
||||
assert.match(policyFeedback(device,true,{...receipt,state:'applying'}).label,/Применяются/);
|
||||
assert.equal(policyFeedback(device,true,{...receipt,state:'complete'}).tone,'success');
|
||||
assert.match(policyFeedback(device,true,{...receipt,state:'complete'}).message,/Агрегация/);
|
||||
for(const state of ['error','unknown']){
|
||||
const result=policyFeedback(device,true,{...receipt,state,error:'router_busy'});
|
||||
assert.equal(result.busy,false);assert.equal(result.tone,'warning');
|
||||
}
|
||||
const offline=policyFeedback(device,false,{...receipt,state:'applying'});
|
||||
assert.equal(offline.busy,false);assert.match(offline.label,/Нет свежих данных/);
|
||||
const fallback={...device,active_mode:'direct',active_slots:[1],client_api:{...device.client_api,details:{fallback:true}}};
|
||||
assert.equal(policyFeedback(fallback,true,{...receipt,state:'complete'}).tone,'warning');
|
||||
assert.match(policyFeedback(fallback,true,{...receipt,state:'complete'}).message,/Агрегация задана, но сейчас выход идёт через/);
|
||||
const settling={...device,client_api:{...device.client_api,details:{pending:true}}};
|
||||
assert.equal(policyFeedback(settling,true,{...receipt,state:'complete'}).tone,'warning');
|
||||
assert.equal(policyFeedback(device,false,{...receipt,state:'complete'}).tone,'warning');
|
||||
});
|
||||
|
||||
test('queued and applying policy show one canonical action loader and visible status after reopening',async()=>{
|
||||
const {ClientRouterControls}=await server.ssrLoadModule('../../packages/router-ui/src/ClientRouterControls.tsx');
|
||||
const device={id:'x',state:'ready',active_mode:'direct',modems:[],client_api:{boot_id:'b',revision:'r',rights:['policy','recovery','diagnostics','reboot'],policy:{mode:'aggregation',fail_seconds:60,recover_seconds:60,min_vpn_seconds:120},checks:[]}};
|
||||
for(const state of ['queued','applying','complete','error','unknown']){
|
||||
const results=[{operation_id:'one',device_id:'x',action:'policy',state,at:100,error:state==='error'?'router_busy':undefined}];
|
||||
const html=renderToStaticMarkup(createElement(ClientRouterControls,{device,value:{control_version:1,runtime_id:'r',results},transport:{},ready:true}));
|
||||
const pending=['queued','applying'].includes(state);
|
||||
assert.equal((html.match(/aria-busy="true"/g)||[]).length,pending?1:0);
|
||||
assert.ok(html.indexOf('role="status"')<html.indexOf('Ожидание отказа, с'));
|
||||
if(pending){assert.doesNotMatch(html,/Не применён|Изменения ещё не применены/);assert.match(html,/disabled/);}
|
||||
}
|
||||
});
|
||||
test('receipts survive out-of-order snapshots without mixing devices, actions or old successes',async()=>{
|
||||
const {latestControlReceipt,controlMessage}=await server.ssrLoadModule('../../packages/router-ui/src/control.ts');
|
||||
const base={operation_id:'old',device_id:'a',action:'policy',state:'complete',at:100};
|
||||
const refused={...base,operation_id:'new',state:'error',error:'router_busy',at:102};
|
||||
const rows=[{...refused,device_id:'other',at:500},{...base,action:'inspect',at:600},refused,base];
|
||||
assert.deepEqual(latestControlReceipt(rows,'a','policy'),refused);
|
||||
assert.deepEqual(latestControlReceipt([{...refused,state:'applying'}],'a','policy',refused),refused);
|
||||
assert.deepEqual(latestControlReceipt([refused],'a','policy',{...refused,state:'queued',at:103}),refused);
|
||||
assert.equal(latestControlReceipt(rows,'absent','policy'),null);
|
||||
assert.match(controlMessage({state:'applying',error:'receipt_pending'}),/повторная команда не отправляется/);
|
||||
assert.doesNotMatch(controlMessage({state:'unknown',action:'policy'}),/сохранена и применена/);
|
||||
});
|
||||
|
||||
test('lost control response waits for the same receipt and never replays the write',async()=>{
|
||||
const {sendControlOnce,controlBusy}=await server.ssrLoadModule('../../packages/router-ui/src/control.ts');
|
||||
const initial={operation_id:'one',device_id:'router',action:'policy',state:'queued',at:100};
|
||||
let writes=0;
|
||||
const uncertain=await sendControlOnce({control:async()=>{writes++;throw Error('response lost');}}, {operation_id:'one'},initial);
|
||||
assert.equal(writes,1);assert.equal(uncertain.operation_id,'one');assert.equal(uncertain.error,'receipt_pending');assert.equal(controlBusy(uncertain),true);
|
||||
const refused=await sendControlOnce({control:async()=>({operation_id:'one',state:'error',error:'router_busy'})},{operation_id:'one'},initial);
|
||||
assert.equal(refused.action,'policy');assert.equal(controlBusy(refused),false);
|
||||
const accepted=await sendControlOnce({control:async()=>({operation_id:'one',state:'queued'})},{operation_id:'one'},initial);
|
||||
assert.equal(controlBusy(accepted),true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user