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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-10 06:50:18 +02:00
commit da4d8c6c96
6 changed files with 103 additions and 27 deletions

View file

@ -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);

View file

@ -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<Exclusion>());
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)

View file

@ -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<CultDocumentAttribute>() != null));
internal static string FindRepoRoot()
{
for (var dir = new DirectoryInfo(AppContext.BaseDirectory); dir != null; dir = dir.Parent)

View file

@ -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()

View file

@ -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<string> Shared = new Lazy<string>(() =>
{
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<string> Shared = new Lazy<string>(() => 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<CultDocumentAttribute>() != null));
// The catalog of the repository at repoRoot: <root>/GameData/Aetheria.cc plus <root>/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)));

View file

@ -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<HullData>(ShipModCatalog.HullKey("mod.skiff")).Name);
Assert.Contains("Wasp", cache.GetAll<HullData>().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<HullData>(ShipModCatalog.HullKey("mod.skiff")).Name);
Assert.NotEmpty(cache.GetAll<HullData>().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<InvalidOperationException>(() => TestCatalog.Resolve(Shipped, Mods, Work));
Assert.Contains("mod.lost", error.Message);
Assert.Contains("ship.cc", error.Message);
Assert.DoesNotContain("mod.good", error.Message);
}
}