Finish the plugin system integration tests

Adds the last three checks from #342 to test_plugin: an InstanceEcho
request handled on a running instance, a Lua module with a remote
interface that the request calls over RCON, and log tagging checks for
the plugin field and host/instance ids on the controller, host and
instance log lines.

test_plugin now has a module, so the create_scenario and patch unit
tests that relied on it having none use global_chat instead.

Closes #342

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-28 22:01:27 +00:00
1 parent 35125a28ab
commit 9ab36151bd
8 files changed
+100 -4

No files matched your search

+2 -1
View File
@@ -1,7 +1,7 @@
// Plugin exercising the plugin system in the integration tests, see #342.
// Written as plain JavaScript so that it does not need to be built.
import { ControllerEcho, HostEcho, HostEchoReceived } from "./messages.js";
import { ControllerEcho, HostEcho, HostEchoReceived, InstanceEcho } from "./messages.js";
export const plugin = {
name: "test_plugin",
@@ -17,5 +17,6 @@ export const plugin = {
ControllerEcho,
HostEcho,
HostEchoReceived,
InstanceEcho,
],
};
+11
View File
@@ -1,3 +1,7 @@
import * as lib from "@clusterio/lib";
import { InstanceEcho } from "./messages.js";
export default async function(context) {
const { instance, plugin, logger } = context;
logger.info("test_plugin instance loaded");
@@ -5,4 +9,11 @@ export default async function(context) {
instance.hooks.start.attach(plugin.name, async () => {
logger.info("test_plugin instance started");
});
instance.handle(InstanceEcho, async (request) => {
logger.info(`test_plugin instance echo ${request.text}`);
const text = lib.escapeString(request.text);
const response = await instance.sendRcon(`/sc rcon.print(remote.call("test_plugin", "echo", "${text}"))`);
return response.replace(/\n$/, "");
});
}
+19
View File
@@ -54,3 +54,22 @@ export class HostEchoReceived {
toJSON() { return this.text; }
static fromJSON(json) { return new this(json); }
}
// Sent from ctl to an instance, which answers with the text echoed back by
// the remote interface of the plugin's Lua module.
export class InstanceEcho {
static type = "request";
static src = "control";
static dst = "instance";
static plugin = "test_plugin";
static permission = null;
static Response = JsonString;
constructor(text) {
this.text = text;
}
static jsonSchema = { type: "string" };
toJSON() { return this.text; }
static fromJSON(json) { return new this(json); }
}
+4
View File
@@ -0,0 +1,4 @@
{
"name": "test_plugin",
"require": ["test_plugin.lua"]
}
@@ -0,0 +1,5 @@
remote.add_interface("test_plugin", {
echo = function(text)
return text
end,
})