Files

68 lines
3.8 KiB
Python

"""Read actual host DB replies and hotfix initialization from both composed codecs."""
import argparse,hashlib,json,os,struct,sys
from pathlib import Path
from collections import Counter
W=Path('/mnt/Games/@project/build/q103-equipment-provider-20261128');P=W.parents[1];J=Path(__file__).resolve().parent;sys.path.insert(0,str(W))
sys.path.insert(0,str(W.parent/'q103-spell-parity-20261128'))
from overlay import CODEC,MODES,load,initialization,request
from spell_aura_restrictions_hotfix_fixture import db_query
from compose import CH,ITEM,base
def read(p):return json.loads(p.read_text())
def digest(b):return hashlib.sha256(b).hexdigest()
def opened(path):
os.environ['GW_TEST_CODEC_PATH']=str(path)
return load()
def check(root):
m=read(root/'candidate.json')
expected={(r['table'],r['id']):r for r in read(root/'rows.json')}
newpath=root/'host/libforever_codec.so'
CUR=J/'current/host/libforever_codec.so';old=opened(CUR);new=opened(newpath)
assert m['source_codec']==digest(CUR.read_bytes())
for name,pin in m['headers'].items():assert digest((root/'candidate-include/gateway'/name).read_bytes())==pin
charge=read(CH/'replies.json')
equip=read(ITEM/'provider-companion.json')
queries=set(expected)
extra=set()
for r in read(ITEM/'rows/effect-actions.json'):
queries.add((0x00cb674f,r['link']))
for r in read(ITEM/'rows/effect-adds.json'):queries.add((0x4002a5b1,r['ID']))
for i in charge['no_override']:extra.add((0xf04238a5,i))
for r in charge['provided']:queries.add((0xf04238a5,r['row']))
for i in [18469,18608,6203,5546,70739,33511,192]:queries.add((0x919be54e,i))
for i in [94676,94677,193836,193837,170070]:queries.add((0x00cb674f,i))
queries.update(extra);stats=Counter()
for table,rid in sorted(queries):
prior,now=[db_query(c,table,rid) for c in (old,new)]
row=expected.get((table,rid))
if row:
assert prior[:17]==now[:17] and prior[12]==0x20
assert digest(prior[17:])==row['before_sha256'] and now[17:]==bytes.fromhex(row['after_hex'])
stats['expected_changed_valid']+=1
else:
assert prior==now,(hex(table),rid)
if (table,rid) in extra:
assert now[12]==0x60 and len(now)==17
stats[f'unchanged_status_{now[12]:02x}']+=1
before_frames,prior=initialization(old);after_frames,current=initialization(new)
assert before_frames==after_frames and prior==current
for push,_ in current:assert request(old,[push])==request(new,[push])
for pg in m['changed_pages']:
assert digest(request(old,[pg['before']]))==pg['before_reply_sha256']
edited=request(new,[pg['after']])
assert digest(edited)==pg['after_reply_sha256'] and base.wire_digest(edited)==pg['after_fnv64']
assert request(new,[pg['before']])==struct.pack('<II',0,0)
assert request(old,[pg['after']])==struct.pack('<II',0,0)
assert len(expected)==stats['expected_changed_valid']==m['rows']
itemset={(int(r['table_hash'],16),r['id']) for r in equip['rows']}
assert itemset<=set(expected) and len(itemset)==129
return dict(variant=m['variant'],baseline_sha256=m['source_codec'],candidate_sha256=digest(newpath.read_bytes()),
distinct_requests=len(queries),direct=stats,unaffected_physical_charge_rows=len(extra),
original_and_candidate_startup_identical=True,advertised=current,unrelated_advertised_page_payload_unchanged=True,
changed_page_payloads=len(m['changed_pages']),old_ids_absent_on_candidate=True,new_ids_absent_on_original=True,
raw_unchanged_equipment_lookup_coverage='all source-corrected links and new effect IDs; additional Benediction/Royal Seal/Thuggish Shield controls')
if __name__=='__main__':
ap=argparse.ArgumentParser();ap.add_argument('root',type=Path);args=ap.parse_args()
print(json.dumps(check(args.root.resolve()),indent=2))