test: close review fixture and refresh race gaps

This commit is contained in:
abaishu0730 committed 2026-10-28 18:32:55 +08:00
1 parent 92dbb8a184
commit 5ab3cf60ce
3 files changed
+8 -4

No files matched your search

+5 -1
View File
@@ -4,6 +4,7 @@ const assert=require('node:assert/strict');
const fs=require('node:fs/promises');
const os=require('node:os');
const path=require('node:path');
const crypto=require('node:crypto');
const {Store}=require('../../src/modules/dashboard/store.cjs');
const {createDashboard}=require('../../src/app/dashboard.cjs');
const {RuleStore}=require('../../src/modules/order-rules/store.cjs');
@@ -20,11 +21,14 @@ test('category editor saves/reloads drafts, previews readable evidence without i
data.window={start:'2026-10-20T00:00:00+08:00',end:'2026-10-20T11:00:00+08:00',label:'工作日第一时段',available:true};
const writes=[];browser=await loadPlaywright().chromium.launch(browserOptions());const page=await browser.newPage({viewport:{width:1440,height:1000}});page.setDefaultTimeout(7000);const errors=[];page.on('pageerror',e=>errors.push(e.message));await page.clock.install();
await page.route('**/api/mail',route=>route.fulfill({json:{channels:[],templates:[],receipts:[],sends:[]}}));
await page.route('**/api/refresh/revisions*',route=>{const token=crypto.createHash('sha256').update(JSON.stringify([data.orders,data.batches,data.settings,data.window])).digest('hex');return route.fulfill({json:{version:1,regions:{home:token,orderRules:token,records:token,health:token,bpm:token,assistant:token,storage:token,mail:token}}});});
await page.route('**/api/order-rules**',async route=>{
const req=route.request(),url=new URL(req.url());let result;
if(req.method()==='GET'){
if(url.pathname==='/api/order-rules/configuration')result={...data,adapters:data.adapters.map(({sample,fields,...adapter})=>({...adapter,reference:false})),scopeProcesses:['订单流程'],scopeCatalog:[{processName:'订单流程',nodeName:'通知'}],resources:{templates:[],bindings:[],servers:[],errors:{}},restrictedTest:null};
else if(url.pathname==='/api/order-rules/status')result={settings:{enabled:data.settings.enabled},capabilities:data.capabilities};
else if(url.pathname==='/api/order-rules/notification-settings')result={settings:data.settings,restrictedTest:null};
else if(url.pathname==='/api/order-rules/catalog')result={processes:[{processName:'订单流程',nodes:['通知']}],bindings:[],templates:[],groups:[],servers:[],errors:{},window:{...data.window}};
else if(url.pathname==='/api/order-rules/configuration/samples'){const {fields,...metadata}=sample;result={samples:[{id:'real-1',provenance:'server-provider',processName:'订单流程',sample:{...metadata,receivedAt:'2026-10-19T09:00:00+08:00'}}]};}
else if(url.pathname.endsWith('/fields'))result={samples:[{id:'real-1',provenance:'server-provider',processName:'订单流程',sample:{...sample,receivedAt:'2026-10-19T09:00:00+08:00'}}]};
else if(['/api/order-rules/orders','/api/order-rules/batches'].includes(url.pathname)){
@@ -33,7 +37,7 @@ test('category editor saves/reloads drafts, previews readable evidence without i
}else if(url.pathname==='/api/order-rules'){
assert.equal(url.searchParams.get('view'),'summary','business views must request the bounded summary');
const {orders,batches,audit,...summary}=data;
result={...summary,issues:[],templateUsage:[],counts:{orders:orders.length,blocked:0,unknown:0,activeBatches:batches.length}};
result={...summary,window:{...data.window,available:true},issues:[],templateUsage:[],counts:{orders:orders.length,blocked:0,unknown:0,activeBatches:batches.length}};
}else throw Error('Unexpected fixture GET '+url.pathname);
}else{
const body=req.postDataJSON();writes.push({path:url.pathname,body});