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

56 lines
2.7 KiB
Python

"""Exact original terrain ESpec; one new multi-block framing boundary."""
import hashlib
import json
from pathlib import Path
import struct
import sys
import unittest
import zlib
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import casc_asset_package as c
class TerrainRepeatedSpecTest(unittest.TestCase):
def test_original_repeat256K_Z_frame_and_refusals(self):
spec='b:{256K*=z}'
self.assertEqual(c.reviewed_encoding_spec(spec),spec.encode('ascii'))
self.assertEqual(c.reviewed_encoding_spec('n'),b'n')
self.assertEqual(c.reviewed_encoding_spec('b:{*=z}'),b'b:{*=z}')
payload=bytes(range(251))*2111
chunks=[(payload[i:i+262144],'Z')for i in range(0,len(payload),262144)]
encoded,row=c.blte_framed(chunks)
self.assertEqual(encoded[:4],b'BLTE')
header=struct.unpack_from('>I',encoded,4)[0]
self.assertEqual(encoded[8],0x0f)
count=int.from_bytes(encoded[9:12],'big')
self.assertEqual(count,3)
self.assertEqual(header,12+24*count)
at=header;decoded=[]
for i in range(count):
size,plain=struct.unpack_from('>II',encoded,12+24*i)
checksum=encoded[20+24*i:36+24*i]
block=encoded[at:at+size];at+=size
self.assertEqual(hashlib.md5(block).digest(),checksum)
self.assertEqual(block[:1],b'Z')
body=zlib.decompress(block[1:]);self.assertEqual(len(body),plain)
self.assertEqual(plain,262144 if i<count-1 else len(payload)%262144)
decoded.append(body)
self.assertEqual(at,len(encoded))
self.assertEqual(b''.join(decoded),payload)
self.assertEqual(row['content_key'],hashlib.md5(payload).hexdigest())
self.assertEqual(row['decoded_size'],len(payload))
refused=[]
for value in ('b:{128K*=z}','b:{256K*=n}','b:{256K*=e}',
'b:{256K*=z}junk','b:{256K*=z,1=n}',None):
with self.assertRaises(ValueError):c.reviewed_encoding_spec(value)
refused.append(value)
job=Path('runtime/rea-system-jobs-20261022/terrain-component-registration-20261025')
(job/'repeat256K-ESpec-focused-check.json').write_text(json.dumps(dict(
status='PASS_EXACT_ORIGINAL_TERRAIN_REPEAT256K_ESPEC',
original_control_receipt=str(job/'two-original-terrain-storage-controls.json'),
accepted_literal=spec,standard_Z_blocks=count,final_partial_block=True,
declared_block_extent_and_checksum_and_decompressed_body_verified=True,
unchanged_n_and_single_Z_path=True,refused_variations=refused,
prior_model_or_terrain_checks_repeated=False),indent=2)+'\n')
if __name__=='__main__':unittest.main()