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]$EntryNodeName = "test-1", [string]$ExitNodeName = "test-2", [string]$EntryBaseUrl = "http://192.168.200.61:19131", [string]$DockerSSH = "test-docker", [string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.211", [string]$ExpectedNodeAgentImage = "rap-node-agent:0.2.208", [string]$ResultPath = "artifacts\c18z31-service-channel-rebuild-ledger-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) return Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec 30 } function Get-NodeByName { param([string]$Name) $nodes = (Invoke-Api -Path "/clusters/$ClusterID/nodes?actor_user_id=$ActorUserID").nodes $node = @($nodes | Where-Object { $_.name -eq $Name }) | Select-Object -First 1 if ($null -eq $node) { throw "Node '$Name' was not found in cluster $ClusterID" } return $node } $baseSmokePath = Join-Path $scriptDir "c18z6-live-service-channel-active-rebuild-smoke.ps1" $baseResultPath = "artifacts\c18z31-base-active-rebuild-smoke-result.json" & $baseSmokePath ` -ApiBaseUrl $ApiBaseUrl ` -ClusterID $ClusterID ` -ActorUserID $ActorUserID ` -EntryNodeName $EntryNodeName ` -ExitNodeName $ExitNodeName ` -EntryBaseUrl $EntryBaseUrl ` -DockerSSH $DockerSSH ` -PreRebuildBatchCount 4 ` -PostRebuildBatchCount 8 ` -PacketsPerBatch 4 ` -BatchDelayMilliseconds 20 ` -RequiredNodeVersion "0.2.208" ` -ResultPath $baseResultPath | Out-Null $baseResultFullPath = Join-Path $repoRoot $baseResultPath $baseResult = Get-Content $baseResultFullPath -Raw | ConvertFrom-Json $entryNode = Get-NodeByName -Name $EntryNodeName $primaryRouteID = [string]$baseResult.route_intents.primary_route_intent_id $alternateRouteID = [string]$baseResult.route_intents.alternate_route_intent_id $ledger = (Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&reporter_node_id=$($entryNode.id)&route_id=$primaryRouteID&limit=20").rebuild_attempts $matching = @($ledger | Where-Object { $_.route_id -eq $primaryRouteID -and $_.replacement_route_id -eq $alternateRouteID -and $_.rebuild_status -eq "applied" -and $_.outcome -eq "replacement_selected" }) $backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String $nodeLines = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_node_test_'") | Out-String $sample = $matching | Select-Object -First 1 $result = [ordered]@{ schema_version = "c18z31.service_channel_rebuild_ledger_smoke.v1" cluster_id = $ClusterID entry_node = @{ name = $entryNode.name; id = $entryNode.id } primary_route_id = $primaryRouteID alternate_route_id = $alternateRouteID passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and $nodeLines.Contains($ExpectedNodeAgentImage) -and $matching.Count -ge 1 -and [string]$sample.rebuild_request_id -ne "" -and [string]$sample.policy_fingerprint -ne "" -and [string]$sample.generation -ne "" -and @($sample.old_hops).Count -gt 0 -and @($sample.replacement_hops).Count -gt 0 ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) node_agent_expected_image_deployed = $nodeLines.Contains($ExpectedNodeAgentImage) ledger_has_matching_applied_rebuild = ($matching.Count -ge 1) ledger_has_request_id = ([string]$sample.rebuild_request_id -ne "") ledger_has_policy_fingerprint = ([string]$sample.policy_fingerprint -ne "") ledger_has_generation = ([string]$sample.generation -ne "") ledger_has_old_and_replacement_hops = (@($sample.old_hops).Count -gt 0 -and @($sample.replacement_hops).Count -gt 0) } summary = [ordered]@{ backend_container = $backendLine.Trim() node_containers = $nodeLines.Trim() ledger_count = @($ledger).Count matching_count = $matching.Count sample = $sample base_smoke_result = $baseResultFullPath } } $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 "C18Z31 service-channel rebuild ledger smoke failed. Result: $resultFullPath" } Write-Host "C18Z31 service-channel rebuild ledger smoke passed. Result: $resultFullPath" $result