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