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.227", [string]$ExpectedNodeAgentImage = "rap-node-agent:0.2.208", [string]$ResultPath = "artifacts\c18z45-service-channel-rebuild-snapshot-auto-warmup-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath $baseResultPath = "artifacts\c18z45-base-rebuild-ledger-smoke-result.json" function Invoke-ApiGet { param([string]$Path, [int]$TimeoutSec = 30) Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec $TimeoutSec } 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 } & (Join-Path $scriptDir "c18z31-service-channel-rebuild-ledger-smoke.ps1") ` -ApiBaseUrl $ApiBaseUrl ` -ClusterID $ClusterID ` -ActorUserID $ActorUserID ` -EntryNodeName $EntryNodeName ` -ExitNodeName $ExitNodeName ` -EntryBaseUrl $EntryBaseUrl ` -DockerSSH $DockerSSH ` -ExpectedBackendImage $ExpectedBackendImage ` -ExpectedNodeAgentImage $ExpectedNodeAgentImage ` -ResultPath $baseResultPath | Out-Null $baseResult = Get-Content (Join-Path $repoRoot $baseResultPath) -Raw | ConvertFrom-Json $entryNodeID = [string]$baseResult.entry_node.id $primaryRouteID = [string]$baseResult.primary_route_id $alternateRouteID = [string]$baseResult.alternate_route_id $generation = [string]$baseResult.summary.sample.generation $auditEvent = $null for ($i = 0; $i -lt 12; $i++) { $audit = @((Invoke-ApiGet -Path "/clusters/$ClusterID/audit?actor_user_id=$ActorUserID&limit=50" -TimeoutSec 15).audit_events) $auditEvent = @($audit | Where-Object { $warmedRouteIDs = @((Get-Prop $_.payload "warmed_route_ids") | ForEach-Object { [string]$_ }) $warmedGenerations = @((Get-Prop $_.payload "warmed_generations") | ForEach-Object { [string]$_ }) $_.event_type -eq "fabric.service_channel_rebuild_snapshot.auto_warmup" -and [string](Get-Prop $_.payload "reporter_node_id") -eq $entryNodeID -and [int](Get-Prop $_.payload "warmed_count") -gt 0 -and $warmedRouteIDs -contains $primaryRouteID -and $warmedGenerations -contains $generation } | Select-Object -First 1) if ($null -ne $auditEvent -and $auditEvent.Count -gt 0) { $auditEvent = $auditEvent | Select-Object -First 1 break } Start-Sleep -Seconds 2 } $deepPath = "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&reporter_node_id=$entryNodeID&route_id=$primaryRouteID&replacement_route_id=$alternateRouteID&generation=$generation&limit=5&enrichment=deep" $deepAttempts = @((Invoke-ApiGet -Path $deepPath -TimeoutSec 30).rebuild_attempts) $warmedAttemptIDs = @() if ($null -ne $auditEvent) { $warmedAttemptIDs = @((Get-Prop $auditEvent.payload "warmed_attempt_ids") | ForEach-Object { [string]$_ }) } $deepSample = $deepAttempts | Where-Object { $warmedAttemptIDs -contains [string]$_.id } | Select-Object -First 1 if ($null -eq $deepSample) { $deepSample = $deepAttempts | Select-Object -First 1 } $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 $result = [ordered]@{ schema_version = "c18z45.service_channel_rebuild_snapshot_auto_warmup_smoke.v1" cluster_id = $ClusterID entry_node_id = $entryNodeID primary_route_id = $primaryRouteID alternate_route_id = $alternateRouteID generation = $generation passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and $nodeLines.Contains($ExpectedNodeAgentImage) -and $null -ne $auditEvent -and [string](Get-Prop $auditEvent.payload "trigger") -eq "node_heartbeat" -and [int](Get-Prop $auditEvent.payload "warmed_count") -gt 0 -and @((Get-Prop $auditEvent.payload "warmed_route_ids") | ForEach-Object { [string]$_ }) -contains $primaryRouteID -and @((Get-Prop $auditEvent.payload "warmed_generations") | ForEach-Object { [string]$_ }) -contains $generation -and $deepAttempts.Count -ge 1 -and [string](Get-Prop $deepSample "correlation_snapshot_at") -ne "" -and ((Get-Prop $deepSample "node_transition_matched") -eq $true -or (Get-Prop $deepSample "node_route_generation_matched") -eq $true -or [string](Get-Prop $deepSample "post_rebuild_selected_route_id") -ne "") ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) node_agent_expected_image_deployed = $nodeLines.Contains($ExpectedNodeAgentImage) audit_auto_warmup_found = ($null -ne $auditEvent) audit_triggered_by_heartbeat = ($null -ne $auditEvent -and [string](Get-Prop $auditEvent.payload "trigger") -eq "node_heartbeat") audit_warmed_snapshot = ($null -ne $auditEvent -and [int](Get-Prop $auditEvent.payload "warmed_count") -gt 0) audit_warmed_current_route = ($null -ne $auditEvent -and @((Get-Prop $auditEvent.payload "warmed_route_ids") | ForEach-Object { [string]$_ }) -contains $primaryRouteID) audit_warmed_current_generation = ($null -ne $auditEvent -and @((Get-Prop $auditEvent.payload "warmed_generations") | ForEach-Object { [string]$_ }) -contains $generation) deep_has_snapshot = ($deepAttempts.Count -ge 1 -and [string](Get-Prop $deepSample "correlation_snapshot_at") -ne "") deep_has_runtime_evidence = ($deepAttempts.Count -ge 1 -and ((Get-Prop $deepSample "node_transition_matched") -eq $true -or (Get-Prop $deepSample "node_route_generation_matched") -eq $true -or [string](Get-Prop $deepSample "post_rebuild_selected_route_id") -ne "")) } summary = [ordered]@{ backend_container = $backendLine.Trim() node_containers = $nodeLines.Trim() audit_event = $auditEvent deep_sample = $deepSample base_smoke_result = (Join-Path $repoRoot $baseResultPath) } } $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 "C18Z45 service-channel rebuild snapshot auto-warmup smoke failed. Result: $resultFullPath" } Write-Host "C18Z45 service-channel rebuild snapshot auto-warmup smoke passed. Result: $resultFullPath" $result