From c3a7cef195527a6b5acb4aef452a2cfd8ead97ff Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 29 Nov 2026 17:34:01 +0000 Subject: [PATCH] fix(scripts): give a repository not pushed yet no tags The registry answers tags/list for a repository that does not exist yet with 404 NAME_UNKNOWN (OCI distribution spec), which failed the Images version step for the first build of a new image such as molecule-controller. A 404 on the first tags/list page now reads as no tags, so the image gets .0; a 404 on a manifest stays an error. Refs #477 Assisted-by: Claude Code --- scripts/next_image_version.py | 8 +++++++- tests/scripts/test_next_image_version.py | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/scripts/next_image_version.py b/scripts/next_image_version.py index 8c001c4..ae915ea 100644 --- a/scripts/next_image_version.py +++ b/scripts/next_image_version.py @@ -135,7 +135,13 @@ class Registry: def tags(self): tags, path = [], "tags/list" while path: - body, headers = self._get(path) + try: + body, headers = self._get(path) + except RegistryError as exc: + # A repository not pushed yet is 404 NAME_UNKNOWN (OCI distribution spec): no tags. + if exc.status == 404 and not tags: + return [] + raise tags += body.get("tags") or [] link = re.search(r"<[^>]*/tags/list(\?[^>]*)>", headers.get("Link", "")) path = f"tags/list{link[1]}" if link else None diff --git a/tests/scripts/test_next_image_version.py b/tests/scripts/test_next_image_version.py index c57411e..0923464 100644 --- a/tests/scripts/test_next_image_version.py +++ b/tests/scripts/test_next_image_version.py @@ -104,6 +104,7 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler): refuse_token = False no_realm = False empty_token = False + unknown = False # the repository does not exist yet agents = None # a fresh list per test, set in setUp def do_GET(self): @@ -127,6 +128,9 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler): b"{}", extra={"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'}, ) + elif self.unknown: + body = {"errors": [{"code": "NAME_UNKNOWN", "message": "unknown"}]} + self.reply(404, json.dumps(body).encode()) else: self.reply(200, json.dumps({"tags": ["0.1.0"]}).encode()) @@ -150,7 +154,7 @@ class QuietServer(http.server.HTTPServer): class RegistryClient(unittest.TestCase): def setUp(self): FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False - FakeRegistry.empty_token = False + FakeRegistry.empty_token = FakeRegistry.unknown = False FakeRegistry.agents = [] server = QuietServer(("127.0.0.1", 0), FakeRegistry) threading.Thread(target=server.serve_forever, daemon=True).start() @@ -165,6 +169,19 @@ class RegistryClient(unittest.TestCase): for agent in FakeRegistry.agents: self.assertTrue(agent.startswith("kamino-"), agent) + def test_a_repository_not_yet_pushed_has_no_tags(self): + FakeRegistry.unknown = True + self.assertEqual(self.registry.tags(), []) + self.assertEqual( + niv.next_version("0.1", self.registry.tags(), "c", no_label), "0.1.0" + ) + + def test_a_missing_manifest_is_still_a_registry_error(self): + FakeRegistry.unknown = True + with self.assertRaises(niv.RegistryError) as caught: + self.registry.label("0.1.0") + self.assertIn("404", str(caught.exception)) + def test_a_refused_request_names_its_status_and_body(self): FakeRegistry.refuse = True with self.assertRaises(niv.RegistryError) as caught: