Skip to content

Commit 3cded23

Browse files
committed
test(mxc): sync Windows policies and isolated CLI harness fixes
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 2f9a05d commit 3cded23

10 files changed

Lines changed: 513 additions & 19 deletions

File tree

‎.agents/skills/build-openshell-mxc-windows/SKILL.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ skill or design doc.
456456

457457
## Final Report Checklist
458458

459+
When syncing from the `windows` branch, consult the selective integration
460+
checkpoint in `crates/openshell-driver-mxc/WINDOWS-INTEGRATION.md`. Preserve
461+
the host-supervisor/Windows-boundary architecture rather than restoring legacy
462+
relay/proxy demo wrappers. The WebSocket, OpenClaw, and inference policy fixtures
463+
have parser/mapper tests; do not report them as live runtime scenarios.
464+
459465
Every substantial Windows build run should report:
460466

461467
| Item | Required detail |

‎crates/openshell-driver-mxc/README.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ from Cargo's passed count.
158158
The E2E runner uses native release artifacts (override with `-BinaryDir`), OpenSSL
159159
on PATH for disposable Ed25519 keys, and per-run writable fixtures under
160160
`target/windows-e2e-results`. It preserves the tracked gateway TOML and isolates
161-
CLI registration via `XDG_CONFIG_HOME`. Signing keys have an owner-only DACL,
161+
CLI registration via disposable APPDATA, LOCALAPPDATA, and XDG directories.
162+
Inherited gateway overrides are cleared for the run and restored exactly
163+
(including empty versus absent entries). The caller's gateway aliases are not
164+
modified. Signing keys have an owner-only DACL,
162165
remain outside result bundles, and are removed unless `-KeepRunning` is requested.
163166

