Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Harden Windows harness validation

Francesco Bonacci56d36b21d2ab
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/README.md b/libs/cua-driver/rust/crates/cua-driver/tests/README.md
index 13fc3e2ea7..4bf932d193 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/README.md
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/README.md
@@ -43,3 +43,9 @@ cargo test -p cua-driver --test modality_desktop_scope_macos_test -- --ignored -
Windows Sandbox runs use `../../sandbox/run-tests-in-sandbox.ps1`, which builds
the Windows harness apps and maps them into the sandbox.
+
+Windows GUI modality tests require a foreground interactive desktop where
+`GetForegroundWindow` returns a real user window. SSH-launched commands,
+scheduled tasks, and PsExec-launched commands can enter the right user session
+while still exposing no foreground desktop; those tests self-skip in that state
+because the focus oracle would otherwise report meaningless pid-0 results.
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/modality_input_e2e_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/modality_input_e2e_test.rs
index 9efc8e7ef9..1ba19787d4 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/modality_input_e2e_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/modality_input_e2e_test.rs
@@ -111,6 +111,30 @@ fn window_ids(driver: &mut McpDriver) -> HashSet<u64> {
.unwrap_or_default()
}
+fn require_interactive_desktop(context: &str) -> bool {
+ if platform_windows::diagnostics::current_session_id() == Some(0) {
+ eprintln!(
+ "{context}: running in Windows Session 0; skipping GUI modality e2e. \
+ Re-run from an interactive logon session (RDP/console)."
+ );
+ return false;
+ }
+
+ match platform_windows::diagnostics::interactive_desktop_check() {
+ Ok(true) => true,
+ Ok(false) => {
+ eprintln!("{context}: no foreground interactive desktop; skipping GUI modality e2e");
+ false
+ }
+ Err(e) => {
+ eprintln!(
+ "{context}: interactive desktop check failed ({e}); skipping GUI modality e2e"
+ );
+ false
+ }
+ }
+}
+
// ── fixture ───────────────────────────────────────────────────────────────────
struct E2eFixture {
@@ -124,6 +148,10 @@ struct E2eFixture {
/// belongs to a child pid) → sentinel (grabs foreground, pushing the app to
/// the background) → reset counters.
fn setup(target_exe: &Path, _title_hint: &str) -> Option<E2eFixture> {
+ if !require_interactive_desktop("modality_input_e2e_test") {
+ return None;
+ }
+
let fm_bin = focus_monitor_binary();
if !fm_bin.exists() {
eprintln!("[e2e] focus-monitor-win.exe not built — skipping");
diff --git a/libs/cua-driver/rust/sandbox/run-tests-in-sandbox.ps1 b/libs/cua-driver/rust/sandbox/run-tests-in-sandbox.ps1
index d532dfef9a..f41b452e28 100644
--- a/libs/cua-driver/rust/sandbox/run-tests-in-sandbox.ps1
+++ b/libs/cua-driver/rust/sandbox/run-tests-in-sandbox.ps1
@@ -1,4 +1,4 @@
-# run-tests-in-sandbox.ps1 — host-side launcher with live log streaming
+# run-tests-in-sandbox.ps1 - host-side launcher with live log streaming
#
# Usage (from workspace root):
# .\sandbox\run-tests-in-sandbox.ps1 [<test-filter>]
@@ -37,7 +37,7 @@ $wsRoot = Split-Path -Parent $sandboxDir
Write-Host "=== cua-driver-rs Windows Sandbox Test Runner ===" -ForegroundColor Cyan
Write-Host "Workspace: $wsRoot"
-# ── Pre-flight: fail fast if a sandbox is already running ────────────────────
+# -- Pre-flight: fail fast if a sandbox is already running --------------------
$running = Get-Process "WindowsSandboxClient","WindowsSandbox" -ErrorAction SilentlyContinue
if ($running) {
Write-Host "`n[ERROR] Windows Sandbox is already running (pid $($running.Id -join ','))." -ForegroundColor Red
@@ -53,7 +53,7 @@ if ($running) {
Write-Host "[OK] Existing sandbox closed. Proceeding." -ForegroundColor Green
}
-# ── 1. Build ──────────────────────────────────────────────────────────────────
+# -- 1. Build ------------------------------------------------------------------
Push-Location $wsRoot
try {
Write-Host "`n[BUILD] cargo build..." -ForegroundColor Yellow
@@ -85,31 +85,31 @@ try {
if ($LASTEXITCODE -ne 0) { throw "cargo test --no-run (harness_bg_modality_test) failed" }
} finally { Pop-Location }
-# ── 1.5. Build the test-harness if dependencies are on PATH ──────────────────
+# -- 1.5. Build the test-harness if dependencies are on PATH ------------------
# The harness produces test-apps/harness-*/ which the sandbox
# runner picks up via the existing mapped-folder route. Skip silently if
-# a dependency isn't available — the smoke tests degrade to "skipped" inside
+# a dependency isn't available - the smoke tests degrade to "skipped" inside
# the sandbox rather than failing the whole run.
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$harnessBuild = Join-Path $wsRoot "..\test-harness\build\windows.ps1"
if (Test-Path $harnessBuild) {
Write-Host "`n[BUILD] test-harness (dotnet publish)..." -ForegroundColor Yellow
# build.ps1 sets $ErrorActionPreference=Stop and throws on
- # `dotnet publish` failure — wrap so the throw doesn't abort
+ # `dotnet publish` failure - wrap so the throw doesn't abort
# the whole sandbox runner before we can log the skip.
try {
& $harnessBuild
if ($LASTEXITCODE -ne 0) {
- Write-Host "[WARN] test-harness build failed (exit $LASTEXITCODE) — harness tests will skip." -ForegroundColor Yellow
+ Write-Host "[WARN] test-harness build failed (exit $LASTEXITCODE) - harness tests will skip." -ForegroundColor Yellow
}
} catch {
- Write-Host "[WARN] test-harness build errored: $($_.Exception.Message) — harness tests will skip." -ForegroundColor Yellow
+ Write-Host "[WARN] test-harness build errored: $($_.Exception.Message) - harness tests will skip." -ForegroundColor Yellow
}
} else {
- Write-Host "`n[SKIP] test-harness/build/windows.ps1 not found — harness tests will skip." -ForegroundColor Yellow
+ Write-Host "`n[SKIP] test-harness/build/windows.ps1 not found - harness tests will skip." -ForegroundColor Yellow
}
} else {
- Write-Host "`n[SKIP] dotnet CLI not on PATH — test-harness build skipped, harness tests will degrade." -ForegroundColor Yellow
+ Write-Host "`n[SKIP] dotnet CLI not on PATH - test-harness build skipped, harness tests will degrade." -ForegroundColor Yellow
}
$mcpBin = Get-ChildItem "$wsRoot\target\debug\deps\mcp_protocol_test-*.exe" |
@@ -121,13 +121,13 @@ $uxBin = Get-ChildItem "$wsRoot\target\debug\deps\ux_guard_test-*.exe" |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($uxBin) { Write-Host "ux_guard_test : $($uxBin.Name)" } else { Write-Host "ux_guard_test : (not found, will skip)" }
-# ── 2. Prepare shared output folder ──────────────────────────────────────────
+# -- 2. Prepare shared output folder ------------------------------------------
$outputDir = "$env:TEMP\cua-sandbox-output"
New-Item -ItemType Directory -Force $outputDir | Out-Null
Get-ChildItem $outputDir -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
$TestFilter | Out-File "$outputDir\test-filter.txt" -Encoding utf8 -NoNewline
-# ── 3. Generate .wsb and launch ───────────────────────────────────────────────
+# -- 3. Generate .wsb and launch -----------------------------------------------
$wsbContent = @"
<Configuration>
<MappedFolders>
@@ -158,7 +158,7 @@ if ($preLaunchCheck) {
}
Start-Process $wsbPath
-# ── 4. Stream logs live ────────────────────────────────────────────────────────
+# -- 4. Stream logs live --------------------------------------------------------
Write-Host "[STREAM] Tailing logs (Ctrl-C to abort)..." -ForegroundColor Yellow
$doneFile = "$outputDir\done.txt"
diff --git a/libs/cua-driver/rust/sandbox/sandbox-runner.ps1 b/libs/cua-driver/rust/sandbox/sandbox-runner.ps1
index 805452a948..35828f98f4 100644
--- a/libs/cua-driver/rust/sandbox/sandbox-runner.ps1
+++ b/libs/cua-driver/rust/sandbox/sandbox-runner.ps1
@@ -1,4 +1,4 @@
-# sandbox-runner.ps1 — runs INSIDE Windows Sandbox as LogonCommand
+# sandbox-runner.ps1 - runs INSIDE Windows Sandbox as LogonCommand
# Streams test output live to C:\sandbox-output\ so the host can tail it.
$ErrorActionPreference = "Continue"
@@ -14,7 +14,7 @@ function Log($msg) {
Log "sandbox-runner.ps1 starting"
-# ── set env so binary_path() resolves cua-driver.exe correctly ─────────────
+# -- set env so binary_path() resolves cua-driver.exe correctly -------------
$env:CARGO_MANIFEST_DIR = "C:\cua-driver-rs\crates\cua-driver"
Log "CARGO_MANIFEST_DIR = $env:CARGO_MANIFEST_DIR"
@@ -27,7 +27,7 @@ if (-not (Test-Path $driverExe)) {
}
Log "cua-driver : $driverExe"
-# ── find test binaries ───────────────────────────────────────────────────────
+# -- find test binaries -------------------------------------------------------
# Run mcp_protocol_test first, then ux_guard_test (UX guard needs a real
# desktop session and spawns visible windows, so it runs second).
$testSuites = @(
@@ -39,7 +39,7 @@ $testSuites = @(
@{ Pattern = "harness_bg_modality_test-*.exe";Label = "harness_bg_modality_test";Extra = @("--ignored") }
)
-# ── stage harness binaries to %TEMP% (same Zone-3 ShellExecute workaround) ──
+# -- stage harness binaries to %TEMP% (same Zone-3 ShellExecute workaround) --
$harnessRoots = @(
@{ Src = "C:\cua-driver-rs\test-apps\harness-wpf"; EnvVar = "HARNESS_WPF_EXE"; Exe = "CuaTestHarness.Wpf.exe" },
@{ Src = "C:\cua-driver-rs\test-apps\harness-winui3"; EnvVar = "HARNESS_WINUI3_EXE"; Exe = "CuaTestHarness.WinUI3.exe" },
@@ -49,24 +49,24 @@ $harnessRoots = @(
)
foreach ($h in $harnessRoots) {
if (-not (Test-Path $h.Src)) {
- Log "harness $($h.Exe) not built — $($h.EnvVar) tests will skip"
+ Log "harness $($h.Exe) not built - $($h.EnvVar) tests will skip"
continue
}
$dst = Join-Path $env:TEMP (Split-Path $h.Src -Leaf)
Copy-Item $h.Src $dst -Recurse -Force
# Confirm the publish output actually contains the exe before exporting
- # the env var — a partial publish would otherwise turn an expected skip
+ # the env var - a partial publish would otherwise turn an expected skip
# into a hard launch failure inside the Rust test.
$stagedExe = Join-Path $dst $h.Exe
if (-not (Test-Path $stagedExe)) {
- Log "WARNING: staged harness exe missing at $stagedExe — $($h.EnvVar) tests will skip"
+ Log "WARNING: staged harness exe missing at $stagedExe - $($h.EnvVar) tests will skip"
continue
}
Set-Item "Env:$($h.EnvVar)" $stagedExe
Log "$($h.Exe) staged to $dst (env $($h.EnvVar)=$stagedExe)"
}
-# ── optional test filter ────────────────────────────────────────────────────
+# -- optional test filter ----------------------------------------------------
$filterSuite = ""
if (Test-Path "C:\sandbox-output\test-filter.txt") {
$filterSuite = (Get-Content "C:\sandbox-output\test-filter.txt" -Raw).Trim()
diff --git a/libs/cua-driver/test-harness/apps/cross-platform/tauri/src-tauri/icons/icon.ico b/libs/cua-driver/test-harness/apps/cross-platform/tauri/src-tauri/icons/icon.ico
new file mode 100644
index 0000000000..d1d851e274
Binary files /dev/null and b/libs/cua-driver/test-harness/apps/cross-platform/tauri/src-tauri/icons/icon.ico differ