push: an added anchor keeps its Id (found by the add-on's first Package over push)

This commit is contained in:
soul 2026-11-28 05:09:28 +01:00
commit 964bccdfb2
2 changed files with 14 additions and 1 deletions

View file

@ -119,6 +119,19 @@ public sealed class ShipAuthoringPushTests : IDisposable
Assert.Equal(files, Listing(path));
}
// An anchor the request adds is a whole anchor: the Id is the one the validator and the node binding read.
[Fact]
public void AnAddedAnchorKeepsItsId()
{
var path = Package();
var request = Edit(Open(path), json => ((JArray)json["visual"]["anchors"]).Add(
new JObject { ["id"] = "extra", ["role"] = "map-icon", ["node"] = "extra", ["parent"] = null, ["order"] = 0 }));
var (code, changes, outcome) = Push(path, request, apply: true);
Assert.True(code == 0, outcome.ToString());
Assert.Contains("mod-ship:mod.skiff anchor[extra] added", changes);
Assert.Contains(Parse(Open(path))["visual"]["anchors"], anchor => (string)anchor["id"] == "extra");
}
[Fact]
public void ApplyWritesTheDryRunResult()
{

View file

@ -531,7 +531,7 @@ public static class ShipAuthoringPush
if (string.IsNullOrWhiteSpace(row.Id)) throw new InvalidOperationException("visual: every anchor needs an id.");
if (!seen.Add(row.Id)) throw new InvalidOperationException($"visual: anchor id {row.Id} is used twice.");
// Joint is not authored here and is carried by the anchor's identity; so is its element id.
var target = stored.TryGetValue(row.Id, out var found) ? Copy(found) : new ShipAnchor { ElementId = row.Id };
var target = stored.TryGetValue(row.Id, out var found) ? Copy(found) : new ShipAnchor { Id = row.Id, ElementId = row.Id };
target.Role = row.Role;
target.ModelNodeId = row.Node;
target.ParentId = row.Parent;