```
refactor(registry): 生产环境数据库访问迁移至 SQLx 并统一测试端口策略 将 rusqlite 从生产依赖移至 dev-dependencies,正式数据库操作全部 由 SQLx 完成;rusqlite 仅保留用于测试夹具及旧数据库兼容验证。 UI 验收脚本移除 HTTP 代理和动态端口分配,统一通过 ui-test-port.mjs 的 assertUiPortAvailable 直连 8787 端口, 确保测试与正式实例串行执行。 新增 doc/registry/rust/axum-sqlx-architecture.md 记录模块职责、 数据兼容、退出资源回收及验证维护规范。 修复接收器页面按钮缺少显式 height 导致的布局偏差。 ```
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Appearance preview acceptance with an isolated database; no physical transports opened.
|
||||
import {mkdtemp} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-appearance-preview-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,output='';const errors=[],sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,output='';const errors=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
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 wait(100)}throw Error('server timeout '+output)}
|
||||
let report={};
|
||||
try {
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
browser=await chromium.launch({headless:true,channel:'msedge'});
|
||||
const page=await browser.newPage({viewport:{width:1600,height:1000}});
|
||||
page.on('pageerror',e=>errors.push(e.message));
|
||||
@@ -73,5 +71,5 @@ try {
|
||||
}
|
||||
assert.deepEqual(errors,[]);report={passed:true,root,checks:['bright wallpapers','preview pixels change','dim','blur','fit','reload persistence','responsive widths']};
|
||||
} finally {
|
||||
await browser?.close();await stop();for(const s of sockets)s.destroy();await new Promise(r=>proxy.close(r));console.log(JSON.stringify(report));
|
||||
await browser?.close();await stop();console.log(JSON.stringify(report));
|
||||
}
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real SQLite, Rust/Wasm, Worker and WebGL acceptance. No physical transports opened.
|
||||
import {mkdtemp,readFile,writeFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-geofences-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,heartbeat,output='';const errors=[],csp=[],sockets=new Set();
|
||||
const proxy=http.createServer(async(req,res)=>{if(process.env.RID_SOURCE_ASSETS==='1'&&!req.url.startsWith('/api/')){const pathname=new URL(req.url,'http://localhost').pathname;const relative=pathname==='/'||pathname==='/realtime'?'index.html':pathname.slice(1);if(!relative.includes('..'))try{let bytes;try{bytes=await readFile(path.join('crates/web-ui/public',relative));}catch{bytes=await readFile(path.join('dist/web-ui',relative));}res.writeHead(200,{'content-type':relative.endsWith('.html')?'text/html':relative.endsWith('.css')?'text/css':relative.endsWith('.wasm')?'application/wasm':relative.endsWith('.svg')?'image/svg+xml':relative.endsWith('.png')?'image/png':'text/javascript'});res.end(bytes);return}catch{}}const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,heartbeat,output='';const errors=[],csp=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/target-lists')).ok)return}catch{}await wait(100)}throw Error('server timeout '+output)}
|
||||
async function snapshot(){return(await fetch(base+'/api/target-lists')).json()}
|
||||
async function save(id,kind,note='验收备注'){const current=await snapshot();const r=await fetch(base+'/api/target-lists/'+id,{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify({list_kind:kind,note,expected_revision:current.revision})});assert.equal(r.status,200);return r.json()}
|
||||
let report={};
|
||||
try{
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
browser=await chromium.launch({headless:true,channel:'msedge'});const context=await browser.newContext({viewport:{width:1600,height:1000}});const page=await context.newPage();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('dialog',d=>d.accept());
|
||||
await page.goto(base+'/realtime');await page.getByRole('button',{name:'电子围栏',exact:true}).click();await page.locator('#gf-new').waitFor();await page.waitForFunction(()=>!document.querySelector('#gf-new').disabled);await page.waitForFunction(()=>window.ridGeofences.metrics()?.ready);
|
||||
assert.equal(await page.evaluate(()=>window.ridGeofences.metrics().camera.zoom),15);
|
||||
@@ -49,4 +47,4 @@ try{
|
||||
await page.setViewportSize({width:1600,height:1000});await page.evaluate(()=>document.documentElement.style.zoom='2');await page.locator('#gf-save').scrollIntoViewIfNeeded();assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);await page.screenshot({path:path.join(root,'fence-200percent.png'),fullPage:true});await page.evaluate(()=>document.documentElement.style.zoom='');await page.locator('#gf-delete').click();await page.locator('#gf-message').filter({hasText:'已删除'}).waitFor();assert.equal((await(await fetch(base+'/api/geofences')).json()).entries.length,1);
|
||||
await page.getByRole('button',{name:'实时目标工作台',exact:true}).click();await page.waitForFunction(()=>window.ridMap?.metrics().mapReady);assert.equal(await page.evaluate(()=>window.ridMap.metrics().camera.pitch),0);assert.equal(await page.locator('.mc-map-toolstrip').count(),0);
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);report={status:'PASS',root,exe,checks:['A sidebar navigation','default15','circle numeric and map edit','polygon drawing','invalid drag restores vertex','safe names','white exemption','persistent events','Escape','invalid geometry','enable/disable','conflict preserves draft','page change preserves draft','failed save preserves draft','five viewports','delete','realtime preserved'],errors,csp};console.log(JSON.stringify(report));
|
||||
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify(errors));if(browser){const p=browser.contexts()[0]?.pages()[0];if(p)await p.screenshot({path:path.join(root,'failure.png'),fullPage:true}).catch(()=>{});}throw error;}finally{if(browser)await browser.close();await stop();for(const socket of sockets)socket.destroy();proxy.closeAllConnections();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|
||||
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify(errors));if(browser){const p=browser.contexts()[0]?.pages()[0];if(p)await p.screenshot({path:path.join(root,'failure.png'),fullPage:true}).catch(()=>{});}throw error;}finally{if(browser)await browser.close();await stop();await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real Rust/Wasm acceptance in an isolated database. Never opens receiver transports.
|
||||
import {mkdtemp,writeFile,readFile,mkdir} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
@@ -5,20 +8,11 @@ import path from 'node:path';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-maps-live-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const base='http://127.0.0.1:18889';
|
||||
// Keep production origin checks unchanged. Only this isolated proxy maps the test origin.
|
||||
const sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:18890,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(18890,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';upstream.write(`GET ${req.url} HTTP/1.1\r\n${Object.entries(headers).map(([k,v])=>`${k}: ${v}`).join('\r\n')}\r\n\r\n`);if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(800)});occupied=true;}catch{}if(occupied)throw Error('18889 occupied; preserving existing service');
|
||||
const backendOccupied=await new Promise(resolve=>{const socket=net.connect(18890,'127.0.0.1');socket.once('connect',()=>{socket.destroy();resolve(true)});socket.once('error',()=>resolve(false));socket.setTimeout(800,()=>{socket.destroy();resolve(false)})});if(backendOccupied)throw Error('18890 occupied; preserving existing service');
|
||||
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);}
|
||||
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',},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;
|
||||
@@ -26,7 +20,7 @@ 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}));
|
||||
try {
|
||||
await new Promise((resolve,reject)=>{proxy.once('error',reject);proxy.listen(18889,'127.0.0.1',resolve)});start();await ready();
|
||||
start();await ready();
|
||||
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'});
|
||||
@@ -57,5 +51,5 @@ try {
|
||||
assert.ok(!output.includes(token),'credential in server log');
|
||||
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));}
|
||||
}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();await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'maps-report.json'),JSON.stringify({...report,errors,csp},null,2));}
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Actual Rust/Wasm + Go integration against an isolated data root and local fixtures.
|
||||
// Does not use a real TianDiTu key or open any receiver transport.
|
||||
import {mkdtemp,mkdir,writeFile,readFile} from 'node:fs/promises';
|
||||
@@ -6,18 +9,13 @@ import path from 'node:path';
|
||||
import {spawn} from 'node:child_process';
|
||||
import assert from 'node:assert/strict';
|
||||
import {createRequire} from 'node:module';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
const require=createRequire(import.meta.url);
|
||||
const {chromium}=require('C:/Users/20143/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
|
||||
const {PNG}=require('C:/Users/20143/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/pngjs');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-map-settings-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const backendPort=await new Promise((resolve,reject)=>{const socket=net.createServer();socket.on('error',reject);socket.listen(0,'127.0.0.1',()=>{const port=socket.address().port;socket.close(()=>resolve(port));});});
|
||||
let base;const sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backendPort,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream);});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backendPort,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';upstream.write(`GET ${req.url} HTTP/1.1\r\n${Object.entries(headers).map(([k,v])=>`${k}: ${v}`).join('\r\n')}\r\n\r\n`);if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)});});
|
||||
const env={...process.env,RID_TEST_PORT:String(backendPort),RID_MAP_DOWNLOADER:process.env.RID_MAP_DOWNLOADER||'D:/Rust_Contact/util/tools/rid-map-downloader/0.1.0/rid-map-downloader.exe'};delete env.TIANDITU_TOKEN;
|
||||
|
||||
const env={...process.env,RID_MAP_DOWNLOADER:process.env.RID_MAP_DOWNLOADER||'D:/Rust_Contact/util/tools/rid-map-downloader/0.1.0/rid-map-downloader.exe'};delete env.TIANDITU_TOKEN;
|
||||
const fixture=new PNG({width:256,height:256});for(let i=0;i<fixture.data.length;i+=4){fixture.data[i]=25;fixture.data[i+1]=45;fixture.data[i+2]=65;fixture.data[i+3]=255;}const png=PNG.sync.write(fixture);
|
||||
function xy(lon,lat,z){const n=2**z,r=lat*Math.PI/180;return [Math.floor((lon+180)/360*n),Math.floor((1-Math.log(Math.tan(r)+1/Math.cos(r))/Math.PI)/2*n)];}
|
||||
const [x,y]=xy(120.155,30.285,11);
|
||||
@@ -29,7 +27,7 @@ async function stop(){if(child?.exitCode===null){const done=new Promise(r=>child
|
||||
const json=async(url,method='GET',body)=>{const r=await fetch(base+url,{method,headers:{'content-type':'application/json'},...(body?{body:JSON.stringify(body)}:{})});const v=await r.json();return {status:r.status,value:v};};
|
||||
async function job(state){for(let i=0;i<150;i++){const v=(await json('/api/maps/downloads')).value.job;if(v?.state===state)return v;if(v?.state==='failed'&&state==='completed')throw Error(JSON.stringify(v));await new Promise(r=>setTimeout(r,100));}throw Error('job timeout '+state);}
|
||||
try{
|
||||
await new Promise((resolve,reject)=>{proxy.on('error',reject);proxy.listen(0,'127.0.0.1',()=>{base='http://127.0.0.1:'+proxy.address().port;resolve();})});
|
||||
|
||||
start();await ready();browser=await chromium.launch({headless:true,channel:'msedge'});const page=await browser.newPage({viewport:{width:1600,height:1000}});
|
||||
for(const name of ['map-settings.css','map-settings-adapter.js','map-loader.js','map-adapter.js'])assert.equal(await(await fetch(base+'/'+name)).text(),await readFile(path.resolve('crates/web-ui/public',name),'utf8'),'stale embedded asset: '+name);
|
||||
page.on('pageerror',e=>errors.push(e.message));page.on('console',m=>{if(/Content Security Policy|Refused to/i.test(m.text()))csp.push(m.text());});
|
||||
@@ -130,6 +128,6 @@ try{
|
||||
await stop();start();await ready();const reloaded=(await json('/api/maps/preferences')).value;assert.equal(reloaded.longitude,116.4);assert.equal(reloaded.regions[0].name,'验收常用区域');
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
|
||||
report={status:'PASS',root,camera,download:done,scenarios:['A layout and C wizard with real MapLibre','step validation and estimate retry','region save preserves location draft','parameter edits invalidate estimate','five viewport sizes and 200percent zoom','pending save locks edits and ignores late map callbacks','invalid coordinates','default camera survives first telemetry','coordinates and unsaved basemap retained across navigation','saved region reload','actual Go sidecar and four-layer offline raster validation','download cancellation and single-job limit','unavailable tiles fail honestly','local service failure and automatic recovery','foreign origin rejection','800px width','no page errors or CSP violations']};console.log(JSON.stringify(report));
|
||||
}catch(error){console.error('MAP TEST FAILED',root,error.stack);const page=browser?.contexts()[0]?.pages()[0];if(page)await page.screenshot({path:path.resolve('previews/map-settings-failure.png'),fullPage:true}).catch(()=>{});throw error;}finally{await browser?.close();await stop();for(const socket of sockets)socket.destroy();proxy.closeAllConnections();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));}
|
||||
}catch(error){console.error('MAP TEST FAILED',root,error.stack);const page=browser?.contexts()[0]?.pages()[0];if(page)await page.screenshot({path:path.resolve('previews/map-settings-failure.png'),fullPage:true}).catch(()=>{});throw error;}finally{await browser?.close();await stop();await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));}
|
||||
|
||||
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Module navigation acceptance with an isolated database; no physical transports opened.
|
||||
import {mkdtemp} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-module-navigation-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,output='';const errors=[],sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,output='';const errors=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
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 wait(100)}throw Error('server timeout '+output)}
|
||||
let report={root};
|
||||
try {
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
browser=await chromium.launch({headless:true,channel:'msedge'});
|
||||
const page=await browser.newPage({viewport:{width:1600,height:1000}});
|
||||
page.on('pageerror',e=>errors.push(e.message));
|
||||
@@ -63,5 +61,5 @@ try {
|
||||
await page.setViewportSize({width:1600,height:1000});await page.screenshot({path:path.join(root,'module-settings.png')});
|
||||
assert.deepEqual(errors,[]);report={passed:true,root,checks:['home without rail or gutter','five distinct A icons','module collapse preference retained','archive export','module menus','settings split','archive split','draft retention','create and view record','edit return','new registration','responsive widths','realtime return','collapse','keyboard']};
|
||||
} finally {
|
||||
await browser?.close();await stop();for(const s of sockets)s.destroy();await new Promise(r=>proxy.close(r));console.log(JSON.stringify(report));
|
||||
await browser?.close();await stop();console.log(JSON.stringify(report));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real SQLite and server monitor, without a browser or physical receiver.
|
||||
import assert from 'node:assert/strict';
|
||||
import {mkdtemp,writeFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-monitoring-'));
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const port=probe.address().port;await new Promise(r=>probe.close(r));const base='http://127.0.0.1:'+port;
|
||||
let child,output='',seq=0;const delay=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(port)},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e);}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e);}
|
||||
async function stop(){if(child?.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}}
|
||||
async function ready(){for(let i=0;i<150;i++){try{if((await fetch(base+'/api/geofences')).ok)return}catch{}await delay(100)}throw Error(output);}
|
||||
async function json(url,method='GET',body){const r=await fetch(base+url,{method,headers:body?{'content-type':'application/json'}:{},body:body?JSON.stringify(body):undefined});assert.equal(r.status,200,await r.clone().text());return r.json();}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Module navigation acceptance with an isolated database; no physical transports opened.
|
||||
import {mkdtemp} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-navigation-edges-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,output='';const errors=[],sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,output='';const errors=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
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 wait(100)}throw Error('server timeout '+output)}
|
||||
let report={root};
|
||||
try {
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
browser=await chromium.launch({headless:true,channel:'msedge'});
|
||||
const page=await browser.newPage();page.on('pageerror',e=>errors.push(e.message));
|
||||
await page.goto(base);await page.locator('#home-app-settings').click();
|
||||
@@ -56,4 +54,4 @@ try {
|
||||
assert.equal(pendingAppearanceProtected,true,'leaving during appearance debounce can lose changes');
|
||||
assert.equal(draftProtected,true,'leaving the registration document can silently discard the draft');
|
||||
assert.deepEqual(errors,[]);
|
||||
} finally {await browser?.close();await stop();for(const s of sockets)s.destroy();await new Promise(r=>proxy.close(r));}
|
||||
} finally {await browser?.close();await stop();}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real Rust/Wasm acceptance in an isolated database. Never opens receiver transports.
|
||||
import {mkdtemp,writeFile,readFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
@@ -5,27 +8,18 @@ import path from 'node:path';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-realtime-layout-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const base='http://127.0.0.1:18887';
|
||||
// Keep production origin checks unchanged. Only this isolated proxy maps the test origin.
|
||||
const sockets=new Set();
|
||||
const proxy=http.createServer(async(req,res)=>{if(process.env.RID_SOURCE_ASSETS==='1'&&!req.url.startsWith('/api/')){const pathname=new URL(req.url,'http://localhost').pathname;const relative=pathname==='/'||pathname==='/realtime'?'index.html':pathname.slice(1);if(!relative.includes('..'))try{let bytes;try{bytes=await readFile(path.join('crates/web-ui/public',relative));}catch{bytes=await readFile(path.join('dist/web-ui',relative));}res.writeHead(200,{'content-type':relative.endsWith('.html')?'text/html':relative.endsWith('.css')?'text/css':relative.endsWith('.wasm')?'application/wasm':relative.endsWith('.svg')?'image/svg+xml':relative.endsWith('.png')?'image/png':'text/javascript'});res.end(bytes);return}catch{}}const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:18888,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(18888,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';upstream.write(`GET ${req.url} HTTP/1.1\r\n${Object.entries(headers).map(([k,v])=>`${k}: ${v}`).join('\r\n')}\r\n\r\n`);if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(800)});occupied=true;}catch{}if(occupied)throw Error('18887 occupied; preserving existing service');
|
||||
const backendOccupied=await new Promise(resolve=>{const socket=net.connect(18888,'127.0.0.1');socket.once('connect',()=>{socket.destroy();resolve(true)});socket.once('error',()=>resolve(false));socket.setTimeout(800,()=>{socket.destroy();resolve(false)})});if(backendOccupied)throw Error('18888 occupied; preserving existing service');
|
||||
let output='',child,browser;const errors=[],csp=[];
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',RID_TEST_PORT:'18888'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message);}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',},windowsHide:true,stdio:['ignore','pipe','pipe']});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;}}
|
||||
const key='rid.realtime.layout.v1';
|
||||
let report={};let heartbeat;let sequence=1;
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
try {
|
||||
await new Promise((resolve,reject)=>{proxy.once('error',reject);proxy.listen(18887,'127.0.0.1',resolve)});start();await ready();
|
||||
start();await ready();
|
||||
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();
|
||||
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())});
|
||||
@@ -66,11 +60,11 @@ try {
|
||||
const afterStart=requests.status;await wait(3200);const afterRate=requests.status-afterStart;assert.ok(afterRate<=beforeRate+2,{beforeRate,afterRate});
|
||||
await page.getByRole('button',{name:'目标快照与事件',exact:true}).click();
|
||||
// Generate real transport events without writing receiver configuration.
|
||||
for(let i=0;i<23;i++){for(const socket of [...sockets])socket.destroy();await page.locator('.rt-status').filter({hasText:'连接断开'}).waitFor();assert.equal(await page.getByRole('button',{name:'聚焦此目标',exact:true}).isDisabled(),true);await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();}
|
||||
for(let i=0;i<23;i++){await stop();await page.locator('.rt-status').filter({hasText:'连接断开'}).waitFor();assert.equal(await page.getByRole('button',{name:'聚焦此目标',exact:true}).isDisabled(),true);start();await ready();await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();}
|
||||
assert.equal(await page.locator('.live-events li').count(),64);
|
||||
await grip.focus();await page.keyboard.press('Home');const scroller=page.locator('#rt-event-scroll');await scroller.evaluate(e=>e.scrollTop=Math.min(400,e.scrollHeight/2));
|
||||
const anchor=await scroller.evaluate(e=>{const r=e.getBoundingClientRect();return [...e.querySelectorAll('li')].map(li=>({text:li.textContent,y:li.getBoundingClientRect().top-r.top})).find(x=>x.y>=0)});
|
||||
for(const socket of [...sockets])socket.destroy();await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();await wait(200);
|
||||
await stop();start();await ready();await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();await wait(200);
|
||||
if(anchor){const next=await scroller.evaluate((e,a)=>{const li=[...e.querySelectorAll('li')].find(li=>li.textContent===a.text);return li?li.getBoundingClientRect().top-e.getBoundingClientRect().top:null},anchor);assert.ok(next!==null&&Math.abs(next-anchor.y)<4,JSON.stringify({anchor,next}));}
|
||||
// Restore a normal useful desktop frame with live Worker data.
|
||||
await ingest(batch.map(x=>({...x,sequence:++sequence})));await page.getByRole('textbox',{name:'搜索实时目标'}).fill('LAYOUT-0000');await page.getByRole('button',{name:'LAYOUT-0000',exact:true}).click();
|
||||
@@ -91,4 +85,4 @@ try {
|
||||
const realtimeStatus=await (await fetch(base+'/api/realtime/status')).json();assert.equal(realtimeStatus.clients,1);
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
|
||||
report={status:'PASS',root,exe,serverPid:child.pid,clients:realtimeStatus.clients,frames,requests,beforeRate,afterRate,checks:['embedded-assets-match-build','empty','real-worker-120-targets','search-pagination','local-record-match-unmatched-error','long-id','safe-focus','drag-keyboard','reload-persistence','hide-restore-focus','receiver-20-switches','events-bounded-at-64','event-scroll-anchor','three-themes-six-sizes-including-low-height','hidden-workspace-keeps-preferences','compact-select-focus','zoom-125-150','corrupt-storage'],note:'Synthetic input; no physical receiver transport opened.'};console.log(JSON.stringify(report));
|
||||
}finally{clearInterval(heartbeat);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(()=>({layout:document.getElementById('rt-layout')?.outerHTML.slice(0,2000),metrics:window.ridMap?.metrics()})).catch(()=>null)}));}}await browser.close();}await stop();for(const s of sockets)s.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,'layout-report.json'),JSON.stringify({...report,errors,csp},null,2));}
|
||||
}finally{clearInterval(heartbeat);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(()=>({layout:document.getElementById('rt-layout')?.outerHTML.slice(0,2000),metrics:window.ridMap?.metrics()})).catch(()=>null)}));}}await browser.close();}await stop();await writeFile(path.join(root,'server.log'),output);await writeFile(path.join(root,'layout-report.json'),JSON.stringify({...report,errors,csp},null,2));}
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real SQLite, Rust/Wasm, Worker and WebGL acceptance. No physical transports opened.
|
||||
import {mkdtemp,readFile,writeFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-menu-status-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,output='';const errors=[],csp=[],sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,output='';const errors=[],csp=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/target-lists')).ok)return}catch{}await wait(100)}throw Error('server timeout '+output)}
|
||||
async function snapshot(){return(await fetch(base+'/api/target-lists')).json()}
|
||||
async function save(id,kind,note='验收备注'){const current=await snapshot();const r=await fetch(base+'/api/target-lists/'+id,{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify({list_kind:kind,note,expected_revision:current.revision})});assert.equal(r.status,200);return r.json()}
|
||||
let report={};
|
||||
try{
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
for(const asset of ['workspace-native.css','index.html']){const response=await fetch(base+'/'+(asset==='index.html'?'realtime':asset));assert.equal(await response.text(),await readFile(path.join('dist/web-ui',asset),'utf8'));}
|
||||
await save('MENU-BLACK','black');await save('MENU-WHITE','white');const before=await snapshot();
|
||||
browser=await chromium.launch({headless:true,channel:'msedge'});const context=await browser.newContext({viewport:{width:1600,height:1000}});const page=await context.newPage();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())});
|
||||
@@ -41,4 +39,4 @@ try{
|
||||
await page.setViewportSize({width:1600,height:1000});await wait(300);await page.getByRole('button',{name:'返回应用总览',exact:true}).click();await page.locator('body[data-screen=home]').waitFor();assert.equal(await page.locator('#rt-blacklist-menu').isVisible(),false);await page.locator('#home-app-register').click();await page.locator('body[data-screen=register]').waitFor();assert.equal(await page.locator('.reference-rail [data-open=register]').isVisible(),true);assert.equal(await page.locator('#rt-blacklist-menu').isVisible(),false);
|
||||
await page.getByRole('button',{name:'返回应用总览',exact:true}).click();await page.locator('#home-app-realtime').click();await page.waitForFunction(()=>document.querySelector('.rt-status')?.textContent.includes('已连接'));assert.equal(await nav.locator('button:visible').count(),4);await corner();
|
||||
assert.deepEqual(await snapshot(),before);assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);report={status:'PASS',root,exe,frames,checks:['left-menu-full-page','both-list-kinds-visible','keyboard-open-and-return-focus','fixed-bottom-right-dock-and-panels','overlays-dock','menu-collapse','four-window-sizes','other-app-navigation-preserved','list-data-unchanged'],errors,csp};console.log(JSON.stringify(report));
|
||||
}finally{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(()=>({screen:document.body.dataset.screen,menu:[...document.querySelectorAll('.reference-rail button')].map(e=>({id:e.id,label:e.getAttribute('aria-label'),height:e.getBoundingClientRect().height})),manager:document.getElementById('rt-list-manager')?.hidden})).catch(()=>null)}));}}await browser.close();}if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}for(const socket of sockets)socket.destroy();const closed=new Promise(r=>proxy.close(r));proxy.closeAllConnections();await closed;await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|
||||
}finally{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(()=>({screen:document.body.dataset.screen,menu:[...document.querySelectorAll('.reference-rail button')].map(e=>({id:e.id,label:e.getAttribute('aria-label'),height:e.getBoundingClientRect().height})),manager:document.getElementById('rt-list-manager')?.hidden})).catch(()=>null)}));}}await browser.close();}if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real Rust/Wasm acceptance in an isolated database. Never opens receiver transports.
|
||||
import {mkdtemp,writeFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
@@ -5,21 +8,11 @@ import path from 'node:path';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-workspace-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const frontendPort=Number(process.env.RID_BROWSER_TEST_PORT||18787),backendPort=Number(process.env.RID_BACKEND_TEST_PORT||18788);
|
||||
const base='http://127.0.0.1:'+frontendPort;
|
||||
// Keep production origin checks unchanged. Only this isolated proxy maps the test origin.
|
||||
const sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backendPort,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backendPort,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';upstream.write(`GET ${req.url} HTTP/1.1\r\n${Object.entries(headers).map(([k,v])=>`${k}: ${v}`).join('\r\n')}\r\n\r\n`);if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(800)});occupied=true;}catch{}if(occupied)throw Error('8787 occupied; preserving existing service');
|
||||
const backendOccupied=await new Promise(resolve=>{const socket=net.connect(backendPort,'127.0.0.1');socket.once('connect',()=>{socket.destroy();resolve(true)});socket.once('error',()=>resolve(false));socket.setTimeout(800,()=>{socket.destroy();resolve(false)})});if(backendOccupied)throw Error('18788 occupied; preserving existing service');
|
||||
let output='',child,browser;const errors=[],csp=[];
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',RID_TEST_PORT:String(backendPort)},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message);}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',},windowsHide:true,stdio:['ignore','pipe','pipe']});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;}}
|
||||
async function preferences(){return (await fetch(base+'/api/appearance')).json();}
|
||||
@@ -43,7 +36,7 @@ async function setLegacyTheme(page, theme) {
|
||||
|
||||
|
||||
try {
|
||||
await new Promise((resolve,reject)=>{proxy.once('error',reject);proxy.listen(frontendPort,'127.0.0.1',resolve)});
|
||||
|
||||
start();await ready();browser=await chromium.launch({headless:true,channel:'msedge'});
|
||||
const context=await browser.newContext({viewport:{width:1600,height:1000},acceptDownloads:true,permissions:['clipboard-read','clipboard-write']});
|
||||
await context.addInitScript(()=>{
|
||||
@@ -122,4 +115,4 @@ try {
|
||||
await page.locator('#history-query').fill('');await page.locator('#page-status').filter({hasText:'共 21 条'}).waitFor();await page.locator('#next-page').click();await page.locator('#page-status').filter({hasText:'第 2 / 2 页'}).waitFor();assert.equal(await page.locator('.archive-card').count(),1);
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
|
||||
await writeFile(path.join(root,'report.json'),JSON.stringify({status:'PASS',root,errors,csp,cases,scenarios:['real Rust/Wasm registration B','validated photo preservation, cancel, replacement, reset, stale decode','immutable submit, failed save, duplicate suppression, busy navigation','draft/result separation, new confirmation','menu focus, selection redraw, current-page Excel and ZIP','duplicate SN, edit atomicity and delete current result','QR PNG and clipboard/archive links','three legacy theme values, 15 viewport cases, 200% zoom, mobile save boundary']},null,2));console.log(JSON.stringify({status:'PASS',root}));
|
||||
}catch(e){console.log('FAILED ROOT',root,e.stack);if(browser){const pages=browser.contexts().flatMap(c=>c.pages());if(pages[0])await pages[0].screenshot({path:path.join(root,'failed.png')}).catch(()=>{});}throw e;}finally{if(browser)await browser.close();await stop();for(const socket of sockets)socket.destroy();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'server.log'),output)}
|
||||
}catch(e){console.log('FAILED ROOT',root,e.stack);if(browser){const pages=browser.contexts().flatMap(c=>c.pages());if(pages[0])await pages[0].screenshot({path:path.join(root,'failed.png')}).catch(()=>{});}throw e;}finally{if(browser)await browser.close();await stop();await writeFile(path.join(root,'server.log'),output)}
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real SQLite, Rust/Wasm, Worker and WebGL acceptance. No physical transports opened.
|
||||
import {mkdtemp,readFile,writeFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-list-page-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,heartbeat,output='';const errors=[],csp=[],sockets=new Set();
|
||||
const proxy=http.createServer(async(req,res)=>{if(process.env.RID_SOURCE_ASSETS==='1'&&!req.url.startsWith('/api/')){const pathname=new URL(req.url,'http://localhost').pathname;const relative=pathname==='/'||pathname==='/realtime'?'index.html':pathname.slice(1);if(!relative.includes('..'))try{let bytes;try{bytes=await readFile(path.join('crates/web-ui/public',relative));}catch{bytes=await readFile(path.join('dist/web-ui',relative));}res.writeHead(200,{'content-type':relative.endsWith('.html')?'text/html':relative.endsWith('.css')?'text/css':relative.endsWith('.wasm')?'application/wasm':relative.endsWith('.svg')?'image/svg+xml':relative.endsWith('.png')?'image/png':'text/javascript'});res.end(bytes);return}catch{}}const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,heartbeat,output='';const errors=[],csp=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/target-lists')).ok)return}catch{}await wait(100)}throw Error('server timeout '+output)}
|
||||
async function snapshot(){return(await fetch(base+'/api/target-lists')).json()}
|
||||
async function save(id,kind,note='验收备注'){const current=await snapshot();const r=await fetch(base+'/api/target-lists/'+id,{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify({list_kind:kind,note,expected_revision:current.revision})});assert.equal(r.status,200);return r.json()}
|
||||
let report={};
|
||||
try{
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
for(let i=0;i<115;i++)await save('PAGE-'+String(i).padStart(3,'0'),i%2?'white':'black','演示备注 '+i);
|
||||
browser=await chromium.launch({headless:true,channel:'msedge'});const context=await browser.newContext({viewport:{width:1366,height:768}});const page=await context.newPage();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())});
|
||||
await page.goto(base+'/realtime');await page.locator('.rt-status').filter({hasText:'已连接'}).waitFor();assert.equal(await page.locator('#rt-dock').isVisible(),false);const fullHeight=await page.locator('.live-list-body').evaluate(e=>e.clientHeight);assert.ok(fullHeight>=240,String(fullHeight));await page.locator('#rt-dock-restore').click();await wait(200);const dockHeight=await page.locator('.live-list-body').evaluate(e=>e.clientHeight);assert.ok(fullHeight-dockHeight>100);await page.getByRole('button',{name:'隐藏事件面板',exact:true}).click();
|
||||
@@ -37,4 +35,4 @@ try{
|
||||
await page.goto(base+'/?app=register');await page.locator('body[data-screen=register]').waitFor();await page.locator('#owner-name').fill('保留登记草稿');const originalUrl=page.url();assert.equal(await page.locator('#rt-blacklist-menu').isVisible(),false);await page.getByRole('button',{name:'打开壁纸与外观',exact:true}).click();await page.locator('body[data-screen=settings]').waitFor();await page.locator('.reference-rail [data-home]').click();await page.locator('#home-app-register').click();await page.locator('body[data-screen=register]').waitFor();assert.equal(page.url(),originalUrl);assert.equal(await page.locator('#owner-name').inputValue(),'保留登记草稿');
|
||||
page.once('dialog',dialog=>dialog.accept());await page.goto(base+'/?app=target-lists');await page.locator('body[data-screen=target-lists]').waitFor();await page.locator('.rt-list-row').first().waitFor();await page.getByRole('button',{name:'新增条目',exact:true}).click();await page.locator('#rt-list-entry-id').fill('PAGE-NEW');await page.locator('#rt-list-entry-note').fill('B方案行内新增');await page.locator('#rt-list-entry-form .primary').click();await page.locator('.rt-list-manager-footer').filter({hasText:'已将 PAGE-NEW 保存'}).waitFor();assert.ok((await snapshot()).entries.some(e=>e.target_id==='PAGE-NEW'));await page.locator('.rt-list-search input').fill('PAGE-NEW');await page.locator('.rt-list-row[data-target-id="PAGE-NEW"]').waitFor();assert.equal(await page.locator('#rt-list-entry-form').count(),1);await page.getByRole('button',{name:'收起编辑',exact:true}).click();assert.equal(await page.locator('#rt-list-entry-form').count(),0);
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);report={status:'PASS',root,exe,fullHeight,dockHeight,checks:['left menu complete page','map hidden; not a dialog','both kinds and search','115 entries pagination','B category navigation and inline editing','draft and filter across pages','five sizes and 200percent','return to origin workspace','module isolation and registration draft','direct bookmark','directory height expanded','default dock collapsed'],errors,csp};console.log(JSON.stringify(report));
|
||||
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify(errors));if(browser){const page=browser.contexts()[0]?.pages()[0];if(page)await page.screenshot({path:path.join(root,'failure.png'),fullPage:true}).catch(()=>{});}throw error;}finally{if(browser)await browser.close();await stop();for(const socket of sockets)socket.destroy();proxy.closeAllConnections();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|
||||
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify(errors));if(browser){const page=browser.contexts()[0]?.pages()[0];if(page)await page.screenshot({path:path.join(root,'failure.png'),fullPage:true}).catch(()=>{});}throw error;}finally{if(browser)await browser.close();await stop();await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output);}
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real SQLite, Rust/Wasm, Worker and WebGL acceptance. No physical transports opened.
|
||||
import {mkdtemp,readFile,writeFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-target-lists-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const probe=net.createServer();await new Promise(r=>probe.listen(0,'127.0.0.1',r));const backend=probe.address().port;await new Promise(r=>probe.close(r));
|
||||
let base,child,browser,heartbeat,output='';const errors=[],csp=[],sockets=new Set();
|
||||
const proxy=http.createServer(async(req,res)=>{if(process.env.RID_SOURCE_ASSETS==='1'&&!req.url.startsWith('/api/')){const pathname=new URL(req.url,'http://localhost').pathname;const relative=pathname==='/'||pathname==='/realtime'?'index.html':pathname.slice(1);if(!relative.includes('..'))try{let bytes;try{bytes=await readFile(path.join('crates/web-ui/public',relative));}catch{bytes=await readFile(path.join('dist/web-ui',relative));}res.writeHead(200,{'content-type':relative.endsWith('.html')?'text/html':relative.endsWith('.css')?'text/css':relative.endsWith('.wasm')?'application/wasm':relative.endsWith('.svg')?'image/svg+xml':relative.endsWith('.png')?'image/png':'text/javascript'});res.end(bytes);return}catch{}}const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backend,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backend,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const nl=String.fromCharCode(13,10);upstream.write(['GET '+req.url+' HTTP/1.1',...Object.entries(headers).map(([k,v])=>k+': '+v),'',''].join(nl));if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let child,browser,heartbeat,output='';const errors=[],csp=[];
|
||||
const wait=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,RID_TEST_PORT:String(backend),PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)}
|
||||
async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}}
|
||||
async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/target-lists')).ok)return}catch{}await wait(100)}throw Error('server timeout '+output)}
|
||||
async function snapshot(){return(await fetch(base+'/api/target-lists')).json()}
|
||||
@@ -24,7 +22,7 @@ let sequence=0;const targetIds=['LIST-WHITE','LIST-BLACK','LIST-OTHER'];
|
||||
async function ingest(){sequence++;const frames=targetIds.map((target_id,i)=>({target_id,receiver_id:'TEST',source_epoch:1,sequence,longitude:120.15+i*.001,latitude:30.28+i*.001,altitude_m:100,heading_deg:40}));const r=await fetch(base+'/api/realtime/ingest',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(frames)});assert.equal(r.status,200)}
|
||||
let report={};
|
||||
try{
|
||||
await new Promise(r=>proxy.listen(0,'127.0.0.1',r));base='http://127.0.0.1:'+proxy.address().port;start();await ready();
|
||||
start();await ready();
|
||||
assert.deepEqual((await snapshot()).entries,[]);
|
||||
await save('LIST-WHITE','white');await save('LIST-BLACK','black');await save('OFFLINE_001','white');
|
||||
for(const file of ['target-lists.css','map-adapter.js'])assert.equal(await(await fetch(base+'/'+file)).text(),await readFile(path.join('dist/web-ui',file),'utf8'));
|
||||
@@ -96,4 +94,4 @@ try{
|
||||
assert.equal(await page.locator('.mc-map-toolstrip').count(),0);assert.equal(await page.evaluate(()=>window.ridMap.metrics().camera.pitch),0);
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
|
||||
report={status:'PASS',root,exe,geometry,errors,csp,revision:persisted.revision,entries:persisted.entries.length,checks:['exact persisted membership independent of registration','online quick marking and offline entry','map and directory filtering without telemetry loss','black alert deduplication','safe notes and reactive remote updates','cross-browser sync preserves unsaved draft','optimistic concurrency and failed save rollback','busy controls and ID validation','removal restores unclassified','four viewports and 200% zoom','escape return focus','restart persistence','failed initial load and stale snapshot recovery','topdown map and removed toolbar preserved']};console.log(JSON.stringify(report));
|
||||
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify({errors,csp}));if(browser){const p=browser.contexts()[0]?.pages()[0];if(p)console.log('MAP',await p.evaluate(()=>window.ridMap?.metrics()).catch(()=>null));}if(browser){const p=browser.contexts()[0]?.pages()[0];if(p)await p.screenshot({path:path.join(root,'failure.png')}).catch(()=>{});}throw error;}finally{clearInterval(heartbeat);if(browser)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,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output)}
|
||||
}catch(error){console.log('FAILED ROOT',root,error.stack,JSON.stringify({errors,csp}));if(browser){const p=browser.contexts()[0]?.pages()[0];if(p)console.log('MAP',await p.evaluate(()=>window.ridMap?.metrics()).catch(()=>null));}if(browser){const p=browser.contexts()[0]?.pages()[0];if(p)await p.screenshot({path:path.join(root,'failure.png')}).catch(()=>{});}throw error;}finally{clearInterval(heartbeat);if(browser)await browser.close();await stop();await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));await writeFile(path.join(root,'server.log'),output)}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs';
|
||||
const base=UI_URL;
|
||||
await assertUiPortAvailable();
|
||||
// Real Rust/Wasm acceptance in an isolated database. Never opens receiver transports.
|
||||
import {mkdtemp,writeFile,readFile} from 'node:fs/promises';
|
||||
import {tmpdir} from 'node:os';
|
||||
@@ -5,8 +8,6 @@ import path from 'node:path';
|
||||
import {spawn} from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import net from 'node:net';
|
||||
const {chromium}=createRequire(import.meta.url)('playwright');
|
||||
const {PNG}=createRequire(import.meta.url)('pngjs');
|
||||
const contrastCases=[];
|
||||
@@ -18,16 +19,8 @@ async function contrast(page, label, selectors, required=true) {
|
||||
}
|
||||
const root=await mkdtemp(path.join(tmpdir(),'RID-workspace-'));
|
||||
const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe';
|
||||
const frontendPort=Number(process.env.RID_BROWSER_TEST_PORT||18787),backendPort=Number(process.env.RID_BACKEND_TEST_PORT||18788);
|
||||
const base='http://127.0.0.1:'+frontendPort;
|
||||
// Keep production origin checks unchanged. Only this isolated proxy maps the test origin.
|
||||
const sockets=new Set();
|
||||
const proxy=http.createServer((req,res)=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';const upstream=http.request({hostname:'127.0.0.1',port:backendPort,path:req.url,method:req.method,headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});upstream.on('error',()=>{res.writeHead(502);res.end()});req.pipe(upstream)});
|
||||
proxy.on('upgrade',(req,socket,head)=>{const upstream=net.connect(backendPort,'127.0.0.1');sockets.add(socket);sockets.add(upstream);upstream.on('connect',()=>{const headers={...req.headers,host:'127.0.0.1:8787'};if(headers.origin===base)headers.origin='http://127.0.0.1:8787';upstream.write(`GET ${req.url} HTTP/1.1\r\n${Object.entries(headers).map(([k,v])=>`${k}: ${v}`).join('\r\n')}\r\n\r\n`);if(head.length)upstream.write(head);socket.pipe(upstream);upstream.pipe(socket)});upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>{upstream.destroy();sockets.delete(socket);sockets.delete(upstream)})});
|
||||
let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(800)});occupied=true;}catch{}if(occupied)throw Error('8787 occupied; preserving existing service');
|
||||
const backendOccupied=await new Promise(resolve=>{const socket=net.connect(backendPort,'127.0.0.1');socket.once('connect',()=>{socket.destroy();resolve(true)});socket.once('error',()=>resolve(false));socket.setTimeout(800,()=>{socket.destroy();resolve(false)})});if(backendOccupied)throw Error('18788 occupied; preserving existing service');
|
||||
let output='',child,browser;const errors=[],csp=[];
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',RID_TEST_PORT:String(backendPort)},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message);}
|
||||
function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32',},windowsHide:true,stdio:['ignore','pipe','pipe']});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;}}
|
||||
async function preferences(){return (await fetch(base+'/api/appearance')).json();}
|
||||
@@ -50,7 +43,7 @@ async function setLegacyTheme(page, theme) {
|
||||
}
|
||||
|
||||
try{
|
||||
await new Promise((resolve,reject)=>{proxy.once('error',reject);proxy.listen(frontendPort,'127.0.0.1',resolve)});start();await ready();browser=await chromium.launch({headless:true,executablePath:process.env.RID_BROWSER_PATH||'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'});
|
||||
start();await ready();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},acceptDownloads:true});const page=await context.newPage();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());});
|
||||
for(const asset of ['glass.css','workbench.css'])assert.equal(await (await fetch(base+'/'+asset)).text(), await readFile('crates/web-ui/public/'+asset,'utf8'));
|
||||
await page.goto(base);await page.locator('body[data-screen=home]').waitFor();
|
||||
@@ -191,4 +184,4 @@ try{
|
||||
await page.setViewportSize({width:1600,height:1000});await page.locator('.reference-rail [data-open=settings]').click();await page.locator('[data-wall=B1]').click();await waitPref(p=>p.wallpaper==='B1');await stop();start();await ready();assert.equal((await preferences()).wallpaper,'B1');await page.reload();await page.waitForFunction(()=>document.getElementById('workspace-wallpaper').src.includes('B1-wallpaper'));
|
||||
assert.deepEqual(errors,[]);assert.deepEqual(csp,[]);
|
||||
await writeFile(path.join(root,'report.json'),JSON.stringify({status:'PASS',root,errors,csp,contrastCases,workbenchCases,scenarios:['B1 home: three accessible cards, keyboard activation and return focus','shared home navigation preserves menu state and return focus','15 home viewport/theme cases','B4 first-use and reset default','real Rust/Wasm','three legacy values share A+C material','application DB preferences across independent browser contexts and server restart','custom wallpaper and invalid file rollback','stale settings update rejected','register/edit/QR/XLSX','actual Worker websocket and synthetic ingress','no fabricated empty targets','real local registration matching','overlay collapse','receiver controls','four viewport sizes']},null,2));console.log(JSON.stringify({status:'PASS',root}));
|
||||
}finally{if(browser)await browser.close();await stop();for(const socket of sockets)socket.destroy();await new Promise(r=>proxy.close(r));await writeFile(path.join(root,'server.log'),output);}
|
||||
}finally{if(browser)await browser.close();await stop();await writeFile(path.join(root,'server.log'),output);}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// UI acceptance runs serially on the same origin as the released application.
|
||||
// Never attach a test to a listener owned by another process.
|
||||
import net from 'node:net';
|
||||
export const UI_URL = 'http://127.0.0.1:8787';
|
||||
export async function assertUiPortAvailable() {
|
||||
await new Promise((resolve, reject) => {
|
||||
const probe = net.createServer();
|
||||
probe.once('error', () => reject(new Error('8787 occupied; stop the project safely before running UI acceptance. No existing service was changed.')));
|
||||
probe.listen(8787, '127.0.0.1', () => probe.close(resolve));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user