File size: 1,132 Bytes
10979b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | from pathlib import Path
from scripts.code_fingerprint import build_manifest
def test_code_manifest_is_root_independent_and_content_sensitive(tmp_path: Path) -> None:
first = tmp_path / "first"
second = tmp_path / "second"
for root in (first, second):
(root / "gmnet").mkdir(parents=True)
(root / "scripts").mkdir()
(root / "configs").mkdir()
(root / "gmnet/model.py").write_text("VALUE = 1\n", encoding="utf-8")
left = build_manifest(first)
right = build_manifest(second)
assert left == right
(second / "gmnet/model.py").write_text("VALUE = 2\n", encoding="utf-8")
changed = build_manifest(second)
assert changed["code_sha256"] != left["code_sha256"]
def test_code_manifest_uses_relative_sorted_paths(tmp_path: Path) -> None:
(tmp_path / "gmnet/z").mkdir(parents=True)
(tmp_path / "gmnet/z/b.py").write_text("b\n", encoding="utf-8")
(tmp_path / "gmnet/a.py").write_text("a\n", encoding="utf-8")
records = build_manifest(tmp_path)["files"]
paths = [record["path"] for record in records]
assert paths == ["gmnet/a.py", "gmnet/z/b.py"]
|