#!/usr/bin/env python3 """Pure unit test for the empty-My-Packs store resolver guard in autopatch.py. Covers the fail-closed guard decision (original -> PATCH, already-patched -> NOOP, unknown -> SKIP) and pins the guarded patch table to the exact RVA/bytes proven on the tested FIFA 17 build (JNZ 0x14869 -> JG 0x14869 at CardsDLL RVA 0x14858). Run: python3 test_autopatch_guard.py """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import autopatch # importable: runtime loop is guarded by `if __name__ == "__main__"` GUARD_VA = 0x180014858 ORIG = bytes.fromhex("750f") # JNZ 0x14869 PATCH = bytes.fromhex("7f0f") # JG 0x14869 def test_table_exact(): assert autopatch.STORE_PATCHES_GUARDED == {GUARD_VA: (ORIG, PATCH)}, \ autopatch.STORE_PATCHES_GUARDED # Byte-level pin so a bad hex literal cannot slip through. assert ORIG == b"\x75\x0f" and PATCH == b"\x7f\x0f" def test_decision(): assert autopatch.guarded_action(ORIG, ORIG, PATCH) == "patch" # apply assert autopatch.guarded_action(PATCH, ORIG, PATCH) == "noop" # already patched assert autopatch.guarded_action(b"\x00\x00", ORIG, PATCH) == "skip" # build mismatch assert autopatch.guarded_action(b"\x90", ORIG, PATCH) == "skip" # wrong length if __name__ == "__main__": test_table_exact() test_decision() print("OK: autopatch guard table + fail-closed decision (PATCH/NOOP/SKIP)")