883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
170 lines
9.7 KiB
Python
170 lines
9.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Offline actual-codec evidence for creation metadata before world entry.
|
|
|
|
Run with GW_TEST_CODEC_PATH and GW_TEST_ITEM_PACKAGE pointing to the same
|
|
isolated build/package. No account, native process, server, or UI is contacted.
|
|
"""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/'ops'))
|
|
from item_package_preflight import read_compatibility_package
|
|
from item_sparse_compat import package_pages
|
|
from native_codec_driver import MODES,load,serialize
|
|
|
|
ADDRESS=0x46010046
|
|
CHAR_BASE=0x3067a8f8
|
|
|
|
|
|
def decode_hotfix(wire):
|
|
if len(wire)<8:raise ValueError('Truncated hotfix envelope')
|
|
count,=struct.unpack_from('<I',wire);at=4;metadata=[]
|
|
if count>4096 or 4+21*count+4>len(wire):raise ValueError('Hotfix directory bounds')
|
|
for _ in range(count):
|
|
push,index,table,record,size=struct.unpack_from('<5I',wire,at)
|
|
metadata.append((push,index,table,record,size,wire[at+20]));at+=21
|
|
content_bytes,=struct.unpack_from('<I',wire,at);at+=4
|
|
if at+content_bytes!=len(wire):raise ValueError('Hotfix content bounds')
|
|
records=[]
|
|
for push,index,table,record,size,status in metadata:
|
|
if at+size>len(wire):raise ValueError('Hotfix row bounds')
|
|
records.append((push,index,table,record,status,wire[at:at+size]));at+=size
|
|
if at!=len(wire):raise ValueError('Unclaimed hotfix payload')
|
|
return records
|
|
|
|
|
|
class PreworldCreationHotfixTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
if not os.environ.get('GW_TEST_CODEC_PATH') or not os.environ.get('GW_TEST_ITEM_PACKAGE'):
|
|
raise AssertionError('Explicit isolated codec and item package required')
|
|
cls.codec=Path(os.environ['GW_TEST_CODEC_PATH']).resolve()
|
|
cls.package_path=Path(os.environ['GW_TEST_ITEM_PACKAGE']).resolve()
|
|
cls.profile,cls.package_sha=read_compatibility_package(cls.package_path)
|
|
cls.provenance_path=cls.codec.parent/'provenance.json'
|
|
cls.provenance=json.loads(cls.provenance_path.read_text())
|
|
if cls.provenance['item_package_sha256']!=cls.package_sha:
|
|
raise AssertionError('Compiled codec/package identity differs')
|
|
if cls.provenance.get('staged_creation_profile',{}).get('source_pair_count')!=59:
|
|
raise AssertionError('Compiled all59 profile not proved')
|
|
cls.candidate_path=ROOT/'runtime/source-race-class-combos-20261022/isolated-eligibility-stage/candidate.json'
|
|
cls.candidate=json.loads(cls.candidate_path.read_text())
|
|
cls.expected=cls.candidate['rows']
|
|
if len(cls.expected)!=16:raise AssertionError('Complete16-pair scope required')
|
|
cls.pages=package_pages(cls.profile['rows'])
|
|
if cls.pages!=cls.profile['pushes']:raise AssertionError('Package page directory differs')
|
|
cls.library=load();cls.observed={}
|
|
cls.bootstrap_mode=MODES.index('--native-client-initialization')
|
|
cls.hotfix_mode=MODES.index('--native-hotfix-reply')
|
|
cls.missing_mode=MODES.index('--native-db-reply-missing')
|
|
|
|
def test_phase0_original_availability_has_every_staged_page(self):
|
|
# This input has realm/time/phase only; no selected GUID, actor or
|
|
# world-entry marker exists in the initialization serializer contract.
|
|
wire=serialize(self.library,self.bootstrap_mode,struct.pack('<IIQ',ADDRESS,0,12345))
|
|
packets,opcode,size=struct.unpack_from('<3I',wire)
|
|
self.assertEqual(packets,2);self.assertEqual(opcode,0x4b0001)
|
|
self.assertEqual(size,8+8*len(self.pages))
|
|
address,count=struct.unpack_from('<II',wire,12)
|
|
self.assertEqual(address,ADDRESS);self.assertEqual(count,len(self.pages))
|
|
advertised=[struct.unpack_from('<II',wire,20+8*i)for i in range(count)]
|
|
self.assertEqual(advertised,[(page['push_id'],1)for page in sorted(self.pages,key=lambda x:x['push_id'])])
|
|
at=12+size
|
|
self.assertEqual(struct.unpack_from('<II',wire,at),(0x4701b6,170))
|
|
self.assertEqual(len(wire),at+178)
|
|
advertised_ids={push for push,status in advertised if status==1}
|
|
positions={(int(row['table_hash'],16),row['id']):i for i,row in enumerate(self.profile['rows'])}
|
|
owners={}
|
|
for row in self.expected:
|
|
position=positions[(CHAR_BASE,row['id'])]
|
|
owner=[page for page in self.pages if page['first']<=position<page['first']+page['count']]
|
|
self.assertEqual(len(owner),1);self.assertIn(owner[0]['push_id'],advertised_ids)
|
|
owners[str(row['id'])]=owner[0]['push_id']
|
|
self.observed['advertised16_record_page_owners']=owners
|
|
|
|
def test_all16_source_pairs_are_exact_typed_additions(self):
|
|
actual=[r for r in self.profile['rows']if r['table_name']=='CharBaseInfo']
|
|
self.assertEqual(actual,self.expected)
|
|
self.assertEqual({(r['record']['RaceID'],r['record']['ClassID'])for r in actual},
|
|
{tuple(pair)for pair in self.candidate['missing_native_pairs']})
|
|
self.assertIn((6,5),{(r['record']['RaceID'],r['record']['ClassID'])for r in actual})
|
|
for row in actual:
|
|
record=row['record'];raw=struct.pack('<bbb',record['RaceID'],record['ClassID'],0)
|
|
self.assertEqual(int(row['table_hash'],16),CHAR_BASE)
|
|
self.assertEqual(bytes.fromhex(row['wire_hex']),raw)
|
|
self.assertEqual(row['sha256'],hashlib.sha256(raw).hexdigest())
|
|
|
|
def test_advertised_page_reply_carries_all16_exact_payloads(self):
|
|
positions={(int(r['table_hash'],16),r['id']):i for i,r in enumerate(self.profile['rows'])}
|
|
wanted={(CHAR_BASE,r['id'])for r in self.expected}
|
|
selected=[page for page in self.pages if any(page['first']<=positions[key]<page['first']+page['count']for key in wanted)]
|
|
found={};page_proofs=[]
|
|
for page in selected:
|
|
request=struct.pack('<4I',70334,70334,1,page['push_id'])
|
|
wire=serialize(self.library,self.hotfix_mode,request)
|
|
records=decode_hotfix(wire)
|
|
expected_page=self.profile['rows'][page['first']:page['first']+page['count']]
|
|
self.assertEqual(len(records),page['count']);self.assertEqual(len(wire),page['wire_bytes'])
|
|
self.assertLessEqual(len(wire),1048576)
|
|
for index,(record,row)in enumerate(zip(records,expected_page),1):
|
|
push,entry,table,identity,status,raw=record
|
|
self.assertEqual((push,entry,table,identity,status),
|
|
(page['push_id'],index,int(row['table_hash'],16),row['id'],64 if row.get('record_status')=='removed' else 32))
|
|
self.assertEqual(raw,bytes.fromhex(row['wire_hex']))
|
|
if(table,identity)in wanted:
|
|
self.assertNotIn(identity,found);found[identity]=raw
|
|
page_proofs.append({'push_id':page['push_id'],'rows':len(records),'bytes':len(wire),'wire_sha256':hashlib.sha256(wire).hexdigest()})
|
|
self.assertEqual(found,{row['id']:bytes.fromhex(row['wire_hex'])for row in self.expected})
|
|
self.observed['exact_hotfix16_ids']=sorted(found)
|
|
self.observed['hotfix_pages']=page_proofs
|
|
|
|
def test_original_db_reply_fallback_carries_each_typed_record(self):
|
|
for row in self.expected:
|
|
wire=serialize(self.library,self.missing_mode,struct.pack('<III',CHAR_BASE,row['id'],12345))
|
|
self.assertEqual(struct.unpack_from('<III',wire),(CHAR_BASE,row['id'],12345))
|
|
self.assertEqual(wire[12],32)
|
|
self.assertEqual(struct.unpack_from('<I',wire,13)[0],3)
|
|
self.assertEqual(wire[17:],bytes.fromhex(row['wire_hex']))
|
|
|
|
def test_unknown_creation_record_remains_missing(self):
|
|
unknown=max(row['id']for row in self.expected)+1
|
|
wire=serialize(self.library,self.missing_mode,struct.pack('<III',CHAR_BASE,unknown,12345))
|
|
self.assertEqual(struct.unpack_from('<III',wire),(CHAR_BASE,unknown,12345))
|
|
self.assertEqual(wire[12:],b'\x60'+bytes(4))
|
|
|
|
def test_bad_namespace_or_phase_never_advertises_records(self):
|
|
for data in [struct.pack('<IIQ',0,0,12345),struct.pack('<IIQ',ADDRESS,2,12345),
|
|
struct.pack('<IIQ',ADDRESS,0,12345)+b'x']:
|
|
with self.subTest(bytes=len(data)),self.assertRaises(ValueError):
|
|
serialize(self.library,self.bootstrap_mode,data)
|
|
|
|
|
|
def main():
|
|
suite=unittest.defaultTestLoader.loadTestsFromTestCase(PreworldCreationHotfixTest)
|
|
result=unittest.TextTestRunner(verbosity=2).run(suite)
|
|
if result.wasSuccessful():
|
|
cls=PreworldCreationHotfixTest
|
|
output=os.environ.get('GW_PREWORLD_CREATION_REPORT')
|
|
if output:
|
|
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
report={'schema':1,'date':'2026-10-22','status':'actual isolated codec preworld metadata contract PASS',
|
|
'tests':result.testsRun,'failures':len(result.failures),'errors':len(result.errors),
|
|
'artifacts':[{'path':str(p),'sha256':sha(p)}for p in [Path(__file__),cls.codec,cls.package_path,cls.provenance_path,cls.candidate_path]],
|
|
'package_rows':len(cls.profile['rows']),'source_availability_pairs':59,'typed_creation_records':16,
|
|
'before_world_input':'Realm address,phase0,time only; no actor/GUID/self-create input',
|
|
'observed':cls.observed,'installed':False,'native_ui_consumption_verified':False,
|
|
'created_character':False,'limit':'Proves actual compiled wire advertisement/reply payloads. Does not prove native cache/UI refresh, custom-race menu or source creation outcome.'}
|
|
path=Path(output)
|
|
if path.exists():raise ValueError('Fresh evidence output required')
|
|
path.write_text(json.dumps(report,indent=2)+'\n')
|
|
return 0 if result.wasSuccessful() else 1
|
|
|
|
|
|
if __name__=='__main__':raise SystemExit(main())
|