Files
WoW-Hybrid-gateway/tests/quest_log_serializer_fixture.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

78 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Independent70334 bit/field goldens against the pinned original UF writers."""
import os
from pathlib import Path
import struct
import subprocess
P=struct.pack
ORACLE=Path(os.environ['QUEST_LOG_ORACLE'])
OUT=Path(os.environ['QUEST_LOG_EVIDENCE'])
OUT.mkdir(parents=True,exist_ok=True)
def dto(slots,removed=(),indices=()):
b=P('<HIQB',70,1,4526,len(slots))
for slot,quest,state,timer,counters in slots:
b+=P('<BIHI4B',slot,quest,state,timer,*counters)
for rows in (removed,indices):
b+=P('<B',len(rows))+b''.join(P('<IB',quest,slot) for quest,slot in rows)
return b
def bits(value):
value+='0'*((-len(value))%8)
return int(value,2).to_bytes(len(value)//8,'big')
def record(slot,create=False):
_,quest,state,timer,counters=slot
objectives=P('<24h',*counters,*([0]*20))
if create:return P('<iH',quest,state)+objectives+P('<qII',timer,0,0)
return bits('1'+f'{0x7fffffff:032b}')+P('<iHqII',quest,state,timer,0,0)+objectives
def expected(slots,removed=(),indices=()):
# Independent Classic group57/slot58+i and map bit26; noQuestLogMask=false.
native=set()
if slots:
native.add(57)
native.update(58+row[0] for row in slots)
if removed or indices:native.update((0,26))
blocks=[sum(1<<(n%32) for n in native if n//32==i) for i in range(11)]
present=sum(1<<i for i,b in enumerate(blocks) if b)
header=bits(f'{present:011b}'+''.join(f'{b:032b}' for b in blocks if b)+'0')
mapping=b''
if removed or indices:
assert len(removed)+len(indices)==1 # byte goldens keep map iteration order independent
mapping=P('<BH',0,len(removed)+len(indices))
if removed:mapping+=P('<iB',removed[0][0],2)
else:mapping+=P('<iBi',indices[0][0],1,indices[0][1])
values=bytes([1,0,3])+P('<I',1<<6)+header+mapping+b''.join(record(r) for r in sorted(slots))
guid=P('<QQ',4526,(2<<58)|(70<<42))
packed=P('<H',sum(1<<i for i,b in enumerate(guid) if b))+bytes(b for b in guid if b)
block=b'\0'+packed+P('<I',len(values))+values
return P('<HIBI',1,1,128,len(block))+block
cases=[
('slot0-create',[(0,101,3,0xffffffff,(1,2,3,63))],[],[(101,0)]),
('slot0-counters-only',[(0,101,1,0xffffffff,(4,5,6,7))],[],[]),
('slot19-timer-only',[(19,202,2,1800000000,(0,0,0,0))],[],[]),
('slot0-clear',[(0,0,0,0,(0,0,0,0))],[(101,0)],[]),
]
for name,slots,removed,indices in cases:
body=dto(slots,removed,indices)
actual=subprocess.run([str(ORACLE),'--values'],input=body,capture_output=True,check=True).stdout
golden=expected(slots,removed,indices)
(OUT/(name+'.original-writer.bin')).write_bytes(actual)
assert actual==golden,(name,actual.hex(),golden.hex())
for n in range(len(body)):
assert subprocess.run([str(ORACLE),'--values'],input=body[:n],capture_output=True).returncode==1
# Exact fixed175array create subwindow,70bytes each, followed by map and empty session count.
slot=(19,202,2,0xffffffff,(63,2,3,4))
body=dto([slot],[],[(202,19)])
actual=subprocess.run([str(ORACLE),'--array-create'],input=body,capture_output=True,check=True).stdout
records=bytearray(175*70)
records[19*70:20*70]=record(slot,True)
golden=bytes(records)+P('<IiiI',1,202,19,0)
assert actual==golden and len(actual)==12266
(OUT/'175-array-create.original-writer.bin').write_bytes(actual)
print('Original70334 QuestLog70-byte create +31-bit nested update, Classic175array/slot0+19/map-add/delete/state/unsigned-seconds goldens PASS')