mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Merge remote-tracking branch 'upstream/master' into feature/wait-for-plugin
This commit is contained in:
commit
7f688d2ed0
77 files changed
+2006
-693
No files matched your search
@@ -6,7 +6,8 @@ import stream from "node:stream";
|
||||
// Capture native fetch before any potential mocks are applied
|
||||
const nativeFetch = global.fetch;
|
||||
|
||||
import { ModStore, ModInfo, ModVersionEquality, zipOutputStream } from "@clusterio/lib";
|
||||
import { ModStore, ModInfo, ModVersionEquality, zipOutputStream, hashFile } from "@clusterio/lib";
|
||||
import * as libBuildMod from "@clusterio/lib/build_mod.js";
|
||||
import { externalTest, createZip, createZipBuffer } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
@@ -706,6 +707,38 @@ describe("lib/ModStore", function () {
|
||||
});
|
||||
|
||||
// === Instance Methods ===
|
||||
describe("readModInfo (static)", function () {
|
||||
it("should load from a mod zip file", async function () {
|
||||
await libBuildMod.build({
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("test", "file", "empty_mod"),
|
||||
outputDir: path.join("temp", "test"),
|
||||
});
|
||||
const filePath = path.join("temp", "test", "empty_mod_1.0.0.zip");
|
||||
const hash = await hashFile(filePath);
|
||||
const stat = await fs.stat(filePath);
|
||||
const mod = await ModStore.readModInfo(filePath);
|
||||
assert.deepEqual(
|
||||
mod,
|
||||
ModInfo.fromJSON({
|
||||
name: "empty_mod",
|
||||
version: "1.0.0",
|
||||
title: "An Empty Mod",
|
||||
author: "Me",
|
||||
description: "An empty mod for testing",
|
||||
factorio_version: "1.1",
|
||||
dependencies: [],
|
||||
filename: "empty_mod_1.0.0.zip",
|
||||
size: stat.size,
|
||||
mtime_ms: stat.mtimeMs,
|
||||
updated_at_ms: stat.mtimeMs,
|
||||
sha1: hash,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Instance Methods", function () {
|
||||
let modStore;
|
||||
let testMod1Name = "test-mod-1";
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as libBuildMod from "@clusterio/lib/build_mod.js";
|
||||
import { ModInfo, ModDependency } from "@clusterio/lib";
|
||||
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../../common.js";
|
||||
@@ -413,35 +410,6 @@ describe("lib/data/ModInfo", function() {
|
||||
["UltraMod", "SuperLib >= 1.00", "! bad-mod"].map(dep => new ModDependency(dep))
|
||||
);
|
||||
});
|
||||
it("should load from a mod zip file", async function() {
|
||||
await libBuildMod.build({
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("test", "file", "empty_mod"),
|
||||
outputDir: path.join("temp", "test"),
|
||||
});
|
||||
const filePath = path.join("temp", "test", "empty_mod_1.0.0.zip");
|
||||
const hash = await lib.hashFile(filePath);
|
||||
const stat = await fs.stat(filePath);
|
||||
const mod = await ModInfo.fromModFile(filePath);
|
||||
assert.deepEqual(
|
||||
mod,
|
||||
ModInfo.fromJSON({
|
||||
name: "empty_mod",
|
||||
version: "1.0.0",
|
||||
title: "An Empty Mod",
|
||||
author: "Me",
|
||||
description: "An empty mod for testing",
|
||||
factorio_version: "1.1",
|
||||
dependencies: [],
|
||||
filename: "empty_mod_1.0.0.zip",
|
||||
size: stat.size,
|
||||
mtime_ms: stat.mtimeMs,
|
||||
updated_at_ms: stat.mtimeMs,
|
||||
sha1: hash,
|
||||
})
|
||||
);
|
||||
});
|
||||
describe("checkDependencySatisfaction()", function() {
|
||||
it("should return undefined when satisfied", function() {
|
||||
const mod = ModInfo.fromJSON({ dependencies: ["! a", "b = 1.0.0", "? c = 2.0.0"] });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { testLines } from "./factorio/lines.js";
|
||||
@@ -66,6 +67,77 @@ describe("lib/logging_utils.js", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("class DailyFileTransport", function() {
|
||||
let tempDir = path.join("temp", "test", "daily_file");
|
||||
beforeEach(async function() {
|
||||
await fs.rm(tempDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function create(now, dirname = tempDir) {
|
||||
return new lib.DailyFileTransport({ dirname, prefix: "test", now });
|
||||
}
|
||||
function write(transport, message) {
|
||||
transport.log({ [Symbol.for("message")]: JSON.stringify({ message }) }, () => {});
|
||||
}
|
||||
async function close(transport) {
|
||||
await new Promise(resolve => transport.close(resolve));
|
||||
}
|
||||
async function read(file) {
|
||||
let content = await fs.readFile(path.join(tempDir, file), "utf8");
|
||||
assert(content.endsWith(os.EOL));
|
||||
return content.split(os.EOL).slice(0, -1).map(line => JSON.parse(line).message);
|
||||
}
|
||||
|
||||
it("should create the directory and write lines to the file for the UTC date", async function() {
|
||||
let transport = create(() => Date.parse("2026-11-19T12:00:00Z"), path.join(tempDir, "nested"));
|
||||
write(transport, "first");
|
||||
write(transport, "second");
|
||||
await close(transport);
|
||||
assert.deepEqual(await read(path.join("nested", "test-2026-11-19.log")), ["first", "second"]);
|
||||
});
|
||||
|
||||
it("should append to an existing file", async function() {
|
||||
await fs.mkdir(tempDir, { recursive: true });
|
||||
await fs.writeFile(path.join(tempDir, "test-2026-11-19.log"), `{"message":"old"}${os.EOL}`);
|
||||
let transport = create(() => Date.parse("2026-11-19T12:00:00Z"));
|
||||
write(transport, "new");
|
||||
await close(transport);
|
||||
assert.deepEqual(await read("test-2026-11-19.log"), ["old", "new"]);
|
||||
});
|
||||
|
||||
it("should switch files when the UTC date changes", async function() {
|
||||
let time = Date.parse("2026-11-19T23:59:59.999Z");
|
||||
let transport = create(() => time);
|
||||
write(transport, "before");
|
||||
time += 1;
|
||||
write(transport, "after");
|
||||
await close(transport);
|
||||
assert.deepEqual((await fs.readdir(tempDir)).sort(), ["test-2026-11-19.log", "test-2026-11-20.log"]);
|
||||
assert.deepEqual(await read("test-2026-11-19.log"), ["before"]);
|
||||
assert.deepEqual(await read("test-2026-11-20.log"), ["after"]);
|
||||
});
|
||||
|
||||
it("should use the UTC date rather than the local one", async function() {
|
||||
let transport = create(() => Date.parse("2026-11-20T00:30:00+02:00"));
|
||||
write(transport, "message");
|
||||
await close(transport);
|
||||
assert.deepEqual(await fs.readdir(tempDir), ["test-2026-11-19.log"]);
|
||||
});
|
||||
|
||||
it("should emit write errors", async function() {
|
||||
await fs.mkdir(path.join(tempDir, "test-2026-11-19.log"), { recursive: true });
|
||||
let transport = create(() => Date.parse("2026-11-19T12:00:00Z"));
|
||||
let error = new Promise(resolve => transport.once("error", resolve));
|
||||
write(transport, "message");
|
||||
assert.equal((await error).code, "EISDIR");
|
||||
});
|
||||
|
||||
it("should close when nothing was written", async function() {
|
||||
await close(create(Date.now));
|
||||
assert.deepEqual(await fs.readdir(tempDir), []);
|
||||
});
|
||||
});
|
||||
|
||||
describe("deleteOldLogs", function() {
|
||||
let tempDir = path.join("temp", "test", "log_retention");
|
||||
let files = [
|
||||
|
||||
@@ -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] }));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/* eslint-disable node/no-sync */
|
||||
import assert from "node:assert/strict";
|
||||
import zlib from "node:zlib";
|
||||
|
||||
import * as browserZlib from "../../packages/lib/src/zlib_sync.browser.ts";
|
||||
|
||||
describe("lib/zlib_sync.browser", function() {
|
||||
const text = JSON.stringify({ name: "pack", mods: [{ name: "base", version: "2.0.0" }] });
|
||||
|
||||
it("should inflate data deflated by node:zlib", function() {
|
||||
const inflated = browserZlib.inflateSync(zlib.deflateSync(text));
|
||||
assert.equal(Buffer.from(inflated).toString(), text);
|
||||
});
|
||||
it("should deflate data node:zlib can inflate", function() {
|
||||
assert.equal(zlib.inflateSync(browserZlib.deflateSync(text)).toString(), text);
|
||||
const bytes = Buffer.from(text);
|
||||
assert.equal(zlib.inflateSync(browserZlib.deflateSync(bytes)).toString(), text);
|
||||
});
|
||||
it("should throw with a Z_ code on invalid data", function() {
|
||||
assert.throws(
|
||||
() => browserZlib.inflateSync(Buffer.from("not zlib data")),
|
||||
err => err.code === "Z_DATA_ERROR"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user