mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Resolve GameVersion type as a plain-string supertype
Cooldude's GameVersion brand was disjoint from the clean version types in both directions, forcing safeVersion/safeFactorioVersion companions and breaking widening from FullVersion at file-name call sites. Make GameVersion a plain string alias: the raw, un-normalised version as the game reads it. The stricter template-literal types (FullVersion, MajorMinorVersion, PartialVersion) now widen into it for free, while a GameVersion still can't be used where a normalised version is required without going through normaliseGameVersion/integerGameVersion. Runtime validation stays in GameVersionSchema. - Drop safeVersion/safeFactorioVersion; ModInfo.version stays raw (verbatim so it matches the mod's file name), integerVersion normalises via the new integerGameVersion. factorioVersion reverts to a normalised MajorMinorVersion since it is never part of a file name. - ModRecord.version becomes a GameVersion so mod packs round-trip the exact file-name version. - ModVersionEquality.testVersion / ModVersionRange.testVersion accept a raw GameVersion and normalise it; the equality bound stays strictly validated. - Migration only pads clean partial versions; raw versions are kept verbatim. - Cover the leading-zeros case: version kept verbatim in the file name while comparing equal to its normalised form. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
523293d4d9
commit
8029ad3b2d
8 files changed
+75
-42
No files matched your search
@@ -341,15 +341,27 @@ describe("lib/data/ModInfo", function() {
|
||||
dependencies: ["base", ""],
|
||||
}), /my-mod/); // check the mod name is included in the error message
|
||||
});
|
||||
it("should normalise lenient version fields the way the game reads them", function() {
|
||||
it("should keep the raw mod version but normalise it for comparison", function() {
|
||||
const mod = ModInfo.fromJSON({
|
||||
name: "my-mod",
|
||||
version: " 1.2.3-extra",
|
||||
factorio_version: "1.1.0",
|
||||
});
|
||||
assert.equal(mod.version, "1.2.3");
|
||||
// The version is kept verbatim so it still matches the mod's file name,
|
||||
// but is read leniently the way the game does when compared.
|
||||
assert.equal(mod.version, " 1.2.3-extra");
|
||||
assert.equal(mod.integerVersion, ModInfo.fromJSON({ version: "1.2.3" }).integerVersion);
|
||||
// factorio_version is not part of any file name, so it is reduced to major.minor.
|
||||
assert.equal(mod.factorioVersion, "1.1");
|
||||
});
|
||||
it("should keep leading zeros in the version so the file name matches", function() {
|
||||
// Mirrors the mods.factorio.com/mod/leading-zeros case: the version has
|
||||
// a zero-padded component that the file name keeps verbatim.
|
||||
const mod = ModInfo.fromJSON({ name: "leading-zeros", version: "1.01.0" });
|
||||
assert.equal(mod.version, "1.01.0");
|
||||
assert.equal(mod.filename, "leading-zeros_1.01.0.zip");
|
||||
assert.equal(mod.integerVersion, ModInfo.fromJSON({ version: "1.1.0" }).integerVersion);
|
||||
});
|
||||
it("should throw for an unparseable mod version", function() {
|
||||
assert.throws(
|
||||
() => ModInfo.fromJSON({ name: "my-mod", version: "not-a-version" }),
|
||||
|
||||
Reference in new issue
Block a user