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

test(windows): diagnose direct unpacked Electron process and local HTTP without bootstrapper

davoodmehraban89 committed Oct 16, 2026 at 23:37 UTC 2bde259f8c05c4749bd477b1e221f9c596af7e0c
1 file changed +71
scripts/windows-vm-unpacked-smoke.ps1 new
+71
@@ -0,0 +1,71 @@
1 +param([Parameter(Mandatory=$true)][string]$SourceRoot)
2 +$ErrorActionPreference='Stop'
3 +$evidenceDir=Join-Path $env:RUNNER_TEMP 'treasuryflow-vm-evidence'
4 +New-Item -ItemType Directory -Path $evidenceDir -Force | Out-Null
5 +$exe=Join-Path $SourceRoot 'release/win-unpacked/TreasuryFlow.exe'
6 +$stdout=Join-Path $env:RUNNER_TEMP 'treasuryflow-unpacked-stdout.txt'
7 +$stderr=Join-Path $env:RUNNER_TEMP 'treasuryflow-unpacked-stderr.txt'
8 +$report=[ordered]@{
9 + mode='DIRECT_UNPACKED_ELECTRON_EXE'
10 + executablePresent=$false
11 + launched=$false
12 + exited=$false
13 + exitCode=$null
14 + httpReady=$false
15 + bankAdapterDisabled=$false
16 + loginHtmlLoaded=$false
17 + stdoutBytes=0
18 + stderrBytes=0
19 + stderrMarkers=@()
20 + outcome='NOT_RUN'
21 +}
22 +$p=$null
23 +try {
24 + if(!(Test-Path $exe)){throw 'UNPACKED_ELECTRON_EXE_MISSING'}
25 + $report.executablePresent=$true
26 + $env:BANK_ADAPTER_MODE='disabled'
27 + $env:TREASURYFLOW_DESKTOP_LOCAL='1'
28 + $env:TREASURYFLOW_DATA_FILE=Join-Path $evidenceDir 'unpacked-synthetic.sqlite'
29 + $p=Start-Process -FilePath $exe -WorkingDirectory (Split-Path $exe) -PassThru -RedirectStandardOutput $stdout -RedirectStandardError $stderr
30 + $report.launched=$true
31 + $stopAt=[DateTime]::UtcNow.AddSeconds(90)
32 + while([DateTime]::UtcNow -lt $stopAt){
33 + Start-Sleep -Milliseconds 700
34 + $p.Refresh()
35 + if($p.HasExited){
36 + $report.exited=$true
37 + $report.exitCode=$p.ExitCode
38 + throw ('UNPACKED_ELECTRON_PROCESS_EXITED_'+$p.ExitCode)
39 + }
40 + try {
41 + $ready=Invoke-RestMethod 'http://127.0.0.1:3210/api/ready' -TimeoutSec 2
42 + if($ready.status -eq 'ready' -and $ready.bankAdapter -eq 'disabled'){
43 + $report.httpReady=$true
44 + $report.bankAdapterDisabled=$true
45 + break
46 + }
47 + }catch{}
48 + }
49 + if(!$report.httpReady){throw 'UNPACKED_ELECTRON_READINESS_TIMEOUT'}
50 + $login=Invoke-WebRequest 'http://127.0.0.1:3210/login' -TimeoutSec 10
51 + $report.loginHtmlLoaded=($login.StatusCode -eq 200 -and $login.Content -match 'TreasuryFlow')
52 + if(!$report.loginHtmlLoaded){throw 'UNPACKED_ELECTRON_LOCAL_LOGIN_FAILED'}
53 + $report.outcome='UNPACKED_ELECTRON_HTTP_AND_PROCESS_PASS'
54 + 'Direct win-unpacked TreasuryFlow.exe launched and passed local-bank-disabled HTTP checks.' >> $env:GITHUB_STEP_SUMMARY
55 +}catch{
56 + $report.outcome='FAILED'
57 + $report.failureCode=$_.Exception.Message
58 + throw
59 +}finally{
60 + if($p -and !$p.HasExited){try{& taskkill.exe /T /F /PID $p.Id | Out-Null}catch{}}
61 + foreach($item in @(@{file=$stdout;key='stdoutBytes'},@{file=$stderr;key='stderrBytes'})){
62 + if(Test-Path $item.file){$report[$item.key]=(Get-Item $item.file).Length}
63 + }
64 + if(Test-Path $stderr){
65 + $raw=Get-Content $stderr -Raw -ErrorAction SilentlyContinue
66 + $report.stderrMarkers=@('MODULE_NOT_FOUND','ERR_MODULE_NOT_FOUND','ENOENT',
67 + 'EACCES','EPERM','EADDRINUSE','UNHANDLED_REJECTION','Failed to launch',
68 + 'server did not start') | Where-Object {$raw -match [regex]::Escape($_)}
69 + }
70 + $report | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $evidenceDir 'unpacked-runtime.json') -Encoding UTF8
71 +}