from pathlib import Path
import json,re
from lupa.luajit21 import LuaRuntime
R=Path(__file__).resolve().parents[1]
lua=LuaRuntime(unpack_returned_tuples=True);lua.globals().SOURCE=str(R/'src')
n=lua.execute((R/'tests/test_native_compat.lua').read_text())
# Guards must be byte-identical to the upstream DRIVER HUD 1.4.5 reviewed set when a checkout is supplied.
up=Path.home()/'ref/dh/src/native_reader.lua'
same=None
if up.exists():
    pat=re.compile(r'\{0x([0-9a-fA-F]+),"([0-9a-f]+)"\}, -- ')
    a=pat.findall((R/'src/native.lua').read_text());b=pat.findall(up.read_text())
    same=(a==b and len(a)==14);assert same,'guards differ from DRIVER HUD 1.4.5'
r={'native_compat_checks':n,'guards_identical_to_driver_hud_1_4_5':same,'scope':'synthetic PE images; no live game memory','live_verified':False}
(R/'validation').mkdir(exist_ok=True);(R/'validation/native_compat.json').write_text(json.dumps(r,indent=2)+'\n');print(r)
