Address review on the suite and instance tests

- The instance tests run against a real Instance with a real InstanceConfig,
  matching the controller tests: the spies are sendTo and the server, which
  record what leaves the instance, so sendRcon passes through the real script
  command gate. The plugin's config fields are registered so the sync mode is
  a real field.
- Shallow eq is gone and eq compares recursively; the suite is created with
  Framework.suite(extend_env), which hands the extension a fresh set of stubs
  per test, so the plugin's env.lua is only the extension.
- add_player assigns continuous indexes itself.
- The lua fixtures are referenced by role name: assignments take names, and
  ids in expectations come from the role object. The name lookup in env.R
  uses a fixture index rather than searching the roles.
- Test names format functions as name() and methods as .name().
- Branch coverage filled in: sort tie breaking, the highest role assertion
  when a player has no roles, has all for the server, the by player default
  from game.player, deleted assignment records on initialise, set_emit_events
  with no argument, printing to a role with no holders, role property update
  validation, the assignment subscription replay, unassignment over the ipc,
  and a refused removal having nothing to roll back.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-25 21:11:58 +00:00
co-authored by Claude Fable 5
parent e6552a39be
commit 3218351db6
12 changed files with 340 additions and 234 deletions
+18 -17
View File
@@ -5,52 +5,53 @@ local test, check, eq = Suite.test, Suite.check, Suite.eq
--- alice and dave are moderators with dave offline, zed has never joined
local function setup(env)
local players = {
alice = env.add_player("alice", 1),
bob = env.add_player("bob", 2),
dave = env.add_player("dave", 4, false),
alice = env.add_player("alice"),
bob = env.add_player("bob"),
dave = env.add_player("dave", false),
}
env.initialise{
env.assignment("alice", { 5 }),
env.assignment("bob", { 6 }),
env.assignment("dave", { 5 }),
env.assignment("zed", { 5 }),
env.assignment("alice", { "Moderator" }),
env.assignment("bob", { "Regular" }),
env.assignment("dave", { "Moderator" }),
env.assignment("zed", { "Moderator" }),
}
env.Roles.set_emit_events(true)
return players
end
test("role:get_player_names includes players not on this map", function(env)
test(".get_player_names() includes players not on this map", function(env)
setup(env)
eq(Suite.sorted(env.R("Moderator"):get_player_names()), { "alice", "dave", "zed" },
"every player given the role is listed")
end)
test("role:get_player_names counts a player in both lists once", function(env)
test(".get_player_names() counts a player in both lists once", function(env)
local players = setup(env)
env.R("Regular"):assign(players.alice, { silent = true, local_only = true })
env.Roles.receive_assignment_updates{ env.assignment("alice", { 5, 6 }) }
env.Roles.receive_assignment_updates{ env.assignment("alice", { "Moderator", "Regular" }) }
local sd = env.Roles._script_data()
check(sd.local_players.alice ~= nil and sd.synced_players.alice ~= nil, "the role is held in both lists")
eq(Suite.sorted(env.R("Regular"):get_player_names()), { "alice", "bob" }, "the player is counted once")
end)
test("role:get_players is limited to this map and can be filtered", function(env)
test(".get_players() is limited to this map and can be filtered", function(env)
setup(env)
local mod = env.R("Moderator")
eq(Suite.sorted(Suite.names(mod:get_players())), { "alice", "dave" }, "players are limited to this map")
eq(Suite.names(mod:get_players(true)), { "alice" }, "filtered to connected players")
eq(Suite.names(mod:get_players(false)), { "dave" }, "filtered to offline players")
local moderator = env.R("Moderator")
eq(Suite.sorted(Suite.names(moderator:get_players())), { "alice", "dave" }, "players are limited to this map")
eq(Suite.names(moderator:get_players(true)), { "alice" }, "filtered to connected players")
eq(Suite.names(moderator:get_players(false)), { "dave" }, "filtered to offline players")
end)
test("role:print reaches online holders", function(env)
test(".print() reaches online holders", function(env)
setup(env)
env.reset_log()
check(env.R("Moderator"):print("hello") == 1, "print returns the number of players reached")
check(#env.printed == 1 and env.printed[1].to == "alice", "only online holders are reached")
check(env.R("Jail"):print("hello") == 0, "a role with no online holders reaches nobody")
end)
test("role:print over get_higher_roles can repeat", function(env)
test(".print() over get_higher_roles() can repeat", function(env)
local players = setup(env)
env.R("Regular"):assign(players.alice, { silent = true, local_only = true })
env.reset_log()