883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
64 lines
6.9 KiB
Python
64 lines
6.9 KiB
Python
"""Complete existing effective slots; no charged-use or spell implementation."""
|
|
from pathlib import Path
|
|
import copy,hashlib,json,sys,unittest
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import item_material_retention as material,item_effect_reference_retention as ref,item_sparse_compat as sparse,item_batch_stage as stage
|
|
from item_effect_compat import TABLES
|
|
from item_package_preflight import UNUSED_TEAM_DEFAULT_REVISION
|
|
|
|
class EffectReferenceRetentionTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.f=json.loads((ROOT/'tests/fixtures/item-effect-reference-retention.json').read_text());cls.items={r['source']['entry']:r for r in cls.f['items']};cls.schema=sparse.fields(ROOT.parent/'tools/WoWDBDefs/definitions/ItemSparse.dbd');cls.schemas={t:sparse.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),layout,count)for t,(_,layout,count)in TABLES.items()};cls.flags=material.flag_namespace(Path.home()/'Servers/tortoise-wow/src/game/Objects/ItemPrototype.h',ROOT.parent/'servers/trinity-forever/src/server/game/Entities/Item/ItemTemplate.h')
|
|
def records(self,i=12450):return copy.deepcopy(self.items[i])
|
|
def package(self):
|
|
f=json.loads((ROOT/'tests/fixtures/native-material-retention-source.json').read_text());n=next(r for r in f['sparse']if r['ID']==739);r=material.native_sparse_record(n,self.schema);raw=sparse.encode(r,self.schema);rows=[dict(table_name='ItemSparse',table_hash=hex(sparse.TABLE),id=739,record=r,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())];return dict(build='1.60.1.70334',rows=rows,push_id=sparse.package_payloads(rows)[0],pushes=sparse.package_pages(rows))
|
|
def context(self,package=None,effects=None,links=None):return ref.context(self.package()if package is None else package,self.f['effects']if effects is None else effects,self.f['links']if links is None else links,self.schemas)
|
|
def proof(self,r,ctx):return ref.evidence(r['source'],r['basic'],r['sparse'],self.schema,ctx)
|
|
def compose(self,rs,ctx=None):return stage.compose_material_retention_batch(self.package(),[r['source']for r in rs],{r['basic']['ID']:r['basic']for r in rs},{r['sparse']['ID']:r['sparse']for r in rs},self.schema,revision=UNUSED_TEAM_DEFAULT_REVISION,flag_namespace=self.flags,retain_native_references=True,effect_context=ctx)
|
|
def test_all13_exact_existing_relationships_and_default_closed(self):
|
|
ctx=self.context()
|
|
for i in self.f['safe_ids']:
|
|
r=self.records(i);p=self.proof(r,ctx);ref.verify(r['source'],r['basic'],r['sparse'],self.schema,ctx,p);self.assertFalse(p['spell_definition_or_execution_support_added']);self.assertEqual(p['new_or_changed_relationships'],0)
|
|
self.assertFalse(self.compose([self.records()])['added']);out=self.compose([self.records(i)for i in self.f['safe_ids']],ctx);self.assertFalse(out['held']);self.assertEqual(len(out['accepted'])+len(out['already_exact']),13)
|
|
def test_sentinel_cooldown_difference_never_normalized(self):
|
|
r=self.records(self.f['sentinel_difference_id'])
|
|
with self.assertRaisesRegex(ValueError,'fields differ'):self.proof(r,self.context())
|
|
out=self.compose([r],self.context());self.assertFalse(out['added']);self.assertTrue(out['held'])
|
|
def test_extra_missing_duplicate_conditional_specialized_and_orphan_slots_rejected(self):
|
|
for mutation in ('extra','missing','duplicate','condition','specialization','charges','spell','trigger','category','ppm','orphan'):
|
|
r=self.records();effects=copy.deepcopy(self.f['effects']);links=copy.deepcopy(self.f['links']);link=next(x for x in links if x['ItemID']==r['source']['entry']);effect=next(x for x in effects if x['ID']==link['ItemEffectID'])
|
|
if mutation in('extra','duplicate'):
|
|
e=copy.deepcopy(effect);e['ID']=999999;e['LegacySlotIndex']=1 if mutation=='extra'else 0;effects.append(e);links.append(dict(ID=999999,ItemID=r['source']['entry'],ItemEffectID=e['ID']))
|
|
elif mutation=='missing':links.remove(link)
|
|
elif mutation=='ppm':r['source']['spellppmrate_1']=1
|
|
elif mutation=='orphan':r['source']['spellcharges_2']=-1
|
|
else:effect[dict(condition='PlayerConditionID',specialization='ChrSpecializationID',charges='Charges',spell='SpellID',trigger='TriggerType',category='SpellCategoryID')[mutation]]+=1
|
|
ctx=self.context(effects=effects,links=links)
|
|
with self.subTest(mutation=mutation),self.assertRaises(ValueError):self.proof(r,ctx)
|
|
out=self.compose([r],ctx);self.assertFalse(out['added']);self.assertTrue(out['held'])
|
|
def test_effective_published_replacement_and_tombstone_are_honored(self):
|
|
r=self.records();package=self.package();link=next(x for x in self.f['links']if x['ItemID']==r['source']['entry']);effect=next(x for x in self.f['effects']if x['ID']==link['ItemEffectID']);record={k:v for k,v in effect.items()if k!='ID'};record['Charges']+=1;raw=sparse.encode(record,self.schemas['ItemEffect']);package['rows'].append(dict(table_name='ItemEffect',table_hash=hex(TABLES['ItemEffect'][0]),id=effect['ID'],record=record,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest()))
|
|
with self.assertRaises(ValueError):self.proof(r,self.context(package))
|
|
package=self.package();package['rows'].append(dict(table_name='ItemXItemEffect',table_hash=hex(TABLES['ItemXItemEffect'][0]),id=link['ID'],record_status='removed'))
|
|
with self.assertRaises(ValueError):self.proof(r,self.context(package))
|
|
def test_invalid_rows_wires_and_stale_proof_or_context_are_rejected(self):
|
|
for mutation in ('duplicate','bool','missing'):
|
|
effects=copy.deepcopy(self.f['effects']);links=copy.deepcopy(self.f['links'])
|
|
if mutation=='duplicate':effects.append(copy.deepcopy(effects[0]))
|
|
elif mutation=='bool':effects[0]['PlayerConditionID']=False
|
|
elif mutation=='missing':del effects[0]['SpellID']
|
|
with self.assertRaises(ValueError):self.context(effects=effects,links=links)
|
|
links=copy.deepcopy(self.f['links']);r=self.records();next(x for x in links if x['ItemID']==r['source']['entry'])['ItemEffectID']=999999;ctx=self.context(links=links)
|
|
with self.assertRaisesRegex(ValueError,'no native/published effect'):self.proof(r,ctx)
|
|
self.assertTrue(self.compose([r],ctx)['held'])
|
|
r=self.records();ctx=self.context();proof=self.proof(r,ctx);proof['complete_effect_slots'][0]['effect']['Charges']+=1
|
|
with self.assertRaises(ValueError):ref.verify(r['source'],r['basic'],r['sparse'],self.schema,ctx,proof)
|
|
ctx['package_push_id']='stale'
|
|
with self.assertRaises(ValueError):self.compose([r],ctx)
|
|
def test_source_flags_scripts_and_skills_stay_guarded_and_inputs_immutable(self):
|
|
ctx=self.context();rs=[self.records()];before=copy.deepcopy((ctx,rs));out=self.compose(rs,ctx);self.assertEqual((ctx,rs),before);self.assertEqual(out['rows'][:1],self.package()['rows']);self.assertEqual(out['package']['pushes'],sparse.package_pages(out['rows']));self.assertTrue(all(x['table_name']=='ItemSparse'for x in out['added']))
|
|
for field,value in [('flags',0x40),('script_name','custom'),('required_skill',164)]:
|
|
r=self.records();r['source'][field]=value;out=self.compose([r],ctx);self.assertFalse(out['added']);self.assertTrue(out['held'])
|
|
if __name__=='__main__':unittest.main()
|