Files
rdp-proxy/scripts/fabric/c19z51-remote-workspace-real-adapter-mode-matrix-v2-compatibility-smoke.ps1
2026-05-14 23:30:34 +03:00

127 lines
6.1 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]$NodeName = "test-1",
[string]$ResultPath = "artifacts\c19z51-remote-workspace-real-adapter-mode-matrix-v2-compatibility-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
$sourceResultPath = "artifacts\c19z51-remote-workspace-real-adapter-mode-matrix-v2-source-result.json"
$requiredRowFields = @(
"mode",
"adapter_contract_probe",
"real_adapter_supervision",
"reported_state",
"execution_mode",
"traffic",
"payload_traffic",
"activation_decision",
"activation_allowed",
"process_start_allowed",
"preconditions_visible",
"missing_checks_visible",
"process_start_disabled_feature",
"passed"
)
$expectedRows = @(
[ordered]@{ mode = "probe_only"; adapter_contract_probe = $true; real_adapter_supervision = $false; reported_state = "running"; execution_mode = "contract_probe"; traffic = "none" },
[ordered]@{ mode = "real_adapter_only"; adapter_contract_probe = $false; real_adapter_supervision = $true; reported_state = "degraded"; execution_mode = "real_adapter_supervision_disabled"; traffic = "blocked" },
[ordered]@{ mode = "probe_and_real_adapter"; adapter_contract_probe = $true; real_adapter_supervision = $true; reported_state = "running"; execution_mode = "contract_probe"; traffic = "none" }
)
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-RowHasFields {
param([object]$Row)
foreach ($field in $requiredRowFields) {
if ($null -eq $Row.PSObject.Properties[$field]) { return $false }
}
return $true
}
function Get-RowByMode {
param([object[]]$Rows, [string]$Mode)
return @($Rows | Where-Object { [string](Get-PropertyValue -Item $_ -Name "mode" -Default "") -eq $Mode } | Select-Object -First 1)
}
function Test-ExpectedRow {
param([object]$Row, [object]$Expected)
if ($null -eq $Row) { return $false }
return (
(Test-RowHasFields -Row $Row) -and
[bool](Get-PropertyValue -Item $Row -Name "adapter_contract_probe" -Default (-not [bool]$Expected.adapter_contract_probe)) -eq [bool]$Expected.adapter_contract_probe -and
[bool](Get-PropertyValue -Item $Row -Name "real_adapter_supervision" -Default (-not [bool]$Expected.real_adapter_supervision)) -eq [bool]$Expected.real_adapter_supervision -and
[string](Get-PropertyValue -Item $Row -Name "reported_state" -Default "") -eq [string]$Expected.reported_state -and
[string](Get-PropertyValue -Item $Row -Name "execution_mode" -Default "") -eq [string]$Expected.execution_mode -and
[string](Get-PropertyValue -Item $Row -Name "traffic" -Default "") -eq [string]$Expected.traffic -and
[string](Get-PropertyValue -Item $Row -Name "payload_traffic" -Default "") -eq "none" -and
[string](Get-PropertyValue -Item $Row -Name "activation_decision" -Default "") -eq "blocked" -and
-not [bool](Get-PropertyValue -Item $Row -Name "activation_allowed" -Default $true) -and
-not [bool](Get-PropertyValue -Item $Row -Name "process_start_allowed" -Default $true) -and
[bool](Get-PropertyValue -Item $Row -Name "preconditions_visible" -Default $false) -and
[bool](Get-PropertyValue -Item $Row -Name "missing_checks_visible" -Default $false) -and
[bool](Get-PropertyValue -Item $Row -Name "process_start_disabled_feature" -Default $false) -and
[bool](Get-PropertyValue -Item $Row -Name "passed" -Default $false)
)
}
& powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19z50-remote-workspace-real-adapter-mode-matrix-v2-smoke.ps1") `
-ApiBaseUrl $ApiBaseUrl `
-ClusterID $ClusterID `
-ActorUserID $ActorUserID `
-NodeName $NodeName `
-ResultPath $sourceResultPath | Out-Null
$sourceFile = Join-Path $repoRoot $sourceResultPath
$sourceResult = Get-Content -Raw -Path $sourceFile | ConvertFrom-Json
$rows = @($sourceResult.matrix_rows)
$rowChecks = [ordered]@{}
foreach ($expected in $expectedRows) {
$mode = [string]$expected.mode
$rowChecks[$mode] = Test-ExpectedRow -Row (Get-RowByMode -Rows $rows -Mode $mode) -Expected $expected
}
$checks = [ordered]@{
source_smoke_passed = ([bool]$sourceResult.passed)
source_schema_expected = ([string]$sourceResult.schema_version -eq "c19z50.remote_workspace_real_adapter_mode_matrix_v2_smoke.v1")
row_count_three = ($rows.Count -eq 3)
required_fields_declared = ($requiredRowFields.Count -eq 14)
all_expected_modes_present = ((Get-RowByMode -Rows $rows -Mode "probe_only") -and (Get-RowByMode -Rows $rows -Mode "real_adapter_only") -and (Get-RowByMode -Rows $rows -Mode "probe_and_real_adapter"))
all_rows_compatible = (@($rowChecks.GetEnumerator() | Where-Object { -not $_.Value }).Count -eq 0)
}
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c19z51.remote_workspace_real_adapter_mode_matrix_v2_compatibility_smoke.v1"
source_result_path = $sourceFile
cluster_id = $ClusterID
required_row_fields = $requiredRowFields
row_checks = $rowChecks
matrix_rows = $rows
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 "C19Z51 remote workspace real-adapter mode matrix v2 compatibility smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
}
Write-Host "C19Z51 remote workspace real-adapter mode matrix v2 compatibility smoke passed. Result: $fullResultPath"
$result