The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: update tag selection to work without local refs
Maciej Lisiewskiba7836459338
diff --git a/scripts/releases/pick_tags.py b/scripts/releases/pick_tags.pyindex f8e982d13f0..818dafa7ab9 100644--- a/scripts/releases/pick_tags.py+++ b/scripts/releases/pick_tags.py@@ -6,19 +6,37 @@ import subprocessfrom pathlib import Path+def _git(repo: Path, *args: str) -> str:+ return subprocess.check_output(["git", "-C", str(repo), *args], text=True, encoding="utf-8", timeout=120)++def pick_tags(repo: Path, count: int, exclude: str = "") -> list[str]:if not 1 <= count <= 10:raise ValueError("Tag count must be between one and ten")- raw = subprocess.check_output(["git", "-C", str(repo), "for-each-ref", "--sort=creatordate",- "--format=%(refname:short)", "refs/tags/v*"], text=True, encoding="utf-8")- tags = [tag for tag in raw.splitlines() if re.fullmatch(r"v\d+\.\d+\.\d+(?:\.\d+)?", tag) and tag != exclude]+ # Enumerate origin's tags without fetching any ref: ls-remote lists refs+ # only. The wire protocol cannot match tighter than a glob, so the+ # version-scheme filter stays here.+ raw = _git(repo, "ls-remote", "--refs", "--tags", "origin", "v*")+ tags = [line.split("\t")[1].removeprefix("refs/tags/") for line in raw.splitlines()]+ tags = [tag for tag in tags if re.fullmatch(r"v\d+\.\d+\.\d+(?:\.\d+)?", tag) and tag != exclude]if not tags:raise ValueError("No released baseline tags remain")- if len(tags) <= count:- return tags+ # Creation dates live inside the tag objects, which ls-remote cannot read:+ # date sort keys resolve against the local object store and fail loudly+ # when an object is absent. Fetch exactly the filtered release tags --+ # never the canary and backup refs a full --tags fetch would pull -- so a+ # checkout with no tags at all still gets the same chronological order.+ _git(repo, "fetch", "--quiet", "--no-tags", "origin", *(f"+refs/tags/{tag}:refs/tags/{tag}" for tag in tags))+ # Order the just-fetched refs by creation date locally: no second remote+ # query to fail or to diverge from what the fetch stored above.+ raw = _git(repo, "for-each-ref", "--sort=creatordate", "--format=%(refname:short)",+ *(f"refs/tags/{tag}" for tag in tags))+ ordered = raw.splitlines()+ if len(ordered) <= count:+ return orderedif count == 1:- return [tags[-1]]- return [tags[(slot * (len(tags) - 1) * 2 + count - 1) // ((count - 1) * 2)] for slot in range(count)]+ return [ordered[-1]]+ return [ordered[(slot * (len(ordered) - 1) * 2 + count - 1) // ((count - 1) * 2)] for slot in range(count)]def main():diff --git a/scripts/sandbox/pick-release-tags.sh b/scripts/sandbox/pick-release-tags.shindex 1363eb14c51..623c4cbf487 100755--- a/scripts/sandbox/pick-release-tags.sh+++ b/scripts/sandbox/pick-release-tags.sh@@ -4,7 +4,7 @@# Emits a JSON array of tag names on stdout, suitable for a GitHub Actions# matrix (`fromJSON`). Choosing at runtime rather than hardcoding keeps the# matrix honest as releases land: a pinned list silently stops covering the-# newest release the day after it ships, and pins the "oldest" forever even+# newest release the day after it ships, and pins an "oldest" forever even# after it stops being a version anyone still runs.## Selection: the newest tag, the oldest tag, and evenly spaced tags in between.@@ -17,12 +17,15 @@## --count how many tags to emit (default 5, minimum 1). Fewer tags than# requested emits all of them.-# --repo repository to read tags from (default: this checkout).+# --repo repository whose origin to read tags from (default: this+# checkout).#-# Reads tags from the local checkout, so it needs one fetched with tags-# (actions/checkout with fetch-depth: 0, or `fetch-tags: true`). A shallow-# checkout has no tags and this exits non-zero rather than silently emitting an-# empty matrix.+# Tags come from origin via ls-remote, so a checkout with no local tags works.+# Only the picked tags are fetched into the checkout afterwards -- never the+# canary and backup refs a full --tags fetch would pull -- because the caller+# walks the picked tags' trees, which needs their refs present. Exits non-zero+# when origin has no release tags rather than silently emitting an empty+# matrix.## Only vYYYY.M.D[.N] release tags are considered; the repo also carries# backup/* and one-off tags that are not releases.@@ -42,14 +45,14 @@ while [ "$#" -gt 0 ]; do--repo)[ "$#" -ge 2 ] || { echo 'error: --repo needs a value' >&2; exit 1; }REPO="$2"; shift 2 ;;- -h|--help) sed -n '2,30p' "$0"; exit 0 ;;+ -h|--help) sed -n '2,31p' "$0"; exit 0 ;;*) echo "error: unknown argument: $1" >&2; exit 1 ;;esacdonecase "$COUNT" in''|*[!0-9]*) echo "error: --count must be a positive integer: $COUNT" >&2; exit 1 ;;esac-[ "$COUNT" -ge 1 ] || { echo 'error: --count must be at least 1' >&2; exit 1; }+[ "$COUNT" -ge 1 ] || { echo "error: --count must be at least 1" >&2; exit 1; }# Resolve the script's own location through symlinks, then ask git which# worktree that path belongs to. Deriving the repo from the script rather than@@ -64,19 +67,22 @@ if [ -z "$REPO" ]; thenREPO="$(git -C "$script_dir" rev-parse --show-toplevel 2>/dev/null || printf '%s' "$script_dir")"fi-# sort -V orders v2026.4.8 before v2026.4.13 (numeric), which a plain-# lexicographic sort gets wrong.+# ls-remote lists origin's refs without fetching any objects. sort -V orders+# v2026.4.8 before v2026.4.13 (numeric), which a plain lexicographic sort gets+# wrong; on CalVer names it is also the release chronology, so the list can be+# ordered from the tag names alone.+remote_tags="$(git -C "$REPO" ls-remote --refs --tags origin 'v*')"mapfile -t tags < <(- git -C "$REPO" tag --list 'v*' \+ printf '%s\n' "$remote_tags" \+ | cut -f2 \+ | sed 's|^refs/tags/||' \| grep -E '^v[0-9]{4}\.[0-9]+\.[0-9]+(\.[0-9]+)?$' \| sort -V)total="${#tags[@]}"if [ "$total" -eq 0 ]; then- echo "error: no release tags found in $REPO" >&2- echo ' A shallow clone has no tags: fetch with tags (actions/checkout' >&2- echo ' with fetch-depth: 0, or fetch-tags: true).' >&2+ echo "error: no vYYYY.M.D[.N] release tags found on origin" >&2exit 1fi@@ -102,6 +108,16 @@ elsedonefi+# Materialize exactly the picked tags as local refs: the caller walks the+# picked tags' trees (git ls-tree), which a checkout without tags cannot do.+# The name-based ordering above needs no objects, so unselected releases are+# never fetched.+refs=()+for tag in "${picked[@]}"; do+ refs+=("+refs/tags/$tag:refs/tags/$tag")+done+git -C "$REPO" fetch --quiet --no-tags origin "${refs[@]}"+printf '['for i in "${!picked[@]}"; do[ "$i" -eq 0 ] || printf ','diff --git a/tests/scripts/test_pick_release_tags.py b/tests/scripts/test_pick_release_tags.pynew file mode 100644index 00000000000..5b9793eca89--- /dev/null+++ b/tests/scripts/test_pick_release_tags.py@@ -0,0 +1,51 @@+"""The release-tag picker reads origin, not the local checkout, and keeps CalVer order."""+import subprocess+from pathlib import Path++SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "sandbox" / "pick-release-tags.sh"+++def _git(cwd, *args):+ return subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, text=True)+++def _pick(repo, *args):+ return subprocess.run(["bash", str(SCRIPT), *args, "--repo", str(repo)], check=True, capture_output=True, text=True).stdout.strip()+++def _origin_with_tags(root, tags):+ origin = root / "origin.git"+ _git(root, "init", "--bare", "-b", "main", str(origin))+ seed = root / "seed"+ _git(root, "init", "-b", "main", str(seed))+ _git(seed, "config", "user.name", "fixture")+ _git(seed, "config", "user.email", "[email protected]")+ for tag in tags:+ _git(seed, "commit", "--allow-empty", "-m", tag)+ _git(seed, "tag", tag)+ _git(seed, "push", str(origin), "main", "refs/tags/*:refs/tags/*")+ return origin+++def test_picking_reads_origin_not_local_tags(tmp_path):+ # CalVer names where version order is the chronology but lexicographic+ # order is not: v2026.4.13 sorts before v2026.4.3 as plain text.+ origin = _origin_with_tags(tmp_path, ["v2026.4.3", "v2026.4.13", "v2026.9.15"])+ # --no-local forces the transport, so the tagless clone truly lacks the+ # tag objects, not just their refs.+ _git(tmp_path, "clone", "--no-local", str(origin), str(tmp_path / "with-tags"))+ _git(tmp_path, "clone", "--no-local", "--no-tags", str(origin), str(tmp_path / "tagless"))+ assert _pick(tmp_path / "tagless", "--count", "2") == '["v2026.4.3","v2026.9.15"]'+ # Only the picked tags are materialized; unselected releases are not fetched.+ assert _git(tmp_path / "tagless", "tag", "--list").stdout.split() == ["v2026.4.3", "v2026.9.15"]+ expected = '["v2026.4.3","v2026.4.13","v2026.9.15"]'+ assert _pick(tmp_path / "tagless", "--count", "5") == expected+ assert _pick(tmp_path / "with-tags", "--count", "5") == expected+++def test_picking_rejects_schemes_other_than_calver(tmp_path):+ origin = _origin_with_tags(tmp_path, ["v0.27.0"])+ _git(tmp_path, "clone", "--no-local", "--no-tags", str(origin), str(tmp_path / "tagless"))+ result = subprocess.run(["bash", str(SCRIPT), "--repo", str(tmp_path / "tagless")], check=False, capture_output=True, text=True)+ assert result.returncode != 0+ assert "release tags found on origin" in result.stderrdiff --git a/tests/scripts/test_release_tag_sampling.py b/tests/scripts/test_release_tag_sampling.pyindex 4f6e34651cf..b767ff1ca48 100644--- a/tests/scripts/test_release_tag_sampling.py+++ b/tests/scripts/test_release_tag_sampling.py@@ -1,20 +1,43 @@-"""Release sampling follows tag chronology across CalVer and SemVer."""+"""Release sampling follows tag chronology across CalVer and SemVer, local tags or not."""import osimport subprocessfrom scripts.releases.pick_tags import pick_tags-def test_sampling_includes_newest_stable_and_excludes_candidate(tmp_path):- def git(*args, env=None):- return subprocess.run(["git", *args], cwd=tmp_path, env=env, check=True, capture_output=True, text=True)+def _git(cwd, *args, env=None):+ return subprocess.run(["git", *args], cwd=cwd, env=env, check=True, capture_output=True, text=True)- git("init", "-b", "main")- git("config", "user.name", "fixture")- git("config", "user.email", "[email protected]")++def _seed_origin(root):+ # Origin carrying three release tags created in CalVer-then-SemVer order:+ # the names sort the other way round, so the assertions below pin+ # chronology, not lexicography. v0.27.0 is annotated to cover both tag+ # object kinds the sampling may have to date-sort.+ origin = root / "origin.git"+ _git(root, "init", "--bare", "-b", "main", str(origin))+ seed = root / "seed"+ _git(root, "init", "-b", "main", str(seed))+ _git(seed, "config", "user.name", "fixture")+ _git(seed, "config", "user.email", "[email protected]")for index, tag in enumerate(["v2026.7.20", "v0.27.0", "v0.28.0"]):- env = {**os.environ, "GIT_AUTHOR_DATE": f"2026-08-{index + 1:02d}T00:00:00Z", "GIT_COMMITTER_DATE": f"2026-08-{index + 1:02d}T00:00:00Z"}- git("commit", "--allow-empty", "-m", tag, env=env)- git("tag", tag)- assert pick_tags(tmp_path, 1, "v0.28.0") == ["v0.27.0"]- assert pick_tags(tmp_path, 3, "v0.28.0") == ["v2026.7.20", "v0.27.0"]+ date = f"2026-08-{index + 1:02d}T00:00:00Z"+ env = {**os.environ, "GIT_AUTHOR_DATE": date, "GIT_COMMITTER_DATE": date}+ _git(seed, "commit", "--allow-empty", "-m", tag, env=env)+ if index == 1:+ _git(seed, "tag", "-a", "-m", "annotated", tag, env=env)+ else:+ _git(seed, "tag", tag, env=env)+ _git(seed, "push", str(origin), "main", "refs/tags/*:refs/tags/*")+++def test_sampling_reads_origin_not_local_tags(tmp_path):+ _seed_origin(tmp_path)+ # --no-local forces the transport, so the tagless clone truly lacks the+ # tag objects, not just their refs.+ _git(tmp_path, "clone", "--no-local", str(tmp_path / "origin.git"), str(tmp_path / "with-tags"))+ _git(tmp_path, "clone", "--no-local", "--no-tags", str(tmp_path / "origin.git"), str(tmp_path / "tagless"))+ expected = ["v2026.7.20", "v0.27.0"]+ assert pick_tags(tmp_path / "with-tags", 3, "v0.28.0") == expected+ assert pick_tags(tmp_path / "tagless", 3, "v0.28.0") == expected+ assert pick_tags(tmp_path / "tagless", 1, "v0.28.0") == ["v0.27.0"]