149 lines
7.9 KiB
PowerShell
149 lines
7.9 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\c19z64-remote-workspace-real-adapter-admin-handoff-digest-compatibility-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
|
|
$sourceResultPath = "artifacts\c19z64-remote-workspace-real-adapter-admin-handoff-digest-source-result.json"
|
|
$requiredDigestFields = @("schema_version", "source_bundle_schema", "digest_status", "admin_status", "admin_action", "row_count", "display_rows", "guardrails")
|
|
$requiredRowFields = @("row_key", "label", "state", "value", "severity")
|
|
$expectedRows = @(
|
|
[ordered]@{ row_key = "runtime_stage"; state = "blocked"; value = "blocked_until_real_runtime_stage"; severity = "warn" },
|
|
[ordered]@{ row_key = "operator_action"; state = "required"; value = "keep_real_adapter_disabled"; severity = "info" },
|
|
[ordered]@{ row_key = "activation"; state = "blocked"; value = "blocked"; severity = "warn" },
|
|
[ordered]@{ row_key = "process_start"; state = "disabled"; value = "False"; severity = "info" },
|
|
[ordered]@{ row_key = "health_probe"; state = "disabled"; value = "False"; severity = "info" },
|
|
[ordered]@{ row_key = "payload_traffic"; state = "disabled"; value = "none"; severity = "info" },
|
|
[ordered]@{ row_key = "checklist"; state = "complete"; value = "6/6"; severity = "info" },
|
|
[ordered]@{ row_key = "actions"; state = "blocked"; value = "6 blocked"; severity = "info" }
|
|
)
|
|
|
|
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-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 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-ExpectedRow {
|
|
param([object]$Row, [object]$Expected)
|
|
if ($null -eq $Row) { return $false }
|
|
return (
|
|
(Test-ObjectHasFields -Item $Row -Fields $requiredRowFields) -and
|
|
[string](Get-PropertyValue -Item $Row -Name "row_key" -Default "") -eq [string](Get-PropertyValue -Item $Expected -Name "row_key" -Default "") -and
|
|
[string](Get-PropertyValue -Item $Row -Name "label" -Default "") -ne "" -and
|
|
[string](Get-PropertyValue -Item $Row -Name "state" -Default "") -eq [string](Get-PropertyValue -Item $Expected -Name "state" -Default "") -and
|
|
[string](Get-PropertyValue -Item $Row -Name "value" -Default "") -eq [string](Get-PropertyValue -Item $Expected -Name "value" -Default "") -and
|
|
[string](Get-PropertyValue -Item $Row -Name "severity" -Default "") -eq [string](Get-PropertyValue -Item $Expected -Name "severity" -Default "")
|
|
)
|
|
}
|
|
|
|
& powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19z63-remote-workspace-real-adapter-admin-handoff-digest-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
|
|
$digest = Get-PropertyValue -Item $sourceResult -Name "admin_handoff_digest" -Default $null
|
|
$rows = @((Get-PropertyValue -Item $digest -Name "display_rows" -Default @()))
|
|
$guardrails = Get-PropertyValue -Item $digest -Name "guardrails" -Default $null
|
|
|
|
$rowChecks = [ordered]@{}
|
|
foreach ($expected in $expectedRows) {
|
|
$key = [string](Get-PropertyValue -Item $expected -Name "row_key" -Default "")
|
|
$rowChecks[$key] = Test-ExpectedRow -Row (Get-RowByKey -Rows $rows -Key $key) -Expected $expected
|
|
}
|
|
|
|
$digestFieldsCompatible = Test-ObjectHasFields -Item $digest -Fields $requiredDigestFields
|
|
$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 $expectedRows.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)
|
|
)
|
|
|
|
$checks = [ordered]@{
|
|
source_smoke_passed = ([bool]$sourceResult.passed)
|
|
source_schema_expected = ([string]$sourceResult.schema_version -eq "c19z63.remote_workspace_real_adapter_admin_handoff_digest_smoke.v1")
|
|
digest_present = ($null -ne $digest)
|
|
digest_fields_compatible = $digestFieldsCompatible
|
|
digest_values_compatible = $digestValuesCompatible
|
|
row_count_expected = ($rows.Count -eq $expectedRows.Count)
|
|
required_row_fields_declared = ($requiredRowFields.Count -eq 5)
|
|
all_rows_compatible = (@($rowChecks.GetEnumerator() | Where-Object { -not $_.Value }).Count -eq 0)
|
|
guardrails_compatible = $guardrailsCompatible
|
|
}
|
|
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c19z64.remote_workspace_real_adapter_admin_handoff_digest_compatibility_smoke.v1"
|
|
source_result_path = $sourceFile
|
|
cluster_id = $ClusterID
|
|
required_digest_fields = $requiredDigestFields
|
|
required_row_fields = $requiredRowFields
|
|
expected_rows = $expectedRows
|
|
row_checks = $rowChecks
|
|
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 "C19Z64 remote workspace real-adapter admin handoff digest compatibility smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
|
|
}
|
|
|
|
Write-Host "C19Z64 remote workspace real-adapter admin handoff digest compatibility smoke passed. Result: $fullResultPath"
|
|
$result
|