#!/usr/bin/env python3
"""Receiver geometry, actual native context and unchanged strict live controls."""
from pathlib import Path
import argparse,subprocess,json,hashlib
from finisher_native_checks import verify
ap=argparse.ArgumentParser(description=__doc__);ap.add_argument('rom',type=Path);ap.add_argument('output',type=Path);ap.add_argument('--baseline',required=True,type=Path);ap.add_argument('--state',required=True,type=Path);a=ap.parse_args();h=Path(__file__).resolve().parent;o=a.output.resolve();o.mkdir(parents=True,exist_ok=True)
verify(a.rom,a.baseline,h,o/'native-context')
subprocess.run(['python3',str(h/'verify_finisher_geometry.py'),str(a.rom.resolve()),str(o/'geometry')],check=True)
subprocess.run(['python3',str(h/'verify_finisher_hold.py'),str(a.rom.resolve()),str(o/'second-native-fixture'),'--baseline',str(a.baseline.resolve()),'--state',str(a.state.resolve())],check=True)
(o/'results.json').write_text(json.dumps(dict(rom_sha256=hashlib.sha256(a.rom.read_bytes()).hexdigest(),native_context=True,geometry=True,second_fixture=json.loads((o/'second-native-fixture/results.json').read_text())),indent=2)+'\n')
print('PASS native receiver positioning; exact paired controls, geometry/ABI and unchanged additional live strict fixture')
