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.222", [string]$ResultPath = "artifacts\c18z40-service-channel-rebuild-incidents-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 } $incidents = @((Invoke-Api -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).rebuild_incidents) if ($incidents.Count -lt 1) { throw "C18Z40 smoke needs at least one rebuild incident." } $sample = $incidents | Select-Object -First 1 $reporterNodeID = [string]$sample.reporter_node_id $routeID = [string]$sample.route_id $serviceClass = [string]$sample.service_class $generation = [string]$sample.generation $ledger = @((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=20&offset=0&enrichment=deep" -TimeoutSec 30).rebuild_attempts) $ledgerMatchesIncident = $ledger.Count -ge 1 -and @($ledger | 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 $ledger.Count $hasRequiredIncidentFields = [string]$sample.fingerprint -ne "" -and [string]$sample.guard_status -ne "" -and [string]$sample.guard_severity -ne "" -and [int]$sample.attempt_count -ge 1 -and [string]$sample.last_seen_at -ne "" -and [string]$sample.recommended_operator_action -ne "" $backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String $result = [ordered]@{ schema_version = "c18z40.service_channel_rebuild_incidents_smoke.v1" cluster_id = $ClusterID incident_fingerprint = [string]$sample.fingerprint route_id = $routeID reporter_node_id = $reporterNodeID service_class = $serviceClass generation = $generation passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and $incidents.Count -ge 1 -and $hasRequiredIncidentFields -and $ledgerMatchesIncident ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) incidents_returned = ($incidents.Count -ge 1) required_incident_fields_present = $hasRequiredIncidentFields deep_ledger_filter_matches_incident = $ledgerMatchesIncident } summary = [ordered]@{ backend_container = $backendLine.Trim() incident_count = $incidents.Count filtered_ledger_count = $ledger.Count sample_incident = $sample filtered_ledger_sample = ($ledger | 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 "C18Z40 service-channel rebuild incidents smoke failed. Result: $resultFullPath" } Write-Host "C18Z40 service-channel rebuild incidents smoke passed. Result: $resultFullPath" $result