"""Strict named-bank bridge for grey/OVR/replay/corner/player-blue-line changes.
No gameplay test is run on normalized bytes; old static protected-region gates
use the reconstructed certified parent only. Actual native tests use ROM as-is.
"""
from pathlib import Path
import json,hashlib
from functools import lru_cache
@lru_cache(maxsize=1)
def fixture():return json.loads((Path(__file__).parent/'testcases/preview_scope_fixture.json').read_text())
def prior_scope_image(after):
 # Old historical parents must retain the original independent gate.
 if after[0x9cdc:0x9ce2]!=bytes.fromhex('4ef90025d014') and after[0x25d000:0x25d002]!=bytes.fromhex('6000'):return after
 f=fixture();b=bytearray(after);assert len(b)==3145728
 for r in f['regions']:
  lo,hi=r['start'],r['end'];assert b[lo:hi]==bytes.fromhex(r['expected_new']),('new feature reservation differs from exact frozen source/build',r['name'],hex(lo),hex(hi))
  b[lo:hi]=bytes.fromhex(r['parent_bytes'])
 assert hashlib.sha256(b).hexdigest()==f['parent_sha256'],'outside named grey/OVR/replay/corner/blue-line source reservations'
 return bytes(b)
