From 4223ef4c7ac6d3e472611ac2385ce7f1ff7159ee Mon Sep 17 00:00:00 2001 From: notplants <@notplants> Date: Mon, 23 Nov 2026 22:46:29 +0000 Subject: [PATCH] Survey true upstream default branch instead of local abra checkout --- .claude/skills/upgrade-all/SKILL.md | 27 +++++++---- scripts/cc-ci/reconcile-upstream.sh | 4 +- scripts/cc-ci/resolve-images.py | 69 +++++++++++++++++++++++++--- scripts/cc-ci/test-resolve-images.py | 35 ++++++++++++++ 4 files changed, 117 insertions(+), 18 deletions(-) diff --git a/.claude/skills/upgrade-all/SKILL.md b/.claude/skills/upgrade-all/SKILL.md index 5b87811..2bc675e 100644 --- a/.claude/skills/upgrade-all/SKILL.md +++ b/.claude/skills/upgrade-all/SKILL.md @@ -155,15 +155,22 @@ ssh cc-ci 'export PATH=/run/current-system/sw/bin:$PATH; R=; \ script -qec "abra recipe upgrade $R -m -n" /dev/null; \ git -C ~/.abra/recipes/$R stash pop >/dev/null 2>&1 || true' ``` -**Mandatory registry cross-check for EVERY recipe and EVERY image, even if abra says current:** after -reconciling the mirror and refreshing the recipe checkout, run -`python3 /srv/cc-ci/scripts/cc-ci/resolve-images.py --recipe-dir /root/.abra/recipes` -on cc-ci. Read the JSON `images`, `upgrades_available`, `unresolved`, and `all_resolved` fields. -The candidate list is the **union** of abra's upgrades and the resolver's upgrades. CryptPad's -`version-YYYY.M.D` app tag is a known counterexample: abra only reports a parse warning, while the -resolver finds the newer image. A warning is never evidence that an image is current. Inspect both -`newest_same_shape` and `newest_within_major`; a newer major is still a candidate for planning, -though it must not be applied without a compatibility check. +**Authoritative baseline for EVERY recipe and EVERY image:** after reconciling the mirror, run +`python3 /srv/cc-ci/scripts/cc-ci/resolve-images.py --recipe-dir /root/.abra/recipes --upstream-default` +on cc-ci. It queries the true coop-cloud remote's symbolic HEAD (main OR master), fetches that +exact commit without changing the local checkout, and reads compose from the fetched commit. Read +`source.branch`, `source.commit`, `images`, `upgrades_available`, `unresolved`, and +`all_resolved`. If upstream cannot be fetched or has no images, mark the recipe unverified and +investigate; never use the mirror default branch or local abra HEAD as a substitute. + +Abra's upgrade output is a **tag availability hint only**: it may compare against an older local +checkout and therefore show a false upgrade (keycloak 26.8.1→26.8.2), or miss a real one (n8n +and matrix-synapse). Confirm every candidate against the upstream-default resolver's baseline; +the authoritative candidate list comes from that baseline plus any useful open PR relative to it. +CryptPad's `version-YYYY.M.D` app tag is a known counterexample: abra only reports a parse +warning, while the resolver finds the newer image. A warning is never evidence that an image is +current. Inspect both `newest_same_shape` and `newest_within_major`; a newer major is still a +candidate for planning, though it must not be applied without a compatibility check. Build `RECIPES_TO_UPGRADE` from every recipe with at least one candidate **or an open recipe PR that still differs from current upstream**. The second case is a PR reconciliation candidate even @@ -174,7 +181,7 @@ Do not call it GREEN based on CI for an old head, or leave an unmergeable PR as fix. Count its CVEs only from the useful change still absent from current upstream. Only label a recipe -`up-to-date` if abra completed successfully **and** the resolver checked every relevant image +`up-to-date` if the upstream-default resolver checked every relevant image (`all_resolved: true`) **and** neither found a candidate **and no open PR needs reconciliation**. If an image is unresolved, templated, floating, or lacks comparable tags, investigate it directly and record the evidence. Otherwise diff --git a/scripts/cc-ci/reconcile-upstream.sh b/scripts/cc-ci/reconcile-upstream.sh index c505630..c2002e7 100755 --- a/scripts/cc-ci/reconcile-upstream.sh +++ b/scripts/cc-ci/reconcile-upstream.sh @@ -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 diff --git a/scripts/cc-ci/resolve-images.py b/scripts/cc-ci/resolve-images.py index 223faeb..bf0e77e 100644 --- a/scripts/cc-ci/resolve-images.py +++ b/scripts/cc-ci/resolve-images.py @@ -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 [--ssh HOST] [--recipe-dir DIR] [--table] [--only IMAGE] + resolve-images.py --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"))], diff --git a/scripts/cc-ci/test-resolve-images.py b/scripts/cc-ci/test-resolve-images.py index d43dd7a..0f3cb3a 100644 --- a/scripts/cc-ci/test-resolve-images.py +++ b/scripts/cc-ci/test-resolve-images.py @@ -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)):