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.

ci: scope the macOS Swift sample builds to what they depend on (#5821)

Francesco Bonacci404cdf573c2d
diff --git a/.github/scripts/ci_swift_samples_scope.py b/.github/scripts/ci_swift_samples_scope.py
new file mode 100644
index 0000000000..f99365612d
--- /dev/null
+++ b/.github/scripts/ci_swift_samples_scope.py
@@ -0,0 +1,234 @@
+#!/usr/bin/env python3
+"""Decide whether a pull request needs a macOS Swift sample build.
+
+Two workflows build a Swift sample on macOS 26 against the cua SDK dylib
+(28 to 33 macOS minutes each): ci-infinite-canvas-swift.yml and the `swift` job
+of ci-openkoalabot-example-samples.yml. They used to run on every change under
+libs/cua/ (the whole Rust workspace). They only need to run when something they
+compile or read changes.
+
+Usage:
+ ci_swift_samples_scope.py scope <lane> changed paths on stdin
+ ci_swift_samples_scope.py check-manifests <lane> run from the repo root
+
+The workflows have no event-level `paths:` filter: a cheap ubuntu scope job is
+the only thing that always runs, so the `ci:full` label, pushes to main and the
+nightly schedule reach it whatever changed. `scope` writes GitHub Actions
+outputs (`run`, plus `typescript` for the openkoalabot lane, and `reason`).
+`check-manifests` fails when the dependency map below no longer matches the
+repository.
+
+What a sample depends on
+------------------------
+* The sample itself, and the files its tests read from elsewhere in the tree.
+* The Swift packages it links, found from its Package.swift `.package(path:)`
+ entries: libs/cua/swift (the Cua package, with the generated CuaSDK binding),
+ libs/spaces-sdk-swift and libs/spaces-app-swift. `check-manifests` follows
+ those entries, so a new path dependency cannot be missed.
+* The SDK binding. libcua_sdk is built from libs/cua/crates/cua-sdk, the only
+ crate that exports the UniFFI surface the Swift binding is generated from,
+ against the wire contract in libs/cua/proto and crates/cua-proto. The Rust
+ workspace manifest, lockfile, toolchain pin and cargo config decide how it is
+ built, and stage-uniffi-library.mjs stages it.
+* The composite actions both builds run: setup-protoc and rust-cache.
+
+What is deliberately not a trigger: the rest of cua-sdk's Rust closure (daemon,
+vmm, spaces, host, ...). A change there that alters the Swift API must
+regenerate libs/cua/swift/Sources/CuaSDK, which the `bindings drift` job of
+ci-cua-sdk.yml enforces on every libs/cua pull request, and that path is a
+trigger here. A change that only alters runtime behavior is covered by the
+full run on every push to main and the nightly schedule.
+
+Always the full build: any event other than pull_request (every push to main,
+the schedule, a manual run), a pull request labelled `ci:full`, a change to the
+workflow or this script, and a file listing that is empty or may be truncated
+(fail closed). The file listing carries both names of a renamed file, so moving
+a dependency out of a mapped directory still counts. Release-please branches
+are skipped by the macOS jobs' own `if`, as before this scope existed;
+ci-cua-sdk.yml and e2b-bindings.yml run the Swift binding on release pull
+requests.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+import posixpath
+import re
+import sys
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+
+# A trailing slash is a directory prefix; anything else is one exact file.
+SWIFT_PACKAGES = (
+ "libs/cua/swift/",
+ "libs/spaces-sdk-swift/",
+ "libs/spaces-app-swift/",
+)
+SDK_BINDING = (
+ "libs/cua/crates/cua-sdk/",
+ "libs/cua/crates/cua-proto/",
+ "libs/cua/proto/",
+ "libs/cua/scripts/stage-uniffi-library.mjs",
+ "libs/cua/Cargo.toml",
+ "libs/cua/Cargo.lock",
+ "libs/cua/rust-toolchain.toml",
+ "libs/cua/.cargo/",
+)
+# Composite actions both builds run.
+ACTIONS = (
+ ".github/actions/setup-protoc/",
+ ".github/actions/rust-cache/",
+)
+COMMON = SWIFT_PACKAGES + SDK_BINDING + ACTIONS + (".github/scripts/ci_swift_samples_scope.py",)
+
+LANES = {
+ "infinite-canvas": {
+ "sample": "examples/infinite-canvas-swift",
+ "inputs": COMMON + (
+ "examples/infinite-canvas-swift/",
+ # scripts/sync-cursor-assets.sh --check compares the sample's copy.
+ "libs/cua-driver/rust/crates/cursor-overlay/assets/",
+ ".github/workflows/ci-infinite-canvas-swift.yml",
+ ),
+ },
+ "openkoalabot": {
+ "sample": "examples/openkoalabot-example-swift",
+ "inputs": COMMON + (
+ "examples/openkoalabot-example-swift/",
+ # ScenarioTests read scenario.json; SpaceCreationTests and
+ # scripts/gen-images.mjs read the shared image list.
+ "examples/openkoalabot-example-scenario/",
+ "libs/images/sandbox-images.json",
+ ".github/workflows/ci-openkoalabot-example-samples.yml",
+ ),
+ # The workflow's TypeScript job (Linux) is not scoped by this change:
+ # it keeps the trigger paths the workflow had before, now evaluated
+ # here because the workflow has no event-level filter.
+ "extra": {
+ "typescript": (
+ "examples/openkoalabot-example-ts/",
+ "examples/openkoalabot-example-swift/",
+ "libs/cua/",
+ "libs/spaces-sdk-swift/",
+ "libs/spaces-app-swift/",
+ "docs/content/docs/spaces/guides/",
+ "docs/content/docs/spaces/examples/",
+ *ACTIONS,
+ ".github/scripts/ci_swift_samples_scope.py",
+ ".github/workflows/ci-openkoalabot-example-samples.yml",
+ ),
+ },
+ },
+}
+
+# A Swift package builds the same without these.
+INERT = re.compile(r".*\.md$|(^|.*/)(LICENSE|CHANGELOG\.md|VERSION)$")
+# `.package(name: "Cua", path: "../../libs/cua/swift")`
+PATH_DEPENDENCY = re.compile(r'\.package\s*\([^)]*?\bpath:\s*"([^"]+)"')
+# The pull request files API stops at 3000 files.
+FILE_LISTING_LIMIT = 3000
+
+
+def matches(inputs: tuple[str, ...], path: str) -> bool:
+ return any(path.startswith(i) if i.endswith("/") else path == i for i in inputs)
+
+
+def covered(lane: str, path: str) -> bool:
+ return matches(LANES[lane]["inputs"], path)
+
+
+def decide(
+ lane: str,
+ files: list[str],
+ event: str,
+ labels: tuple[str, ...] = (),
+ inputs: tuple[str, ...] | None = None,
+) -> tuple[bool, str]:
+ """`files` holds every changed path, and for a rename both the old and the new name.
+
+ `inputs` replaces the lane's dependency map for a job that keeps its old
+ trigger paths; markdown only counts as inert for the Swift builds.
+ """
+ inert = INERT if inputs is None else re.compile(r"(?!)")
+ inputs = LANES[lane]["inputs"] if inputs is None else inputs
+ if event != "pull_request":
+ return True, f"{event} runs the full build"
+ if "ci:full" in labels:
+ return True, "ci:full label"
+ if not files:
+ return True, "no changed files listed, failing closed"
+ if len(files) >= FILE_LISTING_LIMIT:
+ return True, "file listing may be truncated, failing closed"
+ for f in files:
+ if not inert.match(f) and matches(inputs, f):
+ return True, f"{f} is a dependency of the sample"
+ return False, "no changed path is a dependency of the sample"
+
+
+def package_closure(lane: str, root: Path = ROOT) -> dict[str, list[str]]:
+ """Swift packages reachable from the sample through `.package(path:)`."""
+ seen: dict[str, list[str]] = {}
+ stack = [LANES[lane]["sample"]]
+ while stack:
+ directory = stack.pop()
+ if directory in seen:
+ continue
+ manifest = root / directory / "Package.swift"
+ text = manifest.read_text(encoding="utf-8")
+ seen[directory] = [posixpath.normpath(posixpath.join(directory, p)) for p in PATH_DEPENDENCY.findall(text)]
+ stack.extend(seen[directory])
+ return seen
+
+
+def manifest_problems(lane: str, root: Path = ROOT) -> list[str]:
+ problems = [f"{i} does not exist" for i in LANES[lane]["inputs"] if not (root / i).exists()]
+ for directory in package_closure(lane, root):
+ if not covered(lane, f"{directory}/Package.swift"):
+ problems.append(f"{directory} is a Swift package dependency but is not in the {lane} inputs")
+ return problems
+
+
+def emit(**outputs: str) -> None:
+ for k, v in outputs.items():
+ print(f"{k}={v}")
+ path = os.environ.get("GITHUB_OUTPUT")
+ if path:
+ with open(path, "a", encoding="utf-8") as fh:
+ fh.writelines(f"{k}={v}\n" for k, v in outputs.items())
+
+
+def labels_from_env() -> tuple[str, ...]:
+ raw = os.environ.get("LABELS", "").strip()
+ if not raw:
+ return ()
+ try:
+ parsed = json.loads(raw)
+ except json.JSONDecodeError:
+ return tuple(s.strip() for s in raw.split(",") if s.strip())
+ return tuple(parsed) if isinstance(parsed, list) else ()
+
+
+def main(argv: list[str]) -> int:
+ if len(argv) != 3 or argv[1] not in ("scope", "check-manifests") or argv[2] not in LANES:
+ print(__doc__, file=sys.stderr)
+ return 2
+ command, lane = argv[1], argv[2]
+ if command == "check-manifests":
+ problems = manifest_problems(lane)
+ for p in problems:
+ print(f"::error::ci_swift_samples_scope.py: {p}")
+ return 1 if problems else 0
+ files = [line.strip() for line in sys.stdin if line.strip()]
+ event, labels = os.environ.get("EVENT", "pull_request"), labels_from_env()
+ run, reason = decide(lane, files, event, labels)
+ outputs = {"run": str(run).lower(), "reason": reason}
+ for job, inputs in LANES[lane].get("extra", {}).items():
+ outputs[job] = str(decide(lane, files, event, labels, inputs)[0]).lower()
+ emit(**outputs)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/.github/scripts/tests/test_ci_gate_workflow.py b/.github/scripts/tests/test_ci_gate_workflow.py
index 58e09b2639..bb186899b2 100644
--- a/.github/scripts/tests/test_ci_gate_workflow.py
+++ b/.github/scripts/tests/test_ci_gate_workflow.py
@@ -108,6 +108,9 @@ def timeline(tmp_path, snapshots):
('1\t11\tbuild\tcancelled\tcompleted\n1\t10\tbuild\tsuccess\tcompleted', 'test\tcancelled', None, 1, 'build: fail'),
('1\t11\tbuild\tsuccess\tcompleted\n1\t10\tbuild\tfailure\tcompleted', '', 'test\tfailure', 1, 'build: fail'),
('1\t11\tbuild\tskipped\tcompleted', '', None, 0, 'build: skipped'),
+ # A scoped macOS sample build: the scope job ran, the sample job was skipped
+ # (the jobs API reports it as skipped and the gate ignores it), so the run passes.
+ ('1\t11\tinfinite-canvas\tsuccess\tcompleted', 'scope (macOS Swift sample)\tsuccess', None, 0, 'infinite-canvas: pass'),
('1\t11\tbuild\tsuccess\tcompleted', 'distro-smoke\tfailure', None, 0, 'build: pass'),
('1\t11\tbuild\tfailure\tcompleted', 'test\tfailure', None, 1, 'build: fail'),
('1\t11\tbuild\tneutral\tcompleted', 'test\tneutral', None, 0, 'build: pass'),
diff --git a/.github/scripts/tests/test_ci_swift_samples_scope.py b/.github/scripts/tests/test_ci_swift_samples_scope.py
new file mode 100644
index 0000000000..4c226c663c
--- /dev/null
+++ b/.github/scripts/tests/test_ci_swift_samples_scope.py
@@ -0,0 +1,328 @@
+"""Regression fixtures for ci_swift_samples_scope.py and the two workflows that use it."""
+
+import json
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+
+import yaml
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+import ci_swift_samples_scope as scope # noqa: E402
+
+ROOT = Path(__file__).resolve().parents[3]
+WORKFLOWS = ROOT / ".github/workflows"
+LANE_WORKFLOWS = {
+ "infinite-canvas": "ci-infinite-canvas-swift.yml",
+ "openkoalabot": "ci-openkoalabot-example-samples.yml",
+}
+LANES = tuple(LANE_WORKFLOWS)
+
+
+TYPESCRIPT = scope.LANES["openkoalabot"]["extra"]["typescript"]
+
+
+def run(lane, files, event="pull_request", labels=()):
+ return scope.decide(lane, files, event, tuple(labels))[0]
+
+
+def run_typescript(files, event="pull_request", labels=()):
+ return scope.decide("openkoalabot", files, event, tuple(labels), TYPESCRIPT)[0]
+
+
+class ScopeTests(unittest.TestCase):
+ def test_rust_internals_skip(self):
+ # Everything outside the SDK crate: the daemon, vmm, spaces, host, the CLI, the apps' cores.
+ for lane in LANES:
+ for f in (
+ "libs/cua/crates/cua-daemon/src/lib.rs",
+ "libs/cua/crates/cua-vmm/src/managed.rs",
+ "libs/cua/crates/cua-spaces/src/lib.rs",
+ "libs/cua/crates/cua-host/src/driver.rs",
+ "libs/cua/crates/cua-cli/src/main.rs",
+ "libs/cua/crates/cua-spaces-app-core/src/lib.rs",
+ "libs/cua/crates/cua-spaces-ffi/src/lib.rs",
+ "libs/cua/python/src/cua/__init__.py",
+ "libs/cua/typescript/src/index.ts",
+ "libs/cua/kotlin/build.gradle.kts",
+ "libs/cua/VERSION",
+ ):
+ self.assertFalse(run(lane, [f]), (lane, f))
+
+ def test_docs_and_other_samples_skip(self):
+ for lane in LANES:
+ self.assertFalse(run(lane, ["docs/content/docs/spaces/guides/a.mdx"]), lane)
+ self.assertFalse(run(lane, ["examples/openkoalabot-example-ts/src/a.ts"]), lane)
+ self.assertFalse(run(lane, ["examples/openkoalabot-example-tauri/src-tauri/src/main.rs"]), lane)
+ self.assertFalse(run("infinite-canvas", ["examples/openkoalabot-example-swift/Package.swift"]))
+ self.assertFalse(run("openkoalabot", ["examples/infinite-canvas-swift/Package.swift"]))
+
+ def test_shared_dependencies_run_both(self):
+ for lane in LANES:
+ for f in (
+ "libs/cua/swift/Sources/CuaSDK/CuaSDK.swift",
+ "libs/cua/swift/Package.swift",
+ "libs/spaces-sdk-swift/Sources/CuaSpaces/Space.swift",
+ "libs/spaces-app-swift/Sources/CuaSpacesStreaming/View.swift",
+ "libs/cua/crates/cua-sdk/src/lib.rs",
+ "libs/cua/crates/cua-sdk/uniffi.toml",
+ "libs/cua/crates/cua-proto/build.rs",
+ "libs/cua/proto/cua/env/v1/stream.proto",
+ "libs/cua/scripts/stage-uniffi-library.mjs",
+ "libs/cua/Cargo.toml",
+ "libs/cua/Cargo.lock",
+ "libs/cua/rust-toolchain.toml",
+ "libs/cua/.cargo/config.toml",
+ ".github/actions/setup-protoc/action.yml",
+ ".github/actions/rust-cache/action.yml",
+ ".github/scripts/ci_swift_samples_scope.py",
+ ):
+ self.assertTrue(run(lane, ["docs/a.mdx", f]), (lane, f))
+
+ def test_lane_specific_inputs(self):
+ self.assertTrue(run("infinite-canvas", ["examples/infinite-canvas-swift/Sources/CanvasModel/Camera.swift"]))
+ self.assertTrue(run("infinite-canvas", ["libs/cua-driver/rust/crates/cursor-overlay/assets/cua.default.lottie"]))
+ self.assertTrue(run("infinite-canvas", [".github/workflows/ci-infinite-canvas-swift.yml"]))
+ self.assertFalse(run("infinite-canvas", [".github/workflows/ci-openkoalabot-example-samples.yml"]))
+ self.assertFalse(run("openkoalabot", ["libs/cua-driver/rust/crates/cursor-overlay/assets/cua.default.lottie"]))
+ for f in (
+ "examples/openkoalabot-example-swift/Sources/OpenKoalaBotExample/App/A.swift",
+ "examples/openkoalabot-example-scenario/scenario.json",
+ "libs/images/sandbox-images.json",
+ ".github/workflows/ci-openkoalabot-example-samples.yml",
+ ):
+ self.assertTrue(run("openkoalabot", [f]), f)
+ self.assertFalse(run("openkoalabot", [".github/workflows/ci-infinite-canvas-swift.yml"]))
+ self.assertFalse(run("infinite-canvas", ["libs/images/sandbox-images.json"]))
+
+ def test_markdown_is_inert_but_only_markdown(self):
+ for lane in LANES:
+ self.assertFalse(run(lane, ["libs/cua/swift/README.md", "libs/spaces-sdk-swift/README.md"]), lane)
+ self.assertTrue(run(lane, ["libs/cua/swift/README.md", "libs/cua/swift/Package.swift"]), lane)
+ self.assertFalse(run("openkoalabot", ["examples/openkoalabot-example-swift/FRICTION.md"]))
+
+ def test_full_build_everywhere_else(self):
+ for lane in LANES:
+ for event in ("push", "schedule", "workflow_dispatch"):
+ self.assertTrue(run(lane, ["docs/a.md"], event=event), (lane, event))
+ self.assertTrue(run(lane, ["docs/a.md"], labels=["ci:full"]), lane)
+ self.assertFalse(run(lane, ["docs/a.md"], labels=["agent", "bug"]), lane)
+
+ def test_rename_out_of_a_mapped_directory_counts(self):
+ # The files API lists a rename under its new name and carries the old one
+ # as previous_filename; the workflows feed the scope both.
+ for lane, moved in (
+ ("infinite-canvas", "examples/infinite-canvas-swift/Sources/CanvasModel/Camera.swift"),
+ ("openkoalabot", "examples/openkoalabot-example-swift/Sources/OpenKoalaBotExample/App/A.swift"),
+ ("infinite-canvas", "libs/cua/swift/Sources/Cua/Cua.swift"),
+ ("openkoalabot", "libs/spaces-sdk-swift/Sources/CuaSpaces/Space.swift"),
+ ):
+ self.assertFalse(run(lane, ["docs/content/docs/moved/Camera.swift"]), (lane, moved))
+ self.assertTrue(run(lane, ["docs/content/docs/moved/Camera.swift", moved]), (lane, moved))
+
+ def test_workflows_list_both_names_of_a_rename(self):
+ jq = shutil.which("jq")
+ if jq is None:
+ self.skipTest("jq is not installed")
+ payload = json.dumps([
+ {"filename": "docs/moved/Camera.swift", "status": "renamed",
+ "previous_filename": "examples/infinite-canvas-swift/Sources/CanvasModel/Camera.swift"},
+ {"filename": "docs/a.md", "status": "modified"},
+ ])
+ for lane in LANES:
+ script = WorkflowWiringTests.load(lane)["jobs"]["changes"]["steps"][-1]["run"]
+ expression = re.search(r"--jq '([^']+)'", script).group(1)
+ listed = subprocess.run([jq, "-r", expression], input=payload, capture_output=True, text=True, check=True)
+ files = listed.stdout.split()
+ self.assertEqual(files, ["docs/moved/Camera.swift", "examples/infinite-canvas-swift/Sources/CanvasModel/Camera.swift", "docs/a.md"])
+ self.assertTrue(run(lane, files) == (lane == "infinite-canvas"), lane)
+
+ def test_typescript_job_keeps_its_old_trigger_paths(self):
+ for f in (
+ "examples/openkoalabot-example-ts/src/a.ts",
+ "libs/cua/crates/cua-daemon/src/lib.rs",
+ "libs/cua/README.md",
+ "docs/content/docs/spaces/guides/a.mdx",
+ "docs/content/docs/spaces/examples/a.mdx",
+ "libs/spaces-sdk-swift/Package.swift",
+ ".github/actions/rust-cache/action.yml",
+ ".github/workflows/ci-openkoalabot-example-samples.yml",
+ ):
+ self.assertTrue(run_typescript([f]), f)
+ for f in ("docs/content/docs/other.mdx", "apps/cua-spaces/src/a.ts", "examples/infinite-canvas-swift/Package.swift"):
+ self.assertFalse(run_typescript([f]), f)
+ self.assertTrue(run_typescript(["docs/a.md"], event="push"))
+ self.assertTrue(run_typescript(["docs/a.md"], labels=["ci:full"]))
+ self.assertTrue(run_typescript([]))
+
+ def test_unknown_or_truncated_listing_fails_closed(self):
+ for lane in LANES:
+ self.assertTrue(run(lane, []), lane)
+ self.assertTrue(run(lane, ["docs/a.md"] * scope.FILE_LISTING_LIMIT), lane)
+
+ def test_labels_from_env(self):
+ for raw, expected in (
+ ('["ci:full", "x"]', ("ci:full", "x")),
+ ("[]", ()),
+ ("null", ()),
+ ("", ()),
+ ("ci:full, x", ("ci:full", "x")),
+ ):
+ os.environ["LABELS"] = raw
+ self.assertEqual(scope.labels_from_env(), expected, raw)
+ del os.environ["LABELS"]
+
+
+class CommandTests(unittest.TestCase):
+ def scope(self, lane, files, **env):
+ output = Path(tempfile.mkdtemp()) / "out"
+ completed = subprocess.run(
+ [sys.executable, str(ROOT / ".github/scripts/ci_swift_samples_scope.py"), "scope", lane],
+ input="\n".join(files), capture_output=True, text=True, check=True,
+ env={**os.environ, "GITHUB_OUTPUT": str(output), "LABELS": "[]", **env},
+ )
+ written = dict(line.split("=", 1) for line in output.read_text().splitlines())
+ shutil.rmtree(output.parent)
+ self.assertEqual(completed.stdout.splitlines(), [f"{k}={v}" for k, v in written.items()])
+ return written
+
+ def test_outputs(self):
+ out = self.scope("openkoalabot", ["libs/cua/crates/cua-daemon/src/lib.rs"], EVENT="pull_request")
+ self.assertEqual((out["run"], out["typescript"]), ("false", "true"))
+ out = self.scope("openkoalabot", ["docs/other.md"], EVENT="pull_request")
+ self.assertEqual((out["run"], out["typescript"]), ("false", "false"))
+ out = self.scope("openkoalabot", ["docs/other.md"], EVENT="push")
+ self.assertEqual((out["run"], out["typescript"]), ("true", "true"))
+ out = self.scope("infinite-canvas", ["docs/other.md"], EVENT="pull_request", LABELS='["ci:full"]')
+ self.assertEqual(out, {"run": "true", "reason": "ci:full label"})
+
+
+class ManifestTests(unittest.TestCase):
+ def test_repository_matches_the_map(self):
+ for lane in LANES:
+ self.assertEqual(scope.manifest_problems(lane), [], lane)
+
+ def test_closure_follows_path_dependencies(self):
+ for lane in LANES:
+ closure = set(scope.package_closure(lane))
+ self.assertEqual(
+ closure,
+ {scope.LANES[lane]["sample"], "libs/cua/swift", "libs/spaces-sdk-swift", "libs/spaces-app-swift"},
+ lane,
+ )
+
+ def test_a_new_path_dependency_is_reported(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ sample = scope.LANES["openkoalabot"]["sample"]
+ for directory, deps in {
+ sample: ['.package(path: "../../libs/spaces-sdk-swift")', '.package(name: "New", path: "../../libs/new-swift")'],
+ "libs/spaces-sdk-swift": ['.package(name: "Cua", path: "../cua/swift")'],
+ "libs/cua/swift": [],
+ "libs/new-swift": [],
+ }.items():
+ (root / directory).mkdir(parents=True)
+ (root / directory / "Package.swift").write_text("dependencies: [\n" + ",\n".join(deps) + "\n]")
+ problems = scope.manifest_problems("openkoalabot", root)
+ self.assertIn("libs/new-swift is a Swift package dependency but is not in the openkoalabot inputs", problems)
+ self.assertFalse([p for p in problems if "does not exist" not in p and "new-swift" not in p], problems)
+
+ def test_missing_input_is_reported(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ sample = scope.LANES["infinite-canvas"]["sample"]
+ (root / sample).mkdir(parents=True)
+ (root / sample / "Package.swift").write_text("dependencies: []")
+ problems = scope.manifest_problems("infinite-canvas", root)
+ self.assertIn("libs/cua/crates/cua-sdk/ does not exist", problems)
+
+
+class WorkflowWiringTests(unittest.TestCase):
+ @staticmethod
+ def load(lane):
+ return yaml.safe_load((WORKFLOWS / LANE_WORKFLOWS[lane]).read_text())
+
+ @staticmethod
+ def pattern_covers(pattern, path):
+ prefix = pattern[:-3] if pattern.endswith("/**") else pattern
+ return path.rstrip("/") == prefix or path.startswith(prefix + "/")
+
+ def test_no_event_level_path_filter(self):
+ # A `paths:` filter would stop the `ci:full` label, unrelated pushes to
+ # main and renames out of a mapped directory from ever reaching the scope job.
+ for lane in LANES:
+ on = self.load(lane)[True]
+ for event in ("pull_request", "push"):
+ self.assertNotIn("paths", on[event] or {}, (lane, event))
+ self.assertNotIn("paths-ignore", on[event] or {}, (lane, event))
+
+ def test_actions_both_builds_run_are_inputs(self):
+ for lane in LANES:
+ self.assertTrue(scope.covered(lane, ".github/actions/setup-protoc/action.yml"), lane)
+ self.assertTrue(scope.covered(lane, ".github/actions/rust-cache/action.yml"), lane)
+ jobs = self.load(lane)["jobs"]
+ uses = [s.get("uses") for j in jobs.values() for s in j.get("steps", [])]
+ self.assertIn("./.github/actions/setup-protoc", uses)
+ self.assertIn("./.github/actions/rust-cache", uses)
+
+ def test_full_run_on_main_and_nightly(self):
+ for lane in LANES:
+ on = self.load(lane)[True]
+ self.assertEqual(on["push"], {"branches": ["main"]})
+ self.assertEqual(len(on["schedule"]), 1)
+ self.assertRegex(on["schedule"][0]["cron"], r"^\d+ \d+ \* \* \*$")
+ self.assertIn("workflow_dispatch", on)
+
+ @staticmethod
+ def evaluate(condition, **context):
+ """Evaluate the small subset of the expression language the job conditions use."""
+ expression = re.fullmatch(r"\$\{\{\s*(.*?)\s*\}\}", condition.strip()).group(1)
+ expression = re.sub(r"startsWith\(([\w.]+), ('[^']*')\)", r"\1.startswith(\2)", expression)
+ expression = expression.replace("&&", " and ").replace("||", " or ").replace("!", " not ")
+ for name, key in (("needs.changes.outputs.run", "run"), ("needs.changes.outputs.typescript", "typescript"),
+ ("github.head_ref", "head_ref"), ("github.event_name", "event_name")):
+ expression = expression.replace(name, key)
+ return eval(expression, {"__builtins__": {}}, context)
+
+ def test_macos_job_waits_for_the_scope_job(self):
+ for lane in LANES:
+ jobs = self.load(lane)["jobs"]
+ changes = jobs["changes"]
+ self.assertEqual(changes["runs-on"], "ubuntu-24.04")
+ self.assertEqual(changes["outputs"]["run"], "${{ steps.scope.outputs.run }}")
+ script = changes["steps"][-1]["run"]
+ self.assertIn(f"check-manifests {lane}", script)
+ self.assertIn(f"scope {lane}", script)
+ self.assertNotIn("needs", changes)
+ self.assertNotIn("if", changes)
+ swift = jobs["swift"]
+ self.assertEqual(swift["needs"], "changes")
+ self.assertEqual(swift["runs-on"], "macos-26")
+
+ def test_effective_job_conditions(self):
+ # The scope decision is final, except that release-please branches skip the
+ # job as they did before this change (release pull requests get the Swift
+ # binding from ci-cua-sdk.yml and e2b-bindings.yml).
+ for lane in LANES:
+ jobs = self.load(lane)["jobs"]
+ for job, output in (("swift", "run"), ("typescript", "typescript")):
+ if job not in jobs:
+ continue
+ for head_ref in ("feature/x", "", "release-please--branches--main"):
+ for decision in ("true", "false", ""):
+ context = {"run": "", "typescript": "", "head_ref": head_ref, output: decision}
+ expected = decision == "true" and not head_ref.startswith("release-please--branches--")
+ self.assertEqual(self.evaluate(jobs[job]["if"], **context), expected, (lane, job, head_ref, decision))
+ self.assertEqual(self.load("openkoalabot")["jobs"]["typescript"]["needs"], "changes")
+
+ def test_no_other_job_in_the_infinite_canvas_workflow(self):
+ self.assertEqual(set(self.load("infinite-canvas")["jobs"]), {"changes", "swift"})
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/README.md b/.github/workflows/README.md
index ccbda51d21..0ba46e866b 100644
--- a/.github/workflows/README.md
+++ b/.github/workflows/README.md
@@ -14,7 +14,8 @@ exclusive: a change that touches two areas runs both.
| You changed | Workflows that run |
|---|---|
-| `libs/cua/**` (Rust core: SDK, daemon, CLI, spaces crates) | CI: cua SDK (rust lint, rust test, spaces e2e, bindings drift, python/node/browser smoke, kotlin; macOS and Windows legs with the `ci:full` label), CI: Cua Spaces (frontend + Rust tests; installer bundles only with the `ci:full` label), CI: Test Python, CI: openkoalabot-example (TypeScript and Swift, Tauri), CI: infinite-canvas (Swift), CI: cua contrib providers, CI: cua your-cloud providers, CI: Check Docs |
+| `libs/cua/**` (Rust core: SDK, daemon, CLI, spaces crates) | CI: cua SDK (rust lint, rust test, spaces e2e, bindings drift, python/node/browser smoke, kotlin; macOS and Windows legs with the `ci:full` label), CI: Cua Spaces (frontend + Rust tests; installer bundles only with the `ci:full` label), CI: Test Python, CI: openkoalabot-example (TypeScript and Tauri; its Swift job only for the rows below), CI: cua contrib providers, CI: cua your-cloud providers, CI: Check Docs |
+| `libs/cua/swift/**`, `libs/spaces-sdk-swift/**`, `libs/spaces-app-swift/**`, `libs/cua/crates/cua-sdk/**`, `libs/cua/proto/**`, the Rust workspace manifest, lockfile and toolchain pin, `.github/actions/setup-protoc/**`, `.github/actions/rust-cache/**`, or the Swift samples (`examples/infinite-canvas-swift/**`, `examples/openkoalabot-example-swift/**` and the files its tests read) | CI: infinite-canvas (Swift) and the Swift job of CI: openkoalabot-example, each 28 to 33 macOS minutes. The full list is in `.github/scripts/ci_swift_samples_scope.py`. Other `libs/cua/**` changes skip them. Both workflows start a cheap scope job on every pull request and push; it decides, so main, the nightly schedule and the `ci:full` label build them every time. Release-please branches skip them as before |
| `libs/cua-spacesd/**` | CI: cua-spacesd (3 OS + relay e2e), CI: Image doctor, CD: Image linux (build and gates only), CI: Images on the current cua-spacesd, openkoalabot (Tauri) |
| `libs/cua-driver/**` | CI: Rust Linux / macOS / Windows unit, CI: Nix Linux Rust source, CI: cua-driver contract clients, driver quick feedback, Image doctor, CI: cua-spacesd |
| `apps/cua-spaces/src/**` (web frontend only) | CI: Cua Spaces: vitest + typecheck and the Rust command-layer tests. The installer bundles (a Tauri app that does not ship) are not built on pull requests; add the `ci:full` label to build them, and then the Windows and macOS bundles run only when something other than `src/`, `public/`, `e2e/`, `tests/`, `docs/` or markdown changed |
diff --git a/.github/workflows/ci-infinite-canvas-swift.yml b/.github/workflows/ci-infinite-canvas-swift.yml
index 63a24ae4e6..9555316c92 100644
--- a/.github/workflows/ci-infinite-canvas-swift.yml
+++ b/.github/workflows/ci-infinite-canvas-swift.yml
@@ -7,25 +7,25 @@ name: "CI: infinite-canvas (Swift)"
# tile pipeline on a local H.264 test pattern (VideoToolbox encode and
# decode), and a UI smoke test in an offscreen window. Nothing connects to a
# Space and nothing touches host apps. Liquid Glass needs the macOS 26 SDK.
+#
+# The macOS build is 28 to 33 minutes, so a pull request runs it only when
+# something it compiles or reads changes: the sample, the Swift packages, the
+# SDK crate the binding is generated from, the composite actions it runs and
+# the cursor theme (the map and the reasons are in
+# .github/scripts/ci_swift_samples_scope.py). There is no event-level `paths:`
+# filter: the cheap ubuntu `scope` job always runs and decides, so the `ci:full`
+# label, every push to main and the nightly schedule reach it. Rust-internal
+# changes that leave the binding alone are covered by the full run on every
+# push to main and by the nightly schedule. Release-please branches skip the
+# macOS job as they always have.
on:
pull_request:
- paths:
- - "examples/infinite-canvas-swift/**"
- - "libs/cua/**"
- - "libs/spaces-sdk-swift/**"
- - "libs/spaces-app-swift/**"
- - "libs/cua-driver/rust/crates/cursor-overlay/assets/**"
- - ".github/workflows/ci-infinite-canvas-swift.yml"
push:
branches: [main]
- paths:
- - "samples/infinite-canvas-swift/**"
- - "libs/cua/**"
- - "libs/spaces-sdk-swift/**"
- - "libs/spaces-app-swift/**"
- - "libs/cua-driver/rust/crates/cursor-overlay/assets/**"
- - ".github/workflows/ci-infinite-canvas-swift.yml"
+ # Drift check: the full build on main, whatever changed.
+ schedule:
+ - cron: "37 5 * * *"
workflow_dispatch:
permissions:
@@ -43,8 +43,41 @@ env:
CARGO_BUILD_JOBS: "4"
jobs:
+ changes:
+ name: scope (macOS Swift sample)
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ permissions:
+ contents: read
+ pull-requests: read
+ outputs:
+ run: ${{ steps.scope.outputs.run }}
+ steps:
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ with:
+ persist-credentials: false
+ - id: scope
+ env:
+ GH_TOKEN: ${{ github.token }}
+ EVENT: ${{ github.event_name }}
+ LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
+ REPO: ${{ github.repository }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: |
+ set -euo pipefail
+ # Fails when the dependency map no longer matches the Swift manifests.
+ python3 .github/scripts/ci_swift_samples_scope.py check-manifests infinite-canvas
+ files=""
+ if [[ "$EVENT" == pull_request ]]; then
+ # Both names of a renamed file: moving a dependency out of a mapped
+ # directory is still a change to the dependency.
+ files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --jq '.[] | .filename, (.previous_filename // empty)')
+ fi
+ python3 .github/scripts/ci_swift_samples_scope.py scope infinite-canvas <<< "$files" | tee -a "$GITHUB_STEP_SUMMARY"
+
swift:
- if: ${{ !startsWith(github.head_ref, 'release-please--branches--') }}
+ needs: changes
+ if: ${{ needs.changes.outputs.run == 'true' && !startsWith(github.head_ref, 'release-please--branches--') }}
name: infinite-canvas-swift (swift test)
runs-on: macos-26
timeout-minutes: 90
diff --git a/.github/workflows/ci-openkoalabot-example-samples.yml b/.github/workflows/ci-openkoalabot-example-samples.yml
index 321dd90d64..67ef9c1612 100644
--- a/.github/workflows/ci-openkoalabot-example-samples.yml
+++ b/.github/workflows/ci-openkoalabot-example-samples.yml
@@ -6,29 +6,26 @@ name: "CI: openkoalabot-example (TypeScript and Swift)"
# this workflow builds and tests the sources. The Rust/Tauri sample has its own
# workflow (ci-openkoalabot-example-tauri.yml). Tests are hermetic (fixtures, temp
# homes); nothing touches host apps.
+#
+# The macOS Swift build is 28 minutes, so a pull request runs it only when
+# something it compiles or reads changes: the sample, the files its tests read,
+# the Swift packages, the SDK crate the binding is generated from and the
+# composite actions it runs (the map and the reasons are in
+# .github/scripts/ci_swift_samples_scope.py). There is no event-level `paths:`
+# filter: the cheap ubuntu `scope` job always runs and decides, so the `ci:full`
+# label, every push to main and the nightly schedule reach it. Rust-internal
+# changes that leave the binding alone are covered by the full run on every
+# push to main and by the nightly schedule. Release-please branches skip both
+# jobs as they always have. The TypeScript job keeps the trigger paths this
+# workflow had before; the scope job evaluates them too.
on:
pull_request:
- paths:
- - "examples/openkoalabot-example-ts/**"
- - "examples/openkoalabot-example-swift/**"
- - "libs/cua/**"
- - "libs/spaces-sdk-swift/**"
- - "libs/spaces-app-swift/**"
- - "docs/content/docs/spaces/guides/**"
- - "docs/content/docs/spaces/examples/**"
- - ".github/workflows/ci-openkoalabot-example-samples.yml"
push:
branches: [main]
- paths:
- - "samples/openkoalabot-example-ts/**"
- - "samples/openkoalabot-example-swift/**"
- - "libs/cua/**"
- - "libs/spaces-sdk-swift/**"
- - "libs/spaces-app-swift/**"
- - "docs/content/docs/spaces/guides/**"
- - "docs/content/docs/spaces/examples/**"
- - ".github/workflows/ci-openkoalabot-example-samples.yml"
+ # Drift check: the full build on main, whatever changed.
+ schedule:
+ - cron: "53 5 * * *"
workflow_dispatch:
permissions:
@@ -59,7 +56,8 @@ env:
jobs:
typescript:
- if: ${{ !startsWith(github.head_ref, 'release-please--branches--') }}
+ needs: changes
+ if: ${{ needs.changes.outputs.typescript == 'true' && !startsWith(github.head_ref, 'release-please--branches--') }}
name: openkoalabot-example-ts (npm test)
runs-on: ubuntu-24.04
timeout-minutes: 60
@@ -112,8 +110,42 @@ jobs:
npm run typecheck
npm run build:web
+ changes:
+ name: scope (macOS Swift sample)
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ permissions:
+ contents: read
+ pull-requests: read
+ outputs:
+ run: ${{ steps.scope.outputs.run }}
+ typescript: ${{ steps.scope.outputs.typescript }}
+ steps:
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ with:
+ persist-credentials: false
+ - id: scope
+ env:
+ GH_TOKEN: ${{ github.token }}
+ EVENT: ${{ github.event_name }}
+ LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
+ REPO: ${{ github.repository }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: |
+ set -euo pipefail
+ # Fails when the dependency map no longer matches the Swift manifests.
+ python3 .github/scripts/ci_swift_samples_scope.py check-manifests openkoalabot
+ files=""
+ if [[ "$EVENT" == pull_request ]]; then
+ # Both names of a renamed file: moving a dependency out of a mapped
+ # directory is still a change to the dependency.
+ files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --jq '.[] | .filename, (.previous_filename // empty)')
+ fi
+ python3 .github/scripts/ci_swift_samples_scope.py scope openkoalabot <<< "$files" | tee -a "$GITHUB_STEP_SUMMARY"
+
swift:
- if: ${{ !startsWith(github.head_ref, 'release-please--branches--') }}
+ needs: changes
+ if: ${{ needs.changes.outputs.run == 'true' && !startsWith(github.head_ref, 'release-please--branches--') }}
name: openkoalabot-example-swift (swift test)
runs-on: macos-26
timeout-minutes: 60