Render unknown for a zero CreatedAt in Slack/Mattermost messages (closes #298)
All checks were successful
check / check (push) Successful in 3m9s

FormatSlackMessage rendered the Timestamp line unconditionally, so a
reaped-row fallback delivery carried "0001-01-01T00:00:00Z" -- the
exact string #257 was filed
against, indistinguishable from that regression. When
event.CreatedAt.IsZero(), render "unknown" instead; a real CreatedAt
still renders as RFC3339.
This commit is contained in:
2026-08-24 15:46:50 +00:00
parent 5976a4a98f
commit d5bebb8408
2 changed files with 41 additions and 1 deletions

View File

@@ -365,6 +365,41 @@ func TestFormatSlackMessageOverTaskReconstructedEvent(
)
}
// TestFormatSlackMessageZeroTimestamp asserts the rendering choice
// directly, without going through the engine: a zero CreatedAt (the
// shape a reaped-row fallback produces) renders as "unknown" rather
// than the year-1 zero time, while a real CreatedAt still renders as
// RFC3339.
func TestFormatSlackMessageZeroTimestamp(t *testing.T) {
t.Parallel()
zeroEvent := database.Event{
Method: http.MethodPost,
ContentType: testContentType,
Body: tsEventBody,
}
zeroText := delivery.FormatSlackMessage(&zeroEvent)
assert.NotContains(t, zeroText, "0001-01-01",
"slack message carries the zero-time year",
)
assert.Contains(t, zeroText, "*Timestamp:* `unknown`",
"slack message does not mark an unset receipt time as unknown",
)
nonZeroEvent := zeroEvent
nonZeroEvent.CreatedAt = tsEventCreatedAt()
nonZeroText := delivery.FormatSlackMessage(&nonZeroEvent)
assert.Contains(t, nonZeroText,
"*Timestamp:* `"+
tsEventCreatedAt().UTC().Format(time.RFC3339)+"`",
"slack message does not render a real receipt time as RFC3339",
)
}
// TestEventReconstructionSurvivesAReapedRow pins the fallback: an
// event row reaped by retention while its delivery still holds the
// body inline is still delivered, with the receipt time unset,