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.

fix(spaces): keep prereleases off the Stable Sparkle feed; read Stable the way the app does (CUA-3131) (#6362)

cua-agents[bot]53460af030d4
diff --git a/.github/scripts/check_spaces_site_follows_release.py b/.github/scripts/check_spaces_site_follows_release.py
index f5cf34b437..8b84cb062b 100644
--- a/.github/scripts/check_spaces_site_follows_release.py
+++ b/.github/scripts/check_spaces_site_follows_release.py
@@ -16,6 +16,8 @@ import time
import urllib.error
import urllib.request
+import sparkle_feed
+
class _NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *a, **k):
@@ -36,7 +38,9 @@ def fetch(url, method="GET", follow=True, headers=None):
FEEDS = {
- "sparkle": ("cua-spaces-appcast.xml", r"<sparkle:shortVersionString>([^<]+)<"),
+ # Sparkle: the newest item with no channel (what Stable apps get), not the
+ # first item: a beta item sits on top of the feed (CUA-3131).
+ "sparkle": ("cua-spaces-appcast.xml", None),
"electron-win": ("latest.yml", r"(?m)^version:\s*(\S+)"),
"electron-linux": ("latest-linux.yml", r"(?m)^version:\s*(\S+)"),
}
@@ -72,9 +76,18 @@ def mismatches(repo, ver, tag, feeds, token):
for name in feeds:
fname, rx = FEEDS[name]
s, _, b = fetch(base + fname)
- m = re.search(rx, b.decode("utf-8", "replace"))
- if not m or m.group(1) != ver:
- bad.append("updater feed %s advertises %s (status %s)" % (name, m.group(1) if m else None, s))
+ text = b.decode("utf-8", "replace")
+ if rx is None:
+ try:
+ fv = sparkle_feed.stable_version(text)
+ bad += ["updater feed %s: %s" % (name, v) for v in sparkle_feed.violations(text)]
+ except Exception as e: # noqa: BLE001 - unparsable feed
+ fv = "unparsable (%s)" % str(e)[:40]
+ else:
+ m = re.search(rx, text)
+ fv = m.group(1) if m else None
+ if fv != ver:
+ bad.append("updater feed %s advertises %s (status %s)" % (name, fv, s))
return bad
diff --git a/.github/scripts/sparkle_feed.py b/.github/scripts/sparkle_feed.py
new file mode 100644
index 0000000000..aa7231cc8f
--- /dev/null
+++ b/.github/scripts/sparkle_feed.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+"""Read the Cua Spaces Sparkle appcast the way the app does (CUA-3131).
+
+Sparkle offers an app on Stable only the items with no <sparkle:channel>; an
+app on Beta also gets the `beta` items. So the newest stable version is the
+newest *untagged* item by <sparkle:version>, not the first item in the file.
+
+ python3 sparkle_feed.py check FEED.xml # exit 1 if any item is on the wrong channel
+ python3 sparkle_feed.py stable FEED.xml # print the version Stable apps are offered
+
+`check` is the invariant that keeps prereleases off Stable: an X.Y.Z-nightly...
+item must carry `nightly`, any other X.Y.Z-suffix item `beta`, and a plain
+X.Y.Z item no channel at all (a tagged stable release would hide from Stable).
+"""
+import re
+import sys
+import xml.etree.ElementTree as ET
+
+SP = "http://www.andymatuschak.org/xml-namespaces/sparkle"
+
+
+def _items(xml_text):
+ return list(ET.fromstring(xml_text).iter("item"))
+
+
+def _short(item):
+ return (item.findtext("{%s}shortVersionString" % SP) or item.findtext("title") or "").strip()
+
+
+def _channel(item):
+ c = item.findtext("{%s}channel" % SP)
+ return c.strip() if c and c.strip() else None
+
+
+def _key(item):
+ return tuple(int(p) for p in re.findall(r"\d+", item.findtext("{%s}version" % SP) or "0"))
+
+
+def want_channel(short_version):
+ """The channel an item of this version must carry (None: the default, Stable)."""
+ base = short_version.split("+", 1)[0]
+ if "-nightly" in base:
+ return "nightly"
+ if "-" in base:
+ return "beta"
+ return None
+
+
+def violations(xml_text):
+ bad = []
+ for item in _items(xml_text):
+ v, have = _short(item), _channel(item)
+ want = want_channel(v)
+ if have != want:
+ bad.append("%s has channel %s, want %s" % (v or "(no version)", have or "(stable)", want or "(stable)"))
+ return bad
+
+
+def stable_version(xml_text):
+ """The version an app on Stable is offered, or None."""
+ items = [i for i in _items(xml_text) if _channel(i) is None]
+ return _short(max(items, key=_key)) if items else None
+
+
+def main(argv):
+ if len(argv) != 3 or argv[1] not in ("check", "stable"):
+ print(__doc__.strip(), file=sys.stderr)
+ return 2
+ with open(argv[2], encoding="utf-8") as f:
+ text = f.read()
+ if argv[1] == "stable":
+ print(stable_version(text) or "")
+ return 0
+ bad = violations(text)
+ for b in bad:
+ print("::error::Sparkle appcast: %s" % b)
+ if bad:
+ print("::error::a prerelease without its channel would update every Stable Mac to it; fix make-appcast.sh or the feed")
+ return 1
+ print("ok: every appcast item is on its channel; Stable is offered %s" % stable_version(text))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/.github/scripts/tests/test_sparkle_feed.py b/.github/scripts/tests/test_sparkle_feed.py
new file mode 100644
index 0000000000..f403eb705b
--- /dev/null
+++ b/.github/scripts/tests/test_sparkle_feed.py
@@ -0,0 +1,49 @@
+"""Run: python3 .github/scripts/tests/test_sparkle_feed.py (CUA-3131)."""
+
+import sys
+import unittest
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+import sparkle_feed as sf # noqa: E402
+
+
+def feed(*items):
+ body = "".join(
+ "<item><title>%s</title>%s<sparkle:version>%s</sparkle:version>"
+ "<sparkle:shortVersionString>%s</sparkle:shortVersionString></item>"
+ % (short, "<sparkle:channel>%s</sparkle:channel>" % ch if ch else "", build, short)
+ for short, build, ch in items
+ )
+ return ('<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">'
+ "<channel><title>Cua Spaces</title>%s</channel></rss>" % body)
+
+
+class SparkleFeed(unittest.TestCase):
+ def test_beta_on_top_is_not_stable(self):
+ # The 3 Nov 2026 feed: 0.20.0-beta.1 (beta) is the first item.
+ f = feed(("0.20.0-beta.1", "0.20.0.129", "beta"), ("0.19.4", "0.19.4.128", None), ("0.19.3", "0.19.3.127", None))
+ self.assertEqual(sf.stable_version(f), "0.19.4")
+ self.assertEqual(sf.violations(f), [])
+
+ def test_untagged_prerelease_fails(self):
+ f = feed(("0.20.0-beta.1", "0.20.0.129", None), ("0.19.4", "0.19.4.128", None))
+ self.assertEqual(len(sf.violations(f)), 1)
+ self.assertEqual(sf.stable_version(f), "0.20.0-beta.1") # what a Stable Mac would get
+
+ def test_wrong_channels_fail(self):
+ f = feed(("0.21.0-nightly.3", "0.21.0.140", "beta"), ("0.19.4", "0.19.4.128", "beta"))
+ self.assertEqual(len(sf.violations(f)), 2)
+
+ def test_nightly_channel(self):
+ f = feed(("0.21.0-nightly.3", "0.21.0.140", "nightly"), ("0.19.4", "0.19.4.128", None))
+ self.assertEqual(sf.violations(f), [])
+ self.assertEqual(sf.stable_version(f), "0.19.4")
+
+ def test_newest_by_build_not_order(self):
+ f = feed(("0.19.3", "0.19.3.127", None), ("0.19.4", "0.19.4.128", None))
+ self.assertEqual(sf.stable_version(f), "0.19.4")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.yml
index 3f6e4441cc..36a7893ea5 100644
--- a/.github/workflows/cd-cua-spaces.yml
+++ b/.github/workflows/cd-cua-spaces.yml
@@ -2331,6 +2331,11 @@ jobs:
with:
name: sparkle-appcast
path: sparkle
+ # Every item on its channel before the feed goes live: a prerelease
+ # without <sparkle:channel> would update every Stable Mac (CUA-3131).
+ - name: Check the Sparkle appcast channels
+ if: needs.build-macos.outputs.appcast == 'true' || needs.electron-mac.outputs.appcast == 'true'
+ run: python3 .github/scripts/sparkle_feed.py check sparkle/cua-spaces-appcast.xml
- name: Upload the Sparkle appcast to cua-spaces-latest
if: needs.build-macos.outputs.appcast == 'true' || needs.electron-mac.outputs.appcast == 'true'
env:
diff --git a/.github/workflows/release-rollout.yml b/.github/workflows/release-rollout.yml
index 513e9905f5..ce6ff39932 100644
--- a/.github/workflows/release-rollout.yml
+++ b/.github/workflows/release-rollout.yml
@@ -102,6 +102,9 @@ jobs:
[ "${PIPESTATUS[0]}" = 0 ]
shopt -s nullglob
for f in out/*.xml; do xmllint --noout "$f"; done
+ # A prerelease must never reach Stable through a rollout edit (CUA-3131).
+ [ -f out/cua-spaces-appcast.xml ] && python3 .github/scripts/sparkle_feed.py check out/cua-spaces-appcast.xml
+ true
- name: Upload the feeds
if: ${{ !inputs.dry_run }}
run: |