feat(web-ui): 新增首页启动器与地图遮挡感知交互 - 添加首页卡片式应用启动器界面,包含实时视图、登记、 设置三个入口及对应 SVG 图标资源 - 地图组件新增 ResizeObserver 自动适配容器尺寸变化 - 地图组件引入遮挡区域(occlusion)管理,聚焦时自动 计算可见填充偏移,避免目标被面板遮挡 - 将地图加载事件从 load 改为 style.load,提升初始化 可靠性 - 扩展 metrics 接口,返回选中目标像素坐标、遮挡状态、 画布尺寸等运行时诊断信息 - 补充 web-sys features(HtmlImageElement, Storage, PointerEvent, DomRect 等)以支持新 UI 交互 - index.html 新增 workspace/home/registry 样式及资源引用 - .gitignore 忽略 previews 目录与本地编译产物 ```
64 lines
8.7 KiB
JavaScript
64 lines
8.7 KiB
JavaScript
// Isolated real server + browser/Worker/GPU integration. Never uses production data.
|
|
import {mkdtemp,writeFile} from 'node:fs/promises';
|
|
import {tmpdir} from 'node:os';
|
|
import path from 'node:path';
|
|
import {spawn,execFileSync} from 'node:child_process';
|
|
import {createRequire} from 'node:module';
|
|
import assert from 'node:assert/strict';
|
|
const require=createRequire(import.meta.url);const {chromium}=require('playwright');
|
|
const root=await mkdtemp(path.join(tmpdir(),'RID-realtime-'));
|
|
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
|
const count=Number(process.env.RID_TARGETS||1000);const duration=Number(process.env.RID_SOAK_SECONDS||10);
|
|
assert.ok(count>0&&count<=10000&&duration>0&&duration<=7200);
|
|
const base='http://127.0.0.1:8787';
|
|
let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(1000)});occupied=true;}catch{}
|
|
if(occupied)throw Error('8787 occupied; refusing to attach to another server');
|
|
const child=spawn(exe,['--data-root',root,'--simulation-api'],{windowsHide:true,stdio:['ignore','pipe','pipe']});let output='';let failure;
|
|
child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>failure=e);let browser;let monitorHandle;let simulatorProcess;
|
|
try{
|
|
let ready=false;for(let i=0;i<150;i++){if(failure||child.exitCode!==null)throw Error(output||String(failure));try{if((await fetch(base+'/api/realtime/status')).ok){ready=true;break;}}catch{}await new Promise(r=>setTimeout(r,100));}assert.ok(ready);
|
|
const bad=await fetch(base+'/api/realtime/ingest',{method:'POST',headers:{'content-type':'application/json',origin:'https://foreign.example'},body:'[]'});assert.equal(bad.status,403);
|
|
browser=await chromium.launch({headless:true,executablePath:process.env.RID_BROWSER_PATH||'C:/Program Files/Google/Chrome/Application/chrome.exe'});
|
|
const page=await browser.newPage({viewport:{width:1440,height:940}});const errors=[];page.on('pageerror',e=>errors.push(e.message));
|
|
await page.goto(base+'/realtime');await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();
|
|
let accepted=0,sequence=0;const started=performance.now();const latency=[];
|
|
const samples=[];let lastProgress=0;
|
|
if(duration>=60)console.log(JSON.stringify({started:{root,targets:count,durationSeconds:duration,inputFormat:process.env.RID_INPUT_FORMAT||'json'}}));
|
|
let simulationReport=null;
|
|
const performanceSession=await page.context().newCDPSession(page);await performanceSession.send('Performance.enable');
|
|
let sampling=false;const monitor=monitorHandle=setInterval(async()=>{if(sampling)return;sampling=true;try{const m=await performanceSession.send('Performance.getMetrics');const status=await(await fetch(base+'/api/realtime/status')).json();const env={...process.env};delete env.PSModulePath;const privateBytes=Number(execFileSync('powershell',['-NoProfile','-Command',`(Get-Process -Id ${child.pid}).PrivateMemorySize64`],{encoding:'utf8',windowsHide:true,env}).trim());const sample={elapsedMs:performance.now()-started,serverPrivateBytes:privateBytes,browserJsHeapBytes:m.metrics.find(x=>x.name==='JSHeapUsedSize')?.value,activeTargets:status.metrics.active_targets,accepted:status.metrics.accepted};sample.map=await page.evaluate(()=>window.ridMap.metrics());samples.push(sample);if(duration>=60){await writeFile(path.join(root,'progress.json'),JSON.stringify(sample));if(sample.elapsedMs-lastProgress>=60000){lastProgress=sample.elapsedMs;console.log(JSON.stringify({progress:sample}));}}}catch(e){samples.push({samplingError:String(e)});}finally{sampling=false;}},10000);
|
|
|
|
if(process.env.RID_INPUT_FORMAT==='binary'){
|
|
const simulator=simulatorProcess=spawn(path.join(path.dirname(exe),'rid-simulator.exe'),['--targets',String(count),'--interval-ms',process.env.RID_INTERVAL_MS||'10','--seconds',String(duration)],{windowsHide:true,stdio:['ignore','pipe','pipe']});let result='',errors='';simulator.stdout.on('data',b=>result+=b);simulator.stderr.on('data',b=>errors+=b);const finished=new Promise((resolve,reject)=>{simulator.once('exit',resolve);simulator.once('error',reject)});await page.getByRole('button',{name:'SIM-00000',exact:true}).waitFor();await page.getByRole('button',{name:'SIM-00000',exact:true}).click();const code=await finished;assert.equal(code,0,errors);simulationReport=JSON.parse(result.trim());sequence=simulationReport.ticks;accepted=(await(await fetch(base+'/api/realtime/status')).json()).metrics.accepted;
|
|
}
|
|
while(!simulationReport&&performance.now()-started<duration*1000){
|
|
sequence++;const t=performance.now();
|
|
for(let offset=0;offset<count;offset+=1000){
|
|
const batch=Array.from({length:Math.min(1000,count-offset)},(_,j)=>{const i=offset+j;return {target_id:`SIM-${String(i).padStart(5,'0')}`,receiver_id:'SIM',source_epoch:1,sequence,longitude:120+Math.cos(i)*.1+Math.sin(sequence*.01)*.005,latitude:30+Math.sin(i)*.1,altitude_m:100,heading_deg:i%360};});
|
|
const r=await fetch(base+'/api/realtime/ingest',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(batch)});assert.equal(r.status,200);accepted+=(await r.json()).accepted;
|
|
}
|
|
latency.push(performance.now()-t);
|
|
if(sequence%10===0)samples.push({elapsedMs:performance.now()-started,generatorRssBytes:process.memoryUsage().rss});
|
|
await new Promise(r=>setTimeout(r,10));
|
|
}
|
|
clearInterval(monitor);while(sampling)await new Promise(r=>setTimeout(r,50));
|
|
await page.getByText(`目标 ${count} ·`,{exact:false}).waitFor();
|
|
assert.equal(await page.locator('.rt-target').count(),Math.min(count,100));
|
|
if(count>100){await page.getByRole('button',{name:'下一组',exact:true}).click();await page.getByRole('button',{name:'SIM-00100',exact:true}).waitFor();}
|
|
await page.getByRole('textbox',{name:'搜索实时目标'}).fill('SIM-00000');await page.getByRole('button',{name:'SIM-00000',exact:true}).click();
|
|
await page.locator('.rt-details').filter({hasText:'120.'}).waitFor();
|
|
const snapshot=await(await fetch(base+'/api/realtime/snapshot')).json();assert.equal(snapshot.targets.length,count);assert.ok(snapshot.targets[0].observation.source_epoch>=1);
|
|
const duplicate=snapshot.targets[0].observation;const dup=await fetch(base+'/api/realtime/ingest',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify([duplicate])});assert.equal((await dup.json()).accepted,0);
|
|
await page.screenshot({path:path.join(root,'realtime-C.png'),fullPage:true});
|
|
const map=await page.evaluate(()=>window.ridMap.metrics());assert.equal(map.targets,count);const canvas=await page.locator('.maplibregl-canvas').boundingBox();assert.ok(canvas.width>500&&canvas.height>300,JSON.stringify(canvas));
|
|
await page.setViewportSize({width:390,height:844});assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
|
|
const status=await(await fetch(base+'/api/realtime/status')).json();assert.equal(status.metrics.active_targets,count);
|
|
assert.deepEqual(errors,[]);
|
|
latency.sort((a,b)=>a-b);
|
|
const memorySamples=samples.filter(s=>Number.isFinite(s.serverPrivateBytes));
|
|
const memory={samples:memorySamples.length,maxServerPrivateBytes:Math.max(0,...memorySamples.map(s=>s.serverPrivateBytes)),maxBrowserJsHeapBytes:Math.max(0,...memorySamples.map(s=>s.browserJsHeapBytes||0)),maxWorkerWasmBytes:Math.max(0,...memorySamples.map(s=>s.map?.workerWasmBytes||0))};
|
|
if(duration>=600){assert.ok(memorySamples.length>=duration/15);assert.ok(memory.maxServerPrivateBytes<512*1024*1024);assert.ok(memory.maxBrowserJsHeapBytes<256*1024*1024);assert.ok(memory.maxWorkerWasmBytes<128*1024*1024);const warm=memorySamples.filter(s=>s.elapsedMs>=Math.min(300000,duration*500));memory.afterWarmServerSpreadBytes=Math.max(...warm.map(s=>s.serverPrivateBytes))-Math.min(...warm.map(s=>s.serverPrivateBytes));assert.ok(memory.afterWarmServerSpreadBytes<64*1024*1024);}
|
|
const report={status:'PASS',root,kind:simulationReport?'synthetic-Postcard-ingest-and-real-Rust-worker-map':'synthetic-JSON-ingest-and-real-Rust-worker-map',targets:count,accepted,batches:sequence,durationSeconds:(performance.now()-started)/1000,inputRoundP95Ms:latency[Math.floor(latency.length*.95)]??null,simulationReport,map,memory,metrics:status.metrics,samples,note:'Not a device-to-screen latency certification. Input is synthetic HTTP JSON or Postcard; generator shares this machine. Draw submission intervals are not GPU frame time.'};
|
|
await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));console.log(JSON.stringify({...report,samples:samples.length}));
|
|
}finally{clearInterval(monitorHandle);if(simulatorProcess&&simulatorProcess.exitCode===null)simulatorProcess.kill();if(browser)await browser.close();if(child.exitCode===null&&!failure){const exit=new Promise(r=>child.once('exit',r));child.kill();await exit;}await writeFile(path.join(root,'server.log'),output);}
|