Coverage for src / invariant / protocol.py: 70.00%
10 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-20 16:05 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-20 16:05 +0000
1"""ICacheable Protocol definition."""
3from typing import BinaryIO, Protocol, runtime_checkable
6@runtime_checkable
7class ICacheable(Protocol):
8 """Protocol for all cacheable data types.
10 All data passed between Nodes must implement this protocol to ensure
11 valid Manifest construction and artifact storage.
12 """
14 def get_stable_hash(self) -> str:
15 """Returns a deterministic SHA-256 hash of the object's structural state.
17 This represents the 'Identity' of the data. The hash must be:
18 - Deterministic: Same inputs always produce same hash
19 - Stable: Hash doesn't change across serialization/deserialization
20 - Collision-resistant: Different inputs should produce different hashes
22 Returns:
23 A hexadecimal SHA-256 hash string (64 characters).
24 """
25 ...
27 def to_stream(self, stream: BinaryIO) -> None:
28 """Serializes the object to a binary stream for persistent storage.
30 Args:
31 stream: A binary I/O stream to write the serialized data to.
33 The serialization format must be deterministic and allow for
34 complete reconstruction via from_stream.
35 """
36 ...
38 @classmethod
39 def from_stream(cls, stream: BinaryIO) -> "ICacheable":
40 """Hydrates the object from a binary stream.
42 Args:
43 stream: A binary I/O stream to read the serialized data from.
45 Returns:
46 An instance of the class with state restored from the stream.
48 This must be the inverse operation of to_stream.
49 """
50 ...