param([int]$FrontendPort=3220,[int]$BackendPort=8020) $ErrorActionPreference='Stop' $projectRoot=Split-Path $PSScriptRoot -Parent $python=Join-Path $projectRoot 'backend/venv/Scripts/python.exe' $next=Join-Path $projectRoot 'node_modules/next/dist/bin/next' if(!(Test-Path -LiteralPath $python) -or !(Test-Path -LiteralPath $next)){throw '请先安装项目依赖,必须使用backend/venv。'} if(!(Test-Path -LiteralPath (Join-Path $projectRoot '.next/BUILD_ID'))){throw '请先在项目根目录执行npm run build。'} foreach($port in @($FrontendPort,$BackendPort)){ if(Get-NetTCPConnection -State Listen -LocalPort $port -ErrorAction SilentlyContinue){throw "端口$port已占用;本脚本不会停止现有服务。"} } $evidence=Join-Path $projectRoot 'test-evidence' New-Item -ItemType Directory -Path $evidence -Force | Out-Null $stamp=Get-Date -Format 'yyyyMMdd-HHmmss' $env:NO_PROXY='*';$env:HTTP_PROXY='';$env:HTTPS_PROXY='';$env:ALL_PROXY='' $env:RISK_AGENT_BACKEND_URL="http://127.0.0.1:$BackendPort" $env:XINGBANG_DEMO_ROLE_LOGIN='1' $backend=Start-Process -FilePath $python -ArgumentList '-m','uvicorn','app:app','--host','127.0.0.1','--port',"$BackendPort" -WorkingDirectory (Join-Path $projectRoot 'backend') -WindowStyle Hidden -RedirectStandardOutput (Join-Path $evidence "$stamp-backend.out.log") -RedirectStandardError (Join-Path $evidence "$stamp-backend.err.log") -PassThru $frontend=Start-Process -FilePath (Get-Command node).Source -ArgumentList $next,'start','--hostname','127.0.0.1','--port',"$FrontendPort" -WorkingDirectory $projectRoot -WindowStyle Hidden -RedirectStandardOutput (Join-Path $evidence "$stamp-frontend.out.log") -RedirectStandardError (Join-Path $evidence "$stamp-frontend.err.log") -PassThru @{backend_launcher_pid=$backend.Id;frontend_pid=$frontend.Id;frontend_port=$FrontendPort;backend_port=$BackendPort;created_at=$stamp} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $evidence "$stamp-preview-processes.json") Write-Output "新版入口:http://127.0.0.1:$FrontendPort/experience-center" Write-Output '日志与本任务进程信息已保存到test-evidence;旧版服务没有停止。'