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

test(real-stack): diagnose actual GoTrue login and PostgREST responses on failure

davoodmehraban89 committed Oct 18, 2026 at 06:28 UTC 3b62d67dfffd6cc4fa68837706047f9f0d4ccd9a
1 file changed +23 -2
scripts/stage22-real-stack.mjs
+23 -2
@@ -57,6 +57,11 @@ const browser=await chromium.launch({headless:true,args:['--no-sandbox']});
57 const page=await browser.newPage();
58 const remote=[],errors=[];
59 page.on('pageerror',err=>errors.push(String(err.message).slice(0,140)));
60 +const responseCodes=[];
61 +page.on('response',res=>{
62 + const u=new URL(res.url());
63 + if(u.port==='54321')responseCodes.push({path:u.pathname,status:res.status()});
64 +});
65 await page.route('**/*',route=>{
66 const u=new URL(route.request().url());
67 if(!['localhost','127.0.0.1'].includes(u.hostname)){if(/supabase\.co|factoreasy\.ir/.test(u.hostname))remote.push(u.hostname);return route.abort()}
@@ -77,7 +82,23 @@ try{
82 await page.locator('#auth-email').fill('stage22.real.owner@example.invalid');
83 await page.locator('#auth-password').fill('Local-Stage22-Password!12345');
84 await page.locator('#auth-login-button').click();
80 - await page.waitForFunction(()=>document.getElementById('auth-screen')?.style.display==='none'&&!!window.currentUser?.organizationId,{timeout:50000});
85 + try{
86 + await page.waitForFunction(()=>document.getElementById('auth-screen')?.style.display==='none'&&!!window.currentUser?.organizationId,null,{timeout:50000});
87 + }catch(error){
88 + const stage=await page.evaluate(async()=>({
89 + authFormReady:window.FinoraStartupStatus?.authFormReady,
90 + assetsReady:window.FinoraStartupStatus?.extensionsReady,
91 + failedAssets:window.FinoraStartupStatus?.failedExtensionCount,
92 + authChecked:window.FinoraStartupStatus?.authChecked,
93 + loginState:document.getElementById('auth-login-status')?.dataset?.state,
94 + loginMessage:document.getElementById('auth-login-status')?.textContent?.slice(0,180),
95 + hasCurrentUser:!!window.currentUser,
96 + authSession:!!(await sb.auth.getSession()).data.session,
97 + orgContextReady:!!window.FinoraOrganizationContextReady
98 + }));
99 + console.error('REAL_LOGIN_DIAGNOSTIC '+JSON.stringify({stage,errors:errors.slice(0,5),responses:responseCodes.slice(-28)}));
100 + throw error;
101 + }
102 const login=await page.evaluate(async()=>({org:currentUser.organizationId,uid:currentUser.id,hasJWT:!!(await sb.auth.getSession()).data.session?.access_token,api:SUPABASE_URL}));
103 if(login.org!==org||login.uid!==owner||!login.hasJWT||login.api!==API)throw Error('REAL_UI_AUTH_JWT_OR_TENANT_FAILED');
104 evidence.login='PASS';evidence.scenarios.push('real-password-login');
@@ -141,7 +162,7 @@ try{
162 evidence.db={version:row.version,numberUnique:true,balanced:true,postedAudits:audits,auditViolations:violations};
163 console.log('STAGE22_REAL_STACK_PASS '+JSON.stringify({scenarios:evidence.scenarios,db:evidence.db,requests:evidence.network.length}));
164 }finally{
144 - evidence.pageErrors=errors.slice(0,6);evidence.remoteProductionAttempt=remote.length;
165 + evidence.pageErrors=errors.slice(0,6);evidence.authRestResponses=responseCodes.slice(-40);evidence.remoteProductionAttempt=remote.length;
166 fs.writeFileSync('stage22-real-stack-evidence.json',JSON.stringify(evidence,null,2));
167 await browser.close();await new Promise(ok=>server.close(ok));
168 }