mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Refuse to start without required mods and download them
requiredMods entries are now Factorio dependency strings, and a mod listed twice gives a version range. The plugin loader validates them. The host refuses to start an instance whose mod pack is missing a required mod of a loaded plugin, has it disabled or has it outside the version range. On start the controller resolves the required mods of its plugins and their dependencies for the default mod pack's Factorio version and downloads the ones missing from the mod store. The resolver and portal download move from the ControlConnection handlers into Controller methods so both paths share them. Subspace Storage requires subspace_storage >= 1.99.0, and the integration tests build a stub of that mod for the test mod pack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a845b7ac52
commit
bf33f4f52e
12 files changed
+437
-240
No files matched your search
@@ -305,6 +305,50 @@ describe("controller/src/Controller", function() {
|
||||
await assert.rejects(Controller.loadJsonObject(path.join(dir, "invalid.json")), SyntaxError);
|
||||
});
|
||||
});
|
||||
describe(".downloadRequiredMods()", function() {
|
||||
let ctrl, resolveCalls, downloadCalls, resolved;
|
||||
function modInfo(name, version) {
|
||||
return lib.ModInfo.fromJSON({ name, version, factorio_version: "2.0" });
|
||||
}
|
||||
beforeEach(function() {
|
||||
const config = new ControllerConfig("controller", { "controller.version": controllerVersion });
|
||||
ctrl = new Controller({}, [
|
||||
{ name: "foo", title: "Foo", requiredMods: ["foo_mod >= 1.0.0"] },
|
||||
{ name: "bar", title: "Bar" },
|
||||
], config);
|
||||
const modPack = ModPack.fromJSON({ id: 7, name: "default", factorio_version: "2.0.10" });
|
||||
ctrl.modPacks.set(modPack);
|
||||
config.set("controller.default_mod_pack_id", 7);
|
||||
resolveCalls = [];
|
||||
downloadCalls = [];
|
||||
resolved = [modInfo("foo_mod", "1.2.0"), modInfo("dep_mod", "0.1.0")];
|
||||
ctrl.resolveModDependencies = async (mods, factorioVersion) => {
|
||||
resolveCalls.push([mods.map(mod => mod.spec), factorioVersion]);
|
||||
return new lib.ModDependencyResolveRequest.Response(resolved, new Map());
|
||||
};
|
||||
ctrl.downloadModsFromPortal = async (mods, factorioVersion) => {
|
||||
downloadCalls.push([mods.map(mod => `${mod.name} ${mod.version}`), factorioVersion]);
|
||||
};
|
||||
});
|
||||
|
||||
it("should download required mods and their dependencies for the default mod pack", async function() {
|
||||
await ctrl.downloadRequiredMods();
|
||||
assert.deepEqual(resolveCalls, [[["foo_mod >= 1.0.0"], "2.0"]]);
|
||||
assert.deepEqual(downloadCalls, [[["foo_mod = 1.2.0", "dep_mod = 0.1.0"], "2.0"]]);
|
||||
});
|
||||
|
||||
it("should skip mods already in the mod store", async function() {
|
||||
ctrl.modStore = new lib.ModStore("mods", new Map(resolved.map(info => [info.filename, info])));
|
||||
await ctrl.downloadRequiredMods();
|
||||
assert.deepEqual(downloadCalls, []);
|
||||
});
|
||||
|
||||
it("should do nothing when no plugin requires mods", async function() {
|
||||
ctrl.pluginInfos = [{ name: "bar", title: "Bar" }];
|
||||
await ctrl.downloadRequiredMods();
|
||||
assert.deepEqual(resolveCalls, []);
|
||||
});
|
||||
});
|
||||
describe(".loggableHeaders()", function() {
|
||||
it("should redact credentials and keep other headers", function() {
|
||||
const headers = {
|
||||
|
||||
+25
-15
@@ -337,12 +337,9 @@ describe("class Instance", function() {
|
||||
});
|
||||
|
||||
describe(".checkRequiredMods()", function() {
|
||||
let warnings;
|
||||
beforeEach(function() {
|
||||
warnings = [];
|
||||
instance.logger = { warn(message) { warnings.push(message); } };
|
||||
instance.loadedPlugins = new Set([
|
||||
{ name: "foo", requiredMods: ["foo_mod", "bar_mod"] },
|
||||
{ name: "foo", requiredMods: ["foo_mod", "bar_mod >= 1.1.0", "bar_mod < 2.0.0"] },
|
||||
{ name: "bar" },
|
||||
]);
|
||||
});
|
||||
@@ -350,22 +347,35 @@ describe("class Instance", function() {
|
||||
return lib.ModPack.fromJSON({ name: "pack", mods });
|
||||
}
|
||||
|
||||
it("should not warn when the required mods are enabled", function() {
|
||||
it("should accept a mod pack with the required mods", function() {
|
||||
instance.checkRequiredMods(modPack([
|
||||
{ name: "foo_mod", enabled: true, version: "1.0.0" },
|
||||
{ name: "bar_mod", enabled: true, version: "1.0.0" },
|
||||
{ name: "bar_mod", enabled: true, version: "1.1.0" },
|
||||
]));
|
||||
assert.deepEqual(warnings, []);
|
||||
});
|
||||
|
||||
it("should warn about missing and disabled required mods", function() {
|
||||
instance.checkRequiredMods(modPack([
|
||||
{ name: "foo_mod", enabled: false, version: "1.0.0" },
|
||||
]));
|
||||
assert.deepEqual(warnings, [
|
||||
"Plugin foo requires foo_mod, bar_mod which are not enabled in mod pack pack. " +
|
||||
"Add them to the mod pack or set foo.load_plugin to false for this instance.",
|
||||
]);
|
||||
it("should reject missing, disabled and out of range mods", function() {
|
||||
const expected = (unmet) => new lib.ConflictError(
|
||||
"Mod pack pack does not have the mods required by the loaded plugins. " +
|
||||
`Plugin foo requires ${unmet}. ` +
|
||||
"Add the mods to the mod pack or set <plugin>.load_plugin to false for this instance."
|
||||
);
|
||||
assert.throws(
|
||||
() => instance.checkRequiredMods(modPack([{ name: "bar_mod", enabled: true, version: "1.0.0" }])),
|
||||
expected("foo_mod (missing), bar_mod >= 1.1.0 (found 1.0.0)"),
|
||||
);
|
||||
assert.throws(
|
||||
() => instance.checkRequiredMods(modPack([
|
||||
{ name: "foo_mod", enabled: false, version: "1.0.0" },
|
||||
{ name: "bar_mod", enabled: true, version: "2.0.0" },
|
||||
])),
|
||||
expected("foo_mod (disabled), bar_mod < 2.0.0 (found 2.0.0)"),
|
||||
);
|
||||
});
|
||||
|
||||
it("should ignore plugins that are not loaded", function() {
|
||||
instance.loadedPlugins = new Set([{ name: "bar" }]);
|
||||
instance.checkRequiredMods(modPack([]));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -353,6 +353,21 @@ before(async function() {
|
||||
sourceDir: "packages/host/lua/clusterio_lib",
|
||||
outputDir: modsDir,
|
||||
});
|
||||
// Stand-in for the mod required by the subspace_storage plugin
|
||||
const subspaceStorageDir = path.join("temp", "test", "subspace_storage");
|
||||
await fs.rm(subspaceStorageDir, { force: true, recursive: true });
|
||||
await fs.mkdir(subspaceStorageDir, { recursive: true });
|
||||
await fs.writeFile(path.join(subspaceStorageDir, "info.json"), JSON.stringify({
|
||||
name: "subspace_storage",
|
||||
variants: [
|
||||
{ version: "2.3.20", factorio_version: "2.0" },
|
||||
{ version: "2.3.21", factorio_version: "2.1" },
|
||||
],
|
||||
title: "Subspace Storage test stub",
|
||||
author: "Clusterio Team",
|
||||
dependencies: ["base", "clusterio_lib"],
|
||||
}));
|
||||
await lib.build({ build: true, pack: true, sourceDir: subspaceStorageDir, outputDir: modsDir });
|
||||
|
||||
console.log("Setting Controller Config");
|
||||
await execController("config create");
|
||||
@@ -410,6 +425,9 @@ before(async function() {
|
||||
|
||||
const [major, minor] = lib.normaliseMajorMinorVersion(latestFactorioVersion).split(".");
|
||||
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: `2.1.${major}${minor}` });
|
||||
testPack.mods.set(
|
||||
"subspace_storage", { name: "subspace_storage", enabled: true, version: `2.3.${major}${minor}` }
|
||||
);
|
||||
|
||||
await control.sendTo("controller", new lib.ModPackCreateRequest(testPack));
|
||||
await control.sendTo(
|
||||
|
||||
@@ -24,4 +24,22 @@ describe("lib/plugin", function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("pluginRequiredMods()", function() {
|
||||
it("should parse dependency strings", function() {
|
||||
const mods = lib.pluginRequiredMods({
|
||||
name: "foo", title: "Foo", requiredMods: ["bar", "baz >= 1.2.0", "baz < 2.0.0"],
|
||||
});
|
||||
assert.deepEqual(mods.map(mod => [mod.name, mod.version?.toString()]), [
|
||||
["bar", undefined], ["baz", ">= 1.2.0"], ["baz", "< 2.0.0"],
|
||||
]);
|
||||
});
|
||||
it("should return an empty list without requiredMods", function() {
|
||||
assert.deepEqual(lib.pluginRequiredMods({ name: "foo", title: "Foo" }), []);
|
||||
});
|
||||
it("should reject dependency prefixes and invalid versions", function() {
|
||||
for (const spec of ["? bar", "! bar", "~ bar", "bar >= 1..2"]) {
|
||||
assert.throws(() => lib.pluginRequiredMods({ name: "foo", title: "Foo", requiredMods: [spec] }));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user