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\c19z43-remote-workspace-real-adapter-precedence-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath $runId = "c19z43-" + (Get-Date -Format "yyyyMMdd-HHmmss") 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 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 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 Test-Precedence { param([object]$Status) if ($null -eq $Status) { return $false } $payload = Get-PropertyValue -Item $Status -Name "status_payload" -Default $null $contract = Get-PropertyValue -Item $payload -Name "real_adapter_supervision" -Default $null $decision = Get-PropertyValue -Item $contract -Name "activation_decision" -Default $null return ( [string](Get-PropertyValue -Item $Status -Name "reported_state" -Default "") -eq "running" -and [string](Get-PropertyValue -Item $payload -Name "reason" -Default "") -eq "remote_workspace_adapter_contract_probe_ready" -and [string](Get-PropertyValue -Item $payload -Name "execution_mode" -Default "") -eq "contract_probe" -and [string](Get-PropertyValue -Item $payload -Name "traffic" -Default "") -eq "none" -and [string](Get-PropertyValue -Item $payload -Name "payload_traffic" -Default "none") -eq "none" -and [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 [string](Get-PropertyValue -Item $decision -Name "decision" -Default "") -eq "blocked" -and [string](Get-PropertyValue -Item $decision -Name "reason" -Default "") -eq "real_runtime_stage_not_enabled" -and [string](Get-PropertyValue -Item $decision -Name "payload_traffic" -Default "") -eq "none" ) } $node = Get-NodeByName -Name $NodeName Invoke-Api -Method PUT -Path "/clusters/$ClusterID/nodes/$($node.id)/workloads/rdp-worker/desired" -Body @{ actor_user_id = $ActorUserID desired_state = "enabled" version = "c19z43-real-adapter-precedence-$runId" runtime_mode = "native" artifact_ref = "builtin:rdp-worker-adapter-contract-probe" config = @{ adapter_contract_probe = $true real_adapter_supervision = $true service_class = "remote_workspace" run_id = $runId } environment = @{} } | Out-Null $status = $null $deadline = (Get-Date).AddSeconds(80) while ((Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 $status = Get-RdpWorkerStatus -NodeID $node.id if (Test-Precedence -Status $status) { break } } $payload = Get-PropertyValue -Item $status -Name "status_payload" -Default $null $contract = Get-PropertyValue -Item $payload -Name "real_adapter_supervision" -Default $null $decision = Get-PropertyValue -Item $contract -Name "activation_decision" -Default $null $checks = [ordered]@{ status_present = ($null -ne $status) reported_running = ([string](Get-PropertyValue -Item $status -Name "reported_state" -Default "") -eq "running") contract_probe_precedence = ([string](Get-PropertyValue -Item $payload -Name "execution_mode" -Default "") -eq "contract_probe") real_adapter_branch_not_selected = ([string](Get-PropertyValue -Item $payload -Name "reason" -Default "") -ne "remote_workspace_real_adapter_supervision_disabled") payload_traffic_none = ([string](Get-PropertyValue -Item $payload -Name "traffic" -Default "") -eq "none" -and [string](Get-PropertyValue -Item $decision -Name "payload_traffic" -Default "") -eq "none") activation_decision_blocked = ([string](Get-PropertyValue -Item $decision -Name "decision" -Default "") -eq "blocked") precedence_contract_passed = (Test-Precedence -Status $status) } $failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) $result = [ordered]@{ schema_version = "c19z43.remote_workspace_real_adapter_precedence_smoke.v1" run_id = $runId cluster_id = $ClusterID node = [ordered]@{ id = $node.id; name = $node.name } requested_config = [ordered]@{ adapter_contract_probe = $true; real_adapter_supervision = $true } observed = [ordered]@{ reported_state = Get-PropertyValue -Item $status -Name "reported_state" -Default $null reason = Get-PropertyValue -Item $payload -Name "reason" -Default $null execution_mode = Get-PropertyValue -Item $payload -Name "execution_mode" -Default $null traffic = Get-PropertyValue -Item $payload -Name "traffic" -Default $null activation_decision = Get-PropertyValue -Item $decision -Name "decision" -Default $null activation_reason = Get-PropertyValue -Item $decision -Name "reason" -Default $null } 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 "C19Z43 remote workspace real-adapter precedence smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')" } Write-Host "C19Z43 remote workspace real-adapter precedence smoke passed. Result: $fullResultPath" $result