Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

test(layer-stream): the cache link rule holds for a local snapshot path (#1665)

Alpamys Makazhan985158460afc
diff --git a/tests/test_hf_cache_link_containment.py b/tests/test_hf_cache_link_containment.py
index c708e043..62101682 100644
--- a/tests/test_hf_cache_link_containment.py
+++ b/tests/test_hf_cache_link_containment.py
@@ -386,3 +386,64 @@ def test_junction_check_reads_the_mount_point_tag(monkeypatch, reparse_tag, expe
monkeypatch.setattr(spectrum_scan, "os", SimpleNamespace(lstat=lambda _path: info))
assert spectrum_scan._is_junction("snapshots/extra") is expected
+
+
+# --- the same rule for a local path to a snapshot (#1511) ---------------------------
+#
+# A local snapshot path is copied only when its weights are symlinks, so these need one.
+
+
[email protected]("where", LINK_TARGETS)
+def test_local_snapshot_path_with_a_linked_blob_store_is_refused(
+ tmp_path, monkeypatch, where
+) -> None:
+ from soup_cli.utils.spectrum_scan import resolve_model_weights
+
+ repo = _repo(tmp_path)
+ target = _link_target(tmp_path, repo, where)
+ _link_blob_store(repo, target)
+ (target / "notes.json").write_text(OUTSIDE, encoding="utf-8")
+ snapshot = _link_snapshot(repo, config="notes.json")
+ monkeypatch.setenv("SOUP_SPECTRUM_CACHE_DIR", str(tmp_path / "soup-cache"))
+
+ with pytest.raises(ValueError, match=IS_A_LINK) as refusal:
+ resolve_model_weights(str(snapshot))
+
+ _assert_refused_as_a_link(refusal, repo, tmp_path)
+
+
+def test_local_snapshot_in_a_plain_folder_cannot_reach_that_folder(tmp_path, monkeypatch) -> None:
+ """No repo folder at all: ``snapshots`` sits in a folder that holds other files."""
+ from soup_cli.utils.spectrum_scan import resolve_model_weights
+
+ folder = tmp_path / "downloads"
+ (folder / "snapshots" / COMMIT).mkdir(parents=True)
+ (folder / WEIGHT_BLOB).write_bytes(WEIGHTS)
+ (folder / "notes.json").write_text(OUTSIDE, encoding="utf-8")
+ (folder / "blobs").symlink_to(folder, target_is_directory=True)
+ snapshot = _link_snapshot(folder, config="notes.json")
+ monkeypatch.setenv("SOUP_SPECTRUM_CACHE_DIR", str(tmp_path / "soup-cache"))
+
+ with pytest.raises(ValueError, match=IS_A_LINK) as refusal:
+ resolve_model_weights(str(snapshot))
+
+ _assert_refused_as_a_link(refusal, folder, tmp_path)
+
+
+@needs_junction
+def test_local_snapshot_path_with_a_junction_inside_is_refused(tmp_path, monkeypatch) -> None:
+ import _winapi
+
+ from soup_cli.utils.spectrum_scan import resolve_model_weights
+
+ snapshot = _link_snapshot(_repo(tmp_path))
+ _winapi.CreateJunction(str(_outside_directory(tmp_path)), str(snapshot / "extra"))
+ monkeypatch.setenv("SOUP_SPECTRUM_CACHE_DIR", str(tmp_path / "soup-cache"))
+
+ with pytest.raises(ValueError, match="directory junction is not allowed: 'extra'"):
+ resolve_model_weights(str(snapshot))
+
+ assert not _weights_root(tmp_path).exists()