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

58 lines
3.5 KiB
Python

"""Target-only context is opt-in, bounded and independent of source flags."""
import copy
import hashlib
from pathlib import Path
import sys
import unittest
sys.path[:0]=[str(Path(__file__).resolve().parents[1]/'ops'),str(Path(__file__).resolve().parent)]
from spell_client_attributes import attributes,context
import spell_timed_buff_compat as timed
import spell_timed_buff_compat_test as fixture
import content_definition_stage_test as staging
import content_package_stage as stage
from spell_passive_compat import encode
def witnesses():
return [dict(ID=i+1,SpellID=i+10,DifficultyID=0,Attributes=[0]*15+[8192,0])for i in range(2)]
class TargetAttributes(unittest.TestCase):
def test_source_and_default_are_preserved(self):
src=dict(attributes=[64,0,0,0,0]);proof=context(witnesses());before=copy.deepcopy((src,proof))
result=attributes(src,proof);self.assertEqual(result[:5],src['attributes']);self.assertEqual(result[15],8192)
self.assertEqual(attributes(src),src['attributes']+[0]*12);self.assertEqual((src,proof),before)
def test_no_unreviewed_flag_or_witness(self):
for mode in('empty','duplicate','bool','bit','hash','build','field','prefix'):
rows=witnesses()
if mode=='empty':rows=[]
elif mode=='duplicate':rows[1]=copy.deepcopy(rows[0])
elif mode=='bool':rows[0]['Attributes'][15]=True
elif mode=='bit':rows[0]['Attributes'][15]=8193
elif mode=='prefix':
for r in rows:r['Attributes'][0]=64
if mode in('hash','build','field'):
p=context(rows);p[{'hash':'native_witness_sha256','build':'build','field':'field'}[mode]]='incorrect'
with self.assertRaises(ValueError,msg=mode):attributes(dict(attributes=[0]*5),p)
else:
with self.assertRaises(ValueError,msg=mode):context(rows)
def test_typed_generator_changes_only_target_misc(self):
v=fixture.TimedBuffCompatibilityTest().extra_fixture();base=timed.new_component(*v[:5],**v[5]);v[5]['client_attribute_context']=context(witnesses())
out=timed.new_component(*v[:5],**v[5]);changed=[(a,b)for a,b in zip(base['records'],out['records'])if a!=b]
self.assertEqual(len(changed),1);old,new=changed[0];self.assertEqual(new['table_name'],'SpellMisc')
r=copy.deepcopy(old['record']);r['Attributes'][15]=8192;self.assertEqual(r,new['record'])
raw=encode(r,v[2]['SpellMisc']);self.assertEqual(raw.hex(),new['wire_hex']);self.assertEqual(hashlib.sha256(raw).hexdigest(),new['sha256'])
self.assertEqual(base['spells'],out['spells']);self.assertFalse(out['gameplay_verified'])
v=fixture.TimedBuffCompatibilityTest().fixture();v[5]['client_attribute_context']=context(witnesses())
with self.assertRaises(ValueError):timed.new_component(*v[:5],**v[5])
def test_stager_requires_exact_context_and_generated_wire(self):
args=staging.DefinitionStageTest().composite_inputs();c=args[1][0];c['client_attribute_context']=context(witnesses())
row=next(r for r in c['records']if r['table_name']=='SpellMisc');row['record']['Attributes']=attributes(c['spells'][0]['source_definition'],c['client_attribute_context'])
def wire():
raw=encode(row['record'],args[2]['SpellMisc']);row.update(wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
wire();self.assertEqual(stage.compose_definition_candidates(*args)['added_count'],8)
row['record']['Attributes'][15]=8193;wire()
with self.assertRaises(ValueError):stage.compose_definition_candidates(*args)
row['record']['Attributes'][15]=8192;wire();c['client_attribute_context']['value']=8193
with self.assertRaises(ValueError):stage.compose_definition_candidates(*args)
if __name__=='__main__':unittest.main()