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
+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)):