import hashlib import json import os import struct import pytest from py.utils.constants import MAX_SAFETENSORS_HEADER_BYTES from py.utils.file_utils import ( calculate_autov3, calculate_sha256, find_preview_file, get_preview_extension, ) def _write_safetensors(path, metadata, payload=b"payload-bytes"): """Write a minimal real safetensors file: 8-byte little-endian header length, a JSON header containing ``__metadata__``, then arbitrary payload.""" header = json.dumps({"__metadata__": metadata}).encode("utf-8") path.write_bytes(struct.pack("