سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 00:30 UTC
test: expose actionable sync and RPC diagnostics for failing browser workflows (#216)
davoodmehraban89 committed
Nov 18, 2026 at 12:10 UTC
2363a9ac5011b41fc4067e1e4a50a682934a02f2
1 file changed
+15
scripts/accounting-document-workflow.spec.js
+15
@@ -22,10 +22,25 @@ function fakeServer(){
22
}
23
function remoteInvoices(server){return [...server.records.values()].filter(r=>r.collection==='invoices').map(r=>copy(r.data));}
24
25
+test.afterEach(async({page},testInfo)=>{
26
+ if(testInfo.status===testInfo.expectedStatus)return;
27
+ try{
28
+ const state=await page.evaluate(()=>({
29
+ syncPending:typeof syncPending==='undefined'?null:syncPending,
30
+ syncRunning:typeof syncRunning==='undefined'?null:syncRunning,
31
+ syncFailCount:typeof syncFailCount==='undefined'?null:syncFailCount,
32
+ currentOrg:typeof currentUser==='undefined'?null:currentUser?.organizationId,
33
+ pendingDiff:typeof computeDiff==='function'?(()=>{const d=computeDiff();return {up:d.up.map(x=>x.key),del:d.del};})():null,
34
+ alerts:window.__f0Alerts||[]
35
+ }));
36
+ console.log('FINORA_F0_FAILURE_DIAGNOSTICS',JSON.stringify(state));
37
+ }catch(err){console.log('FINORA_F0_DIAGNOSTICS_UNAVAILABLE',String(err));}
38
+});
39
async function installHarness(page,server){
40
await page.exposeFunction('qaF0Read',async()=>[...server.records.values()].map(row=>({...copy(row),version:Number(row.version)||1})));
41
await page.exposeFunction('qaF0Write',async args=>{
42
server.rpcCount++;
43
+ if(server.rpcCount<=3)console.log('FINORA_F0_RPC_TRACE',JSON.stringify({org:args.p_organization_id,upserts:(args.p_upserts||[]).map(x=>x.collection+'|'+x.id),deletes:(args.p_deletes||[]).map(x=>x.collection+'|'+x.id)}));
44
if(server.failNext){server.failNext=false;server.failCount++;return {error:{message:'Network unavailable — isolated QA failure',code:'QA_NETWORK'}};}
45
if(args.p_organization_id!=='QA_ORG')return {error:{message:'Unexpected organization scope',code:'QA_ORG_SCOPE'}};
46
const upserts=[];