|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Runs the formal local MXC validation path. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + Builds the required Windows projects, enables the E2E/MXC gates, and runs |
| 7 | + the real WSL Gateway -> Windows node -> system.run MXC E2E proofs. |
| 8 | +
|
| 9 | + This script is intentionally stricter than the regular GitHub-hosted E2E |
| 10 | + shard: MXC skips fail by default so MXC-related work cannot accidentally |
| 11 | + claim end-to-end validation on a host that did not exercise MXC. |
| 12 | +
|
| 13 | +.PARAMETER NoBuild |
| 14 | + Skip build steps and run against existing outputs. |
| 15 | +
|
| 16 | +.PARAMETER AllowSkip |
| 17 | + Return success when MXC tests are reported but skipped. Use only for |
| 18 | + discovery/documentation of a non-MXC host; do not use as merge validation |
| 19 | + for MXC, system.run, exec approval, Windows node command execution, or |
| 20 | + gateway setup/connect changes. |
| 21 | +#> |
| 22 | +[CmdletBinding()] |
| 23 | +param( |
| 24 | + [switch]$NoBuild, |
| 25 | + |
| 26 | + [switch]$AllowSkip, |
| 27 | + |
| 28 | + [ValidateSet("Debug", "Release")] |
| 29 | + [string]$Configuration = "Debug", |
| 30 | + |
| 31 | + [ValidateSet("win-x64", "win-arm64")] |
| 32 | + [string]$RuntimeIdentifier, |
| 33 | + |
| 34 | + [string]$ResultsDirectory |
| 35 | +) |
| 36 | + |
| 37 | +Set-StrictMode -Version Latest |
| 38 | +$ErrorActionPreference = "Stop" |
| 39 | + |
| 40 | +$repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")).Path |
| 41 | +Set-Location $repoRoot |
| 42 | + |
| 43 | +if ([string]::IsNullOrWhiteSpace($RuntimeIdentifier)) { |
| 44 | + $RuntimeIdentifier = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) { |
| 45 | + ([System.Runtime.InteropServices.Architecture]::Arm64) { "win-arm64"; break } |
| 46 | + default { "win-x64" } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +if ([string]::IsNullOrWhiteSpace($ResultsDirectory)) { |
| 51 | + $ResultsDirectory = Join-Path $repoRoot "TestResults\MxcE2E" |
| 52 | +} |
| 53 | + |
| 54 | +New-Item -ItemType Directory -Force -Path $ResultsDirectory | Out-Null |
| 55 | + |
| 56 | +function Invoke-Checked { |
| 57 | + param( |
| 58 | + [Parameter(Mandatory = $true)][string]$Name, |
| 59 | + [Parameter(Mandatory = $true)][scriptblock]$Command |
| 60 | + ) |
| 61 | + |
| 62 | + Write-Host "" |
| 63 | + Write-Host "=== $Name ===" -ForegroundColor Cyan |
| 64 | + & $Command |
| 65 | + if ($LASTEXITCODE -ne 0) { |
| 66 | + throw "$Name failed with exit code $LASTEXITCODE." |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +function Read-Trx { |
| 71 | + param([Parameter(Mandatory = $true)][string]$Path) |
| 72 | + |
| 73 | + if (-not (Test-Path -LiteralPath $Path)) { |
| 74 | + throw "Expected TRX file was not created: $Path" |
| 75 | + } |
| 76 | + |
| 77 | + [xml](Get-Content -LiteralPath $Path -Raw) |
| 78 | +} |
| 79 | + |
| 80 | +function Get-TrxUnitTestResults { |
| 81 | + param([Parameter(Mandatory = $true)][xml]$Trx) |
| 82 | + |
| 83 | + @($Trx.SelectNodes("//*[local-name()='UnitTestResult']")) |
| 84 | +} |
| 85 | + |
| 86 | +function Get-TrxResultText { |
| 87 | + param([Parameter(Mandatory = $true)][System.Xml.XmlElement]$Result) |
| 88 | + |
| 89 | + $parts = New-Object System.Collections.Generic.List[string] |
| 90 | + foreach ($node in @($Result.SelectNodes(".//*[local-name()='Message' or local-name()='StdOut' or local-name()='StdErr']"))) { |
| 91 | + if ($node -and -not [string]::IsNullOrWhiteSpace($node.InnerText)) { |
| 92 | + $parts.Add($node.InnerText) |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + [string]::Join("`n", $parts) |
| 97 | +} |
| 98 | + |
| 99 | +function Assert-GatewayMxcProofsPassed { |
| 100 | + param([Parameter(Mandatory = $true)][xml]$Trx) |
| 101 | + |
| 102 | + $expectedProofs = @( |
| 103 | + "RealGateway_SystemRun_ExecutesThroughWindowsNodeMxcSandbox", |
| 104 | + "RealGateway_SystemRun_BlocksWritesToTrayDataDirectoryInMxcSandbox" |
| 105 | + ) |
| 106 | + $results = Get-TrxUnitTestResults -Trx $Trx |
| 107 | + $errors = New-Object System.Collections.Generic.List[string] |
| 108 | + |
| 109 | + foreach ($proof in $expectedProofs) { |
| 110 | + $result = @($results | Where-Object { $_.GetAttribute("testName") -like "*$proof*" }) | Select-Object -First 1 |
| 111 | + if ($null -eq $result) { |
| 112 | + $errors.Add("Gateway MXC proof was not reported in TRX: $proof") |
| 113 | + continue |
| 114 | + } |
| 115 | + |
| 116 | + $outcome = $result.GetAttribute("outcome") |
| 117 | + if ($outcome -eq "Passed") { |
| 118 | + Write-Host "Gateway MXC proof passed: $proof" -ForegroundColor Green |
| 119 | + continue |
| 120 | + } |
| 121 | + |
| 122 | + if ($outcome -eq "NotExecuted" -or $outcome -eq "Skipped") { |
| 123 | + $text = Get-TrxResultText -Result $result |
| 124 | + $skipMessage = if ([string]::IsNullOrWhiteSpace($text)) { "no skip reason in TRX" } else { $text.Trim() } |
| 125 | + $message = "Gateway MXC proof skipped: $proof ($skipMessage)" |
| 126 | + if ($AllowSkip) { |
| 127 | + Write-Warning $message |
| 128 | + } else { |
| 129 | + $errors.Add("$message. Run on an MXC-enabled Windows machine or pass -AllowSkip only when documenting a blocked host.") |
| 130 | + } |
| 131 | + continue |
| 132 | + } |
| 133 | + |
| 134 | + $errors.Add("Gateway MXC proof '$proof' had unexpected outcome '$outcome'.") |
| 135 | + } |
| 136 | + |
| 137 | + if ($errors.Count -gt 0) { |
| 138 | + throw [string]::Join("`n", $errors) |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +function Set-ProcessEnv { |
| 143 | + param( |
| 144 | + [Parameter(Mandatory = $true)][string]$Name, |
| 145 | + [string]$Value |
| 146 | + ) |
| 147 | + |
| 148 | + [Environment]::SetEnvironmentVariable($Name, $Value, "Process") |
| 149 | +} |
| 150 | + |
| 151 | +$trackedEnvVars = @( |
| 152 | + "OPENCLAW_REPO_ROOT", |
| 153 | + "OPENCLAW_RUN_E2E", |
| 154 | + "OPENCLAW_RUN_MXC_E2E" |
| 155 | +) |
| 156 | +$previousEnv = @{} |
| 157 | +foreach ($name in $trackedEnvVars) { |
| 158 | + $previousEnv[$name] = [Environment]::GetEnvironmentVariable($name, "Process") |
| 159 | +} |
| 160 | + |
| 161 | +try { |
| 162 | + Set-ProcessEnv -Name "OPENCLAW_REPO_ROOT" -Value $repoRoot |
| 163 | + Set-ProcessEnv -Name "OPENCLAW_RUN_E2E" -Value "1" |
| 164 | + Set-ProcessEnv -Name "OPENCLAW_RUN_MXC_E2E" -Value "1" |
| 165 | + |
| 166 | + Write-Host "OpenClaw MXC validation" |
| 167 | + Write-Host " Repo: $repoRoot" |
| 168 | + Write-Host " Configuration: $Configuration" |
| 169 | + Write-Host " RuntimeIdentifier: $RuntimeIdentifier" |
| 170 | + Write-Host " Results: $ResultsDirectory" |
| 171 | + if ($AllowSkip) { |
| 172 | + Write-Warning "-AllowSkip is enabled. This run may document a non-MXC host, but it is not sufficient merge validation for MXC-related work." |
| 173 | + } |
| 174 | + |
| 175 | + if (-not $NoBuild) { |
| 176 | + Invoke-Checked -Name "Build repository" -Command { |
| 177 | + $powerShellExe = (Get-Process -Id $PID).Path |
| 178 | + & $powerShellExe -NoProfile -File (Join-Path $repoRoot "build.ps1") -Configuration $Configuration |
| 179 | + } |
| 180 | + |
| 181 | + Invoke-Checked -Name "Build tray app for $RuntimeIdentifier" -Command { |
| 182 | + & dotnet build ".\src\OpenClaw.Tray.WinUI\OpenClaw.Tray.WinUI.csproj" -c $Configuration -r $RuntimeIdentifier |
| 183 | + } |
| 184 | + |
| 185 | + Invoke-Checked -Name "Build E2E tests for $RuntimeIdentifier" -Command { |
| 186 | + & dotnet build ".\tests\OpenClaw.E2ETests\OpenClaw.E2ETests.csproj" -c $Configuration -r $RuntimeIdentifier |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + $e2eTrx = Join-Path $ResultsDirectory "OpenClaw.E2ETests.Mxc.trx" |
| 191 | + $e2eConsoleLog = Join-Path $ResultsDirectory "OpenClaw.E2ETests.Mxc.console.log" |
| 192 | + Invoke-Checked -Name "Run Gateway MXC E2E proofs" -Command { |
| 193 | + & dotnet test ".\tests\OpenClaw.E2ETests\OpenClaw.E2ETests.csproj" ` |
| 194 | + --no-build ` |
| 195 | + --no-restore ` |
| 196 | + -c $Configuration ` |
| 197 | + -r $RuntimeIdentifier ` |
| 198 | + --verbosity normal ` |
| 199 | + --results-directory $ResultsDirectory ` |
| 200 | + --logger "trx;LogFileName=OpenClaw.E2ETests.Mxc.trx" ` |
| 201 | + --logger "console;verbosity=detailed" ` |
| 202 | + --filter "FullyQualifiedName~OpenClaw.E2ETests.Setup.MxcSetupAndConnectTests" ` |
| 203 | + 2>&1 | Tee-Object -FilePath $e2eConsoleLog |
| 204 | + } |
| 205 | + Assert-GatewayMxcProofsPassed -Trx (Read-Trx -Path $e2eTrx) |
| 206 | + |
| 207 | + Write-Host "" |
| 208 | + Write-Host "MXC validation completed successfully." -ForegroundColor Green |
| 209 | +} finally { |
| 210 | + foreach ($name in $trackedEnvVars) { |
| 211 | + [Environment]::SetEnvironmentVariable($name, $previousEnv[$name], "Process") |
| 212 | + } |
| 213 | +} |
0 commit comments