Files
rdp-proxy/scripts/fabric/c18z30-node-agent-feedback-provenance-smoke.ps1
T
2026-05-12 21:02:29 +03:00

97 lines
4.7 KiB
PowerShell

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]$NodeID = "108a0d66-d65e-4dea-b9a8-135366bf7dba",
[string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.209",
[string]$ExpectedNodeAgentImage = "rap-node-agent:0.2.208",
[string]$DockerSSH = "test-docker",
[string]$ResultPath = "artifacts\c18z30-node-agent-feedback-provenance-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"
}
$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
$heartbeat = (Invoke-Api -Path "/clusters/$ClusterID/nodes/$NodeID/heartbeats?actor_user_id=$ActorUserID&limit=1").heartbeats[0]
$runtime = $heartbeat.metadata.fabric_service_channel_runtime_report
$channelStats = @()
if ($null -ne $runtime.ingress.flow_scheduler.channel_stats) {
$channelStats = @($runtime.ingress.flow_scheduler.channel_stats.PSObject.Properties | ForEach-Object { $_.Value })
}
$runtimeProvenance = @($channelStats | Where-Object {
$_.recovery_policy_fingerprint -and $_.route_policy_version -and $_.route_generation
})
$feedback = (Invoke-Api -Path "/clusters/$ClusterID/nodes/$NodeID/mesh/synthetic-config?actor_user_id=$ActorUserID").synthetic_mesh_config.service_channel_route_feedback
$observations = @()
if ($null -ne $feedback.observations) {
$observations = @($feedback.observations)
}
$feedbackWithProvenance = @($observations | Where-Object {
$_.payload.recovery_policy_fingerprint -and $_.payload.route_policy_version -and $_.payload.route_generation
})
$missing = if ($feedback.PSObject.Properties["missing_provenance_count"]) { [int]$feedback.missing_provenance_count } else { 0 }
$stalePolicy = if ($feedback.PSObject.Properties["stale_policy_count"]) { [int]$feedback.stale_policy_count } else { 0 }
$staleGeneration = if ($feedback.PSObject.Properties["stale_generation_count"]) { [int]$feedback.stale_generation_count } else { 0 }
$result = [ordered]@{
schema_version = "c18z30.node_agent_feedback_provenance_smoke.v1"
passed = [bool](
$backendLine.Contains($ExpectedBackendImage) -and
$nodeLines.Contains($ExpectedNodeAgentImage) -and
[string]$heartbeat.reported_version -eq "0.2.208" -and
$channelStats.Count -gt 0 -and
$runtimeProvenance.Count -eq $channelStats.Count -and
$observations.Count -gt 0 -and
$feedbackWithProvenance.Count -eq $observations.Count -and
$missing -eq 0 -and
$stalePolicy -eq 0 -and
$staleGeneration -eq 0
)
checks = [ordered]@{
backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage)
node_agent_expected_image_deployed = $nodeLines.Contains($ExpectedNodeAgentImage)
heartbeat_reported_expected_version = ([string]$heartbeat.reported_version -eq "0.2.208")
runtime_channel_stats_have_provenance = ($channelStats.Count -gt 0 -and $runtimeProvenance.Count -eq $channelStats.Count)
feedback_observations_have_provenance = ($observations.Count -gt 0 -and $feedbackWithProvenance.Count -eq $observations.Count)
feedback_provenance_is_current = ($missing -eq 0 -and $stalePolicy -eq 0 -and $staleGeneration -eq 0)
}
summary = [ordered]@{
backend_container = $backendLine.Trim()
node_containers = $nodeLines.Trim()
heartbeat_version = $heartbeat.reported_version
runtime_channel_stats = $channelStats.Count
runtime_provenance_channel_stats = $runtimeProvenance.Count
feedback_observations = $observations.Count
feedback_observations_with_provenance = $feedbackWithProvenance.Count
feedback_counts = [ordered]@{
missing_provenance = $missing
stale_policy = $stalePolicy
stale_generation = $staleGeneration
}
sample_feedback = ($feedbackWithProvenance | Select-Object -First 1)
}
}
$resolvedResultPath = Join-Path $repoRoot $ResultPath
$result | ConvertTo-Json -Depth 100 | Set-Content -Path $resolvedResultPath -Encoding UTF8
if (-not $result.passed) {
throw "C18Z30 node-agent feedback provenance smoke failed. Result: $resolvedResultPath"
}
Write-Host "C18Z30 node-agent feedback provenance smoke passed. Result: $resolvedResultPath"
$result