mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:28:38 +00:00
Twelve test files failed on main at2d53a8055(CI's check and semantic-tests steps, run locally): most are a test and the code it checks changed by different pull requests in the same merge round. Each fix below is either taken from a closed pull request that already had it, or restores what an earlier merged change intended. From closed pull requests: - test_make_game_resume: FakeProc gets poll(), which translate() now calls (#7018) - test_make_game_empty_translation: the Exited stub gets poll() and the failed-shard path is checked (#7214) - test_shader_checks: stub table_fetch_test in the Wave64Checks harness and count it (#7433) - test_runtime_paths: runtime.yml's path filter lists tools/replace_retry.py, which rdna2spirv.py imports (#7029) - test_psin_names: patch the same_report_path helpers that report_paths now calls (#8719) - test_report_source_collision: the fixture is a real Bink 2 header; bink_index refuses other files (#7408) - test_missing_input_exit_codes: tile_probe checks its inputs before it asks for numpy (#4771) Restored: - merge_check: a failed `git show` is an error again (5b88d58);21016cfbrought back the lenient read that treated it as a new file, while new files are already left out when the diff is read - rpf_probe: a symlinked --out updates its target again (44d3595); 55d21cc's staged write replaced the link Updated to the code: - test_shader_stage_resume: TRANSLATION_SOURCES lists fssm_unpack.py and shader_stage_manifest.py, which the translator imports; existing work folders translate once more after this - test_tool_stdout_encoding: the 15 programs merged without the stdout guard get the same block as the others - test_rdna2spirv_decode: drop the test of decode_any_format, which SHADER-849 replaced with the table decode that tests/semantic/test_format_decode_table.py checks Co-authored-by: jewmaster1337 <102986566+jewmaster1337@users.noreply.github.com> Co-authored-by: TanmaySatyam <248538550+TanmaySatyam@users.noreply.github.com> Co-authored-by: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Co-authored-by: slint6614-dev <359954236+slint6614-dev@users.noreply.github.com> Co-authored-by: BlackNife <108077267+Poussistar@users.noreply.github.com> Co-authored-by: fiestorra <65175643+fiestorra@users.noreply.github.com> Co-authored-by: fearkov <289226582+fearkov@users.noreply.github.com> Co-authored-by: DoubleD17 <48109637+DoubleD17@users.noreply.github.com>
131 lines
5.7 KiB
Python
131 lines
5.7 KiB
Python
"""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("<I", head, 4, len(head))
|
|
return bytes(head) + zlib.compress(payload, 9) + bytes(16)
|
|
|
|
|
|
def make_bvh_payload():
|
|
# Minimal hand-built BVH4 stream (same layout as tests/test_bvh_index.py).
|
|
b = bytearray(0x140)
|
|
struct.pack_into("<I", b, 0x100, 0x81020006)
|
|
struct.pack_into("<I", b, 0x104, 0)
|
|
struct.pack_into("<I", b, 0x20, 0x140)
|
|
struct.pack_into("<I", b, 0x28, 0x40)
|
|
return bytes(b)
|
|
|
|
|
|
class ReportSourceCollisionTest(unittest.TestCase):
|
|
def run_tool(self, name, args):
|
|
command = [sys.executable, "-I", os.path.join(TOOLS_DIR, name)] + args
|
|
return subprocess.run(command, cwd=ROOT, capture_output=True, text=True, timeout=60)
|
|
|
|
def assert_refused_without_touching(self, tool, args, source, contents):
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
src = os.path.join(folder, source)
|
|
with open(src, "wb") as fh:
|
|
fh.write(contents)
|
|
argv = [a.replace("{src}", src) for a in args]
|
|
result = self.run_tool(tool, argv)
|
|
with open(src, "rb") as fh:
|
|
after = fh.read()
|
|
self.assertEqual(after, contents, f"{tool} overwrote its input: {after[:60]!r}")
|
|
self.assertNotEqual(result.returncode, 0, f"{tool} accepted source == output")
|
|
self.assertIn("must not overwrite the source", result.stderr)
|
|
|
|
def test_bink_index_refuses_out_equal_to_source(self):
|
|
self.assert_refused_without_touching(
|
|
"bink_index.py", ["{src}", "--out", "{src}"], "x.bk2", make_bink())
|
|
|
|
def test_bvh_index_refuses_out_equal_to_source(self):
|
|
self.assert_refused_without_touching(
|
|
"bvh_index.py", ["{src}", "--out", "{src}"], "x.rpf", make_rpf(make_bvh_payload()))
|
|
|
|
def test_bvh_index_refuses_csv_equal_to_source(self):
|
|
self.assert_refused_without_touching(
|
|
"bvh_index.py", ["{src}", "--csv", "{src}"], "x.rpf", make_rpf(make_bvh_payload()))
|
|
|
|
def test_anim_index_refuses_out_equal_to_source(self):
|
|
self.assert_refused_without_touching(
|
|
"anim_index.py", ["{src}", "{src}"], "x.rpf", make_rpf(b"\0" * 64, 0x40))
|
|
|
|
def test_anim_index_refuses_rigs_equal_to_source(self):
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
src = os.path.join(folder, "x.rpf")
|
|
contents = make_rpf(b"\0" * 64, 0x40)
|
|
with open(src, "wb") as fh:
|
|
fh.write(contents)
|
|
out = os.path.join(folder, "out.csv")
|
|
result = self.run_tool("anim_index.py", [src, out, "--rigs", src])
|
|
with open(src, "rb") as fh:
|
|
self.assertEqual(fh.read(), contents)
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("must not overwrite the source", result.stderr)
|
|
|
|
def test_rbf0_index_refuses_out_equal_to_source(self):
|
|
self.assert_refused_without_touching(
|
|
"rbf0_index.py", ["{src}", "{src}"], "x.rpf", make_rpf(b"RBF0" + bytes(128), 0x100))
|
|
|
|
def test_rbf0_index_refuses_a_different_spelling_of_the_same_path(self):
|
|
# realpath/normcase, not string equality: .\x.rpf and x.rpf are one file on Windows.
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
src = os.path.join(folder, "x.rpf")
|
|
contents = make_rpf(b"RBF0" + bytes(128), 0x100)
|
|
with open(src, "wb") as fh:
|
|
fh.write(contents)
|
|
other = os.path.join(folder, ".", "x.rpf")
|
|
result = self.run_tool("rbf0_index.py", [src, other])
|
|
with open(src, "rb") as fh:
|
|
self.assertEqual(fh.read(), contents)
|
|
self.assertNotEqual(result.returncode, 0)
|
|
|
|
def test_a_distinct_report_path_still_works(self):
|
|
# The guard must not break the normal path.
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
src = os.path.join(folder, "x.bk2")
|
|
out = os.path.join(folder, "index.csv")
|
|
contents = make_bink()
|
|
with open(src, "wb") as fh:
|
|
fh.write(contents)
|
|
result = self.run_tool("bink_index.py", [src, "--out", out])
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
with open(src, "rb") as fh:
|
|
self.assertEqual(fh.read(), contents)
|
|
self.assertTrue(os.path.isfile(out))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|