Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
Fix V6 NSIS installer artifact detection using verified builder target and address GUI harness process binding
davoodmehraban89 committed
Oct 18, 2026 at 06:20 UTC
8aaa9ddd0b14d8a5f85be6b5509135662b239060
1 file changed
+120
-4
.github/workflows/windows-v6-rebuilt-installed-gui-lab-once.yml
+120
-4
@@ -100,12 +100,128 @@ jobs:
100
GENERIC_ERROR='Error:|⨯|error'
101
}
102
foreach($k in $classes.Keys){Write-Host ("BUILDER_LOG_HAS_"+$k+"="+[bool]($txt -match $classes[$k]))}
103
- $setupBefore=@(Get-ChildItem (Join-Path $env:TF_PRIVATE_STAGE 'release') -Recurse -File -Filter 'TreasuryFlow-Setup-*-Windows-x64.exe' -ErrorAction SilentlyContinue)
104
- Write-Host ("BUILDER_SETUP_FILE_COUNT="+$setupBefore.Count)
103
+ $outDir=Join-Path $env:TF_PRIVATE_STAGE 'release'
104
+ $topLevelExe=@(Get-ChildItem -LiteralPath $outDir -File -Filter '*.exe' -ErrorAction SilentlyContinue)
105
+ $nestedExe=@(Get-ChildItem -LiteralPath $outDir -Recurse -File -Filter '*.exe' -ErrorAction SilentlyContinue)
106
+ $targetConfirmed=[bool]($txt -match '(?i)target=nsis(\\s|$)')
107
+ Write-Host ("BUILDER_TOP_LEVEL_EXE_COUNT="+$topLevelExe.Count)
108
+ Write-Host ("BUILDER_NESTED_EXE_COUNT="+$nestedExe.Count)
109
+ Write-Host ("BUILDER_LOG_NSIS_TARGET_CONFIRMED="+$targetConfirmed)
110
Write-Host ("BUILDER_PROCESS_EXIT_NONZERO="+[bool]($builderExit -ne 0))
111
if($builderExit -ne 0){throw 'PRIVATE_V6_NSIS_BUILD_FAILED_SANITIZED_DIAGNOSTIC_ABOVE'}
107
- $setup=@(Get-ChildItem (Join-Path $env:TF_PRIVATE_STAGE 'release') -Recurse -File -Filter 'TreasuryFlow-Setup-*-Windows-x64.exe' -ErrorAction SilentlyContinue)
108
- if($setup.Count -ne 1 -or $setup[0].Length -lt 1000000){throw 'PRIVATE_SETUP_OUTPUT_NOT_UNIQUE'}
112
+ if(!$targetConfirmed){throw 'NSIS_TARGET_NOT_CONFIRMED_IN_BUILDER_LOG'}
113
+ $setup=@($topLevelExe | Where-Object { $_.Name -match '^TreasuryFlow[-_ ].*\\.exe
114
+ "TF_EPHEMERAL_NSIS_SETUP=$($setup[0].FullName)" >> $env:GITHUB_ENV
115
+ Write-Host 'GATE_PASS_PRIVATE_V6_NSIS_INSTALLER_BUILD'
116
+ Write-Host ('INSTALLER_SHA256='+((Get-FileHash $setup[0].FullName -Algorithm SHA256).Hash))
117
+ - name: Install actual private V6 NSIS Setup into isolated Windows VM
118
+ id: install
119
+ run: |
120
+ $ErrorActionPreference='Stop'
121
+ $dest=Join-Path $env:RUNNER_TEMP 'TreasuryFlow-V6-Isolated-Installed'
122
+ $process=Start-Process -FilePath $env:TF_EPHEMERAL_NSIS_SETUP -ArgumentList @('/S',('/D='+$dest)) -PassThru
123
+ if(!$process.WaitForExit(240000)){try{$process.Kill()}catch{};throw 'V6_NSIS_INSTALL_TIMEOUT'}
124
+ if($process.ExitCode -ne 0){throw 'V6_NSIS_NONZERO_EXIT'}
125
+ $installed=@(Get-ChildItem -LiteralPath $dest -Recurse -Filter 'TreasuryFlow.exe' -File -ErrorAction SilentlyContinue)
126
+ if($installed.Count -ne 1){throw 'INSTALLED_V6_EXE_NOT_UNIQUE'}
127
+ "TF_INSTALLED_V6_EXE=$($installed[0].FullName)" >> $env:GITHUB_ENV
128
+ "TF_V6_INSTALL_DIR=$dest" >> $env:GITHUB_ENV
129
+ Write-Host 'GATE_PASS_ACTUAL_V6_NSIS_INSTALL'
130
+ - name: Real Electron GUI and OS clipboard acceptance using synthetic SQL only
131
+ timeout-minutes: 18
132
+ run: |
133
+ $ErrorActionPreference='Continue'
134
+ $PSNativeCommandUseErrorActionPreference=$false
135
+ $probe=Join-Path $env:RUNNER_TEMP 'tf-native-gui-os-copy.mjs'
136
+ @'
137
+ import assert from 'node:assert/strict';
138
+ import {spawn,execFileSync} from 'node:child_process';
139
+ import {writeFileSync} from 'node:fs';
140
+ import {join} from 'node:path';
141
+ const exe=process.argv[2];const out=process.argv[3];
142
+ const report={integrations:false,writable:false,select:false,copyButton:false,osClipboard:false,bankDisabled:false,stage:'START',status:'NOT_RUN'};
143
+ const sleep=ms=>new Promise(ok=>setTimeout(ok,ms));
144
+ async function wait(fn,ms=75000){const end=Date.now()+ms;while(Date.now()<end){try{let v=await fn();if(v)return v}catch{}await sleep(600)}throw Error('TIMEOUT_'+report.stage)}
145
+ const port=9568,base='http://127.0.0.1:3210';
146
+ async function wsConnect(url){
147
+ const ws=new WebSocket(url);await new Promise((ok,no)=>{const t=setTimeout(()=>no(Error('WS_TIMEOUT')),10000);ws.addEventListener('open',()=>{clearTimeout(t);ok()},{once:true});ws.addEventListener('error',()=>{clearTimeout(t);no(Error('WS_ERROR'))},{once:true})});
148
+ let id=0;const pending=new Map();
149
+ ws.addEventListener('message',ev=>{let msg;try{msg=JSON.parse(ev.data)}catch{return}const p=pending.get(msg.id);if(!p)return;pending.delete(msg.id);clearTimeout(p.t);msg.error?p.no(Error('CDP_ERROR')):p.ok(msg.result)});
150
+ const call=(method,params={})=>new Promise((ok,no)=>{const i=++id,t=setTimeout(()=>{pending.delete(i);no(Error('CDP_TIMEOUT'))},16000);pending.set(i,{ok,no,t});ws.send(JSON.stringify({id:i,method,params}))});
151
+ const evalJs=async code=>{const r=await call('Runtime.evaluate',{expression:code,returnByValue:true,awaitPromise:true});if(r.exceptionDetails)throw Error('GUI_EVALUATION_ERROR');return r.result?.value};
152
+ await call('Runtime.enable');await call('Page.enable');return {ws,call,evalJs};
153
+ }
154
+ let electronProcess,conn;
155
+ try{
156
+ report.stage='LAUNCH';
157
+ const prev=await fetch(base+'/api/ready',{signal:AbortSignal.timeout(1600)}).then(()=>true,()=>false);
158
+ assert(!prev,'STALE_SERVER');
159
+ electronProcess=spawn(exe,['--remote-debugging-port='+port,'--remote-allow-origins=*'],{stdio:'ignore',windowsHide:false,env:{...globalThis.process.env,BANK_ADAPTER_MODE:'disabled',TREASURYFLOW_DESKTOP_LOCAL:'1',TREASURYFLOW_ENABLE_MAYAN_EXTERNAL_READ:'0',TREASURYFLOW_ENABLE_SQL_LAB:'0',TREASURYFLOW_DATA_FILE:join(out,'isolated-synthetic.sqlite')}});
160
+ report.stage='BACKEND';
161
+ const ready=await wait(async()=>{const x=await fetch(base+'/api/ready',{signal:AbortSignal.timeout(1500)});return x.ok?x.json():null});
162
+ assert(ready.status==='ready'&&ready.bankAdapter==='disabled','READINESS_CONTRACT_INVALID');
163
+ report.bankDisabled=true;
164
+ report.stage='CDP';
165
+ const pages=async()=>{const r=await fetch('http://127.0.0.1:'+port+'/json/list',{signal:AbortSignal.timeout(1500)});return r.ok?r.json():[]};
166
+ const first=await wait(async()=>{const x=await pages();return x.find(y=>y.type==='page'&&y.url?.startsWith(base)&&y.webSocketDebuggerUrl)});
167
+ conn=await wsConnect(first.webSocketDebuggerUrl);
168
+ report.stage='SQL_PAGE';
169
+ await conn.call('Page.navigate',{url:base+'/integrations'}).catch(()=>null);
170
+ let last='';
171
+ await wait(async()=>{const x=await pages();const p=x.find(z=>z.type==='page'&&z.url?.startsWith(base+'/integrations')&&z.webSocketDebuggerUrl);if(!p)return false;if(p.webSocketDebuggerUrl!==last){try{conn.ws.close()}catch{}conn=await wsConnect(p.webSocketDebuggerUrl);last=p.webSocketDebuggerUrl}return conn.evalJs("location.pathname==='/integrations'&&!!document.querySelector('textarea')&&document.body?.innerText.includes('اتصال به دیتابیس')")});
172
+ report.integrations=true;
173
+ report.stage='EDITOR';
174
+ const state=await conn.evalJs("(()=>{const f=document.querySelector('textarea');f.focus();f.select();return {ro:f.readOnly,disabled:f.disabled,buttons:[...document.querySelectorAll('button')].map(b=>b.textContent?.trim())}})()");
175
+ assert(!state.ro&&!state.disabled,'SQL_EDITOR_NOT_EDITABLE');
176
+ assert(state.buttons.some(x=>x?.includes('انتخاب متن')),'SELECT_BUTTON_MISSING');
177
+ assert(state.buttons.some(x=>x?.includes('کپی کوئری')),'COPY_BUTTON_MISSING');
178
+ report.copyButton=true;
179
+ const sql='SELECT TOP (7) 7 AS ClipboardAcceptanceProbe';
180
+ await conn.call('Input.insertText',{text:sql});
181
+ await wait(()=>conn.evalJs('document.querySelector("textarea")?.value==='+JSON.stringify(sql)),10000);
182
+ report.writable=true;
183
+ report.stage='SELECTION';
184
+ await conn.evalJs("(()=>{[...document.querySelectorAll('button')].find(b=>b.textContent?.includes('انتخاب متن')).click();return true})()");
185
+ assert(await conn.evalJs("(()=>{const f=document.querySelector('textarea');return f.selectionStart===0&&f.selectionEnd===f.value.length})()"),'REAL_SELECT_TEXT_ACTION_FAILED');
186
+ report.select=true;
187
+ report.stage='WINDOWS_OS_CLIPBOARD';
188
+ await conn.evalJs("(()=>{[...document.querySelectorAll('button')].find(b=>b.textContent?.includes('کپی کوئری')).click();return true})()");
189
+ await wait(()=>execFileSync('powershell.exe',['-NoProfile','-NonInteractive','-Command','Get-Clipboard -Raw'],{encoding:'utf8',timeout:4500}).trim()===sql,15000);
190
+ report.osClipboard=true;
191
+ report.status='PASS';
192
+ console.log('GATE_PASS_REAL_WINDOWS_INSTALLED_ELECTRON_SQL_COPY_AND_SELECT');
193
+ }catch(e){report.status='FAIL';report.failure=String(e.message||e).slice(0,90).replace(/[^A-Za-z0-9_ ]/g,'_');console.error('GUI_GATE_FAIL_'+report.failure);globalThis.process.exitCode=1}
194
+ finally{try{conn?.ws.close()}catch{}if(electronProcess?.pid){try{execFileSync('taskkill.exe',['/PID',String(electronProcess.pid),'/T','/F'],{stdio:'ignore',timeout:10000})}catch{}}writeFileSync(join(out,'private-gui-report.json'),JSON.stringify(report))}
195
+ '@ | Set-Content -LiteralPath $probe -Encoding utf8
196
+ $reportDir=Join-Path $env:RUNNER_TEMP 'private-tf-gui'
197
+ New-Item -ItemType Directory -Force -Path $reportDir | Out-Null
198
+ node $probe $env:TF_INSTALLED_V6_EXE $reportDir *> (Join-Path $env:RUNNER_TEMP 'private-gui-output.log')
199
+ $result=Get-Content (Join-Path $reportDir 'private-gui-report.json') -Raw | ConvertFrom-Json
200
+ foreach($key in @('integrations','writable','select','copyButton','osClipboard','bankDisabled')){
201
+ Write-Host ("GUI_"+$key+"="+[bool]$result.$key)
202
+ }
203
+ if($LASTEXITCODE -ne 0 -or $result.status -ne 'PASS'){throw ('INSTALLED_GUI_'+[string]$result.stage+'_FAILED')}
204
+ Write-Host 'GATE_PASS_ACTUAL_WINDOWS_OS_CLIPBOARD'
205
+ - name: Silent uninstall of actual private V6 Setup
206
+ if: ${{ always() && steps.install.outcome == 'success' }}
207
+ run: |
208
+ $ErrorActionPreference='Stop'
209
+ $uninstaller=@(Get-ChildItem $env:TF_V6_INSTALL_DIR -Recurse -File -ErrorAction SilentlyContinue | Where-Object {$_.Name -match '^uninstall.*\.exe$'})
210
+ if($uninstaller.Count -ne 1){throw 'V6_NSIS_UNINSTALLER_NOT_FOUND'}
211
+ $proc=Start-Process -FilePath $uninstaller[0].FullName -ArgumentList '/S' -PassThru
212
+ if(!$proc.WaitForExit(90000)){try{$proc.Kill()}catch{};throw 'V6_UNINSTALL_TIMEOUT'}
213
+ if($proc.ExitCode -ne 0){throw 'V6_UNINSTALL_NONZERO'}
214
+ $remaining=@(Get-ChildItem $env:TF_V6_INSTALL_DIR -Recurse -File -Filter 'TreasuryFlow.exe' -ErrorAction SilentlyContinue)
215
+ if($remaining.Count -ne 0){throw 'V6_UNINSTALL_LEFT_EXECUTABLE'}
216
+ Write-Host 'GATE_PASS_REAL_V6_NSIS_UNINSTALL'
217
+ - name: Strictly bound scope of this validation
218
+ if: always()
219
+ run: |
220
+ Write-Host 'PRIVATE_SOURCE_BINARY_AND_RAW_TEST_LOGS=NOT_UPLOADED'
221
+ Write-Host 'PRODUCTION_BANK_DISABLED=true; MAYAN_EXTERNAL_READ_DISABLED=true'
222
+ Write-Host 'V7_FINAL_ACCEPTANCE=NOT_TESTED; SQL_SERVER_APP_ADAPTER=NOT_TESTED; UPGRADE_ROLLBACK=NOT_TESTED'
223
+ -and $_.Length -gt 1000000 })
224
+ if($setup.Count -ne 1){throw 'PRIVATE_NSIS_TOP_LEVEL_INSTALLER_NOT_UNIQUE'}
225
"TF_EPHEMERAL_NSIS_SETUP=$($setup[0].FullName)" >> $env:GITHUB_ENV
226
Write-Host 'GATE_PASS_PRIVATE_V6_NSIS_INSTALLER_BUILD'
227
Write-Host ('INSTALLER_SHA256='+((Get-FileHash $setup[0].FullName -Algorithm SHA256).Hash))