mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Let plugins migrate the data core stores for them
Plugins had no way to update the config fields and permissions core stores for them, so renaming inventory_sync needed migrations in core packages. A plugin can now declare a migrationEntrypoint. It's loaded on the controller and hosts before configs and roles are read, for every plugin in the plugin list, and attaches handlers to sync hooks for the controller, host and instance configs and roles. lib gets helpers to rename config fields and permissions, and each config gets a hidden <plugin>.version field set after load so migrations can tell which version saved the data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24586a4b7c
commit
aec0fc7a1e
19 files changed
+562
-7
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
|
||||
describe("lib/SyncHook", function() {
|
||||
describe("class SyncHook", function() {
|
||||
let hook;
|
||||
beforeEach(function() {
|
||||
hook = new lib.SyncHook();
|
||||
});
|
||||
|
||||
it("should track attached handlers", function() {
|
||||
assert.equal(hook.size, 0);
|
||||
hook.attach("alpha", value => value);
|
||||
hook.attach("beta", value => value);
|
||||
assert.equal(hook.size, 2);
|
||||
assert.deepEqual([...hook.attached], ["alpha", "beta"]);
|
||||
});
|
||||
it("should reject duplicate handler names", function() {
|
||||
hook.attach("alpha", value => value);
|
||||
assert.throws(
|
||||
() => hook.attach("alpha", value => value),
|
||||
new Error("Handler with name alpha is already attached")
|
||||
);
|
||||
});
|
||||
it("should detach and clear handlers", function() {
|
||||
hook.attach("alpha", value => value);
|
||||
hook.attach("beta", value => value);
|
||||
hook.detach("alpha");
|
||||
assert.deepEqual([...hook.attached], ["beta"]);
|
||||
hook.clear();
|
||||
assert.equal(hook.size, 0);
|
||||
});
|
||||
it("should pass the value through handlers in attach order", function() {
|
||||
hook.attach("alpha", value => [...value, "alpha"]);
|
||||
hook.attach("beta", value => [...value, "beta"]);
|
||||
assert.deepEqual(hook.reduce([]), ["alpha", "beta"]);
|
||||
});
|
||||
it("should return the value unchanged with no handlers", function() {
|
||||
const value = {};
|
||||
assert.equal(hook.reduce(value), value);
|
||||
});
|
||||
it("should rethrow errors as a PluginError named after the handler", function() {
|
||||
hook.attach("alpha", () => { throw new Error("failed"); });
|
||||
assert.throws(
|
||||
() => hook.reduce(1),
|
||||
err => err instanceof lib.PluginError && err.pluginName === "alpha" && err.original.message === "failed"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user