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.219", [string]$ResultPath = "artifacts\c18z38-service-channel-rebuild-ledger-enrichment-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=5&enrichment=summary" -TimeoutSec 15 $summaryAttempts = @($summaryResponse.body.rebuild_attempts) if ($summaryAttempts.Count -lt 1) { throw "C18Z38 smoke needs at least one rebuild attempt in the ledger." } $sampleSummary = $summaryAttempts | Select-Object -First 1 $routeID = [string]$sampleSummary.route_id $reporterNodeID = [string]$sampleSummary.reporter_node_id $deepResponse = Invoke-TimedApi -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&reporter_node_id=$reporterNodeID&route_id=$routeID&limit=5&enrichment=deep" -TimeoutSec 30 $deepAttempts = @($deepResponse.body.rebuild_attempts) $sampleDeep = $deepAttempts | Select-Object -First 1 $readinessResponse = Invoke-TimedApi -Path "/clusters/$ClusterID/fabric/service-channels/readiness?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30 $readiness = $readinessResponse.body.fabric_service_channel_readiness $summaryHasTimeline = $null -ne (Get-Prop $sampleSummary "timeline") $summaryHasGuard = [string](Get-Prop $sampleSummary "guard_status") -ne "" $deepHasTimeline = $null -ne (Get-Prop $sampleDeep "timeline") $deepHasGuard = [string](Get-Prop $sampleDeep "guard_status") -ne "" $backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String $result = [ordered]@{ schema_version = "c18z38.service_channel_rebuild_ledger_enrichment_smoke.v1" cluster_id = $ClusterID route_id = $routeID reporter_node_id = $reporterNodeID passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and $summaryAttempts.Count -ge 1 -and $deepAttempts.Count -ge 1 -and -not $summaryHasTimeline -and -not $summaryHasGuard -and ($deepHasTimeline -or $deepHasGuard) -and [string](Get-Prop $readiness "status") -ne "" ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) summary_returned_attempts = ($summaryAttempts.Count -ge 1) summary_omits_timeline = (-not $summaryHasTimeline) summary_omits_guard = (-not $summaryHasGuard) deep_returned_attempts = ($deepAttempts.Count -ge 1) deep_has_timeline_or_guard = ($deepHasTimeline -or $deepHasGuard) readiness_returned_status = ([string](Get-Prop $readiness "status") -ne "") } timings_ms = [ordered]@{ summary = $summaryResponse.elapsed_ms deep = $deepResponse.elapsed_ms readiness = $readinessResponse.elapsed_ms } summary = [ordered]@{ backend_container = $backendLine.Trim() summary_attempt_count = $summaryAttempts.Count deep_attempt_count = $deepAttempts.Count readiness_status = [string](Get-Prop $readiness "status") summary_sample = $sampleSummary deep_sample = $sampleDeep } } $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 "C18Z38 service-channel rebuild ledger enrichment smoke failed. Result: $resultFullPath" } Write-Host "C18Z38 service-channel rebuild ledger enrichment smoke passed. Result: $resultFullPath" $result