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

1 name: V7 branch nonfinal NSIS Windows 2022 real installed smoke
2 on:
3 push:
4 paths:
5 - .github/workflows/v7-nonfinal-windows-nsis-acceptance-once.yml
6 workflow_dispatch:
7 permissions:
8 contents: read
9 jobs:
10 installed-v7-prototype:
11 runs-on: windows-2022
12 timeout-minutes: 70
13 env:
14 BANK_ADAPTER_MODE: disabled
15 TREASURYFLOW_ENABLE_MAYAN_EXTERNAL_READ: '0'
16 TREASURYFLOW_MAYAN_ENABLE_EXTERNAL_READ: '0'
17 TREASURYFLOW_ENABLE_SQL_LAB: '0'
18 NEXT_TELEMETRY_DISABLED: '1'
19 ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES: 'false'
20 steps:
21 - uses: actions/checkout@v4
22 with:
23 persist-credentials: false
24 - uses: actions/setup-node@v4
25 with:
26 node-version: '22'
27 - name: Install and quality gates
28 shell: pwsh
29 run: |
30 $ErrorActionPreference='Stop'
31 npm ci --ignore-scripts
32 if($LASTEXITCODE -ne 0){throw 'CI_DEPENDENCY_INSTALL_FAILED'}
33 npm test -- --reporter=dot
34 if($LASTEXITCODE -ne 0){throw 'CI_FINANCIAL_UNIT_FAILED'}
35 npm run typecheck
36 if($LASTEXITCODE -ne 0){throw 'CI_TYPESCRIPT_FAILED'}
37 npm run lint
38 if($LASTEXITCODE -ne 0){throw 'CI_LINT_FAILED'}
39 $secureMsal=Get-Content package.json -Raw | ConvertFrom-Json
40 if($secureMsal.overrides.'@azure/msal-node' -ne '7.1.1'){throw 'MSAL_SECURITY_OVERRIDE_NOT_PINNED'}
41 Write-Host 'GATE_PASS_PINNED_CVE_2026_109461_MSAL_REMEDIATION'
42 npm audit --omit=dev --audit-level=low
43 if($LASTEXITCODE -ne 0){throw 'CI_PRODUCTION_NPM_ADVISORY'}
44 Write-Host 'GATE_PASS_V7_BRANCH_WINDOWS_TEST_TYPECHECK_LINT_ZERO_PRODUCTION_AUDIT'
45 - name: Build and package nonfinal NSIS installer
46 shell: pwsh
47 run: |
48 $ErrorActionPreference='Stop'
49 npm run build
50 if($LASTEXITCODE -ne 0){throw 'CI_NEXT_BUILD_FAILED'}
51 $sourceRuntime=Join-Path $pwd '.next/standalone/node_modules/next/package.json'
52 if(!(Test-Path -LiteralPath $sourceRuntime)){throw 'NEXT_STANDALONE_TRACE_RUNTIME_MISSING_BEFORE_PACKAGING'}
53 Write-Host 'GATE_PASS_NEXT_STANDALONE_SOURCE_RUNTIME_PRESENT'
54 node scripts/prepare-standalone.mjs
55 if($LASTEXITCODE -ne 0){throw 'CI_STANDALONE_FAILED'}
56 $env:CSC_IDENTITY_AUTO_DISCOVERY='false'
57 & npx.cmd --no-install electron-builder --win nsis --x64 --publish never
58 if($LASTEXITCODE -ne 0){throw 'CI_NONFINAL_NSIS_PACKAGING_FAILED'}
59 $exe=@(Get-ChildItem -LiteralPath (Join-Path $pwd 'release') -File -Filter '*.exe')
60 if($exe.Count -ne 1 -or $exe[0].Length -lt 1000000){throw 'CI_NONFINAL_NSIS_SINGLE_EXE_NOT_FOUND'}
61 $unpackedRuntime=Join-Path $pwd 'release/win-unpacked/resources/standalone/node_modules/next/package.json'
62 if(!(Test-Path -LiteralPath $unpackedRuntime)){throw 'NEXT_STANDALONE_NODE_MODULES_OMITTED_BY_ELECTRON_BUILDER'}
63 Write-Host 'GATE_PASS_NEXT_RUNTIME_EXPLICITLY_PRESENT_IN_NSIS_UNPACKED_RESOURCES'
64 Write-Host 'GATE_PASS_NONFINAL_V7_BRANCH_NSIS_BUILT'
65 - name: Install exact NSIS setup and verify desktop on real Windows
66 shell: pwsh
67 run: |
68 $ErrorActionPreference='Stop'
69 $setup=@(Get-ChildItem -LiteralPath (Join-Path $pwd 'release') -File -Filter '*.exe')
70 if($setup.Count -ne 1){throw 'EXACT_NSIS_SETUP_MISSING'}
71 $install=Join-Path $env:RUNNER_TEMP 'v7-nonfinal-installed'
72 $sandbox=Join-Path $env:RUNNER_TEMP 'v7-nonfinal-data'
73 New-Item -ItemType Directory -Path $sandbox -Force | Out-Null
74 $p=Start-Process -FilePath $setup[0].FullName -ArgumentList @('/S',('/D='+$install)) -PassThru
75 if(!$p.WaitForExit(120000)){try{$p.Kill()}catch{};throw 'NSIS_INSTALL_TIMEOUT'}
76 if($p.ExitCode -ne 0){throw 'NSIS_INSTALL_NONZERO'}
77 $program=@(Get-ChildItem -LiteralPath $install -Recurse -File -Filter 'TreasuryFlow.exe' -ErrorAction SilentlyContinue)
78 if($program.Count -ne 1){throw 'INSTALLED_ELECTRON_PROGRAM_MISSING'}
79 Write-Host 'GATE_PASS_V7_BRANCH_NSIS_SILENT_INSTALL'
80 $env:LOCALAPPDATA=$sandbox
81 $env:TREASURYFLOW_DESKTOP_LOCAL='1'
82 $env:BANK_ADAPTER_MODE='disabled'
83 $desktop=$null
84 try{
85 $diagnosticError=Join-Path $env:RUNNER_TEMP 'nonfinal-electron-error.txt'
86 $diagnosticOut=Join-Path $env:RUNNER_TEMP 'nonfinal-electron-out.txt'
87 $serverMain=Join-Path $install 'resources/standalone/server.js'
88 $nextRuntime=Join-Path $install 'resources/standalone/node_modules/next/package.json'
89 Write-Host ('V7_PACKAGED_STANDALONE_SERVER_PRESENT='+[bool](Test-Path -LiteralPath $serverMain))
90 Write-Host ('V7_PACKAGED_NEXT_RUNTIME_PRESENT='+[bool](Test-Path -LiteralPath $nextRuntime))
91 # Probe the very same bundled Next server without Electron before
92 # asserting desktop bootstrap. Never expose process output or data.
93 $env:NODE_ENV='production'
94 $env:HOSTNAME='127.0.0.1'
95 $env:PORT='3210'
96 $standaloneNode=Start-Process -FilePath 'node.exe' -ArgumentList @($serverMain) -WorkingDirectory (Split-Path $serverMain) -PassThru -RedirectStandardError (Join-Path $env:RUNNER_TEMP 'nonfinal-direct-server-err.txt') -RedirectStandardOutput (Join-Path $env:RUNNER_TEMP 'nonfinal-direct-server-out.txt')
97 try {
98 $nodeReady=$false
99 for($probe=0;$probe -lt 55;$probe++){
100 try {
101 $nodeResult=Invoke-RestMethod -Uri 'http://127.0.0.1:3210/api/ready' -TimeoutSec 2
102 if($nodeResult.status -eq 'ready' -and $nodeResult.bankAdapter -eq 'disabled'){
103 $nodeReady=$true
104 break
105 }
106 }catch{}
107 if($standaloneNode.HasExited){break}
108 Start-Sleep -Milliseconds 400
109 }
110 Write-Host ('V7_PACKAGED_DIRECT_NODE_READY='+[bool]$nodeReady)
111 Write-Host ('V7_PACKAGED_DIRECT_NODE_EXITED='+[bool]$standaloneNode.HasExited)
112 if(!$nodeReady){throw 'BUNDLED_STANDALONE_SERVER_DIRECT_NODE_NOT_READY'}
113 }finally{
114 if(!$standaloneNode.HasExited){& taskkill.exe /PID $standaloneNode.Id /T /F *> $null}
115 for($probe=0;$probe -lt 20;$probe++){
116 $portOpen=@(Get-NetTCPConnection -LocalPort 3210 -State Listen -ErrorAction SilentlyContinue)
117 if($portOpen.Count -eq 0){break}
118 Start-Sleep -Milliseconds 250
119 }
120 }
121 Write-Host 'GATE_PASS_BUNDLED_STANDALONE_DIRECT_NODE_READY'
122 $desktop=Start-Process -FilePath $program[0].FullName -PassThru -RedirectStandardError $diagnosticError -RedirectStandardOutput $diagnosticOut
123 $ready=$null
124 for($i=0;$i -lt 40;$i++){
125 try{
126 $ready=Invoke-RestMethod -Uri 'http://127.0.0.1:3210/api/ready' -TimeoutSec 2
127 if($ready.status -eq 'ready' -and $ready.bankAdapter -eq 'disabled'){break}
128 }catch{}
129 Start-Sleep -Milliseconds 600
130 }
131 if($null -eq $ready -or $ready.status -ne 'ready' -or $ready.bankAdapter -ne 'disabled'){
132 Write-Host ('V7_ELECTRON_PROCESS_EXITED='+[bool]$desktop.HasExited)
133 $listening=@(Get-NetTCPConnection -LocalPort 3210 -State Listen -ErrorAction SilentlyContinue)
134 Write-Host ('V7_LOCAL_3210_LISTENING='+[bool]($listening.Count -gt 0))
135 $stdErrText=if(Test-Path -LiteralPath $diagnosticError){Get-Content -LiteralPath $diagnosticError -Raw -ErrorAction SilentlyContinue}else{''}
136 foreach($pattern in @('Server exited','MODULE_NOT_FOUND','Cannot find module','ERR_REQUIRE_ESM',
137 'EADDRINUSE','node:sqlite','ERR_UNKNOWN_BUILTIN_MODULE','Cannot read properties')){
138 Write-Host ('V7_SAFE_ERROR_CLASS_'+($pattern -replace '[^A-Za-z]','_').ToUpperInvariant()+'='+[bool]($stdErrText.Contains($pattern)))
139 }
140 throw 'V7_INSTALLED_LOCAL_READINESS_FAILED'
141 }
142 foreach($route in @('/login','/dashboard','/accounts','/payments','/queue','/audit')){
143 $response=Invoke-WebRequest -Uri ('http://127.0.0.1:3210'+$route) -UseBasicParsing -TimeoutSec 12
144 if($response.StatusCode -ne 200){throw 'V7_INSTALLED_NATIVE_ROUTE_HTTP_FAILED'}
145 }
146 Write-Host 'GATE_PASS_V7_BRANCH_REAL_INSTALLED_ELECTRON_READY_SIX_ROUTES_BANK_DISABLED'
147 }finally{
148 if($desktop -and !$desktop.HasExited){& taskkill.exe /PID $desktop.Id /T /F *> $null}
149 }
150 # Replay renderer/CDP under independent Windows Roaming APPDATA and LOCALAPPDATA; never inherit previous Electron Chromium lock.
151 # Independently test the real installed Electron renderer and CDP
152 # with isolated synthetic local database and no external bank access.
153 for($probe=0;$probe -lt 40;$probe++){
154 $stillListening=@(Get-NetTCPConnection -LocalPort 3210 -State Listen -ErrorAction SilentlyContinue)
155 if($stillListening.Count -eq 0){break}
156 Start-Sleep -Milliseconds 250
157 }
158 if($stillListening.Count -gt 0){throw 'PREVIOUS_SYNTHETIC_DESKTOP_PROCESS_PORT_NOT_CLEARED'}
159 $nativeTest=Join-Path $pwd 'qa/windows/v7-installed-native-cdp-smoke.mjs'
160 & node --check $nativeTest
161 if($LASTEXITCODE -ne 0){throw 'NATIVE_ELECTRON_CDP_TEST_SCRIPT_SYNTAX_FAILED'}
162 $nativeData=Join-Path $env:RUNNER_TEMP 'v7-native-cdp-synthetic'
163 New-Item -ItemType Directory -Path $nativeData -Force | Out-Null
164 & node $nativeTest $program[0].FullName $nativeData
165 if($LASTEXITCODE -ne 0){
166 $reportFile=Join-Path $nativeData 'v7-native-cdp-qa.json'
167 if(Test-Path -LiteralPath $reportFile){
168 $failedNative=Get-Content -LiteralPath $reportFile -Raw | ConvertFrom-Json
169 Write-Host ('V7_CDP_SAFE_FAILED_STAGE='+([string]$failedNative.stage -replace '[^A-Za-z0-9_]',''))
170 Write-Host ('V7_CDP_LAUNCHER_EARLY_EXIT='+[bool]$failedNative.launcherExited)
171 Write-Host ('V7_CDP_PAGES_VERIFIED='+[int]@($failedNative.pages).Count)
172 }
173 throw 'REAL_INSTALLED_ELECTRON_CDP_UI_ACCEPTANCE_FAILED'
174 }
175 $nativeResult=Get-Content -LiteralPath (Join-Path $nativeData 'v7-native-cdp-qa.json') -Raw | ConvertFrom-Json
176 if($nativeResult.status -ne 'PASS' -or $nativeResult.pages.Count -ne 5 -or
177 !$nativeResult.actualLocalClick -or !$nativeResult.bankDisabled -or !$nativeResult.screenshot){
178 throw 'REAL_INSTALLED_ELECTRON_CDP_ASSERTIONS_NOT_ALL_VERIFIED'
179 }
180 Write-Host 'GATE_PASS_SAME_INSTALLED_V7_NONFINAL_NATIVE_ELECTRON_CDP_LOGIN_FIVE_ROUTES_SCREENSHOT'
181 $un=@(Get-ChildItem -LiteralPath $install -Recurse -File -Filter 'Uninstall*.exe' -ErrorAction SilentlyContinue)
182 if($un.Count -ne 1){throw 'NSIS_UNINSTALLER_NOT_FOUND'}
183 $p=Start-Process -FilePath $un[0].FullName -ArgumentList '/S' -PassThru
184 if(!$p.WaitForExit(120000)){try{$p.Kill()}catch{};throw 'NSIS_UNINSTALL_TIMEOUT'}
185 if($p.ExitCode -ne 0){throw 'NSIS_UNINSTALL_NONZERO'}
186 for($i=0;$i -lt 60;$i++){
187 $left=@(Get-ChildItem -LiteralPath $install -Recurse -File -Filter 'TreasuryFlow.exe' -ErrorAction SilentlyContinue)
188 if($left.Count -eq 0){break}
189 Start-Sleep -Milliseconds 700
190 }
191 if($left.Count -ne 0){throw 'NSIS_UNINSTALL_LEFT_EXECUTABLE'}
192 Write-Host 'GATE_PASS_V7_BRANCH_SAME_ARTIFACT_NSIS_UNINSTALL'
193 - name: No releases, artifacts or deployment
194 if: always()
195 run: echo NONFINAL_V7_BRANCH_NO_PRIVATE_SOURCE_NO_CUSTOMER_DATA_NO_PUBLIC_RELEASE_NO_BANK