from hashlib import sha256

from nutricoach_continuity.contract import (
    SOURCE_FILE_DIGEST,
    SOURCE_ROW_DIGEST,
    SOURCE_ROW_SIZE,
    canonical_source_frame,
)


def test_source_row_reconstructs_exact_bytes_when_bound_fields_are_used() -> None:
    # Given: the sealed r70 row contract
    # When: the canonical frame is reconstructed
    frame = canonical_source_frame()
    # Then: both byte count and authenticated digests match
    assert len(frame) == SOURCE_ROW_SIZE
    assert sha256(frame).hexdigest() == SOURCE_FILE_DIGEST
    assert b'"row_digest":"' + SOURCE_ROW_DIGEST.encode() + b'"' in frame
