1
This commit is contained in:
@@ -0,0 +1,256 @@
|
||||
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\c19z54-remote-workspace-real-adapter-handoff-v4-smoke-result.json"
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
|
||||
$runId = "c19z54-" + (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||
$requiredEnv = @(
|
||||
"RAP_REMOTE_WORKSPACE_REAL_ADAPTER_ENABLED",
|
||||
"RAP_REMOTE_WORKSPACE_REAL_ADAPTER_COMMAND",
|
||||
"RAP_REMOTE_WORKSPACE_REAL_ADAPTER_ARGS_JSON",
|
||||
"RAP_REMOTE_WORKSPACE_REAL_ADAPTER_WORKDIR"
|
||||
)
|
||||
$requiredGates = @(
|
||||
"real_runtime_stage_enabled",
|
||||
"fabric_service_channel_runtime_ready",
|
||||
"adapter_process_supervisor_enabled",
|
||||
"payload_forwarding_contract_enabled"
|
||||
)
|
||||
$requiredPreconditionChecks = @(
|
||||
"real_runtime_stage_enabled",
|
||||
"command_config_validated",
|
||||
"workdir_config_validated",
|
||||
"process_identity_policy_bound",
|
||||
"fabric_service_channel_runtime_ready",
|
||||
"payload_forwarding_contract_enabled",
|
||||
"health_probe_contract_enabled"
|
||||
)
|
||||
$requiredHealthSignals = @(
|
||||
"process_started",
|
||||
"process_exit_status",
|
||||
"adapter_control_channel_ready",
|
||||
"fabric_service_channel_bound",
|
||||
"payload_forwarding_contract_ready"
|
||||
)
|
||||
$requiredFeatures = @(
|
||||
"config_projection",
|
||||
"activation_decision",
|
||||
"missing_gates",
|
||||
"process_supervisor_preconditions",
|
||||
"process_supervisor_start_disabled",
|
||||
"process_health_probe",
|
||||
"process_health_probe_disabled",
|
||||
"raw_values_redacted"
|
||||
)
|
||||
|
||||
function Invoke-Api {
|
||||
param([string]$Method, [string]$Path, [object]$Body = $null)
|
||||
if ($null -eq $Body) { return Invoke-RestMethod -Method $Method -Uri "$ApiBaseUrl$Path" -TimeoutSec 30 }
|
||||
return Invoke-RestMethod -Method $Method -Uri "$ApiBaseUrl$Path" -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 80) -TimeoutSec 30
|
||||
}
|
||||
|
||||
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-FeatureMap {
|
||||
param([object]$Features)
|
||||
if ($null -eq $Features) { return $false }
|
||||
foreach ($feature in $requiredFeatures) {
|
||||
if (-not [bool](Get-PropertyValue -Item $Features -Name $feature -Default $false)) { return $false }
|
||||
}
|
||||
return $true
|
||||
}
|
||||
|
||||
function Get-NodeByName {
|
||||
param([string]$Name)
|
||||
$nodes = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes?actor_user_id=$ActorUserID").nodes
|
||||
$node = @($nodes | Where-Object { $_.name -eq $Name }) | Select-Object -First 1
|
||||
if ($null -eq $node) { throw "Node '$Name' was not found in cluster $ClusterID" }
|
||||
return $node
|
||||
}
|
||||
|
||||
function Enable-RdpWorkerProbe {
|
||||
param([object]$Node)
|
||||
Invoke-Api -Method PUT -Path "/clusters/$ClusterID/nodes/$($Node.id)/workloads/rdp-worker/desired" -Body @{
|
||||
actor_user_id = $ActorUserID
|
||||
desired_state = "enabled"
|
||||
version = "c19z54-real-adapter-handoff-v4-$runId"
|
||||
runtime_mode = "native"
|
||||
artifact_ref = "builtin:rdp-worker-adapter-contract-probe"
|
||||
config = @{ adapter_contract_probe = $true; service_class = "remote_workspace"; run_id = $runId }
|
||||
environment = @{}
|
||||
} | Out-Null
|
||||
}
|
||||
|
||||
function Get-RdpWorkerStatus {
|
||||
param([string]$NodeID)
|
||||
$statuses = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/workloads/status?actor_user_id=$ActorUserID").workload_statuses
|
||||
return @($statuses | Where-Object { $_.service_type -eq "rdp-worker" } | Select-Object -First 1)
|
||||
}
|
||||
|
||||
function New-HandoffRow {
|
||||
param([object]$Node, [object]$Status, [bool]$ExpectedEnabledRequested, [string]$ExpectedArgsShape, [bool]$ExpectedConfigPresent)
|
||||
$payload = Get-PropertyValue -Item $Status -Name "status_payload" -Default $null
|
||||
$contract = Get-PropertyValue -Item $payload -Name "real_adapter_supervision" -Default $null
|
||||
$projection = Get-PropertyValue -Item $contract -Name "config_projection" -Default $null
|
||||
$decision = Get-PropertyValue -Item $contract -Name "activation_decision" -Default $null
|
||||
$preconditions = Get-PropertyValue -Item $contract -Name "process_supervisor_preconditions" -Default $null
|
||||
$health = Get-PropertyValue -Item $contract -Name "process_health_probe" -Default $null
|
||||
$features = Get-PropertyValue -Item $contract -Name "features" -Default $null
|
||||
$statusContract = Get-PropertyValue -Item $contract -Name "status_contract" -Default @()
|
||||
|
||||
$enabledRequested = [bool](Get-PropertyValue -Item $projection -Name "enabled_requested" -Default $false)
|
||||
$decisionEnabledRequested = [bool](Get-PropertyValue -Item $decision -Name "enabled_requested" -Default (-not $enabledRequested))
|
||||
|
||||
$contractCompatible = (
|
||||
[string](Get-PropertyValue -Item $contract -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_supervision.v1" -and
|
||||
-not [bool](Get-PropertyValue -Item $contract -Name "enabled" -Default $true) -and
|
||||
[string](Get-PropertyValue -Item $contract -Name "payload_traffic" -Default "") -eq "none" -and
|
||||
(Test-RequiredItems -Items (Get-PropertyValue -Item $contract -Name "config_env" -Default @()) -Required $requiredEnv) -and
|
||||
(Test-ArrayItem -Items $statusContract -Want "process_health_probe")
|
||||
)
|
||||
$projectionCompatible = (
|
||||
[string](Get-PropertyValue -Item $projection -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_config_projection.v1" -and
|
||||
$enabledRequested -eq $ExpectedEnabledRequested -and
|
||||
-not [bool](Get-PropertyValue -Item $projection -Name "activation_allowed" -Default $true) -and
|
||||
[string](Get-PropertyValue -Item $projection -Name "args_json_shape" -Default "") -eq $ExpectedArgsShape -and
|
||||
[bool](Get-PropertyValue -Item $projection -Name "raw_values_redacted" -Default $false)
|
||||
)
|
||||
$decisionCompatible = (
|
||||
[string](Get-PropertyValue -Item $decision -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_activation_decision.v1" -and
|
||||
[string](Get-PropertyValue -Item $decision -Name "decision" -Default "") -eq "blocked" -and
|
||||
$decisionEnabledRequested -eq $ExpectedEnabledRequested -and
|
||||
-not [bool](Get-PropertyValue -Item $decision -Name "activation_allowed" -Default $true) -and
|
||||
[string](Get-PropertyValue -Item $decision -Name "payload_traffic" -Default "") -eq "none" -and
|
||||
(Test-RequiredItems -Items (Get-PropertyValue -Item $decision -Name "missing_gates" -Default @()) -Required $requiredGates)
|
||||
)
|
||||
$preconditionsCompatible = (
|
||||
[string](Get-PropertyValue -Item $preconditions -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_process_supervisor_preconditions.v1" -and
|
||||
-not [bool](Get-PropertyValue -Item $preconditions -Name "process_start_allowed" -Default $true) -and
|
||||
[bool](Get-PropertyValue -Item $preconditions -Name "command_config_present" -Default (-not $ExpectedConfigPresent)) -eq $ExpectedConfigPresent -and
|
||||
[bool](Get-PropertyValue -Item $preconditions -Name "args_config_present" -Default (-not $ExpectedConfigPresent)) -eq $ExpectedConfigPresent -and
|
||||
[bool](Get-PropertyValue -Item $preconditions -Name "workdir_config_present" -Default (-not $ExpectedConfigPresent)) -eq $ExpectedConfigPresent -and
|
||||
(Test-RequiredItems -Items (Get-PropertyValue -Item $preconditions -Name "missing_checks" -Default @()) -Required $requiredPreconditionChecks)
|
||||
)
|
||||
$healthCompatible = (
|
||||
[string](Get-PropertyValue -Item $health -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_process_health_probe.v1" -and
|
||||
-not [bool](Get-PropertyValue -Item $health -Name "health_probe_enabled" -Default $true) -and
|
||||
[string](Get-PropertyValue -Item $health -Name "payload_traffic" -Default "") -eq "none" -and
|
||||
(Test-RequiredItems -Items (Get-PropertyValue -Item $health -Name "missing_signals" -Default @()) -Required $requiredHealthSignals)
|
||||
)
|
||||
$featuresCompatible = Test-FeatureMap -Features $features
|
||||
$aligned = (
|
||||
$enabledRequested -eq $decisionEnabledRequested -and
|
||||
[bool](Get-PropertyValue -Item $features -Name "process_health_probe" -Default $false) -eq ($null -ne $health) -and
|
||||
-not [bool](Get-PropertyValue -Item $preconditions -Name "process_start_allowed" -Default $true) -and
|
||||
-not [bool](Get-PropertyValue -Item $health -Name "health_probe_enabled" -Default $true) -and
|
||||
[string](Get-PropertyValue -Item $contract -Name "payload_traffic" -Default "") -eq [string](Get-PropertyValue -Item $decision -Name "payload_traffic" -Default "") -and
|
||||
[string](Get-PropertyValue -Item $health -Name "payload_traffic" -Default "") -eq "none"
|
||||
)
|
||||
|
||||
return [ordered]@{
|
||||
node_id = $Node.id
|
||||
node_name = $Node.name
|
||||
reported_state = Get-PropertyValue -Item $Status -Name "reported_state" -Default $null
|
||||
execution_mode = Get-PropertyValue -Item $payload -Name "execution_mode" -Default $null
|
||||
enabled_requested = $enabledRequested
|
||||
args_json_shape = Get-PropertyValue -Item $projection -Name "args_json_shape" -Default $null
|
||||
activation_decision = Get-PropertyValue -Item $decision -Name "decision" -Default $null
|
||||
process_start_allowed = Get-PropertyValue -Item $preconditions -Name "process_start_allowed" -Default $null
|
||||
health_probe_enabled = Get-PropertyValue -Item $health -Name "health_probe_enabled" -Default $null
|
||||
health_missing_signals = Get-PropertyValue -Item $health -Name "missing_signals" -Default @()
|
||||
contract_compatible = $contractCompatible
|
||||
projection_compatible = $projectionCompatible
|
||||
decision_compatible = $decisionCompatible
|
||||
features_compatible = $featuresCompatible
|
||||
preconditions_compatible = $preconditionsCompatible
|
||||
health_probe_compatible = $healthCompatible
|
||||
all_contracts_aligned = $aligned
|
||||
passed = ($contractCompatible -and $projectionCompatible -and $decisionCompatible -and $featuresCompatible -and $preconditionsCompatible -and $healthCompatible -and $aligned)
|
||||
}
|
||||
}
|
||||
|
||||
$requestedNode = Get-NodeByName -Name $RequestedNodeName
|
||||
$defaultNode = Get-NodeByName -Name $DefaultNodeName
|
||||
Enable-RdpWorkerProbe -Node $requestedNode
|
||||
Enable-RdpWorkerProbe -Node $defaultNode
|
||||
|
||||
$requestedStatus = $null
|
||||
$defaultStatus = $null
|
||||
$rows = @()
|
||||
$deadline = (Get-Date).AddSeconds(80)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
Start-Sleep -Seconds 5
|
||||
$requestedStatus = Get-RdpWorkerStatus -NodeID $requestedNode.id
|
||||
$defaultStatus = Get-RdpWorkerStatus -NodeID $defaultNode.id
|
||||
if ($null -ne $requestedStatus -and $null -ne $defaultStatus) {
|
||||
$rows = @(
|
||||
(New-HandoffRow -Node $requestedNode -Status $requestedStatus -ExpectedEnabledRequested $true -ExpectedArgsShape "json_array" -ExpectedConfigPresent $true),
|
||||
(New-HandoffRow -Node $defaultNode -Status $defaultStatus -ExpectedEnabledRequested $false -ExpectedArgsShape "absent" -ExpectedConfigPresent $false)
|
||||
)
|
||||
if (@($rows | Where-Object { -not $_.passed }).Count -eq 0) { break }
|
||||
}
|
||||
}
|
||||
|
||||
$checks = [ordered]@{
|
||||
requested_status_present = ($null -ne $requestedStatus)
|
||||
default_status_present = ($null -ne $defaultStatus)
|
||||
handoff_rows_present = ($rows.Count -eq 2)
|
||||
all_rows_passed = (@($rows | Where-Object { -not $_.passed }).Count -eq 0)
|
||||
}
|
||||
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
||||
|
||||
$result = [ordered]@{
|
||||
schema_version = "c19z54.remote_workspace_real_adapter_handoff_v4_smoke.v1"
|
||||
cluster_id = $ClusterID
|
||||
required_env = $requiredEnv
|
||||
required_gates = $requiredGates
|
||||
required_precondition_checks = $requiredPreconditionChecks
|
||||
required_health_signals = $requiredHealthSignals
|
||||
required_features = $requiredFeatures
|
||||
handoff_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 "C19Z54 remote workspace real-adapter handoff v4 smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
|
||||
}
|
||||
|
||||
Write-Host "C19Z54 remote workspace real-adapter handoff v4 smoke passed. Result: $fullResultPath"
|
||||
$result
|
||||
Reference in New Issue
Block a user