feat(k1): add USB networking, device management and acquisition recovery

This commit is contained in:
DCCONSTRUCTIONS
2026-11-04 00:42:57 +03:00
parent 14c3c7c2b6
commit 038337783f
78 changed files with 4612 additions and 384 deletions
@@ -4,10 +4,11 @@ import {createElement} from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import {createServer} from './support/vite-server.mjs';
let server,Detail,presentation,enrolledDevice;
let server,Detail,presentation,enrolledDevice,ObservationAction;
before(async()=>{
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
({K1Detail:Detail}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/K1Detail.tsx'));
({K1ObservationAction:ObservationAction}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/K1ObservationAction.tsx'));
presentation=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/presentation.ts');
({enrolledDevice}=await server.ssrLoadModule('../../packages/sensor-ui/src/contracts.ts'));
});
@@ -88,3 +89,47 @@ test('completed scan with healthy control remains connected and permits a named
assert.doesNotMatch(markup,/Проверить состояние K1|Подключить устройство|Устройство остановлено/);
assert.equal(presentation.k1Status(stopped,false).tone,'neutral');
});
test('observation Play only opens configuration; active acquisition offers its existing controls',()=>{
let opened=0;
const action=ObservationAction({device,fresh:true,configure:()=>opened++});
assert.equal(action.props.label,'Начать сканирование K1');assert.equal(action.props.children.props.name,'play');
action.props.onClick();assert.equal(opened,1);
assert.equal(ObservationAction({device,fresh:false,configure:()=>opened++}),null);
const active={...device,snapshot:{...device.snapshot,acquisition:'streaming'}};
let stopped=0;const stop=ObservationAction({device:{...active,control:{...active.control,can_stop:true}},fresh:true,stop:()=>stopped++});
assert.equal(stop.props.label,'Остановить сканирование K1');stop.props.onClick();assert.equal(stopped,1);assert.equal(opened,1);
});
test('observation configuration preserves START fields and STOP without a duplicate media viewer',()=>{
for(const acquisition of ['idle','starting','streaming','stopping']){
const value={...device,snapshot:{...device.snapshot,acquisition}};
const markup=renderToStaticMarkup(createElement(Detail,{device:value,enabled:true,previewEnabled:false,backLabel:'Вернуться к наблюдению',transport:{},back:()=>{},refresh:async()=>{},failure:()=>{},createRerunHost:()=>assert.fail('must not allocate another viewer')}));
assert.match(markup,/Вернуться к наблюдению/);assert.doesNotMatch(markup,/rerun-viewport__canvas|Открыть пространственную сцену/);
if(acquisition==='idle')assert.match(markup,/Название проекта/);
if(acquisition==='streaming')assert.match(markup,/Остановить устройство/);
}
});
test('observation gear contains only acquisition controls, including before START',()=>{
for(const acquisition of ['idle','streaming']){
const value={...device,snapshot:{...device.snapshot,acquisition}};
const markup=renderToStaticMarkup(createElement(Detail,{device:value,enabled:true,previewEnabled:false,sceneProfile:{view:'plan',save:()=>{}},transport:{},back:()=>{},refresh:async()=>{},failure:()=>{}}));
assert.doesNotMatch(markup,/Размер точки|Атрибут цвета|Палитра|rerun-viewport__canvas/);
if(acquisition==='idle')assert.match(markup,/Название проекта/);
else assert.match(markup,/Остановить устройство/);
}
});
test('K1 storage shows used percentage and expires independently of a fresh inventory',()=>{
const now=Date.now(),observed_at=new Date(now-1000).toISOString();
const almostFull={...device,storage_status:{used_percent:98.99,observed_at}};
assert.equal(presentation.k1StorageStatus(almostFull,true,now+18000).tone,'warning');
const status=presentation.k1StorageStatus(almostFull,true,now);
assert.equal(status.tone,'warning');assert.match(status.label,/занято 99 %.*мало свободного места/);
assert.match(render(almostFull),/Хранилище K1: занято 99 %/);
for(const [value,fresh,at] of [[almostFull,false,now],[{...almostFull,online:false},true,now],[almostFull,true,now+20000],[{...device,storage_status:null},true,now]]){
const unavailable=presentation.k1StorageStatus(value,fresh,at);
assert.equal(unavailable.tone,'neutral');assert.match(unavailable.label,/нет свежих данных/);assert.doesNotMatch(unavailable.label,/99/);
}
assert.equal(presentation.k1StorageStatus({...device,storage_status:{used_percent:0,observed_at}},true,now).tone,'neutral');
});