From 9befb6e9e072783f134a049412613f9690365b71 Mon Sep 17 00:00:00 2001 From: JiuContinent Date: Tue, 27 Oct 2026 20:04:53 +0800 Subject: [PATCH] =?UTF-8?q?```=20test(scripts):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC=E4=BB=A5=E9=80=82=E9=85=8D?= =?UTF-8?q?=E6=97=A0=E5=A4=B4=E6=A8=A1=E5=BC=8F=E5=92=8C=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E5=99=A8=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 所有测试脚本的 spawn 调用添加 --no-browser 参数,避免自动打开浏览器 - 更新 test-browser.mjs 导航流程,改为从 archives 页面通过 reference-rail 进入注册模块 - 更新 test-receiver.mjs 断言以适配多接收器架构(receivers.json 数组格式、 接收器前缀 target_id、默认 receiver_id) - test-module-navigation.mjs 新增设备管理模块的导航标签断言 ``` --- scripts/test-browser.mjs | 8 ++++---- scripts/test-map-settings.mjs | 2 +- scripts/test-module-navigation.mjs | 6 +++--- scripts/test-monitoring.mjs | 2 +- scripts/test-realtime.mjs | 2 +- scripts/test-receiver.mjs | 8 ++++---- scripts/verify.mjs | 12 ++++++------ 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/test-browser.mjs b/scripts/test-browser.mjs index b14d01d..140c747 100644 --- a/scripts/test-browser.mjs +++ b/scripts/test-browser.mjs @@ -17,21 +17,21 @@ const db=new DatabaseSync(path.join(root,'registry/data/registry.sqlite')); db.exec("CREATE TABLE records(id TEXT PRIMARY KEY,serial_no TEXT NOT NULL UNIQUE,uas_code TEXT NOT NULL UNIQUE,model_name TEXT NOT NULL DEFAULT '',owner_name TEXT NOT NULL DEFAULT '',created_at TEXT NOT NULL); CREATE TABLE photos(record_id TEXT NOT NULL REFERENCES records(id) ON DELETE CASCADE,slot INTEGER NOT NULL CHECK(slot IN(1,2)),mime_type TEXT NOT NULL,image BLOB NOT NULL,PRIMARY KEY(record_id,slot));"); for(let i=1;i<=21;i++)db.prepare('INSERT INTO records VALUES(?,?,?,?,?,?)').run(String(i).padStart(36,'0'),`BROWSER-${String(i).padStart(3,'0')}`,`FPV${String(i).padStart(8,'0')}`,'演示机型','验收数据','2020-01-01T00:00:00.000Z');db.close(); const png=Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAEElEQVR4nGMImHERiBggFAAuRgblSRFDagAAAABJRU5ErkJggg==','base64'); -const child=spawn(exe,['--data-root',root],{windowsHide:true,env:{...process.env,PATH:'C:\\Windows\\System32'},stdio:['ignore','pipe','pipe']});let output='';let spawnError; +const child=spawn(exe,['--data-root',root,'--no-browser'],{windowsHide:true,env:{...process.env,PATH:'C:\\Windows\\System32'},stdio:['ignore','pipe','pipe']});let output='';let spawnError; child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>spawnError=e); let browser; try{ for(let i=0;i<150;i++){if(spawnError||child.exitCode!==null)throw Error(output||String(spawnError));try{if((await fetch(base+'/api/records')).ok)break;}catch{}await new Promise(r=>setTimeout(r,100));} browser=await chromium.launch({headless:true,executablePath:process.env.RID_BROWSER_PATH||undefined});const page=await browser.newPage({viewport:{width:1366,height:1000},acceptDownloads:true});let errors=[];page.on('pageerror',e=>errors.push(e.message)); - await page.goto(base+'/?app=register');await page.locator('#page-status').filter({hasText:'共 21 条'}).waitFor(); - await page.fill('#serial-no','UI-NEW-001');await page.fill('#model-name','待清空机型');await page.fill('#owner-name','原登记人');await page.setInputFiles('#photo-1',{name:'photo.png',mimeType:'image/png',buffer:png});await page.click('#register-button');await page.locator('#form-message').filter({hasText:'登记成功'}).waitFor(); + await page.goto(base+'/?app=archives');await page.locator('#page-status').filter({hasText:'共 21 条'}).waitFor();await page.locator('.reference-rail [data-open=register]').click(); + await page.fill('#serial-no','UI-NEW-001');await page.fill('#model-name','待清空机型');await page.fill('#owner-name','原登记人');await page.setInputFiles('#photo-1',{name:'photo.png',mimeType:'image/png',buffer:png});await page.click('#register-button');await page.locator('#form-message').filter({hasText:'登记成功'}).waitFor();await page.locator('.reference-rail [data-open=archives]').click(); const card=page.locator('.archive-card').filter({has:page.getByRole('heading',{name:'UI-NEW-001',exact:true})}); await card.locator('.archive-more').click();await card.getByRole('button',{name:'编辑资料 / 照片'}).click();assert.equal(await page.locator('#edit-model').evaluate(el=>el===document.activeElement),true);await page.click('#edit-cancel');assert.equal(await page.locator('#edit-dialog').isVisible(),false); await card.locator('.archive-more').click();await card.getByRole('button',{name:'编辑资料 / 照片'}).click();await page.fill('#edit-model','');await page.fill('#edit-owner','修改后的登记人');await page.check('#edit-delete-1');await page.setInputFiles('#edit-photo-2',{name:'new.png',mimeType:'image/png',buffer:png}); let patches=0;const listener=req=>{if(req.method()==='PATCH')patches++;};page.on('request',listener);await page.click('#edit-save');await page.locator('#edit-dialog').waitFor({state:'hidden'});assert.equal(patches,1);page.off('request',listener); let records=(await (await fetch(base+'/api/records')).json()).records;let r=records.find(r=>r.serialNo==='UI-NEW-001');assert.equal(r.modelName,'');assert.equal(r.ownerName,'修改后的登记人');assert.equal(r.photo1Url,null);assert.ok(r.photo2Url); await card.locator('.archive-more').click();await card.getByRole('button',{name:'编辑资料 / 照片'}).click();await page.fill('#edit-owner','不得保存');await page.setInputFiles('#edit-photo-1',{name:'bad.png',mimeType:'image/png',buffer:Buffer.from('invalid image')});await page.click('#edit-save');await page.locator('#edit-message').filter({hasText:'照片内容与格式不符'}).waitFor();assert.equal((await(await fetch(base+'/api/records')).json()).records.find(item=>item.id===r.id).ownerName,'修改后的登记人');await page.keyboard.press('Escape'); - await page.click('#next-page');await page.locator('#page-status').filter({hasText:'第 2 / 2 页'}).waitFor();assert.equal(await page.locator('.archive-card').count(),2); + await page.fill('#history-query','');await page.locator('#page-status').filter({hasText:'共 22 条'}).waitFor();await page.click('#next-page');await page.locator('#page-status').filter({hasText:'第 2 / 2 页'}).waitFor();assert.equal(await page.locator('.archive-card').count(),2); await page.fill('#history-query','UI-NEW-001');await page.locator('#page-status').filter({hasText:'第 1 / 1 页'}).waitFor();assert.equal(await page.locator('.archive-card').count(),1); await page.fill('#history-query','');await page.locator('#page-status').filter({hasText:'共 22 条'}).waitFor();await page.locator('#selection-toggle').click();await page.check('#select-all');assert.equal(await page.locator('.archive-select input:checked').count(),20); const downloadPromise=page.waitForEvent('download');const exportRequest=page.waitForRequest(req=>req.url().endsWith('/api/export/excel'));await page.click('#export-toggle');await page.click('#export-excel');assert.equal((await exportRequest).postDataJSON().ids.length,20);const download=await downloadPromise;await download.saveAs(path.join(root,'browser-export.xlsx')); diff --git a/scripts/test-map-settings.mjs b/scripts/test-map-settings.mjs index 12bd3fc..c94292a 100644 --- a/scripts/test-map-settings.mjs +++ b/scripts/test-map-settings.mjs @@ -21,7 +21,7 @@ function xy(lon,lat,z){const n=2**z,r=lat*Math.PI/180;return [Math.floor((lon+18 const [x,y]=xy(120.155,30.285,11); for(const layer of ['vec_w','cva_w','img_w','cia_w']){const dir=path.join(root,`maps/cache/${layer}/11/${x}`);await mkdir(dir,{recursive:true});await writeFile(path.join(dir,y+'.tile'),png);} let child,browser,output='';const errors=[],csp=[];let report={}; -function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env,windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);} +function start(){child=spawn(exe,['--data-root',root,'--simulation-api','--no-browser'],{env,windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);} async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/maps/preferences')).ok)return;}catch{}await new Promise(r=>setTimeout(r,100));}throw Error('server timeout');} async function stop(){if(child?.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}} 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};}; diff --git a/scripts/test-module-navigation.mjs b/scripts/test-module-navigation.mjs index 4c619a2..ab6498b 100644 --- a/scripts/test-module-navigation.mjs +++ b/scripts/test-module-navigation.mjs @@ -13,7 +13,7 @@ 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'; 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,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','--no-browser'],{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}; @@ -52,8 +52,8 @@ try { await page.setViewportSize({width,height:1000}); for(const name of ['archives','register']) {await open(name);assert.ok(await page.locator('#workspace-content').evaluate(e=>e.scrollWidth<=e.clientWidth+1));} } - await home();await page.locator('#home-app-realtime').click();await page.waitForURL('**/realtime');await labels(['实时工作台','电子围栏','黑白名单管理']); - for(const name of ['geofences','target-lists','realtime']) {await open(name);await labels(['实时工作台','电子围栏','黑白名单管理']);assert.equal(await page.locator('.reference-rail [aria-current=page]').getAttribute('data-menu'),name);} + await home();await page.locator('#home-app-realtime').click();await page.waitForURL('**/realtime');await labels(['实时工作台','设备管理','电子围栏','黑白名单管理']); + for(const name of ['geofences','target-lists','receivers','realtime']) {await open(name);await labels(['实时工作台','设备管理','电子围栏','黑白名单管理']);assert.equal(await page.locator('.reference-rail [aria-current=page]').getAttribute('data-menu'),name);} await page.locator('#toggle-menu').click();assert.equal(await page.locator('.reference-rail').isVisible(),false);await page.locator('#toggle-menu').click(); await home();await page.locator('#home-app-settings').focus();await page.keyboard.press('Enter');await labels(['壁纸与外观','显示方式','地图配置']); await page.locator('#toggle-menu').click();await page.locator('.workspace-home-link').click();await labels([]);assert.equal(await page.locator('#toggle-menu').isVisible(),false);await page.locator('#home-app-settings').click();assert.equal(await page.locator('.reference-rail').isVisible(),false);assert.equal(await page.locator('#toggle-menu').isVisible(),true);await page.locator('#toggle-menu').click();await labels(['壁纸与外观','显示方式','地图配置']); diff --git a/scripts/test-monitoring.mjs b/scripts/test-monitoring.mjs index 2a61a4e..3478f39 100644 --- a/scripts/test-monitoring.mjs +++ b/scripts/test-monitoring.mjs @@ -10,7 +10,7 @@ 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-')); 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},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','--no-browser'],{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();} diff --git a/scripts/test-realtime.mjs b/scripts/test-realtime.mjs index 9464a63..c8f4626 100644 --- a/scripts/test-realtime.mjs +++ b/scripts/test-realtime.mjs @@ -13,7 +13,7 @@ assert.ok(count>0&&count<=10000&&duration>0&&duration<=7200); const base='http://127.0.0.1:8787'; let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(1000)});occupied=true;}catch{} if(occupied)throw Error('8787 occupied; refusing to attach to another server'); -const child=spawn(exe,['--data-root',root,'--simulation-api'],{windowsHide:true,stdio:['ignore','pipe','pipe']});let output='';let failure; +const child=spawn(exe,['--data-root',root,'--simulation-api','--no-browser'],{windowsHide:true,stdio:['ignore','pipe','pipe']});let output='';let failure; child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>failure=e);let browser;let monitorHandle;let simulatorProcess; try{ let ready=false;for(let i=0;i<150;i++){if(failure||child.exitCode!==null)throw Error(output||String(failure));try{if((await fetch(base+'/api/realtime/status')).ok){ready=true;break;}}catch{}await new Promise(r=>setTimeout(r,100));}assert.ok(ready); diff --git a/scripts/test-receiver.mjs b/scripts/test-receiver.mjs index 25f20ff..7d5369d 100644 --- a/scripts/test-receiver.mjs +++ b/scripts/test-receiver.mjs @@ -8,7 +8,7 @@ import net from 'node:net'; import assert from 'node:assert/strict'; const root=await mkdtemp(path.join(tmpdir(),'RID-receiver-'));const base='http://127.0.0.1:8787'; let occupied=false;try{await fetch(base,{signal:AbortSignal.timeout(1000)});occupied=true;}catch{}if(occupied)throw Error('8787 occupied'); -const child=spawn(process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe',['--data-root',root],{windowsHide:true,stdio:['ignore','pipe','pipe']});let output='',failure;child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>failure=e); +const child=spawn(process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe',['--data-root',root,'--no-browser'],{windowsHide:true,stdio:['ignore','pipe','pipe']});let output='',failure;child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>failure=e); const packet={target_id:'TEST-NET-001',receiver_id:'TEST-RECEIVER',source_epoch:1,sequence:1,longitude:120.1,latitude:30,altitude_m:100,heading_deg:90}; async function poll(test){for(let i=0;i<100;i++){if(await test())return;await new Promise(r=>setTimeout(r,30));}throw Error('receiver state timeout '+output);} async function save(config,expected=200){const r=await fetch(base+'/api/receiver/config',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(config)});assert.equal(r.status,expected);return r;} @@ -20,14 +20,14 @@ try{ const config={...initial,enabled:true,transport:'udp',format:'json-lines',bindIp:'127.0.0.1',port};await save(config); await poll(async()=>(await(await fetch(base+'/api/receiver/status')).json()).state==='udp-listening'); const udp=dgram.createSocket('udp4');await new Promise((resolve,reject)=>udp.send(Buffer.from(JSON.stringify(packet)),port,'127.0.0.1',e=>e?reject(e):resolve()));udp.close(); - await poll(async()=>(await(await fetch(base+'/api/realtime/snapshot')).json()).targets.some(t=>t.observation.target_id===packet.target_id)); + await poll(async()=>(await(await fetch(base+'/api/realtime/snapshot')).json()).targets.some(t=>t.observation.target_id==='SRC-7-default-LEGACY-'+packet.target_id&&t.observation.receiver_id==='default')); await save({...config,transport:'tcp-listen'});await poll(async()=>(await(await fetch(base+'/api/receiver/status')).json()).state==='tcp-listening'); const released=dgram.createSocket('udp4');await new Promise((resolve,reject)=>{released.once('error',reject);released.bind(port,'127.0.0.1',resolve)});released.close(); const tcp=net.createConnection({host:'127.0.0.1',port});await new Promise((resolve,reject)=>{tcp.once('connect',resolve);tcp.once('error',reject)});const bytes=JSON.stringify({...packet,sequence:2,longitude:120.2})+'\n';tcp.write(bytes.slice(0,10));await new Promise(r=>setTimeout(r,5));tcp.end(bytes.slice(10)); - await poll(async()=>(await(await fetch(base+'/api/realtime/snapshot')).json()).targets.some(t=>t.observation.sequence===2)); + await poll(async()=>(await(await fetch(base+'/api/realtime/snapshot')).json()).targets.some(t=>t.observation.longitude===120.2&&t.observation.sequence===1&&t.observation.receiver_id==='default')); await save({...config,transport:'tcp-listen',enabled:false});assert.equal((await(await fetch(base+'/api/receiver/status')).json()).state,'stopped'); const capture=await(await fetch(base+'/api/receiver/capture')).json();assert.ok(capture.bytes>0&&capture.bytes<=4096);assert.ok(capture.data.length>0); - const persisted=JSON.parse(await readFile(path.join(root,'receiver-config.json'),'utf8'));assert.equal(persisted.enabled,false);assert.equal(persisted.transport,'tcp-listen'); + const persisted=JSON.parse(await readFile(path.join(root,'receivers.json'),'utf8')).find(entry=>entry.id==='default').config;assert.equal(persisted.enabled,false);assert.equal(persisted.transport,'tcp-listen'); const foreign=await fetch(base+'/api/receiver/config',{method:'POST',headers:{'content-type':'application/json',origin:'https://foreign.example'},body:JSON.stringify(config)});assert.equal(foreign.status,403); console.log(JSON.stringify({status:'PASS',root,scenarios:['disabled and raw defaults','invalid serial path rejected without device access','UDP JSON input','TCP fragmented JSON input','switch releases UDP socket','disable stops listener','bounded capture retained on stop','configuration persisted','origin restriction']})); }finally{if(child.exitCode===null&&!failure){const done=new Promise(r=>child.once('exit',r));child.kill();await done;}await writeFile(path.join(root,'server.log'),output);} diff --git a/scripts/verify.mjs b/scripts/verify.mjs index 46a3dca..287fd37 100644 --- a/scripts/verify.mjs +++ b/scripts/verify.mjs @@ -56,7 +56,7 @@ async function exports(id,label){ } try{ const exe=path.resolve(process.argv[2]||path.join(repo,'dist/FPV-RID-Rust/fpv-rid-registry.exe')); - await start(exe,['--data-root',root]); + await start(exe,['--data-root',root,'--no-browser']); const a=await api('/api/records','POST',{serialNo:'TEST-SN-001',uasCode:'FPV00000001',modelName:'<测试>',ownerName:'原登记人',photo1:png}); const id=a.record.id;assert.match(id,/^[0-9a-f]{36}$/);assert.equal(a.existing,false); const b=await api('/api/records','POST',{serialNo:'TEST-SN-001',modelName:'',ownerName:''});assert.equal(b.existing,true);assert.equal(b.record.modelName,'<测试>'); @@ -66,7 +66,7 @@ try{ await exports(id,'rust-initial');await stop(); const dbPath=path.join(root,'registry/data/registry.sqlite'); let db=new DatabaseSync(dbPath);const before=db.prepare('SELECT hex(image) AS bytes FROM photos').get().bytes;db.close(); - await start(exe,['--data-root',root]); + await start(exe,['--data-root',root,'--no-browser']); assert.equal((await api('/api/records')).records[0].id,id); assert.equal((await api('/api/resolve?url='+encodeURIComponent(base+'/r/'+id))).id,id); await api('/api/resolve?url='+encodeURIComponent('http://example.com/r/'+id),'GET',undefined,400); @@ -84,7 +84,7 @@ try{ await api('/api/records','POST',{serialNo:'TEST-SN-001',photo1:png}); // Simulate an archive directory failure without modifying the active database. await stop();await rm(path.join(root,'档案库'),{recursive:true});await writeFile(path.join(root,'档案库'),'blocked'); - await start(exe,['--data-root',root]); + await start(exe,['--data-root',root,'--no-browser']); const pending=await api('/api/records','POST',{serialNo:'TEST-SN-003',ownerName:'已保存'});assert.equal(pending.archiveStatus,'pending');assert.ok(pending.warning); assert.equal((await api('/api/archive/status')).archiveStatus,'pending'); await api('/api/archive/retry','POST',{},500); @@ -93,14 +93,14 @@ try{ assert.equal((await api('/api/records')).records.length,2); await api('/api/records/'+id,'DELETE');assert.equal((await api('/api/records')).records.length,1); await api('/api/records/'+id,'PATCH',{ownerName:'resurrect',photo1:png},404); - await stop();await start(exe,['--data-root',root]);assert.equal((await api('/api/records')).records.length,1);await stop(); + await stop();await start(exe,['--data-root',root,'--no-browser']);assert.equal((await api('/api/records')).records.length,1);await stop(); db=new DatabaseSync(path.join(root,'档案库/登记数据库.sqlite'));assert.equal(db.prepare('SELECT COUNT(*) AS n FROM records').get().n,1);assert.equal(db.prepare('PRAGMA integrity_check').get().integrity_check,'ok');db.close(); const legacyRoot=path.join(root,'legacy-regression'); await mkdir(path.join(legacyRoot,'registry/data'),{recursive:true}); const legacyRows=[{id:'1'.repeat(36),serialNo:'IMPORT-001',uasCode:'FPV00000001',createdAt:'2020-01-01T00:00:00.000Z'},{id:'2'.repeat(36),serialNo:'IMPORT-002',uasCode:'FPV00000002'}]; const legacyFile=path.join(legacyRoot,'registry/data/records.json'); await writeFile(legacyFile,JSON.stringify(legacyRows)); - const rejected=spawn(exe,['--data-root',legacyRoot],{windowsHide:true,stdio:['ignore','pipe','pipe']}); + const rejected=spawn(exe,['--data-root',legacyRoot,'--no-browser'],{windowsHide:true,stdio:['ignore','pipe','pipe']}); let importError='';rejected.stderr.on('data',b=>importError+=b); const exitCode=await new Promise((resolve,reject)=>{rejected.once('exit',resolve);rejected.once('error',reject);}); assert.notEqual(exitCode,0);assert.match(importError,/第 2 条/); @@ -108,6 +108,6 @@ try{ assert.equal(db.prepare('SELECT COUNT(*) AS n FROM records').get().n,0); assert.equal(db.prepare('SELECT COUNT(*) AS n FROM registry_meta').get().n,0);db.close(); legacyRows[1].createdAt='2020-01-01T00:00:00.000Z';await writeFile(legacyFile,JSON.stringify(legacyRows)); - await start(exe,['--data-root',legacyRoot]);assert.equal((await api('/api/records')).records.length,2);await stop(); + await start(exe,['--data-root',legacyRoot,'--no-browser']);assert.equal((await api('/api/records')).records.length,2);await stop(); console.log(JSON.stringify({status:'PASS',root,scenarios:['Rust registration','Rust database restart','photo bytes','QR','ZIP/XLSX contents','HTML escaping','origin','PATCH','photo deletion','pagination','archive fault and retry','restart','backup integrity','invalid legacy import fails visibly and rolls back','corrected legacy file retries successfully']})); }finally{await stop();}