feat(system): add worker and VPS catalogs with guarded local removal

This commit is contained in:
DCCONSTRUCTIONS
2026-11-10 01:11:24 +03:00
parent ad5a929e06
commit e8025bc99f
25 changed files with 1556 additions and 116 deletions
@@ -0,0 +1,49 @@
import assert from 'node:assert/strict';
import React from 'react';
import {before,after,test} from 'node:test';
import {createServer} from './support/vite-server.mjs';
let server,Navigation,Workers,availability;
before(async()=>{
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true,hmr:false}});
({SystemNavigationPanel:Navigation}=await server.ssrLoadModule('/src/components/system/SystemNavigationPanel.tsx'));
({WorkersWorkspace:Workers}=await server.ssrLoadModule('/src/workspaces/system/WorkersWorkspace.tsx'));
availability=await server.ssrLoadModule('/src/core/system/servers.ts');
});
after(async()=>{await server?.close();});
function withHooks(hooks,fn){const internals=React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,previous=internals.H;internals.H=hooks;try{return fn();}finally{internals.H=previous;}}
function find(tree,predicate){if(!tree)return null;if(Array.isArray(tree)){for(const item of tree){const r=find(item,predicate);if(r)return r;}return null;}if(typeof tree!=='object')return null;if(predicate(tree))return tree;return find(tree.props?.children,predicate)??find(tree.props?.actions,predicate);}
test('system category returns to catalog from worker detail and has no global add action',()=>{
const selected=[];
const tree=Navigation({title:'System',activeId:'network',onNavigate:id=>selected.push(id),onClose:()=>{}});
assert.deepEqual(tree.props.contexts.map(x=>x.id),['workers','vps']);
assert.equal(tree.props.contexts[0].active,true);
assert.equal(tree.props.headerActions,undefined);
tree.props.contexts[0].onSelect();tree.props.contexts[1].onSelect();
assert.deepEqual(selected,['workers','vps']);
});
test('worker eye selects the requested worker before opening telemetry; settings does not navigate',()=>{
const events=[],states=[];
const store={contours:[{contour_id:'one',display_name:'First',expected_node_id:'node-a'},{contour_id:'two',display_name:'Second',expected_node_id:'node-b'}],selectContour:id=>events.push(id),refresh:()=>{},loading:false,error:null};
const tree=withHooks({useContext:()=>store,useState:()=>[undefined,value=>states.push(value)]},()=>Workers({onView:()=>events.push('view')}));
const eye=find(tree,x=>x.props?.label==='Посмотреть воркер: Second');
eye.props.onClick();assert.deepEqual(events,['two','view']);
const settings=find(tree,x=>x.props?.label==='Настройки воркера: First');
settings.props.onClick();assert.deepEqual(states,['one']);assert.deepEqual(events,['two','view']);
find(tree,x=>x.props?.label==='Добавить воркер').props.onClick();assert.equal(states.at(-1),null);
});
test('service readiness is not liveness; expired and wrong-service observations never show online',()=>{
const service={kind:'wireguard',id:'one',state:'ready',last_seen:100};
const now=Date.now()/1000;
assert.equal(availability.serviceAvailability(service,[],now).online,false);
assert.equal(availability.serviceAvailability(service,[{kind:'wireguard',id:'other',state:'online',checked_at:now}],now).online,false);
const observed={kind:'wireguard',id:'one',state:'online',checked_at:now};
assert.equal(availability.serviceAvailability(service,[observed],now).online,true);
assert.equal(availability.serviceAvailability(service,[observed],now+41).online,false);
const host={services:[service,{kind:'arnavi',id:'two'}]};
assert.equal(availability.serverAvailability(host,[observed]).tone,'warning');
assert.equal(availability.serverAvailability(host,[observed,{kind:'arnavi',id:'two',state:'online',checked_at:now}]).tone,'success');
assert.equal(availability.serverAvailability(host,[]).tone,'neutral');
});