mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 23:24:52 +09:00
Strip downloads by the components the scenario started them with
The instance read its config when the controller answered, so a sync_ field changed during the download could strip a component the scenario still expected, and the scenario treated it as empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aa06b9afe3
commit
45fedf28a0
5 files changed
+26
-18
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
components, enabledComponents, mergePlayerData, stripPlayerData, uploadedComponents,
|
||||
components, enabledComponents, mergePlayerData, stripPlayerData, scenarioComponents,
|
||||
} from "../dist/node/components.js";
|
||||
|
||||
const allComponents = Object.keys(components);
|
||||
@@ -79,19 +79,19 @@ describe("player_sync components", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("uploadedComponents()", function() {
|
||||
it("should sync everything when the upload has no components", function() {
|
||||
assert.deepEqual([...uploadedComponents(undefined)], allComponents);
|
||||
describe("scenarioComponents()", function() {
|
||||
it("should sync everything when no components are sent", function() {
|
||||
assert.deepEqual([...scenarioComponents(undefined)], allComponents);
|
||||
});
|
||||
it("should sync the components marked true", function() {
|
||||
const enabled = uploadedComponents({ force: true, quick_bar: true, settings: false });
|
||||
const enabled = scenarioComponents({ force: true, quick_bar: true, settings: false });
|
||||
assert.deepEqual([...enabled], ["force", "quick_bar"]);
|
||||
});
|
||||
it("should sync nothing for an empty table encoded as an array", function() {
|
||||
assert.equal(uploadedComponents([]).size, 0);
|
||||
assert.equal(scenarioComponents([]).size, 0);
|
||||
});
|
||||
it("should sync the controller without the inventories", function() {
|
||||
assert.deepEqual([...uploadedComponents({ controller: true })], ["controller"]);
|
||||
assert.deepEqual([...scenarioComponents({ controller: true })], ["controller"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -129,14 +129,19 @@ describe("player_sync", function() {
|
||||
const expected = { generation: 1, name: "test", recipe_notifications: await encode({ add: ["a"] }) };
|
||||
assert.deepEqual(instance.server.rconCommands, [downloadCommand(expected)]);
|
||||
});
|
||||
it("should leave out components the instance does not sync", async function() {
|
||||
instance.mockConfigEntries.set("player_sync.sync_force", false);
|
||||
instance.mockConfigEntries.set("player_sync.sync_recipe_notifications", false);
|
||||
it("should leave out components the download was not started with", async function() {
|
||||
respondWith({ generation: 1, name: "test", force: "enemy", tag: "tag", recipe_notifications: "x" });
|
||||
await download({ player_name: "test" });
|
||||
await download({ player_name: "test", components: { appearance: true } });
|
||||
const expected = { generation: 1, name: "test", tag: "tag" };
|
||||
assert.deepEqual(instance.server.rconCommands, [downloadCommand(expected)]);
|
||||
});
|
||||
it("should ignore config changes made after the download was started", async function() {
|
||||
instance.mockConfigEntries.set("player_sync.sync_force", false);
|
||||
respondWith({ generation: 1, name: "test", force: "enemy", tag: "tag" });
|
||||
await download({ player_name: "test", components: { force: true } });
|
||||
const expected = { generation: 1, name: "test", force: "enemy" };
|
||||
assert.deepEqual(instance.server.rconCommands, [downloadCommand(expected)]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("set_components", function() {
|
||||
|
||||
Reference in new issue
Block a user