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:
Joseph Doherty
2026-10-22 09:52:17 -04:00
parent 89d8568fdf
commit 7be22d2ac2
6 changed files with 121 additions and 4 deletions
@@ -160,6 +160,37 @@ public class AuditLogIngestActorCombinedTelemetryTests : TestKit, IClassFixture<
Assert.Equal(siteCall.Status, siteCallRow!.Status);
}
/// <summary>
/// Review 2026-10-21 follow-up: a site LastError longer than the central
/// <c>SiteCalls.LastError</c> column (nvarchar(1024)) used to fail the dual-write with SQL
/// 8152 — the audit row was reported Rejected and the SiteCalls row was never upserted. The
/// ingest now truncates it to the column width, so both rows land.
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[SkippableFact]
public async Task Receive_OverWidthLastError_IsTruncated_BothRowsLand()
{
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
var siteId = NewSiteId();
var (audit, siteCall) = NewEntry(siteId);
siteCall = siteCall with { LastError = new string('x', 5000) };
var actor = CreateActor(BuildServiceProvider());
actor.Tell(
new IngestCachedTelemetryCommand(new[] { new CachedTelemetryEntry(audit, siteCall) }),
TestActor);
var reply = ExpectMsg<IngestCachedTelemetryReply>(TimeSpan.FromSeconds(15));
Assert.Equal(new[] { audit.EventId }, reply.AcceptedEventIds);
Assert.Empty(reply.RejectedEventIds);
await using var read = CreateReadContext();
var siteCallRow = await read.Set<SiteCall>()
.SingleAsync(s => s.TrackedOperationId == siteCall.TrackedOperationId);
Assert.Equal(SiteCallColumnBounds.LastErrorMaxLength, siteCallRow.LastError!.Length);
}
/// <summary>Verifies that a duplicate event id with an unchanged status is a no-op that leaves the row counts unchanged and still acknowledges the id.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[SkippableFact]