Files
WoW-Hybrid-gateway/tests/octo_travel_observer_test.lua
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

105 lines
7.2 KiB
Lua

local root=arg[1];local frames={};local clock=10;local sent=0;local queried={};local zone='Tel Abim'
getglobal=function(n)return _G[n]end
CreateFrame=function()
local f={events={},scripts={}};table.insert(frames,f)
function f:RegisterEvent(e)if e=='TAXIMAP_CLOSED'then error('unsupported')end;self.events[e]=true end
function f:SetScript(k,v)self.scripts[k]=v end
function f:UnregisterAllEvents()self.events={}end
return f
end
SlashCmdList={};local messages={};DEFAULT_CHAT_FRAME={AddMessage=function(self,s)table.insert(messages,s)end}
GetTime=function()return clock end;time=function()return 12345 end
issecretvalue=function(v)return v=='SECRET'end
GetZoneText=function()return zone end;GetSubZoneText=function()return 'Air route'end
GetRealZoneText=GetZoneText;GetCurrentMapContinent=function()return 1 end;GetCurrentMapZone=function()return 9 end
GetPlayerMapPosition=function(u)assert(u=='player');return .2,.8 end
UnitOnTaxi=function(u)return u=='player'end
UnitExists=function(u)queried[u]=true;return u=='target' or u=='mouseover'end
UnitName=function(u)if u=='mouseover'then return 'SECRET'end;return 'Flight Master'end
UnitGUID=function()return 'Creature-1'end;UnitLevel=function()return 60 end
UnitIsPlayer=function()return false end;UnitCreatureType=function()return 'Humanoid'end
NumTaxiNodes=function()return 2 end;TaxiNodeName=function(i)return 'Destination '..i end
TaxiNodePosition=function(i)return .1*i,.2*i end;TaxiNodeGetType=function(i)return i==1 and'CURRENT'or'REACHABLE'end
SendChatMessage=function()sent=sent+1 end;SendAddonMessage=SendChatMessage
SetMapToCurrentZone=function()error('must not alter map')end
pfUI_cache={preserved=true}
local function load(fresh)
if fresh then WoWHybridTravelCapture=nil;pfUI_cache.WoWHybridTravelCapture=nil end
WoWHybridTravelObserver=nil
dofile(root..'/client_addons/OctoTravelCapture/Observer.lua')
local b=frames[#frames];event='PLAYER_LOGIN';b.scripts.OnEvent()
return WoWHybridTravelObserver,WoWHybridTravelCapture
end
local function ev(O,name,a,b)event=name;arg1=a;arg2=b;O.frame.scripts.OnEvent()end
local function tick(O,seconds)clock=clock+seconds;arg1=seconds;O.frame.scripts.OnUpdate()end
local function count(C,kind)local n=0;for _,r in ipairs(C.rows)do if r.kind==kind then n=n+1 end end;return n end
local O,C=load(true)
assert(O.active and sent==0 and pfUI_cache.preserved and #C.rows==2)
assert(C.rows[1].kind=='observer-ready'and C.latestReady==C.rows[1]and C.latestNonce==O.nonce)
assert(C.latestTravel.mapX==.2 and C.latestTravel.onTaxi and C.latestTravel.mounted==nil)
assert(C.capabilities.IsMounted==false and C.unsupportedEvents.TAXIMAP_CLOSED)
ev(O,'PLAYER_TARGET_CHANGED');assert(C.rows[#C.rows].name=='Flight Master'and C.eventCounts.PLAYER_TARGET_CHANGED==1)
ev(O,'UPDATE_MOUSEOVER_UNIT');assert(C.rows[#C.rows].name==nil and not queried.party1)
local n=#C.rows;ev(O,'PLAYER_TARGET_CHANGED');assert(#C.rows==n and C.coalesced.unit==1)
ev(O,'UNIT_FLAGS','party1');assert(#C.rows==n)
ev(O,'UNIT_FLAGS','player');assert(#C.rows==n and C.coalesced.travel==1)
tick(O,5);assert(#C.rows==n and C.latestTravel.time==clock) -- latest retained despite dedup
tick(O,30);assert(#C.rows==n+1 and C.rows[#C.rows].reason=='periodic')
ev(O,'TAXIMAP_OPENED');assert(count(C,'taxi-node')==2)
ev(O,'SPELLCAST_START','Travel Toy',1500)
assert(C.rows[#C.rows].kind=='spellcast'and C.rows[#C.rows].argument2==1500)
ev(O,'SPELLCAST_CHANNEL_START',2000,'Channel Toy');assert(C.rows[#C.rows].argument2=='Channel Toy')
ev(O,'SPELLCAST_FAILED','SECRET','SECRET');assert(C.rows[#C.rows].argument1==nil and C.rows[#C.rows].argument2==nil)
GetPlayerMapPosition=function()return 'SECRET',0/0 end
IsMounted=function()return 'SECRET'end
ev(O,'ZONE_CHANGED');assert(C.latestTravel.mapX==nil and C.latestTravel.mapY==nil and C.latestTravel.mounted==nil)
local previous=C.latestNonce;n=#C.rows;C.dropped=17
local O2,C2=load(false);assert(C2==C and C.loads==2 and C.dropped==17 and C.latestNonce~=previous and #C.rows==n+2)
assert(C.latestReady.nonce==O2.nonce and C.latestReady.revision=='octo-travel-v3')
WoWHybridTravelCapture=nil;local O3,C3=load(false);assert(C3==C and C.loads==3)
pfUI_cache={laterField=true};ev(O3,'PLAYER_LOGOUT');assert(pfUI_cache.WoWHybridTravelCapture==C and pfUI_cache.laterField)
SlashCmdList.WOWHYBRIDTRAVELCAPTURE('stop');n=#C.rows;tick(O3,5);ev(O3,'ZONE_CHANGED');assert(#C.rows==n and next(O3.frame.events)==nil)
-- Exact resolver origins and index/filter contract: no guessed fallback.
local queries={}
GetPlayerBuff=function(index,filter)
table.insert(queries,{index,filter});if index>(PLAYER_BUFF_START_ID or pfUI.env.PLAYER_BUFF_START_ID)+1 then return -1 end
return filter=='HELPFUL'and 7 or 9,true
end
GetPlayerBuffTexture=function(bid)return bid==7 and'Interface\\Icons\\PublicBuff'or'SECRET'end
GetPlayerBuffApplications=function()return 2 end
GetPlayerBuffTimeLeft=function(bid)return bid==7 and 12 or math.huge end
local cases={{-1,nil,nil,'global-vanilla-negative-one',0},{0,nil,nil,'global-tbc-zero',1},
{nil,-1,'vanilla','pfUI.env-vanilla-negative-one',0},{nil,0,'tbc','pfUI.env-tbc-zero',1},
{nil,0,'vanilla','unresolved-or-inconsistent-index-origin',nil},
{nil,-1,'tbc','unresolved-or-inconsistent-index-origin',nil},
{-2,-1,'vanilla','unresolved-or-inconsistent-index-origin',nil},
{nil,nil,'vanilla','unresolved-or-inconsistent-index-origin',nil}}
for _,v in ipairs(cases)do
PLAYER_BUFF_START_ID=v[1];pfUI={env={PLAYER_BUFF_START_ID=v[2]},expansion=v[3]};queries={}
local A,B=load(true);assert(B.auraIndexOrigin==v[4])
if v[5]then
assert(queries[1][1]==v[5]and queries[1][2]=='HELPFUL'and count(B,'aura')==2)
local first
for _,r in ipairs(B.rows)do if r.kind=='aura'and r.filter=='HELPFUL'then first=r;break end end
assert(first.texture=='Interface\\Icons\\PublicBuff'and first.timeLeft==12 and first.stacks==2)
n=#B.rows;ev(A,'PLAYER_AURAS_CHANGED');assert(#B.rows==n) -- identical aura events coalesced
else assert(#queries==0 and count(B,'aura')==0)end
end
-- Priority reserve and bounded latest state survive a completely full history/reload.
PLAYER_BUFF_START_ID=nil;pfUI=nil;GetPlayerBuff=nil;GetPlayerBuffTexture=nil
local A,B=load(true);A.maxRows=8;B.dropped=0
for i=1,4 do ev(A,'SPELLCAST_START','Toy '..i,1000)end
assert(#B.rows==6);ev(A,'SPELLCAST_START','Held toy',1000);assert(#B.rows==6 and B.dropped==1)
zone='First reserve zone';ev(A,'ZONE_CHANGED');assert(#B.rows==7 and B.latestTravel.zone==zone)
zone='Second reserve zone';ev(A,'ZONE_CHANGED');assert(#B.rows==8)
zone='Latest despite full history';ev(A,'ZONE_CHANGED');assert(#B.rows==8 and B.latestTravel.zone==zone and B.dropped>1)
local prefix={};for i,r in ipairs(B.rows)do prefix[i]=r end
-- Simulate the real fixed4096 cap with a prefilled prior capture, no automatic reset.
while #B.rows<4096 do table.insert(B.rows,prefix[1])end
local lost=B.dropped;local nextO,nextC=load(false)
assert(#nextC.rows==4096 and nextC.dropped>lost and nextC.latestReady.nonce==nextO.nonce)
assert(nextC.latestTravel.nonce==nextO.nonce and nextC.latestTravel.zone==zone)
for i,r in ipairs(prefix)do assert(nextC.rows[i]==r)end
assert(sent==0)
print('Travel v3 PASS: exact global/pfUI index origins; passive cast/aura; dedup+priority reserve; bounded latest state and activation at full history; persistence, secrets and no sends.')