lobster_semantic_context_validation.ps1 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Semantic keyword full validation: 8 context scenarios + per-word catalog (6 categories).
  2. # Usage:
  3. # cd d:\ylrz_saas_new\java\scripts
  4. # .\lobster_semantic_context_validation.ps1
  5. # .\lobster_semantic_context_validation.ps1 -Mode catalog
  6. param(
  7. [string]$ApiBase = "http://127.0.0.1:8006",
  8. [int]$CompanyId = 338,
  9. [int]$TenantId = 33,
  10. [string]$OpsSecret = "lobster-dev-ops",
  11. [ValidateSet("full", "catalog")]
  12. [string]$Mode = "full"
  13. )
  14. $ErrorActionPreference = "Stop"
  15. try {
  16. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  17. $OutputEncoding = [System.Text.Encoding]::UTF8
  18. } catch { }
  19. $utf8NoBom = New-Object System.Text.UTF8Encoding $false
  20. $reportDir = Join-Path $PSScriptRoot "reports"
  21. if (-not (Test-Path $reportDir)) { New-Item -ItemType Directory -Path $reportDir | Out-Null }
  22. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  23. $reportFile = Join-Path $reportDir "lobster-semantic-context-validation-$stamp.json"
  24. Write-Host "=== Lobster Semantic Keyword Validation ($Mode) ===" -ForegroundColor Cyan
  25. Write-Host "ApiBase=$ApiBase CompanyId=$CompanyId TenantId=$TenantId"
  26. try {
  27. $pingHeaders = @{ "X-Lobster-Ops-Secret" = $OpsSecret }
  28. Invoke-RestMethod -Uri "$ApiBase/api/lobster/admin/phase2/verify/$CompanyId?tenantId=$TenantId" -Headers $pingHeaders -TimeoutSec 15 | Out-Null
  29. Write-Host "OK service reachable" -ForegroundColor Green
  30. } catch {
  31. Write-Host "FAIL service not reachable at $ApiBase" -ForegroundColor Red
  32. exit 1
  33. }
  34. if ($Mode -eq "catalog") {
  35. $uri = "$($ApiBase.TrimEnd('/'))/api/lobster/admin/validation/semantic-catalog/${CompanyId}?tenantId=${TenantId}"
  36. } else {
  37. $uri = "$($ApiBase.TrimEnd('/'))/api/lobster/admin/validation/semantic-context/${CompanyId}?tenantId=${TenantId}&mode=full"
  38. }
  39. $headers = @{
  40. "Content-Type" = "application/json"
  41. "X-Lobster-Ops-Secret" = $OpsSecret
  42. }
  43. Write-Host "POST $uri"
  44. try {
  45. $resp = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -TimeoutSec 600
  46. $json = $resp | ConvertTo-Json -Depth 30
  47. [System.IO.File]::WriteAllText($reportFile, $json, $utf8NoBom)
  48. Write-Host "Report saved: $reportFile" -ForegroundColor Green
  49. } catch {
  50. Write-Host "FAIL request error: $($_.Exception.Message)" -ForegroundColor Red
  51. exit 1
  52. }
  53. Write-Host ""
  54. Write-Host "Duration: $($resp.durationMs)ms"
  55. Write-Host "Total cases: $($resp.totalCases) Passed: $($resp.passedCases)" -ForegroundColor $(if ($resp.passed) { "Green" } else { "Yellow" })
  56. if ($resp.sections.catalogValidation.categories) {
  57. Write-Host ""
  58. Write-Host "Catalog by category:" -ForegroundColor Cyan
  59. $cats = $resp.sections.catalogValidation.categories
  60. foreach ($prop in $cats.PSObject.Properties) {
  61. $c = $prop.Value
  62. $color = if ($c.passed) { "Green" } else { "Red" }
  63. $label = $prop.Name
  64. Write-Host " $label : keywords=$($c.keywordCount) checks=$($c.totalCases)/$($c.passedCases) passed=$($c.passed)" -ForegroundColor $color
  65. if ($c.failures -and $c.failures.Count -gt 0) {
  66. $show = [Math]::Min(5, $c.failures.Count)
  67. for ($i = 0; $i -lt $show; $i++) {
  68. Write-Host " - $($c.failures[$i])" -ForegroundColor Red
  69. }
  70. if ($c.failures.Count -gt 5) {
  71. Write-Host " ... +$($c.failures.Count - 5) more" -ForegroundColor Red
  72. }
  73. }
  74. }
  75. } elseif ($resp.categories) {
  76. Write-Host ""
  77. Write-Host "Catalog by category:" -ForegroundColor Cyan
  78. foreach ($prop in $resp.categories.PSObject.Properties) {
  79. $c = $prop.Value
  80. $color = if ($c.passed) { "Green" } else { "Red" }
  81. Write-Host " $($prop.Name) : keywords=$($c.keywordCount) checks=$($c.totalCases)/$($c.passedCases)" -ForegroundColor $color
  82. }
  83. }
  84. if ($resp.contextCases) {
  85. Write-Host ""
  86. Write-Host "Context scenarios:" -ForegroundColor Cyan
  87. foreach ($c in $resp.contextCases) {
  88. $color = if ($c.passed) { "Green" } else { "Red" }
  89. Write-Host " [$($c.id)] $($c.input) -> $($c.passed)" -ForegroundColor $color
  90. }
  91. }
  92. if ($resp.failures -and $resp.failures.Count -gt 0) {
  93. Write-Host ""
  94. Write-Host "Failures:" -ForegroundColor Red
  95. foreach ($f in $resp.failures) {
  96. Write-Host " - $f" -ForegroundColor Red
  97. }
  98. }
  99. if ($resp.passed) {
  100. Write-Host ""
  101. Write-Host "RESULT: PASS" -ForegroundColor Green
  102. exit 0
  103. } else {
  104. Write-Host ""
  105. Write-Host "RESULT: FAIL ($($resp.message))" -ForegroundColor Red
  106. exit 1
  107. }