product-lines apply lands on a catalog with older-schema records; refusal axes pinned; one maker-profile table

ExpectUnchanged compares the file's schema ids with the loaded ones, so master's blob (hulls written before
HullData lost GridOffset) made apply throw and write nothing. The batch now expects only that the keys it authors
are absent and lands onto the file as it is. Tests: older-schema replay, the design and maker match, case-insensitive
name conflict, a row name that is a design's, the dispatch word, and the sold-weapon floor replaced by "only Smoke
designs are unsold". LaunchSuppressorCatalogTests reads Program.MakerProfiles instead of spelling six profiles.

Not built or run yet; the catalog blob is regenerated in the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-16 20:50:47 +02:00
commit ceb1a08edb
4 changed files with 98 additions and 13 deletions

View file

@ -67,11 +67,6 @@ public sealed class LaunchSuppressorCatalogTests
}
// Exactly these six products and these makers, each authoring both roles at its maker's own mean and deviation.
var profiles = new Dictionary<string, (float Mean, float Dev)>
{
["NiteLife"] = (.55f, .12f), ["Finch"] = (.65f, .20f), ["DME"] = (.55f, .20f), ["R&D"] = (.60f, .15f),
["Lightsail"] = (.55f, .10f), ["Alakrita"] = (.60f, .14f),
};
foreach (var (name, makers) in new[]
{
(StrongName, new[] { "DME", "Finch", "NiteLife", "R&D" }),
@ -84,7 +79,7 @@ public sealed class LaunchSuppressorCatalogTests
Assert.Equal(products.Length, products.Select(p => p.Name).Distinct().Count());
Assert.All(products, product =>
{
var (mean, dev) = profiles[cache.Get(product.Manufacturer).ShortName];
var (mean, dev) = Program.MakerProfiles[cache.Get(product.Manufacturer).ShortName];
Assert.Equal(new[] { "baffles", "heat sink" }, product.Roles.Select(r => r.Role).OrderBy(r => r, StringComparer.Ordinal).ToArray());
Assert.All(product.Roles, r =>
{

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameCult.Caching;
using Xunit;
@ -16,16 +17,20 @@ public sealed class ProductLinesCatalogTests
{
using var cache = RestoredHullsTests.OpenCatalog();
var products = cache.GetAll<FactionProductData>().ToArray();
var sold = 0;
var unsold = new List<string>();
foreach (var design in cache.GetAll<WeaponItemData>())
{
var key = cache.RefOf(design).Key;
var makers = products.Where(p => p.Design.Key.Equals(key)).Select(p => p.Manufacturer.Key).Distinct().Count();
if (makers == 0) continue;
sold++;
if (makers == 0)
{
unsold.Add(design.Name);
continue;
}
Assert.True(makers >= 2, $"the weapon design \"{design.Name}\" is sold by {makers} maker");
}
Assert.True(sold >= 20, "the catalog should sell many weapon designs");
// The designs no product sells are the Smoke test designs and no others: a design that lost all its products is a failure.
Assert.All(unsold, name => Assert.StartsWith("Smoke ", name));
}
[Fact]

View file

@ -176,4 +176,87 @@ public sealed class ProductLinesCommandTests : IDisposable
using var after = Open();
Assert.Contains(after.GetAll<FactionProductData>(), p => p.Name == "Scratch tier");
}
// Master's committed catalog holds records written on a schema older than today's (HullData lost a member after the last
// catalog write). The scratch copy gets that shape: the hull records point at an earlier schema id the loader resolves to
// the current type.
private string MakeHullsStale()
{
var snapshot = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(CatalogPath));
var current = snapshot.SchemaCatalog.Single(e => e.SchemaName == "aetheria.hulldata");
var stale = new CultSchemaCatalogEntry
{
SchemaId = "sha256:earlier-hulldata", SchemaName = current.SchemaName, SchemaVersion = current.SchemaVersion,
ContentHash = "sha256:earlier-hulldata", CanonicalSchemaJson = current.CanonicalSchemaJson, Members = current.Members,
};
snapshot.SchemaCatalog = snapshot.SchemaCatalog.Append(stale).ToArray();
var hulls = snapshot.Records.Where(r => r.SchemaId == current.SchemaId).ToArray();
Assert.NotEmpty(hulls);
foreach (var hull in hulls) hull.SchemaId = stale.SchemaId;
File.WriteAllBytes(CatalogPath, CultDocumentMessagePackSerialization.SerializeSnapshot(snapshot));
return stale.SchemaId;
}
[Fact]
public void Apply_lands_on_a_catalog_that_holds_records_of_an_older_schema_and_replays_to_the_same_bytes()
{
var stale = MakeHullsStale();
var before = Records();
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
var landed = File.ReadAllBytes(CatalogPath);
Assert.Equal(_shipped, Line20());
var after = Records();
foreach (var (key, record) in before)
Assert.True(record.Payload.AsSpan().SequenceEqual(after[key].Payload) && record.SchemaId == after[key].SchemaId, "a record the command did not author changed");
Assert.Contains(after.Values, r => r.SchemaId == stale);
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
Assert.Equal(landed, File.ReadAllBytes(CatalogPath));
}
private void AddProduct(string name, string design, string maker)
{
using var cache = Open();
var designRecord = cache.GetAll<WeaponItemData>().First(w => w.Name == design);
var makerRecord = cache.GetAll<Faction>().First(f => f.ShortName == maker);
cache.Upsert(new FactionProductData { Name = name, Design = new CultRecordRef<CraftedItemData>(cache.RefOf(designRecord).Key), Manufacturer = cache.RefOf(makerRecord) });
cache.FlushAsync().Wait();
}
// Sparrow is the Light Laser by Finch. A product of that name is the row only when design and maker both match.
[Theory]
[InlineData("Sparrow", "Light Machine Gun", "Finch")]
[InlineData("Sparrow", "Light Laser", "Zhestokost")]
[InlineData("sparrow", "Light Laser", "Finch")]
public void Apply_refuses_a_name_unless_design_and_maker_both_match_it_ignoring_case(string name, string design, string maker)
{
AddProduct(name, design, maker);
var conflicted = File.ReadAllBytes(CatalogPath);
Assert.Throws<InvalidOperationException>(() => ProductLinesCommand.Run(LineApply, _root));
Assert.Equal(conflicted, File.ReadAllBytes(CatalogPath));
}
[Fact]
public void Apply_refuses_a_row_name_that_is_a_designs_and_writes_nothing()
{
using (var cache = Open())
{
cache.Upsert(new WeaponItemData { Name = "Tripwire" });
cache.FlushAsync().Wait();
}
var conflicted = File.ReadAllBytes(CatalogPath);
Assert.Throws<InvalidOperationException>(() => ProductLinesCommand.Run(LineApply, _root));
Assert.Equal(conflicted, File.ReadAllBytes(CatalogPath));
}
// The command is reached as AetherDb's product-lines word, with the line after it; the shipped catalog holds the line.
[Fact]
public void The_product_lines_word_runs_the_named_line_and_refuses_an_unknown_one()
{
Assert.Equal(0, Program.Main(new[] { "product-lines", "weapons" }));
Assert.Equal(1, Program.Main(new[] { "product-lines", "nonesuch" }));
}
}

View file

@ -112,11 +112,13 @@ public static class ProductLinesCommand
return 0;
}
// ExpectUnchanged lands the batch onto the file as it is: every other record keeps the bytes it has, where a plain
// commit would re-encode the whole catalog through today's types.
// The batch lands onto the file as it is: every other record keeps the bytes it has, where a plain commit would
// re-encode the whole catalog through today's types. What it expects is that each key it authors is still absent, the
// one condition the command's own validation rests on. ExpectUnchanged would compare the file's schema ids with the
// loaded ones and refuse any catalog that holds a record written on an older schema, whatever the batch is.
if (!db.Cache.Commit(batch =>
{
batch.ExpectUnchanged();
foreach (var (row, _, _, _) in missing) batch.Expect(KeyOf(row), null);
foreach (var (row, design, maker, _) in missing)
{
var (mean, dev) = Program.MakerProfiles[row.Maker];