test_footprint_digest.py python
47 lines 1.4 KB
Raw
sha256:106ef9e12cca7f3be3ffb2a6bd3abfa76f032dce453c9e5010d732a8d86f2e14 Reconcile reviewed credential compatibility 32254cd939885d9… Human patch 8 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:106ef9e12cca7f3be3ffb2a6bd3abfa76f032dce453c9e5010d732a8d86f2e14 Reconcile reviewed credential compatibility 32254cd939885d9… Human patch 8 days ago
sha256:c87cf2c2f03da507f66f93922cb339a2cbebb33ad6372a6039032fb09a20da12 Reconcile reviewed Overseer recovery d47291d5d9030de5ebef71… Human minor ⚠ 8 days ago