Module:Sandbox/Vergir: Difference between revisions

Vergir (talk | contribs)
Diagnostic: check InfoboxHero render determinism (with help from vergir-bot LLM)
Tag: Replaced
Cleanup after audit (with help from vergir-bot LLM)
Tag: Replaced
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- TEMPORARY diagnostic.
-- Renders heroes through the LIVE Module:InfoboxHero twice each and compares the
-- two outputs, to establish whether rendering is deterministic at all.
-- {{#invoke:Sandbox/Vergir|selfdiff}}
local p = {}
local p = {}
local infobox = require('Module:InfoboxHero')
local SAMPLE_HEROES = {
'hero_atlas',
'hero_viscous',
'hero_haze',
'hero_werewolf',
'hero_targetdummy',
}
-- Byte offset of the first difference, or nil when the strings are equal.
local function first_diff(a, b)
local limit = math.min(#a, #b)
for i = 1, limit do
if a:sub(i, i) ~= b:sub(i, i) then return i end
end
if #a ~= #b then return limit + 1 end
return nil
end
function p.selfdiff(frame)
local keys = {}
if frame.args[1] and frame.args[1] ~= '' then
for key in string.gmatch(frame.args[1], '[^,%s]+') do
table.insert(keys, key)
end
else
keys = SAMPLE_HEROES
end
local out = {}
local mismatches = 0
for _, hero_key in ipairs(keys) do
local child = frame:newChild{ args = { key = hero_key } }
local a = tostring(infobox.render(child))
local b = tostring(infobox.render(child))
local at = first_diff(a, b)
if at ~= nil then
mismatches = mismatches + 1
local from = math.max(1, at - 50)
local to = at + 50
table.insert(out, '* <code>' .. hero_key .. '</code> differs at byte ' .. at ..
' (len ' .. #a .. ' vs ' .. #b .. ')')
table.insert(out, '** A: <code>' .. mw.text.nowiki(a:sub(from, to)) .. '</code>')
table.insert(out, '** B: <code>' .. mw.text.nowiki(b:sub(from, to)) .. '</code>')
end
end
return 'Same module rendered twice per hero, heroes: ' .. #keys ..
'\n\nNon-deterministic: ' .. mismatches .. '\n' .. table.concat(out, '\n')
end
return p
return p