From 54999a642b1645383551ede3e98df6e65d7b0d0d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 22:09:18 +0200 Subject: [PATCH 01/18] Roles backfill: AetherDb command and catalog role tests (CB-R1) AetherDb roles-backfill gives Autocannon, LRMM72, SRMM72, Mine Launcher, Large Drive (and Small Drive, which declared roles no stat read) live roles: each mapped flat stat becomes a 0.8x..1.2x range read through a Quality term naming its role, and every seller authors a ProductRole per role from its maker profile. MineLayerRoles is new; the maker profile table is hoisted so pd-gear and this command share it. ShippedCatalogRolesAreLive and RolesBackfillIsAuthored read the shipped catalog. The catalog blob lands in its own commit. Co-Authored-By: Claude Sonnet 5.5 --- .../Aetheria.Shared.Tests/CatalogRoleTests.cs | 126 +++++++++++++++ tools/AetherDb/Program.cs | 149 ++++++++++++++++-- 2 files changed, 265 insertions(+), 10 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/CatalogRoleTests.cs diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs new file mode 100644 index 000000000..2bab3218d --- /dev/null +++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +// Aetheria release, cut roles-backfill, rule CB-R1: a crafted design declares roles iff a stat varies with quality, +// every declared role is read by a non-flat stat, and every seller authors one ProductRole per role. Both tests read +// the shipped catalog through the real reader. +public sealed class CatalogRoleTests +{ + // Every weapon and every gear of a kind that carries per-part quality stats (the kinds roles-migrate keeps a role + // map for). Cargo bays, docking bays, control modules, tools and hulls carry no quality-reading stat. + private static readonly HardpointType[] QualityGearKinds = + { HardpointType.Radiator, HardpointType.Reactor, HardpointType.Sensors, HardpointType.Thruster }; + + private static IEnumerable StatsOf(EquippableItemData design) => + design.Behaviors.Where(b => b != null) + .SelectMany(b => b.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)).Select(f => (PerformanceStat)f.GetValue(b))) + .Where(s => s?.Terms != null); + + private static PerformanceStat Stat(EquippableItemData design, string field) => + Assert.Single(design.Behaviors.SelectMany(b => b.GetType().GetFields().Where(f => f.Name == field && f.FieldType == typeof(PerformanceStat)).Select(f => (PerformanceStat)f.GetValue(b)))); + + private static string[] NamedQualityRoles(PerformanceStat stat) => + stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => t.Role).ToArray(); + + [Fact] + public void ShippedCatalogRolesAreLive() + { + var cache = RestoredHullsTests.OpenCatalog(); + var products = cache.GetAll().ToArray(); + var broken = new List(); + foreach (var design in cache.GetAll() + .Where(i => i is WeaponItemData || (i is GearData && QualityGearKinds.Contains(i.HardpointType))) + .OrderBy(i => i.Name, StringComparer.Ordinal)) + { + var varying = StatsOf(design).Where(s => s.Min != s.Max).ToArray(); + var read = varying.SelectMany(NamedQualityRoles).Distinct().OrderBy(r => r, StringComparer.Ordinal).ToArray(); + var declared = (design.Roles ?? new List()).Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal).ToArray(); + if (varying.Length == 0) broken.Add($"{design.Name}: every stat is flat"); + if (!read.SequenceEqual(declared)) + broken.Add($"{design.Name}: declares [{string.Join(", ", declared)}] but non-flat stats read [{string.Join(", ", read)}]"); + foreach (var product in products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key))) + { + var authored = (product.Roles ?? new List()).Select(r => r.Role).OrderBy(r => r, StringComparer.Ordinal).ToArray(); + if (!authored.SequenceEqual(declared)) + broken.Add($"{design.Name}: product \"{product.Name}\" authors [{string.Join(", ", authored)}], not each of [{string.Join(", ", declared)}] once"); + } + } + Assert.True(broken.Count == 0, string.Join("\n", broken)); + } + + // value, then the stat's expected Min and Max: a benefit rises with quality (0.8x to 1.2x), a cost falls (1.2x to 0.8x). + private static void AssertRange(EquippableItemData design, string field, float value, bool cost, string role) + { + var stat = Stat(design, field); + Assert.Equal(value * (cost ? 1.2f : .8f), stat.Min, 3); + Assert.Equal(value * (cost ? .8f : 1.2f), stat.Max, 3); + Assert.Contains(role, NamedQualityRoles(stat)); + } + + [Fact] + public void RolesBackfillIsAuthored() + { + var cache = RestoredHullsTests.OpenCatalog(); + EquippableItemData Design(string name) => Assert.Single(cache.GetAll(), i => i.Name == name); + string[] Roles(EquippableItemData d) => d.Roles.Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal).ToArray(); + + var autocannon = Design("Autocannon"); + Assert.Equal(new[] { "barrel", "feed mechanism" }, Roles(autocannon)); + AssertRange(autocannon, "Damage", 3f, false, "barrel"); + AssertRange(autocannon, "Range", 1000f, false, "barrel"); + + var lrm = Design("LRMM72"); + Assert.Equal(new[] { "guidance system", "thruster", "warhead" }, Roles(lrm)); + AssertRange(lrm, "Damage", 256f, false, "warhead"); + AssertRange(lrm, "Cooldown", 10f, true, "guidance system"); + + var srm = Design("SRMM72"); + Assert.Equal(new[] { "guidance system", "thruster", "warhead" }, Roles(srm)); + AssertRange(srm, "Damage", 128f, false, "warhead"); + AssertRange(srm, "Cooldown", 5f, true, "guidance system"); + + var mine = Design("Mine Launcher"); + Assert.Equal(new[] { "dispenser", "warhead" }, Roles(mine)); + AssertRange(mine, "Damage", 50f, false, "warhead"); + AssertRange(mine, "Cooldown", 2f, true, "dispenser"); + AssertRange(mine, "Spread", 5f, true, "dispenser"); + var layer = Assert.Single(mine.Behaviors.OfType()); + Assert.Equal(2f, layer.ArmingDelay); + Assert.Equal(2f, layer.FuseDelay); + Assert.Equal(30f, layer.Lifetime); + + var drive = Design("Large Drive"); + Assert.Equal(new[] { "injector", "nozzle" }, Roles(drive)); + AssertRange(drive, "Thrust", 250000f, false, "nozzle"); + AssertRange(drive, "Visibility", 100f, true, "nozzle"); + AssertRange(drive, "Heat", 2500f, true, "injector"); + + var smallDrive = Design("Small Drive"); + AssertRange(smallDrive, "Thrust", 75000f, false, "nozzle"); + + // Each seller's means come from its maker's profile; the Pirates are middling and inconsistent. + var profiles = new Dictionary + { + ["Zhestokost"] = (.50f, .08f), ["R&D"] = (.60f, .15f), ["DME"] = (.55f, .20f), ["Lightsail"] = (.55f, .10f), ["Pirates"] = (.45f, .22f), + }; + foreach (var design in new[] { autocannon, lrm, srm, mine, drive }) + { + var sellers = cache.GetAll().Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray(); + Assert.NotEmpty(sellers); + foreach (var product in sellers) + { + var maker = cache.Get(product.Manufacturer); + var (mean, dev) = profiles[maker.ShortName]; + Assert.Equal(Roles(design), product.Roles.Select(r => r.Role).OrderBy(r => r, StringComparer.Ordinal).ToArray()); + Assert.All(product.Roles, r => + { + Assert.Equal(mean, r.Mean, 3); + Assert.Equal(dev, r.StandardDeviation, 3); + }); + } + } + Assert.Contains(cache.GetAll(), p => p.Design.Key.Equals(cache.RefOf(autocannon).Key) && cache.Get(p.Manufacturer).ShortName == "Pirates"); + } +} diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 6caed9ac5..2900ac4f1 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -42,11 +42,12 @@ public static class Program case "field-kinds": return FieldKindsCatalog(args.Contains("apply")); case "pd-gear": return PdGearCatalog(args.Contains("apply")); case "mine-launcher": return MineLauncherCatalog(args.Contains("apply")); + case "roles-backfill": return RolesBackfill(args.Contains("apply")); case "pirates-faction": Console.OutputEncoding = new System.Text.UTF8Encoding(false); return PiratesFaction(args.Contains("apply")); default: - Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear ]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, field-kinds [apply], mine-launcher [apply], pd-gear [apply], pirates-faction [apply]"); + Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear ]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, field-kinds [apply], mine-launcher [apply], roles-backfill [apply], pd-gear [apply], pirates-faction [apply]"); return 1; } } @@ -182,6 +183,15 @@ public static class Program ["Thrust"] = "thruster", ["MissileVelocity"] = "thruster", ["Velocity"] = "thruster", }; + // Warhead and dispenser: a mine layer is a launcher without guidance or thrust, so its stats split between the + // charge it lays and the mechanism that lays it. ArmingDelay, FuseDelay and Lifetime are timings, not stats. + private static readonly Dictionary MineLayerRoles = new Dictionary + { + ["Damage"] = "warhead", ["Penetration"] = "warhead", ["DamageSpread"] = "warhead", + ["Range"] = "dispenser", ["Cooldown"] = "dispenser", ["Spread"] = "dispenser", ["Velocity"] = "dispenser", + ["Energy"] = "dispenser", ["Heat"] = "dispenser", ["Visibility"] = "dispenser", + }; + private static readonly Dictionary RadiatorRoles = new Dictionary { ["Emissivity"] = "fins", ["WasteHeat"] = "fins", @@ -231,6 +241,17 @@ public static class Program }, }; + // One Mean / StandardDeviation per maker, applied to every role of a design the maker sells (catalog-growth + // addenda, "Maker profiles"); the Pirates are middling and inconsistent (pirates-record). + private static readonly Dictionary MakerProfiles = new Dictionary + { + ["Zhestokost"] = (.50f, .08f), ["AU"] = (.50f, .12f), ["Lightsail"] = (.55f, .10f), ["R&D"] = (.60f, .15f), + ["Lucent"] = (.60f, .15f), ["NiteLife"] = (.55f, .12f), ["Finch"] = (.65f, .20f), ["Alakrita"] = (.60f, .14f), + ["DME"] = (.55f, .20f), ["Adrasteia"] = (.60f, .10f), + }; + + private static readonly (float Mean, float Dev) PirateProfile = (.45f, .22f); + private static string KindOf(EquippableItemData item) => item is HullData hull ? $"Hull/{hull.HullType}" : item is DockingBayData ? "DockingBay" @@ -1527,12 +1548,6 @@ public static class Program flakData.AmmoType = db.Cache.RefOf(ammunition); flakData.MagazineSize = 40; flakData.ReloadTime = 4f; Track(flakData, 20f); - var makers = new Dictionary - { - ["Zhestokost"] = (.50f, .08f), ["AU"] = (.50f, .12f), ["Lightsail"] = (.55f, .10f), ["R&D"] = (.60f, .15f), - ["Lucent"] = (.60f, .15f), ["NiteLife"] = (.55f, .12f), ["Finch"] = (.65f, .20f), ["Alakrita"] = (.60f, .14f), - ["DME"] = (.55f, .20f), ["Adrasteia"] = (.60f, .10f), - }; var products = new (WeaponItemData Design, string Name, string Maker, string Description)[] { (gun, "Waykeeper", "Lightsail", "Freight first, questions later. Keeps a hauler's paint unscratched through a full salvo."), @@ -1563,7 +1578,7 @@ public static class Program Console.WriteLine("\nNew products:"); foreach (var (design, name, maker, description) in products) { - var (mean, dev) = makers[maker]; + var (mean, dev) = MakerProfiles[maker]; Console.WriteLine($" {design.Name} -> \"{name}\" by {maker}, every role mean {mean:0.##} dev {dev:0.##}: {description}"); } @@ -1580,7 +1595,7 @@ public static class Program foreach (var design in new[] { gun, laser, flak }) keys[design] = batch.Upsert(typeof(WeaponItemData), design); foreach (var (design, name, maker, description) in products) { - var (mean, dev) = makers[maker]; + var (mean, dev) = MakerProfiles[maker]; batch.Upsert(typeof(FactionProductData), new FactionProductData { Name = name, @@ -1706,6 +1721,120 @@ public static class Program return 0; } + // Aetheria release, cut roles-backfill (rule CB-R1): designs that shipped with flat stats and no roles get the + // roles their kind's map names, and every seller authors a ProductRole per role. Each mapped stat becomes a range + // of value x (0.8, 1.2) that rises with quality for a benefit and falls for a cost, read through one Quality term + // naming its role (exponent: the mode of the kind's existing designs on that field, 1 when there is none; an + // existing Quality term keeps its exponent). Zero stats stay flat. Small Drive joined the set because it declares + // roles that no non-flat stat reads. Idempotent: a design with no flat mapped stat is left alone, a product with a + // role is left alone. Dry run unless passed "apply". + private static readonly string[] BackfillDesigns = { "Autocannon", "LRMM72", "SRMM72", "Mine Launcher", "Large Drive", "Small Drive" }; + + private static readonly HashSet CostStats = new HashSet(StringComparer.Ordinal) + { + "Cooldown", "Spread", "Heat", "Visibility", "Energy", "EnergyUsage", "ChargeTime", "ChargeEnergy", "ChargeHeat", + "SensorImpact", "DirectionImpact", "Decay", + }; + + private static Dictionary BackfillMapFor(EquippableItemData item) => + item.Behaviors.OfType().Any() ? MineLayerRoles : RoleMapFor(item, KindOf(item)); + + private static IEnumerable StatsOf(EquippableItemData item) => + (item.Behaviors ?? new List()).Where(b => b != null) + .SelectMany(b => b.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)).Select(f => f.GetValue(b) as PerformanceStat)) + .Where(s => s?.Terms != null); + + private static int RolesBackfill(bool apply) + { + var db = AetherDb.Open(catalogWritable: apply); + var items = db.Cache.GetAll().ToArray(); + var products = db.Cache.GetAll().ToArray(); + var targets = BackfillDesigns.Select(name => items.Where(i => i.Name == name).ToArray()) + .Select((found, i) => found.Length == 1 ? found[0] : throw new InvalidOperationException( + $"Expected exactly one design named \"{BackfillDesigns[i]}\", found {found.Length}.")).ToArray(); + + float ExponentFor(string kind, string field) + { + var precedent = items.Except(targets).Where(i => KindOf(i) == kind && i.Roles != null && i.Roles.Count > 0) + .SelectMany(i => i.Behaviors ?? new List()).Where(b => b != null) + .SelectMany(b => b.GetType().GetFields().Where(f => f.Name == field && f.FieldType == typeof(PerformanceStat)).Select(f => f.GetValue(b) as PerformanceStat)) + .Where(s => s?.Terms != null && s.Min != s.Max) + .SelectMany(s => s.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => t.Exponent)) + .GroupBy(e => e).OrderByDescending(g => g.Count()).ThenBy(g => g.Key).Select(g => g.Key).ToArray(); + return precedent.Length > 0 ? precedent[0] : 1f; + } + + var changedDesigns = new List<(EquippableItemData Document, CultRecordKey Key)>(); + foreach (var design in targets) + { + var kind = KindOf(design); + var map = BackfillMapFor(design) ?? throw new InvalidOperationException($"\"{design.Name}\" has no role map."); + var lines = new List(); + foreach (var behavior in design.Behaviors.Where(b => b != null)) + foreach (var field in behavior.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat))) + { + if (!map.TryGetValue(field.Name, out var role) || !(field.GetValue(behavior) is PerformanceStat stat)) continue; + if (stat.Min != stat.Max || stat.Min == 0f || float.IsInfinity(stat.Min)) continue; + var value = stat.Min; + (stat.Min, stat.Max) = CostStats.Contains(field.Name) ? (value * 1.2f, value * .8f) : (value * .8f, value * 1.2f); + stat.Terms ??= new List(); + var quality = stat.Terms.FirstOrDefault(t => t.Source == StatSource.Quality); + if (quality == null) + { + quality = new StatTerm { Source = StatSource.Quality, Exponent = ExponentFor(kind, field.Name) }; + stat.Terms.Add(quality); + } + quality.Role = role; + lines.Add($" {behavior.GetType().Name}.{field.Name,-16} {value:0.####} -> {stat.Min:0.####}..{stat.Max:0.####} {role} ^{quality.Exponent:0.##}"); + } + if (lines.Count == 0) continue; + design.Roles = StatsOf(design).Where(s => s.Min != s.Max) + .SelectMany(s => s.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => t.Role)) + .Distinct().OrderBy(r => r, StringComparer.Ordinal).Select(r => new ItemRole { Name = r }).ToList(); + Console.WriteLine($" {design.Name} ({kind}) roles [{string.Join(", ", design.Roles.Select(r => r.Name))}]"); + foreach (var line in lines) Console.WriteLine(line); + changedDesigns.Add((design, db.Cache.RefOf(design).Key)); + } + + var changedProducts = new List<(FactionProductData Document, CultRecordKey Key)>(); + foreach (var design in targets) + foreach (var product in products.Where(p => p.Design.Key.Equals(db.Cache.RefOf(design).Key)).OrderBy(p => p.Name, StringComparer.Ordinal)) + { + var maker = db.Cache.Get(product.Manufacturer); + var profile = maker?.Name == "Pirates" ? PirateProfile + : maker != null && MakerProfiles.TryGetValue(maker.ShortName, out var found) ? found + : throw new InvalidOperationException($"No maker profile for the seller of \"{design.Name}\" ({maker?.ShortName ?? "no maker"})."); + product.Roles ??= new List(); + var missing = design.Roles.Select(r => r.Name).Where(r => product.Roles.All(p => p.Role != r)).ToArray(); + if (missing.Length == 0) continue; + foreach (var role in missing) + product.Roles.Add(new ProductRole { Role = role, Mean = profile.Mean, StandardDeviation = profile.Dev }); + Console.WriteLine($" {product.Name,-28} ({design.Name}, {maker.ShortName}) {string.Join(", ", missing)} at {profile.Mean:0.00}/{profile.Dev:0.00}"); + changedProducts.Add((product, db.Cache.RefOf(product).Key)); + } + + if (changedDesigns.Count == 0 && changedProducts.Count == 0) + { + Console.WriteLine("Roles backfill is already authored; nothing to do."); + return 0; + } + Console.WriteLine($"\n{changedDesigns.Count} design(s) and {changedProducts.Count} product(s) to author."); + if (!apply) + { + Console.WriteLine("Dry run. Pass \"apply\" to land them."); + return 0; + } + foreach (var (document, _) in changedDesigns) CultRecordRefs.Validate(document); + foreach (var (document, _) in changedProducts) CultRecordRefs.Validate(document); + db.Cache.Commit(batch => + { + foreach (var (document, key) in changedDesigns) batch.Upsert(document is WeaponItemData ? typeof(WeaponItemData) : typeof(GearData), document, key); + foreach (var (document, key) in changedProducts) batch.Upsert(typeof(FactionProductData), document, key); + }); + Console.WriteLine($"Landed {changedDesigns.Count} design(s) and {changedProducts.Count} product(s) in Aetheria.cc"); + return 0; + } + // Aetheria release, cut pirates-record (rulings pirates-record-content, catalog-grows-generic-designs-branded-products): // the Pirates faction and eight rebrands of other makers' designs, named in emoji. The Pirates own no design: their range // is what they took, so every product points at a design someone else also makes. Each product carries one ProductRole per @@ -1765,7 +1894,7 @@ public static class Program { var design = DesignByName(r.Design); return (Design: design, r.Name, r.Description, - Roles: (design.Roles ?? new List()).Select(role => new ProductRole { Role = role.Name, Mean = .45f, StandardDeviation = .22f }).ToList()); + Roles: (design.Roles ?? new List()).Select(role => new ProductRole { Role = role.Name, Mean = PirateProfile.Mean, StandardDeviation = PirateProfile.Dev }).ToList()); }).ToArray(); Console.WriteLine($"New faction \"{pirates.Name}\": influence {pirates.InfluenceDistance}, names \"{nameFile.Name}\", allegiance 1.0 to {pirates.Allegiance.Count} factions."); From 017da88334f552db0b6253ee0207620ad065d5b7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 22:11:52 +0200 Subject: [PATCH 02/18] Catalog: roles-backfill apply (6 designs, 6 products) Output of `AetherDb roles-backfill apply` on origin/master 325ef4bc's catalog, run on Yggdrasil at 54999a64. Dry run: Autocannon, LRMM72, SRMM72, Mine Launcher, Large Drive and Small Drive gain roles and quality ranges; Autocannon (Zhestokost, Pirates), LRMM72 (R&D), SRMM72 (DME), Mine Launcher (DME) and True North (Lightsail) author their ProductRoles. A replay prints "already authored". At merge, take master's catalog and rerun `AetherDb roles-backfill apply`. Co-Authored-By: Claude Sonnet 5.5 --- GameData/Aetheria.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index 42a50cad4..76685d05d 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:32a2e401a03b00bae994bf1a26a3be58db7226c7c6c9a4e12fa2c449429d80e8 -size 12712398 +oid sha256:3d531aff9e6c2d1ea65a123e987ea4e2ce79610598c7547e26e3ecb7fb95b94a +size 12713666 From f3550b67a453062b2a401b72ddc0ead3c5efd993 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 22:26:34 +0200 Subject: [PATCH 03/18] Tests: roles-backfill fallout (Tractor Beam has no stat, Longinus fitted by name) ShippedCatalogRolesAreLive skips gear with no PerformanceStat at all (Tractor Beam is a thruster kind with none). TheEnvelopeComesFromTheGear fits the Longinus by name: the generator's picks follow the item stream and every authored ProductRole draws from it, so the generated hull stopped carrying Large Drives (Medium Drive and RevvITup instead). Its forward bound is the drives' own thrust, since a Large Drive now rolls 0.8x to 1.2x. Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/CatalogRoleTests.cs | 4 +++- tests/Aetheria.Shared.Tests/EvasionTermTests.cs | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs index 2bab3218d..665602de3 100644 --- a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs +++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs @@ -34,7 +34,9 @@ public sealed class CatalogRoleTests .Where(i => i is WeaponItemData || (i is GearData && QualityGearKinds.Contains(i.HardpointType))) .OrderBy(i => i.Name, StringComparer.Ordinal)) { - var varying = StatsOf(design).Where(s => s.Min != s.Max).ToArray(); + var stats = StatsOf(design).ToArray(); + if (stats.Length == 0) continue; // Tractor Beam: a thruster kind with no stat at all, so nothing for quality to vary + var varying = stats.Where(s => s.Min != s.Max).ToArray(); var read = varying.SelectMany(NamedQualityRoles).Distinct().OrderBy(r => r, StringComparer.Ordinal).ToArray(); var declared = (design.Roles ?? new List()).Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal).ToArray(); if (varying.Length == 0) broken.Add($"{design.Name}: every stat is flat"); diff --git a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs index 93eef6145..594019d43 100644 --- a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs +++ b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs @@ -283,7 +283,17 @@ public sealed partial class RunStartTests [Fact] public void TheEnvelopeComesFromTheGear() { - var (_, longinus, _) = EvFleet(); + // The Longinus is fitted by name, not generated: what the generator picks follows the item stream, and every role a + // product authors draws from it (roles-backfill), so a generated hull would stop carrying these drives. + Ship longinus = null; + var scenario = new Scripted(false, stage => + { + stage.Player(stage.Bare("Djinni"), float2(-50000, -50000)); + longinus = stage.Place(EvLonginus(stage), float2(-30000, -30000), facing: float2(0, 1)) as Ship; + }); + var (_, _, _, failures) = Launch(scenario, Inputs(() => GalaxySeed)); + Assert.True(failures.Count == 0, string.Join("; ", failures)); + Assert.NotNull(longinus); EvSettle(longinus); // A thruster's Thrust property is refreshed only while it fires: turn each way so the flank thrusters hold what // they push with, then read the envelope at rest. @@ -306,7 +316,8 @@ public sealed partial class RunStartTests var envelope = longinus.Envelope; var mass = longinus.Mass; - Assert.InRange(envelope.Forward, 500000f / mass * .99f, 500000f / mass * 1.01f); + var forward = largeDrives.Sum(t => t.Thrust) / mass; // each drive's own thrust: a Large Drive's roll moves it between 0.8x and 1.2x + Assert.InRange(envelope.Forward, forward * .99f, forward * 1.01f); Assert.Equal(0f, envelope.Reverse); var flankAcceleration = flanks.Max(t => t.Thrust) / mass; Assert.InRange(envelope.Left, flankAcceleration * .99f, flankAcceleration * 1.01f); From 303f73e19f485be9855a31c4dd4b2322c99cd6cc Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 22:39:21 +0200 Subject: [PATCH 04/18] Tests: the Longinus envelope's flank sides are each Talaria's own thrust Each fitted Talaria has its own lot's thrust, so Left and Right are the two flanks' accelerations, not both the larger one. Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/EvasionTermTests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs index 594019d43..708f863bb 100644 --- a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs +++ b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs @@ -319,9 +319,11 @@ public sealed partial class RunStartTests var forward = largeDrives.Sum(t => t.Thrust) / mass; // each drive's own thrust: a Large Drive's roll moves it between 0.8x and 1.2x Assert.InRange(envelope.Forward, forward * .99f, forward * 1.01f); Assert.Equal(0f, envelope.Reverse); - var flankAcceleration = flanks.Max(t => t.Thrust) / mass; - Assert.InRange(envelope.Left, flankAcceleration * .99f, flankAcceleration * 1.01f); - Assert.InRange(envelope.Right, flankAcceleration * .99f, flankAcceleration * 1.01f); + // One Talaria pushes each way, and each has its own lot's thrust: the sides are the two flanks' accelerations. + var flankAccelerations = flanks.Select(t => t.Thrust / mass).OrderBy(a => a).ToArray(); + var sides = new[] { envelope.Left, envelope.Right }.OrderBy(a => a).ToArray(); + Assert.InRange(sides[0], flankAccelerations[0] * .99f, flankAccelerations[0] * 1.01f); + Assert.InRange(sides[1], flankAccelerations[1] * .99f, flankAccelerations[1] * 1.01f); var clockwise = thrusters.Where(t => t.Torque > settings.TorqueFloor).Sum(t => t.Torque * t.Thrust) * settings.TorqueMultiplier / mass; var counterClockwise = thrusters.Where(t => t.Torque < -settings.TorqueFloor).Sum(t => -t.Torque * t.Thrust) * settings.TorqueMultiplier / mass; Assert.InRange(envelope.Clockwise, clockwise * .99f, clockwise * 1.01f); From 6a1eb68ddbf7e1fd1000d6896a8f24a7f8143800 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 23:46:26 +0200 Subject: [PATCH 05/18] Roles backfill: one role map per design, the six unnamed non-flat stats named, RolesBackfill takes a root RoleMapFor answers for the Mine Launcher (MineLayerRoles) so roles-migrate and roles-backfill no longer disagree on it; BackfillMapFor is deleted. Count, MinRange, DamageSpread and the reactor Modifier join their kind maps, and the backfill points a varying stat's unnamed Quality term at its role without touching its range. DeathCluster, Flak Gun, GT 3K, plight and both MoveOnPros join the backfill set (CB-R1 forces them). RolesBackfill(apply, root) mirrors PiratesFaction so tests can replay it on a scratch catalog. Co-Authored-By: Claude Sonnet 5.5 --- tools/AetherDb/Program.cs | 46 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 2900ac4f1..9b87bf9b0 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -161,13 +161,13 @@ public static class Program { ["Damage"] = "barrel", ["Range"] = "barrel", ["Velocity"] = "barrel", ["Penetration"] = "barrel", ["Cooldown"] = "feed mechanism", ["Spread"] = "feed mechanism", ["Heat"] = "feed mechanism", - ["Visibility"] = "feed mechanism", ["Energy"] = "feed mechanism", + ["Visibility"] = "feed mechanism", ["Energy"] = "feed mechanism", ["Count"] = "feed mechanism", }; private static readonly Dictionary EnergyWeaponRoles = new Dictionary { ["Damage"] = "focusing array", ["Range"] = "focusing array", ["Velocity"] = "focusing array", - ["Penetration"] = "focusing array", + ["Penetration"] = "focusing array", ["DamageSpread"] = "focusing array", ["Energy"] = "power coupling", ["Heat"] = "power coupling", ["ChargeTime"] = "power coupling", ["ChargeEnergy"] = "power coupling", ["ChargeHeat"] = "power coupling", ["Cooldown"] = "power coupling", ["Spread"] = "power coupling", ["Visibility"] = "power coupling", @@ -178,6 +178,7 @@ public static class Program ["Damage"] = "warhead", ["Penetration"] = "warhead", ["DamageSpread"] = "warhead", ["LockSpeed"] = "guidance system", ["SensorImpact"] = "guidance system", ["LockAngle"] = "guidance system", ["DirectionImpact"] = "guidance system", ["Decay"] = "guidance system", ["Range"] = "guidance system", + ["MinRange"] = "guidance system", ["Cooldown"] = "guidance system", ["Spread"] = "guidance system", ["Visibility"] = "guidance system", ["Energy"] = "guidance system", ["Heat"] = "guidance system", ["Thrust"] = "thruster", ["MissileVelocity"] = "thruster", ["Velocity"] = "thruster", @@ -201,7 +202,7 @@ public static class Program private static readonly Dictionary ReactorRoles = new Dictionary { - ["Charge"] = "core", ["Efficiency"] = "core", + ["Charge"] = "core", ["Efficiency"] = "core", ["Modifier"] = "core", ["OverloadEfficiency"] = "regulator", ["ThrottlingFactor"] = "regulator", }; @@ -262,7 +263,8 @@ public static class Program // The field->role map for one design, or null when its kind carries no per-part behaviour stat at all // (CargoBay, DockingBay, ControlModule, Hull/Station, Hull/Turret -- none of their behaviours read // StatSource.Quality today, so there is no natural role to author and the report says so per design). - private static Dictionary RoleMapFor(EquippableItemData item, string kind) => kind switch + private static Dictionary RoleMapFor(EquippableItemData item, string kind) => + item.Behaviors != null && item.Behaviors.OfType().Any() ? MineLayerRoles : kind switch { "Weapon/Ballistic" => BallisticWeaponRoles, "Weapon/Energy" => EnergyWeaponRoles, @@ -276,6 +278,9 @@ public static class Program _ => null, }; + // Whether CB-R1 maps this design's stats to roles; the catalog test asks the tool, so it keeps no copy of the kinds. + public static bool HasRoleMap(EquippableItemData item) => RoleMapFor(item, KindOf(item)) != null; + private sealed record RoleAuthoring( EquippableItemData Item, string Kind, List<(string Behavior, string Field, string Role)> StatsAssigned, List RolesDeclared, string SkipReason); @@ -1725,10 +1730,13 @@ public static class Program // roles their kind's map names, and every seller authors a ProductRole per role. Each mapped stat becomes a range // of value x (0.8, 1.2) that rises with quality for a benefit and falls for a cost, read through one Quality term // naming its role (exponent: the mode of the kind's existing designs on that field, 1 when there is none; an - // existing Quality term keeps its exponent). Zero stats stay flat. Small Drive joined the set because it declares - // roles that no non-flat stat reads. Idempotent: a design with no flat mapped stat is left alone, a product with a - // role is left alone. Dry run unless passed "apply". - private static readonly string[] BackfillDesigns = { "Autocannon", "LRMM72", "SRMM72", "Mine Launcher", "Large Drive", "Small Drive" }; + // existing Quality term keeps its exponent). Zero stats stay flat. A mapped stat that already varies keeps its range + // and only has its unnamed Quality term pointed at the role. Small Drive joined the set because it declares roles that + // no non-flat stat reads; DeathCluster, Flak Gun, GT 3K, plight and the two MoveOnPros because each had a non-flat stat + // whose Quality term named no role (CB-R1: each non-flat stat reads exactly one declared role). Idempotent: a design with + // no flat mapped stat and no unnamed one is left alone, a product with a role is left alone. Dry run unless passed "apply". + private static readonly string[] BackfillDesigns = { "Autocannon", "LRMM72", "SRMM72", "Mine Launcher", "Large Drive", "Small Drive", + "DeathCluster", "Flak Gun", "GT 3K", "plight", "MoveOnPro", "MoveOnPro Station Reactor" }; private static readonly HashSet CostStats = new HashSet(StringComparer.Ordinal) { @@ -1736,17 +1744,14 @@ public static class Program "SensorImpact", "DirectionImpact", "Decay", }; - private static Dictionary BackfillMapFor(EquippableItemData item) => - item.Behaviors.OfType().Any() ? MineLayerRoles : RoleMapFor(item, KindOf(item)); - private static IEnumerable StatsOf(EquippableItemData item) => (item.Behaviors ?? new List()).Where(b => b != null) .SelectMany(b => b.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)).Select(f => f.GetValue(b) as PerformanceStat)) .Where(s => s?.Terms != null); - private static int RolesBackfill(bool apply) + public static int RolesBackfill(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.Open(catalogWritable: apply, root: root); var items = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); var targets = BackfillDesigns.Select(name => items.Where(i => i.Name == name).ToArray()) @@ -1768,22 +1773,23 @@ public static class Program foreach (var design in targets) { var kind = KindOf(design); - var map = BackfillMapFor(design) ?? throw new InvalidOperationException($"\"{design.Name}\" has no role map."); + var map = RoleMapFor(design, kind) ?? throw new InvalidOperationException($"\"{design.Name}\" has no role map."); var lines = new List(); foreach (var behavior in design.Behaviors.Where(b => b != null)) foreach (var field in behavior.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat))) { if (!map.TryGetValue(field.Name, out var role) || !(field.GetValue(behavior) is PerformanceStat stat)) continue; - if (stat.Min != stat.Max || stat.Min == 0f || float.IsInfinity(stat.Min)) continue; - var value = stat.Min; - (stat.Min, stat.Max) = CostStats.Contains(field.Name) ? (value * 1.2f, value * .8f) : (value * .8f, value * 1.2f); stat.Terms ??= new List(); var quality = stat.Terms.FirstOrDefault(t => t.Source == StatSource.Quality); - if (quality == null) + var value = stat.Min; + if (stat.Min == stat.Max) { - quality = new StatTerm { Source = StatSource.Quality, Exponent = ExponentFor(kind, field.Name) }; - stat.Terms.Add(quality); + if (stat.Min == 0f || float.IsInfinity(stat.Min)) continue; + (stat.Min, stat.Max) = CostStats.Contains(field.Name) ? (value * 1.2f, value * .8f) : (value * .8f, value * 1.2f); + quality ??= new StatTerm { Source = StatSource.Quality, Exponent = ExponentFor(kind, field.Name) }; + if (!stat.Terms.Contains(quality)) stat.Terms.Add(quality); } + else if (quality == null || !string.IsNullOrEmpty(quality.Role)) continue; // already named, or not quality-driven quality.Role = role; lines.Add($" {behavior.GetType().Name}.{field.Name,-16} {value:0.####} -> {stat.Min:0.####}..{stat.Max:0.####} {role} ^{quality.Exponent:0.##}"); } From 2e1c2c439b898fb8167121d59f067091a4b32867 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 23:46:28 +0200 Subject: [PATCH 06/18] Tests: CB-R1 enforced whole, backfill replay on a scratch catalog, envelope and operability read the catalog ShippedCatalogRolesAreLive checks every design of every kind: each non-flat stat reads one declared role, declared roles are read, sellers author each once, role-mapped designs are not all flat (the tool answers which, via Program.HasRoleMap). RolesBackfillIsAuthored pins ratios and roles, with the Autocannon Penetration, Mine Range and LRMM72 LockAngle asserts. RolesBackfillCommandTests resets the backfilled designs on a scratch catalog, applies, and expects the shipped catalog back, then replays as a no-op. EveryShippedProductHasAMaker. TheEnvelopeComesFromTheGear bounds each drive by the catalog's Large Drive Thrust range; ShippedWeaponOperabilityTests reads the catalog's DefaultEntitySettings. Co-Authored-By: Claude Sonnet 5.5 --- .../Aetheria.Shared.Tests/CatalogRoleTests.cs | 105 ++++++++----- .../Aetheria.Shared.Tests/EvasionTermTests.cs | 6 +- .../RolesBackfillCommandTests.cs | 146 ++++++++++++++++++ .../ShippedWeaponOperabilityTests.cs | 4 +- 4 files changed, 219 insertions(+), 42 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs index 665602de3..bb83a23cd 100644 --- a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs +++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs @@ -4,44 +4,47 @@ using System.Linq; using Xunit; // Aetheria release, cut roles-backfill, rule CB-R1: a crafted design declares roles iff a stat varies with quality, -// every declared role is read by a non-flat stat, and every seller authors one ProductRole per role. Both tests read +// every declared role is read by a non-flat stat, and every seller authors one ProductRole per role. These tests read // the shipped catalog through the real reader. public sealed class CatalogRoleTests { - // Every weapon and every gear of a kind that carries per-part quality stats (the kinds roles-migrate keeps a role - // map for). Cargo bays, docking bays, control modules, tools and hulls carry no quality-reading stat. - private static readonly HardpointType[] QualityGearKinds = - { HardpointType.Radiator, HardpointType.Reactor, HardpointType.Sensors, HardpointType.Thruster }; - - private static IEnumerable StatsOf(EquippableItemData design) => + internal static IEnumerable<(string Name, PerformanceStat Stat)> StatsOf(EquippableItemData design) => design.Behaviors.Where(b => b != null) - .SelectMany(b => b.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)).Select(f => (PerformanceStat)f.GetValue(b))) - .Where(s => s?.Terms != null); + .SelectMany(b => b.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)) + .Select(f => ($"{b.GetType().Name}.{f.Name}", (PerformanceStat)f.GetValue(b)))) + .Where(s => s.Item2?.Terms != null); private static PerformanceStat Stat(EquippableItemData design, string field) => Assert.Single(design.Behaviors.SelectMany(b => b.GetType().GetFields().Where(f => f.Name == field && f.FieldType == typeof(PerformanceStat)).Select(f => (PerformanceStat)f.GetValue(b)))); - private static string[] NamedQualityRoles(PerformanceStat stat) => + internal static string[] NamedQualityRoles(PerformanceStat stat) => stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => t.Role).ToArray(); + // The whole of CB-R1 over every design in the catalog: each non-flat stat reads exactly one declared role, every + // declared role is read, and every seller authors each role once. Weapons, and designs of a kind the tool keeps a role + // map for, must also carry a non-flat stat (a design with no stat at all has nothing for quality to vary). [Fact] public void ShippedCatalogRolesAreLive() { - var cache = RestoredHullsTests.OpenCatalog(); + using var cache = RestoredHullsTests.OpenCatalog(); var products = cache.GetAll().ToArray(); var broken = new List(); - foreach (var design in cache.GetAll() - .Where(i => i is WeaponItemData || (i is GearData && QualityGearKinds.Contains(i.HardpointType))) - .OrderBy(i => i.Name, StringComparer.Ordinal)) + foreach (var design in cache.GetAll().OrderBy(i => i.Name, StringComparer.Ordinal)) { var stats = StatsOf(design).ToArray(); - if (stats.Length == 0) continue; // Tractor Beam: a thruster kind with no stat at all, so nothing for quality to vary - var varying = stats.Where(s => s.Min != s.Max).ToArray(); - var read = varying.SelectMany(NamedQualityRoles).Distinct().OrderBy(r => r, StringComparer.Ordinal).ToArray(); + var varying = stats.Where(s => s.Stat.Min != s.Stat.Max).ToArray(); var declared = (design.Roles ?? new List()).Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal).ToArray(); - if (varying.Length == 0) broken.Add($"{design.Name}: every stat is flat"); + foreach (var (name, stat) in varying) + { + var named = NamedQualityRoles(stat); + if (named.Length != 1 || !declared.Contains(named[0])) + broken.Add($"{design.Name}: non-flat {name} reads [{string.Join(", ", named)}], not one of its declared roles [{string.Join(", ", declared)}]"); + } + var read = varying.SelectMany(s => NamedQualityRoles(s.Stat)).Distinct().OrderBy(r => r, StringComparer.Ordinal).ToArray(); if (!read.SequenceEqual(declared)) broken.Add($"{design.Name}: declares [{string.Join(", ", declared)}] but non-flat stats read [{string.Join(", ", read)}]"); + if (varying.Length == 0 && stats.Length > 0 && (design is WeaponItemData || Program.HasRoleMap(design))) + broken.Add($"{design.Name}: every stat is flat"); foreach (var product in products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key))) { var authored = (product.Roles ?? new List()).Select(r => r.Role).OrderBy(r => r, StringComparer.Ordinal).ToArray(); @@ -49,45 +52,62 @@ public sealed class CatalogRoleTests broken.Add($"{design.Name}: product \"{product.Name}\" authors [{string.Join(", ", authored)}], not each of [{string.Join(", ", declared)}] once"); } } - Assert.True(broken.Count == 0, string.Join("\n", broken)); + Assert.True(broken.Count == 0, string.Join(" +", broken)); } - // value, then the stat's expected Min and Max: a benefit rises with quality (0.8x to 1.2x), a cost falls (1.2x to 0.8x). - private static void AssertRange(EquippableItemData design, string field, float value, bool cost, string role) + // A product with no maker would title as its design and take no maker profile for its roles. + [Fact] + public void EveryShippedProductHasAMaker() + { + using var cache = RestoredHullsTests.OpenCatalog(); + var makerless = cache.GetAll().Where(p => cache.Get(p.Manufacturer) == null).Select(p => p.Name).OrderBy(n => n, StringComparer.Ordinal).ToArray(); + Assert.True(makerless.Length == 0, "products with no maker: " + string.Join(", ", makerless)); + } + + // A benefit rises with quality across 0.8x to 1.2x of its authored value (Max/Min 1.5), a cost falls across 1.2x to 0.8x + // (Max/Min 2/3). The ratio and the role are pinned, not the value, so an operator retune of a design stays green. + private static void AssertRange(EquippableItemData design, string field, bool cost, string role) { var stat = Stat(design, field); - Assert.Equal(value * (cost ? 1.2f : .8f), stat.Min, 3); - Assert.Equal(value * (cost ? .8f : 1.2f), stat.Max, 3); - Assert.Contains(role, NamedQualityRoles(stat)); + Assert.Equal(cost ? 2f / 3f : 1.5f, stat.Max / stat.Min, 3); + Assert.Equal(new[] { role }, NamedQualityRoles(stat)); } + // Stats that already varied before the backfill keep their range; only their unnamed Quality term gains the role. + private static void AssertNamed(EquippableItemData design, string field, string role) => + Assert.Equal(new[] { role }, NamedQualityRoles(Stat(design, field))); + [Fact] public void RolesBackfillIsAuthored() { - var cache = RestoredHullsTests.OpenCatalog(); + using var cache = RestoredHullsTests.OpenCatalog(); EquippableItemData Design(string name) => Assert.Single(cache.GetAll(), i => i.Name == name); string[] Roles(EquippableItemData d) => d.Roles.Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal).ToArray(); var autocannon = Design("Autocannon"); Assert.Equal(new[] { "barrel", "feed mechanism" }, Roles(autocannon)); - AssertRange(autocannon, "Damage", 3f, false, "barrel"); - AssertRange(autocannon, "Range", 1000f, false, "barrel"); + AssertRange(autocannon, "Damage", false, "barrel"); + AssertRange(autocannon, "Range", false, "barrel"); + AssertRange(autocannon, "Penetration", false, "barrel"); var lrm = Design("LRMM72"); Assert.Equal(new[] { "guidance system", "thruster", "warhead" }, Roles(lrm)); - AssertRange(lrm, "Damage", 256f, false, "warhead"); - AssertRange(lrm, "Cooldown", 10f, true, "guidance system"); + AssertRange(lrm, "Damage", false, "warhead"); + AssertRange(lrm, "Cooldown", true, "guidance system"); + AssertRange(lrm, "LockAngle", false, "guidance system"); var srm = Design("SRMM72"); Assert.Equal(new[] { "guidance system", "thruster", "warhead" }, Roles(srm)); - AssertRange(srm, "Damage", 128f, false, "warhead"); - AssertRange(srm, "Cooldown", 5f, true, "guidance system"); + AssertRange(srm, "Damage", false, "warhead"); + AssertRange(srm, "Cooldown", true, "guidance system"); var mine = Design("Mine Launcher"); Assert.Equal(new[] { "dispenser", "warhead" }, Roles(mine)); - AssertRange(mine, "Damage", 50f, false, "warhead"); - AssertRange(mine, "Cooldown", 2f, true, "dispenser"); - AssertRange(mine, "Spread", 5f, true, "dispenser"); + AssertRange(mine, "Damage", false, "warhead"); + AssertRange(mine, "Range", false, "dispenser"); + AssertRange(mine, "Cooldown", true, "dispenser"); + AssertRange(mine, "Spread", true, "dispenser"); var layer = Assert.Single(mine.Behaviors.OfType()); Assert.Equal(2f, layer.ArmingDelay); Assert.Equal(2f, layer.FuseDelay); @@ -95,12 +115,19 @@ public sealed class CatalogRoleTests var drive = Design("Large Drive"); Assert.Equal(new[] { "injector", "nozzle" }, Roles(drive)); - AssertRange(drive, "Thrust", 250000f, false, "nozzle"); - AssertRange(drive, "Visibility", 100f, true, "nozzle"); - AssertRange(drive, "Heat", 2500f, true, "injector"); + AssertRange(drive, "Thrust", false, "nozzle"); + AssertRange(drive, "Visibility", true, "nozzle"); + AssertRange(drive, "Heat", true, "injector"); - var smallDrive = Design("Small Drive"); - AssertRange(smallDrive, "Thrust", 75000f, false, "nozzle"); + AssertRange(Design("Small Drive"), "Thrust", false, "nozzle"); + + // Designs whose non-flat stats named no role are pointed at the role their kind's map gives them. + AssertNamed(Design("DeathCluster"), "Count", "feed mechanism"); + AssertNamed(Design("Flak Gun"), "Count", "feed mechanism"); + AssertNamed(Design("GT 3K"), "MinRange", "guidance system"); + AssertNamed(Design("plight"), "DamageSpread", "focusing array"); + AssertNamed(Design("MoveOnPro"), "Modifier", "core"); + AssertNamed(Design("MoveOnPro Station Reactor"), "Modifier", "core"); // Each seller's means come from its maker's profile; the Pirates are middling and inconsistent. var profiles = new Dictionary diff --git a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs index 708f863bb..ea6ce903d 100644 --- a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs +++ b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs @@ -316,7 +316,11 @@ public sealed partial class RunStartTests var envelope = longinus.Envelope; var mass = longinus.Mass; - var forward = largeDrives.Sum(t => t.Thrust) / mass; // each drive's own thrust: a Large Drive's roll moves it between 0.8x and 1.2x + // The shipped Large Drive's Thrust is a range its lot's roll moves it through, so each drive pushes within the catalog's + // range and the envelope forward is what the two push together. + var catalogThrust = _cache.GetAll().Single(gear => gear.Name == "Large Drive").Behaviors.OfType().Single().Thrust; + Assert.All(largeDrives, t => Assert.InRange(t.Thrust, catalogThrust.Min * .99f, catalogThrust.Max * 1.01f)); + var forward = largeDrives.Sum(t => t.Thrust) / mass; Assert.InRange(envelope.Forward, forward * .99f, forward * 1.01f); Assert.Equal(0f, envelope.Reverse); // One Talaria pushes each way, and each has its own lot's thrust: the sides are the two flanks' accelerations. diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs new file mode 100644 index 000000000..923dedbb1 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using GameCult.Caching; +using GameCult.Caching.MessagePack; +using Xunit; + +// AetherDb's roles-backfill command (aetheria-release, cut roles-backfill) run on a scratch copy of the shipped catalog, +// with the designs it backfills put back to the state they shipped in before it: flat stats at the middle of their range, +// no roles, no seller quality, and the unnamed Quality terms of the stats that already varied. The shipped catalog is the +// oracle, since the command produced it. +public sealed class RolesBackfillCommandTests : IDisposable +{ + private static readonly string[] Flattened = { "Autocannon", "LRMM72", "SRMM72", "Mine Launcher", "Large Drive", "Small Drive" }; + + // Designs that shipped with non-flat stats whose Quality term named no role; the field is the stat to unname. + private static readonly (string Design, string Field)[] Unnamed = + { + ("DeathCluster", "Count"), ("Flak Gun", "Count"), ("GT 3K", "MinRange"), ("plight", "DamageSpread"), + ("MoveOnPro", "Modifier"), ("MoveOnPro Station Reactor", "Modifier"), + }; + + private readonly string _root = Path.Combine(Path.GetTempPath(), "roles-backfill-" + Guid.NewGuid().ToString("N")); + private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc"); + private readonly Dictionary _shipped = new Dictionary(); + + public RolesBackfillCommandTests() + { + Directory.CreateDirectory(Path.Combine(_root, "GameData")); + File.Copy(Path.Combine(AetherDb.FindRoot(), "GameData", "Aetheria.cc"), CatalogPath); + // As PiratesFactionCommandTests: edit through a registry scoped to the shipped assembly, then give the catalog the + // record AetherDb's process-wide registry demands in this test host. + var registry = CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() + .Where(t => t is { IsAbstract: false, IsInterface: false }) + .Where(t => t.GetCustomAttribute() != null)); + using (var cache = new CultCache(registry)) + { + cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); + var designs = cache.GetAll().ToArray(); + var products = cache.GetAll().ToArray(); + var changed = new List(); + foreach (var design in designs.Where(d => Flattened.Contains(d.Name))) + { + _shipped[design.Name] = Describe(cache, design, products); + foreach (var (_, stat) in CatalogRoleTests.StatsOf(design)) + { + if (stat.Min != stat.Max) stat.Min = stat.Max = (stat.Min + stat.Max) / 2f; + stat.Terms.RemoveAll(t => t.Source == StatSource.Quality); + } + design.Roles = new List(); + changed.Add(design); + foreach (var product in products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key))) + { + product.Roles = new List(); + changed.Add(product); + } + } + foreach (var (name, field) in Unnamed) + { + var design = designs.Single(d => d.Name == name); + _shipped[name] = Describe(cache, design, products); + foreach (var term in Stat(design, field).Terms.Where(t => t.Source == StatSource.Quality)) term.Role = null; + changed.Add(design); + } + cache.Commit(batch => + { + foreach (var document in changed) batch.Upsert(document.GetType(), document, cache.RefOf(document).Key); + }); + cache.FlushAsync().Wait(); + } + using (var cache = new CultCache()) + { + cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); + cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); + cache.FlushAsync().Wait(); + } + } + + public void Dispose() => Directory.Delete(_root, true); + + private static PerformanceStat Stat(EquippableItemData design, string field) => + Assert.Single(CatalogRoleTests.StatsOf(design), s => s.Name.EndsWith("." + field)).Stat; + + // Everything the command decides about one design: its roles, each stat's range and role, and its sellers' role quality. + private static string Describe(CultCache cache, EquippableItemData design, FactionProductData[] products) + { + static string F(float v) => float.IsInfinity(v) ? v.ToString() : ((double) v).ToString("G5"); + var stats = CatalogRoleTests.StatsOf(design).Select(s => + $"{s.Name} {F(s.Stat.Min)}..{F(s.Stat.Max)} {string.Join("+", CatalogRoleTests.NamedQualityRoles(s.Stat))}"); + var sellers = products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)).OrderBy(p => p.Name, StringComparer.Ordinal) + .Select(p => $"{p.Name}: " + string.Join(", ", (p.Roles ?? new List()).OrderBy(r => r.Role, StringComparer.Ordinal) + .Select(r => $"{r.Role} {F(r.Mean)}/{F(r.StandardDeviation)}"))); + var roles = "roles " + string.Join(", ", (design.Roles ?? new List()).Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal)); + return string.Join("\n", new[] { roles }.Concat(stats).Concat(sellers)); + } + + private Dictionary Read() + { + var db = AetherDb.Open(root: _root); + try + { + var products = db.Cache.GetAll().ToArray(); + return db.Cache.GetAll().Where(d => _shipped.ContainsKey(d.Name)) + .ToDictionary(d => d.Name, d => Describe(db.Cache, d, products)); + } + finally { db.Cache.Dispose(); } + } + + [Fact] + public void A_dry_run_writes_nothing_and_apply_lands_what_the_catalog_ships_and_replays_as_a_no_op() + { + var before = File.ReadAllBytes(CatalogPath); + var start = Read(); + Assert.All(_shipped.Keys, name => Assert.NotEqual(_shipped[name], start[name])); + + Assert.Equal(0, Program.RolesBackfill(apply: false, root: _root)); + Assert.Equal(before, File.ReadAllBytes(CatalogPath)); + + Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); + var landed = File.ReadAllBytes(CatalogPath); + Assert.NotEqual(before, landed); + var after = Read(); + foreach (var name in _shipped.Keys.OrderBy(n => n, StringComparer.Ordinal)) + Assert.Equal(_shipped[name], after[name]); + + // A second apply finds every stat ranged and named and every seller authored, and writes nothing. + Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); + Assert.Equal(landed, File.ReadAllBytes(CatalogPath)); + } + + [Fact] + public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing() + { + var db = AetherDb.Open(catalogWritable: true, root: _root); + var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); + autocannon.Name = "Autocannon (renamed)"; + db.Cache.Commit(batch => batch.Upsert(typeof(WeaponItemData), autocannon, db.Cache.RefOf(autocannon).Key)); + db.Cache.Dispose(); + var before = File.ReadAllBytes(CatalogPath); + + Assert.Throws(() => Program.RolesBackfill(apply: true, root: _root)); + Assert.Equal(before, File.ReadAllBytes(CatalogPath)); + } +} diff --git a/tests/Aetheria.Shared.Tests/ShippedWeaponOperabilityTests.cs b/tests/Aetheria.Shared.Tests/ShippedWeaponOperabilityTests.cs index 537fbc3a9..8ac543451 100644 --- a/tests/Aetheria.Shared.Tests/ShippedWeaponOperabilityTests.cs +++ b/tests/Aetheria.Shared.Tests/ShippedWeaponOperabilityTests.cs @@ -2,7 +2,7 @@ using System.Linq; using Xunit; // A weapon is thermally online only while its performance exceeds the shutdown threshold (Entity.UpdatePerformance -// compares against EntitySettings.ShutdownPerformance), and wear runs at full rate below it. Hull cells +// compares against the catalog settings' DefaultEntitySettings.ShutdownPerformance, which production clones), and wear runs at full rate below it. Hull cells // start at Entity.StartingCellTemperature, so every shipped weapon must perform there, or a ship fitted with it // can never fire it. The catalog comes from the shipped GameData/Aetheria.cc and the temperature from the // constant Entity builds its cells with, so a unit slip in authoring (celsius for kelvin) fails here. @@ -15,7 +15,7 @@ public sealed class ShippedWeaponOperabilityTests var weapons = cache.GetAll().OfType().ToArray(); Assert.NotEmpty(weapons); - var threshold = new EntitySettings().ShutdownPerformance; + var threshold = RestoredHullsTests.Settings().DefaultEntitySettings.ShutdownPerformance; Assert.True(threshold > 0f); var dead = weapons.Where(weapon => weapon.Performance(Entity.StartingCellTemperature) <= threshold) From 6218f9fdc1f4db26b15a70ba0465e4071ef3a1f4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 23:47:54 +0200 Subject: [PATCH 07/18] Roles backfill: Count and MinRange take a role but are never ranged; fix a broken string in the catalog test Co-Authored-By: Claude Sonnet 5.5 --- tools/AetherDb/Program.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 9b87bf9b0..97e5c9151 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -1738,6 +1738,10 @@ public static class Program private static readonly string[] BackfillDesigns = { "Autocannon", "LRMM72", "SRMM72", "Mine Launcher", "Large Drive", "Small Drive", "DeathCluster", "Flak Gun", "GT 3K", "plight", "MoveOnPro", "MoveOnPro Station Reactor" }; + // Stats the backfill names but never ranges: a shot count is whole, and which way a launcher's MinRange should fall is + // each design's own call (GT 3K authors it as a cost already). + private static readonly HashSet RoleOnlyStats = new HashSet(StringComparer.Ordinal) { "Count", "MinRange" }; + private static readonly HashSet CostStats = new HashSet(StringComparer.Ordinal) { "Cooldown", "Spread", "Heat", "Visibility", "Energy", "EnergyUsage", "ChargeTime", "ChargeEnergy", "ChargeHeat", @@ -1784,6 +1788,7 @@ public static class Program var value = stat.Min; if (stat.Min == stat.Max) { + if (RoleOnlyStats.Contains(field.Name)) continue; // a count or a per-design bound: never ranged if (stat.Min == 0f || float.IsInfinity(stat.Min)) continue; (stat.Min, stat.Max) = CostStats.Contains(field.Name) ? (value * 1.2f, value * .8f) : (value * .8f, value * 1.2f); quality ??= new StatTerm { Source = StatSource.Quality, Exponent = ExponentFor(kind, field.Name) }; From d2f40617699997d7a26109b5410dfb5f7b3d1e7d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 23:48:23 +0200 Subject: [PATCH 08/18] Tests: fix the broken join string in the catalog roles test Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/CatalogRoleTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs index bb83a23cd..2e606905b 100644 --- a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs +++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs @@ -52,8 +52,7 @@ public sealed class CatalogRoleTests broken.Add($"{design.Name}: product \"{product.Name}\" authors [{string.Join(", ", authored)}], not each of [{string.Join(", ", declared)}] once"); } } - Assert.True(broken.Count == 0, string.Join(" -", broken)); + Assert.True(broken.Count == 0, string.Join("\n", broken)); } // A product with no maker would title as its design and take no maker profile for its roles. From c5ce2b6409f9c6caddb3522762ed770e578907d8 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 23:50:14 +0200 Subject: [PATCH 09/18] Tests: the replay leaves Small Drive's sellers as they shipped Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index 923dedbb1..8e5053291 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -51,7 +51,8 @@ public sealed class RolesBackfillCommandTests : IDisposable } design.Roles = new List(); changed.Add(design); - foreach (var product in products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key))) + // Small Drive shipped with its sellers' quality already authored (roles-migrate); only its stats were flat. + foreach (var product in products.Where(p => design.Name != "Small Drive" && p.Design.Key.Equals(cache.RefOf(design).Key))) { product.Roles = new List(); changed.Add(product); From 80b51d63eabd830c97f6d7eef87a0983f6d18f26 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 23:50:35 +0200 Subject: [PATCH 10/18] Catalog: roles-backfill apply re-run (6 designs name their unnamed Quality terms) Produced by `AetherDb roles-backfill apply` on Yggdrasil over the previous catalog blob (3d531aff). Dry run: DeathCluster (Weapon/Ballistic) roles [barrel, feed mechanism] AutoWeaponData.Count 12 -> 12..15 feed mechanism ^1 Flak Gun (Weapon/Ballistic) roles [barrel, feed mechanism] AutoWeaponData.Count 6 -> 6..8 feed mechanism ^1 GT 3K (Weapon/Launcher) roles [guidance system, thruster, warhead] LauncherData.MinRange 500 -> 500..50 guidance system ^1.75 plight (Weapon/Energy) roles [focusing array, power coupling] ChargedWeaponData.DamageSpread 1 -> 1..3.3 focusing array ^1.25 MoveOnPro (Reactor) roles [core, regulator] StatModifierData.Modifier 1.1 -> 1.1..1.25 core ^1 MoveOnPro Station Reactor (Reactor) roles [core, regulator] StatModifierData.Modifier 1.1 -> 1.1..1.25 core ^1 6 design(s) and 0 product(s) to author. Dry run. Pass "apply" to land them. Co-Authored-By: Claude Sonnet 5.5 --- GameData/Aetheria.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index 76685d05d..82f4c4cd0 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d531aff9e6c2d1ea65a123e987ea4e2ce79610598c7547e26e3ecb7fb95b94a -size 12713666 +oid sha256:2534838f58c3cb3ccd97d08e7ea81f94bce276b60642a6fad91ccfb64088d0f4 +size 12713731 From e97968e27177da4d872c0fa714dfc1235d4da1ab Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 00:02:46 +0200 Subject: [PATCH 11/18] Roles backfill: read each stat with as, so Stryker can mutate the command Co-Authored-By: Claude Sonnet 5.5 --- tools/AetherDb/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 97e5c9151..170a3dfe9 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -1782,7 +1782,8 @@ public static class Program foreach (var behavior in design.Behaviors.Where(b => b != null)) foreach (var field in behavior.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat))) { - if (!map.TryGetValue(field.Name, out var role) || !(field.GetValue(behavior) is PerformanceStat stat)) continue; + var stat = field.GetValue(behavior) as PerformanceStat; + if (stat == null || !map.TryGetValue(field.Name, out var role)) continue; stat.Terms ??= new List(); var quality = stat.Terms.FirstOrDefault(t => t.Source == StatSource.Quality); var value = stat.Min; From 94f4a9872cda3dcd46e2f48d2f55e78f70e88c7f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 00:11:04 +0200 Subject: [PATCH 12/18] Roles backfill: separate the null and map checks (definite assignment survives mutation) Co-Authored-By: Claude Sonnet 5.5 --- tools/AetherDb/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 170a3dfe9..22c50d456 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -1783,7 +1783,8 @@ public static class Program foreach (var field in behavior.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat))) { var stat = field.GetValue(behavior) as PerformanceStat; - if (stat == null || !map.TryGetValue(field.Name, out var role)) continue; + if (stat == null) continue; + if (!map.TryGetValue(field.Name, out var role)) continue; stat.Terms ??= new List(); var quality = stat.Terms.FirstOrDefault(t => t.Source == StatSource.Quality); var value = stat.Min; From 2843358430e7e543bdfdee45155ced73319d3d3b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 00:24:58 +0200 Subject: [PATCH 13/18] Tests: a names-only replay, so apply still lands designs when no seller changes Co-Authored-By: Claude Sonnet 5.5 --- .../RolesBackfillCommandTests.cs | 73 ++++++++++++++----- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index 8e5053291..c7dd752e4 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -30,20 +30,38 @@ public sealed class RolesBackfillCommandTests : IDisposable { Directory.CreateDirectory(Path.Combine(_root, "GameData")); File.Copy(Path.Combine(AetherDb.FindRoot(), "GameData", "Aetheria.cc"), CatalogPath); - // As PiratesFactionCommandTests: edit through a registry scoped to the shipped assembly, then give the catalog the - // record AetherDb's process-wide registry demands in this test host. + // The catalog needs the record AetherDb's process-wide registry demands in this test host (as PiratesFactionCommandTests). + using (var cache = new CultCache()) + { + cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); + cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); + cache.FlushAsync().Wait(); + } + var db = AetherDb.Open(root: _root); + try + { + var products = db.Cache.GetAll().ToArray(); + foreach (var design in db.Cache.GetAll().Where(d => Flattened.Contains(d.Name) || Unnamed.Any(u => u.Design == d.Name))) + _shipped[design.Name] = Describe(db.Cache, design, products); + } + finally { db.Cache.Dispose(); } + } + + // Puts the named designs back to the state they shipped in before the backfill, through a registry scoped to the shipped + // assembly (as PiratesFactionCommandTests strips its faction). + private void Reset(bool flattened, bool unnamed) + { var registry = CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() .Where(t => t is { IsAbstract: false, IsInterface: false }) .Where(t => t.GetCustomAttribute() != null)); - using (var cache = new CultCache(registry)) - { - cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); - var designs = cache.GetAll().ToArray(); - var products = cache.GetAll().ToArray(); - var changed = new List(); + using var cache = new CultCache(registry); + cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); + var designs = cache.GetAll().ToArray(); + var products = cache.GetAll().ToArray(); + var changed = new List(); + if (flattened) foreach (var design in designs.Where(d => Flattened.Contains(d.Name))) { - _shipped[design.Name] = Describe(cache, design, products); foreach (var (_, stat) in CatalogRoleTests.StatsOf(design)) { if (stat.Min != stat.Max) stat.Min = stat.Max = (stat.Min + stat.Max) / 2f; @@ -58,24 +76,23 @@ public sealed class RolesBackfillCommandTests : IDisposable changed.Add(product); } } + if (unnamed) foreach (var (name, field) in Unnamed) { var design = designs.Single(d => d.Name == name); - _shipped[name] = Describe(cache, design, products); foreach (var term in Stat(design, field).Terms.Where(t => t.Source == StatSource.Quality)) term.Role = null; changed.Add(design); } - cache.Commit(batch => - { - foreach (var document in changed) batch.Upsert(document.GetType(), document, cache.RefOf(document).Key); - }); - cache.FlushAsync().Wait(); - } - using (var cache = new CultCache()) + cache.Commit(batch => { - cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); - cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); - cache.FlushAsync().Wait(); + foreach (var document in changed) batch.Upsert(document.GetType(), document, cache.RefOf(document).Key); + }); + cache.FlushAsync().Wait(); + using (var plain = new CultCache()) + { + plain.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); + plain.Upsert(new TestCatalogGlobal { Name = "Temperament" }); + plain.FlushAsync().Wait(); } } @@ -112,6 +129,7 @@ public sealed class RolesBackfillCommandTests : IDisposable [Fact] public void A_dry_run_writes_nothing_and_apply_lands_what_the_catalog_ships_and_replays_as_a_no_op() { + Reset(flattened: true, unnamed: true); var before = File.ReadAllBytes(CatalogPath); var start = Read(); Assert.All(_shipped.Keys, name => Assert.NotEqual(_shipped[name], start[name])); @@ -131,6 +149,21 @@ public sealed class RolesBackfillCommandTests : IDisposable Assert.Equal(landed, File.ReadAllBytes(CatalogPath)); } + // Only unnamed Quality terms to name: no seller and no range changes, and apply must still land the designs. + [Fact] + public void Naming_an_unnamed_term_alone_lands_without_touching_ranges_or_sellers() + { + Reset(flattened: false, unnamed: true); + var before = File.ReadAllBytes(CatalogPath); + var start = Read(); + Assert.All(Unnamed.Select(u => u.Design), name => Assert.NotEqual(_shipped[name], start[name])); + + Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); + Assert.NotEqual(before, File.ReadAllBytes(CatalogPath)); + var after = Read(); + foreach (var (name, _) in Unnamed) Assert.Equal(_shipped[name], after[name]); + } + [Fact] public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing() { From d7ee26d3895270bda5c0fa4e2286e673990225a8 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 00:36:45 +0200 Subject: [PATCH 14/18] Tests: the replay reads the shipped designs and resets through the scoped registry before the catalog gains the sibling record Co-Authored-By: Claude Sonnet 5.5 --- .../RolesBackfillCommandTests.cs | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index c7dd752e4..2bff3143e 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -30,31 +30,23 @@ public sealed class RolesBackfillCommandTests : IDisposable { Directory.CreateDirectory(Path.Combine(_root, "GameData")); File.Copy(Path.Combine(AetherDb.FindRoot(), "GameData", "Aetheria.cc"), CatalogPath); - // The catalog needs the record AetherDb's process-wide registry demands in this test host (as PiratesFactionCommandTests). - using (var cache = new CultCache()) - { - cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); - cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); - cache.FlushAsync().Wait(); - } - var db = AetherDb.Open(root: _root); - try - { - var products = db.Cache.GetAll().ToArray(); - foreach (var design in db.Cache.GetAll().Where(d => Flattened.Contains(d.Name) || Unnamed.Any(u => u.Design == d.Name))) - _shipped[design.Name] = Describe(db.Cache, design, products); - } - finally { db.Cache.Dispose(); } + using var cache = new CultCache(ScopedRegistry()); + cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); + var products = cache.GetAll().ToArray(); + foreach (var design in cache.GetAll().Where(d => Flattened.Contains(d.Name) || Unnamed.Any(u => u.Design == d.Name))) + _shipped[design.Name] = Describe(cache, design, products); } + // A registry scoped to the shipped assembly, so this test assembly's own documents never reach the real catalog. + private static CultDocumentRegistry ScopedRegistry() => CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() + .Where(t => t is { IsAbstract: false, IsInterface: false }) + .Where(t => t.GetCustomAttribute() != null)); + // Puts the named designs back to the state they shipped in before the backfill, through a registry scoped to the shipped // assembly (as PiratesFactionCommandTests strips its faction). private void Reset(bool flattened, bool unnamed) { - var registry = CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() - .Where(t => t is { IsAbstract: false, IsInterface: false }) - .Where(t => t.GetCustomAttribute() != null)); - using var cache = new CultCache(registry); + using var cache = new CultCache(ScopedRegistry()); cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); var designs = cache.GetAll().ToArray(); var products = cache.GetAll().ToArray(); @@ -83,11 +75,13 @@ public sealed class RolesBackfillCommandTests : IDisposable foreach (var term in Stat(design, field).Terms.Where(t => t.Source == StatSource.Quality)) term.Role = null; changed.Add(design); } - cache.Commit(batch => - { - foreach (var document in changed) batch.Upsert(document.GetType(), document, cache.RefOf(document).Key); - }); + if (changed.Count > 0) + cache.Commit(batch => + { + foreach (var document in changed) batch.Upsert(document.GetType(), document, cache.RefOf(document).Key); + }); cache.FlushAsync().Wait(); + // Then the record AetherDb's process-wide registry demands in this test host (as PiratesFactionCommandTests). using (var plain = new CultCache()) { plain.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes); @@ -167,6 +161,7 @@ public sealed class RolesBackfillCommandTests : IDisposable [Fact] public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing() { + Reset(flattened: false, unnamed: false); var db = AetherDb.Open(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); autocannon.Name = "Autocannon (renamed)"; From 9744d3969f1b33911a394503a6e2f3218398435c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 01:59:25 +0200 Subject: [PATCH 15/18] Roles backfill: the exponent precedent is read before any target changes; the replay sees exponents and a one-of-two-roles seller ExponentFor drew its pool from items.Except(targets), so growing the targets from six to twelve changed the exponents a rerun on master's catalog writes. The pool is now snapshotted once, from every design that declares roles and names a Quality term, before the loop mutates anything. Describe prints each named term's exponent, one test pins Autocannon's and LRMM72's exponents against the shipped blob, and one clears a single role of a two-role seller and expects only that role re-authored. Co-Authored-By: Claude Sonnet 5.5 --- .../RolesBackfillCommandTests.cs | 55 ++++++++++++++++++- tools/AetherDb/Program.cs | 18 ++++-- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index 2bff3143e..40fbe130e 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -95,12 +95,12 @@ public sealed class RolesBackfillCommandTests : IDisposable private static PerformanceStat Stat(EquippableItemData design, string field) => Assert.Single(CatalogRoleTests.StatsOf(design), s => s.Name.EndsWith("." + field)).Stat; - // Everything the command decides about one design: its roles, each stat's range and role, and its sellers' role quality. + // Everything the command decides about one design: its roles, each stat's range, role and exponent, and its sellers' role quality. private static string Describe(CultCache cache, EquippableItemData design, FactionProductData[] products) { static string F(float v) => float.IsInfinity(v) ? v.ToString() : ((double) v).ToString("G5"); var stats = CatalogRoleTests.StatsOf(design).Select(s => - $"{s.Name} {F(s.Stat.Min)}..{F(s.Stat.Max)} {string.Join("+", CatalogRoleTests.NamedQualityRoles(s.Stat))}"); + $"{s.Name} {F(s.Stat.Min)}..{F(s.Stat.Max)} {string.Join("+", s.Stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => $"{t.Role}^{F(t.Exponent)}"))}"); var sellers = products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)).OrderBy(p => p.Name, StringComparer.Ordinal) .Select(p => $"{p.Name}: " + string.Join(", ", (p.Roles ?? new List()).OrderBy(r => r.Role, StringComparer.Ordinal) .Select(r => $"{r.Role} {F(r.Mean)}/{F(r.StandardDeviation)}"))); @@ -158,6 +158,57 @@ public sealed class RolesBackfillCommandTests : IDisposable foreach (var (name, _) in Unnamed) Assert.Equal(_shipped[name], after[name]); } + // The exponents a first apply authors do not depend on which designs it targets: applied to the base-shaped catalog, the + // command reproduces the shipped exponents of Autocannon and LRMM72, which differ across stats (the mode is not one value). + [Fact] + public void Apply_on_the_base_shaped_catalog_reproduces_the_shipped_exponents() + { + static Dictionary Exponents(EquippableItemData d) => CatalogRoleTests.StatsOf(d) + .SelectMany(s => s.Stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => (s.Name, t.Exponent))) + .ToDictionary(x => x.Name, x => x.Exponent); + var designs = new[] { "Autocannon", "LRMM72" }; + Dictionary> Read(string root) + { + var db = AetherDb.Open(root: root); + try { return db.Cache.GetAll().Where(d => designs.Contains(d.Name)).ToDictionary(d => d.Name, Exponents); } + finally { db.Cache.Dispose(); } + } + var shipped = Read(AetherDb.FindRoot()); + Assert.All(designs, name => Assert.True(shipped[name].Values.Distinct().Count() > 1, name + " exponents are one value; the test would not tell a mode from a default")); + + Reset(flattened: true, unnamed: true); + Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); + var after = Read(_root); + foreach (var name in designs) Assert.Equal(shipped[name].OrderBy(x => x.Key, StringComparer.Ordinal), after[name].OrderBy(x => x.Key, StringComparer.Ordinal)); + } + + // A seller that authors one of a design's two roles gets only the other one added, and keeps the one it authored. + [Fact] + public void A_seller_with_one_of_two_roles_authored_gains_only_the_missing_role() + { + Reset(flattened: false, unnamed: false); + var db = AetherDb.Open(catalogWritable: true, root: _root); + var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); + var seller = db.Cache.GetAll().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key) && p.Roles.Count == 2); + var kept = seller.Roles.OrderBy(r => r.Role, StringComparer.Ordinal).First(); + kept.Mean = .91f; + seller.Roles = new List { kept }; + var sellerName = seller.Name; + var keptRole = kept.Role; + db.Cache.Commit(batch => batch.Upsert(typeof(FactionProductData), seller, db.Cache.RefOf(seller).Key)); + db.Cache.Dispose(); + + Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); + db = AetherDb.Open(root: _root); + try + { + var after = db.Cache.GetAll().Single(p => p.Name == sellerName); + Assert.Equal(new[] { "barrel", "feed mechanism" }, after.Roles.Select(r => r.Role).OrderBy(r => r, StringComparer.Ordinal).ToArray()); + Assert.Equal(.91f, after.Roles.Single(r => r.Role == keptRole).Mean, 3); + } + finally { db.Cache.Dispose(); } + } + [Fact] public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing() { diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 22c50d456..953f08e0f 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -1762,15 +1762,21 @@ public static class Program .Select((found, i) => found.Length == 1 ? found[0] : throw new InvalidOperationException( $"Expected exactly one design named \"{BackfillDesigns[i]}\", found {found.Length}.")).ToArray(); + // The precedent is read once, before any target changes: the named Quality exponents of every design that declares + // roles, so a design the command names later never leaves the pool another target draws from, and a design that + // starts with no named term contributes nothing. + var precedent = items.Where(i => i.Roles != null && i.Roles.Count > 0) + .SelectMany(i => (i.Behaviors ?? new List()).Where(b => b != null) + .SelectMany(b => b.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)).Select(f => (Kind: KindOf(i), Field: f.Name, Stat: f.GetValue(b) as PerformanceStat)))) + .Where(x => x.Stat?.Terms != null && x.Stat.Min != x.Stat.Max) + .SelectMany(x => x.Stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => (x.Kind, x.Field, t.Exponent))) + .ToArray(); + float ExponentFor(string kind, string field) { - var precedent = items.Except(targets).Where(i => KindOf(i) == kind && i.Roles != null && i.Roles.Count > 0) - .SelectMany(i => i.Behaviors ?? new List()).Where(b => b != null) - .SelectMany(b => b.GetType().GetFields().Where(f => f.Name == field && f.FieldType == typeof(PerformanceStat)).Select(f => f.GetValue(b) as PerformanceStat)) - .Where(s => s?.Terms != null && s.Min != s.Max) - .SelectMany(s => s.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => t.Exponent)) + var modes = precedent.Where(p => p.Kind == kind && p.Field == field).Select(p => p.Exponent) .GroupBy(e => e).OrderByDescending(g => g.Count()).ThenBy(g => g.Key).Select(g => g.Key).ToArray(); - return precedent.Length > 0 ? precedent[0] : 1f; + return modes.Length > 0 ? modes[0] : 1f; } var changedDesigns = new List<(EquippableItemData Document, CultRecordKey Key)>(); From 651f5cdc4fe06a2685bb6eb343a10430e7171cd7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 01:59:26 +0200 Subject: [PATCH 16/18] Tests: CB-R1 counts every Quality term on a non-flat stat and rejects a role named on a flat one A non-flat stat must carry exactly one Quality term, named, declared, with a positive exponent; a flat stat may not name a role. The check is one function with its own synthetic-stat test. Co-Authored-By: Claude Sonnet 5.5 --- .../Aetheria.Shared.Tests/CatalogRoleTests.cs | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs index 2e606905b..9978f081d 100644 --- a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs +++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs @@ -20,6 +20,21 @@ public sealed class CatalogRoleTests internal static string[] NamedQualityRoles(PerformanceStat stat) => stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => t.Role).ToArray(); + // CB-R1 for one stat. A non-flat stat carries exactly one Quality term, it names a declared role, and its exponent is + // positive (a role that cannot move the stat is not read). A flat stat carries no Quality term that names a role. + // Returns the fault, or null. + internal static string StatFault(PerformanceStat stat, string[] declared) + { + var quality = stat.Terms.Where(t => t.Source == StatSource.Quality).ToArray(); + if (stat.Min == stat.Max) + return quality.Any(t => !string.IsNullOrEmpty(t.Role)) ? $"is flat but a Quality term names [{string.Join(", ", NamedQualityRoles(stat))}]" : null; + if (quality.Length != 1) + return $"is non-flat with {quality.Length} Quality terms, not one"; + if (string.IsNullOrEmpty(quality[0].Role) || !declared.Contains(quality[0].Role)) + return $"is non-flat and reads [{quality[0].Role}], not one of its declared roles [{string.Join(", ", declared)}]"; + return quality[0].Exponent > 0f ? null : $"is non-flat but its role \"{quality[0].Role}\" has exponent {quality[0].Exponent}"; + } + // The whole of CB-R1 over every design in the catalog: each non-flat stat reads exactly one declared role, every // declared role is read, and every seller authors each role once. Weapons, and designs of a kind the tool keeps a role // map for, must also carry a non-flat stat (a design with no stat at all has nothing for quality to vary). @@ -34,11 +49,10 @@ public sealed class CatalogRoleTests var stats = StatsOf(design).ToArray(); var varying = stats.Where(s => s.Stat.Min != s.Stat.Max).ToArray(); var declared = (design.Roles ?? new List()).Select(r => r.Name).OrderBy(r => r, StringComparer.Ordinal).ToArray(); - foreach (var (name, stat) in varying) + foreach (var (name, stat) in stats) { - var named = NamedQualityRoles(stat); - if (named.Length != 1 || !declared.Contains(named[0])) - broken.Add($"{design.Name}: non-flat {name} reads [{string.Join(", ", named)}], not one of its declared roles [{string.Join(", ", declared)}]"); + var fault = StatFault(stat, declared); + if (fault != null) broken.Add($"{design.Name}: {name} {fault}"); } var read = varying.SelectMany(s => NamedQualityRoles(s.Stat)).Distinct().OrderBy(r => r, StringComparer.Ordinal).ToArray(); if (!read.SequenceEqual(declared)) @@ -55,6 +69,23 @@ public sealed class CatalogRoleTests Assert.True(broken.Count == 0, string.Join("\n", broken)); } + private static PerformanceStat Ranged(params StatTerm[] terms) => new PerformanceStat { Min = 1f, Max = 2f, Terms = terms.ToList() }; + private static StatTerm Quality(string role, float exponent = 1f) => new StatTerm { Source = StatSource.Quality, Role = role, Exponent = exponent }; + + // The stat check refuses what the shipped catalog does not hold but a later content cut could author. + [Fact] + public void TheStatCheckRefusesGenericQualityDeadRolesAndNamedFlatStats() + { + var declared = new[] { "barrel" }; + Assert.Null(StatFault(Ranged(Quality("barrel")), declared)); + Assert.Null(StatFault(new PerformanceStat { Min = 3f, Max = 3f, Terms = new List() }, declared)); + Assert.NotNull(StatFault(Ranged(Quality("barrel"), Quality(null)), declared)); + Assert.NotNull(StatFault(Ranged(Quality("barrel", 0f)), declared)); + Assert.NotNull(StatFault(Ranged(Quality(null)), declared)); + Assert.NotNull(StatFault(Ranged(Quality("bogus")), declared)); + Assert.NotNull(StatFault(new PerformanceStat { Min = 3f, Max = 3f, Terms = new List { Quality("bogus") } }, declared)); + } + // A product with no maker would title as its design and take no maker profile for its roles. [Fact] public void EveryShippedProductHasAMaker() From a91bd1f7cfa849c18a55a4ac35983a177bdbdf46 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 02:13:15 +0200 Subject: [PATCH 17/18] Tests: the replay resets the drives to unnamed terms, not stripped ones, as they shipped Large Drive and Small Drive shipped with unnamed Quality terms on their flat stats; the command keeps those exponents. The reset stripped them, so the new exponent check read the Thruster precedent instead. Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index 40fbe130e..a34248df0 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -57,7 +57,10 @@ public sealed class RolesBackfillCommandTests : IDisposable foreach (var (_, stat) in CatalogRoleTests.StatsOf(design)) { if (stat.Min != stat.Max) stat.Min = stat.Max = (stat.Min + stat.Max) / 2f; - stat.Terms.RemoveAll(t => t.Source == StatSource.Quality); + // The drives shipped with unnamed Quality terms on their flat stats (roles-migrate); the command keeps those + // exponents and names them. The other four shipped with no term at all. + if (design.Name.EndsWith(" Drive", StringComparison.Ordinal)) foreach (var term in stat.Terms.Where(t => t.Source == StatSource.Quality)) term.Role = null; + else stat.Terms.RemoveAll(t => t.Source == StatSource.Quality); } design.Roles = new List(); changed.Add(design); From 450e371f748edbd455b9ebbbee8f609ae5dea68e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 9 Oct 2026 02:14:54 +0200 Subject: [PATCH 18/18] Tests: the exponent pin reads the shipped designs through the catalog opener AetherDb.Open refuses a catalog without the test global record the scoped copies lack. Co-Authored-By: Claude Sonnet 5.5 --- .../RolesBackfillCommandTests.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index a34248df0..034ce7455 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -170,18 +170,17 @@ public sealed class RolesBackfillCommandTests : IDisposable .SelectMany(s => s.Stat.Terms.Where(t => t.Source == StatSource.Quality && !string.IsNullOrEmpty(t.Role)).Select(t => (s.Name, t.Exponent))) .ToDictionary(x => x.Name, x => x.Exponent); var designs = new[] { "Autocannon", "LRMM72" }; - Dictionary> Read(string root) - { - var db = AetherDb.Open(root: root); - try { return db.Cache.GetAll().Where(d => designs.Contains(d.Name)).ToDictionary(d => d.Name, Exponents); } - finally { db.Cache.Dispose(); } - } - var shipped = Read(AetherDb.FindRoot()); + Dictionary> shipped; + Dictionary> Read(EquippableItemData[] all) => all.Where(d => designs.Contains(d.Name)).ToDictionary(d => d.Name, Exponents); + using (var catalog = RestoredHullsTests.OpenCatalog()) shipped = Read(catalog.GetAll().ToArray()); Assert.All(designs, name => Assert.True(shipped[name].Values.Distinct().Count() > 1, name + " exponents are one value; the test would not tell a mode from a default")); Reset(flattened: true, unnamed: true); Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); - var after = Read(_root); + var db = AetherDb.Open(root: _root); + Dictionary> after; + try { after = Read(db.Cache.GetAll().ToArray()); } + finally { db.Cache.Dispose(); } foreach (var name in designs) Assert.Equal(shipped[name].OrderBy(x => x.Key, StringComparer.Ordinal), after[name].OrderBy(x => x.Key, StringComparer.Ordinal)); }