Survey true upstream default branch instead of local abra checkout

This commit is contained in:
notplants
2026-11-23 22:46:29 +00:00
parent 7ead707989
commit 4223ef4c7a
4 changed files with 117 additions and 18 deletions
+2 -2
View File
@@ -28,10 +28,10 @@
set -o errexit -o nounset -o pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ORCH="$(dirname "$HERE")"
ORCH="$(cd "$HERE/../.." && pwd)"
SSH="${SSH:-cc-ci}"
RECONCILE="${RECONCILE:-$ORCH/.claude/skills/recipe-upgrade/open-recipe-pr.sh}"
USED_RECIPES="${USED_RECIPES:-$HERE/used-recipes.md}"
USED_RECIPES="${USED_RECIPES:-$ORCH/data/cc-ci/used-recipes.md}"
[ -f "$RECONCILE" ] || { echo "ERROR: reconcile helper not found: $RECONCILE" >&2; exit 1; }
set -a; . /srv/cc-ci/scripts/cc-ci/load-env.sh; set +a
+63 -6
View File
@@ -15,11 +15,11 @@ kept getting skipped, and why a CVE sweep reported it as unknown.
This reads the compose files directly and queries the registries itself, so a digest pin is just a
digest pin. Output is JSON (default) or a table.
resolve-images.py <recipe> [--ssh HOST] [--recipe-dir DIR] [--table] [--only IMAGE]
resolve-images.py <recipe> --upstream-default [--recipe-dir DIR] [--table] [--only IMAGE]
The cc-ci host has no python3, so `--ssh cc-ci` reads the compose files from that host's checkout
over ssh and does the resolving locally. That keeps the source of truth the SAME tree abra and CI
use, rather than a second copy that can drift.
Use `--upstream-default` on the cc-ci host for weekly surveys. It fetches the real coop-cloud
default branch and reads compose from that exact commit, independent of the mirror default or
the local abra checkout. `--ssh` remains available for reading an existing remote checkout.
TAG SHAPES. Registries mix wildly different tag conventions in one repo, so "newest" is meaningless
without a shape. Each tag is reduced to a signature by replacing digit runs with '#':
@@ -440,6 +440,54 @@ def resolve(ref: str) -> dict:
return out
def compose_images_upstream(recipe: str, recipe_dir: str) -> tuple[list[str], dict]:
"""Read compose from the true upstream default branch, regardless of local HEAD or mirror default.
Fetching updates the object database only; it never checks out a branch or changes the
recipe working tree. An unavailable or ambiguous upstream is an error, never an empty
image list that a caller might mistake for up-to-date.
"""
base = os.path.join(recipe_dir, recipe)
if not os.path.isdir(os.path.join(base, ".git")):
raise RuntimeError(f"recipe checkout missing: {base}")
upstream = f"https://git.coopcloud.tech/coop-cloud/{recipe}.git"
remote = subprocess.run(["git", "-C", base, "remote", "get-url", "upstream"],
capture_output=True, text=True)
if remote.returncode == 0 and remote.stdout.strip():
upstream = remote.stdout.strip()
head = subprocess.run(["git", "ls-remote", "--symref", upstream, "HEAD"],
capture_output=True, text=True, timeout=120)
if head.returncode != 0:
raise RuntimeError(f"cannot query true upstream default branch: {head.stderr.strip()[:200]}")
match = re.search(r"^ref:\s+(refs/heads/[^\s]+)\s+HEAD$", head.stdout, re.M)
sha = re.search(r"^([0-9a-f]{40})\s+HEAD$", head.stdout, re.M)
if not match or not sha:
raise RuntimeError(f"true upstream default branch ambiguous for {recipe}")
branch, commit = match.group(1), sha.group(1)
fetched = subprocess.run(["git", "-C", base, "fetch", "--no-tags", "--quiet", upstream, branch],
capture_output=True, text=True, timeout=180)
if fetched.returncode != 0:
raise RuntimeError(f"cannot fetch true upstream {branch}: {fetched.stderr.strip()[:200]}")
present = subprocess.run(["git", "-C", base, "cat-file", "-e", f"{commit}^{{commit}}"],
capture_output=True)
if present.returncode != 0:
raise RuntimeError(f"true upstream changed during fetch; retry {recipe}")
files = subprocess.run(["git", "-C", base, "ls-tree", "-r", "--name-only", commit],
capture_output=True, text=True, check=True).stdout.splitlines()
refs = []
for name in files:
if "/" in name or not re.fullmatch(r"compose[^/]*\.yml", name) or name == "compose.ccci.yml":
continue
content = subprocess.run(["git", "-C", base, "show", f"{commit}:{name}"],
capture_output=True, text=True, check=True).stdout
for image in IMAGE_RE.findall(content):
if image not in refs:
refs.append(image)
if not refs:
raise RuntimeError(f"no image refs in true upstream {branch} at {commit[:8]} for {recipe}")
return refs, {"url": upstream, "branch": branch, "commit": commit}
def compose_images_ssh(recipe: str, host: str, recipe_dir: str) -> list[str]:
"""Same as compose_images, but the recipe tree lives on another host (cc-ci has no python3)."""
# NB: no shell-quoting of the directory — it may legitimately start with ~ or $HOME, and
@@ -482,18 +530,27 @@ def main() -> int:
help="read the recipe's compose files from HOST over ssh (e.g. --ssh cc-ci); "
"resolving still happens locally")
ap.add_argument("--recipe-dir", default=RECIPE_DIR)
ap.add_argument("--upstream-default", action="store_true",
help="fetch and read the true coop-cloud default branch, ignoring local HEAD and mirror default")
ap.add_argument("--table", action="store_true", help="human-readable table instead of JSON")
ap.add_argument("--only", default=None, help="resolve just the images whose ref contains this")
a = ap.parse_args()
rdir = a.recipe_dir if a.recipe_dir != RECIPE_DIR or not a.ssh else "~/.abra/recipes"
refs = (compose_images_ssh(a.recipe, a.ssh, rdir) if a.ssh
else compose_images(a.recipe, a.recipe_dir))
if a.upstream_default and a.ssh:
ap.error("--upstream-default must run on the host with the recipe checkout")
source = None
if a.upstream_default:
refs, source = compose_images_upstream(a.recipe, a.recipe_dir)
else:
refs = (compose_images_ssh(a.recipe, a.ssh, rdir) if a.ssh
else compose_images(a.recipe, a.recipe_dir))
if a.only:
refs = [r for r in refs if a.only in r]
results = [resolve(r) for r in refs]
report = {
"recipe": a.recipe,
"source": source,
"images": results,
"upgrades_available": [r["ref"] for r in results if r["upgrade_available"]],
"unresolved": [r["ref"] for r in results if r["status"].startswith(("error", "skipped", "unverifiable"))],
+35
View File
@@ -3,6 +3,8 @@
import importlib.util
import pathlib
import subprocess
import tempfile
import unittest
from unittest import mock
@@ -13,6 +15,39 @@ spec.loader.exec_module(resolver)
class TestResolverCoverage(unittest.TestCase):
def test_true_upstream_default_ignores_stale_local_and_mirror_branches(self):
def git(*args):
return subprocess.check_output(["git", *map(str, args)], text=True).strip()
for default in ("main", "master"):
with self.subTest(default=default), tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
remote = root / "upstream.git"
checkout = root / "demo"
git("init", "--bare", remote)
git("clone", remote, checkout)
git("-C", checkout, "config", "user.name", "test")
git("-C", checkout, "config", "user.email", "test@example.invalid")
git("-C", checkout, "checkout", "-b", default)
(checkout / "compose.yml").write_text("""services:
app:
image: example:2.0.0
""")
git("-C", checkout, "add", "compose.yml")
git("-C", checkout, "commit", "-m", "true upstream")
git("-C", checkout, "push", "origin", default)
git("--git-dir", remote, "symbolic-ref", "HEAD", f"refs/heads/{default}")
git("-C", checkout, "remote", "add", "upstream", remote)
git("-C", checkout, "checkout", "-b", "stale-mirror")
(checkout / "compose.yml").write_text("""services:
app:
image: example:1.0.0
""")
refs, source = resolver.compose_images_upstream("demo", str(root))
self.assertEqual(refs, ["example:2.0.0"])
self.assertEqual(source["branch"], f"refs/heads/{default}")
self.assertEqual(resolver.compose_images("demo", str(root)), ["example:1.0.0"])
def test_cryptpad_calver_tag_is_found_independently_of_abra(self):
with mock.patch.object(resolver, "list_tags", return_value=(
["version-2026.5.1", "version-2026.10.0", "opendesk-2026.08.04"], None)):