"""AutoV3 resolution in the download completion path (``_build_metadata_entries``). Covers the Civitai-first / local-header fallback contract: a downloaded file whose Civitai file_info reports no AutoV3 gets the embedded safetensors header hash resolved right away (instead of waiting for the next startup's backfill), and a file with no usable header is marked ``''`` (checked but unavailable). """ import json import struct import pytest from py.services.download_manager import DownloadManager from py.utils.models import LoraMetadata 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("