883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
63 lines
5.7 KiB
Python
63 lines
5.7 KiB
Python
"""Source-owned texture ID, complete gender family and staged ROOT contracts."""
|
|
from pathlib import Path
|
|
import copy,hashlib,io,json,struct,sys,unittest
|
|
from PIL import Image
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import item_source_body_resources as m
|
|
|
|
class SourceBodyResourcesTest(unittest.TestCase):
|
|
def inputs(self,equal=False,unisex=False):
|
|
native=[dict(ID=i,FileDataID=i,UsageType=0,MaterialResourcesID=43844)for i in(162713,162712)]+[dict(ID=143079,FileDataID=143079,UsageType=0,MaterialResourcesID=21515)];components=[dict(ID=i,GenderIndex=g,ClassID=0,RaceID=0)for i,g in((162713,0),(162712,1))];paths=['item/texturecomponents/torsouppertexture/tabard_a_01_tu_'+g+'.blp'for g in(('u',)if unisex else('m','f'))];assets=[];matches=[];blobs={}
|
|
for n,path in enumerate(paths):
|
|
b=io.BytesIO();Image.new('P',(4,4),1 if equal else n+1).save(b,format='BLP');raw=b.getvalue();pin=hashlib.sha256(raw).hexdigest();p='wowhybrid/source-equipment/'+pin+'.blp';matches.append(dict(member=path,sha256=pin,bytes=len(raw)))
|
|
if p not in blobs:assets.append(dict(path=p,file_data_id=18000000+len(assets),kind='texture',bytes=len(raw),sha256=pin,content_key=hashlib.md5(raw).hexdigest()));blobs[p]=raw
|
|
source=json.dumps(dict(kind='batch-source-equipment-resource-candidates',matches=matches,conflicting_candidates={})).encode();ids=sorted(a['file_data_id']for a in assets);keys={a['file_data_id']:a['content_key']for a in assets};deltas=[i-(ids[n-1]+1 if n else 0)for n,i in enumerate(ids)];root=struct.pack('<6I',0x4d465354,24,2,len(ids),0,0)+struct.pack('<4IB',len(ids),127990,0,0x12000000,6)+struct.pack('<'+'I'*len(ids),*deltas)+b''.join(bytes.fromhex(keys[i])for i in ids);registered=dict(kind='source-equipment-registered-root-stage',source_manifest_sha256=hashlib.sha256(source).hexdigest(),root=dict(staged_root_md5=hashlib.md5(root).hexdigest()),assets=assets,registry=dict(slots={a['path']:a['file_data_id']for a in assets}));return source,registered,root,[paths],native,components,blobs
|
|
def run_stage(self,args,registry=None):return m.source_body_rows(*args[:6],lambda a:args[6][a['path']],registry)
|
|
def test_new_complete_pair_preserves_inputs_and_stable_allocation(self):
|
|
args=self.inputs();before=copy.deepcopy(args);out=self.run_stage(args);self.assertEqual(args,before);self.assertEqual(len(out['rows']),4);self.assertEqual(out,self.run_stage(args,out['registry']));self.assertEqual({r['record']['GenderIndex']for r in out['rows']if r['table_name']=='ComponentTextureFileData'},{0,1});self.assertTrue(out['publication_required'])
|
|
def test_equal_male_female_content_has_one_exact_unisex_resource(self):
|
|
args=self.inputs(equal=True);out=self.run_stage(args);self.assertEqual(len(args[1]['assets']),1);self.assertEqual(len(out['rows']),1);self.assertEqual(out['rows'][0]['table_name'],'TextureFileData');self.assertEqual(out['bindings'][0]['mode'],'unisex')
|
|
self.assertEqual(len(self.run_stage(self.inputs(unisex=True))['rows']),1)
|
|
def test_source_conflict_missing_or_incomplete_pair_is_blocked(self):
|
|
for change in('missing-gender','wrong-stem','duplicate-gender','source-conflict','source-missing'):
|
|
args=list(self.inputs())
|
|
if change=='missing-gender':args[3][0].pop()
|
|
elif change=='wrong-stem':args[3][0][1]=args[3][0][1].replace('01','02')
|
|
elif change=='duplicate-gender':args[3][0][1]=args[3][0][0]
|
|
else:
|
|
source=json.loads(args[0]);row=source['matches'][0]
|
|
if change=='source-conflict':source['matches'].append(dict(row,sha256='0'*64))
|
|
else:source['matches'].pop()
|
|
args[0]=json.dumps(source).encode();args[1]['source_manifest_sha256']=hashlib.sha256(args[0]).hexdigest()
|
|
with self.subTest(change=change),self.assertRaises(ValueError):self.run_stage(args)
|
|
def test_asset_bytes_root_manifest_or_id_registry_cannot_drift(self):
|
|
for change in('bytes','source-pin','root-pin','root-key','fileid','asset-hash'):
|
|
args=list(self.inputs());a=args[1]['assets'][0]
|
|
if change=='bytes':args[6][a['path']]+=b'changed'
|
|
elif change=='source-pin':args[1]['source_manifest_sha256']='0'*64
|
|
elif change=='root-pin':args[1]['root']['staged_root_md5']='0'*32
|
|
elif change=='root-key':args[2]=args[2][:-16]+bytes(16);args[1]['root']['staged_root_md5']=hashlib.md5(args[2]).hexdigest()
|
|
elif change=='fileid':a['file_data_id']+=100
|
|
else:a['sha256']='0'*64
|
|
with self.subTest(change=change),self.assertRaises(ValueError):self.run_stage(args)
|
|
def test_existing_complete_source_group_reuses_without_replacement(self):
|
|
args=self.inputs();out=self.run_stage(args)
|
|
for r in out['rows']:args[4 if r['table_name']=='TextureFileData'else 5].append(r['record'])
|
|
reused=self.run_stage(args);self.assertFalse(reused['rows']);self.assertEqual(reused['bindings'][0]['material_resource_id'],43845)
|
|
def test_partial_extra_or_specialized_existing_family_and_registry_are_rejected(self):
|
|
for change in('partial','extra','race','class','gender','registry-bool','registry-collision','control'):
|
|
args=self.inputs();out=self.run_stage(args);registry=None
|
|
if change.startswith('registry'):
|
|
registry=copy.deepcopy(out['registry']);key=next(iter(registry['slots']))
|
|
if change=='registry-bool':registry['slots'][key]=True
|
|
else:registry['slots']['other']=registry['slots'][key]
|
|
elif change=='control':args[5][0]['GenderIndex']=1
|
|
else:
|
|
for r in out['rows']:
|
|
if change=='partial'and r['id']==18000001:continue
|
|
args[4 if r['table_name']=='TextureFileData'else 5].append(copy.deepcopy(r['record']))
|
|
if change=='extra':args[4].append(dict(ID=999,FileDataID=999,UsageType=0,MaterialResourcesID=43845))
|
|
elif change in('race','class','gender'):args[5][-1][{'race':'RaceID','class':'ClassID','gender':'GenderIndex'}[change]]+=1
|
|
with self.subTest(change=change),self.assertRaises(ValueError):self.run_stage(args,registry)
|
|
if __name__=='__main__':unittest.main()
|