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

266 lines
17 KiB
Python

#!/usr/bin/env python3
"""Actual conflicting visual plus independent native wire and mutation guards."""
import copy
import json
from pathlib import Path
import struct
import sys
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'ops'))
from spell_passive_compat import BUILD, fields
from spell_visual_compat import new_visual_candidate, review_candidate
class VisualConversionTest(unittest.TestCase):
def fixture(self):
d = json.loads((ROOT / 'tests/fixtures/cast-impact-visual-source.json').read_text())
schemas = {t: fields(ROOT.parent / 'tools/WoWDBDefs/definitions' / (t + '.dbd'), t)
for t in ('SpellVisual', 'SpellVisualEvent')}
return [d['source'], d['source_kits'], d['native_visual'], d['native_events'], schemas,
dict(SpellVisual=194633, SpellVisualEvent=569762),
dict(schema_version=1, build=BUILD, SpellVisual={}, SpellVisualEvent={}),
dict(SpellVisual={6624}, SpellVisualEvent={188138, 188139, 188140})]
def test_separate_identity_and_only_matched_events(self):
v = self.fixture(); before = copy.deepcopy(v); result = new_visual_candidate(*v)
self.assertEqual(v, before)
self.assertEqual((result['source_visual_id'], result['native_visual_id']), (6624, 194634))
self.assertEqual(len(result['records']), 3)
events = [r['record'] for r in result['records'][1:]]
self.assertEqual([(e['ID'], e['SpellVisualID'], e['SpellVisualKitID'], e['TargetType'])
for e in events], [(569763, 194634, 411, 1), (569764, 194634, 3415, 2)])
self.assertEqual([e['ID'] for e in result['omitted_template_events']], [188139])
self.assertFalse(result['existing_records_modified'])
self.assertFalse(result['dependency_complete'])
self.assertFalse(result['installable'])
def test_independent_wire_vectors(self):
result = new_visual_candidate(*self.fixture()); rows = result['records']
# Noninline ID absent; 6 float offsets, three32-bit scalars, two signed
# attachments, five32-bit fields, two16-bit fields and three32-bit fields.
visual = struct.pack('<6f3I2b5I2H3I', *([0] * 9), -1, 34, *([0] * 10))
self.assertEqual(len(visual), 74)
self.assertEqual(bytes.fromhex(rows[0]['wire_hex']), visual)
for row, start, target, kit in zip(rows[1:], (3, 6), (1, 2), (411, 3415)):
expected = struct.pack('<11i', start, 13, 0, 0, 0, 0, target, kit, 0, 0, 194634)
self.assertEqual(len(expected), 44)
self.assertEqual(bytes.fromhex(row['wire_hex']), expected)
def test_registry_reuse_and_multiple_source_visuals(self):
v = self.fixture(); r = new_visual_candidate(*v); v[6] = r['child_id_registry']
self.assertEqual(new_visual_candidate(*v), r)
# This is a shape policy, not an allowlist for6624 or the cloak spell.
v[0][0] = 6001; v[2]['ID'] = 6001
for e in v[3]: e['SpellVisualID'] = 6001
r = new_visual_candidate(*v)
self.assertEqual(r['native_visual_id'], 194635)
self.assertEqual([r['id'] for r in r['records'][1:]], [569765, 569766])
def test_dependent_review_recomputes_all_bytes_and_source_contracts(self):
v = self.fixture(); r = new_visual_candidate(*v)
self.assertEqual(review_candidate(r, v[4], v[7]), r)
for mutation in ('wire', 'flags', 'source', 'event', 'allocation', 'status'):
changed = copy.deepcopy(r)
if mutation == 'wire': changed['records'][0]['wire_hex'] = '00'
elif mutation == 'flags': changed['records'][0]['record']['Flags'] = 1
elif mutation == 'source': changed['source_visual_row'][5] = 99
elif mutation == 'event': changed['native_events'][0]['StartEvent'] = 7
elif mutation == 'allocation': changed['native_visual_id'] += 1
else: changed['engine_accepted'] = True
with self.assertRaises(ValueError, msg=mutation): review_candidate(changed, v[4], v[7])
def test_reject_unsupported_source_behaviors_and_bad_kits(self):
for index in (1, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15):
v = self.fixture(); v[0][index] = 9
with self.assertRaises(ValueError, msg=str(index)): new_visual_candidate(*v)
for mutation in ('missing', 'extra', 'duplicate', 'width', 'type'):
v = self.fixture()
if mutation == 'missing': v[1].pop()
elif mutation == 'extra': v[1].append([99] * 35)
elif mutation == 'duplicate': v[1][1] = v[1][0]
elif mutation == 'width': v[1][0].pop()
else: v[1][0][0] = True
with self.assertRaises(ValueError, msg=mutation): new_visual_candidate(*v)
def test_reject_missing_wrong_target_or_delayed_positive_event(self):
for mutation in ('target', 'start', 'end', 'kit', 'delay', 'duplicate', 'owner'):
v = self.fixture()
if mutation == 'target': v[3][2]['TargetType'] = 1
elif mutation == 'start': v[3][0]['StartEvent'] = 7
elif mutation == 'end': v[3][0]['EndEvent'] = 8
elif mutation == 'kit': v[3][0]['SpellVisualKitID'] = 99
elif mutation == 'delay': v[3][0]['EndMaxOffsetMs'] = 10
elif mutation == 'duplicate': v[3].append(dict(v[3][0], ID=991))
else: v[3][0]['SpellVisualID'] = 999
with self.assertRaises(ValueError, msg=mutation): new_visual_candidate(*v)
def test_reject_schema_tampering_and_non_neutral_template(self):
for table in ('SpellVisual', 'SpellVisualEvent'):
v = self.fixture(); v[4][table][0] = ('Changed', 'int', 32, False, 1)
with self.assertRaisesRegex(ValueError, 'schema'): new_visual_candidate(*v)
for field in ('Flags', 'StateKit', 'MissileTargetingKit', 'CasterSpellVisualID'):
v = self.fixture(); v[2][field] = 77
with self.assertRaises(ValueError): new_visual_candidate(*v)
def test_reject_registry_collision_floor_and_malformed_keys(self):
for mutation in ('collision', 'new-collision', 'floor', 'type', 'key', 'duplicate'):
v = self.fixture()
if mutation == 'collision':
v[6]['SpellVisual']['6624'] = 194634; v[7]['SpellVisual'].add(194634)
elif mutation == 'new-collision': v[7]['SpellVisual'].add(194634)
elif mutation == 'floor': v[6]['SpellVisual']['6624'] = 194633
elif mutation == 'type': v[6]['SpellVisual']['6624'] = True
elif mutation == 'key': v[6]['SpellVisualEvent']['6624:state'] = 569763
else: v[6]['SpellVisualEvent'] = {'6624:cast': 569763, '6624:impact': 569763}
with self.assertRaises(ValueError, msg=mutation): new_visual_candidate(*v)
class HandKitConversionTest(unittest.TestCase):
def fixture(self):
import spell_visual_compat as visual
f=json.loads((ROOT/'tests/fixtures/hand-kit-resource-remap.json').read_text())
tables=('SpellVisualKit','SpellVisualKitModelAttach','SpellVisualKitEffect')
schemas={t:fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in tables}
registry=dict(schema_version=1,build=BUILD,**{t:{}for t in tables})
return [f['source'],f['template'],f['attachments'],f['effects'],{int(k):v for k,v in f['bindings'].items()},schemas,f['maxima'],registry]
def test_actual_source_kit_clones_complete_children_with_correct_resource_and_stable_ids(self):
from spell_visual_compat import remap_hand_attachment_kit
from spell_passive_compat import encode
args=self.fixture();old=copy.deepcopy(args);result=remap_hand_attachment_kit(*args)
self.assertEqual(args,old);self.assertEqual(len(result['records']),6)
attachments=[r['record']for r in result['records']if r['table_name']=='SpellVisualKitModelAttach']
self.assertEqual({r['AttachmentID']for r in attachments},{21,22})
self.assertEqual({r['SpellVisualEffectNameID']for r in attachments},{45451})
effects=[r['record']for r in result['records']if r['table_name']=='SpellVisualKitEffect']
self.assertEqual({r['Effect']for r in effects if r['EffectType']==2},{r['ID']for r in attachments})
self.assertEqual([r['Effect']for r in effects if r['EffectType']==5],[3091])
for row in result['records']:
self.assertGreater(row['id'],args[6][row['table_name']]);self.assertEqual(bytes.fromhex(row['wire_hex']),encode(row['record'],args[5][row['table_name']]))
self.assertFalse(result['installed']);self.assertFalse(result['asset_payloads_verified']);self.assertFalse(result['engine_accepted'])
args[-1]=result['child_id_registry'];self.assertEqual(remap_hand_attachment_kit(*args),result)
def test_hand_kit_does_not_depend_on_a_particular_source_kit_or_spell_id(self):
from spell_visual_compat import remap_hand_attachment_kit
args=self.fixture();args[0][0]=77777
result=remap_hand_attachment_kit(*args);self.assertEqual(result['source_kit_id'],77777)
self.assertNotIn('source_spell_id',str(result))
def test_source_behavior_and_native_contract_changes_reject_before_candidate_creation(self):
from spell_visual_compat import remap_hand_attachment_kit
for mode in ('source-state','animation','shake','other-attachment','missing-child','offset','flags','sound','effect','path','schema','registry'):
args=self.fixture()
if mode=='source-state':args[0][1]=2
elif mode=='animation':args[0][2]=1
elif mode=='shake':args[0][14]=1
elif mode=='other-attachment':args[0][3]=94
elif mode=='missing-child':args[3].pop()
elif mode=='offset':args[2][0]['Offset'][0]=1
elif mode=='flags':args[2][0]['Flags']=0
elif mode=='sound':args[3][0]['Effect']+=1
elif mode=='effect':args[3][1]['EffectType']=9
elif mode=='path':args[4][416]['native_resource']='spells/fanofknives_impact.m2'
elif mode=='schema':args[5]['SpellVisualKit']=[]
else:args[7]['SpellVisualKit']['collision']=1
with self.assertRaises(ValueError,msg=mode):remap_hand_attachment_kit(*args)
def state_visual_fixture(self):
from spell_visual_compat import remap_hand_attachment_kit
args=self.fixture();cast=remap_hand_attachment_kit(*args)
f=json.loads((ROOT/'tests/fixtures/hand-kit-resource-remap.json').read_text())['state']
state=remap_hand_attachment_kit(f['source'],f['template'],f['attachments'],f['effects'],f['bindings'],args[5],args[6],cast['child_id_registry'],kind='state')
visual=json.loads((ROOT/'tests/fixtures/no-sheath-haste-source.json').read_text())
schemas=dict(args[5],**{t:fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellVisual','SpellVisualEvent')})
maxima=dict(SpellVisual=1000000,SpellVisualEvent=2000000)
registry=dict(schema_version=1,build=BUILD,SpellVisual={},SpellVisualEvent={})
occupied={t:set()for t in schemas}
return [visual['source_visual'],visual['native_visual'],visual['native_events'],{'3010':cast,'3009':state},schemas,maxima,registry,occupied]
def test_source_state_graph_preserves_all_events_and_children_and_survives_json_roundtrip(self):
from spell_visual_compat import new_state_visual_candidate
args=self.state_visual_fixture();old=copy.deepcopy(args);candidate=new_state_visual_candidate(*args)
self.assertEqual(args,old);self.assertEqual(len(candidate['records']),15)
self.assertEqual(candidate['source_visual_id'],2759)
kits={int(k):v['native_kit_id']for k,v in candidate['kit_candidates'].items()}
parent=next(r['record']for r in candidate['records']if r['table_name']=='SpellVisual')
self.assertEqual(parent['StateKit'],kits[3009]);self.assertGreater(parent['ID'],1000000)
events=[r['record']for r in candidate['records']if r['table_name']=='SpellVisualEvent']
self.assertEqual({(e['StartEvent'],e['EndEvent'],e['TargetType'])for e in events},{(3,13,1),(7,8,1),(7,8,2)})
self.assertEqual({e['SpellVisualID']for e in events},{parent['ID']})
self.assertEqual(review_candidate(json.loads(json.dumps(candidate)),args[4],args[7]),candidate)
self.assertFalse(candidate['installed']);self.assertFalse(candidate['asset_payloads_verified'])
def test_state_graph_rejects_missing_roles_wrong_owner_delays_and_allocations(self):
from spell_visual_compat import new_state_visual_candidate
for mode in ('missing-kit','wrong-role','missing-event','delay','parent','child-collision','new-visual-collision','unsupported-source'):
args=self.state_visual_fixture()
if mode=='missing-kit':del args[3]['3009']
elif mode=='wrong-role':args[3]['3009']['inputs']['kind']='cast'
elif mode=='missing-event':args[2].pop()
elif mode=='delay':args[2][0]['StartMinOffsetMs']=1
elif mode=='parent':args[1]['StateKit']=0
elif mode=='child-collision':args[7]['SpellVisualKit'].add(args[3]['3010']['native_kit_id'])
elif mode=='new-visual-collision':args[7]['SpellVisual'].add(1000001)
else:args[0][5]=1
with self.assertRaises(ValueError,msg=mode):new_state_visual_candidate(*args)
def test_state_candidate_cannot_hide_reencoded_wire_changes(self):
from spell_visual_compat import new_state_visual_candidate
from spell_passive_compat import encode
import hashlib
args=self.state_visual_fixture();candidate=new_state_visual_candidate(*args)
for table in('SpellVisualKitModelAttach','SpellVisualEvent'):
bad=copy.deepcopy(candidate);row=next(r for r in bad['records']if r['table_name']==table)
row['record']['SpellVisualEffectNameID'if table=='SpellVisualKitModelAttach'else'SpellVisualKitID']=416
wire=encode(row['record'],args[4][table]);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
with self.assertRaises(ValueError):review_candidate(bad,args[4],args[7])
def mapped_link_fixture(self):
from spell_visual_compat import new_state_visual_candidate
from aura_visual_profile import new_mapped_link_candidate
args=self.state_visual_fixture();graph=new_state_visual_candidate(*args)
f=json.loads((ROOT/'tests/fixtures/no-sheath-haste-source.json').read_text())
schema=fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellXSpellVisual.dbd','SpellXSpellVisual')
registry=dict(schema_version=1,build=BUILD,SpellXSpellVisual={})
link=new_mapped_link_candidate(f['server_row'],f['source_visual'],f['native_visual'],f['native_events'],f['native_links'][0],
schema,1000000,registry,set(),visual_candidate=graph,visual_schemas=args[4])
return link,schema,graph,args[4]
def test_mapped_state_link_preserves_source_spell_and_visual_ids_and_revalidates_json(self):
from aura_visual_profile import review_mapped_link,extend_with_package
from spell_timed_buff_compat import source_spell,presentation_namespace
from turtle_data import spell_layout
from types import SimpleNamespace
link,schema,graph,schemas=self.mapped_link_fixture()
self.assertEqual(link['record']['record']['SpellID'],49367)
self.assertEqual(link['record']['record']['SpellVisualID'],1000001)
self.assertEqual(link['visual_reference']['source_visual_id'],2759)
self.assertEqual(review_mapped_link(json.loads(json.dumps(link)),schema),json.loads(json.dumps(link)))
f=json.loads((ROOT/'tests/fixtures/no-sheath-haste-source.json').read_text());family=json.loads((ROOT/'tests/fixtures/item-proc-source.json').read_text())['family_namespace']
dbc=SimpleNamespace(by_id={49367:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
proof=presentation_namespace(Path('/home/praxis/Servers/tortoise-wow/src/game/Spells/SpellDefines.h'),ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
source=source_spell(dbc,f['server_row'],spell_layout(),family_namespace=family,visual_link=link,presentation_context=proof)
self.assertEqual(source['visuals'],[2759,0]);self.assertEqual(source['attributes'][0],0x40000)
package=dict(build=BUILD,schema='wowstatic_camelot_1_60_1',rows=graph['records']+[link['record']]+[dict(table_name=t,id=49367)for t in('Spell','SpellName')])
profile=extend_with_package([],[f['server_row']],package,schema,visual_candidates={2759:graph},visual_schemas=schemas)
self.assertEqual(profile,[dict(spell=49367,spell_x_spell_visual=1000001,visual=1000001)])
def test_mapped_link_rejects_missing_graph_wrong_ids_and_reencoded_conditions(self):
from aura_visual_profile import review_mapped_link
from spell_passive_compat import encode
import hashlib
for mode in('graph','source','target','condition','schema'):
link,schema,_,_=self.mapped_link_fixture()
if mode=='graph':del link['visual_candidate']
elif mode=='source':link['mapping_inputs']['source']['entry']=1
elif mode=='schema':link['mapping_inputs']['link_schema']=[]
else:
row=link['record'];row['record']['SpellVisualID'if mode=='target'else'ViewerUnitConditionID']=1
wire=encode(row['record'],schema);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
with self.assertRaises(ValueError,msg=mode):review_mapped_link(link,schema)
if __name__ == '__main__': unittest.main()