local root=assert(arg[1]);local clock=100;local combat=false;local where='none';local width=1920 local P={Localized=function(a)return a end,hardwareProfile={checkedAt=100,loaded=true,thermalCoverage="full"}} Enum={PlayerSwingType={MainHand=0,OffHand=1,Ranged=2}} RuenUIDB={};RuenUICharacter={};UIParent={} local made={};local function noop()end function CreateFrame(_,name) local f={scripts={},shown=false} for _,k in ipairs({'SetSize','SetPoint','SetFrameStrata','EnableMouse','SetHeight','SetMinMaxValues','SetStatusBarTexture','SetStatusBarColor','RegisterEvent','RegisterUnitEvent','SetWidth','ClearAllPoints','SetAllPoints','SetColorTexture'})do f[k]=noop end function f:SetScript(k,v)self.scripts[k]=v end function f:Show()self.shown=true end;function f:Hide()self.shown=false end function f:SetValue(v)self.value=v end;function f:SetAlpha(v)self.alpha=v end function f:CreateTexture()return CreateFrame('Texture')end made[#made+1]=f;if name then _G[name]=f end;return f end function GetTime()return clock end;function time()return clock end function InCombatLockdown()return combat end local speeds={2,2.5,3};function UnitAttackSpeed()return unpack(speeds)end local secret={};function issecretvalue(v)return v==secret end assert(loadfile(root..'SwingTimers.lua'))('test',P) P.InitializeSwingTimers(function()return true end) local dock=RuenSwingTimers local event=dock.scripts.OnEvent assert(not dock.shown and not dock.scripts.OnUpdate) event(dock,'PLAYER_SWING',2,0);assert(dock.shown and dock.byType[0].shown) clock=101;dock.scripts.OnUpdate();assert(dock.byType[0].value==.5) event(dock,'PLAYER_SWING',3,2);event(dock,'PLAYER_SWING',2.5,1) assert(dock.byType[1].shown and dock.byType[2].shown) clock=105;dock.scripts.OnUpdate();assert(not dock.shown and not dock.scripts.OnUpdate) event(dock,'PLAYER_SWING',secret,0);event(dock,'PLAYER_SWING',3,secret);assert(not dock.shown) event(dock,'PLAYER_SWING',2,0);event(dock,'PLAYER_REGEN_ENABLED');assert(not dock.shown) event(dock,'PLAYER_SWING',2,1);speeds={2};event(dock,'UNIT_INVENTORY_CHANGED','player');assert(not dock.shown) combat=true;P.SwingCommand('preview');assert(not dock.shown);combat=false P.SwingCommand('preview');assert(dock.shown);P.SwingCommand('off');assert(not dock.shown and not dock.scripts.OnUpdate) print('PASS: three native swing lanes, progress, fade, no idle ticks, equipment, combat end, secret values, preview and off') local cvars={RenderScale='0.9',graphicsTextureResolution='2'};local writes=0 C_CVar={GetCVar=function(k)return cvars[k] or '2'end,SetCVar=function(k,v)assert(not combat,'graphics modified in combat');writes=writes+1;cvars[k]=tostring(v)end} function IsGraphicsSettingValueSupported()return 0 end function IsInInstance()return where~='none',where end function GetPhysicalScreenSize()return width,1080 end function GetRealZoneText()return 'Test zone' end function GetSubZoneText()return 'Test cave' end assert(loadfile(root..'FrameTiming.lua'))('test',P) assert(loadfile(root..'Optimizer.lua'))('test',P);P.InitializeOptimizer();local f=made[#made] local function frames(n,dt)for _=1,n do clock=clock+dt; if f.scripts.OnUpdate then f.scripts.OnUpdate(f,dt)end end end P.OptimizerCommand('start') assert(cvars.RAIDsettingsEnabled=='0' and cvars.RenderScale=='0.9','native overrides active or resolution changed') assert(cvars.graphicsLightMode=='0' and cvars.graphicsPBRLiquidDetail=='0','expensive lighting omitted') frames(66*600,1/66) local d=RuenUIDB.optimizer assert(d.profiles.world.calibrated and d.profiles.world.metTarget,'world should pass') assert(d.profiles.world.tier==5 and d.profiles.world.revision==2,'did not search/validate highest allowed tier') assert(d.profiles.world.last.phase=='validate' and d.profiles.world.subzone=='Test cave') assert(not d.profiles.raid.calibrated and not d.profiles.dungeon.calibrated,'solo validated instance') assert(cvars.maxFPS=='60' and not f.scripts.OnUpdate,'trial cap or idle polling leaked') local before=writes;frames(600,1/60);assert(writes==before) -- A plain command must remeasure this cave despite previous world success. P.OptimizerCommand('');assert(P.IsOptimizerCalibrating() and not d.profiles.world.calibrated) P.OptimizerCommand('pause');assert(not f.scripts.OnUpdate and not d.enabled) -- Entering a dungeon must measure/apply dungeon settings, not ignore it. where='party';P.OptimizerCommand('30');assert(d.requestedFPS==30 and d.target==30) frames(33*600,1/33) assert(d.profiles.dungeon.calibrated and d.profiles.dungeon.metTarget and cvars.maxFPS=='30') assert(d.profiles.dungeon.tier==5 and cvars.graphicsShadowQuality=='3') -- Combat defers ALL writes, including environment handoff and restore. where='raid';combat=true;before=writes;f.scripts.OnEvent(f,'ZONE_CHANGED_NEW_AREA') frames(33*120,1/33);assert(writes==before,'combat edits occurred') P.OptimizerCommand('restore');assert(RuenUIDB.optimizer==d) combat=false;f.scripts.OnEvent(f,'PLAYER_REGEN_ENABLED');frames(33*600,1/33) assert(d.profiles.raid.calibrated and not d.profiles.battleground.calibrated) where='pvp';f.scripts.OnEvent(f,'ZONE_CHANGED_NEW_AREA');frames(33*600,1/33) assert(d.profiles.battleground.calibrated and not f.scripts.OnUpdate) P.OptimizerCommand('restore');assert(not RuenUIDB.optimizer and cvars.RAIDsettingsEnabled=='2') assert(cvars.RenderScale=='0.9' and cvars.graphicsTextureResolution=='2','clarity settings lost') -- Sparse 200ms hitches escape p99 but MUST reject a candidate. Only low tiers -- are smooth here, so the chosen tier should stop at 2, with a capped validation. where='none';P.hardwareProfile={};P.OptimizerCommand('60') for i=1,66*600 do local dt=(tonumber(cvars.graphicsShadowQuality)>=2 and i%330==0) and .2 or 1/66 frames(1,dt) end d=RuenUIDB.optimizer assert(d.profiles.world.metTarget and d.profiles.world.tier==2,'brief stutters did not reject higher tier') local rejected=false for _,r in ipairs(d.profiles.world.history)do if r.over100>0 then rejected=true end end assert(rejected,'hitches not retained as evidence') -- Even a >2 second gameplay stall is counted; never silently drop it. P.OptimizerCommand('60') for i=1,66*400 do frames(1,i%330==0 and 2.5 or 1/66)end assert(d.profiles.world.calibrated and not d.profiles.world.metTarget and d.profiles.world.tier==1) assert(d.profiles.world.last.worstMS>=2500 and d.profiles.world.last.over250>0) -- Known loading periods are not gameplay; a fresh window follows them. P.OptimizerCommand('60');frames(66*12,1/66) f.scripts.OnEvent(f,'PLAYER_LEAVING_WORLD');frames(5,5) f.scripts.OnEvent(f,'PLAYER_ENTERING_WORLD');frames(66*600,1/66) assert(d.profiles.world.metTarget and d.profiles.world.last.worstMS<20) -- Invalid requests do not change target or start a measurement. before=writes;P.OptimizerCommand('19');P.OptimizerCommand('999');P.OptimizerCommand('world bad');P.OptimizerCommand('60 30') assert(writes==before and not P.IsOptimizerCalibrating()) -- FPS changed explicitly, report freshness/thermal ceiling, clean pause/undo. P.hardwareProfile={checkedAt=clock,loaded=true,thermalPressure=true} P.OptimizerCommand('60');assert(d.target==45 and d.ceiling==2) P.OptimizerCommand('30');assert(d.target==30 and d.requestedFPS==30) P.OptimizerCommand('pause');assert(not f.scripts.OnUpdate and not d.enabled) P.IsBenchmarkRunning=function()return true end;before=writes P.OptimizerCommand('60');assert(writes==before and not d.enabled) P.IsBenchmarkRunning=nil -- Unsupported options remain unchanged; a rejected write cannot be called applied. IsGraphicsSettingValueSupported=function(k)return k=='graphicsLightMode' and 1 or 0 end cvars.graphicsLightMode='2';P.OptimizerCommand('30');frames(33*600,1/33) assert(d.profiles.world.unsupported.graphicsLightMode and cvars.graphicsLightMode=='2') P.OptimizerCommand('pause') print('PASS: real frame tails/hitches, scene retest, capped validation, four environments, combat/loading guards, target parsing, unsupported settings, hardware evidence, exact restore and idle sleep') -- A different environment reached during a benchmark must wait until it ends. P.OptimizerCommand('resume');frames(33*600,1/33) P.IsBenchmarkRunning=function()return true end where='party';before=writes;f.scripts.OnEvent(f,'ZONE_CHANGED_NEW_AREA') assert(writes==before and not f.scripts.OnUpdate) P.IsBenchmarkRunning=nil;P.OptimizerBenchmarkEnded() assert(P.IsOptimizerCalibrating() and writes>before) frames(33*600,1/33);P.OptimizerCommand('pause') print('PASS: deferred environment handoff resumes after read-only benchmark')