Survey true upstream default branch #53

Merged
autonomic-bot merged 1 commits from fix/survey-true-upstream into main 2026-11-23 22:46:41 +00:00
4 changed files with 117 additions and 18 deletions
+17 -10
View File
@@ -155,15 +155,22 @@ ssh cc-ci 'export PATH=/run/current-system/sw/bin:$PATH; R=<r>; \
script -qec "abra recipe upgrade $R -m -n" /dev/null; \ script -qec "abra recipe upgrade $R -m -n" /dev/null; \
git -C ~/.abra/recipes/$R stash pop >/dev/null 2>&1 || true' 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 **Authoritative baseline for EVERY recipe and EVERY image:** after reconciling the mirror, run
reconciling the mirror and refreshing the recipe checkout, run `python3 /srv/cc-ci/scripts/cc-ci/resolve-images.py <recipe> --recipe-dir /root/.abra/recipes --upstream-default`
`python3 /srv/cc-ci/scripts/cc-ci/resolve-images.py <recipe> --recipe-dir /root/.abra/recipes` on cc-ci. It queries the true coop-cloud remote's symbolic HEAD (main OR master), fetches that
on cc-ci. Read the JSON `images`, `upgrades_available`, `unresolved`, and `all_resolved` fields. exact commit without changing the local checkout, and reads compose from the fetched commit. Read
The candidate list is the **union** of abra's upgrades and the resolver's upgrades. CryptPad's `source.branch`, `source.commit`, `images`, `upgrades_available`, `unresolved`, and
`version-YYYY.M.D` app tag is a known counterexample: abra only reports a parse warning, while the `all_resolved`. If upstream cannot be fetched or has no images, mark the recipe unverified and
resolver finds the newer image. A warning is never evidence that an image is current. Inspect both investigate; never use the mirror default branch or local abra HEAD as a substitute.
`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. 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 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 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. fix. Count its CVEs only from the useful change still absent from current upstream.
Only label a recipe 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**. (`all_resolved: true`) **and** neither found a candidate **and no open PR needs reconciliation**.
If an image is unresolved, templated, If an image is unresolved, templated,
floating, or lacks comparable tags, investigate it directly and record the evidence. Otherwise floating, or lacks comparable tags, investigate it directly and record the evidence. Otherwise
+2 -2
View File
@@ -28,10 +28,10 @@
set -o errexit -o nounset -o pipefail set -o errexit -o nounset -o pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ORCH="$(dirname "$HERE")" ORCH="$(cd "$HERE/../.." && pwd)"
SSH="${SSH:-cc-ci}" SSH="${SSH:-cc-ci}"
RECONCILE="${RECONCILE:-$ORCH/.claude/skills/recipe-upgrade/open-recipe-pr.sh}" 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; } [ -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 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 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. 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 Use `--upstream-default` on the cc-ci host for weekly surveys. It fetches the real coop-cloud
over ssh and does the resolving locally. That keeps the source of truth the SAME tree abra and CI default branch and reads compose from that exact commit, independent of the mirror default or
use, rather than a second copy that can drift. 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 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 '#': 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 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]: 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).""" """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 # 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); " help="read the recipe's compose files from HOST over ssh (e.g. --ssh cc-ci); "
"resolving still happens locally") "resolving still happens locally")
ap.add_argument("--recipe-dir", default=RECIPE_DIR) 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("--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") ap.add_argument("--only", default=None, help="resolve just the images whose ref contains this")
a = ap.parse_args() a = ap.parse_args()
rdir = a.recipe_dir if a.recipe_dir != RECIPE_DIR or not a.ssh else "~/.abra/recipes" 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 if a.upstream_default and a.ssh:
else compose_images(a.recipe, a.recipe_dir)) 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: if a.only:
refs = [r for r in refs if a.only in r] refs = [r for r in refs if a.only in r]
results = [resolve(r) for r in refs] results = [resolve(r) for r in refs]
report = { report = {
"recipe": a.recipe, "recipe": a.recipe,
"source": source,
"images": results, "images": results,
"upgrades_available": [r["ref"] for r in results if r["upgrade_available"]], "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"))], "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 importlib.util
import pathlib import pathlib
import subprocess
import tempfile
import unittest import unittest
from unittest import mock from unittest import mock
@@ -13,6 +15,39 @@ spec.loader.exec_module(resolver)
class TestResolverCoverage(unittest.TestCase): 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): def test_cryptpad_calver_tag_is_found_independently_of_abra(self):
with mock.patch.object(resolver, "list_tags", return_value=( with mock.patch.object(resolver, "list_tags", return_value=(
["version-2026.5.1", "version-2026.10.0", "opendesk-2026.08.04"], None)): ["version-2026.5.1", "version-2026.10.0", "opendesk-2026.08.04"], None)):