Clusterio #988 added a permissions array to PluginDeclaration and a
type level Permissions registry, and made checkPermission and the web
UI hasPermission helpers take PermissionName. Move the definePermission
calls of exp_groups and exp_scenario into the declaration and add the
names to the registry so the web pages type check. The browser
tsconfigs include index.ts so the augmentation is visible to the web
bundle, matching the in-repo plugins.
The exp_scenario table keeps its tuple form and derives the name union
from it, so a new row is still one line. Seed role permissions are typed
as PermissionName, so a typo in seed.ts is now a compile error rather
than a warning at seed time. The tests register the declared
permissions through registerPluginPermissions instead of importing
permissions.ts for its side effect.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The packages use workspace:^ and catalog: versions, so they only
resolve inside a clusterio checkout with this repository under
external_plugins. The workflow clones clusterio master, checks this
repository out into external_plugins/ExpCluster, runs pnpm install
(which runs every prepare script), then runs the tap suites.
A last step wipes dist and runs tsc --build in each package on its own.
pnpm install builds packages in dependency order, which is why the
missing project references fixed in #473 went unnoticed. On the tree
before #473 this step fails with the same five TS2307 errors.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Reference exp_roles and exp_groups from the exp_scenario build
exp_scenario imports types from @expcluster/roles and
@expcluster/permission-groups through their dist folders, so building it
on its own before those packages are built fails with TS2307. A plain
pnpm install runs the prepare scripts in dependency order, but a filtered
install or running tsc --build in exp_scenario on a fresh clone does not.
Referencing the node projects of both packages makes tsc build them first.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Export messages and controller types from exp_roles and exp_groups
exp_scenario reached into @expcluster/roles/dist/node/* for the message
classes and the controller plugin type. The package index now re-exports
messages and the ControllerPlugin type, so consumers import from the
package name like they do with @clusterio/lib. The controller export is
type only, which keeps node code out of the web bundle. The test still
requires the controller classes from dist since they cannot be
re-exported at runtime.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
exp_scenario reached into @expcluster/roles/dist/node/* for the message
classes and the controller plugin type. The package index now re-exports
messages and the ControllerPlugin type, so consumers import from the
package name like they do with @clusterio/lib. The controller export is
type only, which keeps node code out of the web bundle. The test still
requires the controller classes from dist since they cannot be
re-exported at runtime.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
exp_scenario imports types from @expcluster/roles and
@expcluster/permission-groups through their dist folders, so building it
on its own before those packages are built fails with TS2307. A plain
pnpm install runs the prepare scripts in dependency order, but a filtered
install or running tsc --build in exp_scenario on a fresh clone does not.
Referencing the node projects of both packages makes tsc build them first.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
encode_group_permissions filled the whitelist and blacklist starting at
index 0. Factorio's table_to_json only serialises a table as a JSON array
when its keys run 1..n, so the permissions reached the instance plugin as
an object and every GroupUpdateRequest failed schema validation.
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
The seed roles were owned by exp_roles, but they describe the scenario, so
they now live in exp_scenario/seed.ts next to the permissions they grant.
Each seed role names the permission group its holders belong to, and the
five groups the legacy config defined (Admin, Trusted, Standard, Guest,
Restricted) are seeded through exp_groups along with one role mapping per
role. Mapping priorities follow how exp_roles ranks a player's highest
role, so Jail lands in Restricted regardless of other roles.
SeedRolesRequest becomes exp_scenario's SeedRequest behind a new
exp_scenario.seed permission, and the button moves to the scenario's web
plugin, which gets a web entrypoint for it. exp_roles no longer depends on
exp_scenario, and exp_scenario gains controller tests around the seed.
With groups seeded from the controller the legacy expcore.permission_groups
module and its config are removed, along with the Group rcon static.
Clearing the slots on leave meant nothing was known about a player's ammo
until it changed, so the first shot after rejoining was missed. The slots
are now read when a player joins and when they respawn, since a new
character starts empty and a stale single round would otherwise count as
a shot. The change handler reads the slots the same way and compares them
with what was stored.
The cursor was a line of text under the camera, which read as an
afterthought next to the framed header. It is now a slot button in the
header after the zoom buttons: the item sprite with its count, greyed out
for a ghost, an empty slot for an empty cursor, and the item name in the
tooltip. The window keeps its shape whatever the item is called.
A label under the camera shows what the player being followed holds in
their cursor, item and count or the ghost item, so that using a
deconstruction planner or similar can be seen. It is hidden while the
camera shows a fixed location.
Closes#427
Factorio 2.1 changed get_quick_bar_slot and set_quick_bar_slot to take a
page and slot rather than a single index, and to describe slots holding
records, remotes and specific item instances. Saved filters keep their
single index, which is converted on load and save, and only plain item
filters are saved since the other slot types hold data which has no name
to store. The command is enabled again.
Fixes#444
Factorio has no fired event, so the log was written on every ammo
inventory change, which includes loading rockets for the first time and
swapping between rocket types. The last seen name and count of each ammo
slot is now kept per player, and a shot is only logged when a slot holds
the same ammo with one fewer, or empties from a single round. Only the
three configured ammo types are logged, rather than every ammo change.
Fixes#242
The statistics only credited damage and kills when the cause was a
character, so anything done from a car, tank, spidertron or locomotive was
lost. The cause is now resolved to a player through the vehicle's driver,
or passenger when there is no driver, and turrets, remotes and uncrewed
trains still count for nobody.
Fixes#219
Warnings were a moderator tool layered on top of reports and had no
callers left outside their own command and the player list button. The
legacy module, its config and locale, the exp_scenario command and its
permissions, the discord alert block and the player list button are all
removed. Reporting from the player list no longer depends on whether the
player could give warnings, anyone can report a player who is not immune.
The spectate and follow module moves to exp_scenario/module/control/spectate.lua
in the event_handler shape the other control modules use, and the copy in
exp_legacy is removed. Follow state is a typed record rather than a
positional table, the follow label caption is localised, and the escape
handler marks the record to stop on the next tick instead of poking an
invalid position into it.
The LuaPlayer.close_map call is gone: it does not exist in Factorio 2.0,
where the map is the remote controller and set_controller replaces it.
The entity protection module moves to exp_scenario/module/control/protection.lua
in the event_handler shape the other control modules use, and the copy in
exp_legacy is removed. The config lookups are built as local sets instead of
rewriting the config tables in place, the two mined handlers become one, and
the entity and area key helpers are exposed so the protection command no
longer keeps its own copies. Event ids are exposed as
Protection.on_player_mined_protected and Protection.on_repeat_violation.
With the role system finished the jail module has nothing legacy left in
it, so it moves to exp_scenario/module/control/jail.lua and the copy in
exp_legacy is removed. The module takes LuaPlayer only, requires a reason,
returns false rather than nil when there is nothing to do, and exposes its
event ids as Jail.on_player_jailed and Jail.on_player_unjailed in the same
shape as exp_util's selection events.
Building on the class annotations from the smoke test changes:
- The suite is generic over its environment: Framework.suite is
@generic T : Stubs with the extension returning T, and Suite<T> passes T to
every test function. A test file declares
`local Suite = ... --- @type Suite<ExpRoles.TestEnv>` and env autocompletes
from there.
- The stubs declare their recorded fields, add_player returns Stubs.Player,
and the server is one.
- ExpRoles.TestEnv : Stubs declares the extension fields, so env.R returns
ExpRoles.Role and env.Roles is the module.
The typing immediately paid for itself by flagging real drift in the tests,
now fixed: _script_data is package private so the env exposes script_data()
instead, the join event carries its name and tick, the assignment record type
admits is_deleted, admin_state is a file local rather than an undeclared
field, and the event assertions which indexed [1] without a nil check compare
the whole event list.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Suite.empty(value, name) checks a table has no entries and reports what it
held, and Suite.throws(fn, message, name) asserts a function errors with the
given message, so an unrelated error no longer passes as the expected one.
- Scalar comparisons and zero length checks go through eq and empty, and the
announced messages and print output are compared by content, so a failure
shows the actual data.
- get_roles() is asserted through sorted names rather than a count.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- 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>
- 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>
- The registry is a Suite, created around the environment factory it runs its
tests with, so the plugin's env.lua reads as: build environments, hand the
test files a suite of them. The suite returned there becomes `...` in each
test file, which is now said where it happens.
- pass and fail are the primitives every other check goes through. eq and
deep_eq assert rather than compare, failing with both values in the detail.
- Stubs are extended through extend_requires, extend_script, extend_game and
extend_defines, a recursive merge which raises when a value already exists,
rather than by mutating the tables. The strict labels carry the factorio
class names.
- The stubs record registered metatables and can save and load the script
data the way factorio does: functions are refused and only registered
metatables survive. env.save_load() uses it, and a new on_load test shows
role methods and held roles surviving the round trip, which only passes
because the module registers its metatable.
- The names helper moved out of the shared framework, it is role specific.
- Tests are named after the function or method they cover, on both sides:
the lua tests read as "role:assign applies locally and is sent", and the
javascript files wrap their tests in the class they exercise with subtests
per method. module.test.js is control.test.js, after the file it covers.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- The generic parts move to test/ in the repository root so other plugins can
reuse them: the factorio and clusterio stubs, the test framework, the
fengari runner, and clusterio's testMatrix and round trip helpers. A plugin
composes them from its own env.lua, which adds its stubs and fixtures.
- Tests are declared with Test.test(name, fn) and every test function
receives a fresh environment, so nothing carries over between them. A test
which errors is reported as a failure rather than aborting the file.
- Every stub raises on properties it does not implement, which mirrors the
game api. game.player is the one property allowed to read as nil.
- Test.deep_eq compares tables recursively with keys checked from both sides.
- The message records round trip through the same testMatrix and
testRoundTripJsonSerialisable helpers the clusterio tests use, covering
every optional field combination of the records, events and requests.
- controller.test.js and instance.test.js cover the node side of the plugin
against faked controller and instance internals: property creation and
sweeping, record building, broadcasts, subscription replay, assignment
validation, auto assignment and its blocking role, seeding, the initialise
payload, sync mode gating, and the rejection rollback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The list restarts whenever a higher priority is found, rather than collecting
every role and filtering afterwards.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Run with `pnpm --filter @expcluster/roles test`, using tap as the runner.
The lua module is exercised for real: each test file runs in its own lua
state, created on first use by the helper, with the factorio surface and the
clusterio modules stubbed. The environment is passed to the chunk as an
argument so no globals are involved. Covers lookups and comparisons, the
permission checks, assignment with confirmation, rejection and local only
roles, jail suppression, the sync entry points, and the holder listings,
including a player holding a role in both the synced and the local list.
The javascript side covers the message records round tripping through their
schemas, the indexed permission encoding, and the seed: every permission it
grants must be defined by exp_scenario, and every parent must exist and have
its permissions carried into its children.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>