feat(mcp): подготовить сервер и доступ к приёмке

This commit is contained in:
Denozordec committed 2026-11-03 03:12:03 +07:00
commit bf3d50e1ff
3835 files changed
+537122

No files matched your search

@@ -0,0 +1,28 @@
// Pure calculation in a child process: no API, database, browser or network operations.
import assert from 'node:assert/strict'
import { spawnSync } from 'node:child_process'
const variant=process.argv[2] ?? 'equal';
const probeCount=Number(process.argv[3] ?? 20);
if(!Number.isInteger(probeCount)||probeCount<20||probeCount>1000)throw new Error('Probe count must be an integer from 20 to 1000');
if(!['equal','varied','freshness'].includes(variant)) throw new Error('Use equal, varied or freshness');
const code = `
const fs=require('node:fs'),ts=require('typescript');
const source=ts.transpileModule(fs.readFileSync('lib/route-optimizer-data.ts','utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022}}).outputText;
const mod={exports:{}};new Function('exports','require','module',source)(mod.exports,require,mod);
const {buildLiveOptimizerData,DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS}=mod.exports;
const common={host:'192.0.2.1',enabled:true,status:'online',latency:10,country:'RU',site:'TEST',model:'CHR'};
const rows=[{...common,id:1,name:'Home',type:'home-router',wanUplinks:Array.from({length:7},(_,i)=>({id:'wan'+i,name:'WAN'+i,isp:'ISP',iface:'ether'+i,ip:'198.51.100.1',maxDl:100,maxUl:100}))},{...common,id:2,name:'Jump',type:'jump-host'}];
const probes=Array.from({length:${probeCount}},(_,i)=>({id:'p'+i,srcServerId:'1',dstServerId:'2',srcInterface:'',dstInterface:'',enabled:true,lastPingRttMs:10,lastPingLossPct:0,lastTxAvgMbps:100,lastRxAvgMbps:100,lastPingAt:null}));
if(${JSON.stringify(variant)}==='varied') probes.forEach((p,i)=>{if(i<13)p.lastRxAvgMbps=null;if(i<6)p.lastTxAvgMbps=null});
if(${JSON.stringify(variant)}==='freshness') probes.forEach((p,i)=>{p.lastPingAt=new Date(Date.now()-(${probeCount}-i)*3600000).toISOString()});
const start=performance.now();const result=buildLiveOptimizerData(rows,[],DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS,probes);
console.log(JSON.stringify({elapsedMs:performance.now()-start,legs:result.homes[0].wanJhLegs.length,probeIds:result.homes[0].wanJhLegs.map(leg=>leg.observed.probeId)}));
`;
const start=performance.now();
const result=spawnSync(process.execPath,['-e',code],{cwd:process.cwd(),timeout:10000,encoding:'utf8',windowsHide:true});
const profile={variant,wanCount:7,probeCount,timeoutMs:10000,elapsedMs:Math.round(performance.now()-start),status:result.status,timedOut:result.error?.code==='ETIMEDOUT',result:result.stdout.trim(),error:result.stderr.trim()};
console.log(JSON.stringify(profile,null,2));
if(result.error && !profile.timedOut) throw result.error;
if(result.status !== 0 && !profile.timedOut) process.exitCode=1;
if(result.status===0){const measured=JSON.parse(result.stdout);assert.deepEqual(measured.probeIds,Array.from({length:7},(_,i)=>'p'+(variant==='equal'?i:variant==='freshness'?i+probeCount-7:i+13)))}
@@ -0,0 +1,25 @@
// Bounded pure full-route calculation: no API, database, network or browser.
import {spawnSync} from 'node:child_process'
import assert from 'node:assert/strict'
const args=process.argv.slice(2)
if(args.length&&args.length!==3)throw new Error('Provide exactly three dimensions')
const [wanCount,jhCount,exitCount]=args.length?args.map(Number):[10,100,100]
const combinations=wanCount*jhCount*exitCount
if([wanCount,jhCount,exitCount].some(n=>!Number.isInteger(n)||n<0||n>1000)||jhCount<1||exitCount<1||!Number.isFinite(combinations)||combinations>100000||jhCount*exitCount>100000)throw new Error('WAN0..1000, JH/Exit1..1000; products <=100000')
const code=`
const fs=require('node:fs'),ts=require('typescript');
const source=ts.transpileModule(fs.readFileSync('lib/route-optimizer-data.ts','utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022}}).outputText;
const mod={exports:{}};new Function('exports','require','module',source)(mod.exports,require,mod);
const {buildLiveOptimizerData,DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS}=mod.exports;
const common={host:'192.0.2.1',enabled:true,status:'online',latency:10,country:'RU',site:'TEST',model:'CHR'};
const rows=[{...common,id:1,name:'Home',type:'home-router',wanUplinks:Array.from({length:${wanCount}},(_,i)=>({id:'w'+i,name:'WAN'+(i+1),iface:'ether'+(i+1),isp:'ISP',ip:'198.51.100.1',maxDl:100,maxUl:100}))},...Array.from({length:${jhCount}},(_,i)=>({...common,id:i+2,name:'Jump'+i,type:'jump-host'})),...Array.from({length:${exitCount}},(_,i)=>({...common,id:i+2+${jhCount},name:'Exit'+i,type:'exit-node'}))];
const before=process.memoryUsage().heapUsed,start=performance.now();const entry=buildLiveOptimizerData(rows,[],DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS).homes[0];
console.log(JSON.stringify({elapsedMs:performance.now()-start,heapDeltaBytes:process.memoryUsage().heapUsed-before,wanJhLegs:entry.wanJhLegs.length,routes:entry.fullRoutes.length,firstId:entry.fullRoutes[0]?.id,lastId:entry.fullRoutes.at(-1)?.id,bestMatchesFirst:entry.bestRoute===(entry.fullRoutes[0]??null),missingObservations:entry.fullRoutes.every(route=>route.hw.observed.probeId===null&&route.je.observed.probeId===null)}));
`;
const start=performance.now(),r=spawnSync(process.execPath,['--max-old-space-size=256','-e',code],{cwd:process.cwd(),timeout:10000,encoding:'utf8',windowsHide:true,maxBuffer:16384});
const result=r.status===0?JSON.parse(r.stdout):null;
const profile={wanCount,jhCount,exitCount,combinations,memoryCapMb:256,timeoutMs:10000,totalMs:Math.round(performance.now()-start),status:r.status,timedOut:r.error?.code==='ETIMEDOUT',result,error:r.stderr.slice(0,2000)};
console.log(JSON.stringify(profile,null,2));
if(result){assert.equal(result.routes,combinations);assert.equal(result.wanJhLegs,wanCount*jhCount);assert.equal(result.firstId,combinations?`1-w0-2-${jhCount+2}`:undefined);assert.equal(result.lastId,combinations?`1-w${wanCount-1}-${jhCount+1}-${jhCount+exitCount+1}`:undefined);assert.equal(result.bestMatchesFirst,true);assert.equal(result.missingObservations,true)}
if(r.error&&!profile.timedOut)throw r.error;
if(r.status!==0&&!profile.timedOut)process.exitCode=1;