t28-live-acceptance.ps1 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. $ErrorActionPreference = 'Stop'
  2. $base = 'http://192.168.110.96:8301/api/cockpit/v1'
  3. function Read-Cockpit([string]$path) {
  4. $response = Invoke-WebRequest "$base/$path" -UseBasicParsing -TimeoutSec 25
  5. $body = $response.Content | ConvertFrom-Json
  6. if ([int]$response.StatusCode -ne 200 -or $body.code -ne 200) { throw "Unsuccessful response: $path" }
  7. return $body.data
  8. }
  9. $map = Read-Cockpit 'map-snapshot?pageSize=1000'
  10. $overview = Read-Cockpit 'monitoring/overview'
  11. $distribution = Read-Cockpit 'monitoring/distribution?pageSize=1000'
  12. $empty = Read-Cockpit 'monitoring/distribution?pointStatus=EMPTY&pageSize=1000'
  13. $unassigned = Read-Cockpit 'monitoring/distribution?district=UNASSIGNED&pageSize=1000'
  14. $gas = Read-Cockpit 'monitoring/distribution?industry=GAS&pageSize=1000'
  15. $expectedCodes = @('GS001', 'GS002', 'PS001', 'PS002', 'RQ001', 'RQ002') -join ','
  16. $checks = @()
  17. function Check([string]$name, [bool]$passed, $actual, $expected) {
  18. $script:checks += [pscustomobject]@{ name=$name; passed=$passed; actual=$actual; expected=$expected }
  19. }
  20. $mapCodes = @($map.monitoringPoints.pointCode | Sort-Object) -join ','
  21. $distributionCodes = @($distribution.monitoringPoints.pointCode | Sort-Object) -join ','
  22. $overviewCodes = @($overview.mapFilter.pointCodes | Sort-Object) -join ','
  23. Check 'map-six-baseline' ($mapCodes -eq $expectedCodes) $mapCodes $expectedCodes
  24. Check 'overview-count' ($overview.counts.monitoringPointCount -eq 6) $overview.counts.monitoringPointCount 6
  25. Check 'overview-point-codes' ($overviewCodes -eq $expectedCodes) $overviewCodes $expectedCodes
  26. Check 'distribution-point-codes' ($distributionCodes -eq $expectedCodes) $distributionCodes $expectedCodes
  27. $emptyCount = ($distribution.pointStatusDistribution | Where-Object status -eq 'EMPTY').count
  28. Check 'distribution-empty-bucket' ($emptyCount -eq 6) $emptyCount 6
  29. $candidates = @($map.monitoringPoints).Count + @($map.unassociatedEquipment).Count
  30. $excluded = $distribution.excluded.unknownTypeCount + $distribution.excluded.typeKindMismatchCount + $distribution.excluded.nonFormalIndustryCount + $distribution.excluded.invalidCoordinateCount
  31. Check 'whole-source-object-reconciliation' ($candidates -eq ($distribution.pagination.total + $excluded)) ($distribution.pagination.total + $excluded) $candidates
  32. $statesTotal = ($distribution.pointStatusDistribution | Measure-Object -Property count -Sum).Sum
  33. Check 'status-sum-matches-pagination' ($statesTotal -eq $distribution.pagination.total) $statesTotal $distribution.pagination.total
  34. Check 'distribution-no-false-empty-freshness' ($distribution.freshness.status -eq 'CURRENT' -and $distribution.freshness.reason -eq 'READY') "$($distribution.freshness.status)/$($distribution.freshness.reason)" 'CURRENT/READY'
  35. $notRenderable = @($distribution.monitoringPoints | Where-Object { $_.coordinateValidation.renderable -eq $false }).Count
  36. Check 'unrenderable-points-still-counted' ($notRenderable -eq 6) $notRenderable 6
  37. Check 'empty-status-filter' ($empty.pagination.total -eq 6 -and @($empty.monitoringPoints).Count -eq 6 -and @($empty.unassociatedEquipment).Count -eq 0) $empty.pagination.total 6
  38. $unassignedCodes = @($unassigned.monitoringPoints.pointCode | Sort-Object) -join ','
  39. Check 'unassigned-retains-empty-points' ($unassignedCodes -eq $expectedCodes) $unassignedCodes $expectedCodes
  40. $gasPoints = @($gas.monitoringPoints).Count
  41. Check 'formal-industry-does-not-invent-empty-point-industry' ($gasPoints -eq 0) $gasPoints 0
  42. $result = [pscustomobject]@{ observedAt=(Get-Date -Format o); baseUrl=$base; method='GET only'; candidateObjects=$candidates; includedObjects=$distribution.pagination.total; excludedObjects=$excluded; allPassed=(@($checks | Where-Object { -not $_.passed }).Count -eq 0); checks=$checks }
  43. $artifact = Join-Path $PSScriptRoot 'artifacts/t28/acceptance-checks.json'
  44. New-Item -ItemType Directory -Force -Path (Split-Path $artifact) | Out-Null
  45. $result | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $artifact -Encoding utf8
  46. $result | ConvertTo-Json -Depth 10
  47. if (-not $result.allPassed) { exit 1 }