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
ci: dependency-aware lane scoping for cua-spacesd and contract clients (CUA-1910) (#5540)
Francesco Bonacci24e9a8f429ce
diff --git a/.github/scripts/ci_component_scope.py b/.github/scripts/ci_component_scope.pynew file mode 100644index 0000000000..f09f991e20--- /dev/null+++ b/.github/scripts/ci_component_scope.py@@ -0,0 +1,141 @@+#!/usr/bin/env python3+"""Decide which heavy CI lanes a pull request needs (CUA-1910).++Reads one changed repo-relative path per line on stdin and writes GitHub+Actions outputs (`run`, `matrix`, `reason`) for one lane.++The dependency map below is explicit. The Rust entries are the workspace+closure that `cargo metadata` reports for the lane's workspace, so a crate+outside the closure cannot affect the lane. Shared inputs fail closed: they run+the lane on every OS. The calling workflow's `paths:` filter bounds the rest.++Always the full lane, on every OS:+ * any event other than pull_request (main pushes, nightly, tags, manual);+ * a release-please branch;+ * a change to CI files, shared actions, lockfiles, manifests, toolchain pins+ or this script.+"""++from __future__ import annotations++import json+import os+import re+import sys++DRIVER = "libs/cua-driver/rust/"+LINUX, MACOS, WINDOWS = "linux", "macos", "windows"+ALL_OS = (LINUX, MACOS, WINDOWS)++# Files that can affect every lane and every OS.+SHARED = (+ r"\.github/(workflows|actions)/",+ r"\.github/scripts/ci_component_scope",+ r"scripts/ci/",+ r"(^|.*/)(Cargo\.lock|rust-toolchain\.toml|flake\.lock|package-lock\.json|uv\.lock)$",+ # Workspace roots; a member's own Cargo.toml is covered by its crate path.+ r"libs/(cua-driver/rust|cua-spacesd|cua)/Cargo\.toml$",+ r"(^|.*/)\.cargo/",+ r"libs/cua/proto/",+ r"libs/cua/crates/cua-proto/",+ r"libs/cua-driver/rust/(include|tests)/",+)+# Never changes behaviour.+INERT = (r".*\.md$", r".*/(CHANGELOG\.md|VERSION|LICENSE)$", r"\.release-please-manifest\.json$")++# Driver crates that only compile on one OS.+DRIVER_PLATFORM = {+ DRIVER + "crates/platform-linux/": (LINUX,),+ DRIVER + "crates/platform-macos/": (MACOS,),+ DRIVER + "crates/platform-windows/": (WINDOWS,),+}+# Driver crates every OS compiles.+DRIVER_COMMON = (+ "cua-driver-core", "cua-driver-contract", "cua-driver-sdk", "cua-cursor-motion",+ "cursor-overlay", "pip-preview",+)++LANES = {+ # `cargo metadata` in libs/cua-spacesd: its workspace plus these path crates.+ "spacesd": {+ "labels": {LINUX: "ubuntu-latest", MACOS: "macos-26", WINDOWS: "windows-latest"},+ "common": (+ r"libs/cua-spacesd/",+ *(DRIVER + f"crates/{c}/" for c in DRIVER_COMMON),+ *(+ f"libs/cua/crates/{c}/"+ for c in (+ "cua-chromium-storage", "cua-home", "cua-hotspot", "cua-logging",+ "cua-machine-seal", "cua-media-codec", "cua-media-protocol",+ "cua-media-transport", "cua-mesh", "cua-spacesd-client",+ "cua-spacesd-html5", "cua-telemetry", "cua-teleport-bundle", "cua-volume",+ )+ ),+ r"libs/images/windows-2022/(enable-volume|volume-diagnostics)\.ps1",+ ),+ },+ # Runs the driver CLI and the client SDKs on all three OSes.+ "contract-clients": {+ "labels": {LINUX: "ubuntu-latest", MACOS: "macos-latest", WINDOWS: "windows-latest"},+ "common": (+ r"libs/cua-driver/(contract|compat-fixtures|typescript|python|examples/agent-sdks)/",+ r"libs/cua-driver/scripts/(generate-uniffi-bindings|stage-uniffi-library|build-npm-packages)\.mjs",+ r"libs/python/cua-sandbox/",+ r"\.github/scripts/cua-driver-mcp-compat/",+ *(DRIVER + f"crates/{c}/" for c in DRIVER_COMMON),+ DRIVER + "crates/cua-driver/",+ DRIVER + "crates/cua-driver-bindgen/",+ DRIVER + "crates/cua-driver-testkit/",+ ),+ },+}+++def _any(patterns, path: str) -> bool:+ return any(re.match(p, path) for p in patterns)+++def decide(lane: str, files: list[str], event: str, head_ref: str = "") -> tuple[bool, list[str], str]:+ cfg = LANES[lane]+ full = [cfg["labels"][o] for o in ALL_OS]+ if event != "pull_request":+ return True, full, f"{event} runs the full matrix"+ if head_ref.startswith("release-please--"):+ return True, full, "release PR runs the full matrix"+ if not files:+ return True, full, "no changed files listed, failing closed"+ oses: set[str] = set()+ why = ""+ for f in files:+ if _any(SHARED, f):+ return True, full, f"shared input {f}"+ if _any(INERT, f):+ continue+ if _any(cfg["common"], f):+ return True, full, f"{f} affects every OS"+ for prefix, plat in DRIVER_PLATFORM.items():+ if f.startswith(prefix):+ oses.update(plat)+ why = why or f"{f} affects {plat[0]} only"+ break+ # Anything else is outside the lane's dependency closure.+ if not oses:+ return False, [], "no changed path is in this lane's dependency closure"+ return True, [cfg["labels"][o] for o in ALL_OS if o in oses], why+++def main() -> None:+ lane = sys.argv[1]+ files = [l.strip() for l in sys.stdin if l.strip()]+ run, labels, why = decide(lane, files, os.environ.get("EVENT", "pull_request"), os.environ.get("HEAD_REF", ""))+ out = {"run": str(run).lower(), "matrix": json.dumps(labels), "reason": why}+ for k, v in out.items():+ print(f"{k}={v}")+ path = os.environ.get("GITHUB_OUTPUT")+ if path:+ with open(path, "a") as fh:+ fh.writelines(f"{k}={v}\n" for k, v in out.items())+++if __name__ == "__main__":+ main()diff --git a/.github/scripts/tests/test_ci_component_scope.py b/.github/scripts/tests/test_ci_component_scope.pynew file mode 100644index 0000000000..fb25145951--- /dev/null+++ b/.github/scripts/tests/test_ci_component_scope.py@@ -0,0 +1,63 @@+"""Regression fixtures for ci_component_scope.py (CUA-1910)."""++import sys+import unittest+from pathlib import Path++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+from ci_component_scope import decide # noqa: E402++D = "libs/cua-driver/rust/crates/"+++def run(lane, files, event="pull_request", ref="feature/x"):+ return decide(lane, files, event, ref)+++class ScopeTests(unittest.TestCase):+ def test_docs_only_skips(self):+ for lane in ("spacesd", "contract-clients"):+ self.assertFalse(run(lane, ["docs/content/docs/a.mdx"])[0])+ self.assertFalse(run(lane, ["libs/cua-driver/CHANGELOG.md"])[0])++ def test_spaces_app_only_skips(self):+ files = ["apps/cua-spaces-macos/Sources/A.swift", "libs/cua/crates/cua-spaces-app-core/src/lib.rs"]+ self.assertFalse(run("spacesd", files)[0])+ self.assertFalse(run("contract-clients", files)[0])++ def test_platform_crate_narrows_os(self):+ run_, labels, _ = run("spacesd", [D + "platform-linux/src/x.rs"])+ self.assertTrue(run_)+ self.assertEqual(labels, ["ubuntu-latest"])+ _, labels, _ = run("contract-clients", [D + "platform-macos/src/x.rs", D + "platform-windows/src/y.rs"])+ self.assertEqual(labels, ["macos-latest", "windows-latest"])++ def test_common_driver_crate_runs_all(self):+ run_, labels, _ = run("spacesd", [D + "cua-driver-core/src/lib.rs"])+ self.assertTrue(run_)+ self.assertEqual(len(labels), 3)++ def test_driver_crate_outside_closure_skips_spacesd(self):+ self.assertFalse(run("spacesd", [D + "cua-driver-e2e/tests/a.rs"])[0])+ self.assertFalse(run("spacesd", [D + "cua-driver/src/main.rs"])[0])++ def test_closure_crate_missing_from_old_filter_runs(self):+ self.assertTrue(run("spacesd", ["libs/cua/crates/cua-mesh/src/lib.rs"])[0])++ def test_shared_inputs_run_everything(self):+ for f in (".github/workflows/ci-cua-spacesd.yml", D + "../Cargo.lock", "libs/cua-driver/rust/Cargo.toml",+ "libs/cua/proto/a.proto", ".github/scripts/ci_component_scope.py"):+ run_, labels, _ = run("spacesd", [D + "platform-linux/a.rs", f])+ self.assertTrue(run_, f)+ self.assertEqual(len(labels), 3, f)++ def test_full_matrix_for_release_and_main(self):+ self.assertEqual(len(run("spacesd", ["docs/a.md"], event="push")[1]), 3)+ self.assertEqual(len(run("spacesd", ["docs/a.md"], ref="release-please--branches--main")[1]), 3)++ def test_unknown_listing_fails_closed(self):+ self.assertTrue(run("spacesd", [])[0])+++if __name__ == "__main__":+ unittest.main()diff --git a/.github/workflows/ci-cua-driver-contract-clients.yml b/.github/workflows/ci-cua-driver-contract-clients.ymlindex 13db902472..b754268cac 100644--- a/.github/workflows/ci-cua-driver-contract-clients.yml+++ b/.github/workflows/ci-cua-driver-contract-clients.yml@@ -29,6 +29,7 @@ on:- ".github/scripts/cua-driver-mcp-compat/**"- ".github/workflows/cd-py-cua-driver.yml"- ".github/workflows/ci-cua-driver-contract-clients.yml"+ - ".github/scripts/ci_component_scope.py"push:branches: [main]paths:@@ -58,6 +59,7 @@ on:- ".github/scripts/cua-driver-mcp-compat/**"- ".github/workflows/cd-py-cua-driver.yml"- ".github/workflows/ci-cua-driver-contract-clients.yml"+ - ".github/scripts/ci_component_scope.py"workflow_dispatch:permissions:@@ -76,14 +78,48 @@ env:DO_NOT_TRACK: "1"jobs:+ changes:+ name: "contract clients / changes"+ runs-on: ubuntu-latest+ timeout-minutes: 5+ permissions:+ contents: read+ pull-requests: read+ outputs:+ run: ${{ steps.scope.outputs.run }}+ matrix: ${{ steps.scope.outputs.matrix }}+ steps:+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4+ with:+ sparse-checkout: .github/scripts+ # CUA-1910: pull requests run only the OS lanes the changed paths can+ # reach (explicit dependency map in ci_component_scope.py). Pushes,+ # manual runs and release PRs run everything.+ - id: scope+ env:+ GH_TOKEN: ${{ github.token }}+ EVENT: ${{ github.event_name }}+ HEAD_REF: ${{ github.head_ref }}+ REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ run: |+ set -euo pipefail+ files=""+ if [[ "$EVENT" == pull_request ]]; then+ files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --jq '.[].filename')+ fi+ python3 .github/scripts/ci_component_scope.py contract-clients <<< "$files" | tee -a "$GITHUB_STEP_SUMMARY"+mcp-client-discovery:name: MCP discovery in pinned clients (${{ matrix.os }})+ needs: changes+ if: needs.changes.outputs.run == 'true'runs-on: ${{ matrix.os }}timeout-minutes: 30strategy:fail-fast: falsematrix:- os: [ubuntu-latest, macos-latest, windows-latest]+ os: ${{ fromJSON(needs.changes.outputs.matrix) }}steps:- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4- uses: dtolnay/rust-toolchain@4716b85f2fac3e324e64fa2810f6b5c3905760a5 # 1.97.1@@ -137,12 +173,14 @@ jobs:runtime-parity:name: Portable contract parity (${{ matrix.os }})+ needs: changes+ if: needs.changes.outputs.run == 'true'runs-on: ${{ matrix.os }}timeout-minutes: 30strategy:fail-fast: falsematrix:- os: [ubuntu-latest, macos-latest, windows-latest]+ os: ${{ fromJSON(needs.changes.outputs.matrix) }}steps:- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4- uses: dtolnay/rust-toolchain@4716b85f2fac3e324e64fa2810f6b5c3905760a5 # 1.97.1@@ -217,6 +255,8 @@ jobs:verify:name: Generated contract and SDK bindings+ needs: changes+ if: needs.changes.outputs.run == 'true' && contains(needs.changes.outputs.matrix, 'ubuntu')runs-on: ubuntu-latesttimeout-minutes: 30steps:@@ -420,3 +460,19 @@ jobs:- name: Check TypeScript agent SDK exampleworking-directory: libs/cua-driver/examples/agent-sdksrun: npm run typecheck++ # Always-run aggregator: skipped lanes pass, so this is the one check to+ # require if branch protection ever needs one.+ result:+ name: "contract clients / result"+ if: always()+ needs: [changes, mcp-client-discovery, runtime-parity, verify]+ runs-on: ubuntu-latest+ timeout-minutes: 5+ steps:+ - env:+ LANES: ${{ toJSON(needs) }}+ run: |+ bad=$(jq -r 'to_entries[] | select(.value.result != "success" and .value.result != "skipped") | "\(.key)=\(.value.result)"' <<< "$LANES")+ if [[ -n "$bad" ]]; then echo "::error::lanes not green: $bad"; exit 1; fi+ echo "All applicable lanes passed." | tee -a "$GITHUB_STEP_SUMMARY"diff --git a/.github/workflows/ci-cua-spacesd.yml b/.github/workflows/ci-cua-spacesd.ymlindex 8a59ce40bd..4d87480b76 100644--- a/.github/workflows/ci-cua-spacesd.yml+++ b/.github/workflows/ci-cua-spacesd.yml@@ -20,9 +20,16 @@ on:- "libs/cua/crates/cua-media-codec/**"- "libs/cua/crates/cua-logging/**"- "libs/cua/crates/cua-volume/**"+ - "libs/cua/crates/cua-home/**"+ - "libs/cua/crates/cua-hotspot/**"+ - "libs/cua/crates/cua-machine-seal/**"+ - "libs/cua/crates/cua-mesh/**"+ - "libs/cua/crates/cua-spacesd-html5/**"+ - "libs/cua/crates/cua-telemetry/**"- "libs/images/windows-2022/enable-volume.ps1"- "libs/images/windows-2022/volume-diagnostics.ps1"- ".github/workflows/ci-cua-spacesd.yml"+ - ".github/scripts/ci_component_scope.py"push:branches: [main]paths:@@ -39,9 +46,16 @@ on:- "libs/cua/crates/cua-media-codec/**"- "libs/cua/crates/cua-logging/**"- "libs/cua/crates/cua-volume/**"+ - "libs/cua/crates/cua-home/**"+ - "libs/cua/crates/cua-hotspot/**"+ - "libs/cua/crates/cua-machine-seal/**"+ - "libs/cua/crates/cua-mesh/**"+ - "libs/cua/crates/cua-spacesd-html5/**"+ - "libs/cua/crates/cua-telemetry/**"- "libs/images/windows-2022/enable-volume.ps1"- "libs/images/windows-2022/volume-diagnostics.ps1"- ".github/workflows/ci-cua-spacesd.yml"+ - ".github/scripts/ci_component_scope.py"workflow_dispatch:permissions:@@ -67,14 +81,48 @@ env:CUA_ENV_TEST_SANDBOX: "1"jobs:+ changes:+ name: "cua-spacesd / changes"+ runs-on: ubuntu-latest+ timeout-minutes: 5+ permissions:+ contents: read+ pull-requests: read+ outputs:+ run: ${{ steps.scope.outputs.run }}+ matrix: ${{ steps.scope.outputs.matrix }}+ steps:+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4+ with:+ sparse-checkout: .github/scripts+ # CUA-1910: pull requests run only the OS lanes the changed paths can+ # reach (explicit dependency map in ci_component_scope.py). Pushes,+ # manual runs and release PRs run everything.+ - id: scope+ env:+ GH_TOKEN: ${{ github.token }}+ EVENT: ${{ github.event_name }}+ HEAD_REF: ${{ github.head_ref }}+ REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ run: |+ set -euo pipefail+ files=""+ if [[ "$EVENT" == pull_request ]]; then+ files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --jq '.[].filename')+ fi+ python3 .github/scripts/ci_component_scope.py spacesd <<< "$files" | tee -a "$GITHUB_STEP_SUMMARY"+test:name: fmt, clippy, test (${{ matrix.os }})+ needs: changes+ if: needs.changes.outputs.run == 'true'strategy:fail-fast: falsematrix:# macOS 26: the ScreenCaptureKit dependency compiles Metal bindings for# macOS 26 APIs and needs that SDK.- os: [ubuntu-latest, macos-26, windows-latest]+ os: ${{ fromJSON(needs.changes.outputs.matrix) }}runs-on: ${{ matrix.os }}timeout-minutes: 60defaults:@@ -201,6 +249,8 @@ jobs:# 1 GiB transfers, relay killed mid-stream).relay-e2e:name: relay e2e (docker)+ needs: changes+ if: needs.changes.outputs.run == 'true' && contains(needs.changes.outputs.matrix, 'ubuntu')runs-on: ubuntu-latesttimeout-minutes: 90defaults:@@ -216,3 +266,19 @@ jobs:run: scripts/ci/linux-core-tests.sh- name: Relay lanerun: scripts/ci/relay-e2e.sh++ # Always-run aggregator: skipped lanes pass, so this is the one check to+ # require if branch protection ever needs one.+ result:+ name: "cua-spacesd / result"+ if: always()+ needs: [changes, test, relay-e2e]+ runs-on: ubuntu-latest+ timeout-minutes: 5+ steps:+ - env:+ LANES: ${{ toJSON(needs) }}+ run: |+ bad=$(jq -r 'to_entries[] | select(.value.result != "success" and .value.result != "skipped") | "\(.key)=\(.value.result)"' <<< "$LANES")+ if [[ -n "$bad" ]]; then echo "::error::lanes not green: $bad"; exit 1; fi+ echo "All applicable lanes passed." | tee -a "$GITHUB_STEP_SUMMARY"