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

97 lines
6.8 KiB
Python

#!/usr/bin/env python3
"""Named direct-combat proc metadata, without client calls or proc execution."""
import sys,unittest,json
from pathlib import Path
from copy import deepcopy
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from spell_definition_common import PROC_HEADERS,PROC_NAMES,PROC_POLICY,review_proc_conditions,checked_constant_source,proc_namespace
class ProcConditionsTest(unittest.TestCase):
def fixture(self,mask=16):
proof=dict(policy=PROC_POLICY,header_sha256={k:v[1]for k,v in PROC_HEADERS.items()},mappings=[dict(source_name=a,target_name=b,source_bit=1<<(i+2),target_bit=1<<(i+2))for i,(a,b)in enumerate(list(PROC_NAMES.items())[:-1])]+[dict(source_name='PROC_FLAG_TAKEN_ANY_DAMAGE',target_name='PROC_FLAG_TAKE_ANY_DAMAGE',source_bit=1<<20,target_bit=1<<20)])
raw=dict(entry=51899,procFlags=mask,procChance=10,procCharges=0);disk=[0]*173;disk[0]=51899;disk[26:29]=[mask,10,0]
return raw,disk,dict(ProcFlags=26,ProcChance=27,ProcCharges=28),proof
def test_direct_ability_and_compound_events(self):
for mask in(4,16,680,1<<20):
r=review_proc_conditions(*self.fixture(mask));self.assertEqual(r['target_proc_type_mask'],[mask,0]);self.assertTrue(r['server_authoritative']);self.assertFalse(r['complete_definition_converted'])
def test_tampered_semantic_bit_is_rejected(self):
args=list(self.fixture());args[3]['mappings'][2]['target_bit']=1<<30
with self.assertRaisesRegex(ValueError,'event'):review_proc_conditions(*args)
def test_periodic_trap_hand_kill_and_unknown_bits_fail_closed(self):
for mask in(0,1,2,1<<18,1<<19,1<<21,1<<22,1<<23,1<<31):
with self.assertRaisesRegex(ValueError,'semantics'):review_proc_conditions(*self.fixture(mask))
def test_capture_mismatch_and_bad_chance_rejected(self):
for key in('procFlags','procChance','procCharges'):
args=list(self.fixture());args[0][key]+=1
with self.assertRaises(ValueError):review_proc_conditions(*args)
args=list(self.fixture());args[0]['procChance']=101;args[1][27]=101
with self.assertRaises(ValueError):review_proc_conditions(*args)
def test_changed_namespace_and_duplicate_events_rejected(self):
args=list(self.fixture());args[3]['header_sha256']['source']='0'*64
with self.assertRaises(ValueError):review_proc_conditions(*args)
args=list(self.fixture());args[3]['mappings'][1]=deepcopy(args[3]['mappings'][0])
with self.assertRaises(ValueError):review_proc_conditions(*args)
class IncomingHarmfulProcTest(unittest.TestCase):
def proof(self,**options):
root=Path(__file__).resolve().parents[1]
return proc_namespace(Path.home()/'Servers/tortoise-wow/src/game/Spells/SpellDefines.h',
root.parent/'servers/trinity-forever/src/server/game/Spells/SpellMgr.h',**options)
def fixture(self,mask=139944,**options):
raw,disk,offsets,_=ProcConditionsTest().fixture(mask)
return raw,disk,offsets,self.proof(incoming_harmful=True,**options)
def test_earthen_shield_event_mask_maps_exactly_without_claiming_block_filter(self):
args=self.fixture();result=review_proc_conditions(*args,incoming_harmful=True)
self.assertEqual(result['target_proc_type_mask'],[139944,0])
self.assertEqual({r['source_bit']for r in result['events']},{8,32,128,512,8192,131072})
self.assertTrue(result['server_authoritative']);self.assertFalse(result['complete_definition_converted'])
self.assertNotIn('procEx',result)
with self.assertRaises(ValueError):review_proc_conditions(*args)
def test_periodic_and_incoming_are_independent_explicit_reviews(self):
mask=139944|(1<<18)
with self.assertRaises(ValueError):review_proc_conditions(*self.fixture(mask),incoming_harmful=True)
args=self.fixture(mask,damage_periodic=True)
self.assertEqual(review_proc_conditions(*args,incoming_harmful=True,damage_periodic=True)['target_proc_type_mask'],[mask,0])
with self.assertRaises(ValueError):review_proc_conditions(*args,damage_periodic=True)
def test_unknown_outcome_or_event_does_not_become_valid_from_incoming_policy(self):
for bit in (0,1,14,15,19,21,22,23,31):
with self.assertRaises(ValueError):review_proc_conditions(*self.fixture(139944|(1<<bit)),incoming_harmful=True)
args=list(self.fixture());args[-1]['mappings'][-1]['target_bit']=1<<15
with self.assertRaises(ValueError):review_proc_conditions(*args,incoming_harmful=True)
with self.assertRaises(ValueError):self.proof(incoming_harmful=1)
class CapturedProcSourceTest(unittest.TestCase):
def fixture(self):
from turtle_data import spell_layout
data=json.loads((Path(__file__).parent/'fixtures/item-proc-source.json').read_text())
class Captured:
by_id={data['server_row']['entry']:data['disk_row']}
def string(self,index):return data['strings'][str(index)]
return data,Captured(),spell_layout()
def convert(self,data,dbc,offsets):
return checked_constant_source(dbc,data['server_row'],offsets,family_namespace=data['family_namespace'],proc_namespace_proof=data['proc_namespace'])
def test_actual_passive_trigger_identity_and_conditions(self):
data,dbc,offsets=self.fixture();src=self.convert(data,dbc,offsets)
self.assertEqual(src['entry'],51899);self.assertEqual(src['effects'][0][10],51898)
self.assertEqual(src['proc_context']['proc_chance'],10)
self.assertEqual(src['proc_context']['target_proc_type_mask'],[16,0])
self.assertEqual(src['passive_default_stance_order'],0)
def test_previous_policies_stay_fail_closed_without_opt_in(self):
data,dbc,offsets=self.fixture()
with self.assertRaises(ValueError):checked_constant_source(dbc,data['server_row'],offsets,family_namespace=data['family_namespace'])
def test_trigger_capture_and_source_identity_mismatch(self):
for field in('entry','effectTriggerSpell1','procChance','procCharges'):
data,dbc,offsets=self.fixture();data['server_row'][field]+=1
with self.assertRaises(ValueError):self.convert(data,dbc,offsets)
def test_zero_stance_order_is_not_allowed_for_nonpassive_or_stance_spells(self):
for field,value,index in(('attributes',64,'Attributes'),('stances',1,'ShapeshiftMask')):
data,dbc,offsets=self.fixture();data['server_row'][field]=value;data['disk_row'][offsets[index]]=value
with self.assertRaises(ValueError):self.convert(data,dbc,offsets)
def test_unreviewed_disk_dependency_still_rejected(self):
data,dbc,offsets=self.fixture();data['disk_row'][offsets['EffectRadiusIndex']]=123
data['server_row']['effectRadiusIndex1']=123
with self.assertRaises(ValueError):self.convert(data,dbc,offsets)
if __name__=='__main__':unittest.main()