Merge remote-tracking branch 'upstream/master' into refactor/plugin-hooks-v2

# Conflicts:
#	packages/lib/src/data/messages_plugin.ts
#	packages/web_ui/src/components/PluginViewPage.tsx
#	test/lib/plugin.js
This commit is contained in:
bbassie committed 2026-09-12 18:07:12 +00:00
commit db84455c34
37 files changed
+573 -60

No files matched your search

+14 -1
View File
@@ -102,7 +102,7 @@ describe("controller/src/routes", function() {
});
it("should report missing manifest and entrypoint", async function() {
controller.pluginInfos = [
{ name: "foo", version: "1.0.0", npmPackage: "foo" },
{ name: "foo", version: "1.0.0", npmPackage: "foo", webEntrypoint: "dist/web/index.js" },
{ name: "bar", version: "1.0.0", npmPackage: "bar", manifest: {} },
{ name: "baz", version: "1.0.0", npmPackage: "baz", manifest: { "baz.js": "remoteEntry.js" } },
];
@@ -116,6 +116,19 @@ describe("controller/src/routes", function() {
assert.equal(data[1].loaded, false);
assert.equal(data[1].enabled, false);
});
it("should not report a missing manifest for plugins without a web build", async function() {
controller.pluginInfos = [
{ name: "foo", version: "1.0.0", npmPackage: "foo", hostEntrypoint: "dist/node/host.js" },
{ name: "bar", version: "1.0.0", npmPackage: "bar", controllerEntrypoint: "dist/node/controller.js" },
{ name: "baz", version: "1.0.0", npmPackage: "baz", instanceConfigFields: {} },
];
let response = await fetch(endpoint);
assert.equal(response.status, 200);
let data = await response.json();
assert.deepEqual(data[0].web, {});
assert.equal(data[1].web.error, "Missing dist/web/manifest.json");
assert.equal(data[2].web.error, "Missing dist/web/manifest.json");
});
});
describe("/api/cluster-name", function() {
let endpoint;
+28
View File
@@ -38,6 +38,34 @@ describe("class Instance", function() {
});
});
describe(".checkModPackVersion()", function() {
function modPack(factorioVersion) {
return lib.ModPack.fromJSON({ name: "pack", factorio_version: factorioVersion });
}
it("should accept a mod pack for an older or equal Factorio version", function() {
instance.server.version = "1.1.91";
instance.checkModPackVersion(modPack("1.1"));
instance.checkModPackVersion(modPack("1.1.90"));
instance.checkModPackVersion(modPack("1.1.91"));
});
it("should reject a mod pack for a newer Factorio version", function() {
instance.server.version = "1.1.91";
assert.throws(
() => instance.checkModPackVersion(modPack("1.1.110")),
new lib.RequestError(
"Mod pack pack is for Factorio 1.1.110 which is newer than the Factorio 1.1.91 this instance runs"
)
);
assert.throws(() => instance.checkModPackVersion(modPack("2.0")), lib.RequestError);
});
it("should skip the check when the server version is unknown", function() {
instance.checkModPackVersion(modPack("2.0"));
});
});
describe("._recordPlayerJoin()", function() {
it("should add player to playersOnline", function() {
instance._recordPlayerJoin("player");
+6
View File
@@ -521,6 +521,9 @@ describe("Integration of Clusterio", function() {
it("runs", async function() {
await execCtl("controller update");
});
it("accepts --all", async function() {
await execCtl("controller update --all");
});
it("accepts --restart", async function() {
// We cannot restart the controller, so we check for controller error instead
await assert.rejects(
@@ -603,6 +606,9 @@ describe("Integration of Clusterio", function() {
it("runs", async function() {
await execCtl("host update 4");
});
it("accepts --all", async function() {
await execCtl("host update 4 --all");
});
it("accepts --restart", async function() {
// We cannot restart the host, so we check for host error instead
await assert.rejects(
+9
View File
@@ -395,6 +395,15 @@ describe("lib/config/classes", function() {
const json = JSON.parse(await fs.readFile(filepath, "utf8"));
assert.deepEqual(json, testInstance.toJSON());
});
it("should not be readable by other users", async function() {
if (process.platform === "win32") {
this.skip();
}
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
testInstance.set("alpha.foo", "b"); // Sets the dirty flag
await testInstance.save();
assert.equal((await fs.stat(filepath)).mode & 0o777, 0o600);
});
it("should clear the dirty flag after saving", async function() {
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
testInstance.set("alpha.foo", "b"); // Sets the dirty flag
+10
View File
@@ -100,6 +100,16 @@ describe("lib/file_ops", function() {
await assert.rejects(fs.access(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
assert.equal(await fs.readFile(target, "utf8"), "current");
});
it("should apply mode to a leftover temporary file", async function() {
if (process.platform === "win32") {
this.skip();
}
let target = path.join(baseDir, "safe", "mode.txt");
await fs.writeFile(target.replace(".txt", ".tmp.txt"), "stale", { mode: 0o644 });
await lib.safeOutputFile(target, "private", { mode: 0o600 });
assert.equal((await fs.stat(target)).mode & 0o777, 0o600);
assert.equal(await fs.readFile(target, "utf8"), "private");
});
it("should handle creating file in current working directory", async function() {
let target = "temporary-file-made-to-test-cwd.txt";
try {
+27
View File
@@ -0,0 +1,27 @@
import assert from "node:assert/strict";
import * as lib from "@clusterio/lib";
describe("lib/plugin", function() {
describe("pluginNeedsWebBuild()", function() {
it("should be false for plugins with only host, instance or ctl code", function() {
assert.equal(lib.pluginNeedsWebBuild({ name: "foo", title: "Foo" }), false);
assert.equal(lib.pluginNeedsWebBuild({
name: "foo", title: "Foo", hostEntrypoint: "host.js", instanceEntrypoint: "instance.js",
ctlEntrypoint: "ctl.js", messages: [],
}), false);
});
it("should be true for plugins with web or controller code or config fields", function() {
assert.equal(lib.pluginNeedsWebBuild({ name: "foo", title: "Foo", webEntrypoint: "web.js" }), true);
assert.equal(lib.pluginNeedsWebBuild({
name: "foo", title: "Foo", controllerEntrypoint: "controller.js",
}), true);
for (const field of [
"controllerConfigFields", "hostConfigFields", "instanceConfigFields", "controlConfigFields",
]) {
assert.equal(lib.pluginNeedsWebBuild({ name: "foo", title: "Foo", [field]: {} }), true, field);
}
});
});
});
+14
View File
@@ -28,6 +28,20 @@ describe("rce_ops", function() {
});
});
describe("handleUpdateAll", function() {
it("updates the core package and all npm plugins in one command", async function() {
const _audit = lib.logger.audit;
const messages = [];
lib.logger.audit = (msg) => { messages.push(msg); };
try {
await lib.handleUpdateAll("core", [{ npmPackage: "foo" }, { name: "local" }, { npmPackage: "bar" }]);
} finally {
lib.logger.audit = _audit;
}
assert.deepEqual(messages, ["RCE | npm update --save core foo bar"]);
});
});
describe("handlePluginInstall", function() {
const _fetch = global.fetch;
before(function() {
+55
View File
@@ -133,6 +133,61 @@ describe("messages/plugin", function() {
});
});
describe("UpdateAllRequest", function() {
function checkedPermissions(dst) {
const permissions = [];
const user = { checkPermission(permission) { permissions.push(permission); } };
lib.UpdateAllRequest.permission(user, { dst: lib.Address.fromShorthand(dst) });
return permissions;
}
it("requires controller and plugin update permissions on the controller", function() {
assert.deepEqual(checkedPermissions("controller"), ["core.controller.update", "core.plugin.update"]);
});
it("requires host and plugin update permissions on a host", function() {
assert.deepEqual(checkedPermissions({ hostId: 1 }), ["core.host.update", "core.plugin.update"]);
});
it("runs on the controller", async function() {
controller.pluginInfos = [{ npmPackage: "foo" }];
controller.config.set("controller.allow_remote_updates", true);
controller.config.set("controller.allow_plugin_updates", true);
await controlConnection.handleUpdateAllRequest(new lib.UpdateAllRequest());
});
it("rejects if remote updates are disabled on the controller", async function() {
controller.config.set("controller.allow_remote_updates", false);
await assert.rejects(
controlConnection.handleUpdateAllRequest(new lib.UpdateAllRequest()),
/Remote updates are disabled on this machine/
);
});
it("rejects if plugin updates are disabled on the controller", async function() {
controller.config.set("controller.allow_plugin_updates", false);
await assert.rejects(
controlConnection.handleUpdateAllRequest(new lib.UpdateAllRequest()),
/Plugin updates are disabled on this machine/
);
});
it("runs on a host", async function() {
host.pluginInfos = [{ npmPackage: "foo" }];
host.config.set("host.allow_remote_updates", true);
host.config.set("host.allow_plugin_updates", true);
await host.handleUpdateAllRequest(new lib.UpdateAllRequest());
});
it("rejects if remote updates are disabled on the host", async function() {
host.config.set("host.allow_remote_updates", false);
await assert.rejects(
host.handleUpdateAllRequest(new lib.UpdateAllRequest()),
/Remote updates are disabled on this machine/
);
});
it("rejects if plugin updates are disabled on the host", async function() {
host.config.set("host.allow_plugin_updates", false);
await assert.rejects(
host.handleUpdateAllRequest(new lib.UpdateAllRequest()),
/Plugin updates are disabled on this machine/
);
});
});
describe("PluginInstallRequest", function() {
const _fetch = global.fetch;
before(function() {