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

test(windows): installed Electron navigation synthetic finance drafts and restart durability

davoodmehraban89 committed Oct 17, 2026 at 00:19 UTC 25ab38270e676622b062508b2544ec203a7a1559
1 file changed +70 -2
qa/windows/electron-native-gui-smoke.mjs
+70 -2
@@ -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,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,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){
@@ -31,12 +31,42 @@ async function connect(url){
31 }
32 let proc,conn;
33 try{
34 - const env={...process.env,BANK_ADAPTER_MODE:'disabled',TREASURYFLOW_DESKTOP_LOCAL:'1'};
34 + const env={...process.env,BANK_ADAPTER_MODE:'disabled',TREASURYFLOW_DESKTOP_LOCAL:'1',TREASURYFLOW_DATA_FILE:join(reportDir,'vm-only-treasuryflow.sqlite')};
35 proc=spawn(exe,['--remote-debugging-port='+port,'--remote-allow-origins=*'],{env,stdio:'ignore',windowsHide:false});
36 const target=await wait(async()=>{const r=await fetch('http://127.0.0.1:'+port+'/json/list',{signal:AbortSignal.timeout(1500)});
37 if(!r.ok)return null;const pages=await r.json();
38 return pages.find(p=>p.type==='page'&&p.url?.startsWith('http://127.0.0.1:3210')&&p.webSocketDebuggerUrl)?.webSocketDebuggerUrl;});
39 conn=await connect(target);report.cdp=true;
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});
44 + 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;
47 + },30000);
48 + };
49 + const iban=(digit)=>{
50 + const number='0'.repeat(23)+String(digit);
51 + let mod=0;for(const d of number+'182700')mod=(mod*10+Number(d))%97;
52 + return 'IR'+String(98-mod).padStart(2,'0')+number;
53 + };
54 + const submit=async (page,marker,fields)=>{
55 + await go(page,marker);
56 + await conn.evaluate('window.__vmSynthetic='+JSON.stringify(fields));
57 + return conn.evaluate("(()=>{const form=document.querySelector('main form');if(!form)return 'NO_FORM';for(const [k,v] of Object.entries(window.__vmSynthetic)){const el=form.elements.namedItem(k);if(!el)return 'MISSING_'+k;if(el.type==='checkbox'){el.checked=Boolean(v);}else if(el.tagName==='SELECT'){el.value=v==='@FIRST'?[...el.options].find(o=>o.value)?.value||'':String(v);}else{Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').set.call(el,String(v));}el.dispatchEvent(new Event('input',{bubbles:true}));el.dispatchEvent(new Event('change',{bubbles:true}));}if(!form.reportValidity())return 'INVALID_FORM';form.requestSubmit();return 'SUBMITTED';})()");
58 + };
59 + await go('/login','ورود به محیط محلی امن');
60 + assert(await conn.evaluate("(()=>{const a=document.querySelector('a[href=\"/dashboard\"]');if(!a)return false;a.click();return true;})()"),'NATIVE_LOCAL_ENTRY_MISSING');
61 + await wait(()=>conn.evaluate("location.pathname==='/dashboard'&&document.body?.innerText.includes('داشبورد خزانه‌داری')"));
62 + report.localEntry=true; // local entry link, NOT credential authentication
63 + for(const [route,heading] of [
64 + ['/dashboard','داشبورد خزانه‌داری'],['/payments','حواله‌ها'],
65 + ['/payments/new','ثبت حواله جدید'],['/accounts','حساب‌های بانکی'],
66 + ['/beneficiaries','طرف‌حساب‌ها'],['/queue','صف ارسال'],
67 + ['/reconciliation','مغایرت‌گیری'],['/integrations','اتصال به دیتابیس'],
68 + ['/reports','گزارش‌های خزانه‌داری'],['/audit','رویدادهای حسابرسی']
69 + ]){await go(route,heading);report.visitedRoutes.push({route,status:'PASS'});}
70 const home=await wait(()=>conn.evaluate('({href:location.href,title:document.title})'));
71 report.localOrigin=new URL(home.href).origin==='http://127.0.0.1:3210';
72 assert(report.localOrigin,'NATIVE_APP_ORIGIN_NOT_LOCAL');
@@ -74,6 +104,44 @@ try{
104 const png=await conn.command('Page.captureScreenshot',{format:'png',captureBeyondViewport:false});
105 assert(png.data,'NATIVE_SCREENSHOT_MISSING');
106 writeFileSync(join(reportDir,'treasuryflow-installed-ui.png'),Buffer.from(png.data,'base64'));report.screenshot=true;
107 +
108 + // Synthetic local actions through the actual installed Electron UI.
109 + assert.equal(await submit('/accounts','افزودن حساب بانکی',{
110 + name:'VM-SYNTHETIC-SOURCE',bankName:'VM-ONLY-BANK',iban:iban(1)}),'SUBMITTED');
111 + await wait(()=>conn.evaluate("location.pathname==='/accounts'&&document.body?.innerText.includes('حساب ثبت شد')&&document.body.innerText.includes('VM-SYNTHETIC-SOURCE')"));
112 + report.syntheticAccount=true;
113 + assert.equal(await submit('/beneficiaries','افزودن طرف‌حساب',{
114 + name:'VM-SYNTHETIC-BENEFICIARY',iban:iban(2),whitelisted:true}),'SUBMITTED');
115 + await wait(()=>conn.evaluate("location.pathname==='/beneficiaries'&&document.body?.innerText.includes('طرف‌حساب ثبت شد')&&document.body.innerText.includes('VM-SYNTHETIC-BENEFICIARY')"));
116 + report.syntheticBeneficiary=true;
117 + assert.equal(await submit('/payments/new','ثبت پیش‌نویس حواله',{
118 + sourceAccountId:'@FIRST',beneficiaryId:'@FIRST',amountIrr:'1234567',
119 + paymentDate:'2026-10-16',clientReference:'VM-DRAFT-'+(process.env.GITHUB_RUN_ID||'LOCAL'),
120 + description:'VM synthetic draft only'}),'SUBMITTED');
121 + await wait(()=>conn.evaluate("/^\\/payments\\/[^/]+$/.test(location.pathname)&&document.body?.innerText.includes('VM-DRAFT-')"));
122 + report.syntheticDraft=true;
123 + conn.ws.close();
124 + execFileSync('taskkill.exe',['/T','/F','/PID',String(proc.pid)],{stdio:'ignore',timeout:10000});
125 + await wait(async()=>{try{await fetch(origin+'/api/ready',{signal:AbortSignal.timeout(1000)});return false;}catch{return true;}},15000);
126 + proc=spawn(exe,['--remote-debugging-port='+port,'--remote-allow-origins=*'],{env,stdio:'ignore',windowsHide:false});
127 + const second=await wait(async()=>{
128 + const r=await fetch(origin+'/api/ready',{signal:AbortSignal.timeout(1500)});
129 + if(!r.ok)return null;const ready=await r.json();
130 + if(ready.status!=='ready'||ready.bankAdapter!=='disabled')return null;
131 + const targets=await (await fetch('http://127.0.0.1:'+port+'/json/list',{signal:AbortSignal.timeout(1500)})).json();
132 + return targets.find(p=>p.type==='page'&&p.url?.startsWith(origin)&&p.webSocketDebuggerUrl)?.webSocketDebuggerUrl;
133 + },75000);
134 + conn=await connect(second);report.appReopened=true;
135 + await go('/accounts','حساب‌های بانکی');
136 + assert(await conn.evaluate("document.body.innerText.includes('VM-SYNTHETIC-SOURCE')"),'NATIVE_ACCOUNT_NOT_DURABLE');
137 + await go('/beneficiaries','طرف‌حساب‌ها');
138 + assert(await conn.evaluate("document.body.innerText.includes('VM-SYNTHETIC-BENEFICIARY')"),'NATIVE_BENEFICIARY_NOT_DURABLE');
139 + await go('/payments','حواله‌ها');
140 + assert(await conn.evaluate("document.body.innerText.includes('VM-DRAFT-')"),'NATIVE_DRAFT_NOT_DURABLE');
141 + report.durableData=true;
142 + await go('/audit','رویدادهای حسابرسی');
143 + report.auditPersisted=await conn.evaluate("document.body.innerText.includes('ACCOUNT_CREATED')&&document.body.innerText.includes('PAYMENT_CREATED')");
144 + assert(report.auditPersisted,'NATIVE_AUDIT_NOT_DURABLE');
145 report.outcome='REAL_INSTALLED_ELECTRON_GUI_PASS';
146 }catch(e){report.outcome='FAILED';report.errorCode=(e?.message||'UNKNOWN').slice(0,140);process.exitCode=1;}
147 finally{