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
fix(cua): stabilize the known flaky release-gate tests (#5538)
Francesco Bonaccic3b557e1dced
diff --git a/.github/workflows/ci-cua-contrib.yml b/.github/workflows/ci-cua-contrib.ymlindex 8c1fd66545..44aaaaeada 100644--- a/.github/workflows/ci-cua-contrib.yml+++ b/.github/workflows/ci-cua-contrib.yml@@ -95,7 +95,24 @@ jobs:with:go-version-file: libs/cua/crates/cua-contrib/modal-helper/go.modcache-dependency-path: libs/cua/crates/cua-contrib/modal-helper/go.sum+ # Module downloads from proxy.golang.org time out now and then. setup-go+ # restores the module cache by go.sum; a miss downloads here with retries+ # and a fallback proxy (the pipe tries the next on any error), so a slow+ # proxy no longer fails vet, test or build.+ - name: Download modules (retried, fallback proxy)+ env:+ GOPROXY: https://proxy.golang.org|https://goproxy.io|direct+ run: |+ for attempt in 1 2 3 4; do+ go mod download && exit 0+ echo "::warning::go mod download failed (attempt $attempt)"+ sleep $((attempt * 15))+ done+ exit 1- name: Vet, test and build+ env:+ GOPROXY: https://proxy.golang.org|https://goproxy.io|direct+ GOFLAGS: -mod=readonlyrun: |test -z "$(gofmt -l .)" || { gofmt -l .; exit 1; }go vet ./...diff --git a/.github/workflows/nightly-contrib-doctor.yml b/.github/workflows/nightly-contrib-doctor.ymlindex 0580b22910..e2b9062354 100644--- a/.github/workflows/nightly-contrib-doctor.yml+++ b/.github/workflows/nightly-contrib-doctor.yml@@ -91,7 +91,11 @@ jobs:go-version-file: libs/cua/crates/cua-contrib/modal-helper/go.mod- if: steps.key.outputs.run == 'true' && matrix.provider == 'modal'working-directory: libs/cua/crates/cua-contrib/modal-helper+ env:+ # Fallback proxy: a slow proxy.golang.org must not fail the lane.+ GOPROXY: https://proxy.golang.org|https://goproxy.io|directrun: |+ for attempt in 1 2 3 4; do go mod download && break; sleep $((attempt * 15)); donego build -o "$RUNNER_TEMP/bin/cua-modal-helper" .echo "CUA_MODAL_HELPER=$RUNNER_TEMP/bin/cua-modal-helper" >>"$GITHUB_ENV"- id: sandboxdiff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/DaemonRespawnTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/DaemonRespawnTests.swiftindex 653c6a57fd..33698cd1a1 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/DaemonRespawnTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/DaemonRespawnTests.swift@@ -69,7 +69,11 @@ import Testing#expect(await eventually(60) { daemon.lock.withLock { daemon.starts } == 1 })#expect(await eventually(60) { daemon.lock.withLock { daemon.restarted } == 1 })- // The new daemon is watched too.+ // The new daemon is watched too. The supervisor watches the new pid+ // only after its confirming probe (the second one: the miss, then+ // this one), so wait for that probe instead of a fixed sleep; a kill+ // before the watch is armed is never seen until the next hourly probe.+ #expect(await eventually(60) { daemon.lock.withLock { daemon.probes } >= 2 })try await Task.sleep(for: .milliseconds(200))daemon.kill()#expect(await eventually(60) { daemon.lock.withLock { daemon.starts } == 2 })diff --git a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/harness_appkit_test.rs b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/harness_appkit_test.rsindex e2e712e3a7..e6944f6af5 100644--- a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/harness_appkit_test.rs+++ b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/harness_appkit_test.rs@@ -1097,19 +1097,21 @@ fn harness_appkit_invoke_menu_live_path() {invoked.text());assert_eq!(invoked.action_effect(), Some("unverifiable"));- let deadline = std::time::Instant::now() + Duration::from_secs(5);- let mut post = snapshot_elements(driver, pid, wid);- while !post.tree_text().contains("menu_action=window_arrange_left")- && std::time::Instant::now() < deadline- {- std::thread::sleep(Duration::from_millis(50));- post = snapshot_elements(driver, pid, wid);+ // Poll for the fixture's menu_action instead of sleeping a fixed+ // 300 ms: a loaded runner delivers the action later.+ let deadline = std::time::Instant::now() + Duration::from_secs(10);+ loop {+ let post = snapshot_elements(driver, pid, wid);+ if post.tree_text().contains("menu_action=window_arrange_left") {+ break;+ }+ assert!(+ std::time::Instant::now() < deadline,+ "menu action did not reach fixture: {}",+ post.tree_text()+ );+ std::thread::sleep(Duration::from_millis(100));}- assert!(- post.tree_text().contains("menu_action=window_arrange_left"),- "menu action did not reach fixture: {}",- post.tree_text()- );Observation::delivered(vec![OracleKind::FixtureState], Evidence::default())},);diff --git a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rsindex a88bcab775..3813c3f665 100644--- a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs+++ b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs@@ -2942,12 +2942,21 @@ fn run_existing_profile_setup(spec: &BrowserSpec) {prepared.structured()["side_effects"]["created_profile"],false);- let setup_port = devtools_active_port(fixture._profile.path()).unwrap_or_else(|| {- panic!(- "existing-profile setup exposed no DevToolsActivePort in {}",+ // The browser writes DevToolsActivePort when its listener comes up,+ // which can trail the setup call's return (slow on Windows runners):+ // poll for it instead of reading the file once.+ let port_deadline = Instant::now() + Duration::from_secs(15);+ let setup_port = loop {+ if let Some(port) = devtools_active_port(fixture._profile.path()) {+ break port;+ }+ assert!(+ Instant::now() < port_deadline,+ "existing-profile setup exposed no DevToolsActivePort in {} within 15 s",fixture._profile.path().display()- )- });+ );+ std::thread::sleep(Duration::from_millis(100));+ };let public_result = prepared.raw.to_string();assert!(!public_result.contains("ws://"), "{}", prepared.raw);diff --git a/libs/cua-driver/scripts/tests/update-apply-windows-e2e.ps1 b/libs/cua-driver/scripts/tests/update-apply-windows-e2e.ps1index 22b6814b93..d7744c9dc8 100644--- a/libs/cua-driver/scripts/tests/update-apply-windows-e2e.ps1+++ b/libs/cua-driver/scripts/tests/update-apply-windows-e2e.ps1@@ -62,8 +62,23 @@ $versions = @($tags.Output -split "`r?`n" |ForEach-Object { [version]($_ -replace '^cua-driver-rs-v', '') } |Where-Object { $withdrawn -notcontains $_.ToString() } |Sort-Object -Descending -Unique)-Assert-True ($versions.Count -ge 2) 'need two published releases to test an update'-$from = $versions[1].ToString()+# The updater's stable channel resolves the version baked into the published+# installer, which lags the newest release until that release is promoted.+# Update from the release below that version, or "Already up to date" is the+# correct (and failing) answer here.+$latest = $versions[0]+try {+ $script = (Invoke-WebRequest -UseBasicParsing -Uri 'https://cua.ai/driver/_install-rust.sh').Content+ if ($script -match '(?m)^CUA_DRIVER_RS_BAKED_VERSION="v?(\d+\.\d+\.\d+)"') {+ $latest = [version]$Matches[1]+ }+} catch {+ Write-Host "could not read the installer's baked version, using the newest release: $_"+}+Write-Host "Updater target (installer's stable version): $latest"+$versions = @($versions | Where-Object { $_ -lt $latest })+Assert-True ($versions.Count -ge 1) 'need a published release below the updater target to test an update'+$from = $versions[0].ToString()Write-Host "Updating from cua-driver $from"$testRoot = Join-Path ([System.IO.Path]::GetTempPath()) ('cua-driver-update-apply-' + [guid]::NewGuid().ToString('N'))diff --git a/libs/cua/crates/cua-spacesd-client/tests/client.rs b/libs/cua/crates/cua-spacesd-client/tests/client.rsindex 513e01d6e8..8762c13b1d 100644--- a/libs/cua/crates/cua-spacesd-client/tests/client.rs+++ b/libs/cua/crates/cua-spacesd-client/tests/client.rs@@ -66,18 +66,33 @@ fn data(len: usize, seed: u64) -> Bytes {out.into()}+/// Per-test watchdog. A hung test (`grpc_web::stdin_roundtrip` once sat until+/// the CI job's 60 minute timeout) fails here with its name and transport+/// instead. The budget is generous for a loopback test; the large transfers+/// and the keepalive test get more.+async fn watchdog<F: std::future::Future<Output = ()>>(name: &str, transport: &str, fut: F) {+ let budget = if name.contains("256_mib") || name.contains("keepalive") {+ Duration::from_secs(300)+ } else {+ Duration::from_secs(90)+ };+ if tokio::time::timeout(budget, fut).await.is_err() {+ panic!("{transport}::{name} hung: no result within {budget:?}");+ }+}+macro_rules! both_transports {($($name:ident),* $(,)?) => {mod native {$(#[tokio::test(flavor = "multi_thread", worker_threads = 4)]- async fn $name() { super::$name(cua_spacesd_client::Transport::Native).await }+ async fn $name() { super::watchdog(stringify!($name), "native", super::$name(cua_spacesd_client::Transport::Native)).await })*}mod grpc_web {$(#[tokio::test(flavor = "multi_thread", worker_threads = 4)]- async fn $name() { super::$name(cua_spacesd_client::Transport::GrpcWeb).await }+ async fn $name() { super::watchdog(stringify!($name), "grpc_web", super::$name(cua_spacesd_client::Transport::GrpcWeb)).await })*}};diff --git a/libs/cua/crates/cua-telemetry/tests/privacy.rs b/libs/cua/crates/cua-telemetry/tests/privacy.rsindex ebe929062c..c6946b77a2 100644--- a/libs/cua/crates/cua-telemetry/tests/privacy.rs+++ b/libs/cua/crates/cua-telemetry/tests/privacy.rs@@ -781,20 +781,19 @@ fn capture_never_blocks_on_a_slow_or_dead_endpoint() {.product("cli", "1.0.0").build();t.acknowledge_notice();+ // The endpoint never answers, so a capture or flush that waited on it+ // would take the sink's whole send timeout (3 s) or more. Bound the+ // elapsed time just under that: it separates blocking from not blocking+ // without a wall-clock budget a loaded runner can exceed.+ let ceiling = cua_telemetry::sink::SEND_TIMEOUT - Duration::from_millis(500);let start = std::time::Instant::now();for _ in 0..20 {t.capture(events::sandbox_deleted("local", Outcome::Ok, None));}- assert!(- start.elapsed() < Duration::from_millis(500),- "capture blocked"- );+ assert!(start.elapsed() < ceiling, "capture blocked");let start = std::time::Instant::now();t.flush(Duration::from_millis(300));- assert!(- start.elapsed() < Duration::from_secs(2),- "flush exceeded its budget"- );+ assert!(start.elapsed() < ceiling, "flush exceeded its budget");drop(listener);}diff --git a/scripts/ci/linux/run-valgrind-e2e.py b/scripts/ci/linux/run-valgrind-e2e.pyindex 4236f8fd4f..0a9b6da8e5 100755--- a/scripts/ci/linux/run-valgrind-e2e.py+++ b/scripts/ci/linux/run-valgrind-e2e.py@@ -384,7 +384,13 @@ def run_e2e(driver: Path, artifact_dir: Path, smoke_dir: Path, env: dict[str, sttry:ready = False- for _ in range(120):+ # Under Memcheck the server starts 10 to 20 times slower than native+ # and a connection refused returns at once, so the old 120 tries of+ # 0.5 s gave it only 60 s. Wait against a deadline instead, scalable+ # for a slower runner.+ startup_timeout = float(os.environ.get("CUA_VALGRIND_STARTUP_TIMEOUT", "240"))+ startup_deadline = time.monotonic() + startup_timeout+ while time.monotonic() < startup_deadline:if process.poll() is not None:raise RunnerFailure("cua-driver server exited before readiness")try:@@ -403,7 +409,9 @@ def run_e2e(driver: Path, artifact_dir: Path, smoke_dir: Path, env: dict[str, stbreaktime.sleep(0.5)if not ready:- raise RunnerFailure("cua-driver server did not become ready within 60 seconds")+ raise RunnerFailure(+ f"cua-driver server did not become ready within {startup_timeout:g} seconds"+ )readiness = load_json(artifact_dir / "readiness.json")expect(diff --git a/tests/e2e/cua-sdk/python/e2e.py b/tests/e2e/cua-sdk/python/e2e.pyindex 6c3e7e6929..0adc29f128 100644--- a/tests/e2e/cua-sdk/python/e2e.py+++ b/tests/e2e/cua-sdk/python/e2e.py@@ -487,13 +487,15 @@ async def window_origin(env: "cua.SpacesdClient", title: str) -> tuple[int, int]'n=$(xwininfo -id "$wid" | awk "/Absolute upper-left X/{x=\\$4} /Absolute upper-left Y/{y=\\$4} END{print x, y}"); ''[ "$n" = "$o" ] && break; o=$n; done; echo "$n"')- out = await poll(- f"window {title!r}",- lambda: env.sh(f"desktop-env bash -c '{script}'", 20_000),- attempts=30,- delay=1,- )- x, y = out.stdout.decode().split()+ async def origin():+ # The result object is always truthy, and the script prints nothing+ # (or a blank origin) while the window is not mapped yet: only accept+ # an actual "x y" pair so poll() retries instead of unpacking nothing.+ out = await env.sh(f"desktop-env bash -c '{script}'", 20_000)+ parts = out.stdout.decode().split()+ return parts if len(parts) == 2 else None++ x, y = await poll(f"window {title!r}", origin, attempts=30, delay=1)return int(x), int(y)