test(scripts): 更新测试脚本以适配无头模式和接收器重构

- 所有测试脚本的 spawn 调用添加 --no-browser 参数,避免自动打开浏览器
- 更新 test-browser.mjs 导航流程,改为从 archives 页面通过 reference-rail 进入注册模块
- 更新 test-receiver.mjs 断言以适配多接收器架构(receivers.json 数组格式、
  接收器前缀 target_id、默认 receiver_id)
- test-module-navigation.mjs 新增设备管理模块的导航标签断言
```
This commit is contained in:
2026-10-27 20:04:53 +08:00
parent 281af4fe3d
commit 9befb6e9e0
7 changed files with 20 additions and 20 deletions
+6 -6
View File
@@ -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();}