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

1 param([Parameter(Mandatory=$true)][string]$SourceRoot)
2 $ErrorActionPreference='Stop'
3 $dir=Join-Path $env:RUNNER_TEMP 'treasuryflow-vm-evidence'
4 New-Item -ItemType Directory -Path $dir -Force|Out-Null
5 $report=[ordered]@{
6 sourceVersion=$env:LAB_VERSION; portableExeFound=$false; windowsProcessStarted=$false;
7 httpReady=$false; bankAdapterDisabled=$false; userInterfaceHtmlLoaded=$false;
8 outcome='NOT_RUN'
9 }
10 $p=$null
11 try{
12 $exe=@(Get-ChildItem (Join-Path $SourceRoot 'release') -Filter 'TreasuryFlow-*-Windows-x64.exe' -File |
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'
22 $p=Start-Process -FilePath $exe[0].FullName -PassThru
23 $report.windowsProcessStarted=$true
24 for($i=0;$i -lt 90;$i++){
25 Start-Sleep -Milliseconds 700
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
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 }
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')
53 if(!$report.userInterfaceHtmlLoaded){throw 'PACKAGED_UI_HTML_FAILED'}
54 $report.outcome='PACKAGED_PROCESS_AND_HTTP_PASS'
55 'Real packaged Windows process + local HTTP readiness + homepage: PASS.' >> $env:GITHUB_STEP_SUMMARY
56 }catch{
57 $report.outcome='FAIL'
58 $report.reason=$_.Exception.Message
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 }