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
+22 -13
View File
@@ -5,18 +5,18 @@ local test, check, eq = Suite.test, Suite.check, Suite.eq
--- alice is a moderator, bob is a regular, and carol has only the default role
local function setup(env)
local players = {
alice = env.add_player("alice", 1),
bob = env.add_player("bob", 2),
carol = env.add_player("carol", 3),
alice = env.add_player("alice"),
bob = env.add_player("bob"),
carol = env.add_player("carol"),
}
env.initialise{
env.assignment("alice", { 5 }),
env.assignment("bob", { 6 }),
env.assignment("alice", { "Moderator" }),
env.assignment("bob", { "Regular" }),
}
return players
end
test("get_player_roles includes the default role", function(env)
test("get_player_roles() includes the default role", function(env)
local players = setup(env)
eq(Suite.sorted(Suite.names(env.Roles.get_player_roles(players.alice))), { "Moderator", "Player" },
"held roles and the default role")
@@ -24,7 +24,7 @@ test("get_player_roles includes the default role", function(env)
"a player with no roles has the default role")
end)
test("get_player_roles treats nil and index 0 as the server", function(env)
test("get_player_roles() treats nil and index 0 as the server", function(env)
setup(env)
eq(Suite.names(env.Roles.get_player_roles(nil)), { "<server>" }, "nil is the server")
eq(Suite.names(env.Roles.get_player_roles(env.server)), { "<server>" }, "index 0 is the server")
@@ -32,20 +32,28 @@ test("get_player_roles treats nil and index 0 as the server", function(env)
check(not env.R("Player"):has_player(nil), "the server does not have the default role")
end)
test("get_player_highest_role", function(env)
test("get_player_highest_role() returns the most privileged role", function(env)
local players = setup(env)
check(env.Roles.get_player_highest_role(players.alice) == env.R("Moderator"), "the highest held role")
check(env.Roles.get_player_highest_role(players.carol) == env.R("Player"), "the default role when none are held")
end)
test("player_has_permission", function(env)
test("get_player_highest_role() errors when a player has no roles", function(env)
local players = setup(env)
env.Roles.receive_role_updates{
{ id = env.R("Player").id, name = "Player", permissions = {}, meta = { id = 0, order = 5 }, is_deleted = true },
}
check(not pcall(env.Roles.get_player_highest_role, players.carol), "no default role and no held roles errors")
end)
test("player_has_permission()", function(env)
local players = setup(env)
check(env.Roles.player_has_permission(players.alice, "exp_scenario.command.kill"), "granted by a held role")
check(env.Roles.player_has_permission(players.alice, "exp_scenario.gui.readme"), "granted by the default role")
check(not env.Roles.player_has_permission(players.bob, "exp_scenario.command.jail"), "not granted")
end)
test("player_has_any_permission and player_has_all_permission", function(env)
test("player_has_any_permission() and player_has_all_permission()", function(env)
local players = setup(env)
local jail, kill = "exp_scenario.command.jail", "exp_scenario.command.kill"
check(env.Roles.player_has_any_permission(players.bob, jail, kill), "any passes when one is granted")
@@ -56,23 +64,24 @@ test("player_has_any_permission and player_has_all_permission", function(env)
check(not env.Roles.player_has_all_permission(players.bob, jail, kill), "all fails when one is missing")
check(env.Roles.player_has_all_permission(players.bob), "all of none is true")
check(env.Roles.player_has_any_permission(nil, "anything.at.all"), "the server passes any")
check(env.Roles.player_has_all_permission(nil, "anything.at.all", "and.this.too"), "the server passes all")
end)
test("role:has_permission", function(env)
test(".has_permission()", function(env)
setup(env)
check(env.R("Moderator"):has_permission("exp_scenario.command.kill"), "granted")
check(not env.R("Regular"):has_permission("exp_scenario.command.jail"), "not granted")
check(env.R("Cluster Admin"):has_permission("anything.at.all"), "core.admin grants everything")
end)
test("role:has_player", function(env)
test(".has_player()", function(env)
local players = setup(env)
check(env.R("Moderator"):has_player(players.alice), "a held role")
check(not env.R("Moderator"):has_player(players.bob), "a role not held")
check(env.R("Player"):has_player(players.carol), "everyone has the default role")
end)
test("player_outranks", function(env)
test("player_outranks()", function(env)
local players = setup(env)
check(env.Roles.player_outranks(players.alice, players.bob), "a higher role outranks a lower one")
check(not env.Roles.player_outranks(players.bob, players.alice), "a lower role does not outrank a higher one")