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

75 lines
5.2 KiB
Python

"""Retain the complete, source-proven single-aura instant-companion family.
Committed filtered source/native snapshots make regeneration independent of
private runtime files. This produces masks only, never aura state or mechanics.
"""
import copy,hashlib,json,re,struct
from pathlib import Path
from aura_definition_profile import generate,SCALAR_HEADER_PINS
ROOT=Path(__file__).resolve().parents[1]
FOLDER=ROOT/'docs/evidence/content-data/aura-instant-companion-restoration-20261021'
def reviewed_companion_extension(base):
def load(name):return json.loads((FOLDER/name).read_text())
proof=load('manifest.json')
for name,digest in proof['input_sha256'].items():
assert Path(name).name==name
assert hashlib.sha256((FOLDER/name).read_bytes()).hexdigest()==digest
assert proof['kind']=='retained-source-instant-companion-aura-mask-family-v1'
names={'source-aura':'source_auras','target-aura':'target_auras','source-effect':'source_defines','target-effect':'target_defines'}
namespace=load('named-semantics.json');assert set(namespace)==set(names)
for role,semantics in namespace.items():
assert semantics['header_sha256']==SCALAR_HEADER_PINS[names[role]]
expected={'SPELL_AURA_MOD_STUN':12,'SPELL_AURA_MOD_STAT':29,'SPELL_AURA_MOD_DECREASE_SPEED':33,'SPELL_AURA_MOD_MELEE_HASTE':138}if role.endswith('aura')else{'SPELL_EFFECT_APPLY_AURA':6,'SPELL_EFFECT_SCHOOL_DAMAGE':2,'SPELL_EFFECT_HEAL':10,'SPELL_EFFECT_ENERGIZE':30}
assert semantics['symbols']==expected
for symbol,value in expected.items():assert any(re.search(r'\b'+symbol+r'\s*=\s*'+str(value)+r'\s*,',line)for line in semantics['source_lines'])
source=load('source-shapes.json');native=load('native-effect-identities.json')
capture=load('source-field-capture.json')
assert capture['source_sha256']==proof['source_spell_dbc_sha256']
magic,count,fields,size,strings=struct.unpack('<4s4I',bytes.fromhex(capture['dbc_header_hex']))
assert (magic,count,fields,size)==(b'WDBC',28019,173,692)
assert capture['field_indices']==[0,61,91,62,92,63,93]
assert capture['field_names']==['entry','effect1','effectApplyAuraName1','effect2','effectApplyAuraName2','effect3','effectApplyAuraName3']
restored=[dict(zip(capture['field_names'],struct.unpack('<7I',bytes.fromhex(row['selected_u32le_hex']))))for row in capture['rows']]
assert restored==source and len({r['row_index']for r in capture['rows']})==len(source)
assert all(0<=r['row_index']<count and r['entry']==s['entry']for r,s in zip(capture['rows'],source))
assert len(source)==proof['selected_source_rows']==855
assert len(native)==proof['selected_native_identity_rows']==1027
ids={r['entry']for r in source}
package=json.loads((ROOT/'docs/evidence/data/item-sparse-compat/package.json').read_text())
native_ids={r['ID']for r in native}
overlays=[r for r in package['rows']if r['table_name']=='SpellEffect'and (r['id']in native_ids or r.get('record',{}).get('SpellID',r.get('source_spell_id'))in ids)]
assert overlays==load('published-effect-overlays.json') # New overrides require explicit family revalidation.
effective={r['ID']:r for r in native}
for row in overlays:
if row.get('record_status','valid')=='removed':effective.pop(row['id'],None)
else:
assert row['record']['ID']==row['id']
effective[row['id']]=row['record']
family=generate(source,list(effective.values()),instant_companions=True)
assert len(family['definitions'])==852
assert {r['spell']for r in family['excluded']}==set(proof['negative_controls'])
retained=load('retained-mask-baseline.json');by_id={r['spell']:r for r in base}
assert len(by_id)==len(base)==1107
assert [(r['spell'],r['active_flags'])for r in base]==[(r['spell'],r['active_flags'])for r in retained]
added=[]
for row in family['definitions']:
if row['spell']in by_id:assert by_id[row['spell']]['active_flags']==row['active_flags']
else:added.append(row);by_id[row['spell']]=row
assert added==load('restored-definitions.json')and len(added)==344
assert {kind:sum(r['aura_type']==kind for r in added)for kind in(12,29,33,138)}=={12:217,29:7,33:120,138:0}
# Prove namespace/index/ambiguity guards also apply to this retained family.
sample=next(r for r in source if r['entry']==1715)
matches=[r for r in effective.values()if(r['SpellID'],r['EffectIndex'],r['DifficultyID'])==(1715,1,0)]
assert len(matches)==1 and generate([sample],matches,instant_companions=True)['definitions'][0]['active_flags']==2
assert not generate([sample],matches*2,instant_companions=True)['definitions']
for field in('Effect','EffectAura','EffectIndex','DifficultyID'):
bad=copy.deepcopy(matches);bad[0][field]+=1
assert not generate([sample],bad,instant_companions=True)['definitions']
bad=copy.deepcopy(sample);bad['effect3']=6
assert not generate([bad],matches,instant_companions=True)['definitions']
assert not generate([sample],matches)['definitions'] # This family stays explicit opt-in.
result=[by_id[k]for k in sorted(by_id)]
assert len(result)==1451 and all(by_id[r['spell']]['active_flags']==r['active_flags']for r in retained)
return result