ship-authoring push: refuse a blank hull name, judge any named or stored kind, builders read no verdict so price and stats need no catalog
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7516aacb06
commit
6518f260a2
3 changed files with 55 additions and 6 deletions
|
|
@ -427,6 +427,8 @@ public sealed class ShipAuthoringPushTests : IDisposable
|
|||
Assert.Equal((string)Parse(opened)["versions"]["mod-ship:mod.skiff"], (string)reopened["versions"]["mod-ship:mod.skiff"]);
|
||||
Assert.NotEqual((string)Parse(opened)["versions"]["mod-hull:mod.skiff"], (string)reopened["versions"]["mod-hull:mod.skiff"]);
|
||||
|
||||
RefusedUntouched(path, Edit(Open(path), json => Hull(json)["name"] = ""), "name");
|
||||
RefusedUntouched(path, Edit(Open(path), json => Hull(json)["name"] = " "), "name");
|
||||
RefusedUntouched(path, Edit(Open(path), json => Hull(json)["price"] = -1), "price");
|
||||
RefusedUntouched(path, Edit(Open(path), json => Hull(json)["price"] = 1.5), "price");
|
||||
RefusedUntouched(path, Edit(Open(path), json => Hull(json)["mass"] = -1), "mass");
|
||||
|
|
@ -612,4 +614,48 @@ public sealed class ShipAuthoringPushTests : IDisposable
|
|||
var ship = Package();
|
||||
RefusedUntouched(ship, Edit(Open(ship), json => Hull(json)["kind"] = "station-kind:depot"), "only a station hull has one");
|
||||
}
|
||||
|
||||
// A stored kind that names no station kind is never passed as fine: it is judged whenever the request or the hull names one,
|
||||
// by push and by the kind command alike.
|
||||
[Fact]
|
||||
public void AnInvalidStoredKindIsNeverAccepted()
|
||||
{
|
||||
Catalog();
|
||||
var target = Path.Combine(ShipFixture.WritePackage(Mods, "probe.bad", "Probe Bad", tweak: ship =>
|
||||
{
|
||||
ship.Hull.HullType = HullType.Station;
|
||||
ship.Hull.Kind = new CultRecordRef<StationKindData>(StationKindData.KeyOf("nowhere"));
|
||||
}), "ship.cc");
|
||||
var before = File.ReadAllBytes(target);
|
||||
var (code, _, error) = Command("kind", target, "nowhere");
|
||||
Assert.Equal(1, code);
|
||||
Assert.Contains("names no station kind", error);
|
||||
RefusedUntouched(target, Edit(Open(target), json => Hull(json)["mass"] = 11), "names no station kind");
|
||||
Assert.Equal(before, File.ReadAllBytes(target));
|
||||
}
|
||||
|
||||
// price and stats on a valid product package need no shipped catalog: it is opened only for a product's maker or a kind.
|
||||
[Fact]
|
||||
public void PriceAndStatsNeedNoGameData()
|
||||
{
|
||||
var path = Path.Combine(ShipFixture.WritePackage(Mods, "probe.sold", "Probe Sold"), "ship.cc");
|
||||
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
||||
{
|
||||
ShipAuthoringStore.WriteProduct(cache, "probe.sold", new FactionProductData
|
||||
{
|
||||
Name = "Sold",
|
||||
Design = new CultRecordRef<CraftedItemData>(ShipModCatalog.HullKey("probe.sold")),
|
||||
Manufacturer = new CultRecordRef<Faction>(new CultRecordKey("faction:maker"))
|
||||
});
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Assert.False(File.Exists(Path.Combine(_root.Path, "GameData", "Aetheria.cc")));
|
||||
var (code, _, error) = Command("price", path, "300");
|
||||
Assert.True(code == 0, error);
|
||||
(code, _, error) = Command("stats", path, "--mass", "7", "--top-speed", "33");
|
||||
Assert.True(code == 0, error);
|
||||
var (hull, _, products) = ShipAuthoringStore.Load(path);
|
||||
Assert.Equal((300, 7f), (hull.Price, hull.Mass));
|
||||
Assert.Single(products);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ public static class ShipAuthoringCommands
|
|||
ShipAuthoringPush.Request request;
|
||||
using (var cache = ShipAuthoringStore.Open(path)) request = ShipAuthoringPush.Opened(cache, path);
|
||||
edit(request);
|
||||
var result = ShipAuthoringPush.Run(path, request, apply: true);
|
||||
var result = ShipAuthoringPush.Run(path, request, apply: true, judge: false);
|
||||
if (result.Outcome == "refused") throw new InvalidOperationException(result.Message);
|
||||
if (result.Outcome == "stale")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -217,8 +217,8 @@ public static class ShipAuthoringPush
|
|||
}
|
||||
|
||||
// The one core: push and the builders both come here. A refusal leaves the file untouched (Code 1, Message); a stale
|
||||
// record writes nothing (Code 2).
|
||||
internal static Result Run(string path, Request request, bool apply)
|
||||
// record writes nothing (Code 2). Push judges the derived package (judge); the builders do not.
|
||||
internal static Result Run(string path, Request request, bool apply, bool judge = true)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
|
|
@ -259,7 +259,8 @@ public static class ShipAuthoringPush
|
|||
var written = productWrites.ToDictionary(write => write.Key.Value, StringComparer.Ordinal);
|
||||
var judged = products.Where(product => !written.ContainsKey(ShipModCatalog.ProductKey(ship.Id, product.Manufacturer.Key).Value))
|
||||
.Concat(productWrites.Where(write => write.Derived != null).Select(write => (FactionProductData)write.Derived)).ToArray();
|
||||
result.Verdict = Verdict(path, newHull, newShip, judged);
|
||||
// A builder reports its own line and reads no verdict, so a plain stats or price write never opens the shipped catalog.
|
||||
if (judge) result.Verdict = Verdict(path, newHull, newShip, judged);
|
||||
|
||||
// A record the request carries a version for is expected as that instance; one it carries none for (a product it
|
||||
// did not open) is expected absent.
|
||||
|
|
@ -335,6 +336,7 @@ public static class ShipAuthoringPush
|
|||
if (section.Price < 0) throw new InvalidOperationException("hull: price must be a whole number of at least 0.");
|
||||
foreach (var (field, value) in new[] { ("mass", section.Mass), ("durability", section.Durability), ("armor", section.Armor), ("drag", section.Drag) })
|
||||
if (!(value >= 0) || float.IsInfinity(value)) throw new InvalidOperationException($"hull: {field} must be finite and at least 0.");
|
||||
if (string.IsNullOrWhiteSpace(section.Name)) throw new InvalidOperationException("hull: name must not be blank.");
|
||||
derived.Name = section.Name;
|
||||
derived.Price = section.Price;
|
||||
derived.Mass = section.Mass;
|
||||
|
|
@ -356,8 +358,9 @@ public static class ShipAuthoringPush
|
|||
limits[0].TopSpeed.Min = limits[0].TopSpeed.Max = speed;
|
||||
}
|
||||
derived.Kind = string.IsNullOrEmpty(section.Kind) ? default : new CultRecordRef<StationKindData>(new CultRecordKey(section.Kind));
|
||||
// Only a changed kind is judged here, so a kindless station draft still takes stats and price; the verdict judges the package.
|
||||
if (KindText(derived) != KindText(held))
|
||||
// A kind is judged whenever the request or the stored hull names one, so an invalid stored kind is never passed as fine; a
|
||||
// kindless draft that stays kindless is not, so it still takes stats and price (and needs no catalog).
|
||||
if (derived.Kind.IsSet() || held.Kind.IsSet())
|
||||
using (var catalog = AetherDb.Open().Cache)
|
||||
if (StationKinds.HullKindFault(catalog, derived) is { } fault) throw new InvalidOperationException($"{shipId}: {fault}");
|
||||
FlatDiff(lines, key, HullFields(held), HullFields(derived));
|
||||
|
|
|
|||
Loading…
Reference in a new issue