```
feat(target-lists): 新增黑白名单管理与实时告警功能 - rid-shared 新增 target_lists 模块,定义名单数据契约 - 地图适配器支持按名单类型着色渲染目标(白/黑/未知) - 新增名单筛选器与目标目录过滤联动 - 实时详情面板支持加入/编辑白名单与黑名单操作 - 新增黑名单命中告警横幅与事件日志高亮 - 新增名单管理浮层(Manager 组件)与徽章展示 - 底图默认切换为影像图,相机初始俯仰角归零 - color-scheme 切换为 dark,新增 glass/workbench 样式 ```
This commit is contained in:
@@ -21,7 +21,7 @@ let output='',child,browser;const errors=[],csp=[];
|
||||
function start(){const previous=process.env.TIANDITU_TOKEN;delete process.env.TIANDITU_TOKEN;child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',RID_TEST_PORT:'18890'},windowsHide:true,stdio:['ignore','pipe','pipe']});if(previous!==undefined)process.env.TIANDITU_TOKEN=previous;child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message);}
|
||||
async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/appearance')).ok)return;}catch{}await new Promise(r=>setTimeout(r,100));}throw Error('server timeout '+output);}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}}
|
||||
let report={};let keepalive;let minimumOptionContrast=Infinity;
|
||||
let report={};let keepalive;
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
const token=JSON.parse(await readFile(path.resolve('maps/config.json'),'utf8')).tianditu_token;
|
||||
await mkdir(path.join(root,'maps'),{recursive:true});await writeFile(path.join(root,'maps/config.json'),JSON.stringify({tianditu_token:token}));
|
||||
@@ -30,20 +30,22 @@ try {
|
||||
for(const file of ['index.html','map-adapter.js','workspace-native.css']){const response=await fetch(base+'/'+(file==='index.html'?'realtime':file));assert.equal(response.status,200);const body=await response.text();assert.ok(body===await readFile(path.join('dist/web-ui',file),'utf8'),'stale embedded '+file);assert.ok(!body.includes(token),'credential in frontend');}
|
||||
const initial=await(await fetch(base+'/api/maps/status')).json();assert.equal(initial.keyConfigured,true);assert.ok(!JSON.stringify(initial).includes(token));
|
||||
browser=await chromium.launch({headless:true,executablePath:process.env.RID_BROWSER_PATH||'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'});
|
||||
const context=await browser.newContext({viewport:{width:1600,height:1000}});const page=await context.newPage();const loaded=new Set();let credentialRequest=false;
|
||||
const context=await browser.newContext({viewport:{width:1600,height:1000}});await context.addInitScript(()=>localStorage.setItem('rid.realtime.basemap.v1','road'));const page=await context.newPage();const loaded=new Set();let credentialRequest=false;
|
||||
page.on('pageerror',e=>errors.push(e.message));page.on('console',m=>{if(/violates.*Content Security|Refused.*policy/i.test(m.text()))csp.push(m.text())});
|
||||
page.on('request',r=>{if(r.url().includes(token)||r.url().includes('tianditu.gov.cn'))credentialRequest=true;});
|
||||
page.on('response',r=>{const m=r.url().match(/\/api\/maps\/tile\/([^/]+)\//);if(m&&r.status()===200)loaded.add(m[1]);});
|
||||
await page.goto(base+'/realtime');await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();const picker=page.getByRole('combobox',{name:'底图类型'});assert.equal(await picker.inputValue(),'road');
|
||||
await page.waitForFunction(()=>window.ridMap?.metrics().mapReady);await page.waitForFunction(()=>document.querySelector('.mc-map-infobar').textContent.includes('路网图')&&!document.querySelector('.mc-map-infobar').textContent.includes('暂无'),null,{timeout:45000});
|
||||
await page.goto(base+'/realtime');await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();assert.equal(await page.locator('.mc-map-toolstrip').count(),0);await page.waitForFunction(()=>{const m=window.ridMap?.metrics();return m?.mapReady&&m.baseTiles[0].includes('img_w')&&m.labelTiles[0].includes('cia_w')});await page.waitForFunction(()=>document.querySelector('.mc-map-infobar').textContent.includes('影像+路网')&&!document.querySelector('.mc-map-infobar').textContent.includes('暂无'),null,{timeout:45000});await page.screenshot({path:path.join(root,'hybrid-default.png')});await changeBasemap('road');
|
||||
await page.waitForFunction(()=>window.ridMap?.metrics().mapReady);await page.waitForFunction(()=>window.ridMap.metrics().basemap==='road'&&!document.querySelector('.mc-map-infobar').textContent.includes('暂无'),null,{timeout:45000});
|
||||
async function changeBasemap(value){await page.evaluate(v=>window.ridMap.setBasemap(v),value);}
|
||||
assert.deepEqual(await page.evaluate(()=>{const {pitch,bearing}=window.ridMap.metrics().camera;return {pitch,bearing}}),{pitch:0,bearing:0});
|
||||
async function ingest(sequence){const r=await fetch(base+'/api/realtime/ingest',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify([{target_id:'MAP-TEST-001',receiver_id:'MAP-TEST',source_epoch:1,sequence,longitude:120.1538,latitude:30.2874,altitude_m:120,heading_deg:42}])});assert.equal(r.status,200)}
|
||||
let seq=1;await ingest(seq);keepalive=setInterval(()=>ingest(++seq).catch(()=>{}),5000);await page.getByRole('button',{name:'MAP-TEST-001',exact:true}).click();await wait(500);const camera=(await page.evaluate(()=>window.ridMap.metrics())).camera;
|
||||
await page.screenshot({path:path.join(root,'road-live.png')});
|
||||
await picker.selectOption('imagery');await page.waitForFunction(()=>window.ridMap.metrics().baseTiles[0].includes('img_w'));await page.waitForFunction(()=>document.querySelector('.mc-map-infobar').textContent.includes('影像图')&&!document.querySelector('.mc-map-infobar').textContent.includes('暂无'),null,{timeout:45000});await wait(1200);await page.screenshot({path:path.join(root,'imagery-live.png')});
|
||||
for(let i=0;i<8;i++)await picker.selectOption(i%2?'imagery':'road');await wait(1200);
|
||||
await changeBasemap('imagery');await page.waitForFunction(()=>window.ridMap.metrics().baseTiles[0].includes('img_w'));await page.waitForFunction(()=>document.querySelector('.mc-map-infobar').textContent.includes('影像+路网')&&!document.querySelector('.mc-map-infobar').textContent.includes('暂无'),null,{timeout:45000});await wait(1200);await page.screenshot({path:path.join(root,'imagery-live.png')});
|
||||
for(let i=0;i<8;i++)await changeBasemap(i%2?'imagery':'road');await wait(1200);
|
||||
const switched=await page.evaluate(()=>window.ridMap.metrics());assert.equal(switched.mapCreations,1);assert.equal(switched.targets,1);assert.deepEqual(switched.camera,camera);assert.ok(switched.labelTiles[0].includes('cia_w'));assert.ok(switched.selectedTrailPoints>0);
|
||||
await page.reload();await picker.waitFor();assert.equal(await picker.inputValue(),'imagery');await page.waitForFunction(()=>window.ridMap?.metrics().mapReady);await wait(3500);
|
||||
for(const [width,height]of [[1600,1000],[1280,720],[390,844],[360,740]]){await page.setViewportSize({width,height});await wait(250);for(const theme of ['graphite','blue','white']){await page.evaluate(t=>{document.body.classList.remove('theme-blue','theme-white');if(t!=='graphite')document.body.classList.add('theme-'+t)},theme);const clipped=await page.evaluate(()=>{const bar=document.querySelector('.mc-map-toolstrip').getBoundingClientRect();return [...document.querySelectorAll('.mc-map-toolstrip button,.mc-map-toolstrip select')].some(e=>{const r=e.getBoundingClientRect();return r.left<bar.left-1||r.right>bar.right+1||r.right>innerWidth||r.top<bar.top-1||r.bottom>bar.bottom+1})});assert.equal(clipped,false,JSON.stringify({width,height,theme}));assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);const contrast=await picker.locator('option').first().evaluate(e=>{const s=getComputedStyle(e);const lum=color=>{const rgb=color.match(/[\d.]+/g).slice(0,3).map(Number).map(v=>{v/=255;return v<=.04045?v/12.92:((v+.055)/1.055)**2.4});return rgb[0]*.2126+rgb[1]*.7152+rgb[2]*.0722};const a=lum(s.color),b=lum(s.backgroundColor);return (Math.max(a,b)+.05)/(Math.min(a,b)+.05)});minimumOptionContrast=Math.min(minimumOptionContrast,contrast);assert.ok(contrast>=4.5,'Basemap option contrast is insufficient in '+theme);}}
|
||||
await page.reload();await page.waitForFunction(()=>window.ridMap?.metrics().basemap==='imagery');await page.waitForFunction(()=>window.ridMap?.metrics().mapReady);await wait(3500);
|
||||
for(const [width,height]of [[1600,1000],[1280,720],[390,844],[360,740]]){await page.setViewportSize({width,height});await wait(250);assert.equal(await page.locator('.mc-map-toolstrip').count(),0);assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);assert.equal(await page.evaluate(()=>window.ridMap.metrics().camera.pitch),0);}
|
||||
await page.setViewportSize({width:1600,height:1000});await page.evaluate(()=>document.body.classList.remove('theme-blue','theme-white'));await wait(250);
|
||||
// Browser failure/recovery fixtures; backend outage/timeout/offline paths are tested with real local mock upstreams in Rust.
|
||||
let fixture={provider:'tianditu',keyConfigured:true,mode:'offline',retryAfterMs:Date.now()+30000,layers:{img_w:{source:'missing',error:'key-or-permission'},cia_w:{source:'missing',error:'key-or-permission'}}};
|
||||
@@ -53,7 +55,7 @@ try {
|
||||
assert.deepEqual([...loaded].sort(),['cia_w','cva_w','img_w','vec_w']);assert.equal(credentialRequest,false);assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
|
||||
const status=await(await fetch(base+'/api/maps/status')).json();assert.ok(status.servedOnline>0);assert.ok(status.servedOffline>0);assert.equal((await(await fetch(base+'/api/realtime/status')).json()).clients,1);
|
||||
assert.ok(!output.includes(token),'credential in server log');
|
||||
await picker.selectOption('road');await wait(4000);await page.screenshot({path:path.join(root,'road-final.png')});await picker.selectOption('imagery');await wait(4000);await page.screenshot({path:path.join(root,'imagery-final.png')});
|
||||
report={status:'PASS',root,exe,serverPid:child.pid,loadedLayers:[...loaded].sort(),servedOnline:status.servedOnline,servedOffline:status.servedOffline,mapCreations:switched.mapCreations,frames:12,minimumOptionContrast,checks:['real-road-and-labels','real-imagery-and-labels','same-camera-target-trail-on-switch','preference-after-reload','toolbar-four-sizes-three-themes','dropdown-text-contrast','credential-not-in-browser-or-log','error-and-recovery-ui-fixtures','one-worker-connection'],note:'Real TianDiTu tiles; isolated synthetic target. Actual upstream outage tests run in Rust, browser recovery uses provider-state fixtures.'};console.log(JSON.stringify(report));
|
||||
await changeBasemap('road');await wait(4000);await page.screenshot({path:path.join(root,'road-final.png')});await changeBasemap('imagery');await wait(4000);await page.screenshot({path:path.join(root,'imagery-final.png')});
|
||||
report={status:'PASS',root,exe,serverPid:child.pid,loadedLayers:[...loaded].sort(),servedOnline:status.servedOnline,servedOffline:status.servedOffline,mapCreations:switched.mapCreations,frames:12,checks:['legacy-road-preference-upgrades-to-hybrid-default','real-road-and-labels','real-imagery-and-labels','same-camera-target-trail-on-switch','preference-after-reload','removed-toolbar-four-sizes','topdown-default','credential-not-in-browser-or-log','error-and-recovery-ui-fixtures','one-worker-connection'],note:'Real TianDiTu tiles; isolated synthetic target. Actual upstream outage tests run in Rust, browser recovery uses provider-state fixtures.'};console.log(JSON.stringify(report));
|
||||
}finally{clearInterval(keepalive);if(browser){if(report.status!=='PASS'){const p=browser.contexts()[0]?.pages()[0];if(p){await p.screenshot({path:path.join(root,'failure.png')}).catch(()=>{});console.log(JSON.stringify({root,errors,csp,diagnostic:await p.evaluate(()=>({label:document.querySelector('.mc-map-infobar')?.textContent,metrics:window.ridMap?.metrics()})).catch(()=>null)}));}}await browser.close();}await stop();for(const socket of sockets)socket.destroy();const closed=new Promise(r=>proxy.close(r));proxy.closeAllConnections();await closed;await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'maps-report.json'),JSON.stringify({...report,errors,csp},null,2));}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user