Spaces:
Running on Zero
Running on Zero
test(models): keep hub tests out of ci and check the manifest against the hub
Browse filesCI runs `pytest -m "not gpu"`, which overrides addopts' "not network",
so a network-marked test would have run there. Network tests now also
skip unless AMS_NETWORK_TESTS=1 is set.
A new opt-in test lists every manifest repo and every LoRA preset at its
pinned 40-hex commit through the Hub tree API and checks that each path
exists with exactly the listed size, so a typo or a wrong size in the
manifest cannot reach a deploy (snapshot_download silently skips paths
that match nothing).
- tests/test_model_store.py +45 -1
tests/test_model_store.py
CHANGED
|
@@ -1335,7 +1335,13 @@ def test_diagnostics_on_spaces_never_raise_when_everything_fails(tmp_path, roots
|
|
| 1335 |
assert "audio self-test: FAIL" in capsys.readouterr().err
|
| 1336 |
|
| 1337 |
|
| 1338 |
-
# --- opt-in network
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1339 |
|
| 1340 |
_NETWORK_SCRIPT = textwrap.dedent(
|
| 1341 |
"""
|
|
@@ -1357,6 +1363,7 @@ _NETWORK_SCRIPT = textwrap.dedent(
|
|
| 1357 |
|
| 1358 |
|
| 1359 |
@pytest.mark.network
|
|
|
|
| 1360 |
def test_network_download_falls_back_to_plain_http_when_xet_cache_is_unwritable(tmp_path, chmod_tree):
|
| 1361 |
xet = tmp_path / "xet-readonly"
|
| 1362 |
xet.mkdir()
|
|
@@ -1387,3 +1394,40 @@ def test_network_download_falls_back_to_plain_http_when_xet_cache_is_unwritable(
|
|
| 1387 |
assert os.stat(snap / "acestep-v15-turbo" / "silence_latent.pt").st_size == 3841215
|
| 1388 |
assert os.stat(snap / "vae" / "config.json").st_size == 425
|
| 1389 |
assert f"RESULT {snap}" in proc.stdout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1335 |
assert "audio self-test: FAIL" in capsys.readouterr().err
|
| 1336 |
|
| 1337 |
|
| 1338 |
+
# --- opt-in network tests -------------------------------------------------------
|
| 1339 |
+
# CI runs `pytest -m "not gpu"`, which overrides addopts' "not network", so the
|
| 1340 |
+
# marker alone does not keep these offline: they also need AMS_NETWORK_TESTS=1.
|
| 1341 |
+
|
| 1342 |
+
network = pytest.mark.skipif(
|
| 1343 |
+
os.getenv("AMS_NETWORK_TESTS") != "1", reason="reaches the Hugging Face Hub; set AMS_NETWORK_TESTS=1"
|
| 1344 |
+
)
|
| 1345 |
|
| 1346 |
_NETWORK_SCRIPT = textwrap.dedent(
|
| 1347 |
"""
|
|
|
|
| 1363 |
|
| 1364 |
|
| 1365 |
@pytest.mark.network
|
| 1366 |
+
@network
|
| 1367 |
def test_network_download_falls_back_to_plain_http_when_xet_cache_is_unwritable(tmp_path, chmod_tree):
|
| 1368 |
xet = tmp_path / "xet-readonly"
|
| 1369 |
xet.mkdir()
|
|
|
|
| 1394 |
assert os.stat(snap / "acestep-v15-turbo" / "silence_latent.pt").st_size == 3841215
|
| 1395 |
assert os.stat(snap / "vae" / "config.json").st_size == 425
|
| 1396 |
assert f"RESULT {snap}" in proc.stdout
|
| 1397 |
+
|
| 1398 |
+
|
| 1399 |
+
def _hub_tree(repo_id: str, revision: str) -> dict[str, int]:
|
| 1400 |
+
"""``{path: size}`` for every file of ``repo_id`` at ``revision``, from the Hub tree API."""
|
| 1401 |
+
import urllib.request
|
| 1402 |
+
|
| 1403 |
+
url = f"https://huggingface.co/api/models/{repo_id}/tree/{revision}?recursive=true"
|
| 1404 |
+
sizes: dict[str, int] = {}
|
| 1405 |
+
while url:
|
| 1406 |
+
with urllib.request.urlopen(url, timeout=60) as resp:
|
| 1407 |
+
for item in json.loads(resp.read()):
|
| 1408 |
+
if item.get("type") == "file":
|
| 1409 |
+
sizes[item["path"]] = item["size"]
|
| 1410 |
+
links = resp.headers.get("Link", "")
|
| 1411 |
+
nxt = [part for part in links.split(",") if 'rel="next"' in part]
|
| 1412 |
+
url = nxt[0].split(";")[0].strip().strip("<>") if nxt else ""
|
| 1413 |
+
return sizes
|
| 1414 |
+
|
| 1415 |
+
|
| 1416 |
+
@pytest.mark.network
|
| 1417 |
+
@network
|
| 1418 |
+
def test_manifest_and_presets_match_the_hub_at_their_pinned_commits():
|
| 1419 |
+
import lora_stack
|
| 1420 |
+
|
| 1421 |
+
checked = 0
|
| 1422 |
+
for repo in _raw_manifest()["repos"]:
|
| 1423 |
+
upstream = _hub_tree(repo["repo_id"], repo["revision"])
|
| 1424 |
+
for f in repo["files"]:
|
| 1425 |
+
assert f["path"] in upstream, f"{repo['repo_id']}@{repo['revision']}: no {f['path']}"
|
| 1426 |
+
assert upstream[f["path"]] == f["size"], (repo["repo_id"], f, upstream[f["path"]])
|
| 1427 |
+
checked += 1
|
| 1428 |
+
for preset in lora_stack.load_presets():
|
| 1429 |
+
assert re.fullmatch(r"[0-9a-f]{40}", preset["revision"]), preset
|
| 1430 |
+
upstream = _hub_tree(preset["hf_id"], preset["revision"])
|
| 1431 |
+
assert preset["filename"] in upstream, preset
|
| 1432 |
+
checked += 1
|
| 1433 |
+
assert checked == sum(len(r["files"]) for r in _raw_manifest()["repos"]) + len(lora_stack.load_presets())
|