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

+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() {