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.220", [string]$ResultPath = "artifacts\c18z39-service-channel-rebuild-ledger-drilldown-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath function Invoke-Api { param([string]$Path, [int]$TimeoutSec = 30) Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec $TimeoutSec } $firstPage = @(( Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&limit=2&offset=0&enrichment=summary" -TimeoutSec 15 ).rebuild_attempts) if ($firstPage.Count -lt 1) { throw "C18Z39 smoke needs at least one rebuild attempt in the ledger." } $sample = $firstPage | Select-Object -First 1 $routeID = [string]$sample.route_id $reporterNodeID = [string]$sample.reporter_node_id $serviceClass = [string]$sample.service_class $generation = [string]$sample.generation $filteredDeep = @(( Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&reporter_node_id=$reporterNodeID&route_id=$routeID&service_class=$serviceClass&generation=$generation&limit=5&offset=0&enrichment=deep" -TimeoutSec 30 ).rebuild_attempts) $secondPage = @(( Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&limit=1&offset=1&enrichment=summary" -TimeoutSec 15 ).rebuild_attempts) $filteredAllMatch = $filteredDeep.Count -ge 1 -and @($filteredDeep | Where-Object { [string]$_.reporter_node_id -eq $reporterNodeID -and [string]$_.route_id -eq $routeID -and [string]$_.service_class -eq $serviceClass -and [string]$_.generation -eq $generation }).Count -eq $filteredDeep.Count $offsetMoved = $true if ($firstPage.Count -gt 1 -and $secondPage.Count -gt 0) { $offsetMoved = ([string]$firstPage[1].id -eq [string]$secondPage[0].id) -and ([string]$firstPage[0].id -ne [string]$secondPage[0].id) } $deepHasCorrelation = $false if ($filteredDeep.Count -gt 0) { $deepHasCorrelation = $null -ne $filteredDeep[0].timeline -or [string]$filteredDeep[0].guard_status -ne "" } $backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String $result = [ordered]@{ schema_version = "c18z39.service_channel_rebuild_ledger_drilldown_smoke.v1" cluster_id = $ClusterID route_id = $routeID reporter_node_id = $reporterNodeID service_class = $serviceClass generation = $generation passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and $firstPage.Count -ge 1 -and $filteredAllMatch -and $offsetMoved -and $deepHasCorrelation ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) first_page_returned = ($firstPage.Count -ge 1) filtered_deep_all_match = $filteredAllMatch offset_page_matches_expected_second_row = $offsetMoved filtered_deep_has_timeline_or_guard = $deepHasCorrelation } summary = [ordered]@{ backend_container = $backendLine.Trim() first_page_count = $firstPage.Count second_page_count = $secondPage.Count filtered_deep_count = $filteredDeep.Count first_page_ids = @($firstPage | ForEach-Object { [string]$_.id }) second_page_ids = @($secondPage | ForEach-Object { [string]$_.id }) filtered_sample = ($filteredDeep | Select-Object -First 1) } } $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 "C18Z39 service-channel rebuild ledger drilldown smoke failed. Result: $resultFullPath" } Write-Host "C18Z39 service-channel rebuild ledger drilldown smoke passed. Result: $resultFullPath" $result