"""A report tool must never truncate the file it was asked to index. Run with ``python -I tests/test_report_source_collision.py``. Set ``LEONIDA_TOOLS_DIR`` to compare against another revision of the tools (used as the negative control: on main these tests fail because the source file is replaced by the report). All inputs are built here by hand; no game file or game data is used. """ import os import struct import subprocess import sys import tempfile import unittest import zlib ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOLS_DIR = os.environ.get("LEONIDA_TOOLS_DIR", os.path.join(ROOT, "tools")) SENTINEL = b"SYNTHETIC-SOURCE-DO-NOT-OVERWRITE\n" * 4 def make_bink(): """A Bink 2 stream bink_index will accept: the header shape of tests/test_bink_index.py, with the sentinel after it so the source is still recognisable as the file the tool must not replace. bink_index checks a single named file's header before it indexes it (target_problem), because a wrong path or a mislabelled file used to come back as a successful scan of 0 streams. The plain sentinel is neither a KB2 stream nor an RPF archive, so the tool was right to refuse it: the fixture is what was wrong. """ return struct.pack("<4s10I", b"KB2a", 40, 1, 0, 1, 16, 16, 30, 1, 0, 1) + bytes(4) + SENTINEL def make_rpf(payload, head_size=0x40): head = bytearray(head_size) head[0:4] = b"9FPR" struct.pack_into("