fix(transport): import diff compares secrets and bindings; preview honours the name map; CI lookups; area paths; no Rename where unsupported (TRN-2, TRN-3, TRN-6, TRN-7, TRN-8, TRN-9, WP2 tasks 2.4+2.5)

2.4 — ArtifactDiff:
- TRN-2: secret-bearing values (data-connection primary/backup config, DB
  connection string, external-system auth, SMTP credentials, SMS token) are
  compared by SHA-256 and reported value-free as <present> -> <changed>, so a
  changed endpoint no longer reads Identical and is force-skipped.
- TRN-6: the instance diff resolves each existing binding's DataConnectionId to
  its name and compares it (a rebind OPC1 -> OPC2 is Modified); State is no
  longer compared (the import never carries a live state).

2.5 — BundleImporter / ManagementActor / Central UI:
- TRN-3: PreviewAsync takes an optional BundleNameMap (additive optional param);
  under a MapToExisting redirect the connection/instance diffs, connection
  auto-match and unresolved-connection blocker run against the mapped target.
  The CLI import path passes its explicit --map-site/--map-connection redirects
  to the preview before the blocker gate; the Central UI re-runs the preview
  under the Map-step choices at Confirm. Apply binds a CreateNew site/connection
  whose identifier/name already exists to that row instead of inserting a
  duplicate the unique index rejects.
- TRN-7: connection, instance, instance-template and composition/base-template
  lookups match exact spelling first, then case-insensitively.
- TRN-8: InstanceDto gains the additive AreaPath (root->leaf); the exporter
  fills it and the importer resolves/creates areas level by level under their
  real parent. A legacy leaf-only bundle with an ambiguous leaf resolves
  deterministically and adds an ImportResult warning.
- TRN-9: Rename is rejected by ApplyAsync for Site, DataConnection,
  SmtpConfiguration and SmsConfiguration (ImportRenameSupport); the UI does not
  offer it there and the CLI rename policy falls back to Skip with a warning.

