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

101 lines
8.3 KiB
Python

"""Three real source rows; no game/server changes or synthetic gameplay claims."""
import copy,json,sys,unittest,hashlib
from pathlib import Path
from types import SimpleNamespace
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'tests')]
import spell_scripted_aura_compat as m,spell_passive_compat as codec,content_package_stage as stage
from spell_definition_common import checked_constant_source,review_proc_conditions
from turtle_data import spell_layout
from item_sparse_compat import package_payloads
import spell_restore_compat_test as restore
class ScriptedAuraTest(unittest.TestCase):
def source(self):
f=json.loads((ROOT/'tests/fixtures/scripted-vampirism-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__)
kw=dict(family_namespace=f['family_namespace'],proc_proof=f['proc_namespace'],semantics=f['semantics'],proc_event_rows=f['source_proc_event_rows'])
return f,dbc,kw,[m.source_spell(dbc,r,spell_layout(),**kw)for r in f['server_rows']]
def fixture(self):
f,_,_,sources=self.source();v=list(restore.RestorationCompatibilityTest().new_fixture());v[0]=sources
for table in('SpellCategories','SpellAuraOptions'):
v[2][table]=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(table+'.dbd'),table);v[3][table]=1500000
v[1]['SpellDuration']=[dict(ID=21,Duration=-1,MaxDuration=-1,DurationPerResource=0)]
v[5]['source_tables']['SpellDuration']=SimpleNamespace(by_id={21:[21,0xffffffff,0,0xffffffff]})
v[5]['source_tables']['SpellRange'].by_id[4]=[4,0,1106247680,0]+[0]*18
v[1]['SpellRange'].append(dict(ID=4,RangeMin=[0,0],RangeMax=[30,30],Flags=0))
path='interface/icons/spell_shadow_unsummonbuilding.blp';raw=b'BLP2'+bytes(20)
v[5].update(proc_proof=f['proc_namespace'],new_icon_ids={str(s['entry']):136230 for s in sources},target_icon_names={136230:[path]},icon_assets=[dict(path=path,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex())],read_icon=lambda _:raw)
v[5]['source_tables']['SpellIcon']=SimpleNamespace(by_id={150:[150,1]},string=lambda _:'Interface\\Icons\\Spell_Shadow_UnsummonBuilding')
return v
def component(self,v):return m.new_component(*v[:5],**v[5])
def test_three_genuine_percentages_and_distinct_native_positive_representation(self):
v=self.fixture();before=copy.deepcopy(v[:5]);r=self.component(v)
self.assertEqual(v[:5],before);self.assertEqual(len(r['records']),24)
self.assertEqual([r['record']['EffectBasePointsF']for r in r['records']if r['table_name']=='SpellEffect'],[1,2,3])
misc=[r['record']for r in r['records']if r['table_name']=='SpellMisc']
self.assertTrue(all(r['Attributes']==[192,0x10000000,0,0x4000000,0x1000]+[0]*12 for r in misc))
self.assertTrue(all(r['RangeIndex']==4 and r['SchoolMask']==32 for r in misc))
self.assertFalse(r['installable']);self.assertFalse(r['engine_accepted']);self.assertFalse(r['gameplay_verified'])
self.assertTrue(all(not s['known_spells_modified']for s in r['spells']))
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
v[4]=r['child_id_registry'];self.assertEqual(self.component(v),r)
def test_existing_default_ingestion_and_proc_policy_stay_strict(self):
f,dbc,kw,_=self.source();raw=f['server_rows'][0]
with self.assertRaises(ValueError):checked_constant_source(dbc,raw,spell_layout(),family_namespace=kw['family_namespace'])
with self.assertRaises(ValueError):review_proc_conditions(raw,dbc.by_id[raw['entry']],spell_layout(),f['proc_namespace'])
def test_script_capture_flags_categories_or_proc_override_drift_reject(self):
for mutation in('script','category','disk','positive','proc-override','namespace'):
f,dbc,kw,_=self.source();r=f['server_rows'][0]
if mutation=='script':r['script_name']='unreviewed_script'
elif mutation=='category':r['dmgClass']=0
elif mutation=='disk':dbc.by_id[r['entry']][spell_layout()['EffectBasePoints']]=99
elif mutation=='positive':r['customFlags']=2
elif mutation=='proc-override':kw['proc_event_rows']=[dict(procEx=1)]
else:kw['semantics']['server_script_body_sha256']='0'*64
with self.assertRaises(ValueError,msg=mutation):m.source_spell(dbc,r,spell_layout(),**kw)
def test_source_amount_identity_is_not_a_fixed_spell_id_allowlist(self):
v=self.fixture();v[0][:]=v[0][:1];src=v[0][0];src['entry']=600126;src['effects'][0][2]=6;v[5]['new_icon_ids']={'600126':136230}
r=self.component(v);self.assertEqual(r['spells'][0]['spell_id'],600126)
self.assertEqual(next(row['record']['EffectBasePointsF']for row in r['records']if row['table_name']=='SpellEffect'),7)
def test_bad_range_scaling_proc_and_client_effect_substitutions_reject(self):
for mutation in('range','radius','target','heal','flag','periodic-heal','trigger','amount','coefficient','cost','native','icon'):
v=self.fixture();s=v[0][0]
if mutation=='range':v[1]['SpellRange'][-1]['RangeMax']=[40,40]
elif mutation=='radius':s['effects'][0][7]=1
elif mutation=='target':s['effects'][0][8]=1
elif mutation=='heal':s['effects'][0][0]=10
elif mutation=='flag':s['attributes'][4]=4
elif mutation=='periodic-heal':s['conditions']['procFlags']|=1<<19
elif mutation=='trigger':s['effects'][0][10]=123
elif mutation=='amount':s['effects'][0][2]=True
elif mutation=='coefficient':s['effects'][0][11]=0
elif mutation=='cost':s['power'][1]=1
elif mutation=='native':v[1]['SpellName'].append(dict(ID=s['entry'],Name_lang='already exists'))
else:v[5]['target_icon_names']={136230:['interface/icons/unrelated.blp']}
with self.assertRaises(ValueError,msg=mutation):self.component(v)
def stage_args(self):
v=self.fixture();r=self.component(v);metadata=codec.TABLES|codec.SUPPLEMENTAL_TABLES
r['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=v[3][t])for t in{r['table_name']for r in r['records']}}
raw=b'Preserved fixture\0';row=dict(table_name='SpellName',table_hash=hex(codec.TABLES['SpellName'][0]),id=9911,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
package=dict(build=codec.BUILD,schema=codec.SCHEMA,id_remapping=False,rows=[row],push_id=package_payloads([row])[0])
return package,[r],{t:v[2][t]for t in r['native_tables']},{str(s['entry']):dict(infoStatus='nil',nameStatus='nil',descriptionStatus='nil')for s in v[0]}
def test_shared_stager_requires_real_api_absence_and_complete_scripted_children(self):
a=self.stage_args();r=stage.compose_definition_candidates(*a);self.assertEqual(r['added_count'],24);self.assertEqual(r['rows'][:1],a[0]['rows'])
a[0].update(rows=r['rows'],push_id=r['push_id']);self.assertEqual(stage.compose_definition_candidates(*a)['added_count'],0)
a[3]['45420']['infoStatus']='ok'
with self.assertRaises(ValueError):stage.compose_definition_candidates(*a)
def test_stager_rejects_reencoded_semantic_tampering(self):
for mutation in('positive','proc','range','local-heal','missing'):
a=self.stage_args();c=a[1][0]
if mutation=='missing':c['records'][:]=[r for r in c['records']if r['table_name']!='SpellAuraOptions']
else:
table='SpellMisc'if mutation in('positive','range')else'SpellAuraOptions'if mutation=='proc'else'SpellEffect';r=next(r for r in c['records']if r['table_name']==table)
if mutation=='positive':r['record']['Attributes'][4]=4
elif mutation=='range':r['record']['RangeIndex']=1
elif mutation=='proc':r['record']['ProcTypeMask'][0]|=1<<19
else:r['record']['Effect']=10
wire=codec.encode(r['record'],a[2][table]);r.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
with self.assertRaises(ValueError,msg=mutation):stage.compose_definition_candidates(*a)
if __name__=='__main__':unittest.main()