"""TDD — build_presign_payload: client-side Step 1 of the mpack push protocol. PS-1 Given known bytes, mpack_key is "sha256:" + sha256(bytes).hexdigest(). PS-2 size_bytes equals len(mpack_bytes). PS-3 Empty bytes produce a valid (non-empty) mpack_key and size_bytes == 0. PS-4 Two calls with identical bytes produce identical payloads (deterministic). PS-5 Two calls with different bytes produce different mpack_keys. """ from __future__ import annotations from muse.core.mpack import build_presign_payload from muse.core.types import blob_id def test_ps1_mpack_key_is_sha256_prefixed() -> None: data = b"hello mpack" payload = build_presign_payload(data) assert payload["mpack_key"] == blob_id(data) def test_ps2_size_bytes_matches_len() -> None: data = b"x" * 1234 payload = build_presign_payload(data) assert payload["size_bytes"] == 1234 def test_ps3_empty_bytes() -> None: payload = build_presign_payload(b"") assert payload["mpack_key"].startswith("sha256:") assert len(payload["mpack_key"]) == len("sha256:") + 64 assert payload["size_bytes"] == 0 def test_ps4_deterministic() -> None: data = b"same bytes every time" assert build_presign_payload(data) == build_presign_payload(data) def test_ps5_different_bytes_different_key() -> None: a = build_presign_payload(b"aaaa") b = build_presign_payload(b"bbbb") assert a["mpack_key"] != b["mpack_key"]