From cfd44b3f6ab1f79b2b797fdda0ddb044dd494c09 Mon Sep 17 00:00:00 2001 From: chopratejas Date: Wed, 25 Mar 2026 11:32:01 -0700 Subject: [PATCH] Fix test failures: update hash test for MD5, handle unicode surrogates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- headroom/utils.py | 2 +- tests/test_compression_store.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/headroom/utils.py b/headroom/utils.py index 8840b4046..b9d94f604 100644 --- a/headroom/utils.py +++ b/headroom/utils.py @@ -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() diff --git a/tests/test_compression_store.py b/tests/test_compression_store.py index 6e77f650a..2e2f4b5a2 100644 --- a/tests/test_compression_store.py +++ b/tests/test_compression_store.py @@ -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="[]")