From da4d8c6c962971107cd36208a9e46d70135b0737 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 10 Oct 2026 06:50:18 +0200 Subject: [PATCH] Fixture boots the game's catalog under one scoped registry; missing ship.cc is an exclusion; GLB extension is lowercase only AetheriaStores.Open, ShipModCatalog.Compose and ResolveCatalog take an optional registry (the game passes none and keeps the process-wide one). TestCatalog.Registry() is the shipped assembly's registry, so the test assembly's TestCatalogGlobal is no longer a catalog global the real catalog must hold (fixture-fails-on-real-package). TestCatalog.ForRepo(root) is the one binding Repo uses, pinned by a test over a real catalog plus a package (repo-wiring-unpinned). A package directory without ship.cc is excluded with a reason, in Compose and so in ResolveCatalog's pre-check (missing-ship-cc-skipped). The loader takes only a lowercase .glb, matching the case-sensitive LFS rule (lfs-glb-case). All commits build; not yet run (verification job follows). Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/AetheriaStores.cs | 7 +++- Assets/Scripts/ServerShared/ShipModCatalog.cs | 17 ++++---- tests/Aetheria.Shared.Tests/RunStartTests.cs | 6 +-- .../ShipModCatalogTests.cs | 33 ++++++++++++++++ tests/Aetheria.Shared.Tests/TestCatalog.cs | 28 +++++++++---- .../Aetheria.Shared.Tests/TestCatalogTests.cs | 39 +++++++++++++++++-- 6 files changed, 103 insertions(+), 27 deletions(-) diff --git a/Assets/Scripts/ServerShared/AetheriaStores.cs b/Assets/Scripts/ServerShared/AetheriaStores.cs index f265151c9..b335e3442 100644 --- a/Assets/Scripts/ServerShared/AetheriaStores.cs +++ b/Assets/Scripts/ServerShared/AetheriaStores.cs @@ -13,9 +13,12 @@ public static class AetheriaStores // Attaches (hydrates) the catalog read-only unless catalogWritable, then the run and player stores when given. // Throws when a [CultGlobal] type routed to the catalog has no record. The one exemption is a writable catalog with // no records at all, a seed store being authored from nothing; a populated catalog is held to it however it opens. - public static CultCache Open(string catalogPath, string runPath = null, string playerPath = null, bool catalogWritable = false) + // The registry is the process-wide one unless the caller scopes it (the test host does, so its own document types never + // become catalog globals); the global check above is judged against whichever registry opened the cache. + public static CultCache Open(string catalogPath, string runPath = null, string playerPath = null, bool catalogWritable = false, + CultDocumentRegistry registry = null) { - var cache = new CultCache(); + var cache = new CultCache(registry); try { cache.AddBackingStore(new SingleFileMessagePackBackingStore(catalogPath, !catalogWritable), CatalogTypes); diff --git a/Assets/Scripts/ServerShared/ShipModCatalog.cs b/Assets/Scripts/ServerShared/ShipModCatalog.cs index 38216f481..dab613d21 100644 --- a/Assets/Scripts/ServerShared/ShipModCatalog.cs +++ b/Assets/Scripts/ServerShared/ShipModCatalog.cs @@ -45,7 +45,7 @@ public static class ShipModCatalog // named. A collision (with the shipped catalog, or with another package's hull name) excludes every package involved, // since neither has a claim to the name. The derived catalog holds the shipped catalog plus the included packages. // Unsafe inputs and outputs (a missing catalog, a derived file that would replace a source) still throw: nothing is composed. - public static Composition Compose(string shippedCatalog, string outputCatalog, string modsRoot) + public static Composition Compose(string shippedCatalog, string outputCatalog, string modsRoot, CultDocumentRegistry registry = null) { var source = Path.GetFullPath(shippedCatalog); var output = Path.GetFullPath(outputCatalog); @@ -67,8 +67,9 @@ 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); } @@ -84,7 +85,7 @@ public static class ShipModCatalog Directory.CreateDirectory(workspace); File.Copy(source, temporary); Composition composition; - using (var cache = AetheriaStores.Open(temporary, catalogWritable: true)) + using (var cache = AetheriaStores.Open(temporary, catalogWritable: true, registry: registry)) { // Collisions are judged against the shipped records alone, before any package is written, so the // verdict does not depend on directory order. CultCache indexes names per concrete type and lets the @@ -153,14 +154,14 @@ public static class ShipModCatalog // The one game-side choice of catalog: the shipped file when no package is installed or none survives composition, // otherwise the derived file, composed afresh from the shipped one and the surviving packages. Recomposed every // call, so the derived file is never stale and never an authority. Excluded packages come back named, for the menu. - public static (string Catalog, Exclusion[] Excluded) ResolveCatalog(string shippedCatalog, string derivedCatalog, string modsRoot) + public static (string Catalog, Exclusion[] Excluded) ResolveCatalog(string shippedCatalog, string derivedCatalog, string modsRoot, + CultDocumentRegistry registry = null) { - if (!Directory.Exists(modsRoot) || - !Directory.GetDirectories(modsRoot).Any(directory => File.Exists(Path.Combine(directory, "ship.cc")))) + if (!Directory.Exists(modsRoot) || Directory.GetDirectories(modsRoot).Length == 0) 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. - try { composition = Compose(shippedCatalog, derivedCatalog, modsRoot); } + try { composition = Compose(shippedCatalog, derivedCatalog, modsRoot, registry); } catch (Exception error) { return (shippedCatalog, new[] { new Exclusion { Package = "(all mods)", Reason = error.Message } }); } return (composition.Included.Length == 0 ? shippedCatalog : derivedCatalog, composition.Excluded); } @@ -171,7 +172,7 @@ public static class ShipModCatalog throw new InvalidOperationException($"{path}: ship ID must match its package directory name."); var modelPath = Path.GetFullPath(Path.Combine(directory, ship.ModelAsset)); // Containment is ShipAuthoringStore.Validate's job: it refuses rooted and `..` model paths before this line. - if (!File.Exists(modelPath) || !string.Equals(Path.GetExtension(modelPath), ".glb", StringComparison.OrdinalIgnoreCase)) + if (!File.Exists(modelPath) || !string.Equals(Path.GetExtension(modelPath), ".glb", StringComparison.Ordinal)) throw new InvalidOperationException($"{ship.Id}: model asset must name an existing GLB inside its package."); var modelNodes = ReadNodeIds(modelPath); foreach (var anchor in ship.Anchors) diff --git a/tests/Aetheria.Shared.Tests/RunStartTests.cs b/tests/Aetheria.Shared.Tests/RunStartTests.cs index 1111842a5..f1e76f5f6 100644 --- a/tests/Aetheria.Shared.Tests/RunStartTests.cs +++ b/tests/Aetheria.Shared.Tests/RunStartTests.cs @@ -42,7 +42,7 @@ public sealed partial class RunStartTests : IDisposable // A registry scoped to the shipped assembly's own [CultDocument] types, as RestoredHullsTests composes it, so // this test assembly's own documents never reach the real catalog's validation. - _cache = new CultCache(Registry()); + _cache = new CultCache(TestCatalog.Registry()); _cache.AddBackingStore(new SingleFileMessagePackBackingStore(catalog), AetheriaStores.CatalogTypes); _cache.AddBackingStore(new SingleFileMessagePackBackingStore(Path.Combine(_root, "run.cc")), AetheriaStores.RunTypes); @@ -68,10 +68,6 @@ public sealed partial class RunStartTests : IDisposable Directory.Delete(_root, true); } - private static CultDocumentRegistry Registry() => CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() - .Where(t => t is { IsAbstract: false, IsInterface: false }) - .Where(t => t.GetCustomAttribute() != null)); - internal static string FindRepoRoot() { for (var dir = new DirectoryInfo(AppContext.BaseDirectory); dir != null; dir = dir.Parent) diff --git a/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs b/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs index a2426906b..0c119cf91 100644 --- a/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs @@ -286,6 +286,39 @@ 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() + { + WritePackage("mod.skiff", modelAsset: "skiff.GLB"); + + var excluded = Assert.Single(ShipModCatalog.Compose(Shipped, Derived, Mods).Excluded); + + Assert.Equal("mod.skiff", excluded.Package); + Assert.Contains("GLB", excluded.Reason); + } + // The game's boot: a bad package is named and the rest boot; with none left, the shipped catalog boots. [Fact] public void TheBootCatalogSurvivesBadPackages() diff --git a/tests/Aetheria.Shared.Tests/TestCatalog.cs b/tests/Aetheria.Shared.Tests/TestCatalog.cs index 1c4e1c289..9a1bcefdf 100644 --- a/tests/Aetheria.Shared.Tests/TestCatalog.cs +++ b/tests/Aetheria.Shared.Tests/TestCatalog.cs @@ -5,26 +5,38 @@ using System; using System.IO; using System.Linq; +using System.Reflection; +using GameCult.Caching; // The catalog the game boots, for tests: ShipModCatalog.ResolveCatalog over GameData/Mods, the call ActionGameManager // makes. The game skips a broken package so a player still boots; a test never does, so an exclusion throws here and // a broken first-party package fails the suite instead of vanishing from it. internal static class TestCatalog { - private static readonly Lazy Shared = new Lazy(() => - { - var repo = RunStartTests.FindRepoRoot(); - var work = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetheria-testcatalog-" + Guid.NewGuid().ToString("N"))).FullName; - AppDomain.CurrentDomain.ProcessExit += (_, _) => { try { Directory.Delete(work, true); } catch (IOException) { } }; - return Resolve(Path.Combine(repo, "GameData", "Aetheria.cc"), Path.Combine(repo, "GameData", "Mods"), work); - }); + private static readonly Lazy Shared = new Lazy(() => ForRepo(RunStartTests.FindRepoRoot())); // The repo's catalog with its first-party packages composed in, resolved once per test process. public static string Repo => Shared.Value; + // The shipped assembly's own [CultDocument] types and nothing the test assembly registers (CultDocumentRegistry.ForTypes + // does not re-scan the AppDomain), so this assembly's fixture documents never become catalog globals the real catalog + // must hold. The one registry every test that opens a real catalog, and the composition behind Repo, uses. + public static CultDocumentRegistry Registry() => CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() + .Where(t => t is { IsAbstract: false, IsInterface: false }) + .Where(t => t.GetCustomAttribute() != null)); + + // The catalog of the repository at repoRoot: /GameData/Aetheria.cc plus /GameData/Mods, composed into a + // per-call temp directory that goes away with the process. + public static string ForRepo(string repoRoot) + { + var work = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetheria-testcatalog-" + Guid.NewGuid().ToString("N"))).FullName; + AppDomain.CurrentDomain.ProcessExit += (_, _) => { try { Directory.Delete(work, true); } catch (IOException) { } }; + return Resolve(Path.Combine(repoRoot, "GameData", "Aetheria.cc"), Path.Combine(repoRoot, "GameData", "Mods"), work); + } + public static string Resolve(string shippedCatalog, string modsRoot, string workDir) { - var (catalog, excluded) = ShipModCatalog.ResolveCatalog(shippedCatalog, Path.Combine(workDir, "derived.cc"), modsRoot); + 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: " + string.Join("; ", excluded.Select(entry => entry.Package + ": " + entry.Reason))); diff --git a/tests/Aetheria.Shared.Tests/TestCatalogTests.cs b/tests/Aetheria.Shared.Tests/TestCatalogTests.cs index 4d95c4aec..32e832dee 100644 --- a/tests/Aetheria.Shared.Tests/TestCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/TestCatalogTests.cs @@ -16,9 +16,7 @@ public sealed class TestCatalogTests : IDisposable public TestCatalogTests() { Directory.CreateDirectory(Mods); - using var cache = AetheriaStores.Open(Shipped, catalogWritable: true); - // The test assembly registers TestCatalogGlobal (AetheriaStoresTests), so any populated catalog must hold one. - cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); + using var cache = AetheriaStores.Open(Shipped, catalogWritable: true, registry: TestCatalog.Registry()); cache.Upsert(new HullData { Name = "Wasp", Shape = ShipAuthoringTests.Fixture().Hull.Shape }); cache.FlushAsync().Wait(); } @@ -44,7 +42,7 @@ public sealed class TestCatalogTests : IDisposable var catalog = TestCatalog.Resolve(Shipped, Mods, Work); Assert.NotEqual(Shipped, catalog); - using var cache = AetheriaStores.Open(catalog); + using var cache = AetheriaStores.Open(catalog, registry: TestCatalog.Registry()); Assert.Equal("Skiff", cache.Get(ShipModCatalog.HullKey("mod.skiff")).Name); Assert.Contains("Wasp", cache.GetAll().Select(hull => hull.Name)); } @@ -61,4 +59,37 @@ public sealed class TestCatalogTests : IDisposable Assert.Contains("mod.broken", error.Message); Assert.DoesNotContain("mod.good", error.Message); } + + [Fact] + public void AFirstPartyPackageComposesOverTheRealCatalog() + { + // A repository root holding the real shipped catalog (which has no TestCatalogGlobal record) and one valid package + // under GameData/Mods, the layout TestCatalog.Repo resolves from. + var root = Path.Combine(_directory.Path, "repo"); + Directory.CreateDirectory(Path.Combine(root, "GameData")); + File.Copy(Path.Combine(RunStartTests.FindRepoRoot(), "GameData", "Aetheria.cc"), Path.Combine(root, "GameData", "Aetheria.cc")); + ShipFixture.WritePackage(Path.Combine(root, "GameData", "Mods"), "mod.skiff", hullName: "FixtureSkiff"); + + var catalog = TestCatalog.ForRepo(root); + + Assert.NotEqual(Path.Combine(root, "GameData", "Aetheria.cc"), catalog); + // Opened as RunStartTests opens it: the shipped assembly's registry, the game's own global check. + using var cache = AetheriaStores.Open(catalog, registry: TestCatalog.Registry()); + Assert.Equal("FixtureSkiff", cache.Get(ShipModCatalog.HullKey("mod.skiff")).Name); + Assert.NotEmpty(cache.GetAll().Where(hull => hull.Name != "FixtureSkiff")); + } + + [Fact] + public void APackageWithoutItsShipFileFailsLoudly() + { + ShipFixture.WritePackage(Mods, "mod.good", hullName: "Good"); + ShipFixture.WritePackage(Mods, "mod.lost", hullName: "Lost"); + File.Delete(Path.Combine(Mods, "mod.lost", "ship.cc")); + + var error = Assert.Throws(() => TestCatalog.Resolve(Shipped, Mods, Work)); + + Assert.Contains("mod.lost", error.Message); + Assert.Contains("ship.cc", error.Message); + Assert.DoesNotContain("mod.good", error.Message); + } }