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

148 lines
13 KiB
Python

#!/usr/bin/env python3
"""Complete source-backed proc candidate and restorative dependency checks."""
import sys,json,unittest,copy
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_proc_compat as m
import spell_restore_compat_test as restore_tests
import spell_restore_compat as restore
import spell_passive_compat as codec
from turtle_data import spell_layout
class ItemProcCompatibilityTest(unittest.TestCase):
def fixture(self):
r=restore_tests.RestorationCompatibilityTest().new_fixture();trigger=restore.new_component(*r[:5],**r[5]);f=json.loads((ROOT/'tests/fixtures/item-proc-source.json').read_text());dbc=SimpleNamespace(by_id={51899:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
source=m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],proc_proof=f['proc_namespace']);schemas=r[2];schemas['SpellAuraOptions']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellAuraOptions.dbd','SpellAuraOptions');maxima=r[3];maxima['SpellAuraOptions']=1500000
# Reserve trigger child IDs before allocating any proc child.
for row in trigger['records']:
if row['table_name']in maxima:maxima[row['table_name']]=max(maxima[row['table_name']],row['id'])
options=dict(r[5]);options.update(proc_overrides=dict(kind='local-source-proc-override-snapshot',table='tw_world.spell_proc_event',source_spell_ids=[51898,51899],two_reads_equal=True,database_modified=False,rows=[]),new_icon_ids={'51899':136235},proc_proof=f['proc_namespace'],trigger_sources={51898:r[0][0]},trigger_records=trigger['records'])
return [source],r[1],schemas,maxima,dict(schema_version=1,build=codec.BUILD,SpellEffect={}),options
def convert(self,v):return m.new_component(*v[:5],**v[5])
def presentation(self):
return m.presentation_namespace(Path('/home/praxis/Servers/tortoise-wow/src/game/Spells/SpellDefines.h'),
ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
def test_named_passive_presentation_flags_preserve_all_reviewed_combinations(self):
for flags in (192,208,448,464):
v=self.fixture();v[0][0]['attributes'][0]=flags;v[0][0]['passive_proc_presentation']=self.presentation()
result=self.convert(v);self.assertEqual(result['definition_policy'],m.PRESENTED_POLICY)
misc=next(r['record']for r in result['records']if r['table_name']=='SpellMisc')
self.assertEqual(misc['Attributes'],[flags]+[0]*16)
self.assertEqual(result['spells'][0]['source_definition'],v[0][0]);self.assertFalse(result['installed'])
def test_actual_set_passive_keeps_source_ability_hidden_log_flags_and_default_stance(self):
f=json.loads((ROOT/'tests/fixtures/named-passive-proc-source.json').read_text())
dbc=SimpleNamespace(by_id={49368:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
src=m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],proc_proof=f['proc_namespace'],presentation_context=self.presentation())
slots,context=m.validate_source(src,f['proc_namespace'])
self.assertEqual(src['attributes'],[464,0,0,0,0]);self.assertEqual(src['passive_default_stance_order'],0)
self.assertEqual(slots,[0]);self.assertEqual(src['effects'][0][10],49367)
self.assertEqual((context['source_flags'],context['proc_chance']),(4,100))
with self.assertRaises(ValueError):m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],proc_proof=f['proc_namespace'])
f['server_row']['attributes']=192
with self.assertRaises(ValueError):m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],proc_proof=f['proc_namespace'],presentation_context=self.presentation())
def test_passive_presentation_rejects_extra_flags_missing_or_forged_proof(self):
for mode in ('missing','other-flag','nonpassive','extended','forged','boolean','other-mechanic'):
v=self.fixture();src=v[0][0];src['attributes'][0]=464;src['passive_proc_presentation']=self.presentation()
if mode=='missing':del src['passive_proc_presentation']
elif mode=='other-flag':src['attributes'][0]|=512
elif mode=='nonpassive':src['attributes'][0]=400
elif mode=='extended':src['attributes'][1]=1
elif mode=='forged':src['passive_proc_presentation']['flags'][0]['target']='UNVERIFIED'
elif mode=='boolean':src['passive_proc_presentation']['flags'][0]['value']=True
else:src['effects'][0][1]=13
with self.assertRaises(ValueError):self.convert(v)
def test_source_passive_chance_event_trigger_and_no_learned_state(self):
v=self.fixture();before=copy.deepcopy(v[:5]);result=self.convert(v);self.assertEqual(v[:5],before);self.assertEqual(len(result['records']),6)
rows={r['table_name']:r['record']for r in result['records']};self.assertEqual(set(rows),{'Spell','SpellName','SpellMisc','SpellEffect','SpellEquippedItems','SpellAuraOptions'})
self.assertEqual(rows['SpellEffect']['EffectTriggerSpell'],51898);self.assertEqual(rows['SpellEffect']['EffectAura'],42)
self.assertEqual((rows['SpellAuraOptions']['ProcChance'],rows['SpellAuraOptions']['ProcCharges'],rows['SpellAuraOptions']['ProcTypeMask']),(10,0,[16,0]))
self.assertEqual(rows['SpellEffect']['ID'],1500002);self.assertFalse(result['installable']);self.assertFalse(result['gameplay_verified']);self.assertFalse(result['spells'][0]['known_spells_modified'])
for row in result['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
def test_registry_reuse_deterministic_and_pending_trigger_ids_reserved(self):
v=self.fixture();result=self.convert(v);v[4].update(result['child_id_registry']);self.assertEqual(self.convert(v),result)
v[4]['SpellAuraOptions']['51899']=1500000
with self.assertRaises(ValueError):self.convert(v)
def test_missing_or_incorrect_trigger_definition_fails(self):
for change in('source','parent','effect','wire','amount'):
v=self.fixture();o=v[5]
if change=='source':o['trigger_sources']={}
elif change=='parent':o['trigger_records']=[r for r in o['trigger_records']if r['table_name']!='SpellName']
elif change=='effect':o['trigger_records']=[r for r in o['trigger_records']if r['table_name']!='SpellEffect']
elif change=='wire':o['trigger_records'][0]['wire_hex']='00'
else:o['trigger_sources'][51898]['effects'][0][2]=0
with self.assertRaises(ValueError):self.convert(v)
def test_nonproc_flags_cost_visual_restrictions_and_proof_fail_closed(self):
for change in('cost','visual','timing','family','target','chance','flags','coefficient','unused','level','conditions'):
v=self.fixture();s=v[0][0]
if change=='cost':s['power'][1]=1
elif change=='visual':s['visuals'][0]=1
elif change=='timing':s['timing']['recoveryTime']=1
elif change=='family':s['class_family']=None
elif change=='target':s['effects'][0][8]=6
elif change=='chance':s['proc_context']['proc_chance']=11
elif change=='flags':s['conditions']['procFlags']=1<<18
elif change=='coefficient':s['effects'][0][11]=1
elif change=='unused':s['effects'][1][10]=51898
elif change=='level':s['levels']['spellLevel']=60
else:del s['conditions']['customFlags']
with self.assertRaises(ValueError):self.convert(v)
def test_any_positive_native_context_prevents_new_parent_creation(self):
for table in m.REQUIRED_REFERENCE_TABLES:
v=self.fixture();v[1][table].append(dict(ID=51899,SpellID=51899))
with self.assertRaises(ValueError):self.convert(v)
def test_not_a_source_spell_allowlist(self):
v=self.fixture();v[0][0]['entry']=600130;v[5]['proc_overrides']['source_spell_ids'].append(600130);v[5]['new_icon_ids']={'600130':136235}
result=self.convert(v);self.assertTrue(all(r['source_spell_id']==600130 for r in result['records']));self.assertEqual(result['child_id_registry']['SpellAuraOptions'],{'600130':1500001})
def test_multiple_sources_are_sorted_without_duplicate_allocations(self):
v=self.fixture();other=copy.deepcopy(v[0][0]);other['entry']=600131;v[5]['proc_overrides']['source_spell_ids'].append(600131);v[0].insert(0,other);v[5]['new_icon_ids']['600131']=136235
first=self.convert(v);v[0].reverse();self.assertEqual(self.convert(v),first);self.assertEqual(len(first['records']),12)
self.assertEqual(len({(r['table_hash'],r['id'])for r in first['records']}),12)
def test_reencoded_trigger_semantic_changes_still_reject(self):
import hashlib
for table,field,value in(('SpellMisc','DurationIndex',21),('SpellLevels','BaseLevel',1),('SpellClassOptions','SpellClassSet',0),('SpellEffect','ImplicitTarget',[6,0])):
v=self.fixture();r=next(r for r in v[5]['trigger_records']if r['table_name']==table);r['record'][field]=value;wire=codec.encode(r['record'],v[2][table]);r.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
with self.assertRaises(ValueError):self.convert(v)
def test_changed_target_schema_is_rejected_before_encoding(self):
v=self.fixture();v[2]['SpellAuraOptions']=copy.deepcopy(v[2]['SpellAuraOptions']);v[2]['SpellAuraOptions'][0]=('Changed',)+v[2]['SpellAuraOptions'][0][1:]
with self.assertRaisesRegex(ValueError,'schema'):self.convert(v)
def test_missing_override_coverage_or_actual_override_rejects(self):
for mode in('missing','row','unverified'):
v=self.fixture();proof=v[5]['proc_overrides']
if mode=='missing':proof['source_spell_ids']=[51898]
elif mode=='row':proof['rows']=[['51899','0']]
else:proof['two_reads_equal']=False
with self.assertRaisesRegex(ValueError,'overrides'):self.convert(v)
def test_boolean_or_nonfinite_normalized_effect_is_rejected(self):
for index,value in((2,True),(3,True),(5,False),(6,float('nan')),(11,float('inf'))):
v=self.fixture();v[0][0]['effects'][0][index]=value
with self.assertRaises(ValueError):self.convert(v)
def warrior_fixture(self):
import spell_timed_buff_compat_test as timed_tests
import spell_timed_buff_compat as timed
tv=timed_tests.TimedBuffCompatibilityTest().actual_fixture();trigger=timed.new_component(*tv[:5],**tv[5]);v=self.fixture()
f=json.loads((ROOT/'tests/fixtures/item-proc-warrior-source.json').read_text());dbc=SimpleNamespace(by_id={53203:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
src=m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],proc_proof=f['proc_namespace']);v=list(v);v[0]=[src]
v[1]['SpellDuration']=tv[1]['SpellDuration'];v[2]['SpellXSpellVisual']=tv[2]['SpellXSpellVisual']
for row in trigger['records']:
if row['table_name']in v[3]:v[3][row['table_name']]=max(v[3][row['table_name']],row['id'])
v[5].update(new_icon_ids={'53203':136235},trigger_sources={53202:tv[0][0]},trigger_records=trigger['records'],trigger_visual_links={53202:tv[5]['visual_links'][53202]})
v[5]['source_tables']['SpellDuration'].by_id[7]=[7,5000,0,5000]
v[5]['proc_overrides']['source_spell_ids']=[53202,53203]
return v
def test_actual_warrior_proc_preserves_family_and_complete_timed_visual_trigger(self):
v=self.warrior_fixture();result=self.convert(v);rows={r['table_name']:r['record']for r in result['records']};self.assertEqual(len(rows),7)
self.assertEqual(rows['SpellClassOptions']['SpellClassSet'],4);self.assertEqual(rows['SpellClassOptions']['SpellClassMask'],[0]*4)
self.assertEqual(rows['SpellEffect']['EffectTriggerSpell'],53202);self.assertEqual(rows['SpellAuraOptions']['ProcChance'],100)
dependency=result['spells'][0]['trigger_dependencies'][0];self.assertEqual(dependency['definition_family'],'finite-self-melee-haste');self.assertEqual(len(dependency['record_sha256']),8)
self.assertFalse(result['gameplay_verified']);self.assertFalse(result['installed'])
def test_timed_proc_missing_visual_link_duration_or_family_rejected(self):
for mode in('visual','duration','family','linkrow'):
v=self.warrior_fixture()
if mode=='visual':v[5]['trigger_visual_links']={}
elif mode=='duration':v[1]['SpellDuration']=[]
elif mode=='family':v[0][0]['class_family']['target_id']=0
else:v[5]['trigger_records']=[r for r in v[5]['trigger_records']if r['table_name']!='SpellXSpellVisual']
with self.assertRaises(ValueError):self.convert(v)
if __name__=='__main__':unittest.main()