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

112 lines
7.8 KiB
Python

#!/usr/bin/env python3
import copy,json,math,struct,sys,tempfile,unittest
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import spell_shield_slam_compat as m
import spell_passive_compat as typed
class ShieldSlamDefinitionTest(unittest.TestCase):
@classmethod
def setUpClass(cls):cls.fixture=json.loads((Path(__file__).parent/'fixtures/shield-slam-definition.json').read_text())
def case(self):
f=copy.deepcopy(self.fixture);f['controls']['effects']={int(k):v for k,v in f['controls']['effects'].items()}
return [f[k] for k in ('source','relationships','controls','allocations')]
def test_full_thirteen_records_and_strict_publication_gate(self):
r=m.records(*self.case());self.assertEqual(len(r['records'])+len(r['effects']),13)
self.assertFalse(r['production_installable']);self.assertFalse(r['native_combat_or_rng_equivalence_claimed'])
self.assertIn('original-native-api-absence',r['remaining_gates'])
def test_source_ap_operand_not_stale_native_spell_power(self):
a=self.case();self.assertEqual(a[2]['effects'][1]['EffectBasePointsF'],655)
self.assertEqual(a[2]['effects'][1]['EffectBonusCoefficient'],1)
r=m.records(*a)['effects'][1]
self.assertEqual(r['EffectBasePointsF'],350);self.assertEqual(r['EffectBonusCoefficient'],0)
self.assertEqual(r['BonusCoefficientFromAP'],.2)
def test_damage_range_endpoints_after_native_float32_serialization(self):
r=m.records(*self.case())['effects'][1]
f=lambda x:struct.unpack('<f',struct.pack('<f',x))[0]
v=f(r['Variance']);base=f(r['EffectBasePointsF']);low=base-base*v*.5;high=base+base*v*.5
self.assertAlmostEqual(low,342,places=5);self.assertAlmostEqual(high,358,places=5)
def test_source_dice_zero_and_one_use_base_dice_not_implicit_plus_one(self):
s=self.case()[0];s.update(effectBasePoints2=50,effectBaseDice2=0,effectDieSides2=0)
self.assertEqual(m.damage_range(s,1)['minimum'],50)
s['effectDieSides2']=1;self.assertEqual(m.damage_range(s,1)['maximum'],50)
def test_dispel_default_sentinel_is_unused_not_literal_negative_coefficient(self):
r=m.records(*self.case())['effects'][0]
self.assertEqual(r['EffectBasePointsF'],1);self.assertEqual(r['EffectMiscValue'],[1,0])
self.assertEqual(r['EffectBonusCoefficient'],0);self.assertEqual(r['BonusCoefficientFromAP'],0)
def test_missing_ap_flag_default_sentinel_and_unreviewed_flags_rejected(self):
for key,val in (('customFlags',0x8000),('effectBonusCoefficient2',-1),('customFlags',0x808080),('attributesEx4',1)):
a=self.case();a[0][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_source_effect_target_count_coefficient_drift_rejected(self):
for key,val in (('effect1',3),('effectMiscValue1',0),('effectDieSides1',2),('effectImplicitTargetA2',1),('effectBonusCoefficient2',1)):
a=self.case();a[0][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_source_timing_power_category_script_dependency_drift_rejected(self):
for key,val in (('category',0),('categoryRecoveryTime',5000),('manaCost',20),('powerType',0),('script_name',''),('rangeIndex',4)):
a=self.case();a[0][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_non_neutral_requirements_and_extra_effect_rejected(self):
for key,val in (('reagent1',5),('stances',1),('procFlags',1),('effectTriggerSpell1',123),('effect3',6)):
a=self.case();a[0][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_native_constructor_unknown_field_and_nonneutral_drift_rejected(self):
for key,val in (('Unknown',0),('EffectAttributes',1),('Coefficient',1),('ScalingClass',1)):
a=self.case();a[2]['effects'][1][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_native_power_unit_cost_cooldown_and_condition_drift_rejected(self):
for group,key,val in (('power','ManaCost',20),('power','RequiredAuraSpellID',7),('cooldowns','AuraSpellID',1),('categories','ChargeCategory',1),('misc','RangeIndex',4)):
a=self.case();a[2][group][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_exact_source_book_and_visual_relationships_required(self):
for key,val in (('spell_id',23925),('visual_held',True)):
a=self.case();a[1][key]=val
with self.assertRaises(ValueError):m.records(*a)
def test_relationship_rows_rederived_not_trusted(self):
for table,key,value in (('SpellClassOptions','SpellClassMask',[1,0,0,0]),('SpellLevels','BaseLevel',1),('SkillLineAbility','SupercedesSpell',0),('SpellXSpellVisual','SpellVisualID',43)):
a=self.case();a[1]['records'][table][key]=value
with self.assertRaises(ValueError):m.records(*a)
def test_unknown_description_tokens_and_boolean_metadata_rejected(self):
for key,value in (('description','$unknown'),('school',False)):
a=self.case();a[0][key]=value
with self.assertRaises(ValueError):m.records(*a)
def test_exact_reviewer_all_tables_and_rejects_damage_or_book_drift(self):
source,relationship,controls,allocations=self.case()
contract={'relationships':relationship,'controls':controls,'allocations':allocations}
rebuilt=m.records(source,relationship,controls,allocations)
rows=[(table,row) for table,row in rebuilt['records'].items()]+[('SpellEffect',row) for row in rebuilt['effects'].values()]
for table,row in rows:
candidate={'table_name':table,'record':row,'id':row['ID']}
self.assertTrue(m.review_record(source,contract,candidate))
bad=copy.deepcopy(candidate);bad['record']['SpellID']=0
with self.assertRaises(ValueError):m.review_record(source,contract,bad)
bad={'table_name':'Unknown','record':{},'id':1}
with self.assertRaises(ValueError):m.review_record(source,contract,bad)
def test_named_attributes_seventeen_words_without_native_extra_stale_flags(self):
a=self.case();self.assertNotEqual(a[2]['misc']['Attributes'][15],0)
attrs=m.records(*a)['records']['SpellMisc']['Attributes']
self.assertEqual(len(attrs),17);self.assertEqual(attrs[15],0)
self.assertEqual(attrs[:2],[0x50010,0x08000200])
def schema_text(self,table):
data=self.fixture['extra_schemas'][table];fields=data['fields'];declarations=[];body=[]
for name,kind,bits,unsigned,count in fields:
declarations.append(kind+' '+name)
body.append(name+(('<'+('u' if unsigned else '')+str(bits)+'>') if kind=='int' else '')+('['+str(count)+']' if count!=1 else ''))
return '\n'.join(declarations)+'\n\nLAYOUT '+f'{m.EXTRA_TABLES[table][1]:08X}'+'\nBUILD '+typed.BUILD+'\n'+'\n'.join(body)+'\n'
def test_extra_schemas_exact_fields_encoding_and_corruption_rejection(self):
with tempfile.TemporaryDirectory() as d:
for table in ('SpellPower','SpellCooldowns'):
path=Path(d)/(table+'.dbd');text=self.schema_text(table);path.write_text(text)
schema=m.extra_fields(path,table)
self.assertEqual(typed.canonical_sha256(schema),m.EXTRA_TABLES[table][2])
row=m.records(*self.case())['records'][table]
self.assertGreater(len(typed.encode(row,schema)),0)
path.write_text(text.replace('SpellID<32>','SpellID<16>'))
with self.assertRaises(ValueError):m.extra_fields(path,table)
def test_bool_nonfinite_and_new_default_coefficients_rejected(self):
for value in (True,float('inf'),float('nan'),-.1):
a=self.case();a[0]['effectBonusCoefficient2']=value
with self.assertRaises(ValueError):m.records(*a)
if __name__=='__main__':unittest.main()