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

187 lines
25 KiB
Python

"""Native icon staging: real encoders/root structure; no engine acceptance claim."""
import copy,hashlib,io,json,struct,sys,tempfile,unittest
from unittest.mock import patch
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'tests')]
from PIL import Image
from item_icon_native_assets import stage,compose_icon_references,compose_reused_icon_rebase,verify_installed_icon_dependency
from item_sparse_compat import package_payloads,package_pages
from item_basic_compat import record,encode
from item_basic_compat_test import source,icon
from item_batch_stage import source_hash
from casc_asset_package import allocate_asset_ids,extend_existing_root_groups
def write(path,data):path.write_text(json.dumps(data));return hashlib.sha256(path.read_bytes()).hexdigest()
class Icons(unittest.TestCase):
def setUp(self):
self.tmp=tempfile.TemporaryDirectory(dir=ROOT/'runtime');self.addCleanup(self.tmp.cleanup);self.w=Path(self.tmp.name);self.cat=self.w/'catalogue';self.art=self.w/'artwork';self.base=self.w/'baseline'
for p in(self.cat,self.art,self.art/'assets',self.base):p.mkdir()
image=Image.new('P',(8,8));image.putpalette([0,0,0]*256);stream=io.BytesIO();image.save(stream,format='BLP');self.raw=stream.getvalue();sha=hashlib.sha256(self.raw).hexdigest();key=hashlib.md5(self.raw).hexdigest()
native=struct.pack('<6I',0x4d465354,24,2,2,0,0)+struct.pack('<4IB',2,127990,0,0x12000000,6)+struct.pack('<2I',100,142978)+b'a'*16+b'b'*16;(self.w/'native-root.bin').write_bytes(native)
path='wowhybrid/previous.blp';registry=allocate_asset_ids(native,[path]);self.prior=dict(path=path,kind='texture',file='previous.blp',file_data_id=registry['slots'][path],bytes=len(self.raw),sha256=sha,content_key=key,native_group_control=143079)
updated,audit=extend_existing_root_groups(native,[{k:self.prior[k]for k in('path','file_data_id','content_key','native_group_control')}],expected_root_md5=hashlib.md5(native).hexdigest());(self.base/'root.bin').write_bytes(updated);(self.base/'previous.blp').write_bytes(self.raw);write(self.base/'manifest.json',dict(kind='source-equipment-registered-root-stage',root=audit,registry=registry,assets=[self.prior],models=[]))
items=[];rows=[]
for ident in(1000,1001,1002):
p=source(ident);r=record(p,icon_evidence=icon(p));r['record']['IconFileDataID']=0 if ident!=1002 else 134400;wire=encode(r['record']);r.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest());rows.append(r);items.append(dict(entry=ident,source=p,source_record_sha256=source_hash(p),icon=dict(normalized_source=dict(path='interface/icons/inv_fixture'))))
package=dict(build='1.60.1.70334',schema='wowstatic_camelot_1_60_1',id_remapping=False,rows=rows);package.update(push_id=package_payloads(rows)[0],pushes=package_pages(rows));write(self.w/'package.json',package)
pin=write(self.cat/'items-0000.json',items);self.catalogue=dict(kind='source-item-catalogue-conversion',build='1.60.1.70334',files=[dict(path='items-0000.json',sha256=pin)]);write(self.cat/'manifest.json',self.catalogue)
path='interface/icons/gw_test.blp';pin=write(self.art/'item-icons.json',dict(kind='source-item-icon-map',items={str(i):path for i in(1000,1001,1002)}));self.texture=self.art/'assets'/(sha+'.blp');self.texture.write_bytes(self.raw);write(self.art/'manifest.json',dict(kind='source-icon-artwork-batch',files=[dict(path='item-icons.json',sha256=pin)],assets=[dict(path=path,file='assets/'+sha+'.blp',sha256=sha,bytes=len(self.raw))],source_icons=[dict(source_icon='interface/icons/inv_fixture',path=path,sha256=sha)]))
def invoke(self,name='output'):return stage(self.w/'package.json',self.cat,self.art,self.base/'manifest.json',self.w/'native-root.bin',self.w/name)
def test_shared_icon_deduplication_and_prior_positive_references_preserved(self):
r=self.invoke();self.assertEqual(len(r['assets']),1);self.assertEqual(r['new_icon_assets'],0);self.assertEqual({x['item_id']for x in r['source_icon_bindings']},{1000,1001});self.assertEqual({x['file_data_id']for x in r['source_icon_bindings']},{self.prior['file_data_id']});self.assertFalse(r['source_icon_blocked'])
prior=next(x for x in r['assets']if x['path']==self.prior['path']);self.assertEqual(prior['file_data_id'],self.prior['file_data_id']);self.assertEqual((self.w/'output'/prior['file']).read_bytes(),self.raw)
def test_shared_texture_decoded_once_and_change_during_batch_held(self):
import item_icon_native_assets as tool
original=tool.decode_blp
with patch.object(tool,'decode_blp',wraps=original)as decoder:
result=self.invoke()
self.assertEqual(decoder.call_count,1)
self.assertEqual({x['item_id']for x in result['source_icon_bindings']},{1000,1001})
def mutate(raw):
result=original(raw);self.texture.write_bytes(raw+b'x');return result
with patch.object(tool,'decode_blp',side_effect=mutate):
with self.assertRaisesRegex(ValueError,'No source-backed'):self.invoke('changed')
self.assertFalse((self.w/'changed').exists())
def test_explicit_positive_replacement_requires_source_and_exact_old_id(self):
baseline=json.loads((self.base/'manifest.json').read_text());baseline['assets'][0]['kind']='icon';write(self.base/'manifest.json',baseline)
package=json.loads((self.w/'package.json').read_text());p=source(1003);unmatched=record(p,icon_evidence=icon(p))
same=next(row for row in package['rows']if row['id']==1001);same['record']['IconFileDataID']=self.prior['file_data_id'];wire=encode(same['record']);same.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
unmatched['record']['IconFileDataID']=134401;wire=encode(unmatched['record']);unmatched.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest());package['rows'].append(unmatched)
package.update(push_id=package_payloads(package['rows'])[0],pushes=package_pages(package['rows']));write(self.w/'package.json',package)
out=self.w/'replacement';report=stage(self.w/'package.json',self.cat,self.art,self.base/'manifest.json',self.w/'native-root.bin',out,replace_existing=True)
bindings={row['item_id']:row for row in report['source_icon_bindings']};self.assertEqual(set(bindings),{1000,1002})
self.assertEqual([row['item_id']for row in report['source_icon_unchanged']],[1001])
self.assertEqual(bindings[1002]['old_icon_file_data_id'],134400);self.assertEqual(bindings[1002]['file_data_id'],self.prior['file_data_id'])
self.assertEqual(report['new_icon_assets'],0);self.assertEqual([row['item_id']for row in report['source_icon_blocked']],[1003])
with self.assertRaisesRegex(ValueError,'prior icon references'):compose_icon_references(self.w/'package.json',out)
composed,audit=compose_icon_references(self.w/'package.json',out,replace_existing=True)
old={row['id']:row for row in package['rows']};new={row['id']:row for row in composed['rows']}
self.assertEqual(new[1002]['record']['IconFileDataID'],self.prior['file_data_id']);self.assertEqual(new[1003],old[1003]);self.assertEqual(new[1001],old[1001]);self.assertEqual(audit['positive_icons_replaced'],1)
for ident in(1000,1002):
before=dict(old[ident]['record']);after=dict(new[ident]['record']);before.pop('IconFileDataID');after.pop('IconFileDataID');self.assertEqual(before,after)
manifest=json.loads((out/'manifest.json').read_text());next(row for row in manifest['source_icon_bindings']if row['item_id']==1002)['old_icon_file_data_id']=134399;write(out/'manifest.json',manifest)
with self.assertRaisesRegex(ValueError,'prior icon references'):compose_icon_references(self.w/'package.json',out,replace_existing=True)
def test_rebased_saved_bindings_preserve_root_and_do_not_read_payloads(self):
registered=self.invoke();bindings=registered['source_icon_bindings'];assets=[r for r in registered['assets'] if r['file_data_id'] in {b['file_data_id'] for b in bindings}]
for binding in bindings:binding['source_artwork_sha256']=assets[0]['sha256']
frozen=self.w/'frozen.json';frozen_pin=write(frozen,dict(new_assets=assets,source_icon_bindings=bindings))
output=self.w/'output';audit=registered['root'];package_pin=hashlib.sha256((self.w/'package.json').read_bytes()).hexdigest()
manifest=dict(kind='source-icon-rebased-root-candidate-v1',frozen_source_manifest_sha256=frozen_pin,current_package_sha256=package_pin,source_icon_positive_replacement=True,parent_root=audit['original_root_md5'],candidate_root=audit['staged_root_md5'],root_audit=audit,assets=assets,source_icon_bindings=bindings)
write(output/'manifest.json',manifest)
original=Path.read_bytes
def no_blp(path):
if path.suffix.lower()=='.blp':raise AssertionError('frozen icon payload reread')
return original(path)
with patch.object(Path,'read_bytes',no_blp):
result,report=compose_reused_icon_rebase(self.w/'package.json',output,frozen,expected_package_sha256=package_pin,expected_frozen_sha256=frozen_pin)
self.assertEqual(report['items'],2);self.assertEqual(report['textures'],1);self.assertEqual(report['asset_bodies_read'],0)
rows={r['id']:r for r in result['rows']};self.assertTrue(rows[1000]['native_icon_registration_pending']);self.assertEqual(rows[1000]['record']['IconFileDataID'],self.prior['file_data_id']);self.assertEqual(rows[1002]['record']['IconFileDataID'],134400)
with self.assertRaisesRegex(ValueError,'Explicit pending icon rebase required'):
verify_installed_icon_dependency(result,self.w/'client')
# Only the exact verified UI-only descendant may satisfy this dependency.
child='f'*32;ui_key='b'*32;body_sha='a'*64;client=self.w/'client';raw=('root = '+child+'\n').encode();key=hashlib.md5(raw).hexdigest();config=client/'Data/config'/key[:2]/key[2:4]/key;config.parent.mkdir(parents=True);config.write_bytes(raw)
frame=self.w/'child-frame.json';sdk=self.w/'icon-sdk.json';ui=self.w/'ui-sdk.json';readback=self.w/'ui-readback.log';readback.write_text('strict readback')
frame_pin=write(frame,dict(parent_root=audit['staged_root_md5'],root=dict(content_key=child),registered_asset_count=3,root_audit=dict(all_other_root_bytes_identical=True,changes=[dict(file_data_id=8209459,new_content_key=ui_key)])))
sdk_pin=write(sdk,dict(status='PASS_2188_ICON_AND_TWO_UI_FDI_CKEYS',candidate_root=audit['staged_root_md5'],mismatches=[]));ui_pin=write(ui,[dict(file_data_id=8209459,known=True,full_info_available=True,content_key=ui_key)])
receipt=self.w/'child-receipt.json';receipt_pin=write(receipt,dict(status='PRIVATE_COMBINED_COW_SELECTED_UI_SDK_PASSED_NOT_INSTALLED',parent_root=audit['staged_root_md5'],candidate_root=child,candidate_build_config=key,registered_asset_count=3,ui_file_data_id=8209459,ui_content_key=ui_key,ui_body_sha256=body_sha,frame_manifest=str(frame),accepted_icon_sdk_receipt=str(sdk),ui_sdk_selector=str(ui),ui_strict_readback=str(readback)))
pending=result['pending_native_icon_rebase'];pending.update(asset_framing_complete=True,manifest_directory=str(output.relative_to(ROOT)),effective_combined_root=child,combined_ui_child_receipt=str(receipt),combined_ui_child_receipt_sha256=receipt_pin,combined_ui_content_key=ui_key,combined_ui_body_sha256=body_sha,evidence=dict(combined_frame=dict(path=str(frame),sha256=frame_pin),icon_sdk=dict(path=str(sdk),sha256=sdk_pin),combined_ui_sdk=dict(path=str(ui),sha256=ui_pin),combined_ui_readback=dict(path=str(readback),sha256=hashlib.sha256(readback.read_bytes()).hexdigest())))
with patch('client_installation.inspect_installation',return_value=dict(build_key=key)):
accepted=verify_installed_icon_dependency(result,client)
self.assertTrue(accepted['installed_root_dependency_verified']);self.assertFalse(accepted['engine_rendering_verified'])
# The new batch must not silently bypass an inherited icon requirement.
oldroot='e'*32;oldbinding=dict(item_id=1002,file_data_id=134400,source_record_sha256=rows[1002]['source_record_sha256']);oldmanifest=self.w/'old-icons.json';oldpin=write(oldmanifest,dict(root=dict(staged_root_md5=oldroot),source_icon_bindings=[oldbinding]));old_sdk=self.w/'old-sdk.json';old_sdk_pin=write(old_sdk,dict(status='PASS_841_PRIOR_ITEM_SELECTORS_AND_459_FDI_CKEYS',combined_root=child,prior_manifest_sha256=oldpin,current_icon_manifest_sha256=hashlib.sha256((output/'manifest.json').read_bytes()).hexdigest(),prior_items=1,distinct_fdis=1,new_override_count=0,held_count=0,mismatches=[]))
result['required_native_icon_assets']=dict(kind='source-registered-native-item-icons-v1',manifest_sha256=oldpin,root_md5=oldroot,item_ids=[1002],file_data_ids=[134400]);pending['evidence'].update(prior_icon_manifest=dict(path=str(oldmanifest),sha256=oldpin),prior_icon_sdk=dict(path=str(old_sdk),sha256=old_sdk_pin))
with patch('client_installation.inspect_installation',return_value=dict(build_key=key)):
self.assertTrue(verify_installed_icon_dependency(result,client)['installed_root_dependency_verified'])
rows[1002]['record']['IconFileDataID']=0
with self.assertRaisesRegex(ValueError,'Prior item icon metadata differs'):verify_installed_icon_dependency(result,client)
rows[1002]['record']['IconFileDataID']=134400
other=b'root = '+b'0'*32+b'\n';other_key=hashlib.md5(other).hexdigest();other_config=client/'Data/config'/other_key[:2]/other_key[2:4]/other_key;other_config.parent.mkdir(parents=True);other_config.write_bytes(other)
with patch('client_installation.inspect_installation',return_value=dict(build_key=other_key)):
with self.assertRaisesRegex(ValueError,'descendant build is not installed'):verify_installed_icon_dependency(result,client)
frame.write_text('{}')
with patch('client_installation.inspect_installation',return_value=dict(build_key=key)):
with self.assertRaisesRegex(ValueError,'Descendant evidence changed'):verify_installed_icon_dependency(result,client)
manifest['source_icon_bindings'][0]['source_record_sha256']='0'*64;write(output/'manifest.json',manifest)
with self.assertRaisesRegex(ValueError,'identity or rebased ROOT'):
compose_reused_icon_rebase(self.w/'package.json',output,frozen,expected_package_sha256=package_pin,expected_frozen_sha256=frozen_pin)
def test_rebase_already_assigned_source_icons_requires_exact_prior_binding(self):
registered=self.invoke();bindings=registered['source_icon_bindings'];assets=[r for r in registered['assets'] if r['file_data_id'] in {b['file_data_id'] for b in bindings}]
for binding in bindings:binding['source_artwork_sha256']=assets[0]['sha256']
prior=[dict(binding,file_data_id=binding['file_data_id']+100) for binding in bindings]
frozen=self.w/'frozen-prior.json';frozen_pin=write(frozen,dict(new_assets=assets,source_icon_bindings=prior))
package=json.loads((self.w/'package.json').read_text());byid={r['id']:r for r in package['rows']}
for binding in prior:
row=byid[binding['item_id']];row['record']['IconFileDataID']=binding['file_data_id'];wire=encode(row['record']);row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
package.update(push_id=package_payloads(package['rows'])[0],pushes=package_pages(package['rows']));package_pin=write(self.w/'assigned-package.json',package)
audit=registered['root'];output=self.w/'output';manifest=dict(kind='source-icon-rebased-root-candidate-v1',frozen_source_manifest_sha256=frozen_pin,current_package_sha256=package_pin,source_icon_positive_replacement=True,parent_root=audit['original_root_md5'],candidate_root=audit['staged_root_md5'],root_audit=audit,assets=assets,source_icon_bindings=bindings);write(output/'manifest.json',manifest)
result,report=compose_reused_icon_rebase(self.w/'assigned-package.json',output,frozen,expected_package_sha256=package_pin,expected_frozen_sha256=frozen_pin,existing_source_binding=True)
self.assertEqual(report['items'],2);self.assertTrue(result['pending_native_icon_rebase']['existing_source_binding'])
self.assertEqual({r['record']['IconFileDataID'] for r in result['rows'] if r['id'] in (1000,1001)},{assets[0]['file_data_id']})
prior[0]['file_data_id']+=1;frozen_pin=write(frozen,dict(new_assets=assets,source_icon_bindings=prior));manifest['frozen_source_manifest_sha256']=frozen_pin;write(output/'manifest.json',manifest)
with self.assertRaisesRegex(ValueError,'prior icon references'):
compose_reused_icon_rebase(self.w/'assigned-package.json',output,frozen,expected_package_sha256=package_pin,expected_frozen_sha256=frozen_pin,existing_source_binding=True)
def test_ui_parent_icon_closure_requires_every_prior_selector(self):
registered=self.invoke();bindings=registered['source_icon_bindings'];assets=[r for r in registered['assets'] if r['file_data_id'] in {b['file_data_id'] for b in bindings}]
for b in bindings:b['source_artwork_sha256']=assets[0]['sha256']
old=[dict(b,file_data_id=b['file_data_id']+100) for b in bindings]
package=json.loads((self.w/'package.json').read_text());rows={r['id']:r for r in package['rows']}
kept=dict(item_id=1002,file_data_id=134400,old_icon_file_data_id=134400,source_record_sha256=rows[1002]['source_record_sha256']);old.append(kept)
frozen=self.w/'ui-parent-frozen.json';frozen_pin=write(frozen,dict(new_assets=assets,source_icon_bindings=old[:2]))
output=self.w/'output';audit=registered['root'];main=dict(kind='source-icon-rebased-root-candidate-v1',frozen_source_manifest_sha256=frozen_pin,current_package_sha256='a'*64,source_icon_positive_replacement=True,parent_root=audit['original_root_md5'],candidate_root=audit['staged_root_md5'],root_audit=audit,assets=assets,source_icon_bindings=bindings);main_pin=write(output/'manifest.json',main)
for b in bindings:rows[b['item_id']]['record']['IconFileDataID']=b['file_data_id'];rows[b['item_id']]['native_icon_asset_manifest_sha256']=main_pin
prior=self.w/'ui-parent-prior.json';prior_pin=write(prior,dict(root=dict(staged_root_md5='d'*32),source_icon_bindings=old));package['required_native_icon_assets']=dict(kind='source-registered-native-item-icons-v1',manifest_sha256=prior_pin,root_md5='d'*32,item_ids=sorted(b['item_id'] for b in old),file_data_ids=sorted({b['file_data_id'] for b in old}))
prior_proof=self.w/'ui-parent-prior-proof.json';write(prior_proof,dict(prior_manifest_sha256=prior_pin,prior_root='d'*32,retained_bindings=[kept],prior_root_content_keys={'134400':['e'*32]}))
residual_dir=self.w/'ui-parent-residual';residual_dir.mkdir();raw=(output/'root.bin').read_bytes();(residual_dir/'root.bin').write_bytes(raw);root=hashlib.md5(raw).hexdigest();residual=dict(kind='source-qualified-prior-icon-rebind-v1',parent_root=root,candidate_root=root,root_audit=dict(original_root_md5=root,staged_root_md5=root,original_group_order_preserved=True,original_id_and_content_key_prefixes_bit_identical=True),assets=[],bindings=[dict(item_id=1002,old_file_data_id=134400,file_data_id=134400,content_key='e'*32,source_record_sha256=kept['source_record_sha256'],method='preserved')]);residual_path=residual_dir/'manifest.json';residual_pin=write(residual_path,residual)
parent_raw=(self.w/'native-root.bin').read_bytes();parent_root=hashlib.md5(parent_raw).hexdigest();assert parent_root==main['parent_root'];(self.w/'ui-parent-root.bin').write_bytes(parent_raw)
parent_frame=self.w/'ui-parent-frame.json';write(parent_frame,dict(root=dict(content_key=parent_root,decoded_file='ui-parent-root.bin')))
main_frame=self.w/'ui-parent-main-frame.json';write(main_frame,dict(parent_root=parent_root,parent_manifest=str(parent_frame),root=dict(content_key=root),new_asset_count=1,source_rows=[dict(asset=dict(file_data_id=assets[0]['file_data_id'],content_key=assets[0]['content_key']))]))
residual_frame=self.w/'ui-parent-residual-frame.json';write(residual_frame,dict(parent_root=root,parent_manifest=str(main_frame),root=dict(content_key=root),new_asset_count=0,source_rows=[]))
extra_rows=[];extra_bindings=[];extra_fdi=800000
for ident in range(900000,900841):
s=source(ident);r=record(s,icon_evidence=icon(s));r['record']['IconFileDataID']=extra_fdi;extra_rows.append(r);extra_bindings.append(dict(item_id=ident,file_data_id=extra_fdi,source_record_sha256=r['source_record_sha256']))
package['rows']+=extra_rows;extra=self.w/'ui-parent-extra.json';extra_pin=write(extra,dict(assets=[dict(file_data_id=extra_fdi,content_key='f'*32)],source_icon_bindings=extra_bindings))
ui_ids={1967886,8209459,8560817,5612385,5613302};sdk_rows=[dict(file_data_id=i,known=True,content_key='c'*32) for i in ui_ids]+[dict(file_data_id=assets[0]['file_data_id'],known=True,content_key=assets[0]['content_key']),dict(file_data_id=134400,known=True,content_key='e'*32),dict(file_data_id=extra_fdi,known=True,content_key='f'*32)];sdk=self.w/'ui-parent-sdk.json';write(sdk,sdk_rows)
ui_receipt=self.w/'ui-parent-ui-sdk.json';write(ui_receipt,dict(status='FIVE_FILE_SDK_EXACT_MATCH_PRIVATE',candidate_root=parent_root,rows=[dict(file_data_id=i,exact_match=True) for i in ui_ids]))
assessment=self.w/'ui-parent-sdk-assessment.json';write(assessment,dict(status='PASS_MAIN_RESIDUAL_EXTRA_PRIOR_AND_FIVE_UI_CKEYS',candidate_root=root,main_assets=1,prior_bindings=1,extra_prior_bindings=841,ui_count=5,mismatches=[]))
client=self.w/'ui-parent-client';config=('root = '+root+'\n').encode();build=hashlib.md5(config).hexdigest();cfg=client/'Data/config'/build[:2]/build[2:4]/build;cfg.parent.mkdir(parents=True);cfg.write_bytes(config)
cow=self.w/'ui-parent-cow.json';write(cow,dict(logical_parent_root=root,new_build_config=build,new_framing_manifest=str(residual_frame),parent_index_files=[dict(bucket=i) for i in range(16)],parent_index_preimages_preserved_independently_of_native_pruning=True))
def ref(p):return dict(path=str(p),sha256=hashlib.sha256(p.read_bytes()).hexdigest())
evidence=dict(main_frame=ref(main_frame),prior_icon_manifest=ref(prior),frozen_source_manifest=ref(frozen),prior_root_proof=ref(prior_proof),prior_rebind_manifest=ref(residual_path),prior_rebind_frame=ref(residual_frame),final_cow_manifest=ref(cow),final_sdk=ref(sdk),final_sdk_assessment=ref(assessment),parent_ui_frame=ref(parent_frame),parent_ui_sdk=ref(ui_receipt),extra_prior_manifest=ref(extra))
package['pending_native_icon_rebase']=dict(kind='source-icon-rebased-root-candidate-v1',manifest_directory=str(output.relative_to(ROOT)),manifest_sha256=main_pin,parent_root=parent_root,candidate_root=root,asset_framing_complete=True,lineage_kind='ui-parent-icons-retained-v1',candidate_build_config=build,items=2,textures=1,extra_prior_items=841,extra_prior_manifest_sha256=extra_pin,evidence=evidence,prior_rebind=dict(manifest_sha256=residual_pin,parent_root=root,candidate_root=root,asset_framing_complete=True,items=1,changed_items=0,new_assets=0,existing_native_assets=0))
selectors={i:[dict(content_key='c'*32)] for i in ui_ids}
with patch('client_installation.inspect_installation',return_value=dict(build_key=build)),patch('item_icon_native_assets.root_controls_batch',return_value=selectors):
accepted=verify_installed_icon_dependency(package,client);self.assertEqual((accepted['items'],accepted['prior_items'],accepted['extra_prior_items']),(2,1,841))
bad=copy.deepcopy(package);bad['rows'][-1]['record']['IconFileDataID']=extra_fdi+1
with self.assertRaisesRegex(ValueError,'Additional prior icon selector differs'):verify_installed_icon_dependency(bad,client)
def test_source_payload_drift_is_not_published(self):
self.texture.write_bytes(self.raw+b'x')
with self.assertRaisesRegex(ValueError,'No source-backed'):self.invoke()
self.assertFalse((self.w/'output').exists())
def test_prior_assets_and_catalogue_pins_reject_changes(self):
(self.base/'previous.blp').write_bytes(self.raw+b'x')
with self.assertRaisesRegex(ValueError,'Prior registered asset'):self.invoke()
(self.base/'previous.blp').write_bytes(self.raw);(self.cat/'items-0000.json').write_text('[]')
with self.assertRaisesRegex(ValueError,'Catalogue chunk differs'):self.invoke()
def test_one_stale_item_does_not_hide_other_valid_icon_bindings(self):
p=json.loads((self.cat/'items-0000.json').read_text());p[0]['source_record_sha256']='0'*64;self.catalogue['files'][0]['sha256']=write(self.cat/'items-0000.json',p);write(self.cat/'manifest.json',self.catalogue);r=self.invoke()
self.assertEqual([x['item_id']for x in r['source_icon_bindings']],[1001]);self.assertEqual([x['item_id']for x in r['source_icon_blocked']],[1000])
def test_numeric_icon_references_require_registered_assets_and_matching_installed_root(self):
from unittest.mock import patch
registered=self.invoke();package,receipt=compose_icon_references(self.w/'package.json',self.w/'output')
self.assertEqual(receipt['items'],2);rows={r['id']:r for r in package['rows']};self.assertGreater(rows[1000]['record']['IconFileDataID'],0);self.assertEqual(rows[1000]['record']['IconFileDataID'],rows[1001]['record']['IconFileDataID']);self.assertEqual(rows[1002]['record']['IconFileDataID'],134400)
client=self.w/'client'
def config(root):
raw=('root = '+root+'\n').encode();key=hashlib.md5(raw).hexdigest();p=client/'Data/config'/key[:2]/key[2:4]/key;p.parent.mkdir(parents=True,exist_ok=True);p.write_bytes(raw);return key
key=config(registered['root']['staged_root_md5'])
with patch('client_installation.inspect_installation',return_value=dict(build_key=key)):
self.assertTrue(verify_installed_icon_dependency(package,client)['installed_root_dependency_verified'])
key=config('0'*32)
with patch('client_installation.inspect_installation',return_value=dict(build_key=key)):
with self.assertRaisesRegex(ValueError,'ROOT is not installed'):verify_installed_icon_dependency(package,client)
rows[1000]['record']['IconFileDataID']=999
with self.assertRaisesRegex(ValueError,'metadata differs'):verify_installed_icon_dependency(package,client)
if __name__=='__main__':unittest.main()