164167
E2E runs real MXC only: there is no mock mode, and an inherited
@@ -181,3 +184,14 @@ mode, exposes a named endpoint with `openshell service expose`, and verifies two
181184
unique GET responses through gateway host-based routing. It deletes the endpoint
182185
and requires HTTP 404 afterward. Requests connect only to the gateway with the
183186
exposed URL's Host header, so no wildcard DNS setup is required.
187+
188+
The `ws-agent.yaml` and `openclaw-gateway.yaml` policies preserve the Windows
189+
branch's workload grants. `inference.yaml` is a template: replace its filesystem,
190+
curl executable, inference host, and port placeholders before use. Authorize
191+
curl, which owns the network socket, not its cmd launcher. These policies have
192+
parser/mapper regression coverage; they do not add live WebSocket, OpenClaw,
193+
or provider-backed inference scenarios to the six-scenario E2E runner.
194+
195+
With `-KeepRunning`, the runner restores the caller's environment but retains
196+
the disposable CLI/runtime directory for the live gateway and prints its path.
197+
Remove that directory only after stopping the gateway.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Windows integration checkpoint
2+
3+
Reviewed Windows branch through
4+
`d89e4359b810d3d7205bb7d4a706f3c773a59e1f` (PR #4252).
5+
This is a selective port, not a branch merge or a claim of complete demo parity.
6+
7+
- #4252 (`d89e4359b`): MXC 1.0.0 schema, directional networking, and UI contract
8+
already ported in `ce2ca474a`.
9+
- #4199 (`f6ecca206`): authorize the socket-owning curl executable in the
10+
inference policy template and real HTTPS test, rather than its cmd launcher.
11+
- #4192 (`ed35eb9f3`): disposable CLI state, cleared inherited gateway
12+
overrides, exact environment restoration, and strict fresh gateway
13+
registration in the E2E and OCSF runners.
14+
- Restore the WebSocket and OpenClaw policy fixtures with their original
15+
grants, updating comments to the host-supervisor/Windows-boundary architecture.
16+
17+
Keep the always-present `openshell-windows-sandbox`, authenticated Sandbox
18+
Protocol, and host isolation-backend supervisor. Do not restore the old relay
19+
executable, driver-owned CONNECT proxy, or legacy demo/task wrappers requiring
20+
them. Provider-backed inference, live WebSocket, OpenClaw, and OCSF demo coverage
21+
are not implied by policy parsing or by the six core E2E scenarios. Network-fence
22+
evidence remains the documented compatibility TODO, not a verified guarantee.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# OpenClaw gateway policy fixture ported from windows.
5+
# Stage Node, OpenClaw, home, temporary files, and logs under this writable path.
6+
# Node loads user32/gdi32: explicitly permit graphical UI to disable MXC 1.0
7+
# win32k lockdown. Clipboard and input injection remain disabled.
8+
# The host supervisor governs the Node outbound grant. Managed ingress uses the
9+
# Windows sandbox boundary; neither path needs a driver-owned proxy or relay.
10+
# Fixture validation is not live OpenClaw coverage or verified exclusive fencing.
11+
version: 1
12+
13+
filesystem_policy:
14+
include_workdir: false
15+
read_only: []
16+
read_write:
17+
- "C:/openshell-openclaw"
18+
19+
ui:
20+
allow_graphical_ui: true
21+
clipboard: none
22+
allow_input_injection: false
23+
24+
network_policies:
25+
qualification_allowed:
26+
name: qualification-allowed
27+
endpoints:
28+
- host: example.com
29+
port: 443
30+
protocol: tcp
31+
binaries:
32+
- path: "C:/openshell-openclaw/node.exe"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# WebSocket-agent policy fixture ported from windows.
5+
# Stage the workload under the read-only directory; adapt the path before use.
6+
# Managed ingress uses the always-present Windows sandbox boundary and host
7+
# supervisor, not an optional relay binary or a driver-owned network proxy.
8+
# No network_policies means no authorized outbound destinations. This fixture
9+
# does not itself exercise a live WebSocket session or prove network fencing.
10+
version: 1
11+
12+
filesystem_policy:
13+
include_workdir: false
14+
read_only:
15+
- "C:/work/openshell-mxc-ws"
16+
read_write: []
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Policy template: replace the path, host, and port placeholders before use.
5+
# Authorize the socket-owning curl executable, not its cmd.exe launcher (#4199).
6+
# The host supervisor evaluates REST policy and injects provider credentials.
7+
version: 1
8+
9+
filesystem_policy:
10+
include_workdir: false
11+
read_only: []
12+
read_write:
13+
- "__OPENSHELL_DEMO_SHARE__"
14+
15+
network_policies:
16+
nvidia_inference:
17+
name: nvidia-inference
18+
endpoints:
19+
- host: "__INFERENCE_HOST__"
20+
port: __INFERENCE_PORT__
21+
protocol: rest
22+
access: read-write
23+
enforcement: enforce
24+
binaries:
25+
- path: '__CURL_EXE__'

‎crates/openshell-driver-mxc/examples/run-mxc-e2e.ps1‎

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,120 @@ if (-not $BinaryDir) {
7676
$BinaryDir = Join-Path $targetRoot "$target/release"
7777
}
7878
$savedEnv = @{}
79-
foreach ($name in @("OPENSHELL_GATEWAY_CONFIG", "OPENSHELL_GATEWAY", "OPENSHELL_MXC_MOCK_WXC", "OPENSHELL_WXC_EXEC_PATH", "OPENSHELL_COMPUTE_DRIVER", "OPENSHELL_MXC_SHARE_DIR", "XDG_CONFIG_HOME")) {
80-
$savedEnv[$name] = [Environment]::GetEnvironmentVariable($name, "Process")
79+
$processEnvironment = [Environment]::GetEnvironmentVariables("Process")
80+
foreach ($name in @("OPENSHELL_MXC_MOCK_WXC", "OPENSHELL_WXC_EXEC_PATH", "OPENSHELL_COMPUTE_DRIVER", "OPENSHELL_MXC_SHARE_DIR")) {
81+
$exists = $processEnvironment.Contains($name)
82+
$savedEnv[$name] = [pscustomobject]@{
83+
Exists = $exists
84+
Value = if ($exists) { [string] $processEnvironment[$name] } else { $null }
85+
}
8186
}
8287
$secretDir = Join-Path $resultsRoot "keys-$stamp-$([guid]::NewGuid().ToString('N'))"
8388
$transcriptStarted = $false
8489

90+
$cliStateRoot = $null
91+
$cliEnvironmentSnapshot = @{}
92+
$cliEnvironmentNames = @(
93+
"APPDATA", "LOCALAPPDATA", "XDG_CONFIG_HOME", "XDG_STATE_HOME", "XDG_DATA_HOME",
94+
"OPENSHELL_GATEWAY", "OPENSHELL_GATEWAY_ENDPOINT", "OPENSHELL_GATEWAY_INSECURE",
95+
"OPENSHELL_GATEWAY_CONFIG", "OPENSHELL_GATEWAY_NAME"
96+
)
97+
98+
function Set-ProcessEnvironmentVariableExact {
99+
param(
100+
[Parameter(Mandatory = $true)]
101+
[string] $Name,
102+
[Parameter(Mandatory = $true)]
103+
[bool] $Exists,
104+
[AllowNull()]
105+
[string] $Value
106+
)
107+
108+
if (-not $Exists) {
109+
Remove-Item "Env:$Name" -ErrorAction SilentlyContinue
110+
return
111+
}
112+
113+
if ($Value.Length -eq 0) {
114+
# Windows PowerShell 5.1 maps an empty value passed through
115+
# Environment.SetEnvironmentVariable to deletion. Call Win32 directly
116+
# so an inherited empty entry remains distinguishable from absence.
117+
if (-not ("OpenShellMxcProcessEnvironmentNative" -as [type])) {
118+
Add-Type -TypeDefinition @'
119+
using System.Runtime.InteropServices;
120+
121+
public static class OpenShellMxcProcessEnvironmentNative
122+
{
123+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
124+
[return: MarshalAs(UnmanagedType.Bool)]
125+
public static extern bool SetEnvironmentVariable(string name, string value);
126+
}
127+
'@
128+
}
129+
if (-not [OpenShellMxcProcessEnvironmentNative]::SetEnvironmentVariable($Name, [string]::Empty)) {
130+
$errorCode = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
131+
throw "failed to restore empty process environment variable '$Name' (Win32 error $errorCode)"
132+
}
133+
return
134+
}
135+
136+
[Environment]::SetEnvironmentVariable($Name, $Value, "Process")
137+
}
138+
139+
function Enter-IsolatedCliEnvironment {
140+
$processEnvironment = [Environment]::GetEnvironmentVariables("Process")
141+
foreach ($name in $cliEnvironmentNames) {
142+
$exists = $processEnvironment.Contains($name)
143+
$script:cliEnvironmentSnapshot[$name] = [pscustomobject]@{
144+
Exists = $exists
145+
Value = if ($exists) { [string] $processEnvironment[$name] } else { $null }
146+
}
147+
}
148+
$script:cliStateRoot = Join-Path ([IO.Path]::GetTempPath()) "openshell-mxc-e2e-cli-$PID-$([Guid]::NewGuid().ToString('N'))"
149+
$isolatedPaths = @{
150+
APPDATA = Join-Path $script:cliStateRoot "appdata"
151+
LOCALAPPDATA = Join-Path $script:cliStateRoot "localappdata"
152+
XDG_CONFIG_HOME = Join-Path $script:cliStateRoot "xdg-config"
153+
XDG_STATE_HOME = Join-Path $script:cliStateRoot "xdg-state"
154+
XDG_DATA_HOME = Join-Path $script:cliStateRoot "xdg-data"
155+
}
156+
try {
157+
New-Item -ItemType Directory -Force -Path @($isolatedPaths.Values) | Out-Null
158+
foreach ($entry in $isolatedPaths.GetEnumerator()) {
159+
[Environment]::SetEnvironmentVariable($entry.Key, $entry.Value, "Process")
160+
}
161+
foreach ($name in $cliEnvironmentNames | Where-Object { -not $isolatedPaths.ContainsKey($_) }) {
162+
Remove-Item "Env:$name" -ErrorAction SilentlyContinue
163+
}
164+
} catch {
165+
Exit-IsolatedCliEnvironment
166+
throw
167+
}
168+
}
169+
170+
function Exit-IsolatedCliEnvironment {
171+
foreach ($name in $cliEnvironmentNames) {
172+
if (-not $script:cliEnvironmentSnapshot.ContainsKey($name)) { continue }
173+
$snapshot = $script:cliEnvironmentSnapshot[$name]
174+
Set-ProcessEnvironmentVariableExact -Name $name -Exists $snapshot.Exists -Value $snapshot.Value
175+
}
176+
if ($script:cliStateRoot -and (Test-Path -LiteralPath $script:cliStateRoot)) {
177+
if ($KeepRunning -and $gw -and -not $gw.HasExited) {
178+
Write-Host "Retaining isolated CLI/runtime state for live gateway: $script:cliStateRoot"
179+
return
180+
}
181+
# Resolve the generated target before recursive cleanup; never remove an
182+
# arbitrary caller path or the temporary directory itself.
183+
$cleanupPath = [IO.Path]::GetFullPath($script:cliStateRoot)
184+
$tempPrefix = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('\') + '\'
185+
if (-not $cleanupPath.StartsWith($tempPrefix, [StringComparison]::OrdinalIgnoreCase) -or
186+
(Split-Path $cleanupPath -Leaf) -notmatch '^openshell-mxc-(e2e|ocsf)-cli-[0-9]+-[0-9a-f]{32}$') {
187+
throw "refusing unsafe CLI state cleanup: $cleanupPath"
188+
}
189+
Remove-Item -LiteralPath $cleanupPath -Recurse -Force -ErrorAction SilentlyContinue
190+
}
191+
}
192+
85193
function Step([string]$m) { Write-Host "`n=== $m ===" -ForegroundColor Cyan }
86194
function Info([string]$m) { Write-Host " $m" }
87195
function Ok([string]$m) { Write-Host "[OK] $m" -ForegroundColor Green }
@@ -247,14 +355,13 @@ function Stop-Gw($p) {
247355

248356
function Register-Cli {
249357
if ($script:registered) { return }
250-
$env:OPENSHELL_GATEWAY = ""
251358

252359
$addResult = Invoke-NativeCaptured $cli @(
253360
"gateway", "add", "http://127.0.0.1:$Port", "--local", "--name", $GatewayName
254361
)
255362
$addText = ($addResult.Output -join "`n")
256363
if ($addText) { $addResult.Output | ForEach-Object { Info $_ } }
257-
if ($addResult.ExitCode -ne 0 -and $addText -notmatch '(?i)already exists') {
364+
if ($addResult.ExitCode -ne 0) {
258365
throw "gateway add failed (exit $($addResult.ExitCode)): $addText"
259366
}
260367

@@ -510,6 +617,7 @@ $backendProbe = @{ Live = $false; Reason = "not probed" }
510617
$runId = Get-Date -Format 'MMddHHmmss'
511618

512619
try {
620+
Enter-IsolatedCliEnvironment
513621
# Start the transcript inside the guarded region so a Start-Transcript failure
514622
# is caught and the results bundle is still produced. Pre-flight runs
515623
# immediately below, so the transcript still captures the whole run.
@@ -541,7 +649,6 @@ try {
541649

542650
# Capture the pristine TOML once; every scenario renders a fresh copy from this.
543651
$tomlBase = Get-Content $tomlTemplate -Raw
544-
$env:XDG_CONFIG_HOME = Join-Path $resultDir "cli-config"
545652
$openssl = (Get-Command openssl -ErrorAction Stop).Source
546653
New-Item -ItemType Directory $secretDir | Out-Null
547654
$ownerSid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value
@@ -929,7 +1036,11 @@ ingress works, not that direct host ingress is blocked.
9291036
}
9301037
if (Test-Path $secretDir) { Remove-Item -LiteralPath $secretDir -ErrorAction SilentlyContinue }
9311038
}
932-
foreach ($name in $savedEnv.Keys) { [Environment]::SetEnvironmentVariable($name, $savedEnv[$name], "Process") }
1039+
Exit-IsolatedCliEnvironment
1040+
foreach ($name in $savedEnv.Keys) {
1041+
$snapshot = $savedEnv[$name]
1042+
Set-ProcessEnvironmentVariableExact -Name $name -Exists $snapshot.Exists -Value $snapshot.Value
1043+
}
9331044
}
9341045

9351046
if ($harnessError -or $failCount -gt 0) {

0 commit comments

Comments
 (0)