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 <noreply@anthropic.com>
This commit is contained in:
parent
7f09b05725
commit
2806b443c9
3 changed files with 64 additions and 7 deletions
|
|
@ -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<ProductRole>()).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<string, (float Mean, float Dev)>(Program.MakerProfiles) { ["Pirates"] = (.45f, .22f) };
|
||||
foreach (var design in new[] { autocannon, lrm, srm, mine, drive })
|
||||
{
|
||||
var sellers = cache.GetAll<FactionProductData>().Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray();
|
||||
var sellers = cache.GetAll<FactionProductData>().Where(p => p.Bin == null && p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray();
|
||||
Assert.NotEmpty(sellers);
|
||||
foreach (var product in sellers)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().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<ProductRole> { 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<FactionProductData>().Single(p => p.Name == sellerName).Roles.Count);
|
||||
Assert.Empty(db.Cache.GetAll<FactionProductData>().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<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().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<FactionProductData>().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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<string>((product.Roles ?? new List<ProductRole>()).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<EquippableItemData>().ToArray();
|
||||
var products = db.Cache.GetAll<FactionProductData>().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<string>((product.Roles ?? new List<ProductRole>()).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
|
||||
|
|
|
|||
Loading…
Reference in a new issue