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(release): sync the lockfiles that record the cua SDK version on release PRs (#5043)
Francesco Bonaccia4070b9eb1b1
diff --git a/.github/scripts/sync_sdk_release_locks.py b/.github/scripts/sync_sdk_release_locks.pynew file mode 100644index 0000000000..b2c18a96db--- /dev/null+++ b/.github/scripts/sync_sdk_release_locks.py@@ -0,0 +1,87 @@+"""Bring the lockfiles that record the cua SDK version to the release version.++Release Please bumps the SDK's VERSION, pyproject, __init__, package.json and+its own package-lock.json. The other lockfiles that lock the checkout's `cua`+still record the old version, so the release PR fails "lockfiles match+manifests" (scripts/ci/check-lockfiles.sh). Those are:++- every uv.lock whose `cua` package is the checkout (editable or directory);+- every package-lock.json, other than the SDK's own, that links+ libs/cua/typescript.++Only that one recorded version changes. Rewriting the field instead of+relocking keeps the diff independent of the uv and npm versions on the runner+(a newer uv also rewrites the lock `revision`) and runs no package tooling.+Prints the changed lockfiles; staging is the caller's.+"""++from __future__ import annotations++import argparse+import json+from pathlib import Path+import re+import subprocess++SDK_TS = "libs/cua/typescript"+UV_CUA_FROM_CHECKOUT = re.compile(+ r'^(\[\[package\]\]\nname = "cua"\nversion = ")[^"]*("\nsource = \{ (?:editable|directory) = )',+ re.M,+)+++def tracked(root: Path, name: str) -> list[str]:+ out = subprocess.run(+ ["git", "ls-files", "-z", "--", name, f"**/{name}"],+ cwd=root, check=True, capture_output=True, text=True,+ ).stdout+ return sorted({path for path in out.split("\0") if path})+++def sync_uv_lock(path: Path, version: str) -> bool:+ text = path.read_text()+ updated = UV_CUA_FROM_CHECKOUT.sub(rf"\g<1>{version}\g<2>", text)+ if updated == text:+ return False+ path.write_text(updated)+ return True+++def sdk_keys(lock: Path, sdk: Path) -> list[str]:+ packages = json.loads(lock.read_text()).get("packages", {})+ return [key for key in packages if key and (lock.parent / key).resolve() == sdk]+++def sync_npm_lock(path: Path, sdk: Path, version: str) -> bool:+ text = updated = path.read_text()+ for key in sdk_keys(path, sdk):+ # The entry's own fields sit at six spaces; "version" is one of them.+ entry = re.compile(+ r'(\n "' + re.escape(key) + r'": \{\n(?: "(?!version")[^\n]*\n)* "version": ")[^"]*(")'+ )+ updated, count = entry.subn(rf"\g<1>{version}\g<2>", updated)+ if count != 1:+ raise RuntimeError(f"{path}: expected one version for {key}, found {count}")+ if updated == text:+ return False+ path.write_text(updated)+ return True+++def main(argv: list[str] | None = None) -> int:+ parser = argparse.ArgumentParser(description="Sync the cua SDK version recorded in lockfiles.")+ parser.add_argument("--repo-root", dest="root", type=Path, default=Path.cwd())+ args = parser.parse_args(argv)+ root = args.root.resolve()+ version = (root / "libs/cua/VERSION").read_text().strip()+ sdk = (root / SDK_TS).resolve()+ changed = [lock for lock in tracked(root, "uv.lock") if sync_uv_lock(root / lock, version)]+ for lock in tracked(root, "package-lock.json"):+ if (root / lock).parent.resolve() != sdk and sync_npm_lock(root / lock, sdk, version):+ changed.append(lock)+ print("\n".join(changed))+ return 0+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/.github/scripts/tests/test_sync_sdk_release_locks.py b/.github/scripts/tests/test_sync_sdk_release_locks.pynew file mode 100644index 0000000000..7502c08196--- /dev/null+++ b/.github/scripts/tests/test_sync_sdk_release_locks.py@@ -0,0 +1,76 @@+import json+from pathlib import Path+import subprocess++import pytest++from sync_sdk_release_locks import main++ROOT = Path(__file__).resolve().parents[3]+++def uv_package(name: str, version: str, source: str) -> str:+ return f'[[package]]\nname = "{name}"\nversion = "{version}"\nsource = {{ {source} }}\n'+++def repo(tmp_path: Path) -> Path:+ sdk_entry = ' "../../libs/cua/typescript": {\n "name": "@trycua/cua",\n "version": "0.4.1",\n "license": "MIT"\n },\n'+ files = {+ "libs/cua/VERSION": "0.5.0\n",+ # The checkout, editable or as a directory: follows the release.+ "uv.lock": "version = 1\nrevision = 3\n\n" + uv_package("cua", "0.4.1", 'editable = "libs/cua/python"'),+ "libs/a/uv.lock": uv_package("cua", "0.4.1", 'directory = "../cua/python"'),+ # A registry release of cua, and another cua-* package: left alone.+ "libs/b/uv.lock": uv_package("cua", "0.2.0", 'registry = "https://pypi.org/simple"'),+ "libs/c/uv.lock": uv_package("cua-sandbox", "0.4.1", 'editable = "."'),+ # The SDK's own lock is Release Please's.+ "libs/cua/typescript/package-lock.json": '{\n "packages": {\n "": {\n "version": "0.4.1"\n }\n }\n}\n',+ "samples/ts/package-lock.json": '{\n "packages": {\n "": {\n "version": "1.0.0"\n },\n'+ + sdk_entry+ + ' "node_modules/x": {\n "version": "0.4.1"\n }\n }\n}\n',+ # A registry install of the SDK is not a link to the checkout.+ "samples/other/package-lock.json": json.dumps(+ {"packages": {"": {}, "node_modules/@trycua/cua": {"version": "0.4.1"}}}, indent=2+ ),+ }+ for rel, content in files.items():+ path = tmp_path / rel+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(content)+ subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)+ subprocess.run(["git", "add", "-A"], cwd=tmp_path, check=True)+ return tmp_path+++def test_only_the_recorded_sdk_version_changes(repo: Path, capsys: pytest.CaptureFixture[str]) -> None:+ before = {p: p.read_text() for p in repo.rglob("*.*") if ".git" not in p.parts}++ assert main(["--repo-root", str(repo)]) == 0++ assert capsys.readouterr().out.split() == ["libs/a/uv.lock", "uv.lock", "samples/ts/package-lock.json"]+ changed = {p for p, text in before.items() if p.read_text() != text}+ assert changed == {repo / "uv.lock", repo / "libs/a/uv.lock", repo / "samples/ts/package-lock.json"}+ for path in changed:+ assert path.read_text() == before[path].replace('"0.4.1"', '"0.5.0"', 1)+ # The lock revision is not rewritten, and a dependency at the old version stays.+ assert "revision = 3" in (repo / "uv.lock").read_text()+ assert '"node_modules/x": {\n "version": "0.4.1"' in (repo / "samples/ts/package-lock.json").read_text()++ assert main(["--repo-root", str(repo)]) == 0+ assert capsys.readouterr().out.strip() == ""+++def test_an_unrecognised_sdk_link_fails_loudly(repo: Path) -> None:+ lock = repo / "samples/ts/package-lock.json"+ data = json.loads(lock.read_text())+ lock.write_text(json.dumps(data, separators=(",", ":")))+ with pytest.raises(RuntimeError, match="expected one version"):+ main(["--repo-root", str(repo)])+++def test_release_please_runs_the_lock_sync_for_sdk_releases() -> None:+ workflow = (ROOT / ".github/workflows/release-please.yml").read_text()+ sdk_branch = workflow.split('elif [[ "$SDK" == "true" ]]; then', 1)[1].split("else\n", 1)[0]+ assert "python3 .github/scripts/sync_sdk_release_locks.py" in sdk_branch+ assert 'git add -- "${SDK_LOCK_PATHS[@]}"' in sdk_branchdiff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.ymlindex 146fa79b01..35551e68cf 100644--- a/.github/workflows/release-please.yml+++ b/.github/workflows/release-please.yml@@ -274,12 +274,18 @@ jobs:COMMIT_MESSAGE="chore(cua-spacesd): synchronize release lockfiles"elif [[ "$SDK" == "true" ]]; then# Release Please bumps VERSION, pyproject, __init__, package.json- # and package-lock.json together; the stamped docs follow here.+ # and package-lock.json together; the stamped docs and the other+ # lockfiles that lock the checkout's SDK follow here.PREVIOUS=$(git show origin/main:libs/cua/VERSION)python3 .github/scripts/sync_sdk_release_docs.py --from "$PREVIOUS"+ SDK_LOCKS=$(python3 .github/scripts/sync_sdk_release_locks.py)python3 .github/scripts/validate_release_versions.py --product sdkgit add docs/content/docs/cua-cli docs/content/docs/cua-sdk docs/content/docs/fleets scripts/docs-generators/cli-specs/cua.json- COMMIT_MESSAGE="chore(cua-sdk): synchronize release documentation"+ if [[ -n "$SDK_LOCKS" ]]; then+ mapfile -t SDK_LOCK_PATHS <<< "$SDK_LOCKS"+ git add -- "${SDK_LOCK_PATHS[@]}"+ fi+ COMMIT_MESSAGE="chore(cua-sdk): synchronize release documentation and lockfiles"elsepython3 .github/scripts/validate_release_versions.py --product sandbox# The Sandbox reference records the package version, so regenerate