883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
197 lines
10 KiB
Python
197 lines
10 KiB
Python
"""Execute the Source realm view contract; no native client, credentials or server."""
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class SourceRealmProvider(unittest.TestCase):
|
|
def test_progress_and_real_source_error_survive_without_realm_rows(self):
|
|
lua = shutil.which('lua') or shutil.which('lua5.4') or shutil.which('lua5.3')
|
|
if not lua:
|
|
self.skipTest('Lua interpreter unavailable')
|
|
harness = r'''
|
|
local makeProvider=assert(loadfile(arg[1]))();
|
|
local snapshot={abi=1,size=64,generation=17,endpoint_kind=1,state=3,error=-104,
|
|
auth_result=0,discovery_result=1,server_proof_verified=1,realm_count=3,
|
|
selected_index=-1,transport_prepared=0,cancel=0,auth_port=3724,copied_realms=0,
|
|
genuine_discovery=0,username="MUST-NOT-RETAIN",password="MUST-NOT-RETAIN"};
|
|
local p=makeProvider({GetSnapshot=function()return snapshot;end,
|
|
RequestRealm=function()error("No selection without discovery");end});
|
|
assert(not p.Refresh() and not p.IsRealmListComplete());
|
|
local status=p.GetLoginStatus();
|
|
assert(status.error==-104 and status.state==3 and status.realm_count==3 and status.copied_realms==0);
|
|
assert(status.username==nil and status.password==nil and status.r0==nil);
|
|
status.error=0;assert(p.GetLoginStatus().error==-104);
|
|
local ready,reason,generation=p.GetStatus();
|
|
assert(not ready and reason=="discovery-not-proven" and generation==17);
|
|
snapshot.state=1;snapshot.error=0;snapshot.realm_count=0;snapshot.server_proof_verified=0;
|
|
snapshot.auth_result=-1;snapshot.discovery_result=-1;
|
|
assert(not p.Refresh());status=p.GetLoginStatus();
|
|
assert(status.state==1 and status.auth_result==-1 and status.server_proof_verified==0);
|
|
snapshot.abi=2;assert(not p.Refresh() and p.GetLoginStatus()==nil);
|
|
'''
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path=Path(tmp)/'status-test.lua';path.write_text(harness)
|
|
completed=subprocess.run([lua,str(path),str(ROOT/'compat/glue/source_realm_provider.lua')],capture_output=True,text=True)
|
|
self.assertEqual(completed.returncode,0,completed.stderr)
|
|
|
|
def test_exact_float32_bits_without_native_float_marshalling(self):
|
|
lua = shutil.which('lua') or shutil.which('lua5.4') or shutil.which('lua5.3')
|
|
if not lua:
|
|
self.skipTest('Lua interpreter unavailable')
|
|
harness = r'''
|
|
local makeProvider=assert(loadfile(arg[1]))();
|
|
local snapshot={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=1,
|
|
selected_index=-1,transport_prepared=0,cancel=0,auth_port=3724,copied_realms=1,
|
|
genuine_discovery=1,r0={type=1,flags=0,characters=0,category=1,wire_id=1,
|
|
name="Realm",address="127.0.0.1:8085"}};
|
|
local p=makeProvider({GetSnapshot=function()return snapshot;end,
|
|
RequestRealm=function()error("No selection in float check");end});
|
|
local function value(bits)
|
|
snapshot.r0.population_bits=bits;
|
|
assert(p.Refresh());return tonumber(p.GetRealmInfo(0).sourcePopulation);
|
|
end
|
|
assert(value(1040187392)==0.125); -- 0x3e000000
|
|
assert(value(1065353216)==1); -- 0x3f800000
|
|
assert(value(3212836864)==-1); -- 0xbf800000
|
|
assert(value(-1082130432)==-1); -- Same raw bits through a signed int32 carrier.
|
|
assert(value(0)==0 and value(2147483648)==0);
|
|
assert(math.abs(value(1)/2^-149-1)<0.00000001); -- Smallest subnormal.
|
|
snapshot.r0.population_bits=2139095040;assert(not p.Refresh()); -- Infinity.
|
|
snapshot.r0.population_bits=2143289344;assert(not p.Refresh()); -- NaN.
|
|
snapshot.r0.population_bits=4294967296;assert(not p.Refresh());
|
|
snapshot.r0.population_bits=1040187392;snapshot.r0.population_text="0.125";
|
|
assert(not p.Refresh()); -- Two conflicting representation paths are not admitted.
|
|
'''
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path=Path(tmp)/'float32-test.lua';path.write_text(harness)
|
|
completed=subprocess.run([lua,str(path),str(ROOT/'compat/glue/source_realm_provider.lua')],capture_output=True,text=True)
|
|
self.assertEqual(completed.returncode,0,completed.stderr)
|
|
|
|
def test_real_lua_snapshot_view_and_selection_boundary(self):
|
|
lua = shutil.which('lua') or shutil.which('lua5.4') or shutil.which('lua5.3')
|
|
if not lua:
|
|
self.skipTest('Lua interpreter unavailable')
|
|
provider = ROOT / 'compat/glue/source_realm_provider.lua'
|
|
harness = r'''
|
|
local makeProvider = assert(loadfile(arg[1]))();
|
|
local function clone(value)
|
|
if type(value) ~= "table" then return value; end
|
|
local out = {}; for k,v in pairs(value) do out[k] = clone(v); end; return out;
|
|
end
|
|
local baseline = {abi=1,size=64,generation=17,endpoint_kind=0,state=5,error=0,
|
|
auth_result=0,discovery_result=0,server_proof_verified=1,realm_count=3,
|
|
selected_index=-1,transport_prepared=0,cancel=0,auth_port=3724,copied_realms=3,
|
|
genuine_discovery=1};
|
|
for index=0,2 do
|
|
baseline["r"..index] = {type=({1,0,6})[index+1],flags=index==1 and 2 or 0,
|
|
characters=index+1,category=5,wire_id=70+index,population_text="0.125",
|
|
name=({"N'Zoth", "Y'Shaarj", "C'Thun"})[index+1],address="127.0.0.1:8085"};
|
|
end
|
|
local current, calls, requests, result = clone(baseline), 0, {}, 0;
|
|
local backend = {
|
|
GetSnapshot=function() calls=calls+1;return clone(current);end,
|
|
RequestRealm=function(index,generation)
|
|
requests[#requests+1]={index,generation};return result;
|
|
end,
|
|
};
|
|
local p = makeProvider(backend);
|
|
assert(not p.IsRealmListComplete());
|
|
assert(p.Refresh()); assert(calls==1);
|
|
local group=p.GetAvailableCategories()[1];
|
|
local name,tournament,locale=p.GetCategoryInfo(group);
|
|
assert(name=="Octo realms" and not tournament and not locale);
|
|
local indices=p.GetRealmsInCategory(group);
|
|
assert(#indices==3 and indices[1]==0 and indices[3]==2);
|
|
local first=p.GetRealmInfo(0);
|
|
assert(first.name=="N'Zoth" and first.isPvP and not first.isRP);
|
|
assert(first.sourceCategory==5 and first.sourceWireID==70);
|
|
assert(first.sourceCompatibilityUnobserved and first.versionMismatch==nil);
|
|
assert(first.populationState=="SOURCE" and p.GetPopulationLabel(first)=="0.125");
|
|
assert(p.GetRealmInfo(1).populationState=="OFFLINE");
|
|
assert(p.GetRealmInfo(2).isRP and not p.GetRealmInfo(2).isPvP);
|
|
indices[1]=999;first.name="changed";
|
|
assert(p.GetRealmsInCategory(group)[1]==0 and p.GetRealmInfo(0).name=="N'Zoth");
|
|
assert(calls==1); -- One shared snapshot, not another backend read per view accessor.
|
|
local accepted,status=p.ConnectToRealm(0);
|
|
assert(accepted and status=="requested" and #requests==1);
|
|
assert(requests[1][1]==0 and requests[1][2]==17 and calls==2);
|
|
assert(not p.ConnectToRealm(1) and #requests==1);
|
|
current.generation=18;assert(not p.ConnectToRealm(0) and #requests==1);
|
|
current=clone(baseline);current.r0.address="127.0.0.1:8086";
|
|
assert(not p.ConnectToRealm(0) and #requests==1);
|
|
current=clone(baseline);result=-1;
|
|
assert(not p.ConnectToRealm(0) and #requests==2);result=0;
|
|
current=clone(baseline);current.state=2;current.selected_index=0;
|
|
assert(p.Refresh());assert(not p.ConnectToRealm(0));
|
|
assert(not p.RequestChangeRealmList());
|
|
local before=calls;p.ClearRealmList();
|
|
assert(calls==before and not p.IsRealmListComplete() and #p.GetAvailableCategories()==0);
|
|
local invalid = {
|
|
{"server_proof_verified",0}, {"genuine_discovery",0}, {"auth_result",4},
|
|
{"discovery_result",1}, {"cancel",1}, {"error",1}, {"auth_port",8085},
|
|
{"generation",0}, {"endpoint_kind",3}, {"realm_count",65}, {"copied_realms",2},
|
|
};
|
|
for _,change in ipairs(invalid) do
|
|
current=clone(baseline);current[change[1]]=change[2];
|
|
assert(not p.Refresh() and not p.IsRealmListComplete());
|
|
end
|
|
current=clone(baseline);current.r2=nil;assert(not p.Refresh());
|
|
current=clone(baseline);current.r0.population_text="nan";assert(not p.Refresh());
|
|
current=clone(baseline);current.r0.type=16;assert(not p.Refresh());
|
|
current=clone(baseline);current.r0.name="bad\nrealm";assert(not p.Refresh());
|
|
assert(#p.GetRealmsInCategory(group)==0 and p.GetRealmInfo(0)==nil);
|
|
assert(not p.ConnectToRealm(0));
|
|
'''
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / 'provider-test.lua'
|
|
path.write_text(harness)
|
|
completed = subprocess.run([lua, str(path), str(provider)], capture_output=True, text=True)
|
|
self.assertEqual(completed.returncode, 0, completed.stderr)
|
|
|
|
|
|
def test_nonstandard_port_requires_profile5_bound_snapshot(self):
|
|
lua = shutil.which('lua') or shutil.which('lua5.4') or shutil.which('lua5.3')
|
|
if not lua:
|
|
self.skipTest('Lua interpreter unavailable')
|
|
harness = r'''
|
|
local makeProvider=assert(loadfile(arg[1]))();
|
|
local function base()
|
|
return {abi=1,size=64,generation=7,endpoint_kind=1,state=5,error=0,auth_result=0,
|
|
discovery_result=0,server_proof_verified=1,realm_count=1,selected_index=-1,
|
|
transport_prepared=0,cancel=0,auth_port=3725,copied_realms=1,genuine_discovery=1,
|
|
source_bound_profile=5,source_bound_auth_port=3725,source_bound_generation=7,
|
|
r0={name="Local",address="192.168.22.7:8111",type=1,flags=0,characters=0,
|
|
category=1,wire_id=4,population_text="1"}};
|
|
end
|
|
local value=base();local requests=0;
|
|
local p=makeProvider({GetSnapshot=function()return value;end,
|
|
RequestRealm=function(i,g)requests=requests+1;assert(i==0 and g==7);return 0;end});
|
|
assert(p.Refresh());assert(p.ConnectToRealm(0) and requests==1);
|
|
for _,change in ipairs({{"source_bound_profile",4},{"source_bound_auth_port",3724},
|
|
{"source_bound_generation",8},{"endpoint_kind",0},{"genuine_discovery",0},{"auth_port",0}}) do
|
|
value=base();value[change[1]]=change[2];assert(not p.Refresh());
|
|
end
|
|
value=base();value.source_bound_profile=nil;assert(not p.Refresh());
|
|
value=base();value.source_bound_auth_port=nil;assert(not p.Refresh());
|
|
value=base();value.source_bound_generation=nil;assert(not p.Refresh());
|
|
value=base();assert(p.Refresh());value.auth_port=3724;value.source_bound_auth_port=3724;
|
|
assert(not p.ConnectToRealm(0) and requests==1);
|
|
value=base();value.auth_port=3724;value.source_bound_profile=nil;
|
|
value.source_bound_auth_port=nil;value.source_bound_generation=nil;assert(p.Refresh());
|
|
'''
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / 'profile5-port-test.lua'
|
|
path.write_text(harness)
|
|
completed = subprocess.run([lua, str(path), str(ROOT / 'compat/glue/source_realm_provider.lua')], capture_output=True, text=True)
|
|
self.assertEqual(completed.returncode, 0, completed.stderr)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|