mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: decide offline once before the release check
This commit is contained in:
1 parent
1f9633c7e5
commit
c07a47362e
3 files changed
+24
-5
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user