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

94 lines
6.4 KiB
Python

#!/usr/bin/env python3
"""Changed async addon/grid producer only; native acceptance is separate."""
from pathlib import Path
from contextlib import ExitStack
from unittest.mock import patch
from types import SimpleNamespace
import hashlib,json,subprocess,sys,tempfile
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import native_model_probe as probe
import client_ui as ui
LUA=Path(__file__).resolve().parents[1]/'client_addons/GatewayDiagnostics/NativeModelProbe.lua'
def main():
lua=r'''local callbacks,models,creates,gets={},0,0,0
GatewayDiagnosticsSaved={};UIParent={};function UIParent:GetWidth()return 1600 end;function UIParent:GetHeight()return 1000 end
function GetCVar(n)assert(n=='overrideArchive');return '0'end
local secret=setmetatable({},{__tostring=function()error('Secret tostring')end,__eq=function()error('Secret compare')end})
function issecretvalue(v)return rawequal(v,secret)end
C_Timer={After=function(delay,callback)callbacks[#callbacks+1]=callback end}
local function object()
local o={}
for _,n in ipairs({'SetSize','SetPoint','SetFrameStrata','Show','Hide','EnableMouse','SetAllPoints'})do o[n]=function()end end
function o:SetText(v)assert(type(v)=='string');self.text=v end
function o:SetColorTexture(r,g,b,a)self.color={r,g,b}end
function o:CreateTexture()return object()end
function o:CreateFontString()return object()end
function o:ClearModel()self.id=nil end
function o:SetModel(id)models=models+1;self.id=id end
function o:GetModelFileID()gets=gets+1;return self.secret and secret or self.id end
return o
end
function CreateFrame(kind)creates=creates+1;return object()end
'''
lua+='dofile('+json.dumps(str(LUA))+')\n'
lua+=r'''assert(creates==0 and models==0,'Addon must be opt-in')
local p=GWNativeModelProbe;p:Begin('1234abcd',4);assert(creates==5)
p:Show({101,102,103,104},1);assert(models==4 and gets==0 and #p.data.models==4)
assert(p.status.probeTexture.color[1]==1 and p.status.probeTexture.color[2]==0)
while #callbacks>0 do local f=table.remove(callbacks,1);f()end
assert(gets==4 and p.data.groups[1].ready and p.status.probeTexture.color[2]==1)
for i,r in ipairs(p.data.models)do assert(r.loadAccepted and r.loadedFileID==100+i and r.pending==false)end
p:Show({201,202,203,204},2);while #callbacks>0 do local f=table.remove(callbacks,1);f()end
assert(creates==5 and models==8 and #p.data.models==8 and p.status.probeTexture.color[3]==1)
p.frames[1].secret=true;p:Show({301},3)
while #callbacks>0 do local f=table.remove(callbacks,1);f()end
assert(models==9 and p.data.error and p.data.models[9].unavailableOrSecret and p.data.models[9].loadedFileID==nil)
local count=models;C_Timer=nil;local ok=pcall(p.Begin,p,'abcd1234',4);assert(not ok and models==count)
print('Actual addon Lua: opt-in,4 requests/dispatch,deferred IDs,frame reuse,secret/unavailable refusal PASS')
'''
with tempfile.TemporaryDirectory()as tmp:
root=Path(tmp);p=root/'grid.lua';p.write_text(lua);run=subprocess.run(['lua5.1',str(p)],capture_output=True,text=True);assert run.returncode==0,run.stderr
runtime=root/'runtime';runtime.mkdir();(runtime/'native-client.pid').write_text('1475873');logs=runtime/'native-client/_classic_beta_/Logs';logs.mkdir(parents=True)
for name in ['gx.log','AsyncFile.log']:(logs/name).write_text('')
entries=[dict(path='wowhybrid/source-equipment/'+c*64+'.m2',file_data_id=101+i*10)for i,c in enumerate('abcd')]
profile=root/'profile.json';data=(json.dumps(dict(models=[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=[501])for e in entries]))+'\n').encode();profile.write_bytes(data);sha=hashlib.sha256(data).hexdigest()
state={'macros':[],'shots':[],'guards':0,'markers':0}
class Controller:
def __init__(self,pid):assert pid==1475873
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):
if sample.__name__=='sample':return dict(run=state['run'],groups=[dict(group=1,ready=True,count=4)],models=[dict(run=state['run'],requestedFileID=e['file_data_id'],loadedFileID=e['file_data_id'],loadAccepted=True,overrideArchive='0')for e in entries])
assert sample();return True
class Session:
def __init__(self,pid):pass
def __enter__(self):return self
def __exit__(self,*args):return False
def macro(self,text):
state['macros'].append(text)
if ':Begin('in text:state['run']=text.split(':Begin("')[1].split('"')[0]
def shot(self,path):state['shots'].append(path);path.write_bytes(b'synthetic-only')
def wait_world(self,*args):raise AssertionError('No redundant zoneOCR')
def guard(*args):state['guards']+=1;return dict(reused=True)
def marker(*args):state['markers']+=1;return True
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 v:None),(probe,'require_model_probe_native_world',guard),(probe,'grid_completion_marker',marker),(probe,'owned_published_model_bindings',lambda r,e:[dict(file_data_id=x['file_data_id'],path=x['path'])for x in e])]:stack.enter_context(patch.object(obj,name,value))
out=runtime/'grid.json';code=probe.run_batch(entries,out,native_world_readiness=True,resource_profile=profile,resource_profile_sha256=sha,grid_size=4);assert code==0
result=json.loads(out.read_text());assert len(state['shots'])==1 and len(result['frame_bindings'])==4
assert sum(':Show('in m for m in state['macros'])==1 and state['guards']==2 and state['markers']==1
assert all(len(m)<=255 for m in state['macros'])and len(result['models'])==4
# Actual tiny-window marker decoder and existing focus refusal, no native IO.
class Window:
id=7
def get_image(self,*args):return SimpleNamespace(data=bytes([0,255,0,0]))
session=SimpleNamespace(d=object(),win=Window())
with patch.object(ui,'focus_id',lambda d:7):assert probe.grid_completion_marker(session,1)
with patch.object(ui,'focus_id',lambda d:8):
try:probe.grid_completion_marker(session,1)
except RuntimeError:pass
else:raise AssertionError('Focus refusal missing')
print(json.dumps(dict(status='PASS',actual_addon_Lua=True,opt_in_only=True,four_models_one_dispatch_one_frame=True,deferred_nonsecret_ID_results_and_labels=True,original_native_guard_reused=True,focus_and_secret_and_timer_refusals=True,no_native_or_SDK_or_old_test_replay=True)))
if __name__=='__main__':main()