fix(ci): treat only a NAME_UNKNOWN 404 as an image with no tags
next_image_version.py read any 404 on the first tags/list page as a repository not pushed yet, so a wrong registry path or a proxy's 404 page would restart the image at <base>.0 instead of failing. The OCI distribution spec answers a missing repository with 404 and the error code NAME_UNKNOWN, so only that answer now means no tags. RegistryError carried only the readable text of the body, so it now also carries the body's OCI error codes. The tests cover a plain 404 page and a 404 with another code, both of which now raise. Assisted-by: Claude Code
This commit is contained in:
1 parent
6fee0ea8b2
commit
a48cd063ea
2 files changed
+31
-4
No files matched your search
@@ -105,6 +105,7 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
|
||||
no_realm = False
|
||||
empty_token = False
|
||||
unknown = False # the repository does not exist yet
|
||||
not_found = None # a 404 body without NAME_UNKNOWN
|
||||
agents = None # a fresh list per test, set in setUp
|
||||
|
||||
def do_GET(self):
|
||||
@@ -128,6 +129,8 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
|
||||
b"{}",
|
||||
extra={"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'},
|
||||
)
|
||||
elif self.not_found is not None:
|
||||
self.reply(404, self.not_found, "text/plain")
|
||||
elif self.unknown:
|
||||
body = {"errors": [{"code": "NAME_UNKNOWN", "message": "unknown"}]}
|
||||
self.reply(404, json.dumps(body).encode())
|
||||
@@ -155,6 +158,7 @@ class RegistryClient(unittest.TestCase):
|
||||
def setUp(self):
|
||||
FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False
|
||||
FakeRegistry.empty_token = FakeRegistry.unknown = False
|
||||
FakeRegistry.not_found = None
|
||||
FakeRegistry.agents = []
|
||||
server = QuietServer(("127.0.0.1", 0), FakeRegistry)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
@@ -176,6 +180,17 @@ class RegistryClient(unittest.TestCase):
|
||||
niv.next_version("0.1", self.registry.tags(), "c", no_label), "0.1.0"
|
||||
)
|
||||
|
||||
def test_a_404_without_name_unknown_is_a_registry_error(self):
|
||||
for body in (
|
||||
b"404 page not found",
|
||||
b'{"errors":[{"code":"NOT_FOUND","message":"no such route"}]}',
|
||||
):
|
||||
with self.subTest(body=body):
|
||||
FakeRegistry.not_found = body
|
||||
with self.assertRaises(niv.RegistryError) as caught:
|
||||
self.registry.tags()
|
||||
self.assertEqual(caught.exception.status, 404)
|
||||
|
||||
def test_a_missing_manifest_is_still_a_registry_error(self):
|
||||
FakeRegistry.unknown = True
|
||||
with self.assertRaises(niv.RegistryError) as caught:
|
||||
|
||||
Reference in new issue
Block a user