Backup / gmnet /code /journal_exp /tests /test_code_fingerprint.py
YFanwang's picture
Add files using upload-large-folder tool
10979b5 verified
Raw History Blame Contribute Delete
1.13 kB
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"]