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

262 lines
14 KiB
Lua

-- Source metadata appended to the original tooltip; no actual client/network.
local callbacks, hooks, registered = {}, {}, 0
local secrets = {}
issecretvalue = function(value) return secrets[value] or false end
GetLocale = function() return "enUS" end
Enum = {TooltipDataType = {Item = 0}}
TooltipDataProcessor = {AddTooltipPostCall = function(kind, callback)
assert(kind == 0); callbacks[#callbacks + 1] = callback; registered = registered + 1
end}
hooksecurefunc = function(owner, method, callback)
assert(method == "ClearLines" and type(owner[method]) == "function")
hooks[owner] = callback
end
local infoCalls = 0
C_Item = {GetItemInfoInstant = function(id)
infoCalls = infoCalls + 1
return id, 'Weapon', 'Sword', 'INVTYPE_WEAPON', 1, 2, 7
end}
C_Item.GetItemInfo = function(id)
return 'Loaded source weapon', nil, 4, 60, 60, 'Weapon', 'Sword', 1, 'INVTYPE_WEAPON', 1, 0, 2
end
local originalAPI = C_Item
GatewaySourceWeaponDamageData = {
schemaVersion = 1, locale = "enUS", schools = {[0] = "Physical", "Holy", "Fire", "Nature", "Frost", "Shadow", "Arcane"},
items = {
[19019] = {{index = 1, school = 3, minimum = 16, maximum = 30}},
[600001] = {{index = 1, school = 0, minimum = .5, maximum = 2.25}, {index = 4, school = 6, minimum = 9, maximum = 10}},
},
}
local source = arg[1] .. '/client_addons/GatewayDiagnostics/SourceWeaponDamage.lua'
dofile(source)
assert(registered == 1)
local callback = callbacks[1]
local function tooltip()
local self = {lines = {'native primary', 'native speed and DPS', 'native proc'}}
function self:ClearLines()
self.lines = {'native rebuilt primary', 'native rebuilt speed and DPS', 'native rebuilt proc'}
if hooks[self] then hooks[self]() end
end
function self:AddLine(text, r, g, b, wrap)
assert(type(text) == 'string' and r == 1 and g == 1 and b == 1 and wrap == false)
self.lines[#self.lines + 1] = text
end
return self
end
local first, comparison = tooltip(), tooltip()
callback(first, {type = 0, id = 19019})
assert(#first.lines == 4 and first.lines[4] == '+16 - 30 Nature Damage')
assert(first.lines[1] == 'native primary' and first.lines[2] == 'native speed and DPS' and first.lines[3] == 'native proc')
callback(first, {type = 0, id = 19019})
assert(#first.lines == 4) -- Repeated callback/append does not double source line.
first:ClearLines(); callback(first, {type = 0, id = 19019})
assert(#first.lines == 4 and first.lines[1] == 'native rebuilt primary')
callback(comparison, {type = 0, id = 19019})
assert(#comparison.lines == 4) -- Separate original comparison tooltip works.
first:ClearLines(); callback(first, {type = 0, id = 600001})
assert(#first.lines == 5 and first.lines[4] == '+0.5 - 2.25 Physical Damage' and first.lines[5] == '+9 - 10 Arcane Damage')
assert(C_Item == originalAPI and infoCalls > 0)
local private = setmetatable({}, {__index = function() error('Private object indexed') end, __tostring = function() error('Private object stringified') end})
secrets[private] = true
for _, data in ipairs({{}, {type = 1, id = 19019}, {type = 0, id = 0}, {type = 0, id = -1},
{type = 0, id = 1.5}, {type = 0, id = '19019'}, {type = 0, id = 2147483648}, {type = 0, id = private}, private}) do
local t = tooltip(); callback(t, data); assert(#t.lines == 3)
end
callback(private, {type = 0, id = 19019})
local function rejects()
local t = tooltip(); callback(t, {type = 0, id = 19019}); assert(#t.lines == 3)
end
local good = GatewaySourceWeaponDamageData.items[19019]
for _, band in ipairs({
{index = 0, school = 3, minimum = 16, maximum = 30},
{index = 5, school = 3, minimum = 16, maximum = 30},
{index = 1, school = 7, minimum = 16, maximum = 30},
{index = 1, school = 3, minimum = -1, maximum = 30},
{index = 1, school = 3, minimum = 16, maximum = 0},
{index = 1, school = 3, minimum = 16, maximum = 15},
{index = 1, school = 3, minimum = 16, maximum = math.huge},
{index = 1, school = 3, minimum = 16, maximum = 0/0},
{index = 1, school = 3, minimum = 16, maximum = private}, private,
}) do
GatewaySourceWeaponDamageData.items[19019] = {band}; rejects()
end
GatewaySourceWeaponDamageData.items[19019] = {good[1], good[1]}; rejects() -- Reject whole duplicate slot list, no partial append.
GatewaySourceWeaponDamageData.items[19019] = good
GetLocale = function() return 'deDE' end; rejects()
GetLocale = function() return 'enUS' end
local query = C_Item.GetItemInfoInstant
for _, replacement in ipairs({function() end, function() error('private error must stay private') end,
function() return 1, '', '', '', 0, 2 end, function() return 19019, '', '', '', 0, 4 end,
function() return private, '', '', '', 0, 2 end}) do
C_Item.GetItemInfoInstant = replacement; rejects()
end
C_Item.GetItemInfoInstant = query
local full = C_Item.GetItemInfo
for _, replacement in ipairs({function() end, function() error('full metadata unavailable') end,
function() return private end, function() return 'Loaded', nil, 4, 60, 60, '', '', 1, '', 1, 0, 4 end}) do
C_Item.GetItemInfo = replacement; rejects()
end
C_Item.GetItemInfo = nil; rejects()
C_Item.GetItemInfo = full
local publicHook = hooksecurefunc
hooksecurefunc = nil; rejects()
hooksecurefunc = function() error('unsupported lifecycle') end; rejects()
hooksecurefunc = publicHook
local schools = GatewaySourceWeaponDamageData.schools
GatewaySourceWeaponDamageData.schools = {[3] = 'Unreviewed Label'}; rejects()
GatewaySourceWeaponDamageData.schools = schools
local t = tooltip(); callback(t, {type = 0, id = 999999}); assert(#t.lines == 3)
TooltipDataProcessor = nil; dofile(source) -- Unsupported API remains a no-op.
assert(registered == 1)
print('Original tooltip source weapon-band fixtures passed; no engine multi-band claim')
local pre, linePre
Enum.TooltipDataLineType = {None = 0}
TooltipDataProcessor = {
AddTooltipPostCall = function() end,
AddTooltipPreCall = function(kind, callback) assert(kind == 0); pre = callback end,
AddLinePreCall = function(kind, callback) assert(kind == 0); linePre = callback end,
}
GatewaySourceWeaponDamageData.schemaVersion = 2
GatewaySourceWeaponDamageData.primary = {[600001] = {minimum = 94, maximum = 175, delayMS = 2800, dps = 48.0357142857}}
dofile(source)
local function base(name, arg)
local t = tooltip()
t.info = {getterName = name or 'GetHyperlink', getterArgs = {arg or 'item:600001'}}
function t:GetProcessingTooltipInfo() return self.info end
function t:AddDoubleLine(left, right, ...) self.lines[#self.lines + 1] = left .. '|' .. right end
return t
end
local data = {type = 0, id = 600001}
local damageLine = {type = 0, leftText = '94 - 176 Damage', rightText = 'Speed 2.80'}
local dpsLine = {type = 0, leftText = '(48.2 damage per second)'}
local t = base()
pre(t, data)
assert(linePre(t, damageLine) == true and t.lines[4] == '94 - 175 Damage|Speed 2.80')
assert(linePre(t, dpsLine) == true and t.lines[5] == '(48.0 damage per second)')
assert(not linePre(t, damageLine) and not linePre(t, dpsLine) and #t.lines == 5)
local diag = GatewaySourceWeaponDamageDiagnostics
assert(diag.baseTooltips == 1 and diag.damageLines == 1 and diag.dpsLines == 1 and diag.errors == 0)
for _, spec in ipairs({{'GetItemByID', 600001}, {'GetHyperlink', 'item:600001'}}) do
t = base(spec[1], spec[2]); pre(t, data)
assert(not linePre(t, dpsLine)) -- Cannot change an unrelated DPS line first.
assert(linePre(t, damageLine))
pre(t, {type = 0, id = 999999}) -- Reused tooltip drops previous context.
assert(not linePre(t, dpsLine))
end
for _, spec in ipairs({{'GetBagItem', 0}, {'GetInventoryItem', 'player'},
{'GetHyperlink', 'item:600001:1234'}, {'GetHyperlink', '|Hitem:600001|h[Weapon]|h'},
{'GetItemByID', 600002}, {'GetHyperlink', private}}) do
t = base(spec[1], spec[2]); pre(t, data)
assert(not linePre(t, damageLine) and #t.lines == 3)
end
t = base(); pre(t, data)
for _, line in ipairs({{type = 45, leftText = '94 - 176 Damage', rightText = 'Speed 2.80'},
{type = 0, leftText = 'Equip: 94 - 176 Damage', rightText = 'Speed 2.80'},
{type = 0, leftText = private, rightText = 'Speed 2.80'},
{type = 0, leftText = '94 - 176 Damage', rightText = private}, private}) do
assert(not linePre(t, line) and #t.lines == 3)
end
assert(linePre(t, damageLine))
assert(not linePre(t, {type = 0, leftText = '(48.2 damage per second)', rightText = private}))
local originalPrimary = GatewaySourceWeaponDamageData.primary[600001]
for _, row in ipairs({{minimum = -1, maximum = 175, delayMS = 2800, dps = 48},
{minimum = 94, maximum = 175, delayMS = 0, dps = 48},
{minimum = 94, maximum = 175, delayMS = 2800, dps = math.huge}, private}) do
GatewaySourceWeaponDamageData.primary[600001] = row
t = base(); pre(t, data); assert(not linePre(t, damageLine))
end
GatewaySourceWeaponDamageData.primary[600001] = originalPrimary
GetLocale = function() return 'deDE' end
t = base(); pre(t, data); assert(not linePre(t, damageLine))
GetLocale = function() return 'enUS' end
GatewaySourceWeaponDamageData.schemaVersion = 1
t = base(); pre(t, data); assert(not linePre(t, damageLine))
assert(diag.errors == 0 and C_Item == originalAPI)
print('Source primary base-tooltip fixtures passed; instance tooltips and compiled APIs unchanged')
GatewaySourceWeaponDamageData.schemaVersion = 2
GatewaySourceWeaponDamageData.baseEquivalentInstances = true
local nativeData = {type = 0, id = 600001, lines = {damageLine, dpsLine}}
C_TooltipInfo = {GetItemByID = function(id) assert(id == 600001); return nativeData end}
local instanceData = {type = 0, id = 600001, lines = {damageLine, dpsLine}}
for _, spec in ipairs({{'GetInventoryItem', 'player'}, {'GetBagItem', 0}, {'GetHyperlink', 'item:600001:1234'}}) do
t = base(spec[1], spec[2]); pre(t, instanceData)
assert(linePre(t, damageLine) and linePre(t, dpsLine))
assert(t.lines[4] == '94 - 175 Damage|Speed 2.80' and t.lines[5] == '(48.0 damage per second)')
end
assert(diag.instanceBaseMatches == 3)
for _, changed in ipairs({{type = 0, leftText = '94 - 180 Damage', rightText = 'Speed 2.80'},
{type = 0, leftText = '94 - 176 Damage', rightText = 'Speed 3.80'},
{type = 0, leftText = private, rightText = 'Speed 2.80'}}) do
t = base('GetInventoryItem', 'player');pre(t, {type = 0, id = 600001, lines = {changed, dpsLine}})
assert(not linePre(t, damageLine) and #t.lines == 3)
end
t = base('GetInventoryItem', 'player')
pre(t, {type = 0, id = 600001, lines = {damageLine, {type = 0, leftText = '(99.9 damage per second)'}}})
assert(not linePre(t, damageLine))
pre(t, {type = 0, id = 600001, lines = {damageLine, damageLine, dpsLine}})
assert(not linePre(t, damageLine))
GatewaySourceWeaponDamageData.baseEquivalentInstances = false
pre(t, instanceData);assert(not linePre(t, damageLine))
GatewaySourceWeaponDamageData.baseEquivalentInstances = true
nativeData.id = 600002
pre(t, instanceData);assert(not linePre(t, damageLine))
nativeData.id = 600001
pre(t, instanceData)
-- A different line after prepare cannot use another line's equality proof.
assert(not linePre(t, {type = 0, leftText = '95 - 177 Damage', rightText = 'Speed 2.80'}))
assert(linePre(t, damageLine))
assert(diag.errors == 0 and C_Item == originalAPI)
print('Base-equivalent instance lines verified independently; differing bonuses fail closed')
-- Scope3 is generated for physical bow/gun/crossbow records. The original
-- callback contract, instance equality checks and secret guards stay intact.
GatewaySourceWeaponDamageData.schemaVersion = 3
t = base('GetInventoryItem', 'player');pre(t, instanceData)
assert(linePre(t, damageLine) and linePre(t, dpsLine))
assert(diag.errors == 0 and C_Item == originalAPI)
GatewaySourceWeaponDamageData.schemaVersion = 4
t = base('GetInventoryItem', 'player');pre(t, instanceData)
assert(not linePre(t, damageLine))
print('Explicit physical-ranged profile version accepted; unknown versions rejected')
-- Scope4 retains the source primary damage school for wands. It still
-- requires independently equal native base/instance lines and public values.
GatewaySourceWeaponDamageData.schools[2] = 'Fire'
originalPrimary.school = 2
local fireLine = {type = 0, leftText = '94 - 176 Fire Damage', rightText = 'Speed 2.80'}
nativeData.lines = {fireLine, dpsLine}
t = base('GetInventoryItem', 'player');pre(t, {type = 0, id = 600001, lines = {fireLine, dpsLine}})
assert(linePre(t, fireLine) and linePre(t, dpsLine))
assert(t.lines[4] == '94 - 175 Fire Damage|Speed 2.80')
originalPrimary.school = 0
nativeData.lines = {damageLine, dpsLine}
t = base('GetInventoryItem', 'player');pre(t, instanceData)
assert(linePre(t, damageLine) and t.lines[4] == '94 - 175 Damage|Speed 2.80')
nativeData.lines = {fireLine, dpsLine}
for _, school in ipairs({-1, 7, private}) do
originalPrimary.school = school
t = base();pre(t, data);assert(not linePre(t, fireLine))
end
originalPrimary.school = 2
t = base('GetInventoryItem', 'player');pre(t, instanceData)
assert(not linePre(t, damageLine)) -- Physical instance does not equal native fire base.
GatewaySourceWeaponDamageData.schemaVersion = 6
t = base();pre(t, data);assert(not linePre(t, fireLine))
assert(diag.errors == 0 and C_Item == originalAPI)
print('Source wand school presentation verified; modified instances and unknown versions rejected')
GatewaySourceWeaponDamageData.schemaVersion = 5
originalPrimary.school = 0
nativeData.lines = {damageLine, dpsLine}
t = base('GetInventoryItem', 'player');pre(t, instanceData)
assert(linePre(t, damageLine) and linePre(t, dpsLine))
assert(t.lines[4] == '94 - 175 Damage|Speed 2.80')
assert(diag.errors == 0 and C_Item == originalAPI)
print('Explicit physical thrown scope accepted with original instance safeguards')
-- The original shopping manager supplies raw data without a getter; include
-- that regression in the existing registered provider fixture as well.
dofile(arg[1] .. "/tests/source_weapon_damage_comparison_test.lua")