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

122 lines
11 KiB
Python

"""Focused current-SQL tooltip projection; no client, DB or catalogue export."""
import copy
import json
from pathlib import Path
import struct
import sys
import tempfile
import unittest
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'))
sys.path.insert(0,str(ROOT/'tests'))
import class_spell_compat as m
from class_spell_compat_test import native_dir
# Captured120-column currentSource51596 SQL shape, kept inline so discovery
# needs no private runtime fixture. Individual test values are explicit below.
SQL_SHAPE=json.loads(r'''{"entry":51596,"school":0,"category":0,"dispel":0,"mechanic":0,"attributes":327696,"attributesEx":0,"attributesEx2":0,"attributesEx3":0,"attributesEx4":0,"targets":0,"targetCreatureType":0,"requiresSpellFocus":0,"casterAuraState":0,"targetAuraState":0,"castingTimeIndex":1,"recoveryTime":0,"categoryRecoveryTime":0,"interruptFlags":0,"auraInterruptFlags":0,"channelInterruptFlags":0,"procFlags":680,"procChance":100,"procCharges":1,"maxLevel":0,"baseLevel":16,"spellLevel":16,"durationIndex":557,"powerType":1,"manaCost":0,"manCostPerLevel":0,"manaPerSecond":0,"manaPerSecondPerLevel":0,"rangeIndex":1,"speed":0,"modelNextSpell":0,"stackAmount":0,"equippedItemClass":4,"equippedItemSubClassMask":64,"equippedItemInventoryTypeMask":0,"effect1":6,"effect2":0,"effect3":0,"effectDieSides1":1,"effectDieSides2":0,"effectDieSides3":0,"effectBaseDice1":1,"effectBaseDice2":0,"effectBaseDice3":0,"effectDicePerLevel1":0,"effectDicePerLevel2":0,"effectDicePerLevel3":0,"effectRealPointsPerLevel1":0,"effectRealPointsPerLevel2":0,"effectRealPointsPerLevel3":0,"effectBasePoints1":34,"effectBasePoints2":0,"effectBasePoints3":0,"effectBonusCoefficient1":-1,"effectBonusCoefficient2":-1,"effectBonusCoefficient3":-1,"effectMechanic1":0,"effectMechanic2":0,"effectMechanic3":0,"effectImplicitTargetA1":1,"effectImplicitTargetA2":0,"effectImplicitTargetA3":0,"effectImplicitTargetB1":0,"effectImplicitTargetB2":0,"effectImplicitTargetB3":0,"effectRadiusIndex1":0,"effectRadiusIndex2":0,"effectRadiusIndex3":0,"effectApplyAuraName1":51,"effectApplyAuraName2":0,"effectApplyAuraName3":0,"effectAmplitude1":0,"effectAmplitude2":0,"effectAmplitude3":0,"effectMultipleValue1":0,"effectMultipleValue2":0,"effectMultipleValue3":0,"effectChainTarget1":0,"effectChainTarget2":0,"effectChainTarget3":0,"effectItemType1":0,"effectItemType2":0,"effectItemType3":0,"effectMiscValue1":0,"effectMiscValue2":0,"effectMiscValue3":0,"effectTriggerSpell1":0,"effectTriggerSpell2":0,"effectTriggerSpell3":0,"effectPointsPerComboPoint1":0,"effectPointsPerComboPoint2":0,"effectPointsPerComboPoint3":0,"spellVisual1":0,"spellVisual2":0,"spellIconId":2195,"activeIconId":0,"name":"Improved Shield Slam","nameSubtext":"Rank 1","description":"Increases chance to block by $s1% for $d.","auraDescription":"Block chance increased by $s1%.","manaCostPercentage":0,"startRecoveryCategory":0,"startRecoveryTime":0,"minTargetLevel":0,"maxTargetLevel":0,"spellFamilyName":4,"spellFamilyFlags":0,"maxAffectedTargets":0,"dmgClass":0,"preventionType":0,"dmgMultiplier1":1,"dmgMultiplier2":1,"dmgMultiplier3":1,"customFlags":0,"script_name":""}''')
def bits(value):return struct.unpack('<I',struct.pack('<f',value))[0]
def sql_row():
row=copy.deepcopy(SQL_SHAPE)
row.update(entry=10,name='Rend',nameSubtext='Rank 1',description='SQL $s1',auraDescription='',school=0,category=0,procFlags=0,procChance=0,procCharges=0,stackAmount=0,durationIndex=21,castingTimeIndex=1,rangeIndex=1,spellIconId=0,spellVisual1=0,powerType=0,manaCost=0,maxTargetLevel=63,maxAffectedTargets=2)
for key in ['attributes','attributesEx','attributesEx2','attributesEx3','attributesEx4']:row[key]=0
row.update(effect1=6,effectApplyAuraName1=3,effectBasePoints1=19,effectBaseDice1=1,effectDieSides1=1,effectAmplitude1=3000,effectImplicitTargetA1=6,effectImplicitTargetB1=0)
return row
def source_data():
offsets=m.spell_layout();raw=[0]*173;raw[0]=10;raw[offsets['Name_lang']]=1
strings={0:'',1:'Rend'}
spell=type('SpellFixture',(),{'by_id':{10:raw},'rows':[raw],'fields':173,'string':staticmethod(lambda i:strings[i])})()
store=lambda rows:type('DependencyFixture',(),{'by_id':rows,'string':staticmethod(lambda _: '')})()
rng=[0]*14;rng[0]=1;rng[1]=bits(0);rng[2]=bits(5)
return {'Spell':spell,'SpellDuration':store({21:(21,9000,0,9000)}),'SpellCastTimes':store({1:(1,0,0,0)}),'SpellRange':store({1:rng}),'SpellRadius':store({})},offsets
class NativeTooltipClosureTest(unittest.TestCase):
def setUp(self):
out=ROOT/'build/test-output/native-tooltip-closure';out.mkdir(parents=True,exist_ok=True)
self.tmp=tempfile.TemporaryDirectory(dir=out)
self.addCleanup(self.tmp.cleanup)
self.source,self.offsets=source_data();self.sql=sql_row()
native_dir(self.tmp.name,{'SpellCastTimes':[{'ID':1,'Base':0,'Minimum':0}],
'SpellRange':[{'ID':1,'DisplayName_lang':'Melee','DisplayNameShort_lang':'Melee','Flags':0,'RangeMin':[0.0,0.0],'RangeMax':[5.0,5.0]}]})
self.modify('SpellMisc',lambda row:row.update(CastingTimeIndex=1))
self.modify('SpellEffect',lambda row:row.update(EffectBonusCoefficient=.25,BonusCoefficientFromAP=.15,ScalingClass=-1,Coefficient=.5))
def modify(self,table,change):
path=Path(self.tmp.name)/(table+'.json');rows=json.loads(path.read_text())
for row in rows:change(row)
path.write_text(json.dumps(rows))
def append(self,table,row):
path=Path(self.tmp.name)/(table+'.json');rows=json.loads(path.read_text());rows.append(row);path.write_text(json.dumps(rows))
def run_plan(self,package=()):
view=m.NativeView([self.tmp.name],list(package));ids=iter(range(1000,2000))
return m.native_tooltip_plan(self.source,view,[10],self.offsets,server_templates={10:self.sql},icons={},allocate=lambda _:next(ids))
def test_sql_only_definition_has_no_donor_and_matches_complete_sql_dto(self):
expected=m.source_spell(self.source,10,self.offsets,server_template=self.sql)
self.source['Spell'].by_id.clear()
self.assertEqual(m.source_spell(self.source,10,self.offsets,server_template=self.sql),expected)
rows,report=self.run_plan()
self.assertEqual(report['scope_ids'],[10])
self.assertEqual(report['missing_source_ids'],[])
self.assertTrue(any(t=='SpellEffect' for t,_,_ in rows))
bad=copy.deepcopy(self.sql);del bad['effectBasePoints1']
with self.assertRaises(ValueError):m.source_spell(self.source,10,self.offsets,server_template=bad)
with self.assertRaises(ValueError):m.source_spell(self.source,10,self.offsets)
bad=copy.deepcopy(self.sql);bad['entry']=11
with self.assertRaises(ValueError):m.source_spell(self.source,10,self.offsets,server_template=bad)
def test_sql_values_replace_dbc_and_project_maximum_target_level(self):
dto=m.source_spell(self.source,10,self.offsets,server_template=self.sql)
self.assertEqual(dto['effects'][0]['base'],19);self.assertEqual(dto['max_target_level'],63)
rows,report=self.run_plan();effects=[r for t,r,_ in rows if t=='SpellEffect']
self.assertEqual(effects[0]['EffectBasePointsF'],20)
target=next(r for t,r,_ in rows if t=='SpellTargetRestrictions')
self.assertEqual((target['MaxTargetLevel'],target['MaxTargets']),(63,2))
self.assertEqual(target['Targets'],0) # no raw Source target-mask alias
self.assertEqual(report['held_duplicate_spell_ids'],[])
def test_existing_package_text_and_caster_modifiers_are_preserved(self):
package=[{'table_name':'Spell','id':10,'record':{'ID':10,'NameSubtext_lang':'Reviewed rank','Description_lang':'Reviewed literal','AuraDescription_lang':'Reviewed aura'}}]
rows,report=self.run_plan(package)
self.assertFalse(any(t in ('Spell','SpellName') for t,_,_ in rows))
effect=next(r for t,r,_ in rows if t=='SpellEffect')
self.assertEqual((effect['EffectBonusCoefficient'],effect['BonusCoefficientFromAP'],effect['ScalingClass'],effect['Coefficient']),(.25,.15,-1,.5))
self.assertTrue(report['preserved_decisions'])
def test_unsigned_source_health_power_is_signed_before_native_projection(self):
self.sql.update(powerType=0xfffffffe,manaCost=12)
dto=m.source_spell(self.source,10,self.offsets,server_template=self.sql)
self.assertEqual(dto['power_type'],-2)
rows,_=self.run_plan();power=next(r for t,r,_ in rows if t=='SpellPower')
self.assertEqual((power['PowerType'],power['ManaCost']),(-2,12))
def test_duplicate_singular_effect_and_power_keys_fail_closed(self):
# Each ambiguity is isolated; visual variants are deliberately separate.
cases=[('SpellMisc',{'ID':99,'SpellID':10,'DifficultyID':0}),
('SpellEffect',{'ID':99,'SpellID':10,'DifficultyID':0,'EffectIndex':0}),
('SpellPower',{'ID':98,'SpellID':10,'DifficultyID':0,'OrderIndex':0})]
for table,duplicate in cases:
with self.subTest(table=table):
path=Path(self.tmp.name)/(table+'.json');original=path.read_text()
if table=='SpellPower':self.append(table,dict(duplicate,ID=97))
self.append(table,duplicate);rows,report=self.run_plan()
self.assertEqual(report['held_duplicate_spell_ids'],[10]);self.assertFalse(rows)
path.write_text(original)
def test_nonzero_difficulty_and_visual_variants_are_not_false_ambiguities(self):
self.append('SpellMisc',{'ID':99,'SpellID':10,'DifficultyID':1})
for ident in [98,99]:self.append('SpellXSpellVisual',{'ID':ident,'SpellID':10,'DifficultyID':0,'SpellVisualID':1})
_,report=self.run_plan();self.assertEqual(report['held_duplicate_spell_ids'],[])
def test_scaled_duration_holds_spell_but_scaled_cast_preserves_native_reference(self):
self.source['SpellDuration'].by_id[21]=(21,9000,10,9000)
rows,report=self.run_plan();self.assertFalse(rows)
self.assertTrue(any(r.get('kind')=='level-scaled-duration-not-native-resource-duration'for r in report['held']))
self.source['SpellDuration'].by_id[21]=(21,9000,0,9000)
self.source['SpellCastTimes'].by_id[1]=(1,1500,10,500)
rows,report=self.run_plan();effect=next(r for t,r,_ in rows if t=='SpellEffect')
self.assertEqual(effect['EffectBasePointsF'],20)
misc=next(r for t,r,_ in rows if t=='SpellMisc')
self.assertEqual(misc['CastingTimeIndex'],1)
self.assertTrue(any(r.get('kind')=='level-scaled-cast-time-unrepresented'for r in report['held']))
def test_server_identity_and_required_column_errors_are_explicit(self):
dto=m.source_spell(self.source,10,self.offsets)
with self.assertRaisesRegex(ValueError,'identity'):m.server_spell_definition(dto,dict(self.sql,entry=11))
broken=dict(self.sql);del broken['maxTargetLevel']
with self.assertRaisesRegex(ValueError,'maxTargetLevel'):m.server_spell_definition(dto,broken)
if __name__=='__main__':unittest.main()