Add integration tests for the plugin system

Nothing covered whether plugins are loaded at all, or whether the messages
they declare are routed. The integration tests only loaded the first party
plugins, so what coverage existed came incidentally from testing those.

Add a plugin under test/file which exists purely to be loaded by the tests.
It is plain JavaScript rather than TypeScript so that it needs no build
step, which the plugin loader is happy with as it requires the entry point
and reads the version from package.json like any other plugin.

Covered so far: the plugin loads on the controller and on the host, its
title and version are reported, the command it adds is available in
clusterioctl, a request from control reaches the controller, a request from
control reaches a host, and an event sent with broadcastEventToHosts
arrives at the hosts.

Left for a follow up, as all three need a running instance: a request to an
instance, a Lua module reached over rcon, and log statements being tagged
with the plugin and host or instance id.

Part of #342, and a step towards #721 as core no longer needs a first party
plugin to have the plugin system under test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 4.8 committed 2026-07-25 18:13:28 +00:00
1 parent 5e0ab3423f
commit b415d16408
9 files changed
+242

No files matched your search

+59
View File
@@ -16,6 +16,7 @@ const {
spawnNode, instancesDir, factorioDir, databaseDir, controllerConfigPath,
requiresFactorio, hasFactorio,
} = require("./index");
const { ControllerEcho, HostEchoReceived } = require("../file/test_plugin/messages");
/** @returns {Promise<Map<number, lib.InstanceDetails>>} */
@@ -386,6 +387,64 @@ describe("Integration of Clusterio", function() {
});
});
describe("plugin system", function() {
// Exercised with test/file/test_plugin, which is a plugin that exists
// only to be loaded by these tests, see #342.
async function pluginDetails(address) {
const plugins = await getControl().sendTo(address, new lib.PluginListRequest());
const details = plugins.find(plugin => plugin.name === "test_plugin");
assert(details, `test_plugin missing from the plugin list of ${JSON.stringify(address)}`);
return details;
}
it("should load the plugin on the controller", async function() {
const details = await pluginDetails("controller");
assert(details.enabled, "test_plugin is not enabled on the controller");
assert(details.loaded, "test_plugin is not loaded on the controller");
});
it("should load the plugin on the host", async function() {
const details = await pluginDetails({ hostId: 4 });
assert(details.enabled, "test_plugin is not enabled on the host");
assert(details.loaded, "test_plugin is not loaded on the host");
});
it("should report the plugin's title and version", async function() {
const details = await pluginDetails("controller");
assert.equal(details.title, "Test Plugin");
assert.equal(details.version, "0.0.1");
});
it("should add the plugin's command to clusterioctl", async function() {
const { stdout } = await execCtlProcess("test-plugin echo works");
assert(stdout.includes("works"), `plugin command did not print its message, got ${stdout}`);
});
it("should route a plugin request from control to the controller", async function() {
const response = await getControl().sendTo("controller", new ControllerEcho("to-controller"));
assert.equal(response, "to-controller");
});
it("should route a plugin request from control to a host", async function() {
const received = await getControl().sendTo({ hostId: 4 }, new HostEchoReceived("never-broadcast"));
assert.equal(received, false);
});
it("should deliver a plugin event sent with broadcastEventToHosts", async function() {
await getControl().sendTo("controller", new ControllerEcho("to-hosts"));
// The broadcast is sent without waiting for the hosts to receive it.
let received = false;
for (let attempt = 0; attempt < 100 && !received; attempt++) {
received = await getControl().sendTo({ hostId: 4 }, new HostEchoReceived("to-hosts"));
if (!received) {
await lib.wait(20);
}
}
assert(received, "host did not receive the event broadcast to it");
});
});
describe("clusterioctl", function() {
describe("controller config list", function() {
it("runs", async function() {
+1
View File
@@ -350,6 +350,7 @@ before(async function() {
await execController("config set controller.tls_private_key ../../test/file/tls/key.pem");
console.log("Setting Controller Plugins");
await execCtlProcess("plugin add ../../test/file/test_plugin");
await execCtlProcess("plugin add ../../plugins/global_chat");
await execCtlProcess("plugin add ../../plugins/research_sync");
await execCtlProcess("plugin add ../../plugins/statistics_exporter");