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.

fix(cua-bench): fail fast on unsupported Windows Arena hosts (#5356)

injaneity2236b5372a37
diff --git a/libs/cua-bench/cua_bench/tests/test_winarena_platform_requirements.py b/libs/cua-bench/cua_bench/tests/test_winarena_platform_requirements.py
new file mode 100644
index 0000000000..371d5e0e11
--- /dev/null
+++ b/libs/cua-bench/cua_bench/tests/test_winarena_platform_requirements.py
@@ -0,0 +1,61 @@
+"""Platform requirement tests for the Windows Arena adapter.
+
+Windows Arena boots a Windows guest through QEMU with KVM acceleration, so it
+needs an x86_64 host with /dev/kvm. Only the supported-host test exercises the
+real machine and is skipped elsewhere; the rejection tests monkeypatch the host
+so they run on every platform, not just hosts where the guard already passes.
+
+This test lives under ``cua_bench/tests`` rather than next to the adapter: the
+adapter's ``__init__.py`` eagerly imports evaluator dependencies, so pytest
+cannot collect a test inside ``tasks/winarena_adapter`` once the whole-module
+skip is removed. Loading ``cli.py`` by path keeps the guard testable with only
+the standard library available.
+"""
+
+import importlib.util
+import os
+import platform
+from pathlib import Path
+
+import pytest
+
+CLI_PATH = Path(__file__).resolve().parents[2] / "tasks" / "winarena_adapter" / "cli.py"
+
+
+def _load_cli():
+ spec = importlib.util.spec_from_file_location("winarena_adapter_cli", CLI_PATH)
+ assert spec is not None and spec.loader is not None
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+ platform.machine().lower() not in ("x86_64", "amd64") or not os.path.exists("/dev/kvm"),
+ reason="Windows Arena requires an x86_64 host with KVM (/dev/kvm)",
+)
+def test_supported_host_passes_requirements():
+ cli = _load_cli()
+ cli.check_platform_requirements()
+
+
+def test_non_x86_64_hosts_are_rejected(monkeypatch):
+ cli = _load_cli()
+ monkeypatch.setattr(cli.platform, "machine", lambda: "arm64")
+ with pytest.raises(RuntimeError, match="x86_64"):
+ cli.check_platform_requirements()
+
+
+def test_missing_kvm_is_rejected(monkeypatch):
+ cli = _load_cli()
+ monkeypatch.setattr(cli.platform, "machine", lambda: "x86_64")
+ monkeypatch.setattr(cli.os.path, "exists", lambda path: False)
+ with pytest.raises(RuntimeError, match="KVM"):
+ cli.check_platform_requirements()
+
+
+def test_no_kvm_flag_accepts_software_emulation(monkeypatch):
+ cli = _load_cli()
+ monkeypatch.setattr(cli.platform, "machine", lambda: "x86_64")
+ monkeypatch.setattr(cli.os.path, "exists", lambda path: False)
+ cli.check_platform_requirements(no_kvm=True)
diff --git a/libs/cua-bench/tasks/winarena_adapter/cli.py b/libs/cua-bench/tasks/winarena_adapter/cli.py
index 2aec4dbf3d..d1983ac48f 100644
--- a/libs/cua-bench/tasks/winarena_adapter/cli.py
+++ b/libs/cua-bench/tasks/winarena_adapter/cli.py
@@ -15,6 +15,7 @@ Usage:
import argparse
import os
+import platform
import subprocess
import sys
import urllib.request
@@ -48,6 +49,28 @@ def check_docker():
return False
+def check_platform_requirements(no_kvm: bool = False) -> None:
+ """Fail fast on hosts that cannot run the Windows Arena VM.
+
+ The benchmark boots a Windows guest through QEMU with KVM acceleration, so
+ it needs an x86_64 host with /dev/kvm. Unsupported hosts would otherwise
+ wait on a container that never becomes ready; pass ``no_kvm=True`` only to
+ accept software emulation on an x86_64 host.
+ """
+ machine = platform.machine().lower()
+ if machine not in ("x86_64", "amd64"):
+ raise RuntimeError(
+ f"Windows Arena requires an x86_64 host with KVM; detected {platform.machine()}. "
+ "macOS and other non-x86_64 hosts cannot run the Windows VM locally."
+ )
+ if not no_kvm and not os.path.exists("/dev/kvm"):
+ raise RuntimeError(
+ "Windows Arena requires KVM for local execution, but /dev/kvm was not found. "
+ "Use a Linux host with virtualization enabled, or pass --no-kvm to accept "
+ "software emulation (significantly slower)."
+ )
+
+
def check_image_exists(image_name: str) -> bool:
"""Check if a Docker image exists locally."""
try:
@@ -143,6 +166,8 @@ def cmd_vm_setup(args):
4. Waits for Windows to fully initialize (~45-60 minutes)
5. Gracefully shuts down to create a persistent base image
"""
+ check_platform_requirements(getattr(args, "no_kvm", False))
+
if not check_docker():
print("Error: Docker is not running. Please start Docker and try again.")
return 1
@@ -346,6 +371,8 @@ def cmd_vm_setup(args):
def cmd_vm_start(args):
"""Start the base image for testing/development."""
+ check_platform_requirements(getattr(args, "no_kvm", False))
+
if not check_docker():
print("Error: Docker is not running. Please start Docker and try again.")
return 1
@@ -578,6 +605,8 @@ def cmd_task_list(args):
def cmd_task_run(args):
"""Run the Windows Arena container with a specific task."""
+ check_platform_requirements(getattr(args, "no_kvm", False))
+
if not check_docker():
print("Error: Docker is not running. Please start Docker and try again.")
return 1