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]$EntryNodeName = "test-1", [string]$ResultPath = "artifacts\c19z35-remote-workspace-real-adapter-supervision-scaffold-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath $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" ) function Invoke-Api { param([string]$Method, [string]$Path, [object]$Body = $null) $uri = "$ApiBaseUrl$Path" if ($null -eq $Body) { return Invoke-RestMethod -Method $Method -Uri $uri -TimeoutSec 30 } return Invoke-RestMethod -Method $Method -Uri $uri -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 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-RealAdapterScaffold { 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 if ($null -eq $contract) { return $false } $env = Get-PropertyValue -Item $contract -Name "config_env" -Default @() foreach ($item in $requiredEnv) { if (-not (Test-ArrayItem -Items $env -Want $item)) { return $false } } return ( [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 $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 "activation_state" -Default "") -eq "disabled_until_real_runtime_stage" -and [string](Get-PropertyValue -Item $contract -Name "payload_traffic" -Default "") -eq "none" ) } $entryNode = Get-NodeByName -Name $EntryNodeName $status = $null $deadline = (Get-Date).AddSeconds(60) while ((Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 $status = Get-RdpWorkerStatus -NodeID $entryNode.id if (Test-RealAdapterScaffold -Status $status) { break } } if ($null -eq $status) { $status = Get-RdpWorkerStatus -NodeID $entryNode.id } $checks = [ordered]@{ rdp_worker_status_present = ($null -ne $status) contract_probe_remains_active = ([string](Get-PropertyValue -Item $status.status_payload -Name "execution_mode" -Default "") -eq "contract_probe") real_adapter_scaffold_visible = (Test-RealAdapterScaffold -Status $status) } $failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) $result = [ordered]@{ schema_version = "c19z35.remote_workspace_real_adapter_supervision_scaffold_smoke.v1" cluster_id = $ClusterID entry_node = [ordered]@{ id = $entryNode.id; name = $entryNode.name } required_env = $requiredEnv workload_status = $status 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 "C19Z35 remote workspace real-adapter supervision scaffold smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')" } Write-Host "C19Z35 remote workspace real-adapter supervision scaffold smoke passed. Result: $fullResultPath" $result