Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
ci/windows-dual-app-lab-20261016
ci/public-windows-bridge-probe-20261017
ci/windows-dispatch-bootstrap-20261016
ci/windows-dual-app-lab-20261016
dev/v7-production-failclosed-20261021
feature/reconciliation-guard-20261013
main
phase-1-foundation
phase-1-implementation
phase-2-treasury-core
phase-3-banking-reconciliation
phase-4-operations-enterprise-ux
phase-5-hardening-release
phase-6-production-platform
phase-7-production-infrastructure-bank-golive
phase-7-sql-readonly-ux-20261015
transfer-exe-to-drive-20261006
| 1 | import assert from 'node:assert/strict'; |
| 2 | import {spawn} from 'node:child_process'; |
| 3 | import {join} from 'node:path'; |
| 4 | import {mkdtempSync,rmSync} from 'node:fs'; |
| 5 | import {tmpdir} from 'node:os'; |
| 6 | |
| 7 | const nextBin=join(process.cwd(),'node_modules','next','dist','bin','next'); |
| 8 | const isolatedDir=mkdtempSync(join(tmpdir(),'treasuryflow-ci-smoke-')); |
| 9 | const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms)); |
| 10 | |
| 11 | async function withServer(port,env,check){ |
| 12 | const child=spawn(process.execPath,[nextBin,'start','-p',String(port),'-H','127.0.0.1'],{ |
| 13 | env,stdio:['ignore','pipe','pipe'],windowsHide:true |
| 14 | }); |
| 15 | let output='',exited=false,launchError=null; |
| 16 | const collect=chunk=>{output=(output+chunk.toString('utf8')).slice(-3000);}; |
| 17 | child.stdout.on('data',collect); |
| 18 | child.stderr.on('data',collect); |
| 19 | child.on('error',error=>{launchError=error;}); |
| 20 | child.on('exit',()=>{exited=true;}); |
| 21 | const origin='http://127.0.0.1:'+port; |
| 22 | let lastFailure='server did not respond'; |
| 23 | try{ |
| 24 | const expires=Date.now()+45000; |
| 25 | while(Date.now()<expires){ |
| 26 | if(launchError)throw launchError; |
| 27 | if(exited)throw new Error('Next.js process exited during smoke test'); |
| 28 | try{await check(origin);return;} |
| 29 | catch(error){lastFailure=error instanceof Error?error.message:String(error);} |
| 30 | await sleep(500); |
| 31 | } |
| 32 | throw new Error('Smoke timeout: '+lastFailure); |
| 33 | }catch(error){ |
| 34 | console.error('application-smoke details:',error instanceof Error?error.message:String(error)); |
| 35 | if(output)console.error('Next.js output (last 3000 characters):',output); |
| 36 | throw error; |
| 37 | }finally{if(child.exitCode===null&&!child.killed)child.kill();} |
| 38 | } |
| 39 | |
| 40 | async function getJson(origin,path){ |
| 41 | const res=await fetch(origin+path,{signal:AbortSignal.timeout(3000),redirect:'manual'}); |
| 42 | return {status:res.status,body:await res.json()}; |
| 43 | } |
| 44 | |
| 45 | async function expectPage(origin,path,marker){ |
| 46 | const res=await fetch(origin+path,{signal:AbortSignal.timeout(3000)}); |
| 47 | const html=await res.text(); |
| 48 | assert.equal(res.status,200,path+': HTTP '+res.status); |
| 49 | assert(html.includes(marker),path+': expected application content missing'); |
| 50 | } |
| 51 | |
| 52 | async function main(){ |
| 53 | const base={...process.env,NODE_ENV:'production',BANK_ADAPTER_MODE:'disabled'}; |
| 54 | const localEnv={...base,TREASURYFLOW_DESKTOP_LOCAL:'1', |
| 55 | TREASURYFLOW_DATA_FILE:join(isolatedDir,'treasuryflow-test.sqlite')}; |
| 56 | await withServer(3101,localEnv,async origin=>{ |
| 57 | const ready=await getJson(origin,'/api/ready'); |
| 58 | assert.equal(ready.status,200,'local desktop readiness status'); |
| 59 | assert.equal(ready.body.status,'ready','local desktop readiness body'); |
| 60 | assert.equal(ready.body.bankAdapter,'disabled','bank must remain disabled'); |
| 61 | await expectPage(origin,'/login','ورود به محیط محلی امن'); |
| 62 | await expectPage(origin,'/dashboard','داشبورد خزانهداری'); |
| 63 | await expectPage(origin,'/integrations','کپی کوئری'); |
| 64 | }); |
| 65 | console.log('application-smoke: local desktop ready; login/dashboard/SQL UI passed; bank disabled'); |
| 66 | |
| 67 | const productionEnv={...base,TREASURYFLOW_DESKTOP_LOCAL:'0'}; |
| 68 | for(const name of ['DATABASE_URL','IDENTITY_PROVIDER','AUTH_PROXY_HMAC_SECRET', |
| 69 | 'KMS_KEY_ID','SIEM_ENDPOINT','WAF_POLICY_ID','ALERT_CHANNEL'])delete productionEnv[name]; |
| 70 | await withServer(3102,productionEnv,async origin=>{ |
| 71 | const ready=await getJson(origin,'/api/ready'); |
| 72 | assert.equal(ready.status,503,'unconfigured production readiness must fail closed'); |
| 73 | assert.equal(ready.body.status,'not-ready','unconfigured production readiness response'); |
| 74 | assert(ready.body.missing.includes('DATABASE_URL'),'missing production prerequisites not reported'); |
| 75 | assert.equal(ready.body.bankAdapter,'disabled','no production bank connection'); |
| 76 | }); |
| 77 | console.log('application-smoke: unconfigured production readiness correctly blocked'); |
| 78 | console.log('application-smoke: PASS'); |
| 79 | } |
| 80 | |
| 81 | try{await main();} |
| 82 | catch{process.exitCode=1;console.error('application-smoke: FAIL');} |
| 83 | finally{ |
| 84 | try{rmSync(isolatedDir,{recursive:true,force:true});} |
| 85 | catch(error){console.warn('Temporary smoke fixture cleanup deferred:',error?.code||'UNKNOWN');} |
| 86 | } |