From 7330058991ba1835e715dd6a3afc720a6b70711d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 14:40:08 +0200 Subject: [PATCH 1/7] AetherDb: pirates-faction command authors the Pirates and eight emoji-named rebrands Dry run unless given 'apply'. Not yet built when committed. Co-Authored-By: Claude Sonnet 5.5 --- tools/AetherDb/Program.cs | 110 +++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index c65f4c3f2..d1b488c7a 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -38,8 +38,9 @@ public static class Program case "targeting-catalog-6d": return TargetingCatalog6d(args.Contains("apply")); case "ship-authoring": return ShipAuthoringCommands.Run(args.Skip(1).ToArray()); case "field-kinds": return FieldKindsCatalog(args.Contains("apply")); + case "pirates-faction": 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]"); + 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], pirates-faction [apply]"); return 1; } } @@ -1505,4 +1506,111 @@ public static class Program Console.WriteLine("\nAuthored \"Asteroid\" 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 + // role its design declares, middling and inconsistent (mean .45, sd .22, against makers' .15). Names are stored as the emoji + // only, written here as \U escapes so no editor or shell mangles them; the dry run prints them raw and as code points. + // + // Dry run unless passed "apply", same contract as the other *-migrate commands. + private static int PiratesFaction(bool apply) + { + Console.OutputEncoding = new System.Text.UTF8Encoding(false); + var db = AetherDb.Open(catalogWritable: apply); + + var existing = db.Cache.GetAll().FirstOrDefault(f => f.Name == "Pirates"); + if (existing != null) + { + Console.WriteLine("A faction named \"Pirates\" already exists; nothing to do."); + return 0; + } + + CraftedItemData DesignByName(string name) + { + var matches = db.Cache.GetAll().Where(i => i.Name == name).ToArray(); + if (matches.Length != 1) throw new InvalidOperationException($"Expected exactly one design named \"{name}\", found {matches.Length}."); + return matches[0]; + } + + string CodePoints(string text) => string.Join(" ", text.EnumerateRunes().Select(r => $"U+{r.Value:X4}")); + + var nameFile = db.Cache.GetAll().FirstOrDefault(n => n.Name == "pleiades"); + if (nameFile == null) throw new InvalidOperationException("No name file named \"pleiades\"."); + + var others = db.Cache.GetAll().ToArray(); + var pirates = new Faction + { + Name = "Pirates", + ShortName = "Pirates", + Description = "A loose coalition of crews and hidden docks moving people and goods outside official control. No command, no common law: possession has a maintenance schedule.", + PrimaryColor = new float3(.42f, .40f, .37f), + SecondaryColor = new float3(1f, .45f, .05f), + GeonameFile = db.Cache.RefOf(nameFile), + InfluenceDistance = 3, + }; + foreach (var other in others) pirates.Allegiance[db.Cache.RefOf(other)] = 1f; + + var rebrands = new (string Design, string Name, string Description)[] + { + ("Autocannon", "\U0001FAF3\U0001F52B", "Serial number filed off. Still shoots."), + ("Earp", "\U0001FAA6\U0001F920", "The previous owner had no further use for it."), + ("FastBlast+-", "\U0001F9FE\U0001F6AB", "Warranty void where prohibited, which is everywhere."), + ("6k Shooter", "\U0001F3A8\U0001F648", "The logo underneath is somebody else's problem."), + ("scorched void policy", "\U0001F525", "Turns out we did start the fire after all."), + ("Targeting Computer", "\U0001F440\U0001F3AF", "Somebody else's eyes. They still work."), + ("Small Drive", "\U0001F511\U0001F3C3\U0001F4A8", "Hotwired. Do not ask about the ignition."), + ("Store-All Plus", "\U0001F4E6\U0001F92B", "Contents not as declared."), + }; + + var products = rebrands.Select(r => + { + 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()); + }).ToArray(); + + Console.WriteLine($"New faction \"{pirates.Name}\": influence {pirates.InfluenceDistance}, names \"{nameFile.Name}\", allegiance 1.0 to {pirates.Allegiance.Count} factions."); + Console.WriteLine($" {pirates.Description}"); + Console.WriteLine($"\nNew products ({products.Length}):"); + foreach (var (design, name, description, roles) in products) + { + var makers = db.Cache.GetAll() + .Where(p => p.Design.Key.Equals(db.Cache.RefOf(design).Key)) + .Select(p => db.Cache.Get(p.Manufacturer)?.ShortName).OrderBy(n => n, StringComparer.Ordinal); + Console.WriteLine($" {name} [{CodePoints(name)}]"); + Console.WriteLine($" design {design.GetType().Name} \"{design.Name}\" (made by {string.Join(", ", makers)}), roles [{string.Join(", ", roles.Select(r => r.Role))}]"); + Console.WriteLine($" \"{description}\""); + } + + CultRecordRefs.Validate(pirates); + foreach (var (design, name, description, roles) in products) + CultRecordRefs.Validate(new FactionProductData + { + Name = name, Description = description, Roles = roles, + Design = new CultRecordRef(db.Cache.RefOf(design).Key), + Manufacturer = db.Cache.RefOf(others[0]), + }); + + if (!apply) + { + Console.WriteLine($"\nDry run. Pass \"apply\" to land the Pirates faction and {products.Length} products."); + return 0; + } + + db.Cache.Commit(batch => + { + var piratesKey = batch.Upsert(typeof(Faction), pirates); + foreach (var (design, name, description, roles) in products) + batch.Upsert(typeof(FactionProductData), new FactionProductData + { + Name = name, Description = description, Roles = roles, + Design = new CultRecordRef(db.Cache.RefOf(design).Key), + Manufacturer = new CultRecordRef(piratesKey), + }); + }); + + Console.WriteLine($"\nLanded the Pirates faction and {products.Length} products in Aetheria.cc"); + return 0; + } } From e16288bfcf88dc37a7b50f6170682d91f3398936 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 14:50:48 +0200 Subject: [PATCH 2/7] Pirates record: the demo tests read the shipped faction; tests pin its eight emoji-named products Deletes the AddPirates stand-in and its 21 calls. DemoTerminus_missing_cast_refused removes the shipped record from its scratch copy first. LoadoutGenerator.HasHome is public so the catalog test asks production's own home rule. These tests are red on a catalog without the Pirates: the catalog commit (pirates-faction apply) follows separately. Co-Authored-By: Claude Sonnet 5.5 --- .../Scripts/ServerShared/LoadoutGenerator.cs | 2 +- .../DemoTerminusTests.cs | 31 +++------ .../PiratesRecordTests.cs | 67 +++++++++++++++++++ tests/Aetheria.Shared.Tests/RunGoalTests.cs | 10 --- tests/Aetheria.Shared.Tests/ScenarioTests.cs | 2 - 5 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/PiratesRecordTests.cs diff --git a/Assets/Scripts/ServerShared/LoadoutGenerator.cs b/Assets/Scripts/ServerShared/LoadoutGenerator.cs index 42f43033e..f2fd1c955 100644 --- a/Assets/Scripts/ServerShared/LoadoutGenerator.cs +++ b/Assets/Scripts/ServerShared/LoadoutGenerator.cs @@ -198,7 +198,7 @@ public class LoadoutGenerator // Hardpoint gear that no hull in the catalog can mount has no home (operator, 2026-09-30: "we'll need to author a // bunch more hulls before all the gear variety in the game has a home"): generation never offers it, so no station // stocks it. It gains one the moment a hull with a hardpoint that takes it exists. Tool gear goes in any interior. - private static bool HasHome(EquippableItemData design, HullData[] hulls) => + public static bool HasHome(EquippableItemData design, HullData[] hulls) => design.HardpointType == HardpointType.Tool || design.HardpointType == HardpointType.Hull || hulls.Any(hull => hull.Hardpoints.Any(hardpoint => hardpoint.Takes(design))); diff --git a/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs b/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs index 577296ac3..1f282f48a 100644 --- a/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs +++ b/tests/Aetheria.Shared.Tests/DemoTerminusTests.cs @@ -9,30 +9,16 @@ using CultMath; using Xunit; // The demo scenario (aetheria-release, cut demo-galaxy): a prelude galaxy of a fixed cast whose antagonist's home is the -// boss zone and the exit. The shipped catalog holds no Pirates faction yet, so each test that needs one adds it to its -// scratch copy of the catalog. +// boss zone and the exit. The cast, the Pirates included, is in the shipped catalog. public sealed partial class RunStartTests { private static readonly uint[] DemoSeeds = { 1, 2, 3, 4, 5 }; - // The catalog record the demo's protagonist needs, until the shipped catalog has one. Zone names need a name file, - // and the entrance's station needs a faction whose allegiance reaches some manufacturer, so it reaches every one. - private void AddPirates() - { - var pirates = new Faction - { - Name = "Pirates", ShortName = "Pirates", GeonameFile = _cache.RefOf(_cache.GetAll().First()) - }; - foreach (var faction in _cache.GetAll().ToArray()) pirates.Allegiance[_cache.RefOf(faction)] = 1; - _cache.Upsert(pirates); - } - private Galaxy DemoGalaxy(uint seed) => RunStart.Generate(new DemoTerminus(), Inputs(() => seed)); [Fact] public void DemoTerminus_fixed_cast() { - AddPirates(); foreach (var seed in DemoSeeds) Assert.Equal(new[] { "Pirates", "Zhestokost", "Lucent Media", "Aeronautics Unlimited" }, DemoGalaxy(seed).Factions.Select(faction => faction.Name)); @@ -41,7 +27,6 @@ public sealed partial class RunStartTests [Fact] public void DemoTerminus_gate_at_antagonist_home() { - AddPirates(); foreach (var seed in DemoSeeds) { var galaxy = DemoGalaxy(seed); @@ -60,7 +45,6 @@ public sealed partial class RunStartTests [Fact] public void DemoTerminus_standing_survives_continue() { - AddPirates(); var (galaxy, arena, staged, failures) = Launch(new DemoTerminus(), Inputs(() => 1)); Assert.True(failures.Count == 0, string.Join("; ", failures)); galaxy.Entrance.Contents = arena; @@ -83,11 +67,16 @@ public sealed partial class RunStartTests restored.BossZones.Select(boss => (boss.Key.Name, Array.IndexOf(restored.Zones, boss.Value)))); } - // On the shipped catalog, which has no Pirates, the run does not start: the galaxy refuses, naming the cast field, - // and the scenario never reaches staging. + // A catalog without the Pirates (the shipped record and its products removed from this scratch copy) does not start the + // run: the galaxy refuses, naming the cast field, and the scenario never reaches staging. [Fact] public void DemoTerminus_missing_cast_refused() { + var pirates = _cache.GetAll().Single(faction => faction.Name == "Pirates"); + var piratesRef = _cache.RefOf(pirates); + foreach (var product in _cache.GetAll().Where(product => product.Manufacturer.Equals(piratesRef)).ToArray()) + Assert.True(_cache.Remove(_cache.RefOf(product).Key)); + Assert.True(_cache.Remove(piratesRef.Key)); Assert.DoesNotContain(_cache.GetAll(), faction => faction.Name.StartsWith("Pirates", StringComparison.Ordinal)); var refusal = Assert.Throws(() => DemoGalaxy(1)); Assert.Contains("Pirates", refusal.Message); @@ -108,7 +97,6 @@ public sealed partial class RunStartTests [Fact] public void DemoTerminus_player_flies_a_non_pirates_brand_hull_the_longinus() { - AddPirates(); foreach (var seed in DemoSeeds) { var (galaxy, _, staged, failures) = Launch(new DemoTerminus(), Inputs(() => seed)); @@ -130,7 +118,6 @@ public sealed partial class RunStartTests [Fact] public void DemoTerminus_player_carries_the_longinus_default_fit() { - AddPirates(); string Fit(Entity ship) => string.Join(";", ship.Equipment .Select(item => $"{item.Data.Name}@{item.Position}/{item.EquippableItem.Rotation}") .OrderBy(entry => entry, StringComparer.Ordinal)); @@ -151,7 +138,6 @@ public sealed partial class RunStartTests [Fact] public void DemoTerminus_region_is_sixty_four_zones_linked_at_half_density() { - AddPirates(); string Links(Galaxy g) => string.Join(";", g.Zones.Select(zone => string.Join(",", zone.AdjacentZones.Select(adjacent => Array.IndexOf(g.Zones, adjacent)).OrderBy(index => index)))); Galaxy Reference(uint seed, float density) @@ -177,7 +163,6 @@ public sealed partial class RunStartTests [Fact] public void ACastNamingNoQuestFactionPlacesNoQuestZone() { - AddPirates(); var galaxy = DemoGalaxy(1); Assert.Equal(4, galaxy.HomeZones.Count); Assert.Equal(4, galaxy.Factions.Length); diff --git a/tests/Aetheria.Shared.Tests/PiratesRecordTests.cs b/tests/Aetheria.Shared.Tests/PiratesRecordTests.cs new file mode 100644 index 000000000..7a865d1e4 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/PiratesRecordTests.cs @@ -0,0 +1,67 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +using System; +using System.Linq; +using Xunit; + +// The Pirates record (aetheria-release, cut pirates-record): the shipped catalog's faction of rebrands, named in emoji. +public sealed partial class RunStartTests +{ + private Faction ShippedPirates() => _cache.GetAll().Single(faction => faction.Name == "Pirates"); + + private FactionProductData[] PiratesProducts() + { + var pirates = _cache.RefOf(ShippedPirates()); + return _cache.GetAll().Where(product => product.Manufacturer.Equals(pirates)).ToArray(); + } + + // The demo's allied faction exists as catalog data with eight generatable rebrands of other makers' designs. + [Fact] + public void PiratesAreInTheShippedCatalog() + { + var pirates = ShippedPirates(); + var others = _cache.GetAll().Where(faction => faction != pirates).Select(faction => _cache.RefOf(faction)).ToArray(); + Assert.NotEmpty(others); + Assert.All(others, other => Assert.True(pirates.Allegiance.ContainsKey(other))); + Assert.NotNull(_cache.Get(pirates.GeonameFile)); + + var products = PiratesProducts(); + Assert.Equal(8, products.Length); + var hulls = _cache.GetAll().ToArray(); + foreach (var product in products) + { + var design = _cache.Get(product.Design) as EquippableItemData; + Assert.NotNull(design); + Assert.True(LoadoutGenerator.HasHome(design, hulls), $"{design.Name} has no home"); + Assert.True(design.Price > 0, $"{design.Name} has no price"); + Assert.Contains(_cache.GetAll(), other => + other.Design.Key.Equals(product.Design.Key) && !other.Manufacturer.Equals(product.Manufacturer)); + } + } + + // The Pirates' products are named in emoji and nothing else: no ASCII letter or digit survives in a name. + [Fact] + public void PiratesProductsAreNamedInEmoji() + { + foreach (var product in PiratesProducts()) + { + Assert.False(string.IsNullOrEmpty(product.Name)); + Assert.DoesNotContain(product.Name, character => character < 128 && char.IsLetterOrDigit(character)); + Assert.Contains(product.Name.EnumerateRunes(), rune => rune.Value >= 0x1F000); + } + } + + // Brand finds a lot's product by (maker, design), so a maker may sell one product per design. + [Fact] + public void NoMakerSellsTwoProductsOfOneDesign() + { + var twice = _cache.GetAll() + .GroupBy(product => (Maker: product.Manufacturer.Key.Value, Design: product.Design.Key.Value)) + .Where(group => group.Count() > 1) + .Select(group => string.Join(", ", group.Select(product => product.Name))) + .ToArray(); + Assert.Empty(twice); + } +} diff --git a/tests/Aetheria.Shared.Tests/RunGoalTests.cs b/tests/Aetheria.Shared.Tests/RunGoalTests.cs index da7ff39ba..afdaa658a 100644 --- a/tests/Aetheria.Shared.Tests/RunGoalTests.cs +++ b/tests/Aetheria.Shared.Tests/RunGoalTests.cs @@ -41,7 +41,6 @@ public sealed partial class RunStartTests [Fact] public void Boss_spawns_once_in_boss_zone() { - AddPirates(); foreach (var seed in DemoSeeds.Take(3)) { var galaxy = DemoGalaxy(seed); @@ -65,7 +64,6 @@ public sealed partial class RunStartTests [Fact] public void Boss_spawns_in_a_zone_that_is_not_ambient() { - AddPirates(); var galaxy = DemoGalaxy(1); var pack = BossZonePack(galaxy, _items, galaxy.Exit, ambient: false); Assert.Single(pack.Entities, entity => entity.Boss); @@ -75,7 +73,6 @@ public sealed partial class RunStartTests [Fact] public void Boss_hull_from_BossHull_else_fallback() { - AddPirates(); var galaxy = DemoGalaxy(1); var antagonist = Zhestokost(galaxy); var hulls = SoldShipHulls().OrderByDescending(hull => hull.Price).ThenBy(hull => hull.Name, StringComparer.Ordinal).ToArray(); @@ -103,7 +100,6 @@ public sealed partial class RunStartTests [Fact] public void Boss_hull_nobody_sells_falls_back() { - AddPirates(); var galaxy = DemoGalaxy(1); var antagonist = Zhestokost(galaxy); var sold = SoldShipHulls(); @@ -121,7 +117,6 @@ public sealed partial class RunStartTests [Fact] public void Exit_sealed_until_boss_dies() { - AddPirates(); var galaxy = DemoGalaxy(1); var exit = ZoneOf(galaxy, galaxy.Exit); var boss = Assert.Single(exit.Entities, entity => entity.IsBoss); @@ -143,7 +138,6 @@ public sealed partial class RunStartTests [Fact] public void Boss_mark_survives_continue() { - AddPirates(); var (galaxy, arena, staged, failures) = Launch(new DemoTerminus(), Inputs(() => 1)); Assert.True(failures.Count == 0, string.Join("; ", failures)); galaxy.Entrance.Contents = arena; @@ -185,7 +179,6 @@ public sealed partial class RunStartTests [Fact] public void Exit_sealed_and_logged_when_the_boss_cannot_be_generated() { - AddPirates(); var galaxy = DemoGalaxy(1); galaxy.BossZones.Clear(); var log = new List(); @@ -201,7 +194,6 @@ public sealed partial class RunStartTests [Fact] public void Exit_open_after_save_of_a_slain_boss() { - AddPirates(); var galaxy = DemoGalaxy(1); var exit = ZoneOf(galaxy, galaxy.Exit); Assert.Single(exit.Entities, entity => entity.IsBoss).HeatstrokeDeath.OnNext(Unit.Default); @@ -215,7 +207,6 @@ public sealed partial class RunStartTests [Fact] public void Exit_gate_shares_no_point_with_a_wormhole() { - AddPirates(); var ratio = float.Parse(File.ReadLines(Path.Combine(FindRepoRoot(), "Assets", "Resources", "Settings.asset")) .Select(line => Regex.Match(line, @"^ WormholeDistanceRatio: (.+)$")).First(match => match.Success).Groups[1].Value.Trim(), System.Globalization.CultureInfo.InvariantCulture); @@ -244,7 +235,6 @@ public sealed partial class RunStartTests [InlineData(new[] { 0.0, 45.0, 90.0, 135.0, 180.0, -135.0, -90.0, -45.0 })] public void Exit_gate_sits_in_the_widest_gap_at_the_wormhole_radius(double[] neighbourDegrees) { - AddPirates(); var galaxy = DemoGalaxy(1); var zone = ZoneOf(galaxy, galaxy.Exit); const float ratio = 0.75f; diff --git a/tests/Aetheria.Shared.Tests/ScenarioTests.cs b/tests/Aetheria.Shared.Tests/ScenarioTests.cs index 51554904e..a9e3b5678 100644 --- a/tests/Aetheria.Shared.Tests/ScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/ScenarioTests.cs @@ -96,7 +96,6 @@ public sealed partial class RunStartTests [Fact] public void EveryScenarioStages() { - AddPirates(); Assert.Equal(EveryScenario.Count(), EveryScenario.Select(scenario => scenario.Name).Distinct().Count()); foreach (var scenario in EveryScenario) { @@ -523,7 +522,6 @@ public sealed partial class RunStartTests [Fact] public void EveryUnsoldDesignIsAScenarioTestDesign() { - AddPirates(); var runs = EveryScenario.Select(scenario => Launch(scenario, Inputs(() => GalaxySeed)).staged).ToList(); Assert.Empty(UnsoldAndUnplaced(runs)); From 78755fd176dbc482eb48db1cb80e13ff7428c032 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 18:16:10 +0200 Subject: [PATCH 3/7] pirates-faction: callable on a root, prints its colours; tests pin dry run, idempotence, conflict and missing design Not yet built when committed. Co-Authored-By: Claude Sonnet 5.5 --- .../PiratesFactionCommandTests.cs | 89 +++++++++++++++++++ tools/AetherDb/Program.cs | 10 ++- 2 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs diff --git a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs new file mode 100644 index 000000000..f5b0d5851 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs @@ -0,0 +1,89 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +using System; +using System.IO; +using System.Linq; +using Xunit; + +// AetherDb's pirates-faction command (aetheria-release, cut pirates-record), run on a scratch copy of the shipped catalog +// with the Pirates removed from it. +public sealed class PiratesFactionCommandTests : IDisposable +{ + private readonly string _root = Path.Combine(Path.GetTempPath(), "pirates-command-" + Guid.NewGuid().ToString("N")); + private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc"); + + public PiratesFactionCommandTests() + { + Directory.CreateDirectory(Path.Combine(_root, "GameData")); + File.Copy(Path.Combine(AetherDb.FindRoot(), "GameData", "Aetheria.cc"), CatalogPath); + var db = AetherDb.Open(catalogWritable: true, root: _root); + var pirates = db.Cache.GetAll().Single(faction => faction.Name == "Pirates"); + var ours = db.Cache.RefOf(pirates); + foreach (var product in db.Cache.GetAll().Where(product => product.Manufacturer.Equals(ours)).ToArray()) + Assert.True(db.Cache.Remove(db.Cache.RefOf(product).Key)); + Assert.True(db.Cache.Remove(ours.Key)); + db.Cache.Dispose(); + } + + public void Dispose() => Directory.Delete(_root, true); + + private (Faction[] Pirates, FactionProductData[] Products) Read() + { + var db = AetherDb.Open(root: _root); + try + { + var pirates = db.Cache.GetAll().Where(faction => faction.Name == "Pirates").ToArray(); + var products = pirates.Length == 0 ? new FactionProductData[0] + : db.Cache.GetAll().Where(product => product.Manufacturer.Equals(db.Cache.RefOf(pirates[0]))).ToArray(); + return (pirates, products); + } + finally { db.Cache.Dispose(); } + } + + [Fact] + public void A_dry_run_writes_nothing_and_apply_lands_the_record_once() + { + var before = File.ReadAllBytes(CatalogPath); + Assert.Equal(0, Program.PiratesFaction(apply: false, root: _root)); + Assert.Equal(before, File.ReadAllBytes(CatalogPath)); + Assert.Empty(Read().Pirates); + + Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root)); + var landed = File.ReadAllBytes(CatalogPath); + var (pirates, products) = Read(); + Assert.Single(pirates); + Assert.Equal(8, products.Length); + + // A second apply finds the faction and changes nothing. + Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root)); + Assert.Equal(landed, File.ReadAllBytes(CatalogPath)); + } + + [Fact] + public void An_existing_Pirates_faction_is_left_as_it_is() + { + var db = AetherDb.Open(catalogWritable: true, root: _root); + db.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Pirates", ShortName = "Mine", Description = "authored by hand" })); + db.Cache.Dispose(); + + Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root)); + var (pirates, products) = Read(); + Assert.Equal("authored by hand", Assert.Single(pirates).Description); + Assert.Empty(products); + } + + [Fact] + public void A_missing_design_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(); + + Assert.Throws(() => Program.PiratesFaction(apply: true, root: _root)); + Assert.Empty(Read().Pirates); + } +} diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index d1b488c7a..de1319acf 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -38,7 +38,9 @@ public static class Program case "targeting-catalog-6d": return TargetingCatalog6d(args.Contains("apply")); case "ship-authoring": return ShipAuthoringCommands.Run(args.Skip(1).ToArray()); case "field-kinds": return FieldKindsCatalog(args.Contains("apply")); - case "pirates-faction": return PiratesFaction(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], pirates-faction [apply]"); return 1; @@ -1514,10 +1516,9 @@ public static class Program // only, written here as \U escapes so no editor or shell mangles them; the dry run prints them raw and as code points. // // Dry run unless passed "apply", same contract as the other *-migrate commands. - private static int PiratesFaction(bool apply) + public static int PiratesFaction(bool apply, string root = null) { - Console.OutputEncoding = new System.Text.UTF8Encoding(false); - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.Open(catalogWritable: apply, root: root); var existing = db.Cache.GetAll().FirstOrDefault(f => f.Name == "Pirates"); if (existing != null) @@ -1571,6 +1572,7 @@ public static class Program }).ToArray(); Console.WriteLine($"New faction \"{pirates.Name}\": influence {pirates.InfluenceDistance}, names \"{nameFile.Name}\", allegiance 1.0 to {pirates.Allegiance.Count} factions."); + Console.WriteLine($" colours: primary ({pirates.PrimaryColor.x:0.00}, {pirates.PrimaryColor.y:0.00}, {pirates.PrimaryColor.z:0.00}) primer grey, secondary ({pirates.SecondaryColor.x:0.00}, {pirates.SecondaryColor.y:0.00}, {pirates.SecondaryColor.z:0.00}) hazard orange"); Console.WriteLine($" {pirates.Description}"); Console.WriteLine($"\nNew products ({products.Length}):"); foreach (var (design, name, description, roles) in products) From 0a57e417bd99c9e26b862c002c801c4763c5c616 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 18:29:23 +0200 Subject: [PATCH 4/7] Catalog: pirates-faction apply lands the Pirates and eight emoji-named products MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Operator approved the dry run as shown (ruling pirates-record-apply). Dry run output: New faction "Pirates": influence 3, names "pleiades", allegiance 1.0 to 12 factions. colours: primary (0.42, 0.40, 0.37) primer grey, secondary (1.00, 0.45, 0.05) hazard orange A loose coalition of crews and hidden docks moving people and goods outside official control. No command, no common law: possession has a maintenance schedule. New products (8): πŸ«³πŸ”« [U+1FAF3 U+1F52B] design WeaponItemData "Autocannon" (made by Zhestokost), roles [] "Serial number filed off. Still shoots." πŸͺ¦πŸ€  [U+1FAA6 U+1F920] design WeaponItemData "Earp" (made by AU), roles [barrel, feed mechanism] "The previous owner had no further use for it." 🧾🚫 [U+1F9FE U+1F6AB] design WeaponItemData "FastBlast+-" (made by NiteLife), roles [focusing array, power coupling] "Warranty void where prohibited, which is everywhere." πŸŽ¨πŸ™ˆ [U+1F3A8 U+1F648] design WeaponItemData "6k Shooter" (made by Zhestokost), roles [barrel, feed mechanism] "The logo underneath is somebody else's problem." πŸ”₯ [U+1F525] design WeaponItemData "scorched void policy" (made by DME), roles [guidance system, thruster, warhead] "Turns out we did start the fire after all." πŸ‘€πŸŽ― [U+1F440 U+1F3AF] design GearData "Targeting Computer" (made by Finch, Lucent, NiteLife), roles [processor, array] "Somebody else's eyes. They still work." πŸ”‘πŸƒπŸ’¨ [U+1F511 U+1F3C3 U+1F4A8] design GearData "Small Drive" (made by Lightsail), roles [injector, nozzle] "Hotwired. Do not ask about the ignition." πŸ“¦πŸ€« [U+1F4E6 U+1F92B] design CargoBayData "Store-All Plus" (made by Lightsail), roles [] "Contents not as declared." Dry run. Pass "apply" to land the Pirates faction and 8 products. 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 96135d923..a68ed245a 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63250cf21ae9abeec657f0603336bb11b4d50b66560903ef45a8cceb01a7ae25 -size 12703489 +oid sha256:ea087d34398654c2373437de273eb113dc2f60374486561abf9e4f51df91e46d +size 12706863 From 8cb53049aa81c2ba724bec4c44754ff455dc61f9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 18:53:18 +0200 Subject: [PATCH 5/7] PiratesFactionCommandTests: strip the copy through a shipped-assembly registry, then seed the test global AetherDb.Open demands Co-Authored-By: Claude Sonnet 5.5 --- .../PiratesFactionCommandTests.cs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs index f5b0d5851..feed84228 100644 --- a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs @@ -5,6 +5,9 @@ using System; using System.IO; using System.Linq; +using System.Reflection; +using GameCult.Caching; +using GameCult.Caching.MessagePack; using Xunit; // AetherDb's pirates-faction command (aetheria-release, cut pirates-record), run on a scratch copy of the shipped catalog @@ -18,13 +21,28 @@ public sealed class PiratesFactionCommandTests : IDisposable { Directory.CreateDirectory(Path.Combine(_root, "GameData")); File.Copy(Path.Combine(AetherDb.FindRoot(), "GameData", "Aetheria.cc"), CatalogPath); - var db = AetherDb.Open(catalogWritable: true, root: _root); - var pirates = db.Cache.GetAll().Single(faction => faction.Name == "Pirates"); - var ours = db.Cache.RefOf(pirates); - foreach (var product in db.Cache.GetAll().Where(product => product.Manufacturer.Equals(ours)).ToArray()) - Assert.True(db.Cache.Remove(db.Cache.RefOf(product).Key)); - Assert.True(db.Cache.Remove(ours.Key)); - db.Cache.Dispose(); + // AetherDb.Open composes the process-wide registry, which in this test host also sees this assembly's TestCatalogGlobal + // (see FireControlCut7Tests). So the copy is stripped through a registry scoped to the shipped assembly and then given + // the record that registry's shared sibling demands, as AetheriaStoresTests does. + 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 pirates = cache.GetAll().Single(faction => faction.Name == "Pirates"); + var ours = cache.RefOf(pirates); + foreach (var product in cache.GetAll().Where(product => product.Manufacturer.Equals(ours)).ToArray()) + Assert.True(cache.Remove(cache.RefOf(product).Key)); + Assert.True(cache.Remove(ours.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); From b385c65194395fc837f9d02fcfe0d539d87c25e3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 19:15:37 +0200 Subject: [PATCH 6/7] PiratesFactionCommandTests: pin the faction's fields, the eight products' designs, descriptions and roles, and the missing name file Co-Authored-By: Claude Sonnet 5.5 --- .../PiratesFactionCommandTests.cs | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs index feed84228..e9d321e20 100644 --- a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs @@ -71,8 +71,42 @@ public sealed class PiratesFactionCommandTests : IDisposable Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root)); var landed = File.ReadAllBytes(CatalogPath); var (pirates, products) = Read(); - Assert.Single(pirates); - Assert.Equal(8, products.Length); + var faction = Assert.Single(pirates); + Assert.Equal("Pirates", faction.ShortName); + Assert.StartsWith("A loose coalition of crews and hidden docks", faction.Description); + Assert.Equal(3, faction.InfluenceDistance); + Assert.Equal(new CultMath.float3(.42f, .40f, .37f), faction.PrimaryColor); + Assert.Equal(new CultMath.float3(1f, .45f, .05f), faction.SecondaryColor); + Assert.Equal(12, faction.Allegiance.Count); + Assert.All(faction.Allegiance.Values, value => Assert.Equal(1f, value)); + + var db = AetherDb.Open(root: _root); + try + { + Assert.Equal("pleiades", db.Cache.Get(faction.GeonameFile).Name); + var expected = new (string Design, string Name, string Description)[] + { + ("Autocannon", "πŸ«³πŸ”«", "Serial number filed off. Still shoots."), + ("Earp", "πŸͺ¦πŸ€ ", "The previous owner had no further use for it."), + ("FastBlast+-", "🧾🚫", "Warranty void where prohibited, which is everywhere."), + ("6k Shooter", "πŸŽ¨πŸ™ˆ", "The logo underneath is somebody else's problem."), + ("scorched void policy", "πŸ”₯", "Turns out we did start the fire after all."), + ("Targeting Computer", "πŸ‘€πŸŽ―", "Somebody else's eyes. They still work."), + ("Small Drive", "πŸ”‘πŸƒπŸ’¨", "Hotwired. Do not ask about the ignition."), + ("Store-All Plus", "πŸ“¦πŸ€«", "Contents not as declared."), + }; + Assert.Equal(expected.Select(e => e.Name).OrderBy(n => n, StringComparer.Ordinal), products.Select(p => p.Name).OrderBy(n => n, StringComparer.Ordinal)); + foreach (var (designName, name, description) in expected) + { + var product = products.Single(p => p.Name == name); + var design = (CraftedItemData) db.Cache.Get(product.Design); + Assert.Equal(designName, design.Name); + Assert.Equal(description, product.Description); + Assert.Equal(design.Roles.Select(role => role.Name), product.Roles.Select(role => role.Role)); + Assert.All(product.Roles, role => { Assert.Equal(.45f, role.Mean); Assert.Equal(.22f, role.StandardDeviation); }); + } + } + finally { db.Cache.Dispose(); } // A second apply finds the faction and changes nothing. Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root)); @@ -104,4 +138,16 @@ public sealed class PiratesFactionCommandTests : IDisposable Assert.Throws(() => Program.PiratesFaction(apply: true, root: _root)); Assert.Empty(Read().Pirates); } + + [Fact] + public void A_missing_name_file_refuses_and_lands_nothing() + { + var db = AetherDb.Open(catalogWritable: true, root: _root); + var pleiades = db.Cache.GetAll().Single(file => file.Name == "pleiades"); + Assert.True(db.Cache.Remove(db.Cache.RefOf(pleiades).Key)); + db.Cache.Dispose(); + + Assert.Throws(() => Program.PiratesFaction(apply: true, root: _root)); + Assert.Empty(Read().Pirates); + } } From 8e51016f23ebc5ea2337732b18aa1d5968e30505 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 8 Oct 2026 19:39:54 +0200 Subject: [PATCH 7/7] PiratesFactionCommandTests: flush the name-file removal; tolerate a null empty role list Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs index e9d321e20..6a1c245b0 100644 --- a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs @@ -3,6 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -102,7 +103,7 @@ public sealed class PiratesFactionCommandTests : IDisposable var design = (CraftedItemData) db.Cache.Get(product.Design); Assert.Equal(designName, design.Name); Assert.Equal(description, product.Description); - Assert.Equal(design.Roles.Select(role => role.Name), product.Roles.Select(role => role.Role)); + Assert.Equal((design.Roles ?? new List()).Select(role => role.Name), (product.Roles ?? new List()).Select(role => role.Role)); Assert.All(product.Roles, role => { Assert.Equal(.45f, role.Mean); Assert.Equal(.22f, role.StandardDeviation); }); } } @@ -145,6 +146,7 @@ public sealed class PiratesFactionCommandTests : IDisposable var db = AetherDb.Open(catalogWritable: true, root: _root); var pleiades = db.Cache.GetAll().Single(file => file.Name == "pleiades"); Assert.True(db.Cache.Remove(db.Cache.RefOf(pleiades).Key)); + db.Cache.FlushAsync().Wait(); db.Cache.Dispose(); Assert.Throws(() => Program.PiratesFaction(apply: true, root: _root));