From c07a47362e4c3b4ea6a86f8e0d5e912c3efcac34 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:47:53 +0100 Subject: [PATCH] fix: decide offline once before the release check --- scripts/model/largefiles.py | 11 +++++++---- scripts/resolve/packfiles.py | 2 +- tests/test_large_file_cache.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/scripts/model/largefiles.py b/scripts/model/largefiles.py index 9b1b22a02..587c21199 100644 --- a/scripts/model/largefiles.py +++ b/scripts/model/largefiles.py @@ -241,6 +241,12 @@ def _fetch_asset( *, offline: bool, ) -> str | None: + # RETROBIOS_OFFLINE forbids every network call whatever a caller passes: + # the CI test job sets it, since tests fetching 252 MB assets into the + # shared cache filled the runner's disk and changed what later tests + # resolved. Decided once, so the release check of a cached copy obeys it + # as the download does. + offline = offline or bool(os.environ.get("RETROBIOS_OFFLINE")) cached = os.path.join(dest_dir, name) # Between the existence test and the hash, a concurrent run can drop the # same stale entry: the file is gone by the time this one reads it, and @@ -269,10 +275,7 @@ def _fetch_asset( # (gh release upload --clobber): only a download can answer, and # it replaces the copy only if it verifies. - # RETROBIOS_OFFLINE forbids every download whatever a caller passes: the - # CI test job sets it, since tests fetching 252 MB assets into the shared - # cache filled the runner's disk and changed what later tests resolved. - if offline or os.environ.get("RETROBIOS_OFFLINE"): + if offline: return None os.makedirs(dest_dir, exist_ok=True) diff --git a/scripts/resolve/packfiles.py b/scripts/resolve/packfiles.py index 87a9aee26..762c4c4fb 100644 --- a/scripts/resolve/packfiles.py +++ b/scripts/resolve/packfiles.py @@ -273,7 +273,7 @@ def resolve_file( # exactly what the flag forbids. return (path, status) if path else (None, "not_found") cached = _verified_asset( - name, declared, file_entry, OFFLINE if offline is None else offline, + name, declared, file_entry, run_is_offline(offline), ) if cached: return cached, "release_asset" diff --git a/tests/test_large_file_cache.py b/tests/test_large_file_cache.py index cc7357a50..63d70c225 100644 --- a/tests/test_large_file_cache.py +++ b/tests/test_large_file_cache.py @@ -338,6 +338,22 @@ class TheOfflineSwitchHoldsEverywhere(unittest.TestCase): ) urlopen.assert_not_called() + def test_a_cached_copy_of_another_hash_asks_the_release_nothing(self): + """The release check of a cached copy read the caller's flag only: + under RETROBIOS_OFFLINE it listed the release and HEADed the asset.""" + with tempfile.TemporaryDirectory() as tmp, mock.patch.dict( + os.environ, {"RETROBIOS_OFFLINE": "1"} + ), mock.patch.object(largefiles.upstream, "fetch_body") as fetch_body, \ + mock.patch.object(largefiles.upstream, "open_retrying") as head: + Path(tmp, "asset.bin").write_bytes(PAYLOAD_A) + self.assertIsNone(largefiles.fetch_large_file( + "asset.bin", dest_dir=tmp, + expected_sha1=hashlib.sha1(PAYLOAD_B).hexdigest(), offline=False, + )) + fetch_body.assert_not_called() + head.assert_not_called() + self.assertEqual(Path(tmp, "asset.bin").read_bytes(), PAYLOAD_A) + class HashCacheKeepsEveryDigest(unittest.TestCase): """A cache hit must serve the same five digests a fresh hash produces.