Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
test(cua-driver): keep real-input protocol tests out of plain cargo test (#4100)
Francesco Bonacci835190a287bb
diff --git a/.github/workflows/ci-cua-driver-contract-clients.yml b/.github/workflows/ci-cua-driver-contract-clients.ymlindex 90c13c9a56..f69b5f1704 100644--- a/.github/workflows/ci-cua-driver-contract-clients.yml+++ b/.github/workflows/ci-cua-driver-contract-clients.yml@@ -159,11 +159,15 @@ jobs:- name: Prove portable contracts match the live registryif: runner.os != 'Windows' || steps.windows-session.outputs.session_id != '0'working-directory: libs/cua-driver/rust+ env:+ CUA_TEST_REQUIRE_DRIVER_BIN: "1"run: cargo test --locked -p cua-driver --test schema_consistency_test portable_desktop_contracts_are_accepted_by_active_backend- name: Verify released CLI and MCP compatibilityif: runner.os != 'Windows' || steps.windows-session.outputs.session_id != '0'working-directory: libs/cua-driver/rust+ env:+ CUA_TEST_REQUIRE_DRIVER_BIN: "1"run: cargo test --locked -p cua-driver --test compatibility_contract_test- name: Compile the UniFFI SDK librarydiff --git a/.github/workflows/ci-rust-linux.yml b/.github/workflows/ci-rust-linux.ymlindex 281b8b1b3e..0e188b9971 100644--- a/.github/workflows/ci-rust-linux.yml+++ b/.github/workflows/ci-rust-linux.yml@@ -130,6 +130,8 @@ jobs:imagemagick xvfb xauth x11-utils ffmpeg- name: Run Linux Rust testsworking-directory: libs/cua-driver/rust+ env:+ CUA_TEST_REQUIRE_DRIVER_BIN: "1"run: cargo test -p cua-driver -p cua-driver-contract -p cua-driver-core -p cua-driver-testkit -p cursor-overlay -p cursor-theme-cli -p platform-linux --all-targets --locked- name: Compile and link an async-io embedded hostworking-directory: libs/cua-driver/rustdiff --git a/.github/workflows/ci-rust-windows.yml b/.github/workflows/ci-rust-windows.ymlindex 2aa97c0a63..a1ca38facc 100644--- a/.github/workflows/ci-rust-windows.yml+++ b/.github/workflows/ci-rust-windows.yml@@ -139,9 +139,13 @@ jobs:run: .\libs\cua-driver\scripts\tests\uninstall-windows-history-regression.ps1- name: Prove unknown app launch stays bounded and responsiveworking-directory: libs/cua-driver/rust+ env:+ CUA_TEST_REQUIRE_DRIVER_BIN: "1"run: "cargo test -p cua-driver --test protocol_tools_call_test launch_unknown_app_is_bounded_and_keeps_mcp_session_responsive --locked -- --exact --nocapture"- name: Validate desktop AppsFolder launch with Microsoft Edgeworking-directory: libs/cua-driver/rust+ env:+ CUA_TEST_REQUIRE_DRIVER_BIN: "1"run: "cargo test -p cua-driver --test protocol_tools_call_test launch_edge_from_apps_folder_registration --locked -- --ignored --exact --nocapture"- name: Run transport-independent authorization and SDK testsworking-directory: libs/cua-driver/rustdiff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/cli.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/cli.rsindex 61a237dc8a..5c79b6a075 100644--- a/libs/cua-driver/rust/crates/cua-driver-testkit/src/cli.rs+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/cli.rs@@ -13,7 +13,7 @@ use serde_json::Value;use crate::daemon::TestDaemon;use crate::driver::Driver;-use crate::paths::driver_binary;+use crate::paths::{driver_binary, ensure_driver_binary};use crate::reaper::ChildReaper;use crate::response::ToolResponse;@@ -46,7 +46,7 @@ impl CliDriver {}fn with_binary_and_daemon_env(bin: std::path::PathBuf, env: &[(&str, &str)]) -> Self {- if !bin.exists() {+ if !ensure_driver_binary(&bin) {return CliDriver {bin,_reaper: None,diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rsindex 5ee658cf10..c3519e0222 100644--- a/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs@@ -32,6 +32,10 @@//! workspace can override the paths with `CUA_TEST_DRIVER_BIN`,//! `CUA_TEST_APPS_ROOT`, and `CUA_TEST_WORKSPACE_ROOT`. These variables affect//! tests only; they are never read by the shipped driver.+//!+//! A missing driver binary normally makes spawn helpers return `None` so the+//! test skips. CI jobs set `CUA_TEST_REQUIRE_DRIVER_BIN=1` to turn that skip+//! into a panic, so a gate cannot pass without exercising the driver.pub mod ax;mod browser_fixture;@@ -54,7 +58,10 @@ pub use cli::CliDriver;pub use driver::{BehaviorRecording, Driver};pub use journal::FixtureJournal;pub use mcp::McpDriver;-pub use paths::{driver_binary, harness_app, workspace_root};+pub use paths::{+ driver_binary, driver_binary_required, ensure_driver_binary, harness_app, workspace_root,+ REQUIRE_DRIVER_BIN_ENV,+};pub use raw::RawDriver;pub use reaper::{spawn_in_job, ChildReaper};pub use response::ToolResponse;diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/mcp.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/mcp.rsindex 45e42c4138..6630e04bbf 100644--- a/libs/cua-driver/rust/crates/cua-driver-testkit/src/mcp.rs+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/mcp.rs@@ -11,7 +11,7 @@ use serde_json::Value;use crate::daemon::TestDaemon;use crate::driver::{BehaviorRecording, Driver};-use crate::paths::driver_binary;+use crate::paths::{driver_binary, ensure_driver_binary};use crate::reaper::{spawn_in_job, ChildReaper};use crate::response::ToolResponse;use crate::CALL_TIMEOUT;@@ -64,6 +64,7 @@ impl McpDriver {/// Spawn the driver, start the stdout reader thread, and `initialize`./// Returns `None` (with a skip message) if the binary isn't built — the/// caller's test should early-return so an un-built binary skips, not fails.+ /// `CUA_TEST_REQUIRE_DRIVER_BIN=1` makes a missing binary panic instead.pub fn spawn() -> Option<Self> {Self::spawn_internal(&[], &[], None, false, true)}@@ -172,8 +173,7 @@ impl McpDriver {("CUA_DRIVER_DANGEROUSLY_BYPASS_APPROVALS", "1"),]);}- if !bin.exists() {- eprintln!("[testkit] driver binary not built at {bin:?} — skipping");+ if !ensure_driver_binary(&bin) {return None;}diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/paths.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/paths.rsindex 2aafd74cbc..eee6b7f24a 100644--- a/libs/cua-driver/rust/crates/cua-driver-testkit/src/paths.rs+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/paths.rs@@ -5,7 +5,7 @@//! under test (`crates/cua-driver`), so `workspace_root()` resolves the same//! whether called from the test or from here.-use std::path::PathBuf;+use std::path::{Path, PathBuf};/// The Rust workspace root (`libs/cua-driver/rust`).pub fn workspace_root() -> PathBuf {@@ -54,6 +54,45 @@ pub fn driver_binary() -> PathBuf {root.join("target/debug").join(name)}+/// Environment switch that turns a missing driver binary into a test failure.+///+/// Local runs keep the historical behavior: a test whose driver binary is not+/// built logs a skip note and returns early. CI jobs that gate on these tests+/// set `CUA_TEST_REQUIRE_DRIVER_BIN=1` so a missing or misrouted binary fails+/// loudly instead of passing without exercising the driver.+pub const REQUIRE_DRIVER_BIN_ENV: &str = "CUA_TEST_REQUIRE_DRIVER_BIN";++/// Whether `CUA_TEST_REQUIRE_DRIVER_BIN` requests strict binary resolution.+pub fn driver_binary_required() -> bool {+ std::env::var(REQUIRE_DRIVER_BIN_ENV).is_ok_and(|value| {+ matches!(+ value.trim().to_ascii_lowercase().as_str(),+ "1" | "true" | "yes"+ )+ })+}++/// Returns whether `bin` exists. A missing binary panics when+/// [`REQUIRE_DRIVER_BIN_ENV`] is set, and otherwise logs a skip note so the+/// caller can return early.+pub fn ensure_driver_binary(bin: &Path) -> bool {+ check_driver_binary(bin, driver_binary_required())+}++fn check_driver_binary(bin: &Path, required: bool) -> bool {+ if bin.exists() {+ return true;+ }+ if required {+ panic!(+ "[testkit] driver binary not built at {bin:?}; {REQUIRE_DRIVER_BIN_ENV}=1 \+ forbids skipping. Build cua-driver or point CUA_TEST_DRIVER_BIN at it."+ );+ }+ eprintln!("[testkit] driver binary not built at {bin:?} — skipping");+ false+}+/// A built harness app under `test-apps/<dir>/<exe>` (produced by/// `tests/fixtures/build/{windows.ps1,macos.sh}`). Example:/// `harness_app("harness-wpf", "CuaTestHarness.Wpf.exe")`.@@ -66,8 +105,8 @@ pub fn harness_app(dir: &str, exe: &str) -> PathBuf {#[cfg(test)]mod tests {- use super::{driver_binary, harness_app, workspace_root};- use std::path::PathBuf;+ use super::{check_driver_binary, driver_binary, harness_app, workspace_root};+ use std::path::{Path, PathBuf};fn with_env<F>(name: &str, value: &str, test: F)where@@ -97,4 +136,24 @@ mod tests {);});}++ #[test]+ fn missing_driver_binary_skips_by_default() {+ assert!(!check_driver_binary(+ Path::new("/nonexistent/cua-driver-testkit-missing"),+ false+ ));+ }++ #[test]+ #[should_panic(expected = "CUA_TEST_REQUIRE_DRIVER_BIN=1 forbids skipping")]+ fn missing_driver_binary_panics_when_required() {+ check_driver_binary(Path::new("/nonexistent/cua-driver-testkit-missing"), true);+ }++ #[test]+ fn present_driver_binary_is_accepted_when_required() {+ let exe = std::env::current_exe().expect("current test executable");+ assert!(check_driver_binary(&exe, true));+ }}diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/raw.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/raw.rsindex 635d5a677c..c65bcb7e6f 100644--- a/libs/cua-driver/rust/crates/cua-driver-testkit/src/raw.rs+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/raw.rs@@ -15,7 +15,7 @@ use std::process::{ChildStdin, ChildStdout, Command, Stdio};use serde_json::Value;use crate::daemon::TestDaemon;-use crate::paths::driver_binary;+use crate::paths::{driver_binary, ensure_driver_binary};use crate::reaper::{spawn_in_job, ChildReaper};/// A spawned cua-driver with raw stdio access and no handshake performed.@@ -37,7 +37,8 @@ impl RawDriver {/// Spawn the driver with piped stdio. Returns `None` (with a skip eprintln)/// if the binary isn't built — callers early-return so an un-built binary- /// skips rather than fails.+ /// skips rather than fails, unless `CUA_TEST_REQUIRE_DRIVER_BIN=1` makes a+ /// missing binary panic.pub fn spawn() -> Option<Self> {Self::spawn_daemon_backed(driver_binary(), false, &[])}@@ -72,8 +73,7 @@ impl RawDriver {overlay_enabled: bool,env: &[(&str, &str)],) -> Option<Self> {- if !bin.exists() {- eprintln!("[testkit] driver binary not built at {bin:?} — skipping");+ if !ensure_driver_binary(&bin) {return None;}let mut reaper = ChildReaper::new();@@ -121,8 +121,7 @@ impl RawDriver {fn spawn_direct_with_args(args: &[&str]) -> Option<Self> {let bin = driver_binary();- if !bin.exists() {- eprintln!("[testkit] driver binary not built at {bin:?} — skipping");+ if !ensure_driver_binary(&bin) {return None;}let mut reaper = ChildReaper::new();diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rsindex fb9a7ed09b..cff3bfeef4 100644--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs@@ -6,6 +6,10 @@//! `debug_image_out`, and the `set_config` screenshot-resize pipeline. Split//! out of the old monolithic `mcp_protocol_test.rs`; mac/windows pairs merge//! and branch only where assertions differ.+//!+//! Tests that dispatch a real click into whichever window is on screen are+//! `#[ignore]`d so a plain `cargo test` never sends input. Run them with+//! `--ignored` only on a disposable desktop.#![cfg(any(target_os = "macos", target_os = "windows"))]@@ -252,6 +256,7 @@ fn zoom_tool_returns_jpeg() {#[test]#[cfg(any(target_os = "macos", target_os = "windows"))]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn zoom_from_zoom_click_round_trip() {//! Verify the zoom → from_zoom click pipeline://! 1. click(from_zoom=true) with no zoom context returns the expected error.@@ -421,6 +426,7 @@ fn recording_session() {#[test]#[cfg(target_os = "macos")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn recording_screenshot_capture() {//! When recording is active and a tool call includes a window_id, a screenshot.png//! should appear alongside action.json in the turn folder.@@ -627,6 +633,7 @@ fn replay_trajectory() {#[test]#[cfg(target_os = "macos")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn click_debug_image_out() {//! click with debug_image_out writes a PNG crosshair file and then proceeds.//! Verifies the debug capture path works end-to-end.diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rsindex df76760fa2..8651c07cda 100644--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs@@ -8,6 +8,11 @@//! one fn and branch only where the platforms differ (list_apps `apps` vs//! `processes`, get_config platform string, check_permissions keys, type_text//! target app, hotkey modifier, etc.).+//!+//! Tests that dispatch real input (scroll, type_text, hotkey, press_key,+//! click, set_value) target whichever window is on screen, so they are+//! `#[ignore]`d and never run under a plain `cargo test`. Run them with+//! `--ignored` only on a disposable desktop.#![cfg(any(target_os = "macos", target_os = "windows"))]@@ -490,6 +495,7 @@ fn get_window_state_returns_both_with_opt_out() {#[test]#[cfg(any(target_os = "macos", target_os = "windows"))]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn scroll_tool() {//! scroll with direction=down, by=line, amount=1 against the first available window.//! Verifies the tool is accepted and returns content, not a protocol error.@@ -539,6 +545,7 @@ fn scroll_tool() {#[test]#[cfg(target_os = "macos")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn type_text_tool() {//! Opens TextEdit (or reuses it if already running) and types a short string via type_text.//! Skips gracefully if TextEdit is not available or has no window.@@ -606,6 +613,7 @@ fn type_text_tool() {#[test]#[cfg(target_os = "windows")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn type_text_notepad() {//! Launch Notepad, type a short string via type_text. Skips if Notepad unavailable.let Some(mut d) = spawn_unrestricted() else {@@ -673,6 +681,7 @@ fn type_text_notepad() {#[test]#[cfg(target_os = "macos")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn type_text_chars_tool() {//! Verify type_text_chars with delay_ms is accepted without error (dry-run via TextEdit or//! a pid that accepts WM_CHAR). We just verify the tool responds with a non-error.@@ -754,6 +763,7 @@ fn type_text_chars_tool() {#[test]#[cfg(any(target_os = "macos", target_os = "windows"))]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn hotkey_keys_array() {//! Verify hotkey accepts a keys array without a protocol error.let Some(mut d) = spawn_unrestricted() else {@@ -803,6 +813,7 @@ fn hotkey_keys_array() {#[test]#[cfg(any(target_os = "macos", target_os = "windows"))]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn press_key_harmless() {//! press_key with a harmless key (F24 — virtually no app responds to it) sent to the//! first available window. Just verifies the tool doesn't return a protocol error.@@ -844,6 +855,7 @@ fn press_key_harmless() {#[test]#[cfg(any(target_os = "macos", target_os = "windows"))]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn click_pixel_path() {//! click at window-local (5, 5) — title bar area, safe to click without disrupting UI.//! Verifies the pixel-coordinate path for click works without a protocol error.@@ -884,6 +896,7 @@ fn click_pixel_path() {#[test]#[cfg(target_os = "windows")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn double_click_and_right_click() {let Some(mut d) = spawn_unrestricted() else {return;@@ -936,6 +949,7 @@ fn double_click_and_right_click() {#[test]#[cfg(target_os = "macos")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn double_click_and_right_click_pixel_path() {//! double_click and right_click at title-bar coords — verifies both tools accept pixel path.let Some(mut d) = spawn_unrestricted() else {@@ -997,6 +1011,7 @@ fn double_click_and_right_click_pixel_path() {#[test]#[cfg(target_os = "macos")]+#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]fn set_value_via_element_index() {//! get_window_state on TextEdit → find a text-area element → set_value on it.//! Skips gracefully if TextEdit is not available.