Address review on the stubs and controller tests

- The controller tests run against a real Controller, which is side effect
  free while not started, with real users through its UserManager. The only
  fakes left are two spies which record broadcasts and permission pushes on
  their way through. Since any user update also applies auto assignment, the
  leave event is observed directly rather than through a role change.
- raise_event fills in the name and tick of the event the way factorio does,
  rather than wrapping the payload, and game.players finds players by index
  as well as by name through a metatable.
- names is generic over anything with a name property, so it lives on the
  suite; the save and load helper no longer calls on_load, the test calls the
  handler itself as it does for the other handlers.
- Sent messages and events are compared whole with deep_eq, which pins the
  event shape, the tick, and that the unassign key is absent rather than
  empty.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-25 16:18:09 +00:00
co-authored by Claude Fable 5
parent 7adcdde9dc
commit e6552a39be
9 changed files with 195 additions and 164 deletions
+4 -4
View File
@@ -22,14 +22,14 @@ end)
test("get_ordered_roles returns the most privileged first", function(env)
env.initialise{}
eq(env.names(env.Roles.get_ordered_roles()), { "Cluster Admin", "Moderator", "Regular", "Jail", "Player" },
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)
env.initialise{}
local sorted = env.Roles.sort_roles{ env.R("Player"), env.R("Cluster Admin"), env.R("Regular") }
eq(env.names(sorted), { "Cluster Admin", "Regular", "Player" }, "the list is sorted in place")
eq(Suite.names(sorted), { "Cluster Admin", "Regular", "Player" }, "the list is sorted in place")
end)
test("get_default_role follows is_default", function(env)
@@ -39,9 +39,9 @@ end)
test("get_higher_roles and get_lower_roles include the role and exclude the default", function(env)
env.initialise{}
eq(Suite.sorted(env.names(env.Roles.get_higher_roles(env.R("Regular")))),
eq(Suite.sorted(Suite.names(env.Roles.get_higher_roles(env.R("Regular")))),
{ "Cluster Admin", "Moderator", "Regular" }, "higher roles")
eq(Suite.sorted(env.names(env.Roles.get_lower_roles(env.R("Regular")))),
eq(Suite.sorted(Suite.names(env.Roles.get_lower_roles(env.R("Regular")))),
{ "Jail", "Regular" }, "lower roles")
end)