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

81 lines
5.8 KiB
Python

"""Real three-effect source fixture; synthetic payloads, no client/gameplay claim."""
import copy,json,sys,hashlib,unittest
from pathlib import Path
from types import SimpleNamespace
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'tests')]
import spell_item_haste_compat as m
import spell_passive_compat as codec
from spell_definition_common import checked_constant_source
from turtle_data import spell_layout
import spell_restore_compat_test as restore_tests
class ItemHasteTest(unittest.TestCase):
def source(self):
f=json.loads((ROOT/'tests/fixtures/item-haste-source.json').read_text());dbc=SimpleNamespace(by_id={13679:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
return f,dbc,m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],semantics=f['semantics'])
def fixture(self):
f,_,src=self.source();v=list(restore_tests.RestorationCompatibilityTest().new_fixture());v[0]=[src]
v[2]['SpellCategories']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellCategories.dbd','SpellCategories');v[3]['SpellCategories']=1500000
v[1]['SpellDuration']=[dict(ID=21,Duration=-1,MaxDuration=-1,DurationPerResource=0)]
v[5]['source_tables']['SpellDuration']=SimpleNamespace(by_id={21:[21,0xffffffff,0,0xffffffff]})
path='interface/icons/spell_nature_invisibilty.blp';raw=b'BLP2'+bytes(20)
v[5].update(new_icon_ids={'13679':136047},target_icon_names={136047:[path]},icon_assets=[dict(path=path,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex())],read_icon=lambda p:raw)
v[5]['source_tables']['SpellIcon']=SimpleNamespace(by_id={30:f['source_icon_row']},string=lambda _:f['source_icon_string'])
return v
def test_all_source_meanings_and_three_effects_preserved(self):
v=self.fixture();before=copy.deepcopy(v[:5]);r=m.new_component(*v[:5],**v[5]);self.assertEqual(v[:5],before);self.assertEqual(len(r['records']),9)
by={x['table_name']:x['record']for x in r['records']}
self.assertEqual(by['SpellMisc']['Attributes'],[448,0x10000000]+[0]*15);self.assertEqual(by['SpellMisc']['SchoolMask'],8)
self.assertEqual(by['SpellCategories']['DefenseType'],1);self.assertEqual(by['SpellLevels']['SpellLevel'],40)
self.assertEqual(by['SpellMisc']['DurationIndex'],21)
effects=[x['record']for x in r['records']if x['table_name']=='SpellEffect']
self.assertEqual([e['EffectAura']for e in effects],[138,140,65]);self.assertEqual([e['EffectBasePointsF']for e in effects],[1,1,1]);self.assertEqual([e['EffectAmplitude']for e in effects],[1,1,1])
self.assertFalse(r['installable']);self.assertFalse(r['gameplay_verified']);self.assertFalse(r['spells'][0]['known_spells_modified'])
v[4]=r['child_id_registry'];self.assertEqual(m.new_component(*v[:5],**v[5]),r)
def test_categories_exact_pinned_70334_wire_layout(self):
import struct
v=self.fixture();r=m.new_component(*v[:5],**v[5]);row=next(r for r in r['records']if r['table_name']=='SpellCategories')
# DB2Structure.h: int16,int16,int8,int32,int8,int8,int32,int16,int16,uint32.
# The row ID is non-inline and must not be inserted in this23-byte payload.
expected=struct.pack('<hhbibbi hhI'.replace(' ',''),0,0,1,0,0,0,0,0,0,13679)
self.assertEqual(len(expected),23);self.assertEqual(bytes.fromhex(row['wire_hex']),expected)
def test_original_source_policy_still_rejects_extended_fields(self):
f,dbc,_=self.source()
with self.assertRaisesRegex(ValueError,'nonzero server'):checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'])
def test_captured_defense_multipliers_and_attributes_must_match(self):
for change in('class','multiple','disk','attributes','proof'):
f,dbc,_=self.source()
if change=='class':f['server_row']['dmgClass']=0
elif change=='multiple':f['server_row']['effectMultipleValue1']=2
elif change=='disk':f['disk_row'][spell_layout()['EffectAmplitude']]=0
elif change=='attributes':f['server_row']['attributesEx']=0
else:f['semantics']['mappings'][0]['target_value']=0
with self.assertRaises(ValueError,msg=change):m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],semantics=f['semantics'])
def test_no_silent_target_power_aura_lifetime_or_flag_changes(self):
for change in('target','aura','duplicate','power','duration','school','flags','class','multiplier','cooldown','bool','level'):
v=self.fixture();s=v[0][0]
if change=='target':s['effects'][0][8]=6
elif change=='aura':s['effects'][0][1]=52
elif change=='duplicate':s['effects'][0][1]=65
elif change=='power':s['power'][1]=1
elif change=='duration':s['durationIndex']=7
elif change=='school':s['school']=0
elif change=='flags':s['attributes'][1]=0
elif change=='class':s['defense_type']=0
elif change=='multiplier':s['effect_value_multipliers'][1]=2
elif change=='cooldown':s['timing']['recoveryTime']=100
elif change=='bool':s['effects'][0][2]=False
else:s['levels']['spellLevel']=True
with self.assertRaises(ValueError,msg=change):m.new_component(*v[:5],**v[5])
def test_positive_native_reference_bad_schema_and_registry_reject(self):
for change in('positive','schema','registry','icon'):
v=self.fixture()
if change=='positive':v[1]['SpellName'].append(dict(ID=13679,Name_lang='Other spell'))
elif change=='schema':v[2]['SpellCategories'][0]=('Changed',)+v[2]['SpellCategories'][0][1:]
elif change=='registry':v[4]['SpellCategories']={'13679':1500000}
else:v[5]['new_icon_ids']={'13679':1}
with self.assertRaises(ValueError,msg=change):m.new_component(*v[:5],**v[5])
def test_source_id_is_not_an_allowlist_and_names_not_an_effect_rule(self):
v=self.fixture();v[0][0]['entry']=600145;v[0][0]['name']='Synthetic item haste';v[5]['new_icon_ids']={'600145':136047}
r=m.new_component(*v[:5],**v[5]);self.assertTrue(all(row['source_spell_id']==600145 for row in r['records']))
if __name__=='__main__':unittest.main()