883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
110 lines
6.0 KiB
Python
110 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Focused original-golden integration and malformed-input boundary."""
|
|
import json
|
|
import struct
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
|
|
import map_asset_preflight as maps
|
|
BASE=Path(__file__).resolve().parents[1]
|
|
J=BASE/'runtime/continuation-20261026/combined57-map-integration/Root-global-TEX-relationship'
|
|
POLICY='native-tail-area1024-max64-v1'
|
|
|
|
|
|
class GlobalTexTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
pointers=J/'four-alternate-decoded-input-pointers.json'
|
|
if not pointers.exists():
|
|
raise unittest.SkipTest('Frozen original four BLP witnesses unavailable')
|
|
cls.blps={int(k):Path(v).read_bytes() for k,v in json.loads(pointers.read_text()).items()}
|
|
metadata=json.loads((J/'native34-selected-structure-private.json').read_text())
|
|
raw=(BASE/metadata['input']).read_bytes()
|
|
pos=0;table=None;payloads=[]
|
|
while pos<len(raw):
|
|
tag,size=struct.unpack_from('<4sI',raw,pos);data=raw[pos+8:pos+8+size]
|
|
if tag==b'TBXT':table=list(struct.iter_unpack('<III',data))
|
|
elif tag==b'DMXT':payloads.append(data)
|
|
pos+=8+size
|
|
wanted=[(r,body)for r,body in zip(table,payloads)if r[0]in cls.blps]
|
|
assert len(wanted)==4
|
|
cursor=0;rows=[];chunks=[]
|
|
for (ident,old_offset,packed),body in wanted:
|
|
rows.append(struct.pack('<III',ident,cursor,packed))
|
|
chunks.append(b'DMXT'+struct.pack('<I',len(body))+body)
|
|
cursor+=8+len(body)
|
|
cls.golden=(b'RVXT'+struct.pack('<II',4,1)
|
|
+b'TBXT'+struct.pack('<I',len(rows)*12)+b''.join(rows)+b''.join(chunks))
|
|
cls.first=cls.blps[127488]
|
|
|
|
def test_four_original_subset_byte_exact_and_sorted(self):
|
|
out,audit=maps.global_tex_mip_cache_candidate(dict(reversed(list(self.blps.items()))),native_tail_policy=POLICY)
|
|
self.assertEqual(out,self.golden)
|
|
self.assertEqual([r['file_data_id']for r in audit['rows']],sorted(self.blps))
|
|
self.assertEqual({r['format_byte']for r in audit['rows']},{0,16,130})
|
|
self.assertIn([16,64],[r['selected_dimensions']for r in audit['rows']])
|
|
self.assertFalse(audit['source_artwork_recompressed'])
|
|
O=BASE/'runtime/continuation-20261026/global-TEX-mip-cache-producer'
|
|
O.mkdir(exist_ok=True)
|
|
(O/'golden-four-original-subset.tex').write_bytes(self.golden)
|
|
(O/'actual-four-candidate.tex').write_bytes(out)
|
|
(O/'golden-four-audit.json').write_text(json.dumps(audit,indent=2)+'\n')
|
|
|
|
def test_malformed_selected_mip_ranges_and_extents_refused(self):
|
|
cases=[]
|
|
for field,value in [(12,0),(24,0),(88,1),(24,149),(24,len(self.first)+1)]:
|
|
raw=bytearray(self.first);struct.pack_into('<I',raw,field,value);cases.append(bytes(raw))
|
|
raw=bytearray(self.first);struct.pack_into('<I',raw,28,struct.unpack_from('<I',raw,28)[0]+1);cases.append(bytes(raw))
|
|
for body in cases:
|
|
with self.subTest(case=cases.index(body)), self.assertRaises(ValueError):
|
|
maps.global_tex_mip_cache_candidate({127488:body},native_tail_policy=POLICY)
|
|
|
|
def test_unsupported_format_identity_and_policy_refused(self):
|
|
cases=[]
|
|
for field,value in [(8,1),(9,4),(10,1)]:
|
|
raw=bytearray(self.first);raw[field]=value;cases.append(bytes(raw))
|
|
for body in cases:
|
|
with self.assertRaises(ValueError):maps.global_tex_mip_cache_candidate({127488:body},native_tail_policy=POLICY)
|
|
for mapping,policy in [({},POLICY),({0:self.first},POLICY),({True:self.first},POLICY),({127488:self.first,'invalid':self.first},POLICY),({127488:self.first},'unreviewed')]:
|
|
with self.assertRaises(ValueError):maps.global_tex_mip_cache_candidate(mapping,native_tail_policy=policy)
|
|
|
|
|
|
class GlobalTexBC2Test(unittest.TestCase):
|
|
def test_original27_bc2_golden_and_changed_format_refusals(self):
|
|
job=BASE/'runtime/continuation-20261026/global-TEX-mip-cache-producer'
|
|
receipt=json.loads((job/'native129-exact27-alternate-variant-mip-correlation.json').read_text())
|
|
self.assertEqual(receipt['matches'],27)
|
|
blps={r['file_data_id']:Path(r['body_file']).read_bytes() for r in receipt['rows']}
|
|
meta=json.loads((job/'original33-format129-first-needed-row-metadata.json').read_text())
|
|
records=[];chunks=[];cursor=0
|
|
with (BASE/meta['source_file']).open('rb') as original:
|
|
for row in meta['new_format129_rows']:
|
|
original.seek(row['TXMD_header_file_offset'])
|
|
chunk=original.read(8+row['bytes'])
|
|
self.assertEqual(chunk[:4],b'DMXT')
|
|
records.append(struct.pack('<II4B',row['file_data_id'],cursor,
|
|
row['width'],row['height'],row['nominal_mips'],row['format']))
|
|
chunks.append(chunk);cursor+=len(chunk)
|
|
golden=(b'RVXT'+struct.pack('<II',4,1)+b'TBXT'
|
|
+struct.pack('<I',12*len(records))+b''.join(records)+b''.join(chunks))
|
|
actual,audit=maps.global_tex_mip_cache_candidate(blps,native_tail_policy=POLICY)
|
|
self.assertEqual(actual,golden)
|
|
self.assertEqual({r['format_byte'] for r in audit['rows']},{129})
|
|
first=next(iter(blps.values()))
|
|
for field,value in ((8,1),(10,2)):
|
|
bad=bytearray(first);bad[field]=value
|
|
with self.assertRaises(ValueError):
|
|
maps.global_tex_mip_cache_candidate({1:bytes(bad)},native_tail_policy=POLICY)
|
|
bad=bytearray(first)
|
|
level=audit['rows'][0]['first_mip']
|
|
struct.pack_into('<I',bad,84+4*level,8)
|
|
with self.assertRaises(ValueError):
|
|
maps.global_tex_mip_cache_candidate({1:bytes(bad)},native_tail_policy=POLICY)
|
|
(job/'golden-original27-BC2-subset.tex').write_bytes(golden)
|
|
(job/'actual-original27-BC2-candidate.tex').write_bytes(actual)
|
|
(job/'golden-original27-BC2-audit.json').write_text(json.dumps(audit,indent=2)+'\n')
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|