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(ci): cua-auth tests never ran on GitHub; fix the broken flows tests (CUA-3363) (#6478)
Francesco Bonacci1d18983a470c
diff --git a/.github/scripts/tests/test_ci_cua_workspace_tests.py b/.github/scripts/tests/test_ci_cua_workspace_tests.pynew file mode 100644index 0000000000..326c25c3fa--- /dev/null+++ b/.github/scripts/tests/test_ci_cua_workspace_tests.py@@ -0,0 +1,112 @@+"""Every libs/cua crate that has tests runs them in GitHub CI, or says why not.++The Linux Rust lane (ci-cua-sdk.yml, `rust-linux`) lists its crates by hand+with `-p`. A crate missing from the list is never tested there, and a path+filter cannot see that: cua-auth's tests were skipped this way, so three+broken flows tests merged green (CUA-3363). This test makes the list and the+workspace agree.+"""++import functools+import re+import sys+from pathlib import Path++import pytest+import yaml++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))++import ci_gate_scope as scope # noqa: E402+import ci_graph # noqa: E402++ROOT = Path(__file__).resolve().parents[3]+CUA = ROOT / "libs/cua"+WORKFLOW = ROOT / ".github/workflows/ci-cua-sdk.yml"++# Crates with tests that the Linux lane does not run, and where they run (or+# why they do not). Adding a crate here is a decision; leaving it out of both+# places fails this test.+ELSEWHERE = {+ "cua-keyvault": "macOS Keychain and SwiftUI identity tests: ci-cua-spaces-macos.yml",+ "cua-image": "needs registry and platform helpers; run by bin/ci and the image workflows",+ "cua-host": "launchd service tests; run by bin/ci on macOS, not yet checked on Linux",+ "cua-ci": "experiment (`cua ci`); no CI lane yet",+ "cua-replica-lab": "chaos rig, not shipped; run by hand",+}+++def members():+ text = (CUA / "Cargo.toml").read_text()+ block = re.search(r"members\s*=\s*\[(.*?)\]", text, re.S).group(1)+ block = re.sub(r"#[^\n]*", "", block)+ return re.findall(r'"([^"]+)"', block)+++def package_name(crate_dir):+ text = (CUA / crate_dir / "Cargo.toml").read_text()+ return re.search(r'\[package\].*?\bname\s*=\s*"([^"]+)"', text, re.S).group(1)+++def has_tests(crate_dir):+ d = CUA / crate_dir+ if list(d.glob("tests/*.rs")):+ return True+ return any(re.search(r"#\[(tokio::)?test\b", p.read_text(errors="ignore")) for p in d.glob("src/**/*.rs"))++[email protected]_cache(maxsize=None)+def tested_packages():+ """Packages named with `-p` on a `cargo test` / `cargo nextest` command in any workflow."""+ found = set()+ for wf in sorted((ROOT / ".github/workflows").glob("*.yml")):+ doc = yaml.safe_load(wf.read_text()) or {}+ for job in (doc.get("jobs") or {}).values():+ for step in job.get("steps") or []:+ run = (step.get("run") or "").replace("\\\n", " ")+ for cmd in re.split(r"\n|&&|;", run):+ if re.search(r"cargo (nextest run|test)\b", cmd):+ found |= set(re.findall(r"(?:^|\s)(?:-p|--package)[ =](\S+)", cmd))+ return frozenset(found)+++def nextest_packages():+ jobs = yaml.safe_load(WORKFLOW.read_text())["jobs"]+ for step in jobs["rust-linux"]["steps"]:+ run = step.get("run", "")+ if "cargo nextest run" in run:+ return set(re.findall(r"(?:^|\s)-p\s+(\S+)", run))+ raise AssertionError("rust-linux has no cargo nextest step")+++TESTED = sorted(package_name(m) for m in members() if has_tests(m))++[email protected]("name", TESTED)+def test_a_crate_with_tests_runs_them_in_the_linux_lane_or_says_why_not(name):+ assert name in tested_packages() or name in ELSEWHERE, (+ f"{name} has tests but is not named with `-p` on any `cargo test` or `cargo nextest` step in "+ f".github/workflows: its tests never run on GitHub. Add it to the rust-linux nextest list in ci-cua-sdk.yml, or to ELSEWHERE with the reason."+ )+++def test_the_exceptions_are_not_stale():+ listed = tested_packages()+ assert not (set(ELSEWHERE) & listed), "in the lane now: drop it from ELSEWHERE"+ assert set(ELSEWHERE) <= set(TESTED), "no longer a crate with tests: drop it from ELSEWHERE"+++def test_the_lane_names_only_workspace_crates():+ names = {package_name(m) for m in members()}+ assert nextest_packages() <= names+++def test_a_cua_auth_change_always_reaches_the_lane_that_tests_it():+ cfg = scope.load_map()+ graph = ci_graph.load()+ for f in ("libs/cua/crates/cua-auth/tests/flows.rs", "libs/cua/crates/cua-auth/src/lib.rs"):+ areas, skip = scope.scope([f], cfg, graph)+ assert "cua" in areas+ assert "ci-cua-sdk.yml" not in skip+ on = yaml.safe_load(WORKFLOW.read_text())[True]+ assert "libs/cua/**" in on["pull_request"]["paths"]diff --git a/.github/workflows/ci-cua-sdk.yml b/.github/workflows/ci-cua-sdk.ymlindex 7d88a1525a..8a5a475c2b 100644--- a/.github/workflows/ci-cua-sdk.yml+++ b/.github/workflows/ci-cua-sdk.yml@@ -250,7 +250,10 @@ jobs:-p cua-sdk -p cua-daemon -p cua-cli -p cua-spacesd-client-p cua-cluster -p cua-spaces-cluster-p cua-teleport -p cua-teleport-bundle -p cua-chromium-storage -p cua-volume- -p cua-spaces-ext -p cua-spaces-ffi -p cua-spaces-cli --test-threads 4+ -p cua-spaces-ext -p cua-spaces-ffi -p cua-spaces-cli+ -p cua-auth -p cua-bindgen -p cua-connections -p cua-crash -p cua-create-failure -p cua-disk -p cua-home+ -p cua-hotspot -p cua-machine-seal -p cua-mock-llm -p cua-push -p cua-repo-cache -p cua-share+ -p cua-snapshot-sync -p cua-spaces-contract -p cua-spaces-transcript --test-threads 4env:# Teleport send acts only on fake hosts in tests; anything that# reaches the real host fails closed.diff --git a/libs/cua/crates/cua-auth/tests/flows.rs b/libs/cua/crates/cua-auth/tests/flows.rsindex 654a4ff9bb..3ed138c429 100644--- a/libs/cua/crates/cua-auth/tests/flows.rs+++ b/libs/cua/crates/cua-auth/tests/flows.rs@@ -9,8 +9,9 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};#[derive(Default)]struct State {pkce_ok: bool,- challenge: Option<String>,- redirect: Option<String>,+ /// Each browser attempt's PKCE challenge, by its redirect URI (every+ /// attempt has its own listener port), as a real issuer keeps per-request state.+ attempts: std::collections::HashMap<String, String>,refreshes: u32,revoked: bool,refresh_dead: bool,@@ -102,8 +103,11 @@ async fn issuer(state: Arc<Mutex<State>>) -> String {let u = url::Url::parse(&format!("http://x{target}")).unwrap();let q: std::collections::HashMap<String, String> =u.query_pairs().into_owned().collect();- g.challenge = q.get("code_challenge").cloned();- g.redirect = q.get("redirect_uri").cloned();+ if let (Some(r), Some(c)) =+ (q.get("redirect_uri"), q.get("code_challenge"))+ {+ g.attempts.insert(r.clone(), c.clone());+ }if g.pkce_ok {(200, json!({}))} else {@@ -118,8 +122,8 @@ async fn issuer(state: Arc<Mutex<State>>) -> String {("POST", "/token") => match form(&body, "grant_type").as_deref() {Some("authorization_code") => {let v = form(&body, "code_verifier").unwrap_or_default();- if Some(cua_auth::pkce_challenge(&v)) != g.challenge- || form(&body, "redirect_uri") != g.redirect+ let r = form(&body, "redirect_uri").unwrap_or_default();+ if Some(&cua_auth::pkce_challenge(&v)) != g.attempts.get(&r)|| form(&body, "code").as_deref() != Some("code-1"){(400, json!({"error": "invalid_grant"}))@@ -369,7 +373,7 @@ async fn a_browser_sign_in_that_cannot_be_saved_says_so_on_the_page_too() {let (redirect, state) = redirect_of(&p);let s2 = s.clone();let done = tokio::spawn(async move { s2.finish_login(p).await });- let r = reqwest::get(format!("{redirect}?code=c&state={state}"))+ let r = reqwest::get(format!("{redirect}?code=code-1&state={state}")).await.unwrap();let (status, page) = (r.status().as_u16(), r.text().await.unwrap());@@ -378,10 +382,37 @@ async fn a_browser_sign_in_that_cannot_be_saved_says_so_on_the_page_too() {// Never "You're signed in" for a session the app then reports as lost.assert_eq!(status, 500);assert!(page.contains("couldn't be saved"), "{page}");+ assert!(page.contains("Sign-in couldn't be saved"), "{page}");assert!(!page.contains("You're signed in"), "{page}");assert!(s.credentials().is_err() || s.credentials().unwrap().is_none());}+#[tokio::test]+async fn a_browser_sign_in_the_issuer_fails_says_it_did_not_finish() {+ let st = Arc::new(Mutex::new(State {+ pkce_ok: true,+ ..Default::default()+ }));+ let url = issuer(st).await;+ let d = tempfile::tempdir().unwrap();+ let s = Arc::new(session(&url, d.path()));+ let p = s.begin_login(Flow::Browser).await.unwrap();+ let (redirect, state) = redirect_of(&p);+ let s2 = s.clone();+ let done = tokio::spawn(async move { s2.finish_login(p).await });+ let r = reqwest::get(format!(+ "{redirect}?error=server_error&error_description=boom&state={state}"+ ))+ .await+ .unwrap();+ let page = r.text().await.unwrap();+ let e = done.await.unwrap().unwrap_err();+ assert!(e.to_string().contains("boom"), "{e}");+ assert!(page.contains("Sign-in didn't finish"), "{page}");+ assert!(!page.contains("You're signed in"), "{page}");+ assert!(s.credentials().unwrap().is_none());+}+#[tokio::test]async fn a_browser_sign_in_saves_before_the_page_says_signed_in() {let st = Arc::new(Mutex::new(State {@@ -395,7 +426,7 @@ async fn a_browser_sign_in_saves_before_the_page_says_signed_in() {let (redirect, state) = redirect_of(&p);let s2 = s.clone();let done = tokio::spawn(async move { s2.finish_login(p).await });- let r = reqwest::get(format!("{redirect}?code=c&state={state}"))+ let r = reqwest::get(format!("{redirect}?code=code-1&state={state}")).await.unwrap();assert_eq!(r.status().as_u16(), 200);@@ -466,7 +497,7 @@ async fn an_earlier_tab_still_signs_in_after_a_retry() {let (a, b) = (s.clone(), s.clone());let first_done = tokio::spawn(async move { a.finish_login(first).await });let retry_done = tokio::spawn(async move { b.finish_login(retry).await });- let r = reqwest::get(format!("{r1}?code=c&state={s1}"))+ let r = reqwest::get(format!("{r1}?code=code-1&state={s1}")).await.unwrap();assert_eq!(r.status().as_u16(), 200);diff --git a/libs/cua/crates/cua-connections/src/generate.rs b/libs/cua/crates/cua-connections/src/generate.rsindex a80463af23..ada191cb37 100644--- a/libs/cua/crates/cua-connections/src/generate.rs+++ b/libs/cua/crates/cua-connections/src/generate.rs@@ -373,7 +373,7 @@ pub fn docs_table(all: &[ProviderDef]) -> String {let word = match (m.kind.as_str(), m.flow.as_str()) {("api_key", _) => "API key",("import_login", "paste") => "A pasted Claude token",- ("import_login", _) => "Your sign-in on this machine",+ ("import_login", _) => "Your sign-in on this computer",("device_code" | "subscription_login", _) => "Plan sign-in",("browser_oauth", _) => "Browser sign-in",("adc", _) => "Cloud credentials",