mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-19 15:23:12 +09:00
Save controller plugin data on the save hook (#513)
exp_groups and exp_roles only saved their datastores on shutdown, and exp_scenario saved the player store but not the feature store on the save hook. The controller runs the save hook on its autosave interval, so a crash or kill lost every change since the controller started. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
82abc2c332
commit
20ca539af3
5 files changed
+33
-5
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import t from "tap";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { Controller } from "@clusterio/controller";
|
||||
import entrypoint, { ControllerPlugin } from "../dist/node/controller.js";
|
||||
@@ -54,7 +56,7 @@ t.test("entrypoint", async t2 => {
|
||||
const controllerConfig = new lib.ControllerConfig("controller", { "controller.database_directory": t2.testdir() });
|
||||
const controller = new Controller(logger, [], controllerConfig);
|
||||
await entrypoint({ controller, logger, plugin: { name: "exp_roles" }, metrics: undefined });
|
||||
for (const hook of ["shutdown", "controllerConfigFieldChanged", "playerEvent"]) {
|
||||
for (const hook of ["save", "shutdown", "controllerConfigFieldChanged", "playerEvent"]) {
|
||||
t2.ok([...controller.hooks[hook].attached].includes("exp_roles"), `attached to ${hook}`);
|
||||
}
|
||||
await controller.hooks.shutdown.invoke();
|
||||
@@ -208,6 +210,18 @@ t.test("class ControllerPlugin", t2 => {
|
||||
t3.strictSame(plugin.roleMeta.get(5).shortHand, "Mod", "the properties are stored");
|
||||
});
|
||||
|
||||
t2.test("role properties are written on the save hook", async t3 => {
|
||||
const { plugin, controller } = await startPlugin(t3, { roles: [role(1, "Player"), role(5, "Moderator")] });
|
||||
await plugin.handleRoleMetaUpdateRequest(new messages.RoleMetaUpdateRequest(
|
||||
new messages.RoleMetaRecord(5, 2, 0, "Mod"),
|
||||
));
|
||||
await controller.hooks.save.invoke();
|
||||
|
||||
const file = path.join(controller.config.get("controller.database_directory"), "exp_roles", "role_meta.json");
|
||||
const stored = JSON.parse(await fs.readFile(file, "utf8"));
|
||||
t3.ok(stored.some(record => record.id === 5 && record.short_hand === "Mod"), "the update is on disk");
|
||||
});
|
||||
|
||||
t2.test(".handleAssignmentListRequest() returns the current assignments", async t3 => {
|
||||
const { plugin, controller } = await startPlugin(t3, {
|
||||
roles: [role(1, "Player"), role(5, "Moderator")],
|
||||
|
||||
Reference in new issue
Block a user