fix(auditlog): truncate over-width SiteCalls.LastError on the cached-telemetry dual-write and the reconciliation pull (review 2026-10-21 follow-up)
This commit is contained in:
@@ -274,6 +274,45 @@ public class GrpcPullSiteCallsClientTests
|
||||
Assert.False(result.MoreAvailable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Review 2026-10-21 follow-up: a pulled LastError longer than the central SiteCalls column
|
||||
/// is truncated to the column width, so the reconciliation upsert cannot fail with SQL 8152.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task PullAsync_truncates_over_width_last_error_to_the_column_width()
|
||||
{
|
||||
var proto = new ProtoPullResponse();
|
||||
var dto = Dto(Guid.NewGuid(), BaseTime);
|
||||
dto.LastError = new string('e', 5000);
|
||||
proto.Operationals.Add(dto);
|
||||
|
||||
var sut = new GrpcPullSiteCallsClient(
|
||||
new StaticEnumerator(new SiteEntry("site-a", "http://site-a:8083")),
|
||||
FakeInvoker.Returning(proto),
|
||||
NullLogger<GrpcPullSiteCallsClient>.Instance);
|
||||
|
||||
var result = await sut.PullAsync("site-a", BaseTime, afterId: null, batchSize: 256, CancellationToken.None);
|
||||
|
||||
Assert.Equal(SiteCallColumnBounds.LastErrorMaxLength, Assert.Single(result.SiteCalls).LastError!.Length);
|
||||
}
|
||||
|
||||
/// <summary>A surrogate pair straddling the cut is never split; short values pass through untouched.</summary>
|
||||
[Fact]
|
||||
public void SiteCallColumnBounds_Clamp_KeepsSurrogatePairsWhole_AndLeavesShortValuesAlone()
|
||||
{
|
||||
static ZB.MOM.WW.ScadaBridge.Commons.Entities.Audit.SiteCall Call(string lastError) =>
|
||||
SiteCallDtoMapper.FromDto(Dto(Guid.NewGuid(), BaseTime)) with { LastError = lastError };
|
||||
|
||||
var shortCall = Call("boom");
|
||||
Assert.Same(shortCall, SiteCallColumnBounds.Clamp(shortCall));
|
||||
|
||||
var straddle = new string('a', SiteCallColumnBounds.LastErrorMaxLength - 2) + "\U0001F600" + "tail";
|
||||
var clamped = SiteCallColumnBounds.Clamp(Call(straddle)).LastError!;
|
||||
Assert.True(clamped.Length <= SiteCallColumnBounds.LastErrorMaxLength);
|
||||
Assert.False(char.IsHighSurrogate(clamped[^1]));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that PullAsync with a MinValue unspecified-kind cursor does not throw and still dials the site.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user