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

78 lines
5.4 KiB
Python

#!/usr/bin/env python3
"""Affected owned-batch route only; no native client, publication/SDK replay."""
from pathlib import Path
from contextlib import ExitStack
from unittest.mock import patch
import hashlib,json,re,sys,tempfile
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import native_model_probe as probe
import published_client_assets as publication
import item_package_preflight as package
def encoded(path,value):
data=(json.dumps(value,separators=(',',':'))+'\n').encode();path.write_bytes(data);return hashlib.sha256(data).hexdigest()
def main():
with tempfile.TemporaryDirectory()as temporary:
root=Path(temporary);runtime=root/'runtime';runtime.mkdir();(runtime/'native-client.pid').write_text('1433567')
logs=runtime/'native-client/_classic_beta_/Logs';logs.mkdir(parents=True)
for n in ['gx.log','AsyncFile.log']:(logs/n).write_text('')
entries=[dict(path='wowhybrid/source-equipment/'+c*64+'.m2',file_data_id=i)for c,i in [('a',101),('b',201)]]
rows=[dict(model_file_data_id=e['file_data_id'],registered_path=e['path'],SFID=[e['file_data_id']+j for j in range(1,5)],TXID=[301])for e in entries]
profile=root/'dependencies.json';profile_sha=encoded(profile,dict(models=rows))
manifest=root/'assets.json';receipt=root/'receipt.json';proof={};counts={'proof':0,'manifest':0,'profile':0,'native_guard':0,'controllers':0};state={}
def stage(kind='model'):
assets=[dict(**e,kind=kind if index==1 else'model',content_key='c'*32)for index,e in enumerate(entries)]
sha=encoded(manifest,dict(assets=assets));rh=encoded(receipt,dict(inputs=dict(assets=dict(path=str(manifest),sha256=sha))))
encoded(root/'linux-release.json',dict(private_asset_publication=dict(receipt_path=str(receipt))))
proof.update(receipt_sha256=rh,registered_assets=2,composed_root='d'*32)
stage()
read=package.read_public_json
def observed_read(path,*args,**kwargs):
if Path(path)==manifest:counts['manifest']+=1
if Path(path)==profile:counts['profile']+=1
return read(path,*args,**kwargs)
def published(path):assert path==root;counts['proof']+=1;return proof
def native_guard(c,s,account):counts['native_guard']+=1;return dict(reused_frozen_native_guard=True)
class Controller:
def __init__(self,pid):assert pid==1433567;counts['controllers']+=1
def rpc(self,name):
assert name=='inspect-wire-account'
return dict(server_proof_verified=1,transport_prepared=1,auth_port=3724,selected_index=0,realms=[dict(address='127.0.0.1:8090')])
def wait(self,sample,timeout):
return dict(run=state['run'],models=[dict(run=state['run'],requestedFileID=e['file_data_id'],loadedFileID=e['file_data_id'],loadAccepted=True,overrideArchive='0')for e in entries])
class Session:
def __init__(self,pid):self.frames=0
def __enter__(self):return self
def __exit__(self,*args):return False
def wait_world(self,*args):raise AssertionError('Redundant OCR wait in proven native mode')
def macro(self,text):
if 'nativeModelBatch={run='in text:state['run']=re.search('run="([0-9a-f]+)"',text)[1]
def shot(self,path):
path.write_bytes(b'synthetic-route-only-not-a-visual-witness');self.frames+=1
if self.frames==2 and state.get('skin_error'):
with (logs/'AsyncFile.log').open('a')as f:f.write('Streaming failed [Invalid file handle] FileData ID 204\n')
with ExitStack()as stack:
for obj,name,value in [(probe,'ROOT',root),(probe,'Controller',Controller),(probe,'Session',Session),(probe,'local_listeners',lambda:[]),(probe,'require_local_turtle_ports',lambda value:None),(probe,'require_model_probe_native_world',native_guard),(publication,'published_source',published),(package,'read_public_json',observed_read)]:stack.enter_context(patch.object(obj,name,value))
for index,skin_error in enumerate([False,True]):
state['skin_error']=skin_error;before=counts.copy();out=runtime/f'route-{index}.json'
code=probe.run_batch(entries,out,native_world_readiness=True,resource_profile=profile,resource_profile_sha256=profile_sha)
result=json.loads(out.read_text())
assert counts['proof']-before['proof']==1 and counts['manifest']-before['manifest']==1 and counts['profile']-before['profile']==1
assert counts['native_guard']-before['native_guard']==2
assert code==(2 if skin_error else 0) and all(r['original_model_load_accepted']for r in result['models'])
assert result['models'][0]['stream_failures']==[]
assert bool(result['models'][1]['stream_failures'])==skin_error
assert result['owned_registered_model_bindings']and result['target_listfile_sha256']is None
for case in ['mixed','changed-profile','wrong-kind']:
before=counts['controllers'];bad=entries
if case=='mixed':bad=[entries[0],dict(path='Creature/Control/Control.m2',file_data_id=201)]
if case=='wrong-kind':stage('texture')
try:probe.run_batch(bad,runtime/(case+'.json'),native_world_readiness=True,resource_profile=profile,resource_profile_sha256='0'*64 if case=='changed-profile'else profile_sha)
except ValueError:pass
else:raise AssertionError('Unscoped batch accepted: '+case)
assert counts['controllers']==before
print(json.dumps(dict(status='PASS',affected_owned_batch_route=True,publication_and_manifest_once_per_batch=True,frozen_native_guard_reused_no_OCR=True,six_ID_scope_and_skin_failure_attributed=True,mixed_namespace_changed_profile_wrong_kind_refused_before_client=True,synthetic_only_no_native_input_SDK_or_original_proof_retested=True)))
if __name__=='__main__':main()