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

fix(windows): track actual portable child process instead of NSIS launcher lifetime

davoodmehraban89 committed Oct 16, 2026 at 23:24 UTC 81c2037abc6b035a99d783c11d68422b76dece88
1 file changed +21 -3
scripts/windows-vm-treasury-smoke.ps1
+21 -3
@@ -13,6 +13,9 @@ try{
13 Where-Object {$_.Name -notlike '*Setup*'} | Sort-Object LastWriteTime -Descending)
14 if($exe.Count -lt 1){throw 'PORTABLE_EXE_NOT_FOUND'}
15 $report.portableExeFound=$true
16 + $report.launcherExited=$false
17 + $report.launcherExitCode=$null
18 + $report.actualDesktopProcessObserved=$false
19 $report.exeSha256=(Get-FileHash $exe[0].FullName -Algorithm SHA256).Hash
20 $env:BANK_ADAPTER_MODE='disabled'
21 $env:TREASURYFLOW_DATA_FILE=Join-Path $dir 'vm-test-only.sqlite'
@@ -20,17 +23,30 @@ try{
23 $report.windowsProcessStarted=$true
24 for($i=0;$i -lt 90;$i++){
25 Start-Sleep -Milliseconds 700
23 - if($p.HasExited){throw 'WINDOWS_DESKTOP_PROCESS_EXITED_EARLY'}
26 + # electron-builder portable is an NSIS bootstrapper. Its launcher can exit
27 + # after starting TreasuryFlow.exe, so launcher exit alone is not a failure.
28 + $p.Refresh()
29 + if($p.HasExited){
30 + $report.launcherExited=$true
31 + $report.launcherExitCode=$p.ExitCode
32 + }
33 + $desktopProcesses=@(Get-Process -Name 'TreasuryFlow' -ErrorAction SilentlyContinue)
34 + if($desktopProcesses.Count -gt 0){$report.actualDesktopProcessObserved=$true}
35 try{
36 $ready=Invoke-RestMethod 'http://127.0.0.1:3210/api/ready' -TimeoutSec 2
26 - if($ready.status -eq 'ready'){
37 + if($ready.status -eq 'ready' -and $desktopProcesses.Count -gt 0){
38 $report.httpReady=$true
39 $report.bankAdapterDisabled=($ready.bankAdapter -eq 'disabled')
40 break
41 }
42 }catch{}
43 }
33 - if(!$report.httpReady){throw 'PACKAGED_HTTP_READY_TIMEOUT'}
44 + if(!$report.httpReady){
45 + if($report.launcherExited -and !$report.actualDesktopProcessObserved){
46 + throw ('PORTABLE_BOOTSTRAPPER_EXITED_WITHOUT_DESKTOP_PROCESS_'+$report.launcherExitCode)
47 + }
48 + throw 'PACKAGED_HTTP_READY_TIMEOUT'
49 + }
50 if(!$report.bankAdapterDisabled){throw 'BANK_NOT_DISABLED'}
51 $html=Invoke-WebRequest 'http://127.0.0.1:3210' -TimeoutSec 15
52 $report.userInterfaceHtmlLoaded=($html.StatusCode -eq 200 -and $html.Content -match 'TreasuryFlow')
@@ -43,5 +59,7 @@ try{
59 throw
60 }finally{
61 if($p -and !$p.HasExited){try{& taskkill.exe /T /F /PID $p.Id | Out-Null}catch{}}
62 + # Isolated disposable runner: remove any real app process spawned by the portable bootstrapper.
63 + @(Get-Process -Name 'TreasuryFlow' -ErrorAction SilentlyContinue) | ForEach-Object {try{Stop-Process -Id $_.Id -Force -ErrorAction Stop}catch{}}
64 $report|ConvertTo-Json -Depth 3|Set-Content (Join-Path $dir 'runtime.json') -Encoding UTF8
65 }