سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 08:00 UTC
test: capture exact Chromium initiator of unexpected legacy Pages request
davoodmehraban89 committed
Oct 16, 2026 at 01:29 UTC
6dc91cddf403a2d482c30795f2b32e20cd6b82d2
1 file changed
+19
-2
scripts/pages-artifact.spec.js
+19
-2
@@ -59,13 +59,29 @@ test('Production CSP login and connectivity actions work while later ERP JS is s
59
test('Slow final CSP dispatcher keeps login usable without loading legacy ERP scripts',async({page})=>{
60
let delayedDispatcherReleased=false;
61
const unexpectedLegacyRequests=[];
62
+ const initiatorTrace=[];
63
+ const session=await page.context().newCDPSession(page);
64
+ await session.send('Network.enable');
65
+ session.on('Network.requestWillBeSent',event=>{
66
+ if(!/\/enterprise-iran(?:-v2)?\.js(?:\?|$)/.test(event.request.url))return;
67
+ initiatorTrace.push({
68
+ path:new URL(event.request.url).pathname,
69
+ type:event.type||'unknown',
70
+ initiatorType:event.initiator?.type||'unknown',
71
+ stack:(event.initiator?.stack?.callFrames||[]).slice(0,3).map(frame=>({
72
+ file:String(frame.url||'').split('?')[0].replace(/^https?:\/\/[^/]+/,''),
73
+ line:frame.lineNumber,
74
+ name:frame.functionName
75
+ }))
76
+ });
77
+ });
78
const standaloneScripts=new Set([
79
'enterprise-iran.js','enterprise-iran-v2.js','accounting-foundation.js',
80
'journal-engine.js','admin.js','organization-rbac.js','taxpayer-print.js'
81
]);
82
page.on('request',req=>{
83
const filename=new URL(req.url()).pathname.split('/').at(-1);
68
- if(standaloneScripts.has(filename))unexpectedLegacyRequests.push(filename);
84
+ if(standaloneScripts.has(filename))unexpectedLegacyRequests.push({filename,type:req.resourceType()});
85
});
86
// The owner's Chrome waterfall showed this bottom-of-body CSP dispatcher
87
// unusually slow. A delayed response is used; an HTTP 304 is not treated
@@ -98,7 +114,8 @@ test('Slow final CSP dispatcher keeps login usable without loading legacy ERP sc
114
await page.waitForLoadState('domcontentloaded',{timeout:15000});
115
await expect.poll(()=>page.evaluate(()=>window.FinoraStartupStatus?.extensionsReady),{timeout:15000}).toBe(true);
116
expect(delayedDispatcherReleased).toBe(true);
101
- expect(unexpectedLegacyRequests,'Published Pages must not refetch already bundled ERP source modules').toEqual([]);
117
+ if(unexpectedLegacyRequests.length)console.log('LEGACY_PAGES_REQUEST_TRACE='+JSON.stringify(initiatorTrace));
118
+ expect(unexpectedLegacyRequests,'Published Pages must not refetch already bundled ERP source modules; CDP '+JSON.stringify(initiatorTrace)).toEqual([]);
119
expect(await page.locator('#auth-screen').isVisible()).toBe(true);
120
});
121