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

165 lines
9.5 KiB
Python

"""Pinned original controls with owned Source data/show branches; no client."""
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import unittest
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'))
import source_realm_ui as ui
LUA=r'''
local reads, requests, nativeReads, disconnects = 0, 0, 0, 0;
local current = {abi=1,size=64,generation=1,endpoint_kind=0,state=5,error=0,
auth_result=0,discovery_result=0,server_proof_verified=1,realm_count=2,
selected_index=-1,transport_prepared=0,cancel=0,genuine_discovery=1,
auth_port=3724,copied_realms=2,
r0={name="Source Alpha",address="127.0.0.1:8085",type=0,flags=0,
characters=3,category=4,wire_id=1,population_text="0.375"},
r1={name="Source Offline",address="127.0.0.1:8086",type=1,flags=2,
characters=0,category=7,wire_id=2,population_text="1.25"}};
local requestStatus = 0;
local native = {};
native.GetRealmInfo=function(key) nativeReads=nativeReads+1; return {name="Native",populationState="LOW",numCharacters=0}; end;
native.GetAvailableCategories=function() return {99}; end;
native.GetCategoryInfo=function() return "Native category",false,false; end;
native.GetRealmsInCategory=function() return {99}; end;
native.IsRealmListComplete=function() return true; end;
native.ConnectToRealm=function() error("Source request leaked to native"); end;
native.ClearRealmList=function() disconnects=disconnects+1; end;
native.RequestChangeRealmList=function() disconnects=disconnects+1; end;
local errorCategory,errorId,errorCode="BNET",1016,"BLZ51901016";
local login = {
GetTurtleRealmSnapshot=function() reads=reads+1; return current; end,
RequestTurtleRealm=function(index,generation)
assert(index==0 and generation==current.generation); requests=requests+1; return requestStatus;
end,
GetState=function() return {connectedToWoW=false,hasRealmList=false,
superDistrictChoicePending=false,auroraState=0,wowConnectionState=0,
hasSelectedExperiencePreset=true}; end,
GetLastError=function() return errorCategory,errorId,nil,nil,errorCode; end,
DisconnectFromServer=function() disconnects=disconnects+1; end,
};
local function widget()
local value={};
function value:SetText(text) self.text=text; end;
function value:SetEnabled(enabled) self.enabled=not not enabled; end;
function value:SetTextColor(...) self.color={...}; end;
return setmetatable(value,{__index=function(self,key)
if key:match("^Get") then return function() return widget(); end; end
if key:match("^Set") or key=="Show" or key=="Hide"
or key=="LockHighlight" or key=="UnlockHighlight" then return function() end; end
local child=widget(); rawset(self,key,child); return child;
end});
end
local color={r=1,g=1,b=1,GetRGB=function()return 1,1,1;end};
local env=setmetatable({C_Login=login,C_RealmList=native,
NORMAL_FONT_COLOR=color,GRAY_FONT_COLOR=color,HIGHLIGHT_FONT_COLOR=color,
RED_FONT_COLOR=color,GREEN_FONT_COLOR=color,
RealmList={selectedRealm=0},RealmListOkButton=widget(),
C_Log={LogMessage=function()end},LE_AURORA_STATE_NONE=0,
LE_WOW_CONNECTION_STATE_CONNECTING=1}, {__index=_G});
env._G=env;
local realmText=assert(io.open(arg[1],"rb")):read("*a");
local proxy=assert(load(realmText.."\nreturn RealmListProvider;","@original-RealmList-candidate","t",env))();
local nativeIdentity=env.C_RealmList;
proxy.Refresh(); assert(proxy.IsSource() and reads==1);
assert(proxy.GetRealmInfo(0).name=="Source Alpha" and reads==1 and nativeReads==0);
assert(proxy.GetRealmInfo(1).sourceSelectable==false);
assert(proxy.ComparePopulation(0,1)<0);
local button=widget(); button.Load=widget(); button.Type=widget(); button.PlayerCount=widget(); button.SelectedTexture=widget();
env.RealmList_InitButton(button,0); assert(button.Load.text=="0.375" and button.enabled);
env.RealmList_OnOk(); assert(requests==1 and env.RealmListOkButton.enabled==false);
env.RealmList_OnOk(); assert(requests==1); -- accepted proposal is not replayed
local changed,reason=proxy.RequestChangeRealmList(); assert(changed==false and reason=="account-realm-transition-unverified");
local cancelPopups=0; env.StaticPopup_Show=function() cancelPopups=cancelPopups+1; end;
assert(env.RealmList_OnCancel()==false and disconnects==0 and cancelPopups==1);
current.error=7; proxy.Refresh(); assert(proxy.IsSource() and #proxy.GetAvailableCategories()==0 and nativeReads==0);
assert(proxy.GetRealmInfo(0)==nil); -- no stale native account cache on proof loss
current.error=0; current.generation=2; proxy.Refresh(); requestStatus=-2;
assert(proxy.ConnectToRealm(0)==false); assert(requests==2); -- backend disabled stays held
assert(env.C_RealmList==nativeIdentity and env.C_Login==login);
local glueEnv=setmetatable({C_Login=login,C_RealmList=native,
GlueParent={currentScreen="login"},C_Log={LogMessage=function()end},
SOUNDKIT=setmetatable({},{__index=function()return 0;end}),
setprinthandler=function()end,
LE_AURORA_STATE_NONE=0,LE_WOW_CONNECTION_STATE_CONNECTING=1}, {__index=_G});
glueEnv._G=glueEnv;
local glueText=assert(io.open(arg[2],"rb")):read("*a");
local bridge=assert(load(glueText.."\nreturn SourceRealmGlue;","@original-GlueParent-candidate","t",glueEnv))();
local shown;
glueEnv.GlueParent_SetScreen=function(screen) shown=screen;glueEnv.GlueParent.currentScreen=screen;end;
glueEnv.GlueParent_EnsureValidScreen();
assert(shown=="realmlist" and bridge.IsPending());
local dialog;
glueEnv.IsHigherPriorityError=function() return true; end;
login.ClearLastError=function() end;
glueEnv.StaticPopup_Show=function(kind,text,text2,data,inserted,onHide)
dialog={kind=kind,text=text,data=data,onHide=onHide};
end;
glueEnv.EventRegistry={TriggerEvent=function() end};
glueEnv.StaticPopup_HideAllExcept=function() end;
glueEnv.StaticPopup_Hide=function() end;
glueEnv.BNET_ERROR_OTHER="Disconnected";glueEnv.WOW_ERROR_OTHER="World error";
glueEnv.strfind=string.find;glueEnv.strlower=string.lower;
glueEnv.LE_AURORA_STATE_WAITING_FOR_NETWORK=1;glueEnv.LE_AURORA_STATE_CONNECTING=2;
glueEnv.LE_AURORA_STATE_CONNECTED=3;glueEnv.LE_WOW_CONNECTION_STATE_IN_QUEUE=5;
local function checkError(kind,code)
dialog=nil;glueEnv.GlueParent_UpdateDialogs();
assert(dialog and dialog.kind==kind and dialog.text:find(code,1,true)
and dialog.onHide==login.ClearLastError, dialog and (dialog.kind..":"..dialog.text) or "no dialog");
end
checkError("OKAY_WITH_GENERIC_URL","BLZ51901016");
glueEnv.BNET_ERROR_1016_URL="original-help";
checkError("OKAY_WITH_URL","BLZ51901016");assert(dialog.data=="BNET_ERROR_1016_URL");
errorCategory=nil;glueEnv.GlueParent_UpdateDialogs(); -- clear original priority state
errorCategory,errorId,errorCode="WOW",319,"BLZ51900319";
checkError("OKAY_WITH_GENERIC_URL","BLZ51900319");
current.transport_prepared=1; bridge.Refresh(); assert(not bridge.IsPending());
current.transport_prepared=0; current.error=9; bridge.Refresh();
assert(not bridge.IsPending() and bridge.GetSourceStatus().error==9);
shown=nil; glueEnv.GlueParent_EnsureValidScreen(); assert(shown=="login");
assert(glueEnv.C_Login==login and glueEnv.C_RealmList==nativeIdentity);
local disabledText=assert(io.open(arg[3],"rb")):read("*a");
local disabledEnv=setmetatable({C_Login=login,C_RealmList=native},{__index=_G}); disabledEnv._G=disabledEnv;
local disabled=assert(load(disabledText.."\nreturn RealmListProvider;","@disabled-original-RealmList","t",disabledEnv))();
local oldReads=reads; disabled.Refresh(); assert(not disabled.IsSource() and reads==oldReads);
assert(disabled.GetRealmInfo(99).name=="Native" and nativeReads==1);
print("PASS original RealmList data/request and GlueParent source-choice branches");
'''
class SourceRealmOriginalUI(unittest.TestCase):
def test_pinned_original_pair_with_real_factory_and_owned_branches(self):
executable=shutil.which('lua5.4')or shutil.which('lua')
self.assertIsNotNone(executable,'Existing Lua interpreter required')
realm=ROOT/'runtime/native-login-ui/interface/addons/blizzard_gluexml/mainline/realmlist.lua'
glue=ROOT/'runtime/native-login-ui/interface/addons/blizzard_glueparent/mainline/glueparent.lua'
with tempfile.TemporaryDirectory()as temporary:
root=Path(temporary);r=root/'realmlist.lua';g=root/'glueparent.lua';disabled=root/'disabled.lua';fixture=root/'check.lua'
original_realm=realm.read_bytes()
r.write_bytes(ui.transform(original_realm,enable_source_pending=True))
disabled.write_bytes(ui.transform(original_realm))
fixture.write_text(LUA)
for diagnostics in (False, True):
with self.subTest(diagnostics=diagnostics):
g.write_bytes(ui.transform_glue(glue.read_bytes(),enable_source_pending=True,
enable_login_diagnostics=diagnostics))
result=subprocess.run([executable,str(fixture),str(r),str(g),str(disabled)],capture_output=True,text=True)
self.assertEqual(result.returncode,0,result.stdout+result.stderr)
self.assertIn('PASS original RealmList',result.stdout)
def test_unknown_original_or_non_boolean_policy_is_held(self):
with self.assertRaisesRegex(ValueError,'Pinned original'):
ui.transform(b'-- different build')
with self.assertRaisesRegex(ValueError,'Pinned original'):
ui.transform_glue(b'-- different build')
with self.assertRaisesRegex(ValueError,'Explicit Source UI boolean'):
ui.transform(b'',enable_source_pending=1)
if __name__=='__main__':unittest.main()