test_footprint_digest.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
2 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
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
2 days ago