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 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-26 18:06:33 +01:00
commit a39ef352ac
12 changed files with 67 additions and 15 deletions

View file

@ -13,7 +13,7 @@ public sealed class CommodityRecordsTests
public void ShippedCatalogOpensWithTheRetiredKeysGone()
{
using var cache = RestoredHullsTests.OpenCatalog();
Assert.Equal(24, cache.GetAll<SimpleCommodityData>().Count());
Assert.Equal(50, cache.GetAll<SimpleCommodityData>().Count());
Assert.Equal(63, cache.GetAll<CompoundCommodityData>().Count());
Assert.Contains(cache.GetAll<SimpleCommodityData>(), c => c.Name == "Ammo");
Assert.All(cache.GetAll<CompoundCommodityData>(), c => Assert.False(string.IsNullOrEmpty(c.Name)));

View file

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

View file

@ -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<InstantWeaponData>().Single().MagazineSize, PdDesign("Light Laser").Behaviors.OfType<InstantWeaponData>().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)

View file

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

View file

@ -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<GearData>(), g => g.Name == DesignName);
_shippedDesign = Pack(design);
_shippedPrice = design.Price;
var key = cache.RefOf(design).Key;
var products = cache.GetAll<FactionProductData>().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.

View file

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

View file

@ -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<GearData>().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<FactionProductData>().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.

View file

@ -38,6 +38,7 @@ public sealed class MinorPowersTests : IDisposable
Assert.Equal(3, gone.Length);
foreach (var product in cache.GetAll<FactionProductData>().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<Faction>())
foreach (var key in faction.Allegiance.Keys.Where(k => gone.Any(g => g.Key.Equals(k.Key))).ToArray())

View file

@ -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>("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<ProvinceData>().ToArray()) Assert.True(cache.Remove(cache.RefOf(existing).Key));
}
private static void SilenceShippedKinds(CultCache cache)
{
foreach (var existing in cache.GetAll<FieldKindData>().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)});

View file

@ -32,6 +32,7 @@ public sealed class PiratesFactionCommandTests : IDisposable
var ours = cache.RefOf(pirates);
foreach (var product in cache.GetAll<FactionProductData>().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();
}

View file

@ -29,7 +29,9 @@ public sealed class RecipeRoleInputTests
using var cache = AetheriaStores.Open(TestCatalog.Repo, registry: TestCatalog.Registry());
var recipes = cache.GetAll<RecipeData>().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]

View file

@ -13,6 +13,17 @@ using Random = CultMath.Random;
internal static class TestStationKinds
{
public static readonly CultRecordRef<StationKindData> TradeHub = new CultRecordRef<StationKindData>(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<StationKindData>().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<StationKindData>().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<Faction>().Single(f => f.Name == "Zhestokost");