883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
106 lines
11 KiB
Python
106 lines
11 KiB
Python
"""Generic composer: real set modifier captures, synthetic masks/icon I/O."""
|
|
import copy,hashlib,json,sys,unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import content_package_stage as stage
|
|
import spell_set_modifier_compat as modifier
|
|
import spell_passive_compat as codec
|
|
import spell_item_skill_compat_test as common
|
|
from octo_client_data import canonical_sha256
|
|
|
|
class SetModifierPackage(unittest.TestCase):
|
|
def fixture(self,sources=None,*,high_bit=False):
|
|
f=json.loads((ROOT/'tests/fixtures/source-set-modifiers.json').read_text());sources=copy.deepcopy(f['sources']if sources is None else sources)
|
|
v=list(common.ItemSkillDefinitionTest().fixture());schemas=f['schemas'];maxima={t:1500000 for t in schemas};inventory={'source':[],'target':{}}
|
|
for family in {s['class_family']['target_id']for s in sources}:
|
|
mask=0
|
|
for s in sources:
|
|
if s['class_family']['target_id']==family:
|
|
for fallback in s['source_effect_affect_fallbacks']:mask|=fallback
|
|
bits=[i for i in range(64)if mask&(1<<i)];inventory['target'][str(family)]=[]
|
|
# Every source class member, including an unaffected control, has a stable
|
|
# same-ID target witness. Source bit positions are intentionally changed.
|
|
for n,bit in enumerate(bits+[next(i for i in range(64)if not mask&(1<<i))]):
|
|
ident=60000+family*100+n;inventory['source'].append(dict(id=ident,family=family,mask=1<<bit));inventory['target'][str(family)].append(dict(SpellID=ident,SpellClassSet=family,SpellClassMask=[0,0x80000000 if high_bit and n==0 else 1<<n,0,0]))
|
|
tables=v[7]['source_tables'];del tables['SkillLine'];tables['SpellIcon']=SimpleNamespace(by_id={s['spellIconId']:[s['spellIconId'],1]for s in sources},string=lambda _:'interface/icons/temp.blp')
|
|
snapshot=dict(kind='local-read-only-exact-set-modifier-affect-snapshot',named_columns=['entry','effectId','SpellFamilyMask'],equal=True,mutated=False,first_sha256='a'*64,second_sha256='a'*64,spell_ids=[s['entry']for s in sources],rows=[])
|
|
c=modifier.new_component(sources,v[3],schemas,maxima,v[6],source_tables=tables,target_icon_names=v[7]['target_icon_names'],new_icon_ids={str(s['entry']):136235 for s in sources},icon_assets=v[7]['icon_assets'],read_icon=v[7]['read_icon'],modifier_namespace=f['namespace'],affect_inventory=inventory,source_affect_snapshot=snapshot)
|
|
metadata=codec.TABLES|codec.SUPPLEMENTAL_TABLES;c['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=maxima[t],allocation_bound=maxima[t])for t in {r['table_name']for r in c['records']}}
|
|
record=dict(ID=1,Name_lang='Unrelated preserved item-set fixture');wire=codec.encode(record,schemas['SpellName']);rows=[dict(table_name='SpellName',table_hash=hex(metadata['SpellName'][0]),id=1,record=record,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())];base=dict(build=codec.BUILD,schema=codec.SCHEMA,id_remapping=False,rows=rows,push_id=stage.package_payloads(rows)[0]);before={str(s['entry']):dict(infoStatus='nil',nameStatus='nil',descriptionStatus='nil')for s in sources}
|
|
return base,[c],{t:schemas[t]for t in c['native_tables']},before
|
|
def encode_changed(self,row,schemas):
|
|
wire=codec.encode(row['record'],schemas[row['table_name']]);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
|
|
def test_actual_source_classes_flat_percent_and_multiple_effects_compose(self):
|
|
args=self.fixture();before=copy.deepcopy(args);r=stage.compose_definition_candidates(*args);self.assertEqual(args,before);self.assertEqual(r['rows'][0],args[0]['rows'][0]);self.assertEqual(r['source_spell_ids'],[41199,41361,51775]);self.assertEqual(r['added_count'],len(args[1][0]['records']));self.assertFalse(r['installable']);self.assertFalse(r['engine_accepted'])
|
|
self.assertEqual({x['record']['SpellClassSet']for x in r['rows']if x['table_name']=='SpellClassOptions'},{4,6,11});self.assertEqual({x['record']['EffectAura']for x in r['rows']if x['table_name']=='SpellEffect'},{107,108})
|
|
def test_all_nine_named_classes_are_routed_only_by_the_new_policy(self):
|
|
f=json.loads((ROOT/'tests/fixtures/source-set-modifiers.json').read_text());sources=[]
|
|
for name,family in modifier.FAMILIES.items():
|
|
s=copy.deepcopy(f['sources'][0]);s['entry']=610000+family;s['class_family'].update(name=name,source_id=family,target_id=family);sources.append(s)
|
|
args=self.fixture(sources);r=stage.compose_definition_candidates(*args);self.assertEqual(len(r['source_spell_ids']),9);self.assertEqual({x['record']['SpellClassSet']for x in r['rows']if x['table_name']=='SpellClassOptions'},set(range(3,12)))
|
|
def test_recomposition_is_idempotent_and_keeps_the_original_row(self):
|
|
args=self.fixture();r=stage.compose_definition_candidates(*args);args[0].update(rows=r['rows'],push_id=r['push_id']);again=stage.compose_definition_candidates(*args);self.assertEqual(again['added_count'],0);self.assertEqual(again['rows'],r['rows'])
|
|
def test_unsigned_derived_high_bit_keeps_exact_signed_schema_bit_pattern(self):
|
|
args=self.fixture(high_bit=True);r=stage.compose_definition_candidates(*args);effects=[row for row in r['rows']if row['table_name']=='SpellEffect'];self.assertTrue(any(e['record']['EffectSpellClassMask'][1]<0 for e in effects))
|
|
for row in effects:
|
|
metadata=next(s for s in args[1][0]['spells']if s['spell_id']==row['source_spell_id']);mapping=metadata['affect_mappings'][str(row['record']['EffectIndex'])]
|
|
self.assertEqual([word&0xffffffff for word in row['record']['EffectSpellClassMask']],mapping['target_mask'])
|
|
changed=next(row for row in args[1][0]['records']if row['table_name']=='SpellEffect');changed['record']['EffectSpellClassMask'][1]=0x7fffffff;self.encode_changed(changed,args[2])
|
|
with self.assertRaises(ValueError):stage.compose_definition_candidates(*args)
|
|
def test_nonzero_source_levels_require_the_exact_neutral_level_child(self):
|
|
f=json.loads((ROOT/'tests/fixtures/source-set-modifiers.json').read_text());sources=copy.deepcopy(f['sources']);sources[0]['levels']=dict(spellLevel=55,baseLevel=55,maxLevel=0)
|
|
args=self.fixture(sources);r=stage.compose_definition_candidates(*args);level=next(x for x in r['rows']if x['table_name']=='SpellLevels');self.assertEqual((level['record']['SpellLevel'],level['record']['BaseLevel']),(55,55))
|
|
row=next(x for x in args[1][0]['records']if x['table_name']=='SpellLevels');row['record']['MaxPassiveAuraLevel']=1;self.encode_changed(row,args[2])
|
|
with self.assertRaises(ValueError):stage.compose_definition_candidates(*args)
|
|
def test_actual_native_absence_and_unverified_status_guards_remain_required(self):
|
|
for key in('positive','missing-status','learned','installed','wrong-policy','legacy-kind'):
|
|
args=self.fixture();c=args[1][0]
|
|
if key=='positive':args[3]['41199']['infoStatus']='ok'
|
|
elif key=='missing-status':del args[3]['41199']['nameStatus']
|
|
elif key=='learned':c['spells'][0]['known_spells_modified']=True
|
|
elif key=='installed':c['installed']=True
|
|
elif key=='wrong-policy':c['definition_policy']='unreviewed-set-modifier'
|
|
else:c['kind']='source-flat-modifier-definition-candidates'
|
|
with self.assertRaises(ValueError,msg=key):stage.compose_definition_candidates(*args)
|
|
def test_named_namespace_snapshot_and_full_identity_inventory_are_rechecked(self):
|
|
for key in('operation','source-affect-proof','snapshot-scope','duplicate-override','missing-target','collateral-target','forged-mapping'):
|
|
args=self.fixture();c=args[1][0];s=c['spells'][0];family=str(s['class_family']['target_id'])
|
|
if key=='operation':c['modifier_namespace']['operations'][0]['target_name']='Doses'
|
|
elif key=='source-affect-proof':c['source_affect_snapshot']['second_sha256']='b'*64
|
|
elif key=='snapshot-scope':c['source_affect_snapshot']['spell_ids'].remove(s['spell_id'])
|
|
elif key=='duplicate-override':c['source_affect_snapshot']['rows']=[dict(entry=s['spell_id'],effect_index=0,source_mask=1)]*2
|
|
elif key=='missing-target':c['affect_inventory']['target'][family].pop(0)
|
|
elif key=='collateral-target':c['affect_inventory']['target'][family][-1]['SpellClassMask']=c['affect_inventory']['target'][family][0]['SpellClassMask'][:]
|
|
else:s['affect_mappings']['0']['target_mask']=[127,0,0,0]
|
|
with self.assertRaises(ValueError,msg=key):stage.compose_definition_candidates(*args)
|
|
def test_zero_own_class_masks_source_metadata_and_conditions_are_enforced(self):
|
|
for key in('source-mask','target-mask','class-copy','levels-copy','source-hash','proc','unreviewed-attribute'):
|
|
args=self.fixture();s=args[1][0]['spells'][0];src=s['source_definition']
|
|
if key in('source-mask','target-mask'):
|
|
src['class_family']['source_mask'if key=='source-mask'else'target_mask'][0]=1;s['class_family']=copy.deepcopy(src['class_family'])
|
|
elif key=='class-copy':s['class_family']['target_id']=3
|
|
elif key=='levels-copy':s['levels']['baseLevel']=1
|
|
elif key=='source-hash':s['source_record_sha256']='0'*64
|
|
elif key=='proc':src['conditions']['procFlags']=1
|
|
else:src['attributes'][0]|=512
|
|
if key!='source-hash':s['source_record_sha256']=canonical_sha256(src)
|
|
with self.assertRaises(ValueError,msg=key):stage.compose_definition_candidates(*args)
|
|
def test_every_reencoded_row_field_is_compared_with_source_semantics(self):
|
|
cases=[('SpellName','Name_lang','Wrong set bonus'),('Spell','Description_lang','Incorrect bonus'),('SpellMisc','Attributes',[192]+[0]*16),('SpellMisc','SchoolMask',4),('SpellMisc','DurationIndex',1),('SpellEquippedItems','EquippedItemClass',4),('SpellClassOptions','SpellClassMask',[1,0,0,0]),('SpellClassOptions','ModalNextSpell',1),('SpellEffect','EffectAura',42),('SpellEffect','EffectBasePointsF',99),('SpellEffect','EffectMiscValue',[31,0]),('SpellEffect','EffectSpellClassMask',[127,0,0,0]),('SpellEffect','Coefficient',1)]
|
|
for table,key,value in cases:
|
|
args=self.fixture();row=next(r for r in args[1][0]['records']if r['table_name']==table and r['source_spell_id']==41199);self.assertNotEqual(row['record'][key],value);row['record'][key]=value;self.encode_changed(row,args[2])
|
|
with self.assertRaises(ValueError,msg=table+'.'+key):stage.compose_definition_candidates(*args)
|
|
def test_missing_effect_class_child_and_extra_unreviewed_rows_are_rejected(self):
|
|
for key in('effect','class','wrong-schema','wrong-registry','extra-aura-options','wrong-slot'):
|
|
args=self.fixture();c=args[1][0]
|
|
if key in('effect','class'):c['records'].remove(next(r for r in c['records']if r['table_name']==('SpellEffect'if key=='effect'else'SpellClassOptions')))
|
|
elif key=='wrong-schema':c['native_tables']['SpellEffect']['layout_hash']='0x1234'
|
|
elif key=='wrong-registry':c['child_id_registry']['SpellEffect']['41199:0']+=1
|
|
elif key=='wrong-slot':next(r for r in c['records']if r['table_name']=='SpellEffect')['source_effect_index']=2
|
|
else:
|
|
row=copy.deepcopy(c['records'][0]);row['table_name']='SpellAuraOptions';c['records'].append(row)
|
|
with self.assertRaises(ValueError,msg=key):stage.compose_definition_candidates(*args)
|
|
|
|
if __name__=='__main__':unittest.main()
|