param( [string]$ApiBaseUrl = "http://192.168.200.61:18121/api/v1", [string]$ClusterID = "cfc0743d-d960-49fb-9de8-96e063d5e4aa", [string]$ActorUserID = "f67d943f-5397-4b3a-a229-695fe67ad700", [string]$DockerSSH = "test-docker", [string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.224", [string]$ResultPath = "artifacts\c18z42-service-channel-rebuild-correlation-snapshot-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath function Get-Prop { param([object]$Object, [string]$Name) if ($null -eq $Object) { return $null } $prop = $Object.PSObject.Properties[$Name] if ($null -eq $prop) { return $null } return $prop.Value } function Invoke-TimedApi { param([string]$Path, [int]$TimeoutSec = 30) $sw = [System.Diagnostics.Stopwatch]::StartNew() $body = Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec $TimeoutSec $sw.Stop() [pscustomobject]@{ body = $body elapsed_ms = [int]$sw.ElapsedMilliseconds } } $summaryResponse = Invoke-TimedApi -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&limit=1&enrichment=summary" -TimeoutSec 15 $summaryAttempts = @($summaryResponse.body.rebuild_attempts) if ($summaryAttempts.Count -lt 1) { throw "C18Z42 smoke needs at least one rebuild attempt." } $sampleSummary = $summaryAttempts | Select-Object -First 1 $reporterNodeID = [string]$sampleSummary.reporter_node_id $routeID = [string]$sampleSummary.route_id $serviceClass = [string]$sampleSummary.service_class $generation = [string]$sampleSummary.generation $deepPath = "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&reporter_node_id=$reporterNodeID&route_id=$routeID&service_class=$serviceClass&generation=$generation&limit=1&enrichment=deep" $deepFirst = Invoke-TimedApi -Path $deepPath -TimeoutSec 30 $deepFirstAttempts = @($deepFirst.body.rebuild_attempts) $deepFirstSample = $deepFirstAttempts | Select-Object -First 1 $deepSecond = Invoke-TimedApi -Path $deepPath -TimeoutSec 30 $deepSecondAttempts = @($deepSecond.body.rebuild_attempts) $deepSecondSample = $deepSecondAttempts | Select-Object -First 1 $incidentsResponse = Invoke-TimedApi -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30 $incidents = @($incidentsResponse.body.rebuild_incidents) $summaryHasGuard = [string](Get-Prop $sampleSummary "guard_status") -ne "" $summaryHasTimeline = $null -ne (Get-Prop $sampleSummary "timeline") $deepHasSnapshot = [string](Get-Prop $deepSecondSample "correlation_snapshot_at") -ne "" $deepHasGuard = [string](Get-Prop $deepSecondSample "guard_status") -ne "" $deepHasTimeline = $null -ne (Get-Prop $deepSecondSample "timeline") $backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String $result = [ordered]@{ schema_version = "c18z42.service_channel_rebuild_correlation_snapshot_smoke.v1" cluster_id = $ClusterID route_id = $routeID reporter_node_id = $reporterNodeID generation = $generation passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and -not $summaryHasGuard -and -not $summaryHasTimeline -and $deepHasSnapshot -and $deepHasGuard -and $deepHasTimeline -and $incidents.Count -ge 1 ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) summary_omits_guard = (-not $summaryHasGuard) summary_omits_timeline = (-not $summaryHasTimeline) deep_returns_snapshot_timestamp = $deepHasSnapshot deep_returns_guard = $deepHasGuard deep_returns_timeline = $deepHasTimeline incidents_returned = ($incidents.Count -ge 1) } timings_ms = [ordered]@{ summary = $summaryResponse.elapsed_ms deep_first = $deepFirst.elapsed_ms deep_second = $deepSecond.elapsed_ms incidents = $incidentsResponse.elapsed_ms } summary = [ordered]@{ backend_container = $backendLine.Trim() deep_first_sample = $deepFirstSample deep_second_sample = $deepSecondSample incident_count = $incidents.Count } } $resultFullPath = Join-Path $repoRoot $ResultPath $resultDir = Split-Path -Parent $resultFullPath if (-not (Test-Path $resultDir)) { New-Item -ItemType Directory -Path $resultDir | Out-Null } $result | ConvertTo-Json -Depth 100 | Set-Content -Path $resultFullPath -Encoding UTF8 if (-not $result.passed) { throw "C18Z42 service-channel rebuild correlation snapshot smoke failed. Result: $resultFullPath" } Write-Host "C18Z42 service-channel rebuild correlation snapshot smoke passed. Result: $resultFullPath" $result