From 7eabb82287c16a0fc85fde73245028f2ea369fd4 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 3 Dec 2026 10:12:45 -0500 Subject: [PATCH] fix(config-db): unbound SystemArtifactDeploymentRecord.PerSiteStatus (DEP-3, WP2 task 2.9) PerSiteStatus carries one serialized SiteArtifactResult per site (~155 chars for a clean site, more with error text). The 4000-char cap made Deploy Artifacts over ~25 sites throw on the final save, after every site had applied, so no site was stamped and every retry failed the same way. Mapping is now nvarchar(max); the migration + SQL script follow in their own commit. --- .../Configurations/DeploymentConfiguration.cs | 7 ++- ...ifactDeploymentRecordConfigurationTests.cs | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests/Configurations/SystemArtifactDeploymentRecordConfigurationTests.cs diff --git a/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Configurations/DeploymentConfiguration.cs b/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Configurations/DeploymentConfiguration.cs index 0c2ba2fe..453f8f10 100644 --- a/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Configurations/DeploymentConfiguration.cs +++ b/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Configurations/DeploymentConfiguration.cs @@ -113,8 +113,11 @@ public class SystemArtifactDeploymentRecordConfiguration : IEntityTypeConfigurat .IsRequired() .HasMaxLength(200); - builder.Property(d => d.PerSiteStatus) - .HasMaxLength(4000); + // DEP-3: unbounded. One serialized SiteArtifactResult per site (identifier, name, + // error text, removed secret names) is ~155 chars for a clean site, so 4000 ran + // out at ~25 sites (fewer with long errors) — and that save runs AFTER every site + // has applied the artifacts, so the run failed with nothing stamped. + builder.Property(d => d.PerSiteStatus); builder.HasIndex(d => d.DeployedAt); } diff --git a/tests/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests/Configurations/SystemArtifactDeploymentRecordConfigurationTests.cs b/tests/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests/Configurations/SystemArtifactDeploymentRecordConfigurationTests.cs new file mode 100644 index 00000000..61634bee --- /dev/null +++ b/tests/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests/Configurations/SystemArtifactDeploymentRecordConfigurationTests.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore; +using ZB.MOM.WW.ScadaBridge.Commons.Entities.Deployment; + +namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests.Configurations; + +/// +/// DEP-3 (WP2 task 2.9): SystemArtifactDeploymentRecord.PerSiteStatus holds one +/// serialized result per site (~155 chars for a clean site, far more with error text), so a +/// 4000-character cap made Deploy Artifacts over ~25 sites fail AFTER every site had applied, +/// with nothing stamped. The column is unbounded (nvarchar(max)). +/// +public class SystemArtifactDeploymentRecordConfigurationTests : IDisposable +{ + private readonly ScadaBridgeDbContext _context = SqliteTestHelper.CreateInMemoryContext(); + + /// Releases the resources held by this test class. + public void Dispose() + { + _context.Database.CloseConnection(); + _context.Dispose(); + } + + /// The PerSiteStatus property has no maximum length. + [Fact] + public void PerSiteStatus_IsUnbounded() + { + var property = _context.Model.FindEntityType(typeof(SystemArtifactDeploymentRecord))! + .FindProperty(nameof(SystemArtifactDeploymentRecord.PerSiteStatus))!; + + Assert.Null(property.GetMaxLength()); + } + + /// A status payload well past the old 4000-character cap round-trips intact. + /// A task that represents the asynchronous operation. + [Fact] + public async Task PerSiteStatus_LargePayload_RoundTrips() + { + var status = new string('x', 20_000); + var record = new SystemArtifactDeploymentRecord("Artifacts", "alice") { PerSiteStatus = status }; + _context.SystemArtifactDeploymentRecords.Add(record); + await _context.SaveChangesAsync(); + _context.ChangeTracker.Clear(); + + var loaded = await _context.SystemArtifactDeploymentRecords.FindAsync(record.Id); + Assert.Equal(status, loaded!.PerSiteStatus); + } +}