Files
WoW-Hybrid-gateway/tests/spell_item_caster_percent_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
7.7 KiB
Python

"""Captured caster source rows; synthetic icon I/O and production generic guards."""
import copy,hashlib,importlib.util,json,sys,unittest
from pathlib import Path
from types import SimpleNamespace
W=Path(__file__).resolve().parent;R=W.parent;sys.path[:0]=[str(W),str(R/'ops')]
import spell_item_caster_percent_compat as m
import spell_item_static_compat as static
import spell_passive_compat as codec
import spell_item_skill_compat_test as common
from octo_client_data import canonical_sha256
import content_package_stage as stage
class CasterPercent(unittest.TestCase):
def fixture(self,stat='spell-hit'):
v=list(common.ItemSkillDefinitionTest().fixture());d=json.loads((W/'fixtures/item-caster-percent-source.json').read_text());v[2]=[x for x in d['sources']if d['percent_stat_by_id'][str(x['entry'])]==stat];v[4]['SpellLevels']=codec.fields(R.parent/'tools/WoWDBDefs/definitions/SpellLevels.dbd','SpellLevels');v[5]['SpellLevels']=1500000;v[7].pop('skill_rows',None);v[7]['source_tables'].pop('SkillLine');v[7]['source_tables']['SpellIcon']=SimpleNamespace(by_id={1:[1,1]},string=lambda _:'interface/icons/temp.blp');v[7].update(percent_stat=stat,semantics=m.contract(),new_icon_ids={str(s['entry']):136235 for s in v[2]});return v
def convert(self,v):return m.component(*v[2:7],**v[7])
def staged(self):
v=self.fixture();c=self.convert(v);metadata=codec.TABLES|codec.SUPPLEMENTAL_TABLES;c['native_tables']={t:dict(table_hash=hex(metadata[t][0]),layout_hash=hex(metadata[t][1]),serialized_field_sha256=metadata[t][2],native_max_id=1500000,allocation_bound=1500000)for t in {r['table_name']for r in c['records']}};schemas={t:s for t,s in v[4].items()if t in c['native_tables']};record=dict(ID=1,Name_lang='Unrelated preserved');wire=codec.encode(record,schemas['SpellName']);rows=[dict(table_name='SpellName',table_hash=hex(codec.TABLES['SpellName'][0]),id=1,record=record,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())];base=dict(build=codec.BUILD,schema=codec.SCHEMA,id_remapping=False,rows=rows,push_id=stage.package_payloads(rows)[0]);api={str(s['entry']):dict(infoStatus='nil',nameStatus='nil',descriptionStatus='nil')for s in v[2]};return v,c,schemas,base,api
def test_captured_hit_and_crit_keep_named_percentage_points(self):
for stat,aura,amounts in [('spell-hit',55,[1,2,3]),('spell-crit',57,[50])]:
v=self.fixture(stat);old=copy.deepcopy(v[2:7]);c=self.convert(v);self.assertEqual(v[2:7],old);effects=[r['record']for r in c['records']if r['table_name']=='SpellEffect'];self.assertEqual([e['EffectBasePointsF']for e in effects],amounts);self.assertTrue(all(e['EffectAura']==aura and e['EffectMiscValue']==[0,0]for e in effects));self.assertFalse(c['installable']);self.assertFalse(any(r['table_name']=='SkillLineAbility'for r in c['records']))
def test_source_literals_zero_levels_and_every_wire_row_are_preserved(self):
v=self.fixture();c=self.convert(v)
for r in c['records']:
s=next(s for s in v[2]if s['entry']==r['source_spell_id']);self.assertEqual(bytes.fromhex(r['wire_hex']),codec.encode(r['record'],v[4][r['table_name']]));self.assertTrue(m.review_record(s,next(x for x in c['spells']if x['spell_id']==s['entry']),r,'spell-hit',m.contract()))
if r['table_name']=='Spell':self.assertNotIn('$',r['record']['Description_lang']);self.assertIn(str(s['effects'][0][2]+1)+'%',r['record']['Description_lang'])
self.assertFalse(any(r['table_name']=='SpellLevels'for r in c['records']))
def test_existing_swim_school_new_static_entrypoint_stays_separate(self):
v=self.fixture();kwargs=dict(v[7]);kwargs.pop('semantics')
with self.assertRaises(ValueError):static.new_static_component(*v[2:7],**kwargs)
def test_generic_composition_is_additive_and_idempotent(self):
v,c,schemas,b,api=self.staged();old=copy.deepcopy(b);r=stage.compose_definition_candidates(b,[c],schemas,api);self.assertEqual(b,old);self.assertEqual(r['added_count'],15);self.assertFalse(r['engine_accepted']);b.update(rows=r['rows'],push_id=r['push_id']);again=stage.compose_definition_candidates(b,[c],schemas,api);self.assertEqual(again['rows'],r['rows']);self.assertEqual(again['added_count'],0)
def test_original_api_absence_and_source_identity_not_bypassed(self):
for key in('positive','missing','hash','source','policy','legacy-kind','learned','installed'):
v,c,s,b,api=self.staged()
if key=='positive':api['51886']['infoStatus']='ok'
elif key=='missing':del api['51886']['descriptionStatus']
elif key=='hash':c['spells'][0]['source_record_sha256']='0'*64
elif key=='source':c['spells'][0]['class_family']['target_id']=4
elif key=='policy':c['definition_policy']='unknown'
elif key=='legacy-kind':c['kind']='source-item-static-definition-candidates'
elif key=='learned':c['spells'][0]['known_spells_modified']=True
else:c['installed']=True
with self.assertRaises(ValueError,msg=key):stage.compose_definition_candidates(b,[c],s,api)
def test_reencoded_rating_amount_school_flags_and_text_are_rejected(self):
for table,key,value in [('SpellEffect','EffectAura',189),('SpellEffect','EffectBasePointsF',99),('SpellEffect','Coefficient',1),('SpellEffect','EffectMiscValue',[127,0]),('SpellEffect','EffectSpellClassMask',[1,0,0,0]),('SpellMisc','SchoolMask',4),('SpellMisc','DurationIndex',1),('SpellMisc','Attributes',[192,1024]+[0]*15),('Spell','Description_lang','Gives99rating.'),('SpellEquippedItems','EquippedItemClass',4),('SpellName','Name_lang','Unrelated')]:
v,c,s,b,api=self.staged();row=next(r for r in c['records']if r['table_name']==table);row['record'][key]=value;wire=codec.encode(row['record'],s[table]);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
with self.assertRaises(ValueError,msg=table+'.'+key):stage.compose_definition_candidates(b,[c],s,api)
def test_levels_procs_targets_masks_categories_and_unknown_flags_remain_held(self):
for key in('level','proc','chance','aura','target','mask','flag','visual','cost','category'):
v=self.fixture();src=v[2][0]
if key=='level':src['levels']['baseLevel']=1
elif key=='proc':src['conditions']['procFlags']=1
elif key=='chance':src['conditions']['procChance']=50
elif key=='aura':src['effects'][0][1]=71
elif key=='target':src['effects'][0][4]=6
elif key=='mask':src['class_family']['source_mask'][0]=1
elif key=='flag':src['attributes'][0]|=512
elif key=='visual':src['visuals'][0]=1
elif key=='cost':src['power'][1]=1
else:src['category_id']=1
with self.assertRaises(ValueError,msg=key):self.convert(v)
def test_positive_references_timing_and_icon_payload_are_mandatory(self):
for key in('positive','timing','icon','learned','namespace'):
v=self.fixture()
if key=='positive':v[3]['SpellName'].append(dict(ID=51886,Name_lang='Existing'))
elif key=='timing':v[3]['SpellDuration'][0]['Duration']=5000
elif key=='icon':v[7]['read_icon']=lambda _:b'BLP2wrong'
elif key=='learned':v[6]['SkillLineAbility']={'51886':1500001}
else:v[7]['semantics']['rating_conversion']=True
with self.assertRaises(ValueError,msg=key):self.convert(v)
def test_shared_policy_has_no_fixed_item_or_spell_allowlist(self):
v=self.fixture();v[2]=v[2][:1];v[2][0]['entry']=600150;v[7]['new_icon_ids']={'600150':136235};c=self.convert(v);self.assertEqual([s['spell_id']for s in c['spells']],[600150])
def test_semantic_attestation_rejects_boolean_integer_aliases(self):
for key,value in [('rating_conversion',0),('source_base_point_adjustment',True)]:
v=self.fixture();v[7]['semantics'][key]=value
with self.assertRaises(ValueError):self.convert(v)
def test_missing_slots_or_extra_unreviewed_child_stay_blocked(self):
v,c,s,b,api=self.staged();c['records'].remove(next(r for r in c['records']if r['table_name']=='SpellEffect'))
with self.assertRaises(ValueError):stage.compose_definition_candidates(b,[c],s,api)
if __name__=='__main__':unittest.main()