Module:Sandbox/Vergir: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Testing InfoboxHero on shared HeroData helpers (with help from vergir-bot LLM) |
Diagnostic: check InfoboxHero render determinism (with help from vergir-bot LLM) Tag: Replaced |
||
| 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. | |||
-- Renders | -- {{#invoke:Sandbox/Vergir|selfdiff}} | ||
-- | |||
-- | |||
local p = {} | local p = {} | ||
local | local infobox = require('Module:InfoboxHero') | ||
local | 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 | |||
local function | |||
local | |||
for | |||
if | |||
end | end | ||
if #a ~= #b then return limit + 1 end | |||
return nil | |||
if | |||
return | |||
end | end | ||
function p.selfdiff(frame) | |||
function p. | |||
local keys = {} | local keys = {} | ||
if frame.args[1] and frame.args[1] ~= '' then | if frame.args[1] and frame.args[1] ~= '' then | ||
| Line 777: | Line 35: | ||
end | end | ||
local | local out = {} | ||
local mismatches = 0 | |||
for _, hero_key in ipairs(keys) do | for _, hero_key in ipairs(keys) do | ||
local child = frame:newChild{ args = { key = hero_key } } | local child = frame:newChild{ args = { key = hero_key } } | ||
local | local a = tostring(infobox.render(child)) | ||
local | local b = tostring(infobox.render(child)) | ||
local at = first_diff(a, b) | |||
if | if at ~= nil then | ||
mismatches = mismatches + 1 | |||
local from = math.max(1, at - 50) | |||
table.insert( | 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 | ||
end | end | ||
return ' | return 'Same module rendered twice per hero, heroes: ' .. #keys .. | ||
'\n\ | '\n\nNon-deterministic: ' .. mismatches .. '\n' .. table.concat(out, '\n') | ||
end | end | ||
return p | return p | ||
Revision as of 13:41, 11 August 2026
Documentation for this module may be created at Module:Sandbox/Vergir/doc
-- 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 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