883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
129 lines
8.1 KiB
Python
129 lines
8.1 KiB
Python
from pathlib import Path
|
|
import struct,sys
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
from engine_pipe_host import decode_item_request,decode_spell_request
|
|
def specimen(opcode=0x3e0171,length=74,captured=74,reserved=0):
|
|
return struct.pack('<6I',1,280,opcode,length,captured,reserved)+b'X'*256
|
|
assert len(decode_item_request(specimen())['payload_hex'])==148
|
|
assert decode_item_request(specimen(0,0,0))['payload_hex']==''
|
|
for value in (specimen(0,74,74),specimen(0x440011),specimen(length=257,captured=257),specimen(length=75),specimen(reserved=0x7fffffff),specimen()[:-1]):
|
|
try:decode_item_request(value)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unrelated/truncated/inconsistent specimen was exposed')
|
|
print('Only bounded USE_ITEM specimens can expose gameplay bytes; unrelated opcodes, empty-tag payloads and inconsistent records reject.')
|
|
|
|
assert len(decode_spell_request(specimen(0x3e0176,length=68,captured=68))['payload_hex'])==136
|
|
assert decode_spell_request(specimen(0,0,0))['payload_hex']==''
|
|
for value in (specimen(),specimen(0x440011),specimen(0x3e0176,length=68,captured=67),specimen(0x3e0176,length=257,captured=257),specimen(0x3e0176)[:-1]):
|
|
try:decode_spell_request(value)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unrelated/truncated spell specimen exposed')
|
|
print('Separate declared CAST_SPELL specimen rejects item/auth/unrelated opcodes and inconsistent records.')
|
|
|
|
# Entity pages are data-only, independently bounded from gameplay specimens.
|
|
from engine_pipe_host import decode_entity_page
|
|
from native_entity_catalog import read_catalog
|
|
h=struct.pack('<12I',2,41008,300,300,0,1,0,0,0,0,300,0)
|
|
rows=b''.join(struct.pack('<Q16s4I',n,bytes(16),n,3,1,1) for n in range(300))
|
|
p0=decode_entity_page(h,rows[:256*40]);p1=decode_entity_page(h,rows[256*40:],256)
|
|
assert p0['captured']==256 and p0['truncated'] and p0['next_offset']==256 and not p0['snapshot_truncated']
|
|
assert p1['captured']==44 and p1['next_offset'] is None and p1['actors'][-1]['entry']==299
|
|
class Controller:
|
|
def rpc(self,operation,entity_offset):return {'entities':(p0 if entity_offset==0 else p1)}
|
|
assert len(read_catalog(Controller())['actors'])==300
|
|
for offset,body in ((-1,b''),(1,b''),(256,rows[:1]),(1024,b'')):
|
|
try:decode_entity_page(h,body,offset)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Malformed/overflow identity page accepted')
|
|
p0['snapshot_truncated']=True
|
|
try:read_catalog(Controller())
|
|
except RuntimeError:pass
|
|
else:raise AssertionError('Truncated identity list established absence')
|
|
print('Paged300-actor catalog preserves high entries and refuses unproven absence beyond source cap.')
|
|
|
|
from engine_pipe_host import decode_aura_state
|
|
aura=struct.pack('<8I',1,1376,1,0,1,1,1,0)+struct.pack('<7I',21991,5,60,0,1,248700,1)+bytes(47*28)
|
|
assert decode_aura_state(aura)['rows'][0]==dict(slot=0,spell=21991,flags=5,level=60,applications_minus_one=0,active_mask=1,visual_link=248700,queued=1)
|
|
for invalid in (aura[:-1],bytes(1376),aura[:24]+struct.pack('<I',49)+aura[28:],aura[:48]+struct.pack('<I',8)+aura[52:]):
|
|
try:decode_aura_state(invalid)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Malformed/inconsistent aura diagnostic accepted')
|
|
print('Bounded source aura slots distinguish receipt, metadata support and queue state; renderer acceptance is not inferred.')
|
|
|
|
from engine_pipe_host import decode_source_unit_fields,read_source_unit_fields,bound_source_field_reply
|
|
import json
|
|
field_header=struct.pack('<8I',1,2080,41,70,64,6,0,0)
|
|
field_rows=b''.join(struct.pack('<Q6I',4509,i,40,0x1f6,0,164,10241 if i%2 else 10240) for i in range(7,71))
|
|
full=decode_source_unit_fields(field_header,field_rows)
|
|
tail=decode_source_unit_fields(field_header,field_rows[48*32:],48)
|
|
assert full['captured']==64 and full['overwritten']==6 and not full['truncated']
|
|
assert tail['captured']==16 and tail['truncated'] and tail['rows'][0]['sequence']==55
|
|
assert tail['rows'][-1]['value']==10240 and not tail['engine_application_verified']
|
|
mount_header=struct.pack('<8I',1,2080,41,1,1,0,0,0)
|
|
mount_row=struct.pack('<Q6I',4518,1,40,0x1f6,0,133,17158)
|
|
assert decode_source_unit_fields(mount_header,mount_row)['rows'][0]['value']==17158
|
|
# Adjacent non-diagnostic words remain excluded; this only adds mount field133.
|
|
try:decode_source_unit_fields(mount_header,struct.pack('<Q6I',4518,1,40,0x1f6,0,134,17158))
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unrelated adjacent field exposed by mount diagnostics')
|
|
# Existing ABI2 pages remain readable, and ABI3 keeps the identity prefix/layout.
|
|
h3=struct.pack('<12I',3,43088,300,300,0,1,0,0,0,0,300,0)
|
|
assert decode_entity_page(h3,rows[:256*40])['actors']==decode_entity_page(h,rows[:256*40])['actors']
|
|
class FieldMemory:
|
|
def __init__(self):self.blob=field_header+field_rows;self.reads=[]
|
|
def read(self,address,size):
|
|
self.reads.append(size);assert size<=2048
|
|
return self.blob[address:address+size]
|
|
memory=FieldMemory();assert read_source_unit_fields(memory,0,True)==full
|
|
assert memory.reads==[32,2048,32]
|
|
assert read_source_unit_fields(FieldMemory(),0)==tail
|
|
class MotionOnlyMemory(FieldMemory):
|
|
def __init__(self,latest=42):super().__init__();self.headers=0;self.latest=latest
|
|
def read(self,address,size):
|
|
result=super().read(address,size)
|
|
if address==0:
|
|
self.headers+=1
|
|
if self.headers>1:
|
|
values=list(struct.unpack('<8I',result));values[2]=self.latest;return struct.pack('<8I',*values)
|
|
return result
|
|
motion_memory=MotionOnlyMemory();motion_fields=read_source_unit_fields(motion_memory,0,True)
|
|
assert motion_fields['source_packets']==42 and motion_fields['rows']==full['rows']
|
|
assert motion_memory.reads==[32,2048,32] # No retries for unrelated packet traffic.
|
|
try:read_source_unit_fields(MotionOnlyMemory(40),0,True)
|
|
except ValueError as error:assert 'reset' in str(error)
|
|
else:raise AssertionError('Packet counter regression must fail closed')
|
|
class BusyFieldMemory(FieldMemory):
|
|
def __init__(self):super().__init__();self.headers=0
|
|
def read(self,address,size):
|
|
result=super().read(address,size)
|
|
if address==0:
|
|
self.headers+=1;total=70+self.headers
|
|
return struct.pack('<8I',1,2080,100,total,64,total-64,0,0)
|
|
return result
|
|
busy_memory=BusyFieldMemory();busy=read_source_unit_fields(busy_memory,0,True)
|
|
assert busy==dict(available=False,retryable=True,reason='source-field-snapshot-busy',attempts=3,rows=[],engine_application_verified=False)
|
|
assert busy_memory.reads==[32,2048,32]*3
|
|
assert read_source_unit_fields(FieldMemory(),0,True)==full # Later observation can recover normally.
|
|
for bad_header,bad_rows,offset in (
|
|
(field_header[:-1],field_rows,0),(bytes(32),field_rows,0),
|
|
(struct.pack('<8I',1,2080,41,70,65,5,0,0),field_rows,0),
|
|
(field_header,field_rows[:-1],0),(field_header,field_rows,1),
|
|
(field_header,struct.pack('<Q6I',4509,7,40,0x1ee,0,164,0)+field_rows[32:],0),
|
|
(field_header,struct.pack('<Q6I',4509,7,40,0x1f6,0,47,21991)+field_rows[32:],0),
|
|
(field_header,struct.pack('<Q6I',4509,7,42,0x1f6,0,164,0)+field_rows[32:],0),
|
|
(field_header,struct.pack('<Q6I',0,7,40,0x1f6,0,164,0)+field_rows[32:],0)):
|
|
try:decode_source_unit_fields(bad_header,bad_rows,offset)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Malformed/unrelated source field metadata exposed')
|
|
for invalid_blob in (bytes(32)+field_rows,field_header+struct.pack('<Q6I',4509,7,40,0x1f6,0,47,21991)+field_rows[32:]):
|
|
invalid_memory=FieldMemory();invalid_memory.blob=invalid_blob
|
|
try:read_source_unit_fields(invalid_memory,0,True)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Invalid source header/whitelist must not be downgraded to retryable')
|
|
reply=dict(unit_fields_only=False,source_unit_fields=decode_source_unit_fields(field_header,field_rows[48*32:],48),existing='X'*63000)
|
|
bound_source_field_reply(reply)
|
|
assert len(json.dumps(reply).encode())<=64000 and reply['source_unit_fields']['truncated']
|
|
assert reply['source_unit_fields']['captured']<16 and reply['existing']=='X'*63000
|
|
print('ABI3 preserves old entity pagination; strict source-field words/sequence bounds,2048-byte reads,default16/full64 tails and optional reply trimming pass. No engine acceptance inferred.')
|
|
print('Unrelated packet counter advances preserve stable field rows; three busy field tails return retryable unavailability, while invalid metadata and counter regression fail closed.')
|