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\c19z50-remote-workspace-real-adapter-mode-matrix-v2-smoke-result.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath $runId = "c19z50-" + (Get-Date -Format "yyyyMMdd-HHmmss") $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" ) 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-MapBool { param([hashtable]$Map, [string]$Name) if ($null -eq $Map -or -not $Map.ContainsKey($Name)) { return $false } return [bool]$Map[$Name] } 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 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 Set-RdpWorkerDesired { param([object]$Node, [string]$Mode, [hashtable]$Config) Invoke-Api -Method PUT -Path "/clusters/$ClusterID/nodes/$($Node.id)/workloads/rdp-worker/desired" -Body @{ actor_user_id = $ActorUserID desired_state = "enabled" version = "c19z50-real-adapter-mode-matrix-v2-$Mode-$runId" runtime_mode = "native" artifact_ref = "builtin:rdp-worker-mode-matrix-v2" config = $Config 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 Wait-RdpWorkerMode { param([object]$Node, [string]$ExpectedVersion) $deadline = (Get-Date).AddSeconds(80) $last = $null while ((Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 $last = Get-RdpWorkerStatus -NodeID $Node.id if ($null -ne $last -and [string](Get-PropertyValue -Item $last -Name "version" -Default "") -eq $ExpectedVersion) { return $last } } return $last } function New-MatrixRow { param([object]$Status, [hashtable]$Case) $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 $features = Get-PropertyValue -Item $contract -Name "features" -Default $null $reportedState = [string](Get-PropertyValue -Item $Status -Name "reported_state" -Default "") $executionMode = [string](Get-PropertyValue -Item $payload -Name "execution_mode" -Default "") $traffic = [string](Get-PropertyValue -Item $payload -Name "traffic" -Default "") $payloadTraffic = [string](Get-PropertyValue -Item $payload -Name "payload_traffic" -Default "none") $processStartAllowed = [bool](Get-PropertyValue -Item $preconditions -Name "process_start_allowed" -Default $true) $missingChecksVisible = Test-RequiredItems -Items (Get-PropertyValue -Item $preconditions -Name "missing_checks" -Default @()) -Required $requiredPreconditionChecks $preconditionsVisible = ( [string](Get-PropertyValue -Item $preconditions -Name "schema_version" -Default "") -eq "rap.remote_workspace_real_adapter_process_supervisor_preconditions.v1" -and -not $processStartAllowed -and $missingChecksVisible ) $passed = ( $reportedState -eq [string]$Case.expected_reported_state -and $executionMode -eq [string]$Case.expected_execution_mode -and $traffic -eq [string]$Case.expected_traffic -and $payloadTraffic -eq "none" -and -not [bool](Get-PropertyValue -Item $contract -Name "enabled" -Default $true) -and [string](Get-PropertyValue -Item $decision -Name "decision" -Default "") -eq "blocked" -and -not [bool](Get-PropertyValue -Item $decision -Name "activation_allowed" -Default $true) -and [bool](Get-PropertyValue -Item $projection -Name "enabled_requested" -Default $false) -and [bool](Get-PropertyValue -Item $features -Name "process_supervisor_preconditions" -Default $false) -and [bool](Get-PropertyValue -Item $features -Name "process_supervisor_start_disabled" -Default $false) -and $preconditionsVisible ) return [ordered]@{ mode = $Case.mode adapter_contract_probe = Get-MapBool -Map $Case.config -Name "adapter_contract_probe" real_adapter_supervision = Get-MapBool -Map $Case.config -Name "real_adapter_supervision" reported_state = $reportedState execution_mode = $executionMode traffic = $traffic payload_traffic = $payloadTraffic activation_decision = Get-PropertyValue -Item $decision -Name "decision" -Default $null activation_allowed = Get-PropertyValue -Item $decision -Name "activation_allowed" -Default $null process_start_allowed = $processStartAllowed preconditions_visible = $preconditionsVisible missing_checks_visible = $missingChecksVisible process_start_disabled_feature = Get-PropertyValue -Item $features -Name "process_supervisor_start_disabled" -Default $null passed = $passed } } $node = Get-NodeByName -Name $NodeName $cases = @( @{ mode = "probe_only"; config = @{ adapter_contract_probe = $true; service_class = "remote_workspace"; run_id = "$runId-probe" }; expected_reported_state = "running"; expected_execution_mode = "contract_probe"; expected_traffic = "none" }, @{ mode = "real_adapter_only"; config = @{ real_adapter_supervision = $true; service_class = "remote_workspace"; run_id = "$runId-real-only" }; expected_reported_state = "degraded"; expected_execution_mode = "real_adapter_supervision_disabled"; expected_traffic = "blocked" }, @{ mode = "probe_and_real_adapter"; config = @{ adapter_contract_probe = $true; real_adapter_supervision = $true; service_class = "remote_workspace"; run_id = "$runId-both" }; expected_reported_state = "running"; expected_execution_mode = "contract_probe"; expected_traffic = "none" } ) $rows = @() foreach ($case in $cases) { $version = "c19z50-real-adapter-mode-matrix-v2-$($case.mode)-$runId" Set-RdpWorkerDesired -Node $node -Mode $case.mode -Config $case.config $status = Wait-RdpWorkerMode -Node $node -ExpectedVersion $version $rows += New-MatrixRow -Status $status -Case $case } $checks = [ordered]@{ node_present = ($null -ne $node) matrix_rows_present = ($rows.Count -eq 3) all_rows_passed = (@($rows | Where-Object { -not $_.passed }).Count -eq 0) process_start_disabled_all_rows = (@($rows | Where-Object { [bool]$_.process_start_allowed }).Count -eq 0) preconditions_visible_all_rows = (@($rows | Where-Object { -not $_.preconditions_visible }).Count -eq 0) } $failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) $result = [ordered]@{ schema_version = "c19z50.remote_workspace_real_adapter_mode_matrix_v2_smoke.v1" run_id = $runId cluster_id = $ClusterID node = [ordered]@{ id = $node.id; name = $node.name } required_precondition_checks = $requiredPreconditionChecks 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 "C19Z50 remote workspace real-adapter mode matrix v2 smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')" } Write-Host "C19Z50 remote workspace real-adapter mode matrix v2 smoke passed. Result: $fullResultPath" $result