Files
WoW-Hybrid-gateway/tests/profession_values_writer_test.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

63 lines
2.7 KiB
Python

"""Independent original 70334 SkillInfo and profession-slot wire goldens."""
import struct
import subprocess
import sys
from pathlib import Path
if not Path(sys.argv[1]).is_file():
sys.exit(77)
P = struct.pack
def bits(fields):
value = ''.join(format(n, f'0{width}b') for n, width in fields)
value += '0' * (-len(value) % 8)
return int(value, 2).to_bytes(len(value) // 8, 'big')
def packed(raw):
mask = sum(1 << i for i, byte in enumerate(raw) if byte)
return P('<H', mask) + bytes(byte for byte in raw if byte)
def golden(rows, slots):
nested_mask = 1
for slot, _ in rows:
for offset in (1, 301, 601, 901, 1201, 1501, 1801):
nested_mask |= 1 << (offset + slot)
blocks = [(nested_mask >> (32 * i)) & 0xffffffff for i in range(66)]
present = sum(1 << i for i, block in enumerate(blocks) if block)
nested = P('<II', present & 0xffffffff, (present >> 32) & 0xffffffff)
nested += bits([((present >> 64) & 3, 2)] + [(v, 32) for v in blocks if v])
for _, row in sorted(rows):
nested += P('<7H', *row)
active_blocks = {1: (1 << 0) | (1 << 31)}
if slots:
active_blocks[13] = 1 | sum(1 << (1 + i) for i in slots)
active = bits([(sum(1 << i for i in active_blocks), 14)] +
[(active_blocks[i], 32) for i in sorted(active_blocks)])
active += nested + b''.join(P('<i', slots[i]) for i in sorted(slots))
values = bytes((1, 0, 3)) + P('<I', 1 << 7) + active
guid = P('<QQ', 4509, (2 << 58) | (70 << 42))
block = b'\0' + packed(guid) + P('<I', len(values)) + values
return P('<HIBI', 0, 1, 0x80, len(block)) + block
def encode(rows, slots):
mask = sum(1 << i for i in slots)
data = P('<HIQB', 70, 0, 4509, mask)
data += b''.join(P('<i', slots[i]) for i in sorted(slots))
data += P('<H', len(rows))
data += b''.join(P('<8H', slot, *row) for slot, row in rows)
return data
fixtures = [
([(10, (186, 1, 1, 1, 75, 0, 0)), (134, (2946, 1, 1, 1, 75, 0, 0))], {0: 186}),
([(10, (186, 1, 2, 1, 75, 65529, 3)), (134, (2946, 1, 2, 1, 75, 65529, 3))], {}),
([(10, (0, 0, 0, 0, 0, 0, 0)), (134, (2946, 0, 0, 1, 0, 0, 0))], {0: 0}),
]
for rows, slots in fixtures:
payload = encode(rows, slots)
actual = subprocess.run([sys.argv[1], '--profession-values'], input=payload, capture_output=True, check=True).stdout
assert actual == golden(rows, slots), 'Original native writer framing, masks or field values differ'
for cut in (0, 14, len(payload) - 1):
assert subprocess.run([sys.argv[1], '--profession-values'], input=payload[:cut], capture_output=True).returncode
print('Profession create, sparse rank/bonus and removal native writer goldens passed')