883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
111 lines
8.5 KiB
Python
111 lines
8.5 KiB
Python
"""Actual source armor-penetration row; offline schemas/synthetic icon payload."""
|
|
import copy,hashlib,json,struct,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_item_resistance_compat as m
|
|
import spell_passive_compat as codec
|
|
import content_package_stage as stage
|
|
from item_sparse_compat import package_payloads
|
|
from spell_definition_common import checked_constant_source
|
|
from turtle_data import spell_layout
|
|
import spell_restore_compat_test as restore_tests
|
|
|
|
class ItemResistanceTest(unittest.TestCase):
|
|
def source(self):
|
|
f=json.loads((ROOT/'tests/fixtures/item-resistance-source.json').read_text())
|
|
dbc=SimpleNamespace(by_id={48030:f['disk_row']},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
|
|
src=m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],semantics=f['semantics'])
|
|
return f,dbc,src
|
|
def fixture(self):
|
|
f,_,src=self.source();v=list(restore_tests.RestorationCompatibilityTest().new_fixture());v[0]=[src]
|
|
v[2]['SpellCategories']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellCategories.dbd','SpellCategories');v[3]['SpellCategories']=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]})
|
|
path='interface/icons/ability_warrior_sunder.blp';raw=b'BLP2'+bytes(20)
|
|
v[5].update(new_icon_ids={'48030':136047},target_icon_names={136047:[path]},icon_assets=[dict(path=path,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),magic_hex=raw[:4].hex())],read_icon=lambda p:raw)
|
|
v[5]['source_tables']['SpellIcon']=SimpleNamespace(by_id={565:f['source_icon_row']},string=lambda _:f['source_icon_string'])
|
|
return v
|
|
def component(self,v):return m.new_component(*v[:5],**v[5])
|
|
def test_signed_source_amount_categories_and_wire_are_preserved(self):
|
|
v=self.fixture();before=copy.deepcopy(v[:5]);r=self.component(v);self.assertEqual(v[:5],before)
|
|
rows={x['table_name']:x['record']for x in r['records']}
|
|
self.assertEqual(len(r['records']),6)
|
|
self.assertEqual((rows['SpellEffect']['EffectAura'],rows['SpellEffect']['EffectBasePointsF'],rows['SpellEffect']['EffectMiscValue']),(123,-25,[1,0]))
|
|
self.assertEqual(rows['SpellMisc']['Attributes'],[128]+[0]*14+[0x2000,0])
|
|
self.assertEqual(rows['SpellMisc']['DurationIndex'],21)
|
|
self.assertEqual((rows['SpellCategories']['DefenseType'],rows['SpellCategories']['PreventionType']),(1,1))
|
|
category=next(x for x in r['records']if x['table_name']=='SpellCategories')
|
|
self.assertEqual(bytes.fromhex(category['wire_hex']),struct.pack('<hhbib bihhI'.replace(' ',''),0,0,1,0,0,0,1,0,0,48030))
|
|
for row in r['records']: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.assertFalse(r['spells'][0]['known_spells_modified'])
|
|
v[4]=r['child_id_registry'];self.assertEqual(self.component(v),r)
|
|
def test_default_source_policy_is_not_broadened(self):
|
|
f,dbc,_=self.source()
|
|
with self.assertRaisesRegex(ValueError,'nonzero server'):checked_constant_source(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'])
|
|
def test_actual_capture_categories_and_proof_must_match(self):
|
|
for mutation in('defense','prevention','disk','proof','stance'):
|
|
f,dbc,_=self.source()
|
|
if mutation=='defense':f['server_row']['dmgClass']=0
|
|
elif mutation=='prevention':f['server_row']['preventionType']=0
|
|
elif mutation=='disk':f['disk_row'][spell_layout()['PreventionType']]=0
|
|
elif mutation=='proof':f['semantics']['mappings'][0]['target_value']=0
|
|
else:f['server_row']['stanceBarOrder']=-1
|
|
with self.assertRaises(ValueError,msg=mutation):m.source_spell(dbc,f['server_row'],spell_layout(),family_namespace=f['family_namespace'],semantics=f['semantics'])
|
|
def test_other_same_mechanic_spell_ids_and_amounts_are_supported(self):
|
|
v=self.fixture();s=v[0][0];s['entry']=600123;s['effects'][0][2]=-101
|
|
v[5]['new_icon_ids']={'600123':136047}
|
|
rows={r['table_name']:r['record']for r in self.component(v)['records']}
|
|
self.assertEqual(rows['SpellName']['ID'],600123)
|
|
self.assertEqual(rows['SpellEffect']['EffectBasePointsF'],-100)
|
|
def test_no_silent_percent_rating_school_or_state_substitutions(self):
|
|
for change in('positive','aura','mask','target','cost','duration','defense','prevention','bool','level','proc','visual','text','duplicate'):
|
|
v=self.fixture();s=v[0][0]
|
|
if change=='positive':s['effects'][0][2]=24
|
|
elif change=='aura':s['effects'][0][1]=240
|
|
elif change=='mask':s['effects'][0][7]=126
|
|
elif change=='target':s['effects'][0][8]=6
|
|
elif change=='cost':s['power'][1]=1
|
|
elif change=='duration':s['durationIndex']=0
|
|
elif change=='defense':s['defense_type']=0
|
|
elif change=='prevention':s['prevention_type']=0
|
|
elif change=='bool':s['effects'][0][2]=True
|
|
elif change=='level':s['levels']['baseLevel']=1
|
|
elif change=='proc':s['conditions']['procFlags']=1
|
|
elif change=='visual':s['visuals'][0]=1
|
|
elif change=='text':s['description']='$s2'
|
|
else:s['effects'][1]=copy.deepcopy(s['effects'][0])
|
|
with self.assertRaises(ValueError,msg=change):self.component(v)
|
|
def test_positive_native_identity_or_icon_mismatch_refuses_addition(self):
|
|
v=self.fixture();v[1]['SpellName'].append(dict(ID=48030,Name_lang='unrelated'))
|
|
with self.assertRaisesRegex(ValueError,'positive native'):self.component(v)
|
|
v=self.fixture();v[5]['target_icon_names']={136047:['interface/icons/unrelated.blp']}
|
|
with self.assertRaises(ValueError):self.component(v)
|
|
def stage_args(self):
|
|
v=self.fixture();component=self.component(v);metadata=codec.TABLES|codec.SUPPLEMENTAL_TABLES
|
|
component['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 component['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,[component],{t:v[2][t]for t in component['native_tables']},{'48030':dict(infoStatus='nil',nameStatus='nil',descriptionStatus='nil')}
|
|
def test_shared_stager_requires_native_absence_and_preserves_all_source_fields(self):
|
|
args=self.stage_args();result=stage.compose_definition_candidates(*args)
|
|
self.assertEqual(result['added_count'],6);self.assertEqual(result['rows'][:1],args[0]['rows'])
|
|
self.assertFalse(result['requires_asset_installation'])
|
|
args[0].update(rows=result['rows'],push_id=result['push_id'])
|
|
self.assertEqual(stage.compose_definition_candidates(*args)['added_count'],0)
|
|
args[3]['48030']['nameStatus']='ok'
|
|
with self.assertRaisesRegex(ValueError,'API absence'):stage.compose_definition_candidates(*args)
|
|
def test_shared_stager_rejects_reencoded_amount_category_and_missing_children(self):
|
|
for mutation in('sign','prevention','marker','missing'):
|
|
args=self.stage_args();component=args[1][0]
|
|
if mutation=='missing':component['records'][:]=[r for r in component['records']if r['table_name']!='SpellCategories']
|
|
else:
|
|
table='SpellEffect'if mutation=='sign'else'SpellMisc'if mutation=='marker'else'SpellCategories';row=next(r for r in component['records']if r['table_name']==table)
|
|
if mutation=='marker':row['record']['Attributes'][15]=0
|
|
else:row['record']['EffectBasePointsF'if mutation=='sign'else'PreventionType']=25 if mutation=='sign'else 0
|
|
wire=codec.encode(row['record'],args[2][table]);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
|
|
with self.assertRaises(ValueError,msg=mutation):stage.compose_definition_candidates(*args)
|
|
|
|
if __name__=='__main__':unittest.main()
|