fix(options): eager startup validation for AuditLog central sub-options — PartitionMaintenance, Purge, Reconciliation (plan R2-08 T6, arch-review 08r2 NF4)

This commit is contained in:
Joseph Doherty
2026-07-13 10:39:03 -04:00
parent e0dddac0be
commit f85f036b09
7 changed files with 241 additions and 6 deletions
@@ -0,0 +1,41 @@
using ZB.MOM.WW.ScadaBridge.AuditLog.Central;
namespace ZB.MOM.WW.ScadaBridge.AuditLog.Tests.Central;
/// <summary>
/// Eager startup validation for <see cref="AuditLogPartitionMaintenanceOptions"/>
/// (arch-review 08 round 2 NF4). A zero tick interval spins the maintenance
/// hosted service; a zero look-ahead leaves the partition function without a
/// future monthly boundary, risking inserts into the unbounded tail partition.
/// </summary>
public class AuditLogPartitionMaintenanceOptionsValidatorTests
{
[Fact]
public void DefaultOptions_AreValid()
{
var validator = new AuditLogPartitionMaintenanceOptionsValidator();
Assert.True(validator.Validate(null, new AuditLogPartitionMaintenanceOptions()).Succeeded);
}
[Fact]
public void ZeroIntervalSeconds_Fails()
{
var validator = new AuditLogPartitionMaintenanceOptionsValidator();
var result = validator.Validate(null,
new AuditLogPartitionMaintenanceOptions { IntervalSeconds = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(AuditLogPartitionMaintenanceOptions.IntervalSeconds), StringComparison.Ordinal));
}
[Fact]
public void ZeroLookaheadMonths_Fails()
{
var validator = new AuditLogPartitionMaintenanceOptionsValidator();
var result = validator.Validate(null,
new AuditLogPartitionMaintenanceOptions { LookaheadMonths = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(AuditLogPartitionMaintenanceOptions.LookaheadMonths), StringComparison.Ordinal));
}
}
@@ -0,0 +1,53 @@
using ZB.MOM.WW.ScadaBridge.AuditLog.Central;
namespace ZB.MOM.WW.ScadaBridge.AuditLog.Tests.Central;
/// <summary>
/// Eager startup validation for <see cref="AuditLogPurgeOptions"/>
/// (arch-review 08 round 2 NF4). The class self-clamps at resolve time, but a
/// plainly-wrong config (zero cadence, zero batch, zero command timeout) should
/// still fail the boot so the operator learns immediately.
/// <see cref="AuditLogPurgeOptions.IntervalOverride"/> is test-only and left
/// unvalidated.
/// </summary>
public class AuditLogPurgeOptionsValidatorTests
{
[Fact]
public void DefaultOptions_AreValid()
{
var validator = new AuditLogPurgeOptionsValidator();
Assert.True(validator.Validate(null, new AuditLogPurgeOptions()).Succeeded);
}
[Fact]
public void ZeroIntervalHours_Fails()
{
var validator = new AuditLogPurgeOptionsValidator();
var result = validator.Validate(null, new AuditLogPurgeOptions { IntervalHours = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(AuditLogPurgeOptions.IntervalHours), StringComparison.Ordinal));
}
[Fact]
public void ZeroChannelPurgeBatchSize_Fails()
{
var validator = new AuditLogPurgeOptionsValidator();
var result = validator.Validate(null,
new AuditLogPurgeOptions { ChannelPurgeBatchSizeConfigured = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(AuditLogPurgeOptions.ChannelPurgeBatchSizeConfigured), StringComparison.Ordinal));
}
[Fact]
public void ZeroMaintenanceCommandTimeout_Fails()
{
var validator = new AuditLogPurgeOptionsValidator();
var result = validator.Validate(null,
new AuditLogPurgeOptions { MaintenanceCommandTimeoutMinutes = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(AuditLogPurgeOptions.MaintenanceCommandTimeoutMinutes), StringComparison.Ordinal));
}
}
@@ -0,0 +1,54 @@
using ZB.MOM.WW.ScadaBridge.AuditLog.Central;
namespace ZB.MOM.WW.ScadaBridge.AuditLog.Tests.Central;
/// <summary>
/// Eager startup validation for <see cref="SiteAuditReconciliationOptions"/>
/// (arch-review 08 round 2 NF4). A zero tick interval spins the reconciliation
/// singleton, a zero batch pulls nothing, and a zero stalled-cycle threshold
/// would fire the stalled signal on the first non-draining cycle.
/// <see cref="SiteAuditReconciliationOptions.ReconciliationIntervalOverride"/>
/// is test-only and left unvalidated.
/// </summary>
public class SiteAuditReconciliationOptionsValidatorTests
{
[Fact]
public void DefaultOptions_AreValid()
{
var validator = new SiteAuditReconciliationOptionsValidator();
Assert.True(validator.Validate(null, new SiteAuditReconciliationOptions()).Succeeded);
}
[Fact]
public void ZeroReconciliationInterval_Fails()
{
var validator = new SiteAuditReconciliationOptionsValidator();
var result = validator.Validate(null,
new SiteAuditReconciliationOptions { ReconciliationIntervalSeconds = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(SiteAuditReconciliationOptions.ReconciliationIntervalSeconds), StringComparison.Ordinal));
}
[Fact]
public void ZeroBatchSize_Fails()
{
var validator = new SiteAuditReconciliationOptionsValidator();
var result = validator.Validate(null,
new SiteAuditReconciliationOptions { BatchSize = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(SiteAuditReconciliationOptions.BatchSize), StringComparison.Ordinal));
}
[Fact]
public void ZeroStalledCycles_Fails()
{
var validator = new SiteAuditReconciliationOptionsValidator();
var result = validator.Validate(null,
new SiteAuditReconciliationOptions { StalledAfterNonDrainingCycles = 0 });
Assert.False(result.Succeeded);
Assert.Contains(result.Failures!,
f => f.Contains(nameof(SiteAuditReconciliationOptions.StalledAfterNonDrainingCycles), StringComparison.Ordinal));
}
}