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

161 lines
15 KiB
Python

"""Missing equipment skill definitions: real source fixture, synthetic icon I/O."""
import copy,hashlib,json,sys,unittest,struct
from pathlib import Path
from types import SimpleNamespace
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
import spell_item_static_compat as m
import spell_passive_compat as codec
from turtle_data import spell_layout
from spell_family_compat import namespace,validate_namespace
class ItemSkillDefinitionTest(unittest.TestCase):
def fixture(self,*,families=False):
f=json.loads((ROOT/'tests/fixtures/item-skill-source.json').read_text())
def table(rows,strings):
text={int(k):v for k,v in strings.items()}
return SimpleNamespace(by_id={int(k):v for k,v in rows.items()},string=text.__getitem__)
dbc=table(f['disk_rows'],f['strings']);proof=namespace(ROOT.parent.parent.parent/'Servers/tortoise-wow/src/game/Database/DBCEnums.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
source=[m.source_spell(dbc,r,spell_layout(),skill_bonus=True,family_namespace=proof)for r in f['server_rows']if families or r['spellFamilyName']==0]
tables={t:table(v['rows'],v['strings'])for t,v in f['source_tables'].items()}
dbd=ROOT.parent/'tools/WoWDBDefs/definitions';schemas={t:codec.fields(dbd/(t+'.dbd'),t)for t in(codec.TABLES|{'SpellClassOptions':codec.SUPPLEMENTAL_TABLES['SpellClassOptions']})}
# Synthetic icon bytes exercise identity/hash checking only. The real
# private generator separately validates its actual6660-byte CASC asset.
raw=b'BLP2'+bytes(20);assets=[dict(path='interface/icons/temp.blp',bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex())]
options=dict(source_tables=tables,target_icon_names={136235:['interface/icons/temp.blp']},new_icon_ids={str(s['entry']):136235 for s in source},icon_assets=assets,read_icon=lambda path:raw)
return f,dbc,source,f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),options
def component(self,v):return m.new_skill_component(*v[2:7],**v[7])
def test_real_source_identity_dependency_and_zero_learned_links(self):
v=self.fixture();before=copy.deepcopy(v[2:7]);r=self.component(v);self.assertEqual(v[2:7],before)
self.assertEqual(len(r['records']),5);self.assertEqual({row['table_name']for row in r['records']},{'Spell','SpellName','SpellMisc','SpellEquippedItems','SpellEffect'})
self.assertTrue(all(row['source_spell_id']==7524 for row in r['records']))
e=next(row['record']for row in r['records']if row['table_name']=='SpellEffect')
self.assertEqual((e['ID'],e['SpellID'],e['EffectAura'],e['EffectBasePointsF'],e['EffectMiscValue']),(1500001,7524,30,4,[43,0]))
self.assertFalse(r['installable']);self.assertFalse(r['engine_accepted']);self.assertFalse(r['spells'][0]['known_spells_modified']);self.assertFalse(r['spells'][0]['installed_definition_absence_verified'])
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[4][row['table_name']]))
def test_talent_skill_aura_and_arbitrary_source_ids_are_not_remapped(self):
v=self.fixture();s=v[2][0];s.update(entry=600125,name='Source unarmed skill fixture',attributes=[192,0,0,0,0]);s['effects'][0][1]=98;s['effects'][0][7]=162;s['effects'][0][2]=4
v[7]['new_icon_ids']={'600125':136235};r=self.component(v);e=next(row['record']for row in r['records']if row['table_name']=='SpellEffect')
self.assertEqual((e['SpellID'],e['EffectAura'],e['EffectMiscValue'],e['EffectBasePointsF']),(600125,98,[162,0],5))
self.assertEqual(r['spells'][0]['skill_references'][0]['source_skill_name'],'Unarmed')
def test_repeat_registry_is_stable_and_multiple_ids_sort_deterministically(self):
v=self.fixture();other=copy.deepcopy(v[2][0]);other['entry']=600126;v[2].append(other);v[7]['new_icon_ids']['600126']=136235
r=self.component(v);v[6].update(r['child_id_registry']);v[2].reverse();self.assertEqual(self.component(v),r)
self.assertEqual(r['child_id_registry']['SpellEffect'],{'7524:0':1500001,'600126:0':1500002})
def test_native_timing_skill_and_positive_parent_collisions_fail(self):
for mutation in('positive','missing-context','skill','category','cast','duration','range','icon-id','icon-bytes','new-sla'):
v=self.fixture();n=v[3];options=v[7]
if mutation=='positive':n['SpellName'].append(dict(ID=7524,Name_lang='Existing destination'))
if mutation=='missing-context':del n['SpellClassOptions']
if mutation=='skill':n['SkillLine'][0]['DisplayName_lang']='Other weapon'
if mutation=='category':n['SkillLine'][0]['CategoryID']=9
if mutation=='cast':n['SpellCastTimes'][0]['Base']=10
if mutation=='duration':n['SpellDuration'][0]['Duration']=1000
if mutation=='range':n['SpellRange'][0]['RangeMax']=[30,30]
if mutation=='icon-id':options['target_icon_names']={136235:['interface/icons/other.blp']}
if mutation=='icon-bytes':options['read_icon']=lambda path:b'BLP2'+bytes(21)
if mutation=='new-sla':v[6]['SkillLineAbility']={'7524':1500001}
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def test_source_dependencies_and_nonzero_family_are_not_cleared(self):
v=self.fixture();v[0]['server_rows'][0]['spellFamilyName']=4
with self.assertRaisesRegex(ValueError,'spellFamilyName'):m.source_spell(v[1],v[0]['server_rows'][0],spell_layout(),skill_bonus=True)
for table,ident,index,value in(('SpellCastTimes',1,1,10),('SpellDuration',21,1,1000),('SpellRange',1,3,1)):
v=self.fixture();v[7]['source_tables'][table].by_id[ident][index]=value
with self.assertRaises(ValueError,msg=table):self.component(v)
def test_level_conditions_proc_and_wrong_source_skill_rejected(self):
for mutation in('level','proc','chance','skill','amount','resource','bool'):
v=self.fixture();s=v[2][0]
if mutation=='level':s['levels']['baseLevel']=10
if mutation=='proc':s['conditions']['procFlags']=1
if mutation=='chance':s['conditions']['procChance']=50
if mutation=='skill':s['effects'][0][7]=65536
if mutation=='amount':s['effects'][0][2]=32767
if mutation=='resource':s['power'][1]=10
if mutation=='bool':s['castingTimeIndex']=True
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def test_real_warrior_family_is_preserved_in_32_bit_class_options(self):
v=self.fixture(families=True);r=self.component(v)
self.assertEqual(len(r['records']),11);self.assertEqual([s['spell_id']for s in r['spells']],[7524,52322])
rows=[row for row in r['records']if row['table_name']=='SpellClassOptions'];self.assertEqual(len(rows),1);row=rows[0]
self.assertEqual(row['table_hash'],'0x288eab81');self.assertEqual(row['record']['SpellClassSet'],4)
self.assertEqual(bytes.fromhex(row['wire_hex']),struct.pack('<iIi4i',52322,0,4,0,0,0,0))
self.assertEqual(row['record']['ID'],1500001);self.assertEqual(r['child_id_registry']['SpellEffect'],{'7524:0':1500001,'52322:0':1500002})
effect=next(row['record']for row in r['records']if row['table_name']=='SpellEffect'and row['source_spell_id']==52322)
self.assertEqual((effect['EffectAura'],effect['EffectMiscValue'],effect['EffectBasePointsF']),(98,[162,0],5))
self.assertEqual(r['spells'][1]['class_family']['name'],'SPELLFAMILY_WARRIOR')
self.assertFalse(any(row['table_name']=='SkillLineAbility'for row in r['records']))
def test_nonzero_or_mismatched_family_masks_remain_blocked(self):
for mutation in('raw-mask','disk-mask','wrong-family','normalized-mask','normalized-target','normalized-missing-family','normalized-null-family','native-positive'):
v=self.fixture(families=True);raw=next(r for r in v[0]['server_rows']if r['entry']==52322);disk=v[1].by_id[52322]
if mutation in('raw-mask','disk-mask','wrong-family'):
if mutation=='raw-mask':raw['spellFamilyFlags']=1;disk[161]=1
if mutation=='disk-mask':disk[162]=1
if mutation=='wrong-family':raw['spellFamilyName']=3;disk[160]=3
proof=namespace(ROOT.parent.parent.parent/'Servers/tortoise-wow/src/game/Database/DBCEnums.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
with self.assertRaises(ValueError,msg=mutation):m.source_spell(v[1],raw,spell_layout(),skill_bonus=True,family_namespace=proof)
else:
src=next(s for s in v[2]if s['entry']==52322)
if mutation=='normalized-mask':src['class_family']['target_mask'][3]=1
if mutation=='normalized-target':src['class_family']['target_id']=8
if mutation=='normalized-missing-family':del src['class_family']
if mutation=='normalized-null-family':src['class_family']=None
if mutation=='native-positive':v[3]['SpellClassOptions'].append(dict(ID=12,SpellID=52322,ModalNextSpell=0,SpellClassSet=4,SpellClassMask=[0]*4))
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def test_family_policy_is_explicit_and_schema_is_build_pinned(self):
v=self.fixture(families=True);raw=next(r for r in v[0]['server_rows']if r['entry']==52322)
with self.assertRaises(ValueError):m.source_spell(v[1],raw,spell_layout(),skill_bonus=True)
proof=namespace(ROOT.parent.parent.parent/'Servers/tortoise-wow/src/game/Database/DBCEnums.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
proof['target']['SPELLFAMILY_WARRIOR']=8
with self.assertRaises(ValueError):validate_namespace(proof)
self.assertEqual(v[4]['SpellClassOptions'],[('SpellID','int',32,False,1),('ModalNextSpell','int',32,True,1),('SpellClassSet','int',32,False,1),('SpellClassMask','int',32,False,4)])
class ItemStaticDefinitionTest(unittest.TestCase):
def fixture(self,policy):
v=list(ItemSkillDefinitionTest().fixture());f=json.loads((ROOT/'tests/fixtures'/('item-swim-speed-source.json'if policy=='swim-speed'else 'item-school-damage-source.json')).read_text())
rows=f.get('server_rows',[f.get('source')]);disk=f.get('disk_rows',{'8747':f.get('disk')})
dbc=SimpleNamespace(by_id={int(k):r for k,r in disk.items()},string={int(k):s for k,s in f['strings'].items()}.__getitem__)
proof=namespace(ROOT.parent.parent.parent/'Servers/tortoise-wow/src/game/Database/DBCEnums.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
opts=dict(percent_stat=policy)if policy=='swim-speed'else dict(school_damage=True)
v[2]=[m.source_spell(dbc,r,spell_layout(),family_namespace=proof,**opts)for r in rows]
v[4]['SpellLevels']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellLevels.dbd','SpellLevels');v[5]['SpellLevels']=1500000
del v[7]['source_tables']['SkillLine'];v[7]['new_icon_ids']={str(s['entry']):136235 for s in v[2]};v[7].update(opts)
return v
def component(self,v):return m.new_static_component(*v[2:7],**v[7])
def test_real_swim_level_and_source_school_are_preserved(self):
v=self.fixture('swim-speed');before=copy.deepcopy(v[2:]);r=self.component(v);self.assertEqual(v[2:],before)
rows={r['table_name']:r['record']for r in r['records']};self.assertEqual(len(rows),6)
self.assertEqual((rows['SpellLevels']['SpellLevel'],rows['SpellLevels']['BaseLevel']),(20,0))
self.assertEqual((rows['SpellMisc']['Attributes'][0],rows['SpellMisc']['SchoolMask']),(262208,8))
self.assertEqual((rows['SpellEffect']['EffectAura'],rows['SpellEffect']['EffectBasePointsF'],rows['SpellEffect']['EffectMiscValue']),(58,15,[0,0]))
self.assertEqual(rows['Spell']['Description_lang'],'Increases swim speed by 15%.')
self.assertFalse(r['installable']);self.assertFalse(r['gameplay_verified']);self.assertFalse(r['spells'][0]['known_spells_modified'])
def test_school_index_and_effect_school_mask_do_not_alias(self):
v=self.fixture('school-damage');r=self.component(v);self.assertEqual(len(r['records']),10)
misc=[r['record']for r in r['records']if r['table_name']=='SpellMisc'];effects=[r['record']for r in r['records']if r['table_name']=='SpellEffect']
self.assertEqual([r['SchoolMask']for r in misc],[1,16]);self.assertEqual([r['EffectMiscValue']for r in effects],[[4,0],[16,0]])
self.assertTrue(all(r['EffectAura']==13 and r['EffectBasePointsF']==36 for r in effects))
self.assertTrue(all('$'not in r['record']['Description_lang']and '36'in r['record']['Description_lang']for r in r['records']if r['table_name']=='Spell'))
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[4][row['table_name']]))
v[6].update(r['child_id_registry']);v[2].reverse();self.assertEqual(self.component(v),r)
def test_missing_parent_policy_rejects_positive_children_and_incomplete_dependencies(self):
for mutation in('parent','child','table','icon','duration','chance','level-type','learned-link','wrong-policy','combined-policy','no-policy'):
v=self.fixture('swim-speed');s=v[2][0]
if mutation=='parent':v[3]['SpellName'].append(dict(ID=s['entry'],Name_lang=s['name']))
if mutation=='child':v[3]['SpellLevels'].append(dict(ID=100,SpellID=s['entry'],SpellLevel=20))
if mutation=='table':del v[3]['SpellPower']
if mutation=='icon':v[7]['read_icon']=lambda p:b'BLP2wrong'
if mutation=='duration':v[7]['source_tables']['SpellDuration'].by_id[21][1]=0
if mutation=='chance':s['conditions']['procChance']=50
if mutation=='level-type':s['levels']['spellLevel']=True
if mutation=='learned-link':v[6]['SkillLineAbility']={'8747':1500001}
if mutation=='wrong-policy':v[7]['percent_stat']='weapon-crit'
if mutation=='combined-policy':v[7]['school_damage']=True
if mutation=='no-policy':del v[7]['percent_stat']
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def test_arbitrary_source_identity_stays_on_parent_and_effect(self):
v=self.fixture('swim-speed');v[2][0]['entry']=600128;v[7]['new_icon_ids']={'600128':136235};r=self.component(v)
self.assertTrue(all(row['source_spell_id']==600128 for row in r['records']))
self.assertEqual(next(row['record']['SpellID']for row in r['records']if row['table_name']=='SpellEffect'),600128)
if __name__=='__main__':unittest.main()