From 561c5b85642184ce0b671347c31c52d7b4f79983 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 17 Sep 2026 05:11:43 +0200 Subject: [PATCH] Fix F4: cover GetPrice, the durability/thermal exponent paths, role fills, Produced brand, and multi-zone GC roots Adds tests for behavior that Cut B shipped without coverage: - GetPriceReadsLotQuality: price varies with the lot's quality through GameplaySettings.QualityPriceModifier. - EvaluateDurabilityExponentReadsLotQuality: ItemManager.Evaluate's durability exponent path reads the lot's quality independently of the quality-for-role term. - EquippedItemThermalExponentReadsLotQuality: EquippedItem's thermal exponent (Entity.cs) reads the lot's quality on a real equip. - CreateLotFillsRolesFromProductSpread: CreateLot(product) fills role quality from the product's own per-role spread, not the design default. - BrandReadsProducedFaction: Brand resolves the maker off a Produced origin, not only Attributed. - CommitTakesRootsFromEveryZone (RunSaveTests): GC roots are collected from every committed zone, not only the first. All six verified by mutation (GetTier/Evaluate/CreateLot/Brand paths patched to ignore the lot or return a fixed value; RunSave.Commit's roots truncated to zones.Take(1)) and reverted after confirming the kill. 42 of 42 tests pass on the real code. Co-Authored-By: Claude Opus 5 --- tests/Aetheria.Shared.Tests/LoadoutTests.cs | 111 ++++++++++++++++++++ tests/Aetheria.Shared.Tests/RunSaveTests.cs | 34 ++++++ 2 files changed, 145 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/LoadoutTests.cs b/tests/Aetheria.Shared.Tests/LoadoutTests.cs index b684d2552..e68e834c4 100644 --- a/tests/Aetheria.Shared.Tests/LoadoutTests.cs +++ b/tests/Aetheria.Shared.Tests/LoadoutTests.cs @@ -508,6 +508,117 @@ public sealed class LoadoutTests : IDisposable Assert.Equal(.2f, items.GetTier(secondInstance).tier.Quality, 3); } + // F4: GetPrice reads the lot's quality through GameplaySettings.QualityPriceModifier. + [Fact] + public void GetPriceReadsLotQuality() + { + using var cache = Open(); + var settings = RunSaveTests.TestSettings(); + settings.QualityPriceModifier = new ExponentialLerp { Minimum = 0, Maximum = 1, Exponent = 1 }; + var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); + var lamp = cache.GetByName("Lamp"); + var lowLot = items.Lots.Add(new Lot { Design = cache.RefOf(lamp), Origin = new Attributed(), Quality = .2f, Roles = new List() }); + var highLot = items.Lots.Add(new Lot { Design = cache.RefOf(lamp), Origin = new Attributed(), Quality = .8f, Roles = new List() }); + var low = (EquippableItem) items.CreateInstance(lowLot); + var high = (EquippableItem) items.CreateInstance(highLot); + Assert.True(items.GetPrice(high) > items.GetPrice(low)); + } + + // F4: the durability exponent path in ItemManager.Evaluate reads the lot's quality (GameplaySettings. + // DurabilityQuality{Min,Max,Exponent}), independently of the quality-for-role term (zeroed here via + // QualityExponent 0). + [Fact] + public void EvaluateDurabilityExponentReadsLotQuality() + { + using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); + var durable = cache.Upsert(new GearData { Name = "Durable", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10, Durability = 100 }); + cache.FlushAsync().Wait(); + + var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); + var lowLot = items.Lots.Add(new Lot { Design = new CultRecordRef(durable.Key), Origin = new Attributed(), Quality = .1f, Roles = new List() }); + var highLot = items.Lots.Add(new Lot { Design = new CultRecordRef(durable.Key), Origin = new Attributed(), Quality = .9f, Roles = new List() }); + var low = (EquippableItem) items.CreateInstance(lowLot); + var high = (EquippableItem) items.CreateInstance(highLot); + low.Durability = items.GetData(low).Durability / 2; + high.Durability = items.GetData(high).Durability / 2; + + var stat = new PerformanceStat { Min = 0, Max = 1, QualityExponent = 0, DurabilityExponentMultiplier = 1 }; + Assert.NotEqual(items.Evaluate(stat, low), items.Evaluate(stat, high)); + } + + // F4: EquippedItem's thermal exponent (Entity.cs's EquippedItem constructor) reads the lot's quality + // (GameplaySettings.ThermalQuality{Min,Max,Exponent}), through a real equip on a live entity. + [Fact] + public void EquippedItemThermalExponentReadsLotQuality() + { + using var cache = Open(); + var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); + var maker = cache.RefOf(cache.GetByName("Maker")); + var hullData = cache.GetByName("Skiff"); + var lampData = cache.GetByName("Lamp"); + + // TestSettings has one tier, so materializing through a Loadout always rolls the same quality; mint the + // gear's lot directly at a chosen quality and equip it onto a bare ship instead. + Ship BuildWithGearQuality(float quality) + { + var hullItem = (EquippableItem) items.CreateInstance(items.CreateLot(hullData, maker, .5f)); + var ship = new Ship(items, null, hullItem, new EntitySettings()); + var gearItem = (EquippableItem) items.CreateInstance(items.CreateLot(lampData, maker, quality)); + Assert.True(ship.TryEquip(gearItem, HardpointCell)); + return ship; + } + + var lowEquipped = BuildWithGearQuality(.1f).Equipment.Single(e => e.Data is GearData); + var highEquipped = BuildWithGearQuality(.9f).Equipment.Single(e => e.Data is GearData); + Assert.NotEqual(lowEquipped.ThermalExponent, highEquipped.ThermalExponent); + } + + // F4: CreateLot(product) fills each of the design's roles from the product's own per-role spread + // (FactionProductData.Roles), not the design-wide default. + [Fact] + public void CreateLotFillsRolesFromProductSpread() + { + using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); + var maker = cache.RefOf(cache.GetByName("Maker")); + var lensGear = cache.Upsert(new GearData + { + Name = "Lensed", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10, + Roles = { new ItemRole { Name = "lens" } } + }); + cache.Upsert(new FactionProductData + { + Name = "Lensed by Maker", Design = new CultRecordRef(lensGear.Key), Manufacturer = maker, + Roles = { new ProductRole { Role = "lens", Mean = .9f, StandardDeviation = 0 } } + }); + cache.FlushAsync().Wait(); + + var product = cache.GetAll().Single(p => p.Name == "Lensed by Maker"); + var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); + var lotId = items.CreateLot(product); + var roleFill = items.Lots[lotId].Roles.Single(r => r.Role == "lens"); + Assert.Equal(.9f, roleFill.Quality, 3); + } + + // F4: Brand reads the maker faction off a Produced origin, not only Attributed. + [Fact] + public void BrandReadsProducedFaction() + { + using var cache = Open(); + var maker = cache.RefOf(cache.GetByName("Maker")); + var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); + var lamp = cache.GetByName("Lamp"); + var lotId = items.Lots.Add(new Lot + { + Design = cache.RefOf(lamp), + Origin = new Produced { Faction = maker, Station = 1, Facility = 2, Inputs = Array.Empty() }, + Quality = .5f, Roles = new List() + }); + var instance = (EquippableItem) items.CreateInstance(lotId); + var (brandMaker, _) = items.Brand(instance); + Assert.NotNull(brandMaker); + Assert.Equal(maker.Key, cache.RefOf(brandMaker).Key); + } + [Fact] public void OutOfRangeWeaponGroupIndexBuildsNothing() { diff --git a/tests/Aetheria.Shared.Tests/RunSaveTests.cs b/tests/Aetheria.Shared.Tests/RunSaveTests.cs index d46cc10c8..3002c0395 100644 --- a/tests/Aetheria.Shared.Tests/RunSaveTests.cs +++ b/tests/Aetheria.Shared.Tests/RunSaveTests.cs @@ -170,6 +170,40 @@ public sealed class RunSaveTests : IDisposable } } + // F4: RunSave.Commit must take GC roots from every committed zone, not only the first. Two zones, each with a + // different lot on its hull; both must survive. + [Fact] + public void CommitTakesRootsFromEveryZone() + { + using (var cache = Open()) + { + var lots = new ProvenanceLedger { NextLot = 3 }; + lots.Lots[1] = new Lot { Origin = new Attributed() }; + lots.Lots[2] = new Lot { Origin = new Attributed() }; + + var zones = new[] + { + new SavedZone + { + Name = "Zone 0", AdjacentZones = Array.Empty(), Factions = Array.Empty(), Owner = -1, + Contents = new ZonePack { Entities = new List { BarePack(hull: new EquippableItem { Lot = 1 }) } } + }, + new SavedZone + { + Name = "Zone 1", AdjacentZones = Array.Empty(), Factions = Array.Empty(), Owner = -1, + Contents = new ZonePack { Entities = new List { BarePack(hull: new EquippableItem { Lot = 2 }) } } + } + }; + RunSave.Commit(cache, Game(cache), zones, lots); + } + + using (var cache = Open()) + { + var stored = RunSave.Lots(cache); + Assert.Equal(new[] { 1, 2 }, stored.Lots.Keys.OrderBy(k => k)); + } + } + [Fact] public void MissingLotIsLoud() {