lobster_travel_full_validation.ps1 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Lobster travel full-chain validation (21 sections + stress).
  2. # Usage:
  3. # cd d:\ylrz_saas_new\java\scripts
  4. # .\lobster_travel_full_validation.ps1
  5. # .\lobster_travel_full_validation.ps1 -CompanyId 338 -TenantId 33
  6. # .\lobster_travel_full_validation.ps1 -SkipStress
  7. # CI one-click (build + restart + validate):
  8. # .\run_lobster_travel_validation_ci.ps1 -CompanyId 338 -TenantId 33
  9. param(
  10. [string]$ApiBase = "http://127.0.0.1:8006",
  11. [int]$CompanyId = 338,
  12. [int]$TenantId = 33,
  13. [string]$OpsSecret = "lobster-dev-ops",
  14. [string]$DialogueIndustry = "travel",
  15. [switch]$SkipStress
  16. )
  17. $ErrorActionPreference = "Stop"
  18. # Windows 控制台与报告文件统一 UTF-8,避免中文乱码
  19. try {
  20. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  21. $OutputEncoding = [System.Text.Encoding]::UTF8
  22. } catch { }
  23. $utf8NoBom = New-Object System.Text.UTF8Encoding $false
  24. $reportDir = Join-Path $PSScriptRoot "reports"
  25. if (-not (Test-Path $reportDir)) { New-Item -ItemType Directory -Path $reportDir | Out-Null }
  26. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  27. $reportFile = Join-Path $reportDir "lobster-travel-validation-$stamp.json"
  28. Write-Host "=== Lobster Travel Full Validation ===" -ForegroundColor Cyan
  29. Write-Host "ApiBase=$ApiBase CompanyId=$CompanyId TenantId=$TenantId DialogueIndustry=$DialogueIndustry"
  30. # 1) Service reachable
  31. try {
  32. $pingHeaders = @{ "X-Lobster-Ops-Secret" = $OpsSecret }
  33. Invoke-RestMethod -Uri "$ApiBase/api/lobster/admin/phase2/verify/$CompanyId?tenantId=$TenantId" -Headers $pingHeaders -TimeoutSec 15 | Out-Null
  34. Write-Host "OK service reachable" -ForegroundColor Green
  35. } catch {
  36. Write-Host "FAIL service not reachable at $ApiBase" -ForegroundColor Red
  37. Write-Host "Start fs-saas-company on port 8006 first."
  38. exit 1
  39. }
  40. $includeStress = if ($SkipStress) { "false" } else { "true" }
  41. $uri = "$($ApiBase.TrimEnd('/'))/api/lobster/admin/validation/travel-full/${CompanyId}?tenantId=${TenantId}&includeStress=$includeStress&dialogueIndustry=$DialogueIndustry"
  42. $headers = @{
  43. "Content-Type" = "application/json"
  44. "X-Lobster-Ops-Secret" = $OpsSecret
  45. }
  46. Write-Host "POST $uri" -ForegroundColor DarkGray
  47. Write-Host "Running validation (may take 1-3 min)..." -ForegroundColor Yellow
  48. try {
  49. $r = Invoke-WebRequest -Uri $uri -Method POST -Headers $headers -UseBasicParsing -TimeoutSec 900
  50. $body = $r.Content
  51. [System.IO.File]::WriteAllText($reportFile, $body, $utf8NoBom)
  52. Write-Host "Report saved: $reportFile" -ForegroundColor Green
  53. $json = $body | ConvertFrom-Json
  54. Copy-Item -Path $reportFile -Destination (Join-Path $reportDir "lobster-travel-validation-latest.json") -Force
  55. Write-Host ""
  56. Write-Host "--- Section Summary ---" -ForegroundColor Cyan
  57. if ($json.sections) {
  58. $json.sections.PSObject.Properties | ForEach-Object {
  59. $name = $_.Name
  60. $sec = $_.Value
  61. if ($sec -is [PSCustomObject] -and $sec.passed -ne $null) {
  62. $color = if ($sec.passed -eq $true) { "Green" } else { "Red" }
  63. Write-Host (" {0}: {1} ({2})" -f $name, $sec.passed, $sec.message) -ForegroundColor $color
  64. } elseif ($name -eq "stress" -and $sec) {
  65. Write-Host " stress:" -ForegroundColor Cyan
  66. $sec.PSObject.Properties | ForEach-Object {
  67. $st = $_.Value
  68. if ($st.passed -ne $null) {
  69. $color = if ($st.passed -eq $true) { "Green" } else { "Red" }
  70. Write-Host (" {0}: {1}" -f $_.Name, $st.passed) -ForegroundColor $color
  71. }
  72. }
  73. }
  74. }
  75. }
  76. Write-Host ("Duration: {0}ms Overall: {1}" -f $json.durationMs, $json.passed) -ForegroundColor Cyan
  77. Write-Host ""
  78. if ($json.passed -eq $true) {
  79. Write-Host "PASSED all checks" -ForegroundColor Green
  80. exit 0
  81. } else {
  82. Write-Host "FAILED some checks did not pass" -ForegroundColor Red
  83. if ($json.failures) {
  84. foreach ($f in $json.failures) {
  85. Write-Host " - $f" -ForegroundColor Yellow
  86. }
  87. }
  88. exit 1
  89. }
  90. } catch {
  91. Write-Host "FAIL request error: $($_.Exception.Message)" -ForegroundColor Red
  92. exit 1
  93. }