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(images): pins PR regenerates the parity goldens and docs it feeds (#4588)
ddupontfbec9eece30a
diff --git a/scripts/images/image_pins.py b/scripts/images/image_pins.pyindex d7a929ae11..36498ccbea 100755--- a/scripts/images/image_pins.py+++ b/scripts/images/image_pins.py@@ -32,7 +32,8 @@ apply moves every ready OS: ``record-image-sizes.py --refresh-digest`` forits tags (new digest and sizes), checks the catalog now holds exactlythe digests that were verified, and moves the dated pin named in thelibs/images/README.md table row of each tag that has one. Writes the- pins PR body (a per-OS checklist) to --body and prints a JSON summary.+ pins PR body (a per-OS checklist) to --body and prints a JSON summary+ (the only line on stdout).Exits 1 when an OS whose CI build (--results) succeeded still doesnot report the version: a green run that pushed nothing.lag the CI check: every catalog digest that does not report the version@@ -56,6 +57,7 @@ from typing import CallableROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))CATALOG = os.path.join(ROOT, "libs", "images", "sandbox-images.json")README = os.path.join(ROOT, "libs", "images", "README.md")+RECORD_SIZES = os.path.join(ROOT, "scripts", "images", "record-image-sizes.py")VERSION_FILE = os.path.join(ROOT, "libs", "cua-spacesd", "VERSION")REPORT_TYPE = "application/vnd.cua.doctor.report.v1+json"INDEX_TYPES = {@@ -264,7 +266,8 @@ def body(oses: list[OS], version: str, *, run_url: str = "", results: dict[str,"A tag counts as on the version when the newest passing doctor report attached to each of its ""platform children (an OCI referrer) says so: a green run that pushed nothing cannot move a pin. ""Sizes are from `record-image-sizes.py --refresh-digest`, the app-core parity goldens from "- "`UPDATE_PARITY=1`, and README pin rows follow their tags.",+ "`UPDATE_PARITY=1`, the docs pages generated from the catalog from their docs generators "+ "(`scripts/docs-generators`), and README pin rows follow their tags.","","This PR is regenerated from `main` and the registry on every run of ""`.github/workflows/cd-images-spacesd-release.yml` (each cua-spacesd release, and after "@@ -293,11 +296,14 @@ def update_readme(text: str, ref: str, pin: str) -> str:return row.sub(lambda m: PIN_RE.sub(f"pin `{pin}`", m.group(1)), text)-def refresh_sizes(refs: list[str]) -> None:- cmd = [sys.executable, os.path.join(ROOT, "scripts", "images", "record-image-sizes.py"), "--refresh-digest"]+def refresh_sizes(refs: list[str], script: str = RECORD_SIZES) -> None:+ cmd = [sys.executable, script, "--refresh-digest"]for r in refs:cmd += ["--ref", r]- subprocess.run(cmd, check=True)+ # apply's stdout is the one-line JSON summary pins-pr.sh parses: the+ # child's progress lines go to stderr.+ proc = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, text=True)+ sys.stderr.write(proc.stdout)def apply(diff --git a/scripts/images/pins-pr.sh b/scripts/images/pins-pr.shindex c1aa613167..179affab15 100755--- a/scripts/images/pins-pr.sh+++ b/scripts/images/pins-pr.sh@@ -7,7 +7,12 @@# VERSION (doctor reports attached to the pushed digests) and differ from# the catalog gets its new digests and sizes in libs/images/sandbox-images.json# and its README pin rows moved.-# 2. The app-core parity goldens follow the catalog (UPDATE_PARITY=1).+# 2. Everything generated from the catalog follows it, so the PR passes its+# checks by itself: the app-core parity goldens (UPDATE_PARITY=1) and every+# docs generator the docs check routes the change to+# (scripts/docs-generators/runner.ts --changed-files-file, e.g. the sandbox+# reference pages). The generators rewrite their whole output, so drift+# main already had in those pages is fixed here too.# 3. The branch is rebuilt from the checked-out main and force-pushed, and the# PR's title and body (a per-OS checklist) are set. The PR is a pure function# of main and the registry, so every run (CI, or after a local macOS@@ -17,7 +22,8 @@# Run by .github/workflows/cd-images-spacesd-release.yml (pins job), which sets# the git identity and GH_TOKEN (the release GitHub App, so the PR's checks run).# --dry-run leaves the changes in the working tree and prints the body.-# Needs crane, oras, jq, cargo (with protoc) and gh.+# Needs crane, oras, jq, cargo (with protoc), node (npx when docs/node_modules+# is not installed) and gh.set -euo pipefailROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"BRANCH=images/pins@@ -27,7 +33,7 @@ while [ $# -gt 0 ]; do--results) RESULTS="$2"; shift 2 ;;--run-url) RUN_URL="$2"; shift 2 ;;--dry-run) DRY=1; shift ;;- -h|--help) sed -n '2,22p' "$0"; exit 0 ;;+ -h|--help) sed -n '2,28p' "$0"; exit 0 ;;-*) echo "unknown option $1" >&2; exit 2 ;;*) VERSION="$1"; shift ;;esac@@ -35,7 +41,8 @@ done[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "usage: pins-pr.sh X.Y.Z [--results ...] [--run-url URL] [--dry-run]" >&2; exit 2; }cd "$ROOT"TITLE="chore(images): pin Space images on cua-spacesd $VERSION"-FILES=(libs/images/sandbox-images.json libs/images/README.md libs/cua/crates/cua-spaces-app-core/parity/golden)+PINS=(libs/images/sandbox-images.json libs/images/README.md)+FILES=("${PINS[@]}" libs/cua/crates/cua-spaces-app-core/parity/golden docs/content)work="$(mktemp -d)"trap 'rm -rf "$work"' EXIT@@ -46,12 +53,40 @@ python3 scripts/images/image_pins.py apply --version "$VERSION" --body "$work/bo--results "$RESULTS" --run-url "$RUN_URL" >"$work/summary.json" || rc=$?[ -s "$work/summary.json" ] || exit "${rc:-1}"cat "$work/summary.json"-if [ "$(jq '.moved | length' "$work/summary.json")" -gt 0 ]; then+# Not inside an `if`: a summary that is not the JSON line fails the script+# instead of silently skipping the regeneration below.+moved="$(jq -e '.moved | length' "$work/summary.json")"++# The docs app's lockfile-pinned tsx, or that same version through npx where+# docs/node_modules is not installed (the CI pins job).+tsx() {+ if [ -f docs/node_modules/tsx/dist/cli.mjs ]; then+ node docs/node_modules/tsx/dist/cli.mjs "$@"+ else+ local v+ v="$(grep -m1 -oE '^ tsx@[0-9]+\.[0-9]+\.[0-9]+' docs/pnpm-lock.yaml | cut -d@ -f2)"+ [ -n "$v" ] || { echo "pins-pr.sh: no tsx version in docs/pnpm-lock.yaml" >&2; return 1; }+ npx --yes "tsx@$v" "$@"+ fi+}++regenerate() {(cd libs/cua && UPDATE_PARITY=1 cargo test --locked -p cua-spaces-app-core --test parity)-fi+ git diff --name-only -- "${PINS[@]}" >"$work/changed"+ local gens g script+ gens="$(tsx scripts/docs-generators/runner.ts --changed-files-file "$work/changed" | tail -n1)"+ for g in $gens; do+ script="$(jq -er --arg g "$g" '.generators[$g].generatorScript' scripts/docs-generators/config.json)"+ echo "docs generator $g ($script)"+ tsx "$script"+ done+}open_pr="$(gh pr list --head "$BRANCH" --base main --state open --json number -q '.[0].number // empty' 2>/dev/null || true)"-if git diff --quiet -- "${FILES[@]}"; then+if [ "$moved" -gt 0 ] || ! git diff --quiet -- "${PINS[@]}"; then+ regenerate+fi+if git diff --quiet -- "${PINS[@]}"; thenecho "nothing to pin for cua-spacesd $VERSION"if [ -n "$open_pr" ] && [ "$DRY" = 0 ]; thengh pr close "$open_pr" --delete-branch \@@ -65,7 +100,7 @@ if [ "$DRY" = 1 ]; thenexit "$rc"figit checkout -B "$BRANCH"-git add -- "${FILES[@]}"+git add -A -- "${FILES[@]}"git commit -q -m "$TITLE" -m "Generated by scripts/images/pins-pr.sh${RUN_URL:+ in $RUN_URL}."git push --force origin "$BRANCH"if [ -n "$open_pr" ]; thendiff --git a/scripts/images/tests/test_image_pins.py b/scripts/images/tests/test_image_pins.pyindex ad1fb129c1..bbe0fa82b6 100644--- a/scripts/images/tests/test_image_pins.py+++ b/scripts/images/tests/test_image_pins.py@@ -218,6 +218,19 @@ class PinsTests(unittest.TestCase):warnings = [line for line in out.getvalue().splitlines() if line.startswith("::warning")]self.assertEqual(len(warnings), 2) # one per OS+ def test_refresh_keeps_stdout_for_the_summary(self) -> None:+ # pins-pr.sh parses apply's stdout as JSON: record-image-sizes.py's+ # progress lines must not land there (they once skipped the parity+ # goldens and left the pins PR red).+ script = os.path.join(self.tmp, "record-image-sizes.py")+ with open(script, "w") as fh:+ fh.write("import sys\nprint('record-image-sizes: %d image(s) measured' % sys.argv[1:].count('--ref'))\n")+ out, err = io.StringIO(), io.StringIO()+ with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):+ image_pins.refresh_sizes(["ghcr.io/trycua/linux:24.04"], script=script)+ self.assertEqual(out.getvalue(), "")+ self.assertIn("record-image-sizes: 1 image(s) measured", err.getvalue())+def test_parse_results(self) -> None:self.assertEqual(image_pins.parse_results("linux=success, omarchy=failure,windows=skipped"),@@ -320,6 +333,30 @@ class ReleaseWiringTests(unittest.TestCase):self.assertTrue(os.access(os.path.join(ROOT, "scripts/images/pins-pr.sh"), os.X_OK))self.assertTrue(os.access(os.path.join(ROOT, "scripts/images/release-macos.sh"), os.X_OK))+ def test_pins_pr_regenerates_everything_the_catalog_feeds(self) -> None:+ with open(os.path.join(ROOT, "scripts/images/pins-pr.sh")) as fh:+ script = fh.read()+ # The summary is parsed strictly, outside a conditional that would+ # swallow a jq failure.+ self.assertRegex(script, r"(?m)^moved=\"\$\(jq -e '\.moved \| length'")+ self.assertIn("UPDATE_PARITY=1 cargo test --locked -p cua-spaces-app-core --test parity", script)+ # Docs: the generators the docs check routes the change to.+ self.assertIn("scripts/docs-generators/runner.ts --changed-files-file", script)+ self.assertIn("libs/cua/crates/cua-spaces-app-core/parity/golden docs/content)", script)+ self.assertIn('git add -A -- "${FILES[@]}"', script)++ def test_docs_generators_fed_by_the_catalog_write_where_pins_pr_stages(self) -> None:+ with open(os.path.join(ROOT, "scripts/docs-generators/config.json")) as fh:+ generators = json.load(fh)["generators"]+ fed = {+ k: g for k, g in generators.items()+ if g.get("enabled") and {"libs/images/sandbox-images.json", "libs/images/README.md"} & set(g.get("watchPaths", []))+ }+ self.assertIn("sandbox", fed)+ for key, g in fed.items():+ self.assertTrue(g["docsOutputPath"].startswith("docs/content/"), key)+ self.assertFalse(g.get("buildCommand"), f"{key} needs a build pins-pr.sh does not run")+def test_macos_command_refreshes_this_workflow(self) -> None:with open(os.path.join(ROOT, "scripts/images/release-macos.sh")) as fh:script = fh.read()