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

84 lines
4.8 KiB
Python

#!/usr/bin/env python3
"""One new qualified-texture receipt/stage boundary; no old asset checks."""
import argparse
import copy
import hashlib
import json
from pathlib import Path
import sys
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from item_model_assets import stage_registered
def check(job):
load=lambda p:json.loads(p.read_text())
pin=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
parameters=load(job/'Source28-receipt-stage-inputs.json')
source=Path(parameters['source']);conversion=Path(parameters['conversion'])
parent=Path(parameters['baseline']);native=Path(parameters['native_root'])
output=Path(parameters['output']);receipt=Path(parameters['validated_texture_receipt'])
candidate_paths=set(parameters['Source28_payload_files'])
forbidden=set(parameters['Source180_parent_payload_files'])
original_read=Path.read_bytes;reads={};raw_inputs={}
def guarded_read(path):
name=str(path.resolve())
assert name not in forbidden,'Existing180 texture body unexpectedly read'
raw=original_read(path)
if name in candidate_paths:
reads[name]=reads.get(name,0)+1;raw_inputs[name]=raw
return raw
arguments=dict(frozen_parent_manifest_sha256=parameters['baseline_sha256'],
validated_texture_receipt=receipt,
validated_texture_receipt_sha256=parameters['validated_texture_receipt_sha256'])
with patch.object(Path,'read_bytes',guarded_read),patch('octo_icon_assets.decode_blp',side_effect=AssertionError('Accepted texture decode repeated')):
result=stage_registered(source,conversion,parent,native,output,**arguments)
assert len(result['assets'])==9344 and len(result['validated_texture_decodes_reused'])==28
assert len(reads)==28 and all(n==1 for n in reads.values())
before=load(parent);old={r['path']:r for r in before['assets']};new={r['path']:r for r in result['assets']}
assert all(new[p]==row for p,row in old.items())
delta=[row for p,row in new.items()if p not in old];assert len(delta)==28
source_rows=load(source)['matches'];source_by_sha={row['sha256']:row for row in source_rows}
for row in delta:
src=source_by_sha[row['sha256']];expected=raw_inputs[str((source.parent/src['file']).resolve())]
actual=(output/row['file']).read_bytes()
assert actual==expected and len(actual)==row['bytes']
assert hashlib.md5(actual).hexdigest()==row['content_key']==src['content_key']
# Changed receipt/payload cases are the only refusals exercised here.
refused=[]
def reject(label,src=source,conv=conversion,**changes):
opts=dict(arguments,**changes);target=job/('refused-'+label)
try:stage_registered(src,conv,parent,native,target,**opts)
except ValueError as error:refused.append(dict(case=label,reason=str(error)))
else:raise AssertionError('Changed texture proof accepted: '+label)
assert not target.exists()
reject('receipt-pin',validated_texture_receipt_sha256='0'*64)
bad=load(receipt);first=source_rows[0]
next(r for r in bad['rows']if r['source_path']==first['member'])['content_key']='0'*32
bad_path=job/'changed-receipt-control.json';bad_path.write_text(json.dumps(bad)+'\n')
reject('receipt-tuple',validated_texture_receipt=bad_path,validated_texture_receipt_sha256=pin(bad_path))
bad_dir=job/'changed-payload-control';bad_dir.mkdir()
raw=raw_inputs[str((source.parent/first['file']).resolve())]
(bad_dir/first['file']).write_bytes(bytes([raw[0]^1])+raw[1:])
bad_source=bad_dir/'source.json';bad_source.write_text(json.dumps(dict(matches=[copy.deepcopy(first)]))+'\n')
bad_conversion=bad_dir/'conversion.json';bad_conversion.write_text(json.dumps(dict(source_manifest_sha256=pin(bad_source),records=[]))+'\n')
reject('payload-SHA',src=bad_source,conv=bad_conversion)
assert 'Asset bytes changed'in refused[-1]['reason']
report=dict(status='PASS_NEW28_PINNED_TEXTURE_RECEIPT_STAGE_AND_REFUSALS',
staged_total=9344,new_texture_payloads=28,reused_accepted_decodes=28,
unchanged9316_asset_identities_exact=True,Source180_payload_reads=0,
Source28_input_reads=28,Source208_decoder_repeated=False,
actual_file_SHA_guard_retained=True,refusals=refused,
candidate_manifest=str(output/'manifest.json'),
candidate_manifest_sha256=pin(output/'manifest.json'),
Native_SDK_or_Game_acceptance=False)
(job/'completed-new28-texture-receipt-focused-check.json').write_text(json.dumps(report,indent=2)+'\n')
return report
if __name__=='__main__':
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--job',type=Path,required=True)
args=parser.parse_args();check(args.job)
print('PASS:28 pinned decodes reused; actual payload guards/refusals; no180body reads.')