Fix test failures: update hash test for MD5, handle unicode surrogates

- Update test_hash_uses_sha256_truncated → test_hash_uses_md5_truncated
  to match the SHA256→MD5 change in compression_store.py
- Use errors="surrogatepass" in compute_hash to handle lone surrogates
  in unicode content (fixes pre-existing UnicodeEncodeError)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
chopratejas 2026-03-25 11:32:01 -07:00
parent 4605fc1971
commit cfd44b3f6a
2 changed files with 4 additions and 4 deletions

View file

@ -23,7 +23,7 @@ def generate_request_id() -> str:
def compute_hash(data: str | bytes) -> str:
"""Compute SHA256 hash, returning hex string."""
if isinstance(data, str):
data = data.encode("utf-8")
data = data.encode("utf-8", errors="surrogatepass")
return hashlib.sha256(data).hexdigest()

View file

@ -1249,10 +1249,10 @@ class TestHashCollisionDetection:
# Should not have collision warning
assert "Hash collision detected" not in caplog.text
def test_hash_uses_sha256_truncated(self, store: CompressionStore):
"""Hash is SHA256 truncated to 24 characters."""
def test_hash_uses_md5_truncated(self, store: CompressionStore):
"""Hash is MD5 truncated to 24 characters (fast, non-crypto)."""
content = "test content"
expected_hash = hashlib.sha256(content.encode()).hexdigest()[:24]
expected_hash = hashlib.md5(content.encode()).hexdigest()[:24]
hash_key = store.store(original=content, compressed="[]")