1818 ParsedContainer ,
1919)
2020from agentrun_cli ._utils .cloud_build import (
21+ BUILDER_RELEASE_SHA256 ,
2122 BUILDER_RELEASE_TAG ,
2223 CloudBuildError ,
2324 build_builder_args ,
@@ -159,7 +160,14 @@ def test_ensure_builder_binary_rejects_bad_binpath(monkeypatch, tmp_path):
159160 ensure_builder_binary ()
160161
161162
162- def test_ensure_builder_binary_downloads_latest_with_checksum (monkeypatch , tmp_path ):
163+ def test_builder_release_tag_is_pinned ():
164+ assert BUILDER_RELEASE_TAG .startswith ("v0.0.0-" )
165+ assert BUILDER_RELEASE_TAG != "latest"
166+
167+
168+ def test_ensure_builder_binary_downloads_pinned_version_with_checksum (
169+ monkeypatch , tmp_path
170+ ):
163171 monkeypatch .delenv ("DOCKER_IMAGE_BUILDER_BINPATH" , raising = False )
164172 monkeypatch .delenv ("DOCKER_IMAGE_BUILDER_BINTAG" , raising = False )
165173 monkeypatch .setenv ("HOME" , str (tmp_path ))
@@ -173,18 +181,18 @@ def fake_download(url, target):
173181 assert f"/{ BUILDER_RELEASE_TAG } /" in url
174182 target .write_bytes (content )
175183
176- def fake_download_sha256 ( url , artifact_name ):
177- assert url . endswith ( "/docker-image-builder-linux-amd64.sha256" )
178- assert artifact_name == "docker-image-builder-linux-amd64"
179- return sha256 (content ).hexdigest ()
180-
184+ monkeypatch . setitem (
185+ BUILDER_RELEASE_SHA256 ,
186+ "docker-image-builder-linux-amd64" ,
187+ sha256 (content ).hexdigest (),
188+ )
181189 monkeypatch .setattr (
182190 "agentrun_cli._utils.cloud_build._download_binary" ,
183191 fake_download ,
184192 )
185193 monkeypatch .setattr (
186194 "agentrun_cli._utils.cloud_build._download_sha256" ,
187- fake_download_sha256 ,
195+ lambda * _args : pytest . fail ( "pinned release should use embedded checksum" ) ,
188196 )
189197 binary = ensure_builder_binary ()
190198 expected_suffix = (
@@ -214,7 +222,45 @@ def test_ensure_builder_binary_uses_cached_bintag(monkeypatch, tmp_path):
214222 assert ensure_builder_binary () == str (cached )
215223
216224
217- def test_ensure_builder_binary_replaces_stale_cached_latest (monkeypatch , tmp_path ):
225+ def test_ensure_builder_binary_downloads_custom_bintag_with_remote_checksum (
226+ monkeypatch , tmp_path
227+ ):
228+ monkeypatch .delenv ("DOCKER_IMAGE_BUILDER_BINPATH" , raising = False )
229+ monkeypatch .setenv ("DOCKER_IMAGE_BUILDER_BINTAG" , "custom-tag" )
230+ monkeypatch .setenv ("HOME" , str (tmp_path ))
231+ monkeypatch .setattr (
232+ "agentrun_cli._utils.cloud_build._artifact_name" ,
233+ lambda : "docker-image-builder-linux-amd64" ,
234+ )
235+ content = b"custom"
236+
237+ def fake_download (url , target ):
238+ assert "/custom-tag/" in url
239+ target .write_bytes (content )
240+
241+ def fake_download_sha256 (url , artifact_name ):
242+ assert url .endswith ("/custom-tag/docker-image-builder-linux-amd64.sha256" )
243+ assert artifact_name == "docker-image-builder-linux-amd64"
244+ return sha256 (content ).hexdigest ()
245+
246+ monkeypatch .setattr (
247+ "agentrun_cli._utils.cloud_build._download_binary" ,
248+ fake_download ,
249+ )
250+ monkeypatch .setattr (
251+ "agentrun_cli._utils.cloud_build._download_sha256" ,
252+ fake_download_sha256 ,
253+ )
254+
255+ binary = ensure_builder_binary ()
256+
257+ assert binary .endswith (".docker-image-builder/custom-tag/docker-image-builder" )
258+ assert os .access (binary , os .X_OK )
259+
260+
261+ def test_ensure_builder_binary_replaces_stale_cached_pinned_release (
262+ monkeypatch , tmp_path
263+ ):
218264 monkeypatch .delenv ("DOCKER_IMAGE_BUILDER_BINPATH" , raising = False )
219265 monkeypatch .delenv ("DOCKER_IMAGE_BUILDER_BINTAG" , raising = False )
220266 monkeypatch .setenv ("HOME" , str (tmp_path ))
@@ -232,9 +278,10 @@ def test_ensure_builder_binary_replaces_stale_cached_latest(monkeypatch, tmp_pat
232278 cached .write_bytes (b"old" )
233279 cached .chmod (cached .stat ().st_mode | stat .S_IXUSR )
234280 new_content = b"new"
235- monkeypatch .setattr (
236- "agentrun_cli._utils.cloud_build._download_sha256" ,
237- lambda * _args : sha256 (new_content ).hexdigest (),
281+ monkeypatch .setitem (
282+ BUILDER_RELEASE_SHA256 ,
283+ "docker-image-builder-linux-amd64" ,
284+ sha256 (new_content ).hexdigest (),
238285 )
239286
240287 def fake_download (_url , target ):
@@ -256,9 +303,10 @@ def test_ensure_builder_binary_rejects_checksum_mismatch(monkeypatch, tmp_path):
256303 "agentrun_cli._utils.cloud_build._artifact_name" ,
257304 lambda : "docker-image-builder-linux-amd64" ,
258305 )
259- monkeypatch .setattr (
260- "agentrun_cli._utils.cloud_build._download_sha256" ,
261- lambda * _args : sha256 (b"expected" ).hexdigest (),
306+ monkeypatch .setitem (
307+ BUILDER_RELEASE_SHA256 ,
308+ "docker-image-builder-linux-amd64" ,
309+ sha256 (b"expected" ).hexdigest (),
262310 )
263311 monkeypatch .setattr (
264312 "agentrun_cli._utils.cloud_build._download_binary" ,
@@ -276,9 +324,10 @@ def test_ensure_builder_binary_download_failure(monkeypatch, tmp_path):
276324 "agentrun_cli._utils.cloud_build._artifact_name" ,
277325 lambda : "docker-image-builder-linux-amd64" ,
278326 )
279- monkeypatch .setattr (
280- "agentrun_cli._utils.cloud_build._download_sha256" ,
281- lambda * _args : sha256 (b"bin" ).hexdigest (),
327+ monkeypatch .setitem (
328+ BUILDER_RELEASE_SHA256 ,
329+ "docker-image-builder-linux-amd64" ,
330+ sha256 (b"bin" ).hexdigest (),
282331 )
283332 monkeypatch .setattr (
284333 "agentrun_cli._utils.cloud_build._download_binary" ,
@@ -329,6 +378,11 @@ def read(self):
329378 )
330379
331380
381+ def test_pinned_sha256_rejects_unknown_artifact ():
382+ with pytest .raises (CloudBuildError , match = "missing pinned sha256" ):
383+ cloud_build_mod ._pinned_sha256 ("docker-image-builder-plan9-amd64" )
384+
385+
332386def test_parse_sha256_accepts_raw_digest ():
333387 digest = "a" * 64
334388 assert cloud_build_mod ._parse_sha256 (digest , "artifact" ) == digest
0 commit comments