From 61f49b7ac008e9fa447941bffbefc881edef86f5 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:09:39 +0200 Subject: [PATCH] fix: report missing assets when no cache exists --- scripts/restore_large_files.py | 11 +++++++---- tests/test_audit_regressions.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/scripts/restore_large_files.py b/scripts/restore_large_files.py index 8200cd80..cccfeb5f 100644 --- a/scripts/restore_large_files.py +++ b/scripts/restore_large_files.py @@ -54,11 +54,14 @@ def index_cache(cache_dir: str) -> dict[str, str]: def restore( cache_dir: str, db_path: str, gitignore: str ) -> tuple[int, list[str]]: - if not os.path.isdir(cache_dir): - print(f"No cache at {cache_dir}, nothing to restore") - return 0, [] ignored = gitignored_paths(gitignore) - index = index_cache(cache_dir) + # No cache is not nothing to do: the paths it would have supplied are + # still missing, and the check below is the one that must say so. + if os.path.isdir(cache_dir): + index = index_cache(cache_dir) + else: + print(f"No cache at {cache_dir}") + index = {} db = load_database(db_path) restored = 0 unsatisfied: list[str] = [] diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 8914af3d..b343fb5d 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -1414,6 +1414,28 @@ class CheckoutCompletenessRegressions(unittest.TestCase): finally: os.chdir(cwd) + def test_restore_without_a_cache_names_what_is_missing(self): + """A job that skipped `mkdir .cache/large` exited 0 with every + gitignored file absent: the early return ran before the check.""" + from scripts.restore_large_files import restore + + with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + root = Path(directory) + (root / ".gitignore").write_text("bios/big.bin\n", encoding="utf-8") + (root / "database.json").write_text( + json.dumps({"files": {"a" * 40: {"path": "bios/big.bin"}}}), + encoding="utf-8", + ) + cwd = os.getcwd() + os.chdir(root) + try: + self.assertEqual( + restore("no-cache", "database.json", ".gitignore"), + (0, ["bios/big.bin"]), + ) + finally: + os.chdir(cwd) + class EveryManifestEntryIsFetchable(unittest.TestCase): """An install manifest may not list a file the installer cannot get.