💫 Toolkit to help you get started with SDD or any other process!
fix: use chunked read for integration and preset manifest hash (#3843)
Quratulain-bilald3f921270176
diff --git a/src/specify_cli/integrations/catalog.py b/src/specify_cli/integrations/catalog.pyindex e93dab518..b8d76cb9c 100644--- a/src/specify_cli/integrations/catalog.py+++ b/src/specify_cli/integrations/catalog.py@@ -871,5 +871,8 @@ class IntegrationDescriptor:def get_hash(self) -> str:"""SHA-256 hash of the descriptor file."""+ h = hashlib.sha256()with open(self.path, "rb") as fh:- return f"sha256:{hashlib.sha256(fh.read()).hexdigest()}"+ for chunk in iter(lambda: fh.read(8192), b""):+ h.update(chunk)+ return f"sha256:{h.hexdigest()}"diff --git a/src/specify_cli/presets/__init__.py b/src/specify_cli/presets/__init__.pyindex 54dc5d284..a5cea4f95 100644--- a/src/specify_cli/presets/__init__.py+++ b/src/specify_cli/presets/__init__.py@@ -541,8 +541,11 @@ class PresetManifest:def get_hash(self) -> str:"""Calculate SHA256 hash of manifest file."""+ h = hashlib.sha256()with open(self.path, 'rb') as f:- return f"sha256:{hashlib.sha256(f.read()).hexdigest()}"+ for chunk in iter(lambda: f.read(8192), b""):+ h.update(chunk)+ return f"sha256:{h.hexdigest()}"class PresetRegistry:diff --git a/tests/integrations/test_integration_catalog.py b/tests/integrations/test_integration_catalog.pyindex 87ab98a4d..c414c3d8e 100644--- a/tests/integrations/test_integration_catalog.py+++ b/tests/integrations/test_integration_catalog.py@@ -745,6 +745,10 @@ class TestIntegrationDescriptor:desc = IntegrationDescriptor(p)h = desc.get_hash()assert h.startswith("sha256:")+ import hashlib+ content = p.read_bytes()+ expected = f"sha256:{hashlib.sha256(content).hexdigest()}"+ assert h == expecteddef test_tools_accessor(self, tmp_path):data = {**VALID_DESCRIPTOR, "requires": {diff --git a/tests/test_presets.py b/tests/test_presets.pyindex 660a26d1b..47201d8f6 100644--- a/tests/test_presets.py+++ b/tests/test_presets.py@@ -484,7 +484,10 @@ provides:manifest = PresetManifest(pack_dir / "preset.yml")hash_val = manifest.get_hash()assert hash_val.startswith("sha256:")- assert len(hash_val) > 10+ import hashlib+ content = (pack_dir / "preset.yml").read_bytes()+ expected = f"sha256:{hashlib.sha256(content).hexdigest()}"+ assert hash_val == expecteddef test_multiple_templates(self, temp_dir, valid_pack_data):"""Test pack with multiple templates of different types."""