diff --git a/Assets/Scripts/ServerShared/ShipModCatalog.cs b/Assets/Scripts/ServerShared/ShipModCatalog.cs index dab613d21..13fcd587f 100644 --- a/Assets/Scripts/ServerShared/ShipModCatalog.cs +++ b/Assets/Scripts/ServerShared/ShipModCatalog.cs @@ -67,9 +67,8 @@ public static class ShipModCatalog foreach (var directory in Directory.GetDirectories(root).OrderBy(path => path, StringComparer.Ordinal)) { var path = Path.Combine(directory, "ship.cc"); + if (!File.Exists(path)) continue; var name = Path.GetFileName(directory); - // A package directory without its ship.cc is a package that lost its records, named like any other failure. - if (!File.Exists(path)) { Exclude(name, "the package holds no ship.cc."); continue; } // A package can fail in any way a hostile or broken file can, so its failure is quarantined whatever it is. try { packages.Add((name, ReadPackage(path))); } catch (Exception error) { Exclude(name, error.Message); } @@ -157,7 +156,8 @@ public static class ShipModCatalog public static (string Catalog, Exclusion[] Excluded) ResolveCatalog(string shippedCatalog, string derivedCatalog, string modsRoot, CultDocumentRegistry registry = null) { - if (!Directory.Exists(modsRoot) || Directory.GetDirectories(modsRoot).Length == 0) + if (!Directory.Exists(modsRoot) || + !Directory.GetDirectories(modsRoot).Any(directory => File.Exists(Path.Combine(directory, "ship.cc")))) return (shippedCatalog, Array.Empty()); Composition composition; // A failure of the composition itself (an unwritable derived path, say) is still a mod problem, never a reason not to boot. diff --git a/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs b/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs index 0c119cf91..1fe18a4e6 100644 --- a/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs @@ -286,27 +286,6 @@ public sealed class ShipModCatalogTests : IDisposable Assert.Equal("ship ID collides with an existing catalog ship authoring record.", Assert.Single(composition.Excluded).Reason); } - // A package directory that lost its ship.cc is a package left out, named with the reason; it never vanishes silently. - [Fact] - public void APackageDirectoryWithoutAShipFileIsExcludedWithAReason() - { - WritePackage("mod.good", hullName: "Good"); - WritePackage("mod.lost", hullName: "Lost"); - File.Delete(Path.Combine(Mods, "mod.lost", "ship.cc")); - - var composition = ShipModCatalog.Compose(Shipped, Derived, Mods); - - Assert.Equal(new[] { "mod.good" }, composition.Included); - var lost = Assert.Single(composition.Excluded); - Assert.Equal("mod.lost", lost.Package); - Assert.Equal("the package holds no ship.cc.", lost.Reason); - - Directory.Delete(Path.Combine(Mods, "mod.good"), true); - var (catalog, excluded) = ShipModCatalog.ResolveCatalog(Shipped, Derived, Mods); - Assert.Equal(Shipped, catalog); - Assert.Equal("mod.lost", Assert.Single(excluded).Package); - } - // The loader and the LFS rule (GameData/Mods/**/*.glb) agree: only a lowercase .glb is a model. [Fact] public void AModelWithAnUppercaseExtensionIsRefused() diff --git a/tests/Aetheria.Shared.Tests/TestCatalog.cs b/tests/Aetheria.Shared.Tests/TestCatalog.cs index 9a1bcefdf..60d41c996 100644 --- a/tests/Aetheria.Shared.Tests/TestCatalog.cs +++ b/tests/Aetheria.Shared.Tests/TestCatalog.cs @@ -36,6 +36,14 @@ internal static class TestCatalog public static string Resolve(string shippedCatalog, string modsRoot, string workDir) { + // Every directory under the first-party tree is a package. The game treats a directory without a ship.cc as not a + // package (a stray folder is not an error for a player), so the compose never names it; a first-party package whose + // ship.cc is gone must not vanish from the catalog the suite stages from. + var lost = Directory.Exists(modsRoot) + ? Directory.GetDirectories(modsRoot).Where(directory => !File.Exists(Path.Combine(directory, "ship.cc"))).Select(Path.GetFileName).OrderBy(name => name, StringComparer.Ordinal).ToArray() + : Array.Empty(); + if (lost.Length > 0) + throw new InvalidOperationException("First-party packages hold no ship.cc: " + string.Join(", ", lost)); var (catalog, excluded) = ShipModCatalog.ResolveCatalog(shippedCatalog, Path.Combine(workDir, "derived.cc"), modsRoot, Registry()); if (excluded.Length > 0) throw new InvalidOperationException("First-party packages were excluded from the catalog: " +