From ce5d0125408df4eb44f9a214cd2b9aa3d5bf48de Mon Sep 17 00:00:00 2001 From: soul Date: Tue, 17 Nov 2026 18:53:45 +0100 Subject: [PATCH] Wren becomes a test fixture; compose and validate refuse an offered hull with no schematic Move the starter-box aetheria.wren package from GameData/Mods to tests/fixtures/mods (LFS rule added) so it no longer ships; the Wren tests compose it through TestCatalog.RepoWithFixtures. ShipModCatalog.SchematicFault, built on LoadoutGenerator.IsOffered, excludes an offered hull with no schematic lines at compose and is reported by ship-authoring validate. Co-Authored-By: Claude Sonnet 5.5 --- .gitattributes | 2 + Assets/Scripts/ServerShared/ShipModCatalog.cs | 13 +++++ docs/element-ids.md | 2 +- docs/mining-cut-refresh.md | 4 +- .../ElementIdUpgradeTests.cs | 2 +- .../RestoredHullsTests.cs | 1 + .../ShipModCatalogTests.cs | 47 +++++++++++++++++++ .../Aetheria.Shared.Tests/ShipProductTests.cs | 24 ++++++++++ tests/Aetheria.Shared.Tests/TestCatalog.cs | 21 +++++++++ .../Aetheria.Shared.Tests/WrenPackageTests.cs | 10 ++-- .../fixtures/mods}/aetheria.wren/ship.cc | 0 .../fixtures/mods}/aetheria.wren/ship.glb | 0 tools/AetherDb/ShipAuthoringCommands.cs | 4 ++ 13 files changed, 121 insertions(+), 9 deletions(-) rename {GameData/Mods => tests/fixtures/mods}/aetheria.wren/ship.cc (100%) rename {GameData/Mods => tests/fixtures/mods}/aetheria.wren/ship.glb (100%) diff --git a/.gitattributes b/.gitattributes index 9d4b872b4..87c9db929 100644 --- a/.gitattributes +++ b/.gitattributes @@ -55,6 +55,8 @@ GameData/*.cc filter=lfs diff=lfs merge=lfs -text GameData/Mods/**/*.cc filter=lfs diff=lfs merge=lfs -text GameData/Mods/**/*.glb filter=lfs diff=lfs merge=lfs -text +tests/fixtures/mods/**/*.cc filter=lfs diff=lfs merge=lfs -text +tests/fixtures/mods/**/*.glb filter=lfs diff=lfs merge=lfs -text tools/blender/tests/fixtures/*.glb filter=lfs diff=lfs merge=lfs -text *.a filter=lfs diff=lfs merge=lfs -text *AkSoundEngine filter=lfs diff=lfs merge=lfs -text diff --git a/Assets/Scripts/ServerShared/ShipModCatalog.cs b/Assets/Scripts/ServerShared/ShipModCatalog.cs index 88dc06b85..d085974b4 100644 --- a/Assets/Scripts/ServerShared/ShipModCatalog.cs +++ b/Assets/Scripts/ServerShared/ShipModCatalog.cs @@ -110,6 +110,7 @@ public static class ShipModCatalog if (shipIds.Contains(ship.Id)) Exclude(directory, $"ship ID collides with an existing catalog ship authoring record."); if (StationKinds.HullKindFault(cache, hull) is { } kindFault) Exclude(directory, kindFault); + if (SchematicFault(cache, ship, package.Products) is { } schematicFault) Exclude(directory, schematicFault); foreach (var product in package.Products) { if (!factionKeys.Contains(product.Manufacturer.Key)) @@ -157,6 +158,18 @@ public static class ShipModCatalog } } + // Why a package's hull cannot go on the market, or null: a hull offered through any of its products is drawn on the map and + // the schematic by its lines (ShipModVisual.BuildLineMesh builds nothing from none), so an offered hull without any is + // excluded. An unoffered stand-in is left alone. Offered is LoadoutGenerator.IsOffered, the one reader of NotOffered + // (ruling off-market-is-unoffered-product); `items` is the catalog the products' bins resolve in. A product whose bin + // line the catalog does not hold is not judged here: the catalog read refuses it. + public static string SchematicFault(CultCache items, ShipAuthoring ship, FactionProductData[] products) + { + if (ship.SchematicLines != null && ship.SchematicLines.Any(line => line?.Points != null && line.Points.Length > 0)) return null; + var offered = products.Any(product => (product.Bin == null || items.Get(product.Bin.Line) != null) && LoadoutGenerator.IsOffered(items, product)); + return offered ? $"{ship.Id}: the hull is offered on the market but has no schematic lines." : null; + } + public static Package ReadPackage(string shipPath) { var path = Path.GetFullPath(shipPath); diff --git a/docs/element-ids.md b/docs/element-ids.md index b4ae9584a..32ccdafc8 100644 --- a/docs/element-ids.md +++ b/docs/element-ids.md @@ -26,7 +26,7 @@ that some intermediate pins read a single-file v3 store silently and drop the id writers, keep a pre-upgrade copy of any real store (`GameData/Aetheria.cc` and the mod packages are tracked in git; player saves and run stores are not), and do not roll the pin back after a store has been written under the new one. -The shipped mod packages (`GameData/Mods/aetheria.wren/ship.cc`, `aetheria.nakovalnya/ship.cc`) held only default +The shipped mod package (`GameData/Mods/aetheria.nakovalnya/ship.cc`) and the test fixture package (`tests/fixtures/mods/aetheria.wren/ship.cc`) held only default placeholders (`0` and `[]`) in the retired `HullData` slots 21 and 22, which the new CultLib refuses to write over (`CultSchemaConflictException`). They were regenerated with `AetherDb ship-authoring regenerate apply`, which loads the records, writes them into a fresh file under the current schema, requires them to read back identical and replaces the file. Both diff --git a/docs/mining-cut-refresh.md b/docs/mining-cut-refresh.md index 7adb1e951..b0bf89420 100644 --- a/docs/mining-cut-refresh.md +++ b/docs/mining-cut-refresh.md @@ -304,11 +304,11 @@ Every mining question is ruled. - LFS staging set. `SubstanceCleanBreakTests` fails loudly on any LFS pointer it scans, so the job must restore every LFS-tracked file under `Assets/`, `Packages/`, `ProjectSettings/` and `GameData/*.cc` that is not a binary-media extension (the test's `BinaryExtensions` denylist): 99 files at `83e6957de`, 96 `*.asset` and 3 - `*.cc` (`GameData/Aetheria.cc`, `GameData/Mods/aetheria.nakovalnya/ship.cc`, `GameData/Mods/aetheria.wren/ship.cc`), + `*.cc` (`GameData/Aetheria.cc`, `GameData/Mods/aetheria.nakovalnya/ship.cc`, `tests/fixtures/mods/aetheria.wren/ship.cc`), which includes `ProjectSettings/ProjectSettings.asset` and `Assets/Resources/Settings.asset`. Derive the list from the merged tree instead of hand-copying it: `git ls-files Assets Packages ProjectSettings 'GameData/*.cc' | git check-attr --stdin filter | grep 'lfs$' | sed 's/: filter: lfs//' | grep -viE '\.(png|jpg|jpeg|tga|tif|tiff|psd|bmp|gif|exr|hdr|dds|wav|mp3|ogg|mp4|fbx|glb|blend|ttf|otf|dll|so|pdb|msgpack|zip|bank)$'`, - then copy each path from the `/lfs` mount over the checkout. That set (99: the 97 the sbsar guards read plus the two mod `ship.cc` files the Nakovalnya and Wren tests open) makes `SubstanceCleanBreakTests` green and nothing more: staging only two files turns it red. For a fully green suite also stage `GameData/Mods/*/ship.glb` (the catalog excludes a package with an invalid GLB header, failing about 520 tests) and the LFS `.ttf`/`.otf` fonts `CreditsTests.FontCreditsShowWhatTheFontsThemselvesEmbed` reads. + then copy each path from the `/lfs` mount over the checkout. That set (99: the 97 the sbsar guards read plus the two mod `ship.cc` files the Nakovalnya and Wren tests open) makes `SubstanceCleanBreakTests` green and nothing more: staging only two files turns it red. For a fully green suite also stage `GameData/Mods/*/ship.glb` and `tests/fixtures/mods/*/ship.glb` (the catalog excludes a package with an invalid GLB header, failing about 520 tests) and the LFS `.ttf`/`.otf` fonts `CreditsTests.FontCreditsShowWhatTheFontsThemselvesEmbed` reads. - Unity batchmode compile of the merged tree (Self, in a worktree, never with the operator's editor open on the main tree). This is the Cut 1 renderer compile the map still owes. - Operator: fly through a belt (the Cut 1 check the map still owes). Rocks orbit smoothly, and the minimap diff --git a/tests/Aetheria.Shared.Tests/ElementIdUpgradeTests.cs b/tests/Aetheria.Shared.Tests/ElementIdUpgradeTests.cs index d94222635..682b20409 100644 --- a/tests/Aetheria.Shared.Tests/ElementIdUpgradeTests.cs +++ b/tests/Aetheria.Shared.Tests/ElementIdUpgradeTests.cs @@ -107,7 +107,7 @@ public class ElementIdUpgradeTests { using var directory = new TempDirectory(); var copy = Path.Combine(directory.Path, "ship.cc"); - File.Copy(Path.Combine(RunStartTests.FindRepoRoot(), "GameData", "Mods", "aetheria.wren", "ship.cc"), copy); + File.Copy(Path.Combine(RunStartTests.FindRepoRoot(), "tests", "fixtures", "mods", "aetheria.wren", "ship.cc"), copy); var bytes = File.ReadAllBytes(copy); var (hull, visual, products) = ShipAuthoringStore.Load(copy); diff --git a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs index 121d468b3..f5d3e8498 100644 --- a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs +++ b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs @@ -61,6 +61,7 @@ public sealed class RestoredHullsTests } internal static CultCache OpenCatalog() => OpenReadOnlyRealCatalog(TestCatalog.Repo); + internal static CultCache OpenCatalogWithFixtures() => OpenReadOnlyRealCatalog(TestCatalog.RepoWithFixtures); // Shared tutorial-galaxy construction settings (Assets/Resources/Settings.asset's own values), factored out // so every test that needs a real tutorial Galaxy -- not just EntranceZoneAlwaysGetsADockedStationAcrossSeeds diff --git a/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs b/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs index 175a6bd9f..b4003954c 100644 --- a/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipModCatalogTests.cs @@ -49,6 +49,53 @@ public sealed class ShipModCatalogTests : IDisposable AssertOnlyTheDerivedFile(); } + // A package selling one product through the one product writer, with or without schematic lines and offered or not. + private void PricedPackage(string id, bool lines, bool offered) + { + var factionKey = AddFaction(); + WritePackage(id, id, tweak: ship => + { + ship.Hull.Price = 100; + if (!lines) ship.Visual.SchematicLines = new List(); + }); + using var cache = ShipAuthoringStore.Open(Path.Combine(Mods, id, "ship.cc"), writable: true); + ShipAuthoringStore.WriteProduct(cache, id, new FactionProductData + { + Name = id + " product", + Design = new CultRecordRef(ShipModCatalog.HullKey(id)), + Manufacturer = new CultRecordRef(factionKey), + NotOffered = !offered + }); + cache.FlushAsync().Wait(); + } + + private CultRecordKey AddFaction() + { + using var cache = AetheriaStores.Open(Shipped, catalogWritable: true); + var existing = cache.GetAll().FirstOrDefault(); + var key = existing != null ? cache.RefOf(existing).Key : cache.Upsert(new Faction { Name = "Acme", ShortName = "ACM" }).Key; + cache.FlushAsync().Wait(); + return key; + } + + // An offered hull is drawn by its schematic lines (ShipModVisual.BuildLineMesh builds nothing from none), so one without any + // is left out of the catalog with its reason; an offered hull with lines and an unoffered stand-in without them both compose. + [Fact] + public void ComposeExcludesAnOfferedHullWithoutSchematicLinesAndKeepsTheRest() + { + PricedPackage("mod.offeredbare", lines: false, offered: true); + PricedPackage("mod.offeredlined", lines: true, offered: true); + PricedPackage("mod.standin", lines: false, offered: false); + + var composition = ShipModCatalog.Compose(Shipped, Derived, Mods); + + Assert.Equal(new[] { "mod.offeredlined", "mod.standin" }, composition.Included.OrderBy(id => id, StringComparer.Ordinal)); + var excluded = Assert.Single(composition.Excluded); + Assert.Equal("mod.offeredbare", excluded.Package); + Assert.Contains("mod.offeredbare", excluded.Reason); + Assert.Contains("no schematic", excluded.Reason); + } + // A package's station kind is checked per package: a bad one is left out, named with its reason, and the derived catalog // still opens. The shipped catalog's own check is unchanged. [Fact] diff --git a/tests/Aetheria.Shared.Tests/ShipProductTests.cs b/tests/Aetheria.Shared.Tests/ShipProductTests.cs index 82f094e88..0ee2db012 100644 --- a/tests/Aetheria.Shared.Tests/ShipProductTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipProductTests.cs @@ -99,6 +99,30 @@ public sealed class ShipProductTests : IDisposable } } + // validate gives the verdict compose gives: an offered hull with no schematic lines is refused, an unoffered one is not. + [Fact] + public void ValidateRefusesAnOfferedHullWithoutSchematicLinesAsComposeDoes() + { + Environment.CurrentDirectory = _root.Path; + string Bare(string id, bool offered) + { + var directory = ShipFixture.WritePackage(Mods, id, id, tweak: ship => { ship.Hull.Price = 100; ship.Visual.SchematicLines = new List(); }); + var path = Path.Combine(directory, "ship.cc"); + using var cache = ShipAuthoringStore.Open(path, writable: true); + var product = Product(id + " product", _acme, id); + product.NotOffered = !offered; + ShipAuthoringStore.WriteProduct(cache, id, product); + cache.FlushAsync().Wait(); + return path; + } + + var (code, _, error) = Run("validate", Bare("mod.offered", offered: true)); + Assert.Equal(1, code); + Assert.Contains("no schematic", error); + Assert.Equal(0, Run("validate", Bare("mod.standin", offered: false)).Item1); + Assert.Equal(new[] { "mod.standin" }, ShipModCatalog.Compose(Shipped, Derived, Mods).Included); + } + [Fact] public void APackageWithAnUnknownMakerIsExcluded() { diff --git a/tests/Aetheria.Shared.Tests/TestCatalog.cs b/tests/Aetheria.Shared.Tests/TestCatalog.cs index 60d41c996..2561406f2 100644 --- a/tests/Aetheria.Shared.Tests/TestCatalog.cs +++ b/tests/Aetheria.Shared.Tests/TestCatalog.cs @@ -18,6 +18,12 @@ internal static class TestCatalog // The repo's catalog with its first-party packages composed in, resolved once per test process. public static string Repo => Shared.Value; + private static readonly Lazy SharedWithFixtures = new Lazy(() => ForRepoWithFixtures(RunStartTests.FindRepoRoot())); + + // The repo's catalog with its first-party packages and the test fixture packages (tests/fixtures/mods) composed in. For a + // test whose subject is a fixture package; Repo is the catalog the game ships. + public static string RepoWithFixtures => SharedWithFixtures.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. @@ -34,6 +40,21 @@ internal static class TestCatalog return Resolve(Path.Combine(repoRoot, "GameData", "Aetheria.cc"), Path.Combine(repoRoot, "GameData", "Mods"), work); } + // ForRepo over a mods root assembled from GameData/Mods and tests/fixtures/mods, copied into the per-call temp directory. + public static string ForRepoWithFixtures(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) { } }; + var mods = Path.Combine(work, "Mods"); + foreach (var root in new[] { Path.Combine(repoRoot, "GameData", "Mods"), Path.Combine(repoRoot, "tests", "fixtures", "mods") }) + foreach (var package in Directory.GetDirectories(root)) + { + var target = Directory.CreateDirectory(Path.Combine(mods, Path.GetFileName(package))).FullName; + foreach (var file in Directory.GetFiles(package)) File.Copy(file, Path.Combine(target, Path.GetFileName(file))); + } + return Resolve(Path.Combine(repoRoot, "GameData", "Aetheria.cc"), mods, work); + } + 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 diff --git a/tests/Aetheria.Shared.Tests/WrenPackageTests.cs b/tests/Aetheria.Shared.Tests/WrenPackageTests.cs index bb95cbb55..3395d7f32 100644 --- a/tests/Aetheria.Shared.Tests/WrenPackageTests.cs +++ b/tests/Aetheria.Shared.Tests/WrenPackageTests.cs @@ -5,7 +5,7 @@ using Xunit; using static CultMath.math; using Random = CultMath.Random; -// GameData/Mods/aetheria.wren: a first-party package written by `ship-authoring starter --like Djinni`, then priced and given +// tests/fixtures/mods/aetheria.wren: a test fixture package, not shipped with the game, written by `ship-authoring starter --like Djinni`, then priced and given // an unoffered Aeronautics Unlimited product by `ship-authoring price` and `product`; its model is the starter's boxed // stand-in. It is the pipeline's proof from a hull package on disk to a ship that flies in the headless simulation: the // package composes into the catalog, its mounts take catalog gear, and the fitted ship moves under thrust. `fly` cannot @@ -19,7 +19,7 @@ public sealed class WrenPackageTests [Fact] public void TheStarterPackageIsInTheComposedCatalogWithTheStatsOfItsLike() { - using var cache = RestoredHullsTests.OpenCatalog(); + using var cache = RestoredHullsTests.OpenCatalogWithFixtures(); var hull = Wren(cache); var like = cache.GetByName("Djinni"); Assert.NotNull(hull); @@ -34,7 +34,7 @@ public sealed class WrenPackageTests [Fact] public void TheStarterIsMadeButNeverOffered() { - using var cache = RestoredHullsTests.OpenCatalog(); + using var cache = RestoredHullsTests.OpenCatalogWithFixtures(); var hull = Wren(cache); var product = Assert.Single(cache.GetAll(), p => p.Design.Key.Equals(ShipModCatalog.HullKey(Id))); Assert.Equal("Aeronautics Unlimited", cache.Get(product.Manufacturer).Name); @@ -47,7 +47,7 @@ public sealed class WrenPackageTests [Fact] public void EveryMountTakesACatalogDesign() { - using var cache = RestoredHullsTests.OpenCatalog(); + using var cache = RestoredHullsTests.OpenCatalogWithFixtures(); var designs = cache.GetAll().ToArray(); var bare = Wren(cache).Hardpoints.Where(hardpoint => !designs.Any(hardpoint.Takes)).Select(hardpoint => $"{hardpoint.Transform} ({hardpoint.Type})").ToArray(); // No shield design fits a 1x1 yet (hardpoint-fit lists Djinni's 4-cell shield with none either); every other mount does. @@ -57,7 +57,7 @@ public sealed class WrenPackageTests [Fact] public void TheStarterFliesUnderThrust() { - using var cache = RestoredHullsTests.OpenCatalog(); + using var cache = RestoredHullsTests.OpenCatalogWithFixtures(); var ship = RestoredHullsTests.BuildThrustedShip(cache, "Wren"); var start = ship.Velocity; ship.MovementDirection = float2(0, 1); diff --git a/GameData/Mods/aetheria.wren/ship.cc b/tests/fixtures/mods/aetheria.wren/ship.cc similarity index 100% rename from GameData/Mods/aetheria.wren/ship.cc rename to tests/fixtures/mods/aetheria.wren/ship.cc diff --git a/GameData/Mods/aetheria.wren/ship.glb b/tests/fixtures/mods/aetheria.wren/ship.glb similarity index 100% rename from GameData/Mods/aetheria.wren/ship.glb rename to tests/fixtures/mods/aetheria.wren/ship.glb diff --git a/tools/AetherDb/ShipAuthoringCommands.cs b/tools/AetherDb/ShipAuthoringCommands.cs index 458ae4038..4298bc198 100644 --- a/tools/AetherDb/ShipAuthoringCommands.cs +++ b/tools/AetherDb/ShipAuthoringCommands.cs @@ -53,6 +53,10 @@ public static class ShipAuthoringCommands var judged = model != null && File.Exists(model) ? "records and model" : "records only, no model yet"; if (judged == "records and model") ShipModCatalog.ReadPackage(args[1]); else ShipAuthoringStore.ValidateLoaded(hull, ship, products); + // Compose refuses an offered hull with no schematic; the author sees that verdict here, before compose. + // A package with no products is never offered, so the shipped catalog (which only resolves a product's bin) is opened for none. + using var catalog = products.Length > 0 ? AetherDb.Open().Cache : null; + if (ShipModCatalog.SchematicFault(catalog, ship, products) is { } fault) throw new InvalidOperationException(fault); Console.WriteLine($"{ship.Id}: {hull.Name}, {hull.Hardpoints.Count} hardpoints, {ship.Anchors.Count} anchors, {ship.SchematicLines.Count} lines ({judged})"); return 0; }