Convert global_chat, research_sync and statistics_exporter to entrypoint functions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-08 05:15:00 +00:00
1 parent bd609c3c54
commit cfeb4b6a4a
7 files changed
+231 -237

No files matched your search

+25 -20
View File
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
import * as lib from "@clusterio/lib";
import * as mock from "../../../test/mock.js";
import * as lines from "../../../test/lib/factorio/lines.js";
@@ -31,40 +32,44 @@ describe("global_chat plugin", function() {
});
});
describe("class InstancePlugin", function() {
let instancePlugin;
describe("instance entrypoint", function() {
let mockInstance;
before(async function() {
instancePlugin = new instance.InstancePlugin(info, new mock.MockInstance(), new mock.MockHost());
await instancePlugin.init();
try {
lib.registerPluginMessages([info]);
} catch (err) {
// Already registered by the full test suite
}
({ instance: mockInstance } = await mock.loadInstancePlugin(instance.default, info));
});
describe(".handleChatEvent()", function() {
describe("ChatEvent handler", function() {
it("should send received chat as command", async function() {
instancePlugin.instance.server.rconCommands = [];
await instancePlugin.handleChatEvent(new ChatEvent("test", "User: message"));
mockInstance.server.rconCommands = [];
await mock.getHandler(mockInstance, ChatEvent)(new ChatEvent("test", "User: message"));
assert.deepEqual(
instancePlugin.instance.server.rconCommands,
mockInstance.server.rconCommands,
["/sc game.print('[test] User: message')"],
);
});
it("should filter server-specific tags from received chat", async function() {
instancePlugin.instance.server.rconCommands = [];
await instancePlugin.handleChatEvent(new ChatEvent("test", "Train [train=1235]"));
mockInstance.server.rconCommands = [];
await mock.getHandler(mockInstance, ChatEvent)(new ChatEvent("test", "Train [train=1235]"));
assert.deepEqual(
instancePlugin.instance.server.rconCommands,
mockInstance.server.rconCommands,
["/sc game.print('[test] Train ')"],
);
});
});
describe(".onOutput()", function() {
describe("output hook", function() {
it("should forward chat", async function() {
let count = 0;
for (let [_, output] of lines.testLines) {
for (let [line, output] of lines.testLines) {
if (output.type === "action" && output.action === "CHAT") {
instancePlugin.instance.connector.sentMessages = [];
await instancePlugin.onOutput(output);
assert(instancePlugin.instance.connector.sentMessages.length, "message was not sent");
mockInstance.connector.sentMessages = [];
await mockInstance.hooks.output.invoke(output, line);
assert(mockInstance.connector.sentMessages.length, "message was not sent");
count += 1;
}
}
@@ -72,11 +77,11 @@ describe("global_chat plugin", function() {
});
it("should ignore regular output", async function() {
let count = 0;
for (let [_, output] of lines.testLines) {
for (let [line, output] of lines.testLines) {
if (output.type !== "action" || output.action !== "CHAT") {
instancePlugin.instance.connector.sentMessages = [];
await instancePlugin.onOutput(output);
assert(!instancePlugin.instance.connector.sentMessages.length, "message was sent");
mockInstance.connector.sentMessages = [];
await mockInstance.hooks.output.invoke(output, line);
assert(!mockInstance.connector.sentMessages.length, "message was sent");
count += 1;
}
}