Files
factorio-clusterio/test/file/test_plugin/controller.js
T
bbassieandClaude Opus 4.8 b415d16408 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>
2026-07-25 18:13:28 +00:00

22 lines
584 B
JavaScript

"use strict";
const { BaseControllerPlugin } = require("@clusterio/controller");
const { ControllerEcho, HostEcho } = require("./messages");
class ControllerPlugin extends BaseControllerPlugin {
async init() {
this.logger.info("test_plugin controller loaded");
this.controller.handle(ControllerEcho, this.handleControllerEcho.bind(this));
}
async handleControllerEcho(request) {
this.logger.info(`test_plugin controller echo ${request.text}`);
this.broadcastEventToHosts(new HostEcho(request.text));
return request.text;
}
}
module.exports = {
ControllerPlugin,
};