```
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,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));}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user