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

88 lines
9.0 KiB
Python

"""Actual nine-source family; synthetic texture bytes, no client or SQL."""
from pathlib import Path
from types import SimpleNamespace
import copy,hashlib,json,sys,unittest
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'tests')]
import spell_item_static_compat as m,spell_passive_compat as codec
import spell_item_skill_compat_test as old_fixtures
from turtle_data import spell_layout
from spell_definition_common import checked_constant_source
class CategorizedSkillTest(unittest.TestCase):
def sources(self):
f=json.loads((ROOT/'tests/fixtures/categorized-item-skill-source.json').read_text());dbc=SimpleNamespace(by_id={int(k):v for k,v in f['disk_rows'].items()},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
sources=[m.source_spell(dbc,r,spell_layout(),skill_bonus=True,family_namespace=f['family_namespace'],skill_category_reference=f['category_reference'])for r in f['server_rows']]
return f,dbc,sources
def fixture(self):
f,_,sources=self.sources();v=old_fixtures.ItemSkillDefinitionTest().fixture();native=copy.deepcopy(v[3]);native['SpellCategory']=[copy.deepcopy(f['category_reference']['native_category'])];native['SkillLine']=copy.deepcopy(f['native_skills']);schemas=copy.deepcopy(v[4]);schemas['SpellCategories']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellCategories.dbd','SpellCategories');maxima={t:1500000 for t in schemas};tables=copy.deepcopy(v[7]['source_tables'])
def table(rows,strings):return SimpleNamespace(by_id={int(k):v for k,v in rows.items()},string={int(k):v for k,v in strings.items()}.__getitem__)
tables['SpellCategory']=SimpleNamespace(by_id={38:[38,0]});tables['SkillLine']=table(f['skill_rows'],f['skill_strings']);tables['SpellIcon']=table(f['icon_rows'],f['icon_strings']);raw=b'BLP2'+bytes(20);assets=[];names={};icons={}
for n,src in enumerate(sources):
path=tables['SpellIcon'].string(tables['SpellIcon'].by_id[src['spellIconId']][1]).replace('\\','/').lower()+'.blp';fid=9000+n;names[fid]=[path];icons[str(src['entry'])]=fid
if not any(a['path']==path for a in assets):assets.append(dict(path=path,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex()))
opts=dict(source_tables=tables,target_icon_names=names,new_icon_ids=icons,icon_assets=assets,read_icon=lambda _:raw)
return sources,native,schemas,maxima,dict(schema_version=1,build=codec.BUILD,SpellEffect={}),opts
def component(self,v):return m.new_skill_component(*v[:5],**v[5])
def test_actual_nine_source_categories_and_default_checker_closed(self):
f,dbc,s=self.sources();self.assertEqual({x['entry']for x in s},{7823,7825,7826,8082,8083,15956,24301,45853,46041})
for raw in f['server_rows']:
with self.assertRaisesRegex(ValueError,'category'):checked_constant_source(dbc,raw,spell_layout(),family_namespace=f['family_namespace'])
self.assertTrue(all(x['category_id']==38 for x in s));self.assertEqual(next(x for x in s if x['entry']==45853)['effects'][0][2]+1,30)
def test_full_family_serializes_secondary_and_weapon_skills_without_learned_links(self):
v=self.fixture();before=copy.deepcopy(v[:5]);result=self.component(v);self.assertEqual(v[:5],before);self.assertEqual(result['definition_policy'],m.NEW_CATEGORIZED_SKILL_POLICY);self.assertEqual(len(result['records']),54)
for source in v[0]:
rows={r['table_name']:r for r in result['records']if r['source_spell_id']==source['entry']};self.assertEqual(set(rows),{'Spell','SpellName','SpellMisc','SpellEffect','SpellEquippedItems','SpellCategories'});self.assertEqual(rows['SpellCategories']['record']['Category'],38);self.assertEqual(rows['SpellEffect']['record']['EffectMiscValue'],[source['effects'][0][7],0]);self.assertEqual(rows['SpellEffect']['record']['EffectBasePointsF'],source['effects'][0][2]+1)
for r in rows.values():self.assertEqual(bytes.fromhex(r['wire_hex']),codec.encode(r['record'],v[2][r['table_name']]))
meta=next(s for s in result['spells']if s['spell_id']==source['entry']);self.assertEqual(meta['source_definition'],source);self.assertEqual(meta['skill_category_reference'],source['skill_category_reference'])
self.assertFalse(result['engine_accepted']);self.assertFalse(result['installable']);self.assertFalse(any(r['table_name']=='SkillLineAbility'for r in result['records']))
def test_reference_and_source_category_cannot_be_changed_or_omitted(self):
for mutation in('raw-id','disk-id','raw-flag','native-id','native-name','charges','cooldown','typemask','namespace','bool','no-reference'):
f,dbc,_=self.sources();raw=next(r for r in f['server_rows']if r['entry']==45853);proof=f['category_reference']
if mutation=='raw-id':raw['category']=39
elif mutation=='disk-id':dbc.by_id[45853][spell_layout()['Category']]=39
elif mutation=='raw-flag':proof['source_category'][1]=1
elif mutation=='native-id':proof['native_category']['ID']=39
elif mutation=='native-name':proof['native_category']['Name_lang']='Other'
elif mutation=='charges':proof['native_category']['MaxCharges']=1
elif mutation=='cooldown':proof['native_category']['ChargeRecoveryTime']=1000
elif mutation=='typemask':proof['native_category']['TypeMask']=1
elif mutation=='namespace':proof['skill_category_namespace']['mappings'][1]['target_value']=11
elif mutation=='bool':proof['source_category'][1]=False
else:proof=None
with self.assertRaises(ValueError,msg=mutation):m.source_spell(dbc,raw,spell_layout(),skill_bonus=True,family_namespace=f['family_namespace'],skill_category_reference=proof)
def test_actual_references_skills_and_positive_native_context_fail_closed(self):
for mutation in('source-category','native-category','skill-category','skill-name','missing-category','positive','mixed-context'):
v=self.fixture()
if mutation=='source-category':v[5]['source_tables']['SpellCategory'].by_id[38][1]=1
elif mutation=='native-category':v[1]['SpellCategory'][0]['Flags']=1
elif mutation=='skill-category':v[1]['SkillLine'][1]['CategoryID']=11
elif mutation=='skill-name':v[1]['SkillLine'][1]['DisplayName_lang']='Other'
elif mutation=='missing-category':del v[5]['source_tables']['SpellCategory']
elif mutation=='positive':v[1]['SpellName'].append(dict(ID=45853,Name_lang='Positive native'))
else:v[0][0]['defense_type']=False
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def test_category_proof_is_not_admitted_to_another_mechanic_or_neutral_skill(self):
f,dbc,_=self.sources();raw=f['server_rows'][0]
with self.assertRaises(ValueError):m.source_spell(dbc,raw,spell_layout(),family_namespace=f['family_namespace'],skill_category_reference=f['category_reference'])
v=self.fixture();del v[0][0]['skill_category_reference']
with self.assertRaises(ValueError):self.component(v)
def test_existing_positive_family_retains_exact_category_and_requires_it(self):
f,_,sources=self.sources();native=copy.deepcopy(f['native_positive']);native['SkillLine']=f['native_skills'];src=next(s for s in sources if s['entry']==7823);schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('Spell','SpellName','SpellMisc','SpellEffect','SpellLevels')};duration=dict(source_duration_id=21,target_duration_id=21,duration_ms=-1,max_duration_ms=-1,source_duration_per_level=0,target_duration_per_resource=0,permanent=True)
opts=dict(skill_bonus=True,skill_rows=native['SkillLine'],duration_reference=duration);args=(sources[:1],native,schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}))
for source in sources:
if source['entry']in(45853,46041):continue
r=m.component([source],*args[1:],**opts);self.assertEqual(r['records'],[])
native['SpellCategories']=[r for r in native['SpellCategories']if r['SpellID']!=7823]
with self.assertRaises(ValueError):m.component([src],*args[1:],**opts)
def test_all_six_reencoded_row_mutations_are_rejected(self):
v=self.fixture();c=self.component(v);src=next(s for s in v[0]if s['entry']==45853);meta=next(s for s in c['spells']if s['spell_id']==45853)
edits={'SpellName':('Name_lang','wrong'),'Spell':('Description_lang','wrong'),'SpellMisc':('DurationIndex',0),'SpellEquippedItems':('EquippedItemClass',2),'SpellEffect':('EffectAura',225),'SpellCategories':('Category',0)}
for row in c['records']:
if row['source_spell_id']!=45853:continue
self.assertTrue(m.review_categorized_skill_record(src,meta,row));mutant=copy.deepcopy(row);k,value=edits[row['table_name']];mutant['record'][k]=value;wire=codec.encode(mutant['record'],v[2][row['table_name']]);mutant.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
with self.assertRaises(ValueError,msg=row['table_name']):m.review_categorized_skill_record(src,meta,mutant)
def test_stable_allocation_and_prior_policy_unchanged(self):
v=self.fixture();a=self.component(v);v[4].update(a['child_id_registry']);v[0].reverse();self.assertEqual(self.component(v),a)
old=old_fixtures.ItemSkillDefinitionTest().fixture();r=m.new_skill_component(*old[2:7],**old[7]);self.assertEqual(r['definition_policy'],m.NEW_SKILL_POLICY);self.assertEqual(len(r['records']),5)
if __name__=='__main__':unittest.main()