سامانه صدور فاکتور و حسابداری

test: reproduce slow Pages dispatcher without delaying login controls

davoodmehraban89 committed Oct 16, 2026 at 01:22 UTC 926a44321daf56f989a595b74048145e155451cc
1 file changed +46
scripts/pages-artifact.spec.js
+46
@@ -56,6 +56,52 @@ test('Production CSP login and connectivity actions work while later ERP JS is s
56 expect(delayedModuleFinished).toBe(false);
57 });
58
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 standaloneScripts=new Set([
63 + 'enterprise-iran.js','enterprise-iran-v2.js','accounting-foundation.js',
64 + 'journal-engine.js','admin.js','organization-rbac.js','taxpayer-print.js'
65 + ]);
66 + page.on('request',req=>{
67 + const filename=new URL(req.url()).pathname.split('/').at(-1);
68 + if(standaloneScripts.has(filename))unexpectedLegacyRequests.push(filename);
69 + });
70 + // The owner's Chrome waterfall showed this bottom-of-body CSP dispatcher
71 + // unusually slow. A delayed response is used; an HTTP 304 is not treated
72 + // as a failed script, and no authenticated account or finance data is used.
73 + await page.route('**/js/generated-dynamic-handlers.js',async route=>{
74 + await new Promise(resolve=>setTimeout(resolve,4500));
75 + delayedDispatcherReleased=true;
76 + await route.continue();
77 + });
78 + await page.goto(base,{waitUntil:'commit'});
79 + await expect(page.locator('#auth-login-button')).toBeEnabled({timeout:3500});
80 + const early=await page.evaluate(()=>({
81 + documentState:document.readyState,
82 + authReady:window.FinoraStartupStatus?.authFormReady,
83 + staticHandlers:window.FinoraLoginActionsBound,
84 + authVisible:getComputedStyle(document.getElementById('auth-screen')).display!=='none'
85 + }));
86 + expect(early).toMatchObject({
87 + documentState:'loading',
88 + authReady:true,
89 + staticHandlers:true,
90 + authVisible:true
91 + });
92 + expect(delayedDispatcherReleased,'The auth form must not await the bottom dispatcher').toBe(false);
93 + const prompt=page.waitForEvent('dialog').then(async dialog=>{
94 + expect(dialog.message()).toContain('ایمیل');
95 + await dialog.dismiss();
96 + });
97 + await Promise.all([page.locator('#auth-login-button').click(),prompt]);
98 + await page.waitForLoadState('domcontentloaded',{timeout:15000});
99 + await expect.poll(()=>page.evaluate(()=>window.FinoraStartupStatus?.extensionsReady),{timeout:15000}).toBe(true);
100 + expect(delayedDispatcherReleased).toBe(true);
101 + expect(unexpectedLegacyRequests,'Published Pages must not refetch already bundled ERP source modules').toEqual([]);
102 + expect(await page.locator('#auth-screen').isVisible()).toBe(true);
103 +});
104 +
105 test('Built Pages uses exactly one SHA-pinned local bundle for all 14 ERP extensions',async({page})=>{
106 const requested=[];
107 page.on('request',req=>{