test_footprint_digest.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
3 days ago
| 1 | """Unit tests for footprint_digest algorithm (§K4.7).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from cli.digest import ( |
| 6 | FootprintRecord, |
| 7 | canonical_bytes, |
| 8 | compute_footprint_digest, |
| 9 | sha256_hex, |
| 10 | ) |
| 11 | |
| 12 | |
| 13 | def test_deterministic_digest() -> None: |
| 14 | records = [ |
| 15 | FootprintRecord("docs/A.md", sha256_hex(b"alpha\n")), |
| 16 | FootprintRecord("docs/B.md", sha256_hex(b"beta\n")), |
| 17 | ] |
| 18 | d1 = compute_footprint_digest(records) |
| 19 | d2 = compute_footprint_digest(list(reversed(records))) |
| 20 | assert d1 == d2 |
| 21 | assert d1.startswith("sha256:") |
| 22 | |
| 23 | |
| 24 | def test_sort_order_independence() -> None: |
| 25 | a = FootprintRecord("a.txt", sha256_hex(b"x")) |
| 26 | b = FootprintRecord("b.txt", sha256_hex(b"y")) |
| 27 | assert compute_footprint_digest([a, b]) == compute_footprint_digest([b, a]) |
| 28 | |
| 29 | |
| 30 | def test_crlf_normalization_equality() -> None: |
| 31 | assert sha256_hex(b"a\r\nb\n") == sha256_hex(b"a\nb\n") |
| 32 | |
| 33 | |
| 34 | def test_empty_footprint_digest() -> None: |
| 35 | digest = compute_footprint_digest([]) |
| 36 | assert digest == "sha256:" + __import__("hashlib").sha256(b"").hexdigest() |
| 37 | |
| 38 | |
| 39 | def test_single_byte_change_flips_digest() -> None: |
| 40 | r1 = [FootprintRecord("f.txt", sha256_hex(b"same"))] |
| 41 | r2 = [FootprintRecord("f.txt", sha256_hex(b"same!"))] |
| 42 | assert compute_footprint_digest(r1) != compute_footprint_digest(r2) |
| 43 | |
| 44 | |
| 45 | def test_trailing_newlines_preserved() -> None: |
| 46 | assert sha256_hex(b"line\n") != sha256_hex(b"line\n\n") |
| 47 | assert canonical_bytes(b"x\r\n") == b"x\n" |
File History
2 commits
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
3 days ago
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
54 days ago