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

75 lines
5.1 KiB
Python

"""Real modifier source fixture; synthetic icon I/O and class inventories."""
import copy, hashlib, json, sys, unittest
from pathlib import Path
from types import SimpleNamespace
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
import spell_flat_modifier_compat as m
import spell_passive_compat as codec
import spell_item_skill_compat_test as common
from spell_definition_common import checked_constant_source
from spell_family_compat import namespace
from turtle_data import spell_layout
from content_package_stage import compose_definition_candidates
from item_sparse_compat import package_payloads
class FlatModifierTest(unittest.TestCase):
def fixture(self):
v=list(common.ItemStaticDefinitionTest().fixture('swim-speed'))
f=json.loads((ROOT/'tests/fixtures/item-flat-modifier-source.json').read_text())
dbc=SimpleNamespace(by_id={53204:f['disk']},string={int(k):s for k,s in f['strings'].items()}.__getitem__)
proof=namespace(Path.home()/'Servers/tortoise-wow/src/game/Database/DBCEnums.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h')
source=checked_constant_source(dbc,f['source'],spell_layout(),family_namespace=proof,flat_modifier_namespace=f['normalized']['flat_modifier_namespace'])
v[2]=[source];v[7].pop('percent_stat',None)
path='interface/icons/spell_nature_healingwavegreater.blp'
v[7]['source_tables']['SpellIcon']=SimpleNamespace(by_id={963:[963,1]},string=lambda _:path)
v[7]['target_icon_names']={136042:[path]};v[7]['new_icon_ids']={'53204':136042};v[7]['icon_assets'][0]['path']=path
v[7].update(modifier_namespace=source['flat_modifier_namespace'],affect_masks={'53204:0':1<<35},
affect_inventory=dict(source=[dict(id=1680,family=4,mask=1<<35),dict(id=20230,family=4,mask=1)],
target=[dict(SpellID=1680,SpellClassSet=4,SpellClassMask=[-2147483648,4,0,0]),
dict(SpellID=20230,SpellClassSet=4,SpellClassMask=[-2147483648,0,0,0])]))
return v
def component(self,v):return m.new_component(*v[2:7],**v[7])
def staged(self):
v=self.fixture();c=self.component(v);meta=codec.TABLES|codec.SUPPLEMENTAL_TABLES
c['native_tables']={t:dict(table_hash=hex(meta[t][0]),layout_hash=hex(meta[t][1]),serialized_field_sha256=meta[t][2],native_max_id=1500000,allocation_bound=v[5][t])for t in {r['table_name']for r in c['records']}}
record=dict(ID=1,Name_lang='Preserved unrelated fixture');raw=codec.encode(record,v[4]['SpellName'])
base=[dict(table_name='SpellName',table_hash=hex(meta['SpellName'][0]),id=1,record=record,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())]
package=dict(build=codec.BUILD,schema=codec.SCHEMA,id_remapping=False,rows=base,push_id=package_payloads(base)[0])
return package,[c],{t:v[4][t]for t in c['native_tables']},{'53204':dict(infoStatus='nil',nameStatus='nil',descriptionStatus='nil')}
def test_source_definition_uses_real_id_amount_and_precise_mask(self):
v=self.fixture();before=copy.deepcopy(v[2:7]);r=self.component(v)
self.assertEqual(v[2:7],before)
e=next(row['record']for row in r['records']if row['table_name']=='SpellEffect')
self.assertEqual((e['SpellID'],e['EffectAura'],e['EffectBasePointsF'],e['EffectMiscValue'],e['EffectSpellClassMask']),(53204,107,2,[17,0],[0,4,0,0]))
self.assertNotIn('SkillLineAbility',{row['table_name']for row in r['records']})
self.assertFalse(r['gameplay_verified']);self.assertFalse(r['installable'])
def test_composition_is_idempotent_and_preserves_source_identity(self):
args=self.staged();r=compose_definition_candidates(*args)
self.assertEqual(r['added_count'],6);self.assertEqual(r['source_spell_ids'],[53204])
args[0].update(rows=r['rows'],push_id=r['push_id'])
self.assertEqual(compose_definition_candidates(*args)['added_count'],0)
def test_reencoded_collateral_mask_and_wrong_amount_rejected(self):
for field,value in [('EffectSpellClassMask',[-2147483648,4,0,0]),('EffectBasePointsF',3),('EffectMiscValue',[18,0])]:
args=self.staged();row=next(r for r in args[1][0]['records']if r['table_name']=='SpellEffect')
row['record'][field]=value;raw=codec.encode(row['record'],args[2]['SpellEffect']);row.update(wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
with self.assertRaises(ValueError,msg=field):compose_definition_candidates(*args)
def test_namespace_mapping_and_known_spell_mutations_rejected(self):
for mutation in ('namespace','mask','known','stance','positive'):
v=self.fixture()
if mutation=='namespace':v[7]['modifier_namespace']['target_op']=18
elif mutation=='mask':v[7]['affect_masks']['53204:0']=1
elif mutation=='known':v[6]['SkillLineAbility']={'53204':1500001}
elif mutation=='stance':v[2][0]['conditions']['stances']=1
else:v[3]['SpellName'].append(dict(ID=53204,Name_lang='Already present'))
with self.assertRaises(ValueError,msg=mutation):self.component(v)
if __name__=='__main__':unittest.main()