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(spaces): report-only promote check for the main-built build set (CUA-2067) (#5754)
Francesco Bonaccic3c2138629a8
diff --git a/.github/scripts/spaces_verify_build_set.py b/.github/scripts/spaces_verify_build_set.pynew file mode 100644index 0000000000..1009de79fc--- /dev/null+++ b/.github/scripts/spaces_verify_build_set.py@@ -0,0 +1,106 @@+#!/usr/bin/env python3+"""Check a main-built Cua Spaces build set before a tag run promotes it (CUA-2067).++ spaces_verify_build_set.py DIR --tag-version V --tag-sha SHA \+ [--repository trycua/cua] [--skip-attestations]++Fails (exit 1, one reason per line) unless DIR holds a complete set:+- build-manifest.json exists and its source SHA is the tag's commit;+- its version is the tag version;+- every listed file exists, matches its sha256, and no other file is present;+- every file (the manifest included) has a GitHub artifact attestation made by+ cd-cua-spaces-build.yml on refs/heads/main (`gh attestation verify`).+Prints the sha256 of build-manifest.json (the digest the staging smoke status+must carry) as the last line, "manifest-digest=<hex>", when the set passes.+Nothing here publishes or changes anything.+"""+import argparse+import hashlib+import json+import subprocess+import sys+from pathlib import Path++SIGNER = "{repo}/.github/workflows/cd-cua-spaces-build.yml"+++def sha256(path: Path) -> str:+ h = hashlib.sha256()+ with path.open("rb") as f:+ for chunk in iter(lambda: f.read(1 << 20), b""):+ h.update(chunk)+ return h.hexdigest()+++def check_manifest(root: Path, tag_version: str, tag_sha: str):+ """Return (problems, manifest_digest). Pure file checks, no network."""+ problems = []+ mpath = root / "build-manifest.json"+ if not mpath.is_file():+ return ["build-manifest.json is missing"], None+ manifest = json.loads(mpath.read_text())+ if manifest.get("schema") != 1:+ problems.append(f"unsupported manifest schema {manifest.get('schema')!r}")+ if manifest.get("source_sha") != tag_sha:+ problems.append(f"manifest source SHA {manifest.get('source_sha')} is not the tag commit {tag_sha}")+ if manifest.get("version") != tag_version:+ problems.append(f"manifest version {manifest.get('version')} is not the tag version {tag_version}")+ listed = {}+ for entry in manifest.get("files", []):+ listed[entry["file"]] = entry+ if entry.get("version") != tag_version:+ problems.append(f"{entry['file']}: version {entry.get('version')} is not {tag_version}")+ if entry.get("source_sha") != tag_sha:+ problems.append(f"{entry['file']}: source SHA is not the tag commit")+ path = root / entry["file"]+ if not path.is_file():+ problems.append(f"{entry['file']}: listed but missing")+ elif sha256(path) != entry["sha256"]:+ problems.append(f"{entry['file']}: sha256 differs from the manifest")+ if not listed:+ problems.append("manifest lists no files")+ present = {p.name for p in root.iterdir() if p.is_file()} - {"build-manifest.json"}+ for extra in sorted(present - set(listed)):+ problems.append(f"{extra}: present but not in the manifest")+ return problems, sha256(mpath)+++def check_attestations(root: Path, repository: str):+ problems = []+ for path in sorted(p for p in root.iterdir() if p.is_file()):+ r = subprocess.run(+ [+ "gh", "attestation", "verify", str(path),+ "--repo", repository,+ "--signer-workflow", SIGNER.format(repo=repository),+ "--source-ref", "refs/heads/main",+ ],+ capture_output=True, text=True,+ )+ if r.returncode != 0:+ problems.append(f"{path.name}: attestation not verified: {(r.stderr or r.stdout).strip().splitlines()[-1:]}")+ return problems+++def main() -> int:+ p = argparse.ArgumentParser()+ p.add_argument("dir")+ p.add_argument("--tag-version", required=True)+ p.add_argument("--tag-sha", required=True)+ p.add_argument("--repository", default="trycua/cua")+ p.add_argument("--skip-attestations", action="store_true", help="tests only")+ a = p.parse_args()+ root = Path(a.dir)+ problems, digest = check_manifest(root, a.tag_version, a.tag_sha)+ if not problems and not a.skip_attestations:+ problems += check_attestations(root, a.repository)+ for line in problems:+ print(line)+ if problems:+ return 1+ print(f"manifest-digest={digest}")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/.github/scripts/tests/test_spaces_verify_build_set.py b/.github/scripts/tests/test_spaces_verify_build_set.pynew file mode 100644index 0000000000..1d25ec0410--- /dev/null+++ b/.github/scripts/tests/test_spaces_verify_build_set.py@@ -0,0 +1,70 @@+"""Fixtures for spaces_verify_build_set.py (CUA-2067)."""++import hashlib+import json+import sys+import tempfile+import unittest+from pathlib import Path++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+from spaces_verify_build_set import check_manifest # noqa: E402++SHA = "a" * 40+V = "0.14.0"+++def make_set(root: Path, **over):+ files = {"a.dmg": b"dmg", "latest.yml": b"feed"}+ entries = [+ {"file": n, "sha256": hashlib.sha256(b).hexdigest(), "version": V, "source_sha": SHA}+ for n, b in files.items()+ ]+ for n, b in files.items():+ (root / n).write_bytes(b)+ m = {"schema": 1, "version": V, "source_sha": SHA, "files": entries}+ m.update(over)+ (root / "build-manifest.json").write_text(json.dumps(m))+++class VerifyTests(unittest.TestCase):+ def check(self, tag_version=V, tag_sha=SHA, mutate=None, **over):+ with tempfile.TemporaryDirectory() as d:+ root = Path(d)+ make_set(root, **over)+ if mutate:+ mutate(root)+ return check_manifest(root, tag_version, tag_sha)++ def test_good_set_returns_the_manifest_digest(self):+ problems, digest = self.check()+ self.assertEqual(problems, [])+ self.assertEqual(len(digest), 64)++ def test_other_commit_fails(self):+ problems, _ = self.check(tag_sha="b" * 40)+ self.assertTrue(any("not the tag commit" in p for p in problems))++ def test_other_version_fails(self):+ problems, _ = self.check(tag_version="0.14.1")+ self.assertTrue(any("not the tag version" in p for p in problems))++ def test_changed_bytes_fail(self):+ problems, _ = self.check(mutate=lambda r: (r / "a.dmg").write_bytes(b"evil"))+ self.assertTrue(any("sha256 differs" in p for p in problems))++ def test_extra_file_fails(self):+ problems, _ = self.check(mutate=lambda r: (r / "x.exe").write_bytes(b"x"))+ self.assertTrue(any("not in the manifest" in p for p in problems))++ def test_missing_file_fails(self):+ problems, _ = self.check(mutate=lambda r: (r / "a.dmg").unlink())+ self.assertTrue(any("listed but missing" in p for p in problems))++ def test_missing_manifest_fails(self):+ problems, _ = self.check(mutate=lambda r: (r / "build-manifest.json").unlink())+ self.assertEqual(problems, ["build-manifest.json is missing"])+++if __name__ == "__main__":+ unittest.main()diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.ymlindex 6624f0ed8e..1f40e86190 100644--- a/.github/workflows/cd-cua-spaces.yml+++ b/.github/workflows/cd-cua-spaces.yml@@ -1853,6 +1853,60 @@ jobs:GH_TOKEN: ${{ steps.app-token.outputs.token }}run: .github/scripts/request_staging_smoke.sh cua-spaces "$GITHUB_SHA"+ # Promote check (CUA-2067, phase 2 of CUA-1991). Looks for the signed set the+ # main build made for this tag's commit and verifies it the way a promotion+ # would: manifest source SHA and version, every digest, no extra files, and a+ # GitHub attestation from cd-cua-spaces-build.yml on refs/heads/main. It only+ # reports (job summary and outputs); nothing consumes it yet, so the tag run+ # still builds and publishes as before. Off unless the repository variable+ # CUA_SPACES_PROMOTE_CHECK is "true". Never fails the run.+ promote-check:+ name: Promote check (report only)+ if: startsWith(github.ref, 'refs/tags/cua-spaces-v') && vars.CUA_SPACES_PROMOTE_CHECK == 'true'+ runs-on: ubuntu-latest+ timeout-minutes: 20+ continue-on-error: true+ defaults:+ run:+ working-directory: .+ permissions:+ contents: read+ actions: read+ attestations: read+ outputs:+ promotable: ${{ steps.verify.outputs.promotable }}+ manifest_digest: ${{ steps.verify.outputs.manifest_digest }}+ steps:+ - uses: actions/checkout@v4+ - name: Find and verify the main-built set for this commit+ id: verify+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ set -uo pipefail+ version="${GITHUB_REF_NAME#cua-spaces-v}"+ report() { echo "$1" | tee -a "$GITHUB_STEP_SUMMARY"; }+ echo "promotable=false" >> "$GITHUB_OUTPUT"+ run_id="$(gh run list --workflow cd-cua-spaces-build.yml --branch main --commit "$GITHUB_SHA" \+ --status success --limit 1 --json databaseId --jq '.[0].databaseId // empty')"+ if [ -z "$run_id" ]; then report "No successful main build for $GITHUB_SHA: this tag would fall back to the full build."; exit 0; fi+ if ! gh run download "$run_id" --name "spaces-build-$GITHUB_SHA" --dir set; then+ report "Main build run $run_id has no spaces-build-$GITHUB_SHA artifact (expired, or the build was a no-op): this tag would fall back to the full build."; exit 0+ fi+ out="$(python3 -I .github/scripts/spaces_verify_build_set.py set --tag-version "$version" --tag-sha "$GITHUB_SHA" --repository "$GITHUB_REPOSITORY")"+ rc=$?+ report "### Promote check for $GITHUB_REF_NAME (main build run $run_id)"+ report '```'+ report "$out"+ report '```'+ if [ $rc -eq 0 ]; then+ echo "promotable=true" >> "$GITHUB_OUTPUT"+ echo "manifest_digest=$(echo "$out" | sed -n 's/^manifest-digest=//p')" >> "$GITHUB_OUTPUT"+ report "Promotable: yes. Nothing was promoted."+ else+ report "Promotable: no. The tag run builds as usual."+ fi+# Staging first (CUA-1907): customers get nothing unless the staging smoke# (cloud scripts/spaces-staging/smoke.py) is recorded green for this exact# commit as the commit status "staging-smoke/cua-spaces". Only a release