sensor-stat-set skips a bin, as the other role writers do; it takes an optional root for its test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-18 21:08:11 +02:00
commit 8d65e957f8
2 changed files with 24 additions and 3 deletions

View file

@ -290,6 +290,27 @@ public sealed class RolesBackfillCommandTests : IDisposable
finally { db.Cache.Dispose(); }
}
// sensor-stat-set authors an emission-discipline role on every product of a sensor design; a bin of one authors none.
[Fact]
public void A_binned_seller_gains_no_roles_from_sensor_stat_set()
{
var db = AetherDb.Open(catalogWritable: true, root: _root);
var sensor = db.Cache.GetAll<EquippableItemData>().Where(d => d.Behaviors != null && d.Behaviors.OfType<SensorData>().Any()).OrderBy(d => d.Name, StringComparer.Ordinal).First();
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Bin == null && p.Design.Key.Equals(db.Cache.RefOf(sensor).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.SensorStatSet(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()
{

View file

@ -1719,9 +1719,9 @@ public static class Program
// product of such a design authors that role, and the Passive Array (a generic listener gear, ListenerData) is
// authored with two products from the stealth makers. Prints the sensor census first. Dry run unless passed
// "apply"; idempotent, so a second apply writes nothing and a catalog another cut changed is rerun, never merged.
private static int SensorStatSet(bool apply)
internal static int SensorStatSet(bool apply, string root = null)
{
var db = AetherDb.Open(catalogWritable: apply);
var db = AetherDb.Open(catalogWritable: apply, root: root);
var designs = db.Cache.GetAll<EquippableItemData>().ToArray();
var products = db.Cache.GetAll<FactionProductData>().ToArray();
Faction MakerOf(FactionProductData p) => db.Cache.Get(p.Manufacturer);
@ -1760,7 +1760,7 @@ public static class Program
design.Roles ??= new List<ItemRole>();
if (!design.Roles.Any(r => r.Name == EmissionDiscipline)) { design.Roles.Add(new ItemRole { Name = EmissionDiscipline }); designChanged = true; }
if (designChanged) changedDesigns.Add((design, key));
foreach (var product in products.Where(p => p.Design.Key.Equals(key)))
foreach (var product in products.Where(p => p.Bin == null && p.Design.Key.Equals(key)))
{
var maker = MakerOf(product) ?? throw new InvalidOperationException($"Product \"{product.Name}\" has no maker.");
product.Roles ??= new List<ProductRole>();