From 63b41faad605746972f3514b3984070350cec102 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Tue, 27 Oct 2026 16:53:50 +0000 Subject: [PATCH] Download model files again after cache eviction --- .../large_file/large_file/large_file_base.py | 2 -- tests/large_file/test_storage_safety.py | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/great_ai/large_file/large_file/large_file_base.py b/great_ai/large_file/large_file/large_file_base.py index 22a12fc..f3f640a 100644 --- a/great_ai/large_file/large_file/large_file_base.py +++ b/great_ai/large_file/large_file/large_file_base.py @@ -4,7 +4,6 @@ import shutil import sys import tempfile from abc import ABC, abstractmethod -from functools import lru_cache from pathlib import Path from types import TracebackType from typing import IO, Any, List, Literal, Optional, Type, Union, cast @@ -163,7 +162,6 @@ class LargeFileBase(ABC): return cast(int, self._version) - @lru_cache(1) def get(self, hide_progress: bool = False) -> Path: """Return path to the proxy of a file (or directory). diff --git a/tests/large_file/test_storage_safety.py b/tests/large_file/test_storage_safety.py index 7ebceba..b4907d3 100644 --- a/tests/large_file/test_storage_safety.py +++ b/tests/large_file/test_storage_safety.py @@ -1,8 +1,11 @@ +import io +import tarfile from pathlib import Path -from typing import Iterator +from typing import Any, Iterator +from unittest.mock import MagicMock, patch import pytest -from great_ai.large_file import LargeFileBase, LargeFileLocal +from great_ai.large_file import LargeFileBase, LargeFileLocal, LargeFileS3 @pytest.fixture(autouse=True) @@ -71,3 +74,29 @@ def test_failed_write_removes_temporary_file() -> None: finally: if temporary is not None: temporary.unlink(missing_ok=True) + + +def test_evicted_remote_model_is_downloaded_again() -> None: + backend = MagicMock() + backend.list_objects_v2.return_value = {"Contents": [{"Key": "model/0"}]} + downloads = [] + + def download( + self: LargeFileS3, remote_path: Any, local_path: Path, hide_progress: bool + ) -> None: + downloads.append(remote_path) + with tarfile.open(local_path, "w:gz") as archive: + payload = b"remote weights" + member = tarfile.TarInfo("model-0") + member.size = len(payload) + archive.addfile(member, io.BytesIO(payload)) + + with ( + patch.object(LargeFileS3, "_client", backend), + patch.object(LargeFileS3, "_download", download), + ): + reader = LargeFileS3("model") + cached = reader.get() + cached.unlink() + assert reader.get().read_text() == "remote weights" + assert downloads == ["model/0", "model/0"]