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]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.281-c18z109", [string]$DockerSSH = "test-docker", [string]$ResultPath = "artifacts\c18z104-focused-fabric-audit-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath $runId = "c18z104-" + (Get-Date -Format "yyyyMMdd-HHmmss") function Invoke-Api { param([string]$Method, [string]$Path, [object]$Body = $null) $params = @{ Method = $Method; Uri = "$ApiBaseUrl$Path"; TimeoutSec = 30 } if ($null -ne $Body) { $params.ContentType = "application/json" $params.Body = ($Body | ConvertTo-Json -Depth 50) } return Invoke-RestMethod @params } function Get-PropertyValue { param([object]$Item, [string]$Name, [object]$Default = $null) if ($null -eq $Item) { return $Default } $property = $Item.PSObject.Properties[$Name] if ($null -eq $property) { return $Default } return $property.Value } $checks = [ordered]@{} $backendImage = (& ssh $DockerSSH "docker inspect rap_test_backend --format '{{.Config.Image}}'").Trim() $checks.backend_expected_image_deployed = ($backendImage -eq $ExpectedBackendImage) $feedbackChannelID = "$runId-channel" $incidentRouteID = "$runId-route" $feedbackViolationStatus = "fabric_route_send_failed_degraded_route_blocked" Invoke-Api -Method POST -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents/investigations" -Body @{ actor_user_id = $ActorUserID feedback_source = "fabric_service_channel_access_report" feedback_channel_id = $feedbackChannelID feedback_violation_status = $feedbackViolationStatus drilldown_source = "rebuild_health_feedback_breakdown" reason = "synthetic c18z104 focused feedback audit" } | Out-Null Invoke-Api -Method POST -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents/investigations" -Body @{ actor_user_id = $ActorUserID reporter_node_id = "test-entry" route_id = $incidentRouteID service_class = "vpn_packets" guard_status = "bad" incident_id = "$runId-incident" reason = "synthetic c18z104 focused incident audit" } | Out-Null $eventTypes = @( "fabric.service_channel_rebuild_feedback_breakdown.investigation_opened", "fabric.service_channel_rebuild_incident.investigation_opened" ) $focusedQuery = ($eventTypes | ForEach-Object { "event_type=$([uri]::EscapeDataString($_))" }) -join "&" $focusedEvents = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/audit?actor_user_id=$ActorUserID&limit=20&$focusedQuery").audit_events $feedbackOnlyEvents = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/audit?actor_user_id=$ActorUserID&limit=20&event_type=$([uri]::EscapeDataString($eventTypes[0]))").audit_events $targetOnlyEvents = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/audit?actor_user_id=$ActorUserID&limit=20&target_type=fabric_service_channel_rebuild_feedback_breakdown").audit_events $focusedFeedback = @($focusedEvents | Where-Object { $_.event_type -eq $eventTypes[0] -and (Get-PropertyValue -Item $_.payload -Name "feedback_channel_id" -Default "") -eq $feedbackChannelID }) | Select-Object -First 1 $focusedIncident = @($focusedEvents | Where-Object { $_.event_type -eq $eventTypes[1] -and $_.target_id -eq $incidentRouteID }) | Select-Object -First 1 $feedbackOnlyMatch = @($feedbackOnlyEvents | Where-Object { $_.event_type -eq $eventTypes[0] -and (Get-PropertyValue -Item $_.payload -Name "feedback_channel_id" -Default "") -eq $feedbackChannelID }) | Select-Object -First 1 $feedbackOnlyWrongType = @($feedbackOnlyEvents | Where-Object { $_.event_type -ne $eventTypes[0] }) | Select-Object -First 1 $targetOnlyMatch = @($targetOnlyEvents | Where-Object { $_.target_type -eq "fabric_service_channel_rebuild_feedback_breakdown" -and $_.target_id -eq $feedbackChannelID }) | Select-Object -First 1 $checks.focused_query_returns_both_investigation_types = ($null -ne $focusedFeedback -and $null -ne $focusedIncident) $checks.event_type_filter_excludes_other_types = ($null -ne $feedbackOnlyMatch -and $null -eq $feedbackOnlyWrongType) $checks.target_type_filter_returns_breakdown = ($null -ne $targetOnlyMatch) $failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) $result = [ordered]@{ schema_version = "c18z104.focused_fabric_audit_smoke.v1" run_id = $runId cluster_id = $ClusterID feedback_channel_id = $feedbackChannelID incident_route_id = $incidentRouteID passed = ($failed.Count -eq 0) checks = $checks failed_checks = $failed summary = [ordered]@{ backend_image = $backendImage focused_count = @($focusedEvents).Count feedback_only_count = @($feedbackOnlyEvents).Count target_only_count = @($targetOnlyEvents).Count } } $target = Join-Path $repoRoot $ResultPath $result | ConvertTo-Json -Depth 50 | Set-Content -Path $target -Encoding UTF8 if ($failed.Count -gt 0) { throw "C18Z104 focused fabric audit smoke failed: $($failed -join ', ')" } Write-Host "C18Z104 focused fabric audit smoke passed. Result: $target" $result