N-th fix od model DL

This commit is contained in:
Dobromir Popov
2026-07-06 23:41:06 +03:00
parent 4bfdc814e2
commit d83224a62f
5 changed files with 224 additions and 18 deletions

View File

@@ -412,21 +412,15 @@ def test_download_shard_prefers_tracker_model_source_over_huggingface(
monkeypatch,
):
"""A working tracker model source is used exclusively — HF is never contacted."""
source_dir = tmp_path / "source"
source_dir.mkdir()
(source_dir / "config.json").write_text("{}")
(source_dir / "model-00002-of-00004.safetensors").write_text("tracker")
archive = io.BytesIO()
with tarfile.open(fileobj=archive, mode="w") as tf:
tf.add(source_dir / "config.json", arcname="config.json")
tf.add(
source_dir / "model-00002-of-00004.safetensors",
arcname="model-00002-of-00004.safetensors",
)
contents = {
"config.json": b"{}",
"model-00002-of-00004.safetensors": b"tracker",
}
class FakeTrackerResponse:
class FakeFileResponse:
def __init__(self, payload: bytes):
self._payload = io.BytesIO(payload)
self._length = len(payload)
def __enter__(self):
return self
@@ -434,14 +428,23 @@ def test_download_shard_prefers_tracker_model_source_over_huggingface(
def __exit__(self, exc_type, exc, tb):
return False
def getheader(self, name: str):
if name == "Content-Length":
return str(self._length)
if name == "Content-Type":
return "application/octet-stream"
return None
def read(self, size: int = -1) -> bytes:
return self._payload.read(size)
monkeypatch.setattr(
urllib.request,
"urlopen",
lambda *args, **kwargs: FakeTrackerResponse(archive.getvalue()),
)
def fake_urlopen(url, *args, **kwargs):
query = urllib.parse.parse_qs(urllib.parse.urlparse(url).query)
rel = query.get("file", [None])[0]
assert rel in contents, f"unexpected per-file request: {url}"
return FakeFileResponse(contents[rel])
monkeypatch.setattr(urllib.request, "urlopen", fake_urlopen)
hf_calls = []
def fake_snapshot_download(**kwargs):