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 -12
View File
@@ -2,42 +2,48 @@
local Suite = ... --- The suite this file adds its tests to, see test/lua/framework.lua
local test, check, eq = Suite.test, Suite.check, Suite.eq
test("get_role returns the role with the given clusterio id", function(env)
test("get_role() returns the role with the given clusterio id", function(env)
env.initialise{}
check(env.Roles.get_role(6).name == "Regular", "the role is found by id")
check(env.Roles.get_role(env.R("Jail").id) == env.R("Jail"), "lookups return the same object")
check(env.Roles.get_role(env.R("Regular").id) == env.R("Regular"), "the role is found by id")
check(env.Roles.get_role(9) == nil, "deleted roles are not known")
end)
test("get_role_by_name searches the roles", function(env)
test("get_role_by_name() searches the roles", function(env)
env.initialise{}
check(env.Roles.get_role_by_name("Moderator").id == 5, "the role is found by name")
check(env.Roles.get_role_by_name("Moderator") == env.R("Moderator"), "the role is found by name")
check(env.Roles.get_role_by_name("Gone") == nil, "deleted roles are not known")
end)
test("get_roles returns every role", function(env)
test("get_roles() returns every role", function(env)
env.initialise{}
check(#env.Roles.get_roles() == 5, "every role is returned with deleted roles skipped")
end)
test("get_ordered_roles returns the most privileged first", function(env)
test("get_ordered_roles() returns the most privileged first", function(env)
env.initialise{}
eq(Suite.names(env.Roles.get_ordered_roles()), { "Cluster Admin", "Moderator", "Regular", "Jail", "Player" },
"roles follow their order")
end)
test("sort_roles orders most privileged first", function(env)
test("sort_roles() orders most privileged first and breaks ties on the id", function(env)
env.initialise{}
local sorted = env.Roles.sort_roles{ env.R("Player"), env.R("Cluster Admin"), env.R("Regular") }
eq(Suite.names(sorted), { "Cluster Admin", "Regular", "Player" }, "the list is sorted in place")
-- A role with the same order as Regular but a higher id sorts after it
env.Roles.receive_role_updates{
{ id = 10, name = "Twin", permissions = {}, meta = { id = 0, order = env.R("Regular").order } },
}
local tied = env.Roles.sort_roles{ env.R("Twin"), env.R("Regular") }
eq(Suite.names(tied), { "Regular", "Twin" }, "order ties break on the id")
end)
test("get_default_role follows is_default", function(env)
test("get_default_role() follows is_default", function(env)
env.initialise{}
check(env.Roles.get_default_role() == env.R("Player"), "the default role is known")
end)
test("get_higher_roles and get_lower_roles include the role and exclude the default", function(env)
test("get_higher_roles() and get_lower_roles() include the role and exclude the default", function(env)
env.initialise{}
eq(Suite.sorted(Suite.names(env.Roles.get_higher_roles(env.R("Regular")))),
{ "Cluster Admin", "Moderator", "Regular" }, "higher roles")
@@ -45,14 +51,14 @@ test("get_higher_roles and get_lower_roles include the role and exclude the defa
{ "Jail", "Regular" }, "lower roles")
end)
test("role:is_higher_than and role:is_lower_than compare on order", function(env)
test(".is_higher_than() and .is_lower_than() compare on order", function(env)
env.initialise{}
check(env.R("Moderator"):is_higher_than(env.R("Player")), "a lower order is more privileged")
check(env.R("Player"):is_lower_than(env.R("Moderator")), "is_lower_than is the reverse")
check(not env.R("Moderator"):is_higher_than(env.R("Moderator")), "a role is not higher than itself")
end)
test("initialise decodes the role records", function(env)
test("initialise() decodes the role records", function(env)
env.initialise{}
check(env.R("Cluster Admin").short_hand == "SYS", "short hand decoded")
check(env.R("Moderator").short_hand == "Moderator", "short hand falls back to the name")