From 2806b443c9c20f58c7ffc615d1e672f73b358d59 Mon Sep 17 00:00:00 2001
From: Meta Vens
Date: Sun, 18 Oct 2026 18:06:07 +0200
Subject: [PATCH] Census, roles-migrate and roles-backfill skip a bin: it
authors no roles, it reads its line's
RolesMigrate takes an optional root, as RolesBackfill does, so its bin skip has a test.
Co-Authored-By: Claude Sonnet 5.5
---
.../Aetheria.Shared.Tests/CatalogRoleTests.cs | 8 +--
.../RolesBackfillCommandTests.cs | 53 +++++++++++++++++++
tools/AetherDb/Program.cs | 10 ++--
3 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs
index b50e0142d..10056b421 100644
--- a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs
+++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs
@@ -36,7 +36,7 @@ public sealed class CatalogRoleTests
}
// 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
+ // declared role is read, and every seller authors each role once (a bin authors none: it reads its line's). 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()
@@ -59,13 +59,15 @@ public sealed class CatalogRoleTests
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)))
+ foreach (var product in products.Where(p => p.Bin == null && 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");
}
}
+ foreach (var bin in products.Where(p => p.Bin != null))
+ if (bin.Roles?.Count > 0 || bin.Assembly != null) broken.Add($"bin \"{bin.Name}\" authors roles or an assembly of its own");
Assert.True(broken.Count == 0, string.Join("\n", broken));
}
@@ -264,7 +266,7 @@ public sealed class CatalogRoleTests
var profiles = new Dictionary(Program.MakerProfiles) { ["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();
+ var sellers = cache.GetAll().Where(p => p.Bin == null && p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray();
Assert.NotEmpty(sellers);
foreach (var product in sellers)
{
diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs
index 1f276c639..1f0f974f5 100644
--- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs
+++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs
@@ -207,6 +207,59 @@ public sealed class RolesBackfillCommandTests : IDisposable
finally { db.Cache.Dispose(); }
}
+ // A bin authors no roles (ProductBin): the backfill that restores its line's missing roles leaves the bin's list empty.
+ [Fact]
+ public void A_binned_seller_gains_no_roles()
+ {
+ 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 sellerName = seller.Name;
+ seller.Roles = new List { seller.Roles.OrderBy(r => r.Role, StringComparer.Ordinal).First() };
+ var bin = new FactionProductData
+ {
+ Name = "Binned " + sellerName, Design = seller.Design, Manufacturer = seller.Manufacturer,
+ Bin = new ProductBin { Line = db.Cache.RefOf(seller), Floor = 0f }
+ };
+ db.Cache.Commit(batch =>
+ {
+ batch.Upsert(typeof(FactionProductData), seller, db.Cache.RefOf(seller).Key);
+ batch.Upsert(typeof(FactionProductData), bin);
+ });
+ db.Cache.Dispose();
+
+ Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root));
+ db = AetherDb.Open(root: _root);
+ try
+ {
+ Assert.Equal(2, db.Cache.GetAll().Single(p => p.Name == sellerName).Roles.Count);
+ Assert.Empty(db.Cache.GetAll().Single(p => p.Name == "Binned " + sellerName).Roles);
+ }
+ finally { db.Cache.Dispose(); }
+ }
+
+ // roles-migrate authors a role on every product that sells a design lacking one; a bin sells none of its own.
+ [Fact]
+ public void A_binned_seller_gains_no_roles_from_roles_migrate()
+ {
+ 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));
+ var bin = new FactionProductData
+ {
+ Name = "Binned " + seller.Name, Design = seller.Design, Manufacturer = seller.Manufacturer,
+ Bin = new ProductBin { Line = db.Cache.RefOf(seller), Floor = 0f }
+ };
+ db.Cache.Commit(batch => batch.Upsert(typeof(FactionProductData), bin));
+ db.Cache.Dispose();
+
+ Assert.Equal(0, Program.RolesMigrate(apply: true, root: _root));
+ db = AetherDb.Open(root: _root);
+ try { Assert.Empty(db.Cache.GetAll().Single(p => p.Name == "Binned " + seller.Name).Roles); }
+ 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 5df9ed99c..46a812ba2 100644
--- a/tools/AetherDb/Program.cs
+++ b/tools/AetherDb/Program.cs
@@ -132,7 +132,8 @@ public static class Program
foreach (var item in items.Where(i => i.Roles != null && i.Roles.Count > 0))
{
var design = db.Cache.RefOf(item).Key;
- var sellers = products.Where(p => p.Design.Key.Equals(design)).ToArray();
+ // A bin authors no spread: it reads its line's (ProductBin).
+ var sellers = products.Where(p => p.Bin == null && p.Design.Key.Equals(design)).ToArray();
foreach (var product in sellers)
{
var covered = new HashSet((product.Roles ?? new List()).Select(r => r.Role));
@@ -309,9 +310,9 @@ public static class Program
// Dry run unless passed "apply", which alone opens the catalog writable; every record must derive cleanly or
// nothing is written, the same all-or-nothing contract ShieldMigrate and BrownoutMigrate already use. Prints
// the operator review table (grouped by item kind) either way.
- private static int RolesMigrate(bool apply)
+ public static int RolesMigrate(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 changedDesigns = new List<(object Document, CultRecordKey Key)>();
@@ -366,6 +367,7 @@ public static class Program
var byDesign = items.ToDictionary(i => db.Cache.RefOf(i).Key, i => i);
foreach (var product in products.OrderBy(p => p.Name, StringComparer.Ordinal))
{
+ if (product.Bin != null) continue; // a bin authors no roles; the mint reads its line's
if (!byDesign.TryGetValue(product.Design.Key, out var design) || design.Roles == null || design.Roles.Count == 0)
continue;
var existing = new HashSet((product.Roles ?? new List()).Select(r => r.Role));
@@ -2218,7 +2220,7 @@ public static class Program
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))
+ foreach (var product in products.Where(p => p.Bin == null && 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