Also moves a doc comment misplaced by the 2.6 commit. Reflection round-trip
guard (RoundTripEquivalenceTests) re-run: green.
This commit is contained in:
Joseph Doherty
2026-12-03 10:11:07 -05:00
parent cbdd9fc40b
commit baecf10fea
16 changed files with 1391 additions and 169 deletions
@@ -4426,7 +4426,8 @@ public class ManagementActorTests : TestKit, IDisposable
Manifest = null!,
ExpiresAt = DateTimeOffset.UtcNow.AddMinutes(5),
});
importer.PreviewAsync(sessionId, Arg.Any<CancellationToken>())
// TRN-3: the preview may run under the operator's explicit redirects, so match any map.
importer.PreviewAsync(sessionId, Arg.Any<CancellationToken>(), Arg.Any<Commons.Types.Transport.BundleNameMap?>())
.Returns(new Commons.Types.Transport.ImportPreview(
sessionId,
Array.Empty<Commons.Types.Transport.ImportPreviewItem>(),
@@ -4449,6 +4450,87 @@ public class ManagementActorTests : TestKit, IDisposable
return (sessionId, () => captured);
}
/// <summary>
/// TRN-3: an explicit --map-site / --map-connection redirect reaches the PREVIEW, so its
/// unresolved-connection blockers and auto-matches are computed against the mapped target.
/// </summary>
[Fact]
public void ImportBundleCommand_ExplicitRedirects_ArePassedToThePreview()
{
var (_, importer) = AddBundleSubstitutes();
var (sessionId, _) = ConfigureImportForMapping(
importer,
new[] { new Commons.Types.Transport.RequiredSiteMapping("site-a", "Site A", AutoMatchTargetIdentifier: null) },
new[] { new Commons.Types.Transport.RequiredConnectionMapping("site-a", "OPC1", AutoMatchTargetName: null) });
Commons.Types.Transport.BundleNameMap? previewMap = null;
importer.When(i => i.PreviewAsync(sessionId, Arg.Any<CancellationToken>(),
Arg.Any<Commons.Types.Transport.BundleNameMap?>()))
.Do(ci => previewMap = ci.ArgAt<Commons.Types.Transport.BundleNameMap?>(2));
var cmd = new ImportBundleCommand(
Convert.ToBase64String(new byte[] { 0x01 }), null, "overwrite",
SiteMappings: new[] { new SiteMappingSpec("site-a", "site-x") },
ConnectionMappings: new[] { new ConnectionMappingSpec("site-a", "OPC1", "OPC1") });
CreateActor().Tell(Envelope(cmd, "Administrator"));
ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
Assert.NotNull(previewMap);
var site = Assert.Single(previewMap!.Sites);
Assert.Equal(("site-a", Commons.Types.Transport.MappingAction.MapToExisting, "site-x"),
(site.SourceSiteIdentifier, site.Action, site.TargetSiteIdentifier));
Assert.Equal("OPC1", Assert.Single(previewMap.Connections).TargetConnectionName);
}
/// <summary>
/// TRN-9: --conflict-policy rename falls back to Skip (with a warning) for a site, data
/// connection, SMTP or SMS configuration, and still renames a template.
/// </summary>
[Fact]
public void ImportBundleCommand_RenamePolicy_FallsBackToSkipForUnsupportedTypes()
{
var (_, importer) = AddBundleSubstitutes();
var sessionId = Guid.NewGuid();
importer.LoadAsync(Arg.Any<Stream>(), Arg.Any<string?>(), Arg.Any<CancellationToken>(), Arg.Any<string?>())
.Returns(new Commons.Types.Transport.BundleSession
{
SessionId = sessionId,
Manifest = null!,
ExpiresAt = DateTimeOffset.UtcNow.AddMinutes(5),
});
Commons.Types.Transport.ImportPreviewItem Modified(string type, string name) =>
new(type, name, null, null, Commons.Types.Transport.ConflictKind.Modified, "{}", null);
importer.PreviewAsync(sessionId, Arg.Any<CancellationToken>(), Arg.Any<Commons.Types.Transport.BundleNameMap?>())
.Returns(new Commons.Types.Transport.ImportPreview(sessionId, new[]
{
Modified("SmtpConfiguration", "smtp.example.com"),
Modified("Template", "Pump"),
}));
IReadOnlyList<Commons.Types.Transport.ImportResolution>? captured = null;
importer.ApplyAsync(
Arg.Any<Guid>(),
Arg.Do<IReadOnlyList<Commons.Types.Transport.ImportResolution>>(r => captured = r),
Arg.Any<string>(),
Arg.Any<CancellationToken>(),
Arg.Any<Commons.Types.Transport.BundleNameMap?>())
.Returns(new Commons.Types.Transport.ImportResult(
BundleImportId: Guid.NewGuid(),
Added: 0, Overwritten: 0, Skipped: 1, Renamed: 1,
StaleInstanceIds: Array.Empty<int>(),
AuditEventCorrelation: "correlation"));
CreateActor().Tell(Envelope(
new ImportBundleCommand(Convert.ToBase64String(new byte[] { 0x01 }), null, "rename"), "Administrator"));
var success = ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
Assert.NotNull(captured);
var smtp = captured!.Single(r => r.EntityType == "SmtpConfiguration");
Assert.Equal(Commons.Types.Transport.ResolutionAction.Skip, smtp.Action);
Assert.Null(smtp.RenameTo);
var template = captured.Single(r => r.EntityType == "Template");
Assert.Equal(Commons.Types.Transport.ResolutionAction.Rename, template.Action);
Assert.Contains("Rename is not supported", success.JsonData);
}
/// <summary>Verifies that import bundle command, when explicit spec, overrides auto match.</summary>
[Fact]
public void ImportBundleCommand_ExplicitSpec_OverridesAutoMatch()