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

131 lines
9.0 KiB
Python

#!/usr/bin/env python3
"""Source-derived multi-category armor composition and fail-closed boundaries."""
import copy,json,sys,unittest
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from item_batch_stage import compose_plain_armor_batch
from item_sparse_compat import package_payloads
class PlainArmor(unittest.TestCase):
def setUp(self):
self.f=json.loads((Path(__file__).parent/'fixtures/owned-plain-armor.json').read_text())
rows=[self.f['preserved_record']];push,_=package_payloads(rows)
self.package=dict(build='1.60.1.70334',schema='wowstatic_camelot_1_60_1',push_id=push,rows=rows)
self.basics={r['id']:r for r in self.f['basics']}
self.baselines={r['identity']['entry']:r for r in self.f['baselines']}
def run_batch(self):
return compose_plain_armor_batch(self.package,self.f['source'],self.basics,
{r['ID']:r for r in self.f['points']},{},self.f['schema'],self.baselines, self.f['native_links'])
def test_all_source_records_preserve_identity_and_exact_armor(self):
before=copy.deepcopy((self.package,self.f));r=self.run_batch()
self.assertEqual(len(r['added']),8)
for row in r['added']:
if row['table_name']!='ItemSparse':continue
stats=list(zip(row['record']['StatModifier_bonusStat'],row['record']['StatPercentEditor']))
# Exact original compiled armor baselines plus per-item modifier,
# including the shoulder's58 additional armor. Native UI tested apart.
source=next(s for s in self.f['source']if s['entry']==row['id'])
base=self.baselines[row['id']]['native_armor']
self.assertEqual(row['record']['Display_lang'],source['name'])
self.assertEqual(sum(1 for stat,_ in stats if stat==50),int(source['armor']!=base))
self.assertEqual(before,(self.package,self.f));self.assertFalse(r['engine_accepted'])
self.f['source'].reverse();self.assertEqual(r,self.run_batch())
def test_dependencies_are_not_silently_dropped(self):
for field,value in [('block',1),('spellid_1',123),('spellcharges_1',1),('set_id',1),('extra_flags',1),('duration',1),('script_name','x')]:
with self.subTest(field=field):
old=self.f['source'][0].get(field);self.f['source'][0][field]=value
with self.assertRaises(ValueError):self.run_batch()
self.f['source'][0][field]=old
self.f['native_links']=[dict(ID=1,ItemID=self.f['source'][0]['entry'],ItemEffectID=2)]
with self.assertRaises(ValueError):self.run_batch()
def test_stale_component_missing_baseline_and_collision_fail(self):
i=self.f['source'][0]['entry'];b=self.basics[i];old=b['source_record_sha256'];b['source_record_sha256']='0'*64
with self.assertRaises(ValueError):self.run_batch()
b['source_record_sha256']=old;base=self.baselines.pop(i)
with self.assertRaises(ValueError):self.run_batch()
self.baselines[i]=base;r=self.run_batch();self.package.update(rows=r['rows'],push_id=r['push_id'])
with self.assertRaises(ValueError):self.run_batch()
def test_existing_package_prefix_is_unchanged(self):
first=self.f['source'].pop();first_basic=self.basics[first['entry']]
self.package['rows']=[copy.deepcopy(first_basic)];self.package['push_id']=package_payloads(self.package['rows'])[0]
r=self.run_batch();self.assertEqual(r['rows'][0],first_basic);self.assertEqual(len(r['added']),6)
def test_passive_equipment_reuses_armor_baselines_and_genuine_effect_links(self):
from item_batch_stage import compose_passive_equipment_batch,compose_accessory_batch
from item_batch_stage_test import AccessoryCompositionTest
from octo_client_data import canonical_sha256
args=AccessoryCompositionTest().inputs();args.update(package=self.package,
source=copy.deepcopy(self.f['source']),basics=copy.deepcopy(self.basics),
points={r['ID']:r for r in self.f['points']})
for p in args['source']:
p.update(spellid_1=123,spelltrigger_1=1)
args['basics'][p['entry']]['source_record_sha256']=canonical_sha256(p)
before=copy.deepcopy(args)
result=compose_passive_equipment_batch(**args,armor_baselines=self.baselines)
self.assertEqual(args,before)
self.assertEqual(result['rows'][:1],self.package['rows'])
self.assertEqual(len(result['added']),16)
self.assertEqual(len([r for r in result['added']if r['table_name']=='ItemEffect']),4)
sparse={r['id']:r['wire_hex']for r in result['added']if r['table_name']=='ItemSparse'}
plain={r['id']:r['wire_hex']for r in self.run_batch()['added']if r['table_name']=='ItemSparse'}
self.assertEqual(sparse,plain) # Linking spells cannot change armor/stat arithmetic.
with self.assertRaises(ValueError):compose_accessory_batch(**args)
with self.assertRaises(ValueError):compose_passive_equipment_batch(**args)
args['source'][0]['spelltrigger_1']=2
args['basics'][args['source'][0]['entry']]['source_record_sha256']=canonical_sha256(args['source'][0])
with self.assertRaises(ValueError):compose_passive_equipment_batch(**args,armor_baselines=self.baselines)
def test_shared_composer_admits_all_verified_plain_weapon_components(self):
from item_batch_stage_test import scalar
from item_basic_compat import equipment_record
from item_catalog_stage_test import Catalog
from item_damage_profile import native_weapon_baseline
sources=[];basics={};weapons={}
for ident,sub,inv in((500701,4,13),(500702,7,21),(500703,1,17)):
p=dict(scalar(ident),**{'class':2,'subclass':sub,'inventory_type':inv,'item_level':20,'quality':4,'delay':2000,'dmg_min1':15,'dmg_max1':25})
sources.append(p);basics[ident]=equipment_record(p,icon_evidence=Catalog().icon(p)['target_reference'])
tables={name:[dict(ID=20,ItemLevel=20,Quality=[10]*7)]for name in('ItemDamageOneHand','ItemDamageTwoHand')}
weapons[ident]=native_weapon_baseline(p,tables)
r=compose_plain_armor_batch(self.package,sources,basics,{}, {},self.f['schema'],{},[],weapon_baselines=weapons)
self.assertEqual(len(r['added']),6);self.assertEqual(r['rows'][0],self.package['rows'][0])
self.assertTrue(all(row['record']['DmgVariance']==.5 for row in r['added']if row['table_name']=='ItemSparse'))
sources[0]['spellid_1']=100
with self.assertRaises(ValueError):compose_plain_armor_batch(self.package,sources,basics,{}, {},self.f['schema'],{},[],weapon_baselines=weapons)
def test_explicit_source_shield_block_is_flat_value_not_rating(self):
self.f['source']=self.f['blocked_source']
with self.assertRaisesRegex(ValueError,'explicit'):self.run_batch()
r=compose_plain_armor_batch(self.package,self.f['source'],self.basics,
{r['ID']:r for r in self.f['points']},{},self.f['schema'],self.baselines,[],shield_block=True)
self.assertEqual(len(r['added']),2)
item=next(v['record']for v in r['added']if v['table_name']=='ItemSparse')
self.assertEqual(item['Display_lang'],"Husk of Nerub'enkan")
stats=dict(zip(item['StatModifier_bonusStat'],item['StatPercentEditor']))
from item_sparse_compat import f32
points=next(p for p in self.f['points']if p['ID']==61)['SuperiorF'][2]
decoded=lambda stat:int(f32(f32(stats[stat]*f32(points))*f32(.0001))+.5)
self.assertEqual(decoded(48),38);self.assertEqual(decoded(7),10)
self.assertEqual(decoded(55),15);self.assertNotIn(15,stats)
self.assertEqual(item['ItemLevel'],61)
def test_shield_block_type_category_capacity_and_budget_guards(self):
from item_sparse_compat import shield_block_stat,requires_stat_budget,convert
p=copy.deepcopy(self.f['blocked_source'][0])
for bad in(-1,True,False,None,'38',38.0,1<<31):
with self.subTest(bad=bad),self.assertRaises(ValueError):shield_block_stat(dict(p,block=bad),True)
for key,value in(('class',2),('subclass',4),('inventory_type',13)):
with self.assertRaises(ValueError):shield_block_stat(dict(p,**{key:value}),True)
for i in range(1,11):p['stat_value'+str(i)]=0
for key in('nature_res','fire_res','frost_res','holy_res','shadow_res','arcane_res'):p[key]=0
base=self.baselines[p['entry']];p['armor']=base['native_armor']
self.assertTrue(requires_stat_budget(p,armor_baseline=base,shield_block=True))
with self.assertRaisesRegex(ValueError,'budget'):
convert(p,self.basics[p['entry']]['record'],None,self.f['schema'],armor_baseline=base,shield_block=True)
p['block']=0;self.assertFalse(requires_stat_budget(p,armor_baseline=base,shield_block=True))
p['block']=38
for i in range(1,11):p['stat_type'+str(i)]=7;p['stat_value'+str(i)]=1
with self.assertRaisesRegex(ValueError,'capacity'):
convert(p,self.basics[p['entry']]['record'],self.f['points'][0],self.f['schema'],armor_baseline=base,shield_block=True)
if __name__=='__main__':unittest.main()