diff --git a/scripts/resolve/packfiles.py b/scripts/resolve/packfiles.py index 762c4c4fb..c3cdf9c5a 100644 --- a/scripts/resolve/packfiles.py +++ b/scripts/resolve/packfiles.py @@ -73,7 +73,7 @@ def download_external( if declared is None: print(f" WARNING: no hash for {name}, skipping unverifiable download") return False - if OFFLINE if offline is None else offline: + if run_is_offline(offline): print(f" WARNING: {name} is external and the run is offline, not fetched") return False algo, expected = declared[0], set(declared[1]) diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 256391b50..44edcca55 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -7658,6 +7658,13 @@ class ExternalDownloadsFollowTheRunPolicy(unittest.TestCase): ENTRY = {"name": "ext.bin", "source_url": "https://example.invalid/ext.bin", "sha1": hashlib.sha1(b"payload").hexdigest()} + def setUp(self): + # tests/__init__ sets RETROBIOS_OFFLINE for the suite: these cases + # download from a mocked urlopen, so the switch is cleared here. + patcher = mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""}) + patcher.start() + self.addCleanup(patcher.stop) + def _response(self, body: bytes): stream = _ResponseBody(body) response = mock.MagicMock() @@ -7689,6 +7696,18 @@ class ExternalDownloadsFollowTheRunPolicy(unittest.TestCase): finally: packresolve.set_offline(saved) + def test_the_environment_switch_holds_whatever_the_caller_passes(self): + """RETROBIOS_OFFLINE stopped release assets but not external URLs.""" + from resolve import packfiles as packresolve + + with tempfile.TemporaryDirectory() as tmp, \ + mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": "1"}), \ + mock.patch("urllib.request.urlopen") as urlopen, \ + contextlib.redirect_stdout(io.StringIO()): + self.assertFalse( + packresolve.download_external(self.ENTRY, f"{tmp}/x", offline=False)) + urlopen.assert_not_called() + def test_a_verified_body_lands_and_a_wrong_one_is_removed(self): from resolve import packfiles as packresolve