mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 23:24:52 +09:00
Review changes for #1142: - base becomes template everywhere (is_template, template_id, --template, --is-template, --templates, InstanceDetails.isTemplate). - Object fields inherit per property. inherited_fields lists the overridden properties for object fields and the template object is merged with them. - Linking a template also inherits fields that hold the default value. The server name stays per instance. - Ports are never inherited. - InstanceDetails carries templateId. Web UI: inherited values are locked until unlocked, overridden values can be inherited again, templates are listed separately, the create modal can create templates and instances from templates, and the instance page has "Create template" which can link the source. Part of #200 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.3 KiB
JavaScript
83 lines
3.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
|
|
describe("lib/config/definitions", function() {
|
|
describe("InstanceConfig", function() {
|
|
describe("isInheritable()", function() {
|
|
it("should allow regular fields", function() {
|
|
assert.equal(lib.InstanceConfig.isInheritable("factorio.version"), true);
|
|
assert.equal(lib.InstanceConfig.isInheritable("instance.auto_start"), true);
|
|
});
|
|
it("should reject identity, hidden, host only and unknown fields", function() {
|
|
for (const name of [
|
|
"instance.name", "instance.id", "instance.assigned_host", "instance.is_template",
|
|
"instance.template_id", "instance.inherited_fields", "factorio.host_assigned_game_port",
|
|
"factorio.game_port", "factorio.rcon_port", "factorio.lua_udp_port", "no.field",
|
|
]) {
|
|
assert.equal(lib.InstanceConfig.isInheritable(name), false, name);
|
|
}
|
|
});
|
|
});
|
|
describe(".isInherited()", function() {
|
|
it("should only report fields as inherited when a template is set", function() {
|
|
const config = new lib.InstanceConfig("controller", {
|
|
"instance.inherited_fields": { "factorio.version": true },
|
|
});
|
|
assert.equal(config.isInherited("factorio.version"), false);
|
|
config.set("instance.template_id", 1);
|
|
assert.equal(config.isInherited("factorio.version"), true);
|
|
assert.equal(config.isInherited("factorio.game_port"), false);
|
|
});
|
|
it("should report object properties not overridden as inherited", function() {
|
|
const config = new lib.InstanceConfig("controller", {
|
|
"instance.template_id": 1,
|
|
"instance.inherited_fields": { "factorio.settings": ["name"] },
|
|
});
|
|
assert.equal(config.isInherited("factorio.settings"), true);
|
|
assert.equal(config.isInherited("factorio.settings", "max_players"), true);
|
|
assert.equal(config.isInherited("factorio.settings", "name"), false);
|
|
});
|
|
});
|
|
it("should not send inheritance fields to the host", function() {
|
|
const config = new lib.InstanceConfig("controller", { "instance.template_id": 1 });
|
|
const remote = config.toRemote("host");
|
|
for (const name of ["instance.is_template", "instance.template_id", "instance.inherited_fields"]) {
|
|
assert(!Object.hasOwn(remote, name), name);
|
|
}
|
|
});
|
|
it("should not let control write inherited_fields", function() {
|
|
const config = new lib.InstanceConfig("controller");
|
|
assert.throws(
|
|
() => config.set("instance.inherited_fields", { "factorio.version": true }, "control"),
|
|
new lib.InvalidAccessError("Field 'instance.inherited_fields' is not accessible from control"),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("addPluginConfigFields()", function() {
|
|
after(function() {
|
|
delete lib.CtlConfig.fieldDefinitions["ctl_test.field"];
|
|
});
|
|
|
|
it("should add ctl config fields", function() {
|
|
lib.addPluginConfigFields([{
|
|
name: "ctl_test",
|
|
ctlConfigFields: { "ctl_test.field": { type: "string", initialValue: "value" } },
|
|
}]);
|
|
const config = new lib.CtlConfig("control");
|
|
assert.equal(config.get("ctl_test.field"), "value");
|
|
});
|
|
it("should reject ctl config fields not named after the plugin", function() {
|
|
assert.throws(
|
|
() => lib.addPluginConfigFields([{
|
|
name: "ctl_test",
|
|
ctlConfigFields: { "other.field": { type: "string" } },
|
|
}]),
|
|
new Error("Expected name of config field 'other.field' for ctl_test to start with 'ctl_test.'")
|
|
);
|
|
});
|
|
});
|
|
});
|