Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

fix(windows): reattach Electron CDP after full Next.js page navigations

davoodmehraban89 committed Oct 17, 2026 at 00:44 UTC 71cd92a9afaf37ae55c0529152cb4282dc40db5b
1 file changed +19 -5
qa/windows/electron-native-gui-smoke.mjs
+19 -5
@@ -9,7 +9,7 @@ assert(exe&&existsSync(exe),'real installed TreasuryFlow.exe required');
9 assert(reportDir,'evidence output directory required');
10 mkdirSync(reportDir,{recursive:true});
11 const port=9345;
12 -const report={mode:'REAL_INSTALLED_ELECTRON_CDP',exe:basename(exe),cdp:false,localOrigin:false,integrations:false,queryEditor:false,copyQuery:false,copyExactlyEditedSql:false,clipboardMode:'INTERCEPTED_API_NOT_WINDOWS_CLIPBOARD',screenshot:false,localEntry:false,visitedRoutes:[],syntheticAccount:false,syntheticBeneficiary:false,syntheticDraft:false,appReopened:false,durableData:false,auditPersisted:false,upgrade:'NOT_RUN_NO_BASELINE',outcome:'NOT_RUN'};
12 +const report={mode:'REAL_INSTALLED_ELECTRON_CDP',exe:basename(exe),cdp:false,localOrigin:false,integrations:false,queryEditor:false,copyQuery:false,copyExactlyEditedSql:false,clipboardMode:'INTERCEPTED_API_NOT_WINDOWS_CLIPBOARD',screenshot:false,stage:'connect',cdpReconnections:0,localEntry:false,visitedRoutes:[],syntheticAccount:false,syntheticBeneficiary:false,syntheticDraft:false,appReopened:false,durableData:false,auditPersisted:false,upgrade:'NOT_RUN_NO_BASELINE',outcome:'NOT_RUN'};
13 const sleep=ms=>new Promise(r=>setTimeout(r,ms));
14 async function wait(fn,timeout=75000){let error;const until=Date.now()+timeout;while(Date.now()<until){try{const x=await fn();if(x)return x;}catch(e){error=e;}await sleep(400);}throw error||Error('CDP_WAIT_TIMEOUT');}
15 async function connect(url){
@@ -40,10 +40,24 @@ try{
40
41 const origin='http://127.0.0.1:3210';
42 const go=async(path,heading)=>{
43 - await conn.command('Page.navigate',{url:origin+path});
43 + // A full Next.js navigation may replace the renderer's CDP target and
44 + // invalidate pending Page.navigate replies. Reattach by URL after navigation.
45 + report.stage='native-route:'+path;
46 + const dest=origin+path;
47 + const pending=conn.command('Page.navigate',{url:dest}).catch(()=>null);
48 + await Promise.race([pending,sleep(850)]);
49 + const socket=await wait(async()=>{
50 + const response=await fetch('http://127.0.0.1:'+port+'/json/list',{signal:AbortSignal.timeout(1500)});
51 + if(!response.ok)return null;
52 + const pages=await response.json();
53 + return pages.find(p=>p.type==='page'&&p.url?.startsWith(dest)&&p.webSocketDebuggerUrl)?.webSocketDebuggerUrl;
54 + },35000);
55 + try{conn.ws.close()}catch{}
56 + conn=await connect(socket);
57 + report.cdpReconnections++;
58 return wait(async()=>{
45 - const x=await conn.evaluate("({path:location.pathname,text:document.body?.innerText||''})");
46 - return x?.path===path&&x.text.includes(heading)&&!x.text.includes('خطا در بارگذاری صفحه')?x:null;
59 + const x=await conn.evaluate("({path:location.pathname,text:document.body?.innerText||'',errorToast:!!document.querySelector('.toast-error')})");
60 + return x?.path===path&&x.text.includes(heading)&&!x.errorToast&&!x.text.includes('خطا در بارگذاری صفحه')?x:null;
61 },30000);
62 };
63 const iban=(digit)=>{
@@ -71,7 +85,7 @@ try{
85 report.localOrigin=new URL(home.href).origin==='http://127.0.0.1:3210';
86 assert(report.localOrigin,'NATIVE_APP_ORIGIN_NOT_LOCAL');
87 assert.match(home.title,/TreasuryFlow/i);
74 - await conn.command('Page.navigate',{url:'http://127.0.0.1:3210/integrations'});
88 + await go('/integrations','اتصال به دیتابیس');
89 const page=await wait(async()=>{const x=await conn.evaluate(
90 "({href:location.href,title:document.title,editor:!!document.querySelector('textarea'),copy:[...document.querySelectorAll('button')].some(b=>b.textContent.includes('کپی کوئری'))})");
91 return isIntegrationsEditorReady(x)?x:null;});