mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Merge upstream/master and address review
Resolves the ESM conflicts in patch.ts, Instance.ts and host.ts. The module gathering in Instance now goes through patch.loadModules with the instance's loadedPlugins, and imports use explicit extensions. Review changes: the existing-output check only treats ENOENT as "does not exist" and rethrows anything else, a --zip option keeps the output as a zip file for transfer (extracting stays the default), the --scenario option describes that it takes a path and what the default is, and the docs note that IPC is not available outside Clusterio. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
187138bec5
297 files changed
+4980
-3274
No files matched your search
@@ -1,22 +1,21 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("node:fs/promises");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const path = require("path");
|
||||
const events = require("events");
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import jwt from "jsonwebtoken";
|
||||
import path from "node:path";
|
||||
import events from "node:events";
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const libBuildMod = require("@clusterio/lib/build_mod");
|
||||
const { wait } = lib;
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { wait } from "@clusterio/lib";
|
||||
import * as libBuildMod from "@clusterio/lib/build_mod.js";
|
||||
|
||||
const testStrings = require("../lib/factorio/test_strings");
|
||||
const {
|
||||
import * as testStrings from "../lib/factorio/test_strings.js";
|
||||
import {
|
||||
TestControl, TestControlConnector, url, controlToken, slowTest,
|
||||
execCtl, execCtlProcess, execController, execHost, sendRcon, getControl,
|
||||
spawnNode, instancesDir, factorioDir, databaseDir, controllerConfigPath,
|
||||
requiresFactorio, hasFactorio,
|
||||
} = require("./index");
|
||||
const { ControllerEcho, HostEchoReceived } = require("../file/test_plugin/messages");
|
||||
} from "./index.js";
|
||||
import { ControllerEcho, HostEchoReceived } from "../file/test_plugin/messages.js";
|
||||
|
||||
|
||||
/** @returns {Promise<Map<number, lib.InstanceDetails>>} */
|
||||
@@ -535,6 +534,9 @@ describe("Integration of Clusterio", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("controller update");
|
||||
});
|
||||
it("accepts --all", async function() {
|
||||
await execCtl("controller update --all");
|
||||
});
|
||||
it("accepts --restart", async function() {
|
||||
// We cannot restart the controller, so we check for controller error instead
|
||||
await assert.rejects(
|
||||
@@ -617,6 +619,9 @@ describe("Integration of Clusterio", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("host update 4");
|
||||
});
|
||||
it("accepts --all", async function() {
|
||||
await execCtl("host update 4 --all");
|
||||
});
|
||||
it("accepts --restart", async function() {
|
||||
// We cannot restart the host, so we check for host error instead
|
||||
await assert.rejects(
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("node:fs/promises");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const path = require("path");
|
||||
const events = require("events");
|
||||
const child_process = require("child_process");
|
||||
const util = require("util");
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import jwt from "jsonwebtoken";
|
||||
import path from "node:path";
|
||||
import events from "node:events";
|
||||
import child_process from "node:child_process";
|
||||
import util from "node:util";
|
||||
|
||||
const cwd = path.join("temp", "test_integration");
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
|
||||
const { _exportLocale } = require("@clusterio/host/dist/node/src/export");
|
||||
const { FactorioServer } = require("@clusterio/host/dist/node/src/server");
|
||||
import { _exportLocale } from "@clusterio/host/dist/node/src/export.js";
|
||||
import { FactorioServer } from "@clusterio/host/dist/node/src/server.js";
|
||||
|
||||
const { factorioDir, requiresFactorio } = require("./index");
|
||||
import { factorioDir, requiresFactorio } from "./index.js";
|
||||
|
||||
|
||||
describe("Integration of lib/factorio/export", function() {
|
||||
|
||||
+44
-76
@@ -1,27 +1,26 @@
|
||||
/* eslint-disable no-console */
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const fs = require("node:fs/promises");
|
||||
const { readFileSync } = require("node:fs");
|
||||
const child_process = require("child_process");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const util = require("util");
|
||||
const events = require("events");
|
||||
import path from "node:path";
|
||||
import fs from "node:fs/promises";
|
||||
import { readFileSync } from "node:fs";
|
||||
import child_process from "node:child_process";
|
||||
import jwt from "jsonwebtoken";
|
||||
import util from "node:util";
|
||||
import events from "node:events";
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const { LineSplitter, ConsoleTransport, logger } = lib;
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { LineSplitter, ConsoleTransport, logger } from "@clusterio/lib";
|
||||
|
||||
const { selectTargetCommand, initialize: initializeCtl } = require("@clusterio/ctl");
|
||||
const { _listFactorioVersions } = require("@clusterio/host/dist/node/src/server");
|
||||
import { selectTargetCommand, initialize as initializeCtl } from "@clusterio/ctl";
|
||||
import { _listFactorioVersions } from "@clusterio/host/dist/node/src/server.js";
|
||||
|
||||
// Make sure permissions from plugins are loaded
|
||||
require("../../plugins/global_chat/dist/node/index");
|
||||
require("../../plugins/player_auth/dist/node/index");
|
||||
require("../../plugins/research_sync/dist/node/index");
|
||||
require("../../plugins/statistics_exporter/dist/node/index");
|
||||
require("../../plugins/subspace_storage/dist/node/index");
|
||||
import "../../plugins/global_chat/dist/node/index.js";
|
||||
import "../../plugins/player_auth/dist/node/index.js";
|
||||
import "../../plugins/research_sync/dist/node/index.js";
|
||||
import "../../plugins/statistics_exporter/dist/node/index.js";
|
||||
import "../../plugins/subspace_storage/dist/node/index.js";
|
||||
|
||||
class TestControl extends lib.Link {
|
||||
export class TestControl extends lib.Link {
|
||||
constructor(connector, subscribe = true) {
|
||||
super(connector);
|
||||
this.hostUpdates = [];
|
||||
@@ -93,7 +92,7 @@ class TestControl extends lib.Link {
|
||||
}
|
||||
}
|
||||
|
||||
class TestControlConnector extends lib.WebSocketClientConnector {
|
||||
export class TestControlConnector extends lib.WebSocketClientConnector {
|
||||
register() {
|
||||
this.sendHandshake(
|
||||
new lib.MessageRegisterControl(
|
||||
@@ -105,7 +104,7 @@ class TestControlConnector extends lib.WebSocketClientConnector {
|
||||
}
|
||||
}
|
||||
|
||||
class TestHostConnector extends lib.WebSocketClientConnector {
|
||||
export class TestHostConnector extends lib.WebSocketClientConnector {
|
||||
register() {
|
||||
this.sendHandshake(
|
||||
new lib.MessageRegisterHost(
|
||||
@@ -119,7 +118,7 @@ class TestHostConnector extends lib.WebSocketClientConnector {
|
||||
}
|
||||
|
||||
// Mark that this test takes a lot of time, or depends on a test that takes a lot of time.
|
||||
function slowTest(test) {
|
||||
export function slowTest(test) {
|
||||
|
||||
if (process.env.FAST_TEST) {
|
||||
test.skip();
|
||||
@@ -129,7 +128,7 @@ function slowTest(test) {
|
||||
}
|
||||
|
||||
// Mark that this test depends on an external API and may be slow or flaky.
|
||||
function externalTest(test) {
|
||||
export function externalTest(test) {
|
||||
if (process.env.NO_EXTERNAL_TEST) {
|
||||
test.skip();
|
||||
}
|
||||
@@ -138,7 +137,7 @@ function externalTest(test) {
|
||||
}
|
||||
|
||||
// Mark that this test or suite of tests requires a factorio install to run.
|
||||
function requiresFactorio(testOrSuite) {
|
||||
export function requiresFactorio(testOrSuite) {
|
||||
if (testOrSuite.skip) {
|
||||
if (!haveFactorioInstall) {
|
||||
testOrSuite.skip();
|
||||
@@ -152,11 +151,11 @@ function requiresFactorio(testOrSuite) {
|
||||
}
|
||||
}
|
||||
|
||||
function hasFactorio() {
|
||||
export function hasFactorio() {
|
||||
return haveFactorioInstall;
|
||||
}
|
||||
|
||||
async function get(urlPath) {
|
||||
export async function get(urlPath) {
|
||||
const url = new URL("https://localhost:4443");
|
||||
url.pathname = urlPath;
|
||||
let res = await fetch(url);
|
||||
@@ -191,16 +190,16 @@ let haveFactorioInstall;
|
||||
|
||||
const baseHostConfig = loadJSON("config-host.json");
|
||||
|
||||
let url = "https://localhost:4443/";
|
||||
let controlToken = jwt.sign({ aud: "user", user: "test" }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
let instancesDir = path.join("temp", "test", "instances");
|
||||
let modsDir = path.join("temp", "test", "mods");
|
||||
let databaseDir = path.join("temp", "test", "database");
|
||||
let factorioDir = getFactorioDir(baseHostConfig);
|
||||
export let url = "https://localhost:4443/";
|
||||
export let controlToken = jwt.sign({ aud: "user", user: "test" }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
export let instancesDir = path.join("temp", "test", "instances");
|
||||
export let modsDir = path.join("temp", "test", "mods");
|
||||
export let databaseDir = path.join("temp", "test", "database");
|
||||
export let factorioDir = getFactorioDir(baseHostConfig);
|
||||
let pluginListPath = path.join("temp", "test", "plugin-list.json");
|
||||
let controllerConfigPath = path.join("temp", "test", "config-controller.json");
|
||||
let hostConfigPath = path.join("temp", "test", "config-host.json");
|
||||
let controlConfigPath = path.join("temp", "test", "config-control.json");
|
||||
export let controllerConfigPath = path.join("temp", "test", "config-controller.json");
|
||||
export let hostConfigPath = path.join("temp", "test", "config-host.json");
|
||||
export let controlConfigPath = path.join("temp", "test", "config-control.json");
|
||||
|
||||
function childOptions(options) {
|
||||
return {
|
||||
@@ -210,33 +209,33 @@ function childOptions(options) {
|
||||
};
|
||||
}
|
||||
|
||||
function exec(command, options = {}) {
|
||||
export function exec(command, options = {}) {
|
||||
// Uncomment to show commands run in tests
|
||||
// console.log(command);
|
||||
return util.promisify(child_process.exec)(command, childOptions(options));
|
||||
}
|
||||
|
||||
function execController(...args) {
|
||||
export function execController(...args) {
|
||||
args[0] = `node --enable-source-maps ../../packages/controller ${args[0]}`;
|
||||
return exec(...args);
|
||||
}
|
||||
|
||||
function execHost(...args) {
|
||||
export function execHost(...args) {
|
||||
args[0] = `node --enable-source-maps ../../packages/host ${args[0]}`;
|
||||
return exec(...args);
|
||||
}
|
||||
|
||||
function execCtlProcess(...args) {
|
||||
export function execCtlProcess(...args) {
|
||||
args[0] = `node --enable-source-maps ../../packages/ctl ${args[0]}`;
|
||||
return exec(...args);
|
||||
}
|
||||
|
||||
let inExecCtl = false;
|
||||
async function execCtl(command) {
|
||||
export async function execCtl(command) {
|
||||
inExecCtl = true;
|
||||
process.chdir("temp/test");
|
||||
try {
|
||||
const initArgs = await initializeCtl(command, control.plugins, true);
|
||||
const initArgs = await initializeCtl(command, control.hooks, true);
|
||||
if (!initArgs.shouldRun) {
|
||||
return;
|
||||
}
|
||||
@@ -257,16 +256,16 @@ afterEach(function() {
|
||||
}
|
||||
});
|
||||
|
||||
async function sendRcon(instanceId, command) {
|
||||
export async function sendRcon(instanceId, command) {
|
||||
return await control.sendTo({ instanceId }, new lib.InstanceSendRconRequest(command));
|
||||
}
|
||||
|
||||
function getControl() {
|
||||
export function getControl() {
|
||||
return control;
|
||||
}
|
||||
|
||||
/** @returns {Promise<child_process.ChildProcess>} */
|
||||
function spawn(name, cmd, waitFor, options = {}) {
|
||||
export function spawn(name, cmd, waitFor, options = {}) {
|
||||
|
||||
const silent = process.env.SILENT_TEST;
|
||||
const bootstrap = !controllerProcess || !hostProcess;
|
||||
@@ -303,7 +302,7 @@ function spawn(name, cmd, waitFor, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
function spawnNode(name, cmd, waitFor, options) {
|
||||
export function spawnNode(name, cmd, waitFor, options) {
|
||||
return spawn(name, `node --enable-source-maps ${cmd}`, waitFor, options);
|
||||
}
|
||||
|
||||
@@ -395,7 +394,7 @@ before(async function() {
|
||||
|
||||
const initArgs = await initializeCtl(`--plugin-list ${pluginListPath} control-config list`, undefined, true);
|
||||
control.config = initArgs.controlConfig;
|
||||
control.plugins = initArgs.ctlPlugins;
|
||||
control.hooks = initArgs.ctlHooks;
|
||||
|
||||
const testPack = lib.ModPack.fromJSON({});
|
||||
testPack.id = 12;
|
||||
@@ -437,34 +436,3 @@ process.on("exit", () => {
|
||||
if (hostProcess) { hostProcess.kill(); }
|
||||
if (controllerProcess) { controllerProcess.kill(); }
|
||||
});
|
||||
|
||||
|
||||
module.exports = {
|
||||
TestControl,
|
||||
TestControlConnector,
|
||||
TestHostConnector,
|
||||
execController,
|
||||
execCtlProcess,
|
||||
slowTest,
|
||||
externalTest,
|
||||
requiresFactorio,
|
||||
get,
|
||||
exec,
|
||||
execCtl,
|
||||
execHost,
|
||||
sendRcon,
|
||||
getControl,
|
||||
spawn,
|
||||
spawnNode,
|
||||
|
||||
url,
|
||||
controlToken,
|
||||
instancesDir,
|
||||
modsDir,
|
||||
databaseDir,
|
||||
factorioDir,
|
||||
hasFactorio,
|
||||
controllerConfigPath,
|
||||
hostConfigPath,
|
||||
controlConfigPath,
|
||||
};
|
||||
@@ -1,14 +1,13 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const assert = require("assert").strict;
|
||||
const lib = require("@clusterio/lib");
|
||||
const fs = require("node:fs/promises");
|
||||
import path from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
const { testMatrix } = require("../common");
|
||||
const {
|
||||
import { testMatrix } from "../common.js";
|
||||
import {
|
||||
slowTest, exec, execCtl, execCtlProcess, sendRcon, getControl,
|
||||
requiresFactorio, hasFactorio, instancesDir,
|
||||
} = require("./index");
|
||||
} from "./index.js";
|
||||
|
||||
const instId = 48;
|
||||
const instName = "Integration";
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
const fs = require("node:fs/promises");
|
||||
const jwt = require("jsonwebtoken");
|
||||
import assert from "node:assert/strict";
|
||||
import events from "node:events";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
const { TestControlConnector, TestHostConnector, TestControl, get, exec, url, slowTest } = require("./index");
|
||||
const { ConnectionClosed, ProtocolError, PolicyViolation, AuthenticationFailed } = require("@clusterio/lib");
|
||||
import { TestControlConnector, TestHostConnector, TestControl, get, exec, url, slowTest } from "./index.js";
|
||||
import { ConnectionClosed, ProtocolError, PolicyViolation, AuthenticationFailed } from "@clusterio/lib";
|
||||
|
||||
let token = jwt.sign({ aud: "user", user: "test" }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
let tokenHost = jwt.sign({ aud: "host", host: 0 }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("node:fs/promises");
|
||||
const JSZip = require("jszip");
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import JSZip from "jszip";
|
||||
import path from "node:path";
|
||||
|
||||
const { patch, SaveModule } = require("@clusterio/host/dist/node/src/patch");
|
||||
const lib = require("@clusterio/lib");
|
||||
import { patch, SaveModule } from "@clusterio/host/dist/node/src/patch.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
const { slowTest } = require("./index");
|
||||
import { slowTest } from "./index.js";
|
||||
|
||||
|
||||
// The server integration test is required to run before this one
|
||||
require("./server");
|
||||
import "./server.js";
|
||||
|
||||
describe("Integration of lib/factorio/patch", function() {
|
||||
describe("patch()", function() {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const { Host, Instance, InstanceConnection } = require("@clusterio/host");
|
||||
const { ControlConnection, Controller, HostConnection, InstanceRecord } = require("@clusterio/controller");
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { Host, Instance, InstanceConnection } from "@clusterio/host";
|
||||
import { ControlConnection, Controller, HostConnection, InstanceRecord } from "@clusterio/controller";
|
||||
|
||||
// Although there are no imports, the file has side-effects such as "before" which can effect tests
|
||||
require("./index");
|
||||
import "./index.js";
|
||||
|
||||
const addr = lib.Address.fromShorthand;
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import events from "node:events";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const { InstanceManager } = require("@clusterio/controller");
|
||||
const { FactorioServer, _getFactorioVersion } = require("@clusterio/host/dist/node/src/server");
|
||||
const { logger } = lib;
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { InstanceManager } from "@clusterio/controller";
|
||||
import { FactorioServer, _getFactorioVersion } from "@clusterio/host/dist/node/src/server.js";
|
||||
import { logger } from "@clusterio/lib";
|
||||
|
||||
const { slowTest, factorioDir, requiresFactorio } = require("./index");
|
||||
import { slowTest, factorioDir, requiresFactorio } from "./index.js";
|
||||
|
||||
|
||||
describe("Integration of host/src/server", function() {
|
||||
|
||||
Reference in new issue
Block a user