Files
rdp-proxy/scripts/fabric/c19z63-remote-workspace-real-adapter-admin-handoff-digest-smoke.ps1
2026-05-14 23:30:34 +03:00

194 lines
9.5 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]$MatrixNodeName = "test-1",
[string]$ResultPath = "artifacts\c19z63-remote-workspace-real-adapter-admin-handoff-digest-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
$sourceResultPath = "artifacts\c19z63-remote-workspace-real-adapter-admin-handoff-digest-source-result.json"
$requiredDigestRows = @(
"runtime_stage",
"operator_action",
"activation",
"process_start",
"health_probe",
"payload_traffic",
"checklist",
"actions"
)
$requiredRowFields = @("row_key", "label", "state", "value", "severity")
function Get-PropertyValue {
param([object]$Item, [string]$Name, [object]$Default = $null)
if ($null -eq $Item) { return $Default }
if ($Item -is [System.Collections.IDictionary]) {
if ($Item.Contains($Name)) { return $Item[$Name] }
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 Get-RowByKey {
param([object[]]$Rows, [string]$Key)
return @($Rows | Where-Object { [string](Get-PropertyValue -Item $_ -Name "row_key" -Default "") -eq $Key } | Select-Object -First 1)
}
function Test-ObjectHasFields {
param([object]$Item, [string[]]$Fields)
if ($null -eq $Item) { return $false }
foreach ($field in $Fields) {
if ($Item -is [System.Collections.IDictionary]) {
if (-not $Item.Contains($field)) { return $false }
continue
}
if ($null -eq $Item.PSObject.Properties[$field]) { return $false }
}
return $true
}
function Test-RowsHaveFields {
param([object[]]$Rows)
if ($Rows.Count -eq 0) { return $false }
foreach ($row in $Rows) {
if (-not (Test-ObjectHasFields -Item $row -Fields $requiredRowFields)) { return $false }
}
return $true
}
function Test-RequiredRows {
param([object[]]$Rows)
foreach ($key in $requiredDigestRows) {
if ($null -eq (Get-RowByKey -Rows $Rows -Key $key)) { return $false }
}
return $true
}
function New-DigestRow {
param([string]$Key, [string]$Label, [string]$State, [string]$Value, [string]$Severity)
return [ordered]@{
row_key = $Key
label = $Label
state = $State
value = $Value
severity = $Severity
}
}
& powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19z62-remote-workspace-real-adapter-admin-handoff-bundle-compatibility-smoke.ps1") `
-ApiBaseUrl $ApiBaseUrl `
-ClusterID $ClusterID `
-ActorUserID $ActorUserID `
-RequestedNodeName $RequestedNodeName `
-DefaultNodeName $DefaultNodeName `
-MatrixNodeName $MatrixNodeName `
-ResultPath $sourceResultPath | Out-Null
$sourceFile = Join-Path $repoRoot $sourceResultPath
$sourceResult = Get-Content -Raw -Path $sourceFile | ConvertFrom-Json
$bundle = Get-PropertyValue -Item $sourceResult -Name "admin_handoff_bundle" -Default $null
$summary = Get-PropertyValue -Item $bundle -Name "readiness_summary" -Default $null
$counts = Get-PropertyValue -Item $bundle -Name "counts" -Default $null
$guardrails = Get-PropertyValue -Item $bundle -Name "guardrails" -Default $null
$actionMap = Get-PropertyValue -Item $bundle -Name "operator_action_map" -Default $null
$rows = @(
(New-DigestRow -Key "runtime_stage" -Label "Runtime stage" -State "blocked" -Value ([string](Get-PropertyValue -Item $summary -Name "readiness_state" -Default "")) -Severity "warn"),
(New-DigestRow -Key "operator_action" -Label "Operator action" -State "required" -Value ([string](Get-PropertyValue -Item $bundle -Name "admin_action" -Default "")) -Severity "info"),
(New-DigestRow -Key "activation" -Label "Activation" -State "blocked" -Value ([string](Get-PropertyValue -Item $summary -Name "activation_decision" -Default "")) -Severity "warn"),
(New-DigestRow -Key "process_start" -Label "Process start" -State "disabled" -Value ([string](Get-PropertyValue -Item $summary -Name "process_start_allowed" -Default "")) -Severity "info"),
(New-DigestRow -Key "health_probe" -Label "Health probe" -State "disabled" -Value ([string](Get-PropertyValue -Item $summary -Name "health_probe_enabled" -Default "")) -Severity "info"),
(New-DigestRow -Key "payload_traffic" -Label "Payload traffic" -State "disabled" -Value ([string](Get-PropertyValue -Item $summary -Name "payload_traffic" -Default "")) -Severity "info"),
(New-DigestRow -Key "checklist" -Label "Checklist" -State "complete" -Value ("{0}/{1}" -f (Get-PropertyValue -Item $counts -Name "checklist_passed_count" -Default 0), (Get-PropertyValue -Item $counts -Name "checklist_total_count" -Default 0)) -Severity "info"),
(New-DigestRow -Key "actions" -Label "Actions" -State "blocked" -Value ("{0} blocked" -f (Get-PropertyValue -Item $counts -Name "blocked_action_count" -Default 0)) -Severity "info")
)
$digest = [ordered]@{
schema_version = "rap.remote_workspace_real_adapter_admin_handoff_digest.v1"
source_bundle_schema = Get-PropertyValue -Item $bundle -Name "schema_version" -Default $null
digest_status = "complete"
admin_status = Get-PropertyValue -Item $bundle -Name "admin_status" -Default $null
admin_action = Get-PropertyValue -Item $bundle -Name "admin_action" -Default $null
row_count = $rows.Count
display_rows = $rows
guardrails = $guardrails
}
$rowsHaveFields = Test-RowsHaveFields -Rows $rows
$rowsPresent = Test-RequiredRows -Rows $rows
$digestValuesCompatible = (
[string](Get-PropertyValue -Item $digest -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_admin_handoff_digest.v1" -and
[string](Get-PropertyValue -Item $digest -Name "source_bundle_schema" -Default "") -eq "rap.remote_workspace_real_adapter_admin_handoff_bundle.v1" -and
[string](Get-PropertyValue -Item $digest -Name "digest_status" -Default "") -eq "complete" -and
[string](Get-PropertyValue -Item $digest -Name "admin_status" -Default "") -eq "not_ready" -and
[string](Get-PropertyValue -Item $digest -Name "admin_action" -Default "") -eq "keep_real_adapter_disabled" -and
[int](Get-PropertyValue -Item $digest -Name "row_count" -Default -1) -eq $requiredDigestRows.Count
)
$guardrailsCompatible = (
[bool](Get-PropertyValue -Item $guardrails -Name "activation_blocked" -Default $false) -and
-not [bool](Get-PropertyValue -Item $guardrails -Name "process_start_allowed" -Default $true) -and
-not [bool](Get-PropertyValue -Item $guardrails -Name "health_probe_enabled" -Default $true) -and
[string](Get-PropertyValue -Item $guardrails -Name "payload_traffic" -Default "") -eq "none" -and
-not [bool](Get-PropertyValue -Item $guardrails -Name "allows_payload_traffic" -Default $true) -and
-not [bool](Get-PropertyValue -Item $guardrails -Name "allows_process_start" -Default $true)
)
$rowValuesCompatible = (
[string](Get-PropertyValue -Item (Get-RowByKey -Rows $rows -Key "runtime_stage") -Name "value" -Default "") -eq "blocked_until_real_runtime_stage" -and
[string](Get-PropertyValue -Item (Get-RowByKey -Rows $rows -Key "operator_action") -Name "value" -Default "") -eq "keep_real_adapter_disabled" -and
[string](Get-PropertyValue -Item (Get-RowByKey -Rows $rows -Key "activation") -Name "value" -Default "") -eq "blocked" -and
[string](Get-PropertyValue -Item (Get-RowByKey -Rows $rows -Key "process_start") -Name "value" -Default "") -eq "False" -and
[string](Get-PropertyValue -Item (Get-RowByKey -Rows $rows -Key "health_probe") -Name "value" -Default "") -eq "False" -and
[string](Get-PropertyValue -Item (Get-RowByKey -Rows $rows -Key "payload_traffic") -Name "value" -Default "") -eq "none"
)
$checks = [ordered]@{
source_smoke_passed = ([bool]$sourceResult.passed)
source_schema_expected = ([string]$sourceResult.schema_version -eq "c19z62.remote_workspace_real_adapter_admin_handoff_bundle_compatibility_smoke.v1")
digest_values_compatible = $digestValuesCompatible
rows_have_fields = $rowsHaveFields
required_rows_present = $rowsPresent
row_values_compatible = $rowValuesCompatible
guardrails_compatible = $guardrailsCompatible
}
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c19z63.remote_workspace_real_adapter_admin_handoff_digest_smoke.v1"
source_result_path = $sourceFile
cluster_id = $ClusterID
required_digest_rows = $requiredDigestRows
required_row_fields = $requiredRowFields
admin_handoff_digest = $digest
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 "C19Z63 remote workspace real-adapter admin handoff digest smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
}
Write-Host "C19Z63 remote workspace real-adapter admin handoff digest smoke passed. Result: $fullResultPath"
$result