feat(transport): manifest summary counts + schemaVersion 1.1 (M8 B3)

This commit is contained in:
Joseph Doherty
2026-06-18 05:52:12 -04:00
parent 0e507052a1
commit aefdb9f4b6
3 changed files with 70 additions and 4 deletions
@@ -95,7 +95,15 @@ public sealed class BundleExporter : IBundleExporter
DbConnections: resolved.DatabaseConnections.Count, DbConnections: resolved.DatabaseConnections.Count,
NotificationLists: resolved.NotificationLists.Count, NotificationLists: resolved.NotificationLists.Count,
SmtpConfigs: resolved.SmtpConfigs.Count, SmtpConfigs: resolved.SmtpConfigs.Count,
ApiMethods: resolved.ApiMethods.Count); ApiMethods: resolved.ApiMethods.Count,
// M8 (B3): additive site/dataConnection/instance counts. Sourced from
// the serialized content DTO — the same arrays the importer reads —
// so the manifest summary always matches the packed payload. These
// arrays default to empty until B1/B2 populate them, so the counts
// are 0 today and become correct once those waves land.
Sites: contentDto.Sites.Count,
DataConnections: contentDto.DataConnections.Count,
Instances: contentDto.Instances.Count);
// 4. Build a TEMPLATE manifest. BundleSerializer.Pack re-stamps both // 4. Build a TEMPLATE manifest. BundleSerializer.Pack re-stamps both
// ContentHash and EncryptionMetadata against the bytes it actually // ContentHash and EncryptionMetadata against the bytes it actually
@@ -12,7 +12,12 @@ namespace ZB.MOM.WW.ScadaBridge.Transport.Serialization;
public sealed class ManifestBuilder public sealed class ManifestBuilder
{ {
public const int CurrentBundleFormatVersion = 1; public const int CurrentBundleFormatVersion = 1;
public const string CurrentSchemaVersion = "1.0";
// Schema minor version. Bumped 1.0 → 1.1 in M8 to carry the additive
// site/dataConnection/instance summary counts (and their content arrays).
// Minor bumps are additive-only: ManifestValidator gates solely on
// BundleFormatVersion, so an older "1.0" bundle still validates Ok.
public const string CurrentSchemaVersion = "1.1";
/// <summary> /// <summary>
/// Builds a <see cref="BundleManifest"/> with the current format version, a SHA-256 content hash, /// Builds a <see cref="BundleManifest"/> with the current format version, a SHA-256 content hash,
@@ -14,7 +14,8 @@ public sealed class ManifestBuilderTests
public void Build_populates_summary_from_contents() public void Build_populates_summary_from_contents()
{ {
var sut = new ManifestBuilder(); var sut = new ManifestBuilder();
var summary = new BundleSummary(2, 1, 0, 0, 0, 0, 0, 0); // M8 (B3): summary now carries trailing Sites/DataConnections/Instances counts.
var summary = new BundleSummary(2, 1, 0, 0, 0, 0, 0, 0, Sites: 3, DataConnections: 4, Instances: 5);
var contents = new[] var contents = new[]
{ {
new ManifestContentEntry("Template", "T1", 1, Array.Empty<string>()), new ManifestContentEntry("Template", "T1", 1, Array.Empty<string>()),
@@ -25,12 +26,17 @@ public sealed class ManifestBuilderTests
var manifest = sut.Build("env", "user", "1.0.0", encryption: null, summary, contents, contentBytes: new byte[] { 1, 2, 3 }); var manifest = sut.Build("env", "user", "1.0.0", encryption: null, summary, contents, contentBytes: new byte[] { 1, 2, 3 });
Assert.Equal(summary, manifest.Summary); Assert.Equal(summary, manifest.Summary);
// New M8 summary counts flow through the builder verbatim.
Assert.Equal(3, manifest.Summary.Sites);
Assert.Equal(4, manifest.Summary.DataConnections);
Assert.Equal(5, manifest.Summary.Instances);
Assert.Equal(contents, manifest.Contents); Assert.Equal(contents, manifest.Contents);
Assert.Equal("env", manifest.SourceEnvironment); Assert.Equal("env", manifest.SourceEnvironment);
Assert.Equal("user", manifest.ExportedBy); Assert.Equal("user", manifest.ExportedBy);
Assert.Equal("1.0.0", manifest.ScadaBridgeVersion); Assert.Equal("1.0.0", manifest.ScadaBridgeVersion);
Assert.Equal(1, manifest.BundleFormatVersion); Assert.Equal(1, manifest.BundleFormatVersion);
Assert.Equal("1.0", manifest.SchemaVersion); // M8 (B3): schema minor bumped 1.0 → 1.1; format version stays 1.
Assert.Equal("1.1", manifest.SchemaVersion);
Assert.Null(manifest.Encryption); Assert.Null(manifest.Encryption);
} }
@@ -100,4 +106,51 @@ public sealed class ManifestBuilderTests
Assert.Equal(ManifestValidationResult.Ok, result); Assert.Equal(ManifestValidationResult.Ok, result);
} }
[Fact]
public void Validate_accepts_older_schemaVersion_1_0_manifest()
{
// An older "1.0" bundle (pre-M8) must still import: schema minor differences
// are additive and the validator gates only on BundleFormatVersion.
var bytes = Encoding.UTF8.GetBytes("legacy-bundle");
var hash = "sha256:" + Convert.ToHexString(SHA256.HashData(bytes)).ToLowerInvariant();
var manifest = new BundleManifest(
BundleFormatVersion: ManifestBuilder.CurrentBundleFormatVersion,
SchemaVersion: "1.0",
CreatedAtUtc: DateTimeOffset.UtcNow,
SourceEnvironment: "env",
ExportedBy: "u",
ScadaBridgeVersion: "v",
ContentHash: hash,
Encryption: null,
Summary: EmptySummary,
Contents: NoContents);
var result = new ManifestValidator().Validate(manifest, bytes);
Assert.Equal(ManifestValidationResult.Ok, result);
}
[Fact]
public void Validate_refuses_bundleFormatVersion_2()
{
// A future format-version 2 is a hard refusal (not a minor schema bump).
var bytes = Encoding.UTF8.GetBytes("future-bundle");
var hash = "sha256:" + Convert.ToHexString(SHA256.HashData(bytes)).ToLowerInvariant();
var manifest = new BundleManifest(
BundleFormatVersion: 2,
SchemaVersion: "1.1",
CreatedAtUtc: DateTimeOffset.UtcNow,
SourceEnvironment: "env",
ExportedBy: "u",
ScadaBridgeVersion: "v",
ContentHash: hash,
Encryption: null,
Summary: EmptySummary,
Contents: NoContents);
var result = new ManifestValidator().Validate(manifest, bytes);
Assert.Equal(ManifestValidationResult.UnsupportedFormatVersion, result);
}
} }