Product lines: records get keys derived from the product name; two catalog tests stop hard-coding the old seller sets
The command's records now land with a key derived from the product name, so a replay at a merge reproduces the same records. CatalogRoleTests.RenamedDesignsKeepTheirKeysAndProducts asserts the renamed products are among a design's sellers, not all of them; RolesBackfillIsAuthored reads maker profiles from Program.MakerProfiles (plus the Pirates) instead of its own copy, which lacked AU. Catalog commit before this one is stale: the next regenerates it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
58b78f81de
commit
05b262f139
3 changed files with 22 additions and 7 deletions
|
|
@ -172,7 +172,8 @@ public sealed class CatalogRoleTests
|
|||
Assert.Equal(generic, design.Name);
|
||||
Assert.Equal(Program.Renames.Single(r => r.Generic == generic).Functional, design.Description);
|
||||
var products = cache.GetAll<FactionProductData>().Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray();
|
||||
Assert.Equal(sold.Select(p => p.Key).OrderBy(k => k, StringComparer.Ordinal), products.Select(p => cache.RefOf(p).Key.Value).OrderBy(k => k, StringComparer.Ordinal));
|
||||
// Later product lines add sellers to these designs; the renamed designs keep the products they were renamed with.
|
||||
Assert.All(sold, product => Assert.Contains(products, p => cache.RefOf(p).Key.Value == product.Key));
|
||||
foreach (var (key, name, maker) in sold)
|
||||
{
|
||||
var product = products.Single(p => cache.RefOf(p).Key.Value == key);
|
||||
|
|
@ -260,10 +261,7 @@ public sealed class CatalogRoleTests
|
|||
AssertNamed(Design("Muon Fusion Station Reactor"), "Modifier", "core");
|
||||
|
||||
// Each seller's means come from its maker's profile; the Pirates are middling and inconsistent.
|
||||
var profiles = new Dictionary<string, (float Mean, float Dev)>
|
||||
{
|
||||
["Zhestokost"] = (.50f, .08f), ["R&D"] = (.60f, .15f), ["DME"] = (.55f, .20f), ["Lightsail"] = (.55f, .10f), ["Pirates"] = (.45f, .22f),
|
||||
};
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
|
||||
// The rows as the shipped catalog holds them, taken before they are removed from the scratch copy.
|
||||
private readonly string[] _shipped;
|
||||
private readonly string[] _shippedKeys;
|
||||
|
||||
private static string Describe(CultCache cache, FactionProductData product) =>
|
||||
$"{cache.Get(product.Design).Name} | {product.Name} | {cache.Get(product.Manufacturer).ShortName} | {product.Description} | " +
|
||||
|
|
@ -36,6 +37,7 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
var products = cache.GetAll<FactionProductData>().Where(p => Names.Contains(p.Name)).ToArray();
|
||||
Assert.Equal(Names.Length, products.Length);
|
||||
_shipped = products.Select(p => Describe(cache, p)).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
_shippedKeys = products.Select(p => cache.RefOf(p).Key.Value).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
foreach (var product in products) Assert.True(cache.Remove(cache.RefOf(product).Key));
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
|
@ -55,6 +57,12 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
return cache.GetAll<FactionProductData>().Where(p => Names.Contains(p.Name)).Select(p => Describe(cache, p)).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
}
|
||||
|
||||
private string[] Line20Keys()
|
||||
{
|
||||
using var cache = Open();
|
||||
return cache.GetAll<FactionProductData>().Where(p => Names.Contains(p.Name)).Select(p => cache.RefOf(p).Key.Value).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_dry_run_writes_nothing_and_apply_lands_the_shipped_rows_once()
|
||||
{
|
||||
|
|
@ -68,8 +76,10 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
var landed = File.ReadAllBytes(CatalogPath);
|
||||
Assert.NotEqual(before, landed);
|
||||
// Record keys are CultCache's to mint and differ run to run; the rows do not.
|
||||
// The command derives each record's key from the product's name, so applying the table again lands the keys the
|
||||
// shipped catalog holds.
|
||||
Assert.Equal(_shipped, Line20());
|
||||
Assert.Equal(_shippedKeys, Line20Keys());
|
||||
|
||||
// A second apply finds everything authored and writes nothing; so does a dry run.
|
||||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using GameCult.Caching;
|
||||
|
||||
// product-lines <line> [apply] (aetheria-release, cut product-lines-weapons; rulings catalog-grows-generic-designs-branded-products,
|
||||
|
|
@ -48,6 +50,11 @@ public static class ProductLinesCommand
|
|||
// A line's rows, for the catalog tests that check the shipped records against the table the command authors from.
|
||||
internal static IReadOnlyList<Row> Table(string line) => Lines[line];
|
||||
|
||||
// A product's record key is derived from its name, so the same table lands the same records every time it is applied: the
|
||||
// replay at a merge reproduces the branch's blob, and nothing that orders products by key reads a different order after it.
|
||||
private static CultRecordKey KeyOf(Row row) =>
|
||||
new(new Guid(SHA256.HashData(Encoding.UTF8.GetBytes("product-line:" + row.Name)).AsSpan(0, 16)).ToString("N"));
|
||||
|
||||
public static int Run(string[] args, string root = null)
|
||||
{
|
||||
var apply = args.Contains("apply");
|
||||
|
|
@ -120,7 +127,7 @@ public static class ProductLinesCommand
|
|||
Design = db.Cache.RefOf(design),
|
||||
Manufacturer = db.Cache.RefOf(maker),
|
||||
Roles = design.Roles.Select(r => new ProductRole { Role = r.Name, Mean = mean, StandardDeviation = dev }).ToList(),
|
||||
});
|
||||
}, KeyOf(row));
|
||||
}
|
||||
}))
|
||||
throw new InvalidOperationException("The catalog changed while the product line was being authored; nothing was written. Run it again.");
|
||||
|
|
|
|||
Loading…
Reference in a new issue