Format names of players who never joined the instance

Reports carry names from the controller, so the reported player, the
reporter or the caller may never have joined this server. The exp_util
formatter asserts the player exists, so those names now fall back to
plain white text. The test stub of the formatter now requires a LuaPlayer
like the real one, which made the existing receiver tests fail before the
fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-09-26 23:22:18 +00:00
1 parent 12ac7052a1
commit fd0401e781
2 files changed
+19 -3

No files matched your search

+13 -1
View File
@@ -9,7 +9,8 @@ player who asked once it arrives, if they are still online.
local clusterio_api = require("modules/clusterio/api")
local ExpUtil = require("modules/exp_util")
local format_player_name = ExpUtil.format_player_name_locale
local format_player_name_locale = ExpUtil.format_player_name_locale
local format_rich_text_color_locale = ExpUtil.format_rich_text_color_locale
--- @class ExpReports
local ExpReports = {
@@ -88,6 +89,17 @@ local function get_online_player(name)
return nil
end
--- Names come from the controller, so the player may never have joined this server
--- @param name string
--- @return LocalisedString
local function format_player_name(name)
local player = game.get_player(name)
if player then
return format_player_name_locale(player)
end
return format_rich_text_color_locale(name, ExpUtil.color.white)
end
--- The controller accepted a report
--- @param payload { report: ExpReports.Report, reports: ExpReports.Report[] }
function ExpReports.receive_created(payload)
+6 -2
View File
@@ -23,8 +23,12 @@ return Framework.suite(function(env)
--- @cast env ExpReports.TestEnv
env.extend_requires{
["modules/exp_util"] = {
format_player_name_locale = function(name) return name end,
color = { orange_red = "orange_red" },
format_player_name_locale = function(player)
assert(type(player) == "table", "format_player_name_locale takes a LuaPlayer")
return player.name
end,
format_rich_text_color_locale = function(message) return message end,
color = { orange_red = "orange_red", white = "white" },
},
}
env.Reports = assert(loadfile(plugin_root .. "/module/control.lua"))() --- @type ExpReports