883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
118 lines
10 KiB
Python
118 lines
10 KiB
Python
"""Actual source reflection rows; synthetic icon bytes, no client or SQL."""
|
|
import copy, hashlib, json, sys, unittest
|
|
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_reflection_compat as m
|
|
import spell_passive_compat as codec
|
|
from spell_definition_common import checked_constant_source
|
|
from aura_visual_profile import new_link_candidate
|
|
from turtle_data import spell_layout
|
|
|
|
class ReflectionTest(unittest.TestCase):
|
|
def sources(self):
|
|
f=json.loads((ROOT/'tests/fixtures/school-reflection-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(),family_namespace=f['family_namespace'],semantics=f['semantics'],category_context=f['category_context'],proc_proof=f['proc_namespace'])for r in f['server_rows']]
|
|
return f,dbc,sources
|
|
def fixture(self):
|
|
f,_,sources=self.sources();sources=[s for s in sources if s['entry']!=23216]
|
|
tables=set(m.REQUIRED_REFERENCE_TABLES)|{'SpellCastTimes','SpellDuration','SpellRange'}
|
|
native=copy.deepcopy(f['native']);schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in set(m.NEW_DEFINITION_CHILD_TABLES)|{'Spell','SpellName','SpellAuraOptions','SpellCategories','SpellXSpellVisual'}}
|
|
maxima={t:1500000 for t in schemas};registry=dict(schema_version=1,build=codec.BUILD,SpellEffect={})
|
|
source_tables={k:SimpleNamespace(by_id={int(i):v for i,v in x['rows'].items()},string={int(i):v for i,v in x['strings'].items()}.__getitem__)for k,x in f['source_tables'].items()}
|
|
raw=b'BLP2'+bytes(20);icon_assets=[];target_names={};new_icons={}
|
|
for index,src in enumerate(sources):
|
|
icon=source_tables['SpellIcon'];path=icon.string(icon.by_id[src['spellIconId']][1]).replace('\\','/').lower()+'.blp';fid=9000+index
|
|
icon_assets.append(dict(path=path,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex()));target_names[fid]=[path];new_icons[str(src['entry'])]=fid
|
|
visuals={};visual_registry=dict(schema_version=1,build=codec.BUILD,SpellXSpellVisual={})
|
|
cases=json.loads((ROOT/'tests/fixtures/source-present-stage-visuals.json').read_text())['cases']
|
|
for src in sources:
|
|
c=next(c for c in cases if c['source']['entry']==src['entry'])
|
|
candidate=new_link_candidate(c['source'],c['source_visual'],c['native_visual'],c['native_events'],c['native_template'],schemas['SpellXSpellVisual'],1500000,visual_registry,set(),present_stages=True)
|
|
visual_registry=candidate['child_id_registry'];visuals[src['entry']]=candidate
|
|
opts=dict(source_tables=source_tables,target_icon_names=target_names,new_icon_ids=new_icons,icon_assets=icon_assets,read_icon=lambda _:raw,proc_proof=f['proc_namespace'],proc_overrides=f['proc_overrides'],visual_links=visuals)
|
|
return sources,native,schemas,maxima,registry,opts
|
|
def component(self,v):return m.new_component(*v[:5],**v[5])
|
|
def test_actual_source_all_three_modes_and_default_policy_stays_closed(self):
|
|
f,dbc,src=self.sources();self.assertEqual({s['entry']for s in src},{23178,23216,52976})
|
|
charged=next(s for s in src if s['entry']==52976)
|
|
self.assertEqual((charged['school'],charged['dispel_type'],charged['defense_type'],charged['conditions']['procCharges']),(2,1,1,1))
|
|
for raw in f['server_rows']:
|
|
with self.assertRaises(ValueError):checked_constant_source(dbc,raw,spell_layout(),family_namespace=f['family_namespace'])
|
|
def test_actual_source_dbc_and_named_contract_mismatch_rejected(self):
|
|
for mutation in ('mask','dispel','chance','school','multiplier','proof','unknown','stance'):
|
|
f,dbc,_=self.sources();r=next(r for r in f['server_rows']if r['entry']==52976)
|
|
if mutation=='mask':r['effectMiscValue1']=8
|
|
elif mutation=='dispel':dbc.by_id[52976][spell_layout()['DispelType']]=0
|
|
elif mutation=='chance':r['procCharges']=0
|
|
elif mutation=='school':r['school']=3
|
|
elif mutation=='multiplier':r['effectMultipleValue1']=1
|
|
elif mutation=='proof':f['semantics']['mappings'][0]['target_value']=75
|
|
elif mutation=='unknown':r['effectRadiusIndex1']=1
|
|
else:r['stanceBarOrder']=0
|
|
with self.assertRaises(ValueError,msg=mutation):m.source_spell(dbc,r,spell_layout(),family_namespace=f['family_namespace'],semantics=f['semantics'],category_context=f['category_context'],proc_proof=f['proc_namespace'])
|
|
def test_preserves_school_charge_dispel_duration_and_source_multiplier(self):
|
|
v=self.fixture();before=copy.deepcopy(v[:5]);r=self.component(v);self.assertEqual(v[:5],before);self.assertEqual(len(r['records']),16)
|
|
for src in v[0]:
|
|
meta=next(s for s in r['spells']if s['spell_id']==src['entry']);rows={x['table_name']:x['record']for x in r['records']if x['source_spell_id']==src['entry']}
|
|
self.assertEqual((rows['SpellMisc']['SchoolMask'],rows['SpellMisc']['DurationIndex']),(1<<src['school'],src['durationIndex']))
|
|
self.assertEqual(rows['SpellCategories']['DispelType'],src['dispel_type']);self.assertEqual(rows['SpellCategories']['DefenseType'],src['defense_type'])
|
|
self.assertEqual(rows['SpellEffect']['EffectAura'],74);self.assertEqual(rows['SpellEffect']['EffectBasePointsF'],100)
|
|
self.assertEqual(rows['SpellEffect']['EffectMiscValue'],[1<<src['school'],0]);self.assertEqual(rows['SpellEffect']['EffectAmplitude'],src['effect_value_multipliers'][0])
|
|
self.assertEqual(rows['SpellAuraOptions']['ProcCharges'],src['conditions']['procCharges']);self.assertEqual(rows['SpellAuraOptions']['ProcChance'],src['conditions']['procChance'])
|
|
self.assertEqual(meta['duration_reference']['duration_ms'],6000 if src['entry']==52976 else 5000)
|
|
for row in r['records']:
|
|
if row['source_spell_id']==src['entry']:self.assertTrue(m.review_record(src,meta,row));self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[2][row['table_name']]))
|
|
self.assertFalse(r['installable']);self.assertFalse(r['engine_accepted']);self.assertFalse(r['gameplay_verified']);self.assertEqual(r['proc_override_snapshot'],v[5]['proc_overrides'])
|
|
def test_source_mutations_cannot_strip_or_invent_metadata(self):
|
|
for mutation in ('charges','chance','flags','mask','target','amount','scale','extra','cost','timing','levels','attribute','category','bool','multiplier'):
|
|
f,_,sources=self.sources();s=next(s for s in sources if s['entry']==52976)
|
|
if mutation=='charges':s['conditions']['procCharges']=0
|
|
elif mutation=='chance':s['conditions']['procChance']=8
|
|
elif mutation=='flags':s['conditions']['procFlags']=0
|
|
elif mutation=='mask':s['effects'][0][7]=126
|
|
elif mutation=='target':s['effects'][0][8]=6
|
|
elif mutation=='amount':s['effects'][0][2]=98
|
|
elif mutation=='scale':s['effects'][0][6]=1
|
|
elif mutation=='extra':s['effects'][1]=copy.deepcopy(s['effects'][0])
|
|
elif mutation=='cost':s['power'][1]=1
|
|
elif mutation=='timing':s['timing']['recoveryTime']=1000
|
|
elif mutation=='levels':s['levels']['baseLevel']=1
|
|
elif mutation=='attribute':s['attributes'][0]=64
|
|
elif mutation=='category':s['dispel_type']=0
|
|
elif mutation=='bool':s['effects'][0][2]=True
|
|
else:s['effect_value_multipliers'][0]=.5
|
|
with self.assertRaises(ValueError,msg=mutation):m.validate_source(s,f['proc_namespace'])
|
|
def test_wire_reencoding_does_not_hide_semantic_mutations(self):
|
|
v=self.fixture();r=self.component(v);s=next(s for s in v[0]if s['entry']==52976);meta=next(s for s in r['spells']if s['spell_id']==52976)
|
|
fields={'SpellName':('Name_lang','wrong'),'Spell':('AuraDescription_lang','wrong'),'SpellMisc':('SchoolMask',8),'SpellEquippedItems':('EquippedItemClass',2),'SpellEffect':('EffectAura',75),'SpellCategories':('DispelType',0),'SpellAuraOptions':('ProcCharges',0),'SpellXSpellVisual':('SpellVisualID',334)}
|
|
for table,(key,value)in fields.items():
|
|
row=copy.deepcopy(next(x for x in r['records']if x['source_spell_id']==52976 and x['table_name']==table));row['record'][key]=value;wire=codec.encode(row['record'],v[2][table]);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
|
|
with self.assertRaisesRegex(ValueError,'semantics differ',msg=table):m.review_record(s,meta,row)
|
|
def test_visual_stage_event_and_owner_must_be_complete(self):
|
|
for mutation in ('missing','stage','owner','wire','collision'):
|
|
v=self.fixture();candidate=v[5]['visual_links'][52976]
|
|
if mutation=='missing':del v[5]['visual_links'][52976]
|
|
elif mutation=='stage':candidate['lifecycle_review']['inputs']['native_events'].pop()
|
|
elif mutation=='owner':candidate['profile_definition']['spell']=123
|
|
elif mutation=='wire':candidate['record']['wire_hex']='00'
|
|
else:v[3]['SpellXSpellVisual']=candidate['record']['id']
|
|
with self.assertRaises(ValueError,msg=mutation):self.component(v)
|
|
def test_arcane_source_valid_but_no_visual_bypass(self):
|
|
f,_,s=self.sources();arcane=next(x for x in s if x['entry']==23216);self.assertEqual(m.validate_source(arcane,f['proc_namespace'])[0],[0])
|
|
v=list(self.fixture());v[0].append(arcane);v[5]['new_icon_ids']['23216']=9002
|
|
with self.assertRaisesRegex(ValueError,'visual dependencies'):self.component(v)
|
|
def test_native_positives_filter_overrides_and_icon_drift_are_rejected(self):
|
|
for mutation in ('positive','override','icon','duration'):
|
|
v=self.fixture()
|
|
if mutation=='positive':v[1]['SpellName'].append(dict(ID=52976,Name_lang='existing'))
|
|
elif mutation=='override':v[5]['proc_overrides']['rows']=[dict(zip(v[5]['proc_overrides']['columns'],[52976]+[0]*10))]
|
|
elif mutation=='icon':v[5]['read_icon']=lambda _:b'wrong'
|
|
else:v[1]['SpellDuration'][0]['Duration']=100
|
|
with self.assertRaises(ValueError,msg=mutation):self.component(v)
|
|
def test_stable_allocations_and_source_order(self):
|
|
v=list(self.fixture());r=self.component(v);v[0].reverse();v[4]=r['child_id_registry'];self.assertEqual(self.component(v),r)
|
|
|
|
if __name__=='__main__':unittest.main()
|