From a39ef352acc0fe73464cb0ee1fd7475438b77229 Mon Sep 17 00:00:00 2001 From: soul Date: Thu, 26 Nov 2026 18:06:33 +0100 Subject: [PATCH] Tests that pinned the shipped catalog before the ore batch and the rescale now read what the batch ships (18 failures at the previous head, all passing at d1ff2f78e) Gear price pins move to the rescaled values (PdGearStatsAreAuthored, LaunchSuppressorCatalogTests, ConsumablesFirstSetTests); the two one-shot command tests compare a landed design to the shipped record through GearPrices.Rescaled, since the commands keep their gear-scale literals. A test that takes factions out of a catalog copy takes their stand-ins too (the batch stands every faction in on mining), and the station-kind worlds start with none. Shipped provinces are stripped where a test deals its own. Recipes with Inputs read an empty RoleInputs (the first smelting step takes roles); the simple commodity count is 50. Co-Authored-By: Claude Sonnet 5.5 --- .../Aetheria.Shared.Tests/CommodityRecordsTests.cs | 2 +- .../ConsumablesFirstSetTests.cs | 4 ++-- .../Aetheria.Shared.Tests/EvasionTrackingTests.cs | 6 +++--- tests/Aetheria.Shared.Tests/GearPrices.cs | 12 ++++++++++++ .../InspectionScannerCommandTests.cs | 8 +++++++- .../LaunchSuppressorCatalogTests.cs | 4 ++-- .../LaunchSuppressorCommandTests.cs | 14 ++++++++++---- tests/Aetheria.Shared.Tests/MinorPowersTests.cs | 1 + tests/Aetheria.Shared.Tests/OreGeographyTests.cs | 13 ++++++++++++- .../PiratesFactionCommandTests.cs | 1 + .../Aetheria.Shared.Tests/RecipeRoleInputTests.cs | 4 +++- tests/Aetheria.Shared.Tests/StationKindTests.cs | 13 +++++++++++++ 12 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/GearPrices.cs diff --git a/tests/Aetheria.Shared.Tests/CommodityRecordsTests.cs b/tests/Aetheria.Shared.Tests/CommodityRecordsTests.cs index b59885c26..f0bc1159a 100644 --- a/tests/Aetheria.Shared.Tests/CommodityRecordsTests.cs +++ b/tests/Aetheria.Shared.Tests/CommodityRecordsTests.cs @@ -13,7 +13,7 @@ public sealed class CommodityRecordsTests public void ShippedCatalogOpensWithTheRetiredKeysGone() { using var cache = RestoredHullsTests.OpenCatalog(); - Assert.Equal(24, cache.GetAll().Count()); + Assert.Equal(50, cache.GetAll().Count()); Assert.Equal(63, cache.GetAll().Count()); Assert.Contains(cache.GetAll(), c => c.Name == "Ammo"); Assert.All(cache.GetAll(), c => Assert.False(string.IsNullOrEmpty(c.Name))); diff --git a/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs b/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs index a3858a407..840f1a1e7 100644 --- a/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs @@ -53,7 +53,7 @@ public sealed class ConsumablesFirstSetTests Assert.Equal(1, overdrive.Shape.Width); Assert.Equal(1, overdrive.Shape.Height); Assert.Equal(10f, overdrive.Mass); - Assert.Equal(18000, overdrive.Price); + Assert.Equal(180, overdrive.Price); Assert.False(overdrive.Stackable); Assert.Equal(6f, overdrive.Duration); Assert.Equal(new[] { "propellant", "regulator" }, overdrive.Roles.Select(r => r.Name).ToArray()); @@ -68,7 +68,7 @@ public sealed class ConsumablesFirstSetTests Assert.Equal(1, vent.Shape.Width); Assert.Equal(1, vent.Shape.Height); Assert.Equal(15f, vent.Mass); - Assert.Equal(12000, vent.Price); + Assert.Equal(120, vent.Price); Assert.False(vent.Stackable); Assert.Equal(15f, vent.Duration); Assert.Equal(new[] { "nozzle", "coolant" }, vent.Roles.Select(r => r.Name).ToArray()); diff --git a/tests/Aetheria.Shared.Tests/EvasionTrackingTests.cs b/tests/Aetheria.Shared.Tests/EvasionTrackingTests.cs index f6c461aab..bda7eb1ea 100644 --- a/tests/Aetheria.Shared.Tests/EvasionTrackingTests.cs +++ b/tests/Aetheria.Shared.Tests/EvasionTrackingTests.cs @@ -365,11 +365,11 @@ public sealed partial class RunStartTests (float min, float max) velocity, (float min, float max) energy, (float min, float max) heat, (float min, float max) visibility, bool ammo, int magazine, float reload)[] { - ("Point Defense Gun", 40f, 80000, 60f, WeaponModifiers.RapidFire, (1.5f, 4f), (1f, 1f), (300f, 550f), (.06f, .025f), (1f, .3f), + ("Point Defense Gun", 40f, 800, 60f, WeaponModifiers.RapidFire, (1.5f, 4f), (1f, 1f), (300f, 550f), (.06f, .025f), (1f, .3f), (1100f, 1600f), (.4f, .2f), (40f, 15f), (400f, 150f), true, 250, 3f), - ("Point Defense Laser", 30f, 110000, 30f, PdDesign("Light Laser").WeaponModifiers, (5f, 12f), (1f, 1f), (400f, 750f), (.2f, .1f), (.05f, 0f), + ("Point Defense Laser", 30f, 1100, 30f, PdDesign("Light Laser").WeaponModifiers, (5f, 12f), (1f, 1f), (400f, 750f), (.2f, .1f), (.05f, 0f), (0f, 0f), (6f, 10f), (300f, 150f), (300f, 100f), false, PdDesign("Light Laser").Behaviors.OfType().Single().MagazineSize, PdDesign("Light Laser").Behaviors.OfType().Single().ReloadTime), - ("Flak Gun", 120f, 180000, 80f, WeaponModifiers.Cluster, (30f, 70f), (6f, 8f), (350f, 800f), (.6f, .35f), (4f, 2f), + ("Flak Gun", 120f, 1800, 80f, WeaponModifiers.Cluster, (30f, 70f), (6f, 8f), (350f, 800f), (.6f, .35f), (4f, 2f), (900f, 1300f), (1f, .5f), (300f, 150f), (800f, 300f), true, 40, 4f), }; foreach (var e in expected) diff --git a/tests/Aetheria.Shared.Tests/GearPrices.cs b/tests/Aetheria.Shared.Tests/GearPrices.cs new file mode 100644 index 000000000..1cfb97d9d --- /dev/null +++ b/tests/Aetheria.Shared.Tests/GearPrices.cs @@ -0,0 +1,12 @@ +using System; + +// The one-shot catalog commands (pd-gear, launch-suppressor, inspection-scanner, ...) author gear at the prices they were written +// with, a hundred times the shipped catalog's (cut gear-money-rescale: Equippable and Consumable prices were divided by 100 once and +// the commands keep their literals). A test that sets a command's landed design against the shipped record compares the price +// through this, the transform the rescale applied: half away from zero, never below 1. +internal static class GearPrices +{ + public const int Divisor = 100; + + public static int Rescaled(int price) => Math.Max(1, (int) Math.Round(price / (double) Divisor, MidpointRounding.AwayFromZero)); +} diff --git a/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs b/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs index 8dbc47873..666d6fae7 100644 --- a/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs @@ -19,6 +19,7 @@ public sealed class InspectionScannerCommandTests : IDisposable // The design and products as the shipped catalog holds them, taken before they are removed from the scratch copy. private readonly byte[] _shippedDesign; + private readonly int _shippedPrice; private readonly string[] _shippedProducts; private static byte[] Pack(GearData design) => @@ -39,6 +40,7 @@ public sealed class InspectionScannerCommandTests : IDisposable cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); var design = Assert.Single(cache.GetAll(), g => g.Name == DesignName); _shippedDesign = Pack(design); + _shippedPrice = design.Price; var key = cache.RefOf(design).Key; var products = cache.GetAll().Where(p => p.Design.Key.Equals(key)).ToArray(); _shippedProducts = products.Select(p => Describe(cache, p)).OrderBy(x => x, StringComparer.Ordinal).ToArray(); @@ -88,7 +90,11 @@ public sealed class InspectionScannerCommandTests : IDisposable Assert.NotEqual(before, landed); var (designs, products) = Read(); // The record keys are CultCache's to mint and differ run to run; the design and products do not. - Assert.True(_shippedDesign.AsSpan().SequenceEqual(Pack(Assert.Single(designs))), "the design differs from the shipped catalog's record"); + // The command authors at its own literal price, a hundred times the shipped (GearPrices); everything else is the shipped record. + var landedDesign = Assert.Single(designs); + Assert.Equal(_shippedPrice, GearPrices.Rescaled(landedDesign.Price)); + landedDesign.Price = _shippedPrice; + Assert.True(_shippedDesign.AsSpan().SequenceEqual(Pack(landedDesign)), "the design differs from the shipped catalog's record"); Assert.Equal(_shippedProducts, products); // A second apply finds everything authored and writes nothing; so does a dry run. diff --git a/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs b/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs index 7a1481670..8e1392359 100644 --- a/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs @@ -42,8 +42,8 @@ public sealed class LaunchSuppressorCatalogTests var computer = Design(cache, "Targeting Computer"); var designs = new[] { - (Design: Design(cache, StrongName), Price: 40000, Factor: (.08f, .03f), Heat: (1.4f, .8f), Rated: (310f, 330f)), - (Design: Design(cache, MildName), Price: 25000, Factor: (.4f, .2f), Heat: (.8f, .5f), Rated: (310f, 330f)), + (Design: Design(cache, StrongName), Price: 400, Factor: (.08f, .03f), Heat: (1.4f, .8f), Rated: (310f, 330f)), + (Design: Design(cache, MildName), Price: 250, Factor: (.4f, .2f), Heat: (.8f, .5f), Rated: (310f, 330f)), }; foreach (var (design, price, factor, heat, rated) in designs) { diff --git a/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs b/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs index 47cc9a29e..1d7fb2cd6 100644 --- a/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs @@ -18,7 +18,7 @@ public sealed class LaunchSuppressorCommandTests : IDisposable private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc"); // The designs and products as the shipped catalog holds them, taken before they are removed from the scratch copy. - private readonly (string Name, byte[] Bytes)[] _shippedDesigns; + private readonly (string Name, int Price, byte[] Bytes)[] _shippedDesigns; private readonly string[] _shippedProducts; private static byte[] Pack(GearData design) => @@ -39,7 +39,7 @@ public sealed class LaunchSuppressorCommandTests : IDisposable cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); var designs = cache.GetAll().Where(g => DesignNames.Contains(g.Name)).ToArray(); Assert.Equal(DesignNames.Length, designs.Length); - _shippedDesigns = designs.Select(d => (d.Name, Pack(d))).ToArray(); + _shippedDesigns = designs.Select(d => (d.Name, d.Price, Pack(d))).ToArray(); var keys = designs.Select(d => cache.RefOf(d).Key).ToArray(); var products = cache.GetAll().Where(p => keys.Any(k => p.Design.Key.Equals(k))).ToArray(); _shippedProducts = products.Select(p => Describe(cache, p)).OrderBy(x => x, StringComparer.Ordinal).ToArray(); @@ -89,8 +89,14 @@ public sealed class LaunchSuppressorCommandTests : IDisposable Assert.NotEqual(before, landed); var (designs, products) = Read(); // The record keys are CultCache's to mint and differ run to run; the designs and products do not. - foreach (var (name, bytes) in _shippedDesigns) - Assert.True(bytes.AsSpan().SequenceEqual(Pack(designs.Single(d => d.Name == name))), $"{name} differs from the shipped catalog's record"); + // The command authors at its own literal price, a hundred times the shipped (GearPrices); everything else is the shipped record. + foreach (var (name, price, bytes) in _shippedDesigns) + { + var landedDesign = designs.Single(d => d.Name == name); + Assert.Equal(price, GearPrices.Rescaled(landedDesign.Price)); + landedDesign.Price = price; + Assert.True(bytes.AsSpan().SequenceEqual(Pack(landedDesign)), $"{name} differs from the shipped catalog's record"); + } Assert.Equal(_shippedProducts, products); // A second apply finds everything authored and writes nothing; so does a dry run. diff --git a/tests/Aetheria.Shared.Tests/MinorPowersTests.cs b/tests/Aetheria.Shared.Tests/MinorPowersTests.cs index 1988a033e..2ed33cab3 100644 --- a/tests/Aetheria.Shared.Tests/MinorPowersTests.cs +++ b/tests/Aetheria.Shared.Tests/MinorPowersTests.cs @@ -38,6 +38,7 @@ public sealed class MinorPowersTests : IDisposable Assert.Equal(3, gone.Length); foreach (var product in cache.GetAll().Where(p => gone.Any(g => g.Key.Equals(p.Manufacturer.Key))).ToArray()) Assert.True(cache.Remove(cache.RefOf(product).Key)); + TestStationKinds.DropStandInsOf(cache, gone.Select(g => g.Key).ToArray()); foreach (var reference in gone) Assert.True(cache.Remove(reference.Key)); foreach (var faction in cache.GetAll()) foreach (var key in faction.Allegiance.Keys.Where(k => gone.Any(g => g.Key.Equals(k.Key))).ToArray()) diff --git a/tests/Aetheria.Shared.Tests/OreGeographyTests.cs b/tests/Aetheria.Shared.Tests/OreGeographyTests.cs index 764ec66c0..bae4d18aa 100644 --- a/tests/Aetheria.Shared.Tests/OreGeographyTests.cs +++ b/tests/Aetheria.Shared.Tests/OreGeographyTests.cs @@ -754,13 +754,16 @@ public sealed class OreGeographyTests : IDisposable }).ToArray(); var (cache, _, _) = Shipped(); + var (bare, _, _) = Shipped(); + StripShippedProvinces(cache); + StripShippedProvinces(bare); Province(cache, "one", 2); Province(cache, "two", 1); var compared = 0; foreach (var prelude in new[] {false, true}) for (uint seed = 1; seed <= 4; seed++) { - var without = SharedGalaxy(prelude, seed); + var without = TryBuild(bare, prelude, seed); var with = TryBuild(cache, prelude, seed); Assert.Equal(without == null, with == null); if (without == null) continue; @@ -937,6 +940,13 @@ public sealed class OreGeographyTests : IDisposable private ItemManager Items(CultCache cache) => new ItemManager(1u, cache, new ProvenanceLedger(), Authored.Read("GameplaySettings"), _ => { }); + // The shipped catalog deals six province types (batch OresAndProvinces); a test that draws by provinces it adds, or compares a galaxy dealt + // none with one dealt some, takes the shipped ones out first. + private static void StripShippedProvinces(CultCache cache) + { + foreach (var existing in cache.GetAll().ToArray()) Assert.True(cache.Remove(cache.RefOf(existing).Key)); + } + private static void SilenceShippedKinds(CultCache cache) { foreach (var existing in cache.GetAll().ToArray()) @@ -955,6 +965,7 @@ public sealed class OreGeographyTests : IDisposable { var (cache, _, _) = Shipped(); SilenceShippedKinds(cache); + StripShippedProvinces(cache); var a = Kind(cache, "a", 1f); var b = Kind(cache, "b", 1f); Province(cache, "no-a", 1, new[] {KindFactor(a, 0f)}); diff --git a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs index 99ec92249..1dee99d84 100644 --- a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs @@ -32,6 +32,7 @@ public sealed class PiratesFactionCommandTests : IDisposable var ours = cache.RefOf(pirates); foreach (var product in cache.GetAll().Where(product => product.Manufacturer.Equals(ours)).ToArray()) Assert.True(cache.Remove(cache.RefOf(product).Key)); + TestStationKinds.DropStandInsOf(cache, ours.Key); Assert.True(cache.Remove(ours.Key)); cache.FlushAsync().Wait(); } diff --git a/tests/Aetheria.Shared.Tests/RecipeRoleInputTests.cs b/tests/Aetheria.Shared.Tests/RecipeRoleInputTests.cs index fdf387130..b348d58e3 100644 --- a/tests/Aetheria.Shared.Tests/RecipeRoleInputTests.cs +++ b/tests/Aetheria.Shared.Tests/RecipeRoleInputTests.cs @@ -29,7 +29,9 @@ public sealed class RecipeRoleInputTests using var cache = AetheriaStores.Open(TestCatalog.Repo, registry: TestCatalog.Registry()); var recipes = cache.GetAll().ToArray(); Assert.NotEmpty(recipes); - Assert.All(recipes, r => { Assert.NotNull(r.RoleInputs); Assert.Empty(r.RoleInputs); }); + Assert.All(recipes, r => Assert.NotNull(r.RoleInputs)); + // Only the batch's first smelting step takes a role instead of a commodity: every recipe with Inputs reads an empty list. + Assert.All(recipes.Where(r => r.Inputs.Count > 0), r => Assert.Empty(r.RoleInputs)); } [Fact] diff --git a/tests/Aetheria.Shared.Tests/StationKindTests.cs b/tests/Aetheria.Shared.Tests/StationKindTests.cs index dc28fd955..a30221d48 100644 --- a/tests/Aetheria.Shared.Tests/StationKindTests.cs +++ b/tests/Aetheria.Shared.Tests/StationKindTests.cs @@ -13,6 +13,17 @@ using Random = CultMath.Random; internal static class TestStationKinds { public static readonly CultRecordRef TradeHub = new CultRecordRef(StationKindData.KeyOf("trade-hub")); + + // A test that takes factions out of a catalog copy takes their stand-ins with them: a stand-in naming a faction the catalog no + // longer holds is a refused catalog (StationKinds.Validate), and the shipped catalog stands every faction in on mining. + public static void DropStandInsOf(CultCache cache, params CultRecordKey[] factions) + { + foreach (var kind in cache.GetAll().Where(k => k.StandIns.Any(s => factions.Contains(s.Faction.Key))).ToArray()) + { + kind.StandIns.RemoveAll(s => factions.Contains(s.Faction.Key)); + cache.Commit(batch => batch.Upsert(typeof(StationKindData), kind, cache.RefOf(kind).Key)); + } + } } // Station kinds (aetheria-living-world, cut station-kind-datum): the one list of kinds in the catalog, a hull's kind, a @@ -53,6 +64,8 @@ public sealed class StationKindTests : IDisposable host._caches.Add(cache); cache.AddBackingStore(new SingleFileMessagePackBackingStore(Path.Combine(dir, "Aetheria.cc")), AetheriaStores.CatalogTypes); cache.AddBackingStore(new SingleFileMessagePackBackingStore(Path.Combine(dir, "run.cc")), AetheriaStores.RunTypes); + // The shipped catalog stands every faction in on mining (batch OresAndProvinces); these worlds hold only the stand-ins a test adds. + foreach (var kind in cache.GetAll().Where(k => k.StandIns.Count > 0).ToArray()) { kind.StandIns.Clear(); cache.Upsert(kind); } var world = new World { Cache = cache }; world.Items = new ItemManager(1u, cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), world.Log.Add); world.Zh = cache.GetAll().Single(f => f.Name == "Zhestokost");