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:
2026-10-27 20:04:34 +08:00
parent a68dc50798
commit 281af4fe3d
42 changed files with 2435 additions and 1301 deletions
+7 -9
View File
@@ -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);}