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

334 lines
22 KiB
Python

#!/usr/bin/env python3
"""Exact local DB2/WDBC-backed isolated request translation; no live creation."""
import copy
from dataclasses import replace
import json
from pathlib import Path
import struct
import sys
import unittest
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import character_creation as c
FIXTURE=json.loads((Path(__file__).parent/'fixtures/character_creation_tauren_70334.json').read_text())
def schema(data=None):
data=FIXTURE if data is None else data
return c.AppearanceSchema(data['conversions'],data['choices'],data['sections'],data['facial_hair'],data['hair_geosets'])
def encode(request):
name=request.name.encode();surname=request.surname.encode()
bits=(len(name)<<18)|(int(request.template_set is not None)<<17)|(int(request.trial_boost)<<16)
bits|=(int(request.use_npe)<<15)|(int(request.hardcore_self_found)<<14)|(request.unknown_bits<<12)
bits|=(len(surname)<<6)|request.padding_bits
result=bits.to_bytes(3,'big')+struct.pack('<BBB I i i',request.race,request.cls,request.sex,len(request.customizations),request.unknown_word,request.timerunning_season)
result+=name+surname
if request.template_set is not None:result+=struct.pack('<i',request.template_set)
return result+b''.join(struct.pack('<II',*pair) for pair in request.customizations)
class CharacterCreation(unittest.TestCase):
@classmethod
def setUpClass(cls):cls.schema=schema()
def test_source_registered_sdk_inherits_only_selection_bound_additive_child(self):
parent='a'*32;child='b'*32;old_build='c'*32;new_build='d'*32;store='/tmp/source-parent-store'
indexes=[dict(bucket=i,generation=1,file=f'{i:02x}00000001.idx',
relative=f'Data/data/{i:02x}00000001.idx',preserved_preimage=f'/tmp/{i:02x}.idx',
bytes=100,sha256='e'*64) for i in range(16)]
lineage={
'root_delta':dict(status='PRIVATE_ALIAS',parent_root=parent,candidate_root=child,
root_audit=dict(original_root_md5=parent,staged_root_md5=child,
original_groups_bit_identical=True,new_records=1),
assets=[dict(file_data_id=200,content_key='f'*32)]),
'framing':dict(status='PASS_FRAMED_PRIVATE',parent_root=parent,root=dict(content_key=child),
new_asset_count=1,new_physical_texture_frames=0,
encoding_audit=dict(original_entries_preserved=True,all_original_content_key_encoding_bindings_preserved=True),
download_audit=dict(original_entry_bytes_preserved=True,original_tag_bits_preserved=True),
tvfs_child_audit=dict(all_original_path_offsets_preserved=True,CFT_VFS_ESpec_bytes_and_offsets_exact=True,
aliases=[dict(file_data_id=200,content_key='f'*32)]),
tvfs_parent_audit=dict(all_other_path_offsets_preserved=True)),
'cow':dict(kind='independent-cow-native-casc-candidate',logical_parent_root=parent,independent_cow_data=True,
existing_index_generations_preserved=True,parent_index_preimages_preserved_independently_of_native_pruning=True,
new_objects_routed_by_exact_index_prefix_absence=True,parent_index_files=indexes,
new_index_generations=[dict(old_file='0000000001.idx',original_sha256='e'*64,original_entries_bit_identical=True)],
parent_store=store,original_build_config=old_build,new_build_config=new_build),
'child_selection':dict(status='PASS_CHILD_STORE_BUILD_CONFIG_BINDS_SELECTED_ROOT',parent_root=parent,candidate_root=child,
parent_build_key=old_build,candidate_build_key=new_build,parent_store=store),
'parent_handoff':dict(candidate_root=parent,candidate_build_key=old_build,candidate_store=store)}
self.schema._source_registered_additive_lineage(lineage,parent,child,{101})
proof=dict(status='PASS_PARENT_SDK',candidate_root=parent,mismatch_count=0,requested=1,returned=1)
sdk=[dict(file_data_id=101,known=True,full_info_available=True,resolved_file_data_id=101,
content_key='9'*32,content_size=100)]
wrapped=self.schema.prepare_source_registered_additive_receipt(lineage,proof,sdk,candidate_root=child)
self.schema._source_registered_additive_receipt(wrapped,proof,sdk,child)
bad_receipt=copy.deepcopy(wrapped);bad_receipt['receipt']['child_root']='0'*32
with self.assertRaises(ValueError):self.schema._source_registered_additive_receipt(bad_receipt,proof,sdk,child)
bad_sdk=copy.deepcopy(sdk);bad_sdk[0]['content_key']='0'*32
with self.assertRaises(ValueError):self.schema._source_registered_additive_receipt(wrapped,proof,bad_sdk,child)
bad=copy.deepcopy(lineage);bad['root_delta']['assets'][0]['file_data_id']=101
with self.assertRaises(ValueError):self.schema._source_registered_additive_lineage(bad,parent,child,{101})
bad=copy.deepcopy(lineage);bad['framing']['tvfs_child_audit']['aliases'][0]['content_key']='0'*32
with self.assertRaises(ValueError):self.schema._source_registered_additive_lineage(bad,parent,child,{101})
bad=copy.deepcopy(lineage);bad['cow']['new_index_generations'][0]['original_sha256']='0'*64
with self.assertRaises(ValueError):self.schema._source_registered_additive_lineage(bad,parent,child,{101})
bad=copy.deepcopy(lineage);bad['parent_handoff']['candidate_store']='/tmp/other-parent'
with self.assertRaises(ValueError):self.schema._source_registered_additive_lineage(bad,parent,child,{101})
bad=copy.deepcopy(lineage);bad['child_selection']['candidate_root']='0'*32
with self.assertRaises(ValueError):self.schema._source_registered_additive_lineage(bad,parent,child,{101})
def test_source_skin_face_registered_fdis_and_rejections(self):
root='1'*32
entries=[('body.blp',101,'a','d',100),('lower.blp',102,'b','e',101),
('upper.blp',103,'c','f',102)]
textures=[dict(source_member=path,content_key=ck*32,sha256=sha*64,bytes=size)
for path,_,ck,sha,size in entries]
assets=[dict(file_data_id=ident,content_key=ck*32,sha256=sha*64,bytes=size,
source_members=[dict(member=path)]) for path,ident,ck,sha,size in entries]
sdk=[dict(file_data_id=ident,known=True,full_info_available=True,resolved_file_data_id=ident,
content_key=ck*32,content_size=size) for _,ident,ck,_,size in entries]
proof=dict(status='PASS_SOURCE_SDK',candidate_root=root,mismatch_count=0,requested=3,returned=3)
relation=dict(race=9,sex=0,skin=1,face=3,status='source_qualified',
body=dict(textures=[textures[0],None,None]),
face_section=dict(textures=[textures[1],textures[2],None]))
call=lambda rel,asset_rows,sdk_rows,selected_root: self.schema.source_skin_face_registered_associations(
rel,asset_rows,sdk_rows,proof,candidate_root=selected_root)
result=call([relation],assets,sdk,root)
self.assertEqual(result['relationships'][0]['status'],'source_associated')
self.assertEqual([x['file_data_id'] for x in result['relationships'][0]['textures']],[101,102,103])
self.assertFalse(result['native_material_selected'])
self.assertFalse(result['actor_customization_selected'])
self.assertFalse(result['runtime_accepted'])
with self.assertRaisesRegex(ValueError,'SDK proof'):
call([relation],assets,sdk,'0'*32)
bad_sdk=copy.deepcopy(sdk);bad_sdk[0]['content_key']='0'*32
with self.assertRaisesRegex(ValueError,'SDK identity differs'):
call([relation],assets,bad_sdk,root)
duplicate=copy.deepcopy(assets);duplicate[1]['file_data_id']=duplicate[0]['file_data_id']
with self.assertRaisesRegex(ValueError,'Duplicate registered Source selector'):
call([relation],duplicate,sdk,root)
missing=copy.deepcopy(relation);missing['face_section']['textures'][0]['content_key']='0'*32
self.assertEqual(call([missing],assets,sdk,root)['relationships'][0]['status'],'held')
def test_source_skin_face_texture_batch_preserves_flags_and_holds(self):
def row(ident,sex,section,variation,color,flags,textures):
return dict(id=ident,race=10,sex=sex,section=section,variation=variation,color=color,flags=flags,textures=textures)
rows=[row(1,1,0,0,0,0,['body0.blp','glow.blp','']),
row(2,1,0,0,0,1,['body1.blp','glow.blp','']),
row(3,1,1,0,0,0,['lower0.blp','upper0.blp','']),
row(4,1,1,0,0,1,['lower1.blp','upper1.blp','']),
row(5,1,1,1,0,0,['lower0.blp','upper0.blp','']),
row(6,1,1,1,0,0,['lower0.blp','upper0.blp','']),
row(7,0,0,0,0,0,['male.blp','glow.blp','']),
row(8,0,1,0,0,0,['lower0.blp','upper0.blp',''])]
data=copy.deepcopy(FIXTURE);data['sections']=[{k:v for k,v in r.items() if k!='textures'} for r in rows]
index=schema(data)
def identity(name,n):
return dict(source_member=name.upper(),status='MATCH',current_ckey=f'{n:032x}',current_sha256=f'{n:064x}',current_bytes=100)
identities=[identity(name,n) for n,name in enumerate(('body0.blp','glow.blp','lower0.blp','upper0.blp','lower1.blp','upper1.blp','male.blp'),1)]
batch=index.source_skin_face_texture_relationships(rows,identities,race=10)
by_key={(r['sex'],r['skin'],r['face']):r for r in batch['relationships']}
self.assertEqual(by_key[(1,0,0)]['status'],'source_qualified')
self.assertEqual(by_key[(0,0,0)]['body']['record_id'],7)
self.assertEqual(by_key[(1,1,0)]['body']['flags'],1)
self.assertIn('unverified_body_texture_slot_0',by_key[(1,1,0)]['reasons'])
self.assertIn('ambiguous_face_row',by_key[(1,0,1)]['reasons'])
self.assertIn('missing_face_row',by_key[(1,1,1)]['reasons'])
self.assertFalse(batch['native_material_selected'])
conflict=identities+[identity('body0.blp',99)]
held=index.source_skin_face_texture_relationships(rows,conflict,race=10)
self.assertIn('ambiguous_body_texture_slot_0',next(r for r in held['relationships'] if (r['sex'],r['skin'],r['face'])==(1,0,0))['reasons'])
with self.assertRaisesRegex(ValueError,'differ from appearance section index'):
index.source_skin_face_texture_relationships(rows[:-1],identities,race=10)
def test_source_section_flag_index_preserves_clear_and_flagged_colors(self):
data=copy.deepcopy(FIXTURE)
data['sections']=[];data['facial_hair']=[];data['hair_geosets']=[]
for sex in (0,1):
for ident,section,color,flags in ((1,0,0,0),(2,0,0,1),(3,1,0,0),(4,1,1,0),(5,3,0,0)):
data['sections'].append(dict(id=100+sex*10+ident,race=32,sex=sex,section=section,variation=0,color=color,flags=flags))
data['facial_hair'].append(dict(race=32,sex=sex,variation=0))
data['hair_geosets'].append(dict(race=32,sex=sex,variation=0))
index=schema(data)
for sex in (0,1):
self.assertTrue(index.source_valid(32,sex,(0,0,0,0,0)))
self.assertTrue(index.source_valid(32,sex,(1,0,0,0,0)))
self.assertFalse(index.source_valid(32,sex,(2,0,0,0,0)))
def base(self):return bytes.fromhex(FIXTURE['cases'][0]['native_packet_hex'])
def native(self):return c.parse_native(c.NATIVE_CREATE,self.base())
def forward(self,appearance,sex=0):
result={}
for (race,row_sex,choice),relations in self.schema.relations.items():
if (race,row_sex)==(6,sex) and any(appearance[f-1]==v and (not d or appearance[d-1]==dv) for f,v,d,dv in relations):
option=self.schema.choices[choice]
if option in result and result[option]!=choice:raise ValueError('fixture forward collision')
result[option]=choice
return tuple(sorted(result.items()))
def test_actual_db2_wdbc_tauren_priest_positive_packet_oracles(self):
for case in FIXTURE['cases']:
with self.subTest(appearance=case['source_appearance'],sex=case['sex']):
result=c.translate_native(c.NATIVE_CREATE,bytes.fromhex(case['native_packet_hex']),self.schema,[(6,1),(6,5)])
self.assertEqual(result.opcode,0x36)
self.assertEqual(result.body.hex(),case['source_packet_hex'])
self.assertEqual(result.appearance,tuple(case['source_appearance']))
self.assertEqual(result.body[:7],b'Taurea\0')
self.assertEqual(result.body[-4:],bytes(4))
def test_skin_dependent_face_is_solved_simultaneously(self):
case=FIXTURE['cases'][1]
native=c.parse_native(c.NATIVE_CREATE,bytes.fromhex(case['native_packet_hex']))
self.assertEqual(self.schema.resolve(native),(1,2,3,1,2))
dependent=[r for r in FIXTURE['conversions'] if r['ChrRacesID']==6 and r['Sex']==0 and r['OptionID']==2 and r['Data']==2 and r['DependentOptionID']==1 and r['DependentData']==1]
self.assertTrue(dependent)
def test_class_does_not_rewrite_tauren_model_appearance(self):
request=self.native();warrior=replace(request,cls=1)
priest=c.translate_native(c.NATIVE_CREATE,encode(request),self.schema,[(6,1),(6,5)])
other=c.translate_native(c.NATIVE_CREATE,encode(warrior),self.schema,[(6,1),(6,5)])
self.assertEqual(priest.appearance,other.appearance)
self.assertEqual(priest.body[:8],other.body[:8])
self.assertEqual(priest.body[8],5);self.assertEqual(other.body[8],1)
def test_actual_native_legacy_feature0_7_collision_held(self):
request=replace(self.native(),customizations=self.forward((0,0,0,0,0)))
self.assertEqual(self.forward((0,0,0,0,0)),self.forward((0,0,0,0,7)))
with self.assertRaises(c.UnsupportedCreation):self.schema.resolve(request)
def test_new_character_only_canonical_zero_exact_native_equivalence(self):
request=replace(self.native(),customizations=self.forward((0,0,0,0,0)))
with self.assertRaises(c.UnsupportedCreation):self.schema.resolve(request)
result=c.translate_native(c.NATIVE_CREATE,encode(request),self.schema,[(6,5)])
self.assertEqual(result.appearance,(0,0,0,0,0))
self.assertEqual(result.body,b'Taurea\0'+bytes((6,5,0,0,0,0,0,0,0))+bytes(4))
def test_new_canonical_zero_requires_complete_native_forward_output(self):
full=self.forward((0,0,0,0,0))
request=replace(self.native(),customizations=tuple(p for p in full if p[0]!=73))
with self.assertRaises(c.UnsupportedCreation):
c.translate_native(c.NATIVE_CREATE,encode(request),self.schema,[(6,5)])
def test_new_canonical_zero_never_invents_missing_source_zero(self):
data=copy.deepcopy(FIXTURE)
data['facial_hair']=[r for r in data['facial_hair'] if not(r['race']==6 and r['sex']==0 and r['variation']==0)]
request=replace(self.native(),customizations=self.forward((0,0,0,0,0)))
result=c.translate_native(c.NATIVE_CREATE,encode(request),schema(data),[(6,5)])
self.assertEqual(result.appearance,(0,0,0,0,7))
def test_new_creation_keeps_other_inverse_ambiguities_held(self):
request=replace(self.native(),customizations=self.forward((0,0,0,0,0)))
for mutation in ['third-feature','different-feature-pair','other-source-field','different-forward']:
data=copy.deepcopy(FIXTURE);rows=data['conversions']
if mutation=='third-feature':
additions=[dict(r,ID=100000+r['ID'],Data=8) for r in rows if r['Sex']==0 and r['OptionID']==5 and r['Data']==7]
rows.extend(additions)
elif mutation=='different-feature-pair':
for r in rows:
if r['Sex']==0 and r['OptionID']==5 and r['Data']==7:r['Data']=6
elif mutation=='other-source-field':
additions=[dict(r,ID=100000+r['ID'],Data=1) for r in rows if r['Sex']==0 and r['OptionID']==2 and r['Data']==0]
rows.extend(additions)
else:
data['choices'].append({'ID':999999,'ChrCustomizationOptionID':999999})
r=next(r for r in rows if r['Sex']==0 and r['OptionID']==5 and r['Data']==7)
rows.append(dict(r,ID=999999,ChrCustomizationChoiceID=999999))
with self.subTest(mutation=mutation),self.assertRaises(c.UnsupportedCreation):
c.translate_native(c.NATIVE_CREATE,encode(request),schema(data),[(6,5)])
def test_native_skin_without_source_charsections_held(self):
request=replace(self.native(),customizations=self.forward((24,0,0,0,1)))
with self.assertRaises(c.UnsupportedCreation):self.schema.resolve(request)
def test_incomplete_request_never_defaults_missing_classic_fields(self):
request=self.native()
for choices in [(),request.customizations[:1]]:
with self.subTest(choices=choices),self.assertRaises(c.UnsupportedCreation):
self.schema.resolve(replace(request,customizations=choices))
def test_wrong_race_sex_choice_is_not_aliased(self):
request=self.native()
for changed in [replace(request,race=1),replace(request,sex=1)]:
with self.subTest(changed=changed),self.assertRaises(c.UnsupportedCreation):self.schema.resolve(changed)
def test_native_option_parent_mismatch_and_unknown_choice_held(self):
request=self.native();choices=list(request.customizations)
for pair in [(999999,choices[0][1]),(choices[0][0],999999)]:
with self.subTest(pair=pair),self.assertRaises(c.UnsupportedCreation):
self.schema.resolve(replace(request,customizations=tuple([pair]+choices[1:])))
def test_source_geoset_and_facial_require_actual_variation_rows(self):
for table,variation in [('facial_hair',1),('hair_geosets',0)]:
data=copy.deepcopy(FIXTURE);data[table]=[r for r in data[table] if not(r['race']==6 and r['sex']==0 and r['variation']==variation)]
with self.subTest(table=table),self.assertRaises(c.UnsupportedCreation):schema(data).resolve(self.native())
def test_source_pair_eligibility_is_required(self):
with self.assertRaises(c.UnsupportedCreation):c.translate_native(c.NATIVE_CREATE,self.base(),self.schema,[(6,1)])
def test_advanced_native_modes_are_explicitly_held(self):
request=self.native()
for key,value in [('surname','Other'),('template_set',0),('trial_boost',True),('use_npe',True),('hardcore_self_found',True),('unknown_bits',1),('timerunning_season',1),('unknown_word',0)]:
changed=replace(request,**{key:value})
with self.subTest(field=key),self.assertRaises(c.UnsupportedCreation):
c.translate_native(c.NATIVE_CREATE,encode(changed),self.schema,[(6,5)])
def test_source_ui_control_surname_is_normalized_exactly(self):
original=self.native()
control=replace(original,surname='Control')
normal=c.translate_native(c.NATIVE_CREATE,encode(original),self.schema,[(6,5)])
result=c.translate_native(c.NATIVE_CREATE,encode(control),self.schema,[(6,5)])
self.assertEqual(result.body,normal.body)
self.assertEqual(result.native.surname,'')
self.assertEqual(c.parse_native(c.NATIVE_CREATE,encode(control)).surname,'Control')
def test_named_reference_header_layout(self):
# Reference source records a real70009 header08 00 80 for "Df"/"Df".
request=replace(self.native(),name='Df',surname='Df')
body=encode(request);self.assertEqual(body[:3],bytes.fromhex('080080'))
result=c.parse_native(c.NATIVE_CREATE,body)
self.assertEqual((result.name,result.surname),('Df','Df'))
def test_padding_is_ignored_like_original_ResetBitPos(self):
request=replace(self.native(),padding_bits=63)
self.assertEqual(c.parse_native(c.NATIVE_CREATE,encode(request)).customizations,request.customizations)
def test_optional_template_field_and_following_choices_parse_exactly(self):
request=replace(self.native(),template_set=123)
parsed=c.parse_native(c.NATIVE_CREATE,encode(request))
self.assertEqual(parsed.template_set,123);self.assertEqual(parsed.customizations,request.customizations)
def test_all_truncations_and_tail_rejected(self):
body=self.base()
for end in range(len(body)):
with self.subTest(end=end),self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,body[:end])
with self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,body+b'\0')
def test_actual_opcode_namespace_only(self):
for opcode in [0x430070,0x36,True,0]:
with self.subTest(opcode=opcode),self.assertRaises(ValueError):c.parse_native(opcode,self.base())
def test_customization_count_bound_and_duplicate_options(self):
raw=bytearray(self.base());struct.pack_into('<I',raw,6,251)
with self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,bytes(raw))
request=self.native();changed=replace(request,customizations=request.customizations+(request.customizations[0],))
with self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,encode(changed))
def test_nul_utf8_and_gender_framing(self):
request=self.native()
with self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,encode(replace(request,name='Ta\0rea')))
raw=bytearray(self.base());raw[18]=255
with self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,bytes(raw))
with self.assertRaises(ValueError):c.parse_native(c.NATIVE_CREATE,encode(replace(request,sex=2)))
def test_table_discriminator_and_choice_parent_remain_strict(self):
for field,value in [('Field_3_4_0_45166_007',0),('ChrCustomizationChoiceID',999999),('Data',256),('DependentOptionID',2)]:
data=copy.deepcopy(FIXTURE);data['conversions'][0][field]=value
with self.subTest(field=field),self.assertRaises(ValueError):schema(data)
def test_signed_sex_minus1_is_held_not_guessed_both_sexes(self):
data=copy.deepcopy(FIXTURE);data['conversions'][0]['Sex']=-1
result=schema(data);self.assertEqual(len(result.held_conversion_rows),1)
self.assertNotIn((6,-1,data['conversions'][0]['ChrCustomizationChoiceID']),result.relations)
if __name__=='__main__':unittest.main()