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.223", [string]$ResultPath = "artifacts\c18z41-service-channel-rebuild-incident-actions-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-ApiGet { param([string]$Path, [int]$TimeoutSec = 30) Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec $TimeoutSec } function Invoke-ApiPost { param([string]$Path, [object]$Body, [int]$TimeoutSec = 30) Invoke-RestMethod -Method Post -Uri "$ApiBaseUrl$Path" -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 20) -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 } $before = @((Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).rebuild_incidents) if ($before.Count -lt 1) { throw "C18Z41 smoke needs at least one rebuild incident." } $target = $before | Where-Object { (Get-Prop $_ "alert_silenced") -ne $true } | Select-Object -First 1 if ($null -eq $target) { $target = $before | Select-Object -First 1 } $investigationPayload = [ordered]@{ actor_user_id = $ActorUserID reporter_node_id = [string]$target.reporter_node_id route_id = [string]$target.route_id service_class = [string]$target.service_class generation = [string]$target.generation guard_status = [string]$target.guard_status incident_id = [string]$target.fingerprint reason = "c18z41 smoke opened deep rebuild ledger" } Invoke-ApiPost -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents/investigations" -Body $investigationPayload -TimeoutSec 15 | Out-Null $audit = @((Invoke-ApiGet -Path "/clusters/$ClusterID/audit?actor_user_id=$ActorUserID&limit=20" -TimeoutSec 15).audit_events) $auditMatched = @($audit | Where-Object { [string]$_.event_type -eq "fabric.service_channel_rebuild_incident.investigation_opened" -and [string]$_.target_id -eq [string]$target.route_id }).Count -ge 1 $silencePayload = [ordered]@{ actor_user_id = $ActorUserID reporter_node_id = [string]$target.reporter_node_id route_id = [string]$target.route_id guard_status = [string]$target.guard_status generation = [string]$target.generation reason = "c18z41 smoke incident acknowledgement" ttl_seconds = 21600 } Invoke-ApiPost -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-health/silences" -Body $silencePayload -TimeoutSec 15 | Out-Null $after = @((Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).rebuild_incidents) $afterTarget = $after | Where-Object { [string]$_.reporter_node_id -eq [string]$target.reporter_node_id -and [string]$_.route_id -eq [string]$target.route_id -and [string]$_.service_class -eq [string]$target.service_class -and [string]$_.generation -eq [string]$target.generation -and [string]$_.guard_status -eq [string]$target.guard_status } | Select-Object -First 1 $health = (Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-health?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).rebuild_health $backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String $incidentSilenced = $null -ne $afterTarget -and (Get-Prop $afterTarget "alert_silenced") -eq $true $result = [ordered]@{ schema_version = "c18z41.service_channel_rebuild_incident_actions_smoke.v1" cluster_id = $ClusterID incident_fingerprint = [string]$target.fingerprint route_id = [string]$target.route_id reporter_node_id = [string]$target.reporter_node_id generation = [string]$target.generation passed = [bool]( $backendLine.Contains($ExpectedBackendImage) -and $auditMatched -and $incidentSilenced -and [int]$health.silenced_count -ge 1 ) checks = [ordered]@{ backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage) investigation_audit_recorded = $auditMatched incident_marked_silenced = $incidentSilenced health_reports_silenced = ([int]$health.silenced_count -ge 1) } summary = [ordered]@{ backend_container = $backendLine.Trim() before_incident_count = $before.Count after_incident_count = $after.Count target_before = $target target_after = $afterTarget health_silenced_count = [int]$health.silenced_count } } $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 "C18Z41 service-channel rebuild incident actions smoke failed. Result: $resultFullPath" } Write-Host "C18Z41 service-channel rebuild incident actions smoke passed. Result: $resultFullPath" $result