lobster_profile_source_validation.ps1 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Simulate all wired profile patch sources and verify event + read-back
  2. param(
  3. [string]$ApiBase = "http://127.0.0.1:8006",
  4. [int]$CompanyId = 338,
  5. [int]$TenantId = 33,
  6. [string]$OpsSecret = "lobster-dev-ops"
  7. )
  8. $ErrorActionPreference = "Stop"
  9. try {
  10. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  11. $OutputEncoding = [System.Text.Encoding]::UTF8
  12. } catch { }
  13. $utf8NoBom = New-Object System.Text.UTF8Encoding $false
  14. $reportDir = Join-Path $PSScriptRoot "reports"
  15. if (-not (Test-Path $reportDir)) { New-Item -ItemType Directory -Path $reportDir | Out-Null }
  16. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  17. $reportFile = Join-Path $reportDir "lobster-profile-source-validation-$stamp.json"
  18. $headers = @{
  19. "Content-Type" = "application/json"
  20. "X-Lobster-Ops-Secret" = $OpsSecret
  21. }
  22. Write-Host "=== Profile Domain Source Hook Validation ===" -ForegroundColor Cyan
  23. Write-Host "ApiBase=$ApiBase CompanyId=$CompanyId TenantId=$TenantId"
  24. try {
  25. Invoke-RestMethod -Uri "$ApiBase/api/lobster/admin/phase2/verify/$CompanyId?tenantId=$TenantId" -Headers $headers -TimeoutSec 15 | Out-Null
  26. Write-Host "OK service reachable" -ForegroundColor Green
  27. } catch {
  28. Write-Host "FAIL service not reachable at $ApiBase" -ForegroundColor Red
  29. exit 1
  30. }
  31. $uri = "$($ApiBase.TrimEnd('/'))/api/lobster/admin/validation/profile-domain-sources/${CompanyId}?tenantId=${TenantId}"
  32. Write-Host "POST $uri"
  33. $resp = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -TimeoutSec 300
  34. $json = $resp | ConvertTo-Json -Depth 30
  35. [System.IO.File]::WriteAllText($reportFile, $json, $utf8NoBom)
  36. Write-Host "Report saved: $reportFile" -ForegroundColor Green
  37. if ($resp.sources) {
  38. foreach ($s in $resp.sources) {
  39. $label = $s.source
  40. if ($s.variant) { $label = "$label/$($s.variant)" }
  41. $color = if ($s.passed) { "Green" } else { "Red" }
  42. Write-Host " $label passed=$($s.passed) eventOk=$($s.eventOk) readBack=$($s.readBack)" -ForegroundColor $color
  43. if ($s.error) { Write-Host " error: $($s.error)" -ForegroundColor Red }
  44. }
  45. }
  46. Write-Host "passedCount=$($resp.passedCount)/$($resp.totalCount)" -ForegroundColor $(if ($resp.passed) { "Green" } else { "Yellow" })
  47. if ($resp.passed) {
  48. Write-Host "RESULT: PASS" -ForegroundColor Green
  49. exit 0
  50. }
  51. Write-Host "RESULT: FAIL - $($resp.message)" -ForegroundColor Red
  52. exit 1