Files
rdp-proxy/scripts/fabric/c19z53-remote-workspace-real-adapter-process-health-probe-compatibility-smoke.ps1
2026-05-14 23:30:34 +03:00

135 lines
5.8 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]$RequestedNodeName = "test-1",
[string]$DefaultNodeName = "test-2",
[string]$ResultPath = "artifacts\c19z53-remote-workspace-real-adapter-process-health-probe-compatibility-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
$sourceResultPath = "artifacts\c19z53-remote-workspace-real-adapter-process-health-probe-source-result.json"
$requiredSignals = @(
"process_started",
"process_exit_status",
"adapter_control_channel_ready",
"fabric_service_channel_bound",
"payload_forwarding_contract_ready"
)
$requiredFields = @(
"schema_version",
"health_probe_enabled",
"reason",
"payload_traffic",
"probe_model",
"required_signals",
"missing_signals"
)
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
}
function Test-ArrayItem {
param([object]$Items, [string]$Want)
foreach ($item in @($Items)) {
if ([string]$item -eq $Want) { return $true }
}
return $false
}
function Test-RequiredItems {
param([object]$Items, [string[]]$Required)
foreach ($item in $Required) {
if (-not (Test-ArrayItem -Items $Items -Want $item)) { return $false }
}
return $true
}
function Test-RequiredFields {
param([object]$Item)
if ($null -eq $Item) { return $false }
foreach ($field in $requiredFields) {
if ($null -eq $Item.PSObject.Properties[$field]) { return $false }
}
return $true
}
function Test-HealthProbeContract {
param([object]$HealthProbe)
if ($null -eq $HealthProbe) { return $false }
return (
(Test-RequiredFields -Item $HealthProbe) -and
[string](Get-PropertyValue -Item $HealthProbe -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_process_health_probe.v1" -and
-not [bool](Get-PropertyValue -Item $HealthProbe -Name "health_probe_enabled" -Default $true) -and
[string](Get-PropertyValue -Item $HealthProbe -Name "reason" -Default "") -eq "disabled_until_real_runtime_stage" -and
[string](Get-PropertyValue -Item $HealthProbe -Name "payload_traffic" -Default "") -eq "none" -and
[string](Get-PropertyValue -Item $HealthProbe -Name "probe_model" -Default "") -eq "external_process_health" -and
(Test-RequiredItems -Items (Get-PropertyValue -Item $HealthProbe -Name "required_signals" -Default @()) -Required $requiredSignals) -and
(Test-RequiredItems -Items (Get-PropertyValue -Item $HealthProbe -Name "missing_signals" -Default @()) -Required $requiredSignals)
)
}
& powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19z52-remote-workspace-real-adapter-process-health-probe-smoke.ps1") `
-ApiBaseUrl $ApiBaseUrl `
-ClusterID $ClusterID `
-ActorUserID $ActorUserID `
-RequestedNodeName $RequestedNodeName `
-DefaultNodeName $DefaultNodeName `
-ResultPath $sourceResultPath | Out-Null
$sourceFile = Join-Path $repoRoot $sourceResultPath
$sourceResult = Get-Content -Raw -Path $sourceFile | ConvertFrom-Json
$requestedHealthProbe = Get-PropertyValue -Item $sourceResult -Name "requested_health_probe" -Default $null
$defaultHealthProbe = Get-PropertyValue -Item $sourceResult -Name "default_health_probe" -Default $null
$checks = [ordered]@{
source_smoke_passed = ([bool]$sourceResult.passed)
source_schema_expected = ([string]$sourceResult.schema_version -eq "c19z52.remote_workspace_real_adapter_process_health_probe_smoke.v1")
requested_contract_compatible = (Test-HealthProbeContract -HealthProbe $requestedHealthProbe)
default_contract_compatible = (Test-HealthProbeContract -HealthProbe $defaultHealthProbe)
health_probe_disabled_in_both = (
-not [bool](Get-PropertyValue -Item $requestedHealthProbe -Name "health_probe_enabled" -Default $true) -and
-not [bool](Get-PropertyValue -Item $defaultHealthProbe -Name "health_probe_enabled" -Default $true)
)
payload_traffic_none_in_both = (
[string](Get-PropertyValue -Item $requestedHealthProbe -Name "payload_traffic" -Default "") -eq "none" -and
[string](Get-PropertyValue -Item $defaultHealthProbe -Name "payload_traffic" -Default "") -eq "none"
)
required_fields_declared = ($requiredFields.Count -eq 7)
required_signals_declared = ($requiredSignals.Count -eq 5)
}
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c19z53.remote_workspace_real_adapter_process_health_probe_compatibility_smoke.v1"
source_result_path = $sourceFile
cluster_id = $ClusterID
required_fields = $requiredFields
required_signals = $requiredSignals
requested_health_probe = $requestedHealthProbe
default_health_probe = $defaultHealthProbe
checks = $checks
failed_checks = $failed
passed = ($failed.Count -eq 0)
}
$fullResultPath = Join-Path $repoRoot $ResultPath
$resultDir = Split-Path -Parent $fullResultPath
if ($resultDir) { New-Item -ItemType Directory -Force -Path $resultDir | Out-Null }
$result | ConvertTo-Json -Depth 100 | Set-Content -Encoding UTF8 -Path $fullResultPath
if (-not $result.passed) {
throw "C19Z53 remote workspace real-adapter process health probe compatibility smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
}
Write-Host "C19Z53 remote workspace real-adapter process health probe compatibility smoke passed. Result: $fullResultPath"
$result