mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
v1.4.15 Phase B2, criterion 3. The status helper introduced in commit4db72a8already trips the dispatcher when the consecutive-failure counter crosses INTEGRATION_FAILURE_ALERT_THRESHOLD (default 3) and the 24h re-alert window has lapsed. This commit: 1. Extracts the message formatter into a pure exported function formatAdminAlertPayload() so the message shape is unit-testable without standing up Prisma + the dispatcher. Same byte-identical output, refactor only. 2. Locks the alert payload contract via 7 focused unit tests: - integration display name uses "Withings" / "moodLog" (not the lowercase storage key) - subjectLabel falls back to userId when no email/label - reauth_required maps to "ask the user to reconnect" - transient maps to "investigate the upstream service" - 4 KB stack traces are trimmed to 280 chars + ellipsis (Telegram cap is 4096; envelope eats ~150 so 280 keeps margin) - errorCode renders as "(503)" suffix on the reason line, or is omitted entirely when undefined (no "(undefined)" leak) - metadata block shapes affectedUserId / integration / consecutiveFailures / errorCode (null when absent) The dispatcher itself is reused as-is — no new sender, no new channel type, no new retry path. B3 owns the dispatcher reliability surface; we are exclusively a caller. Admins who haven't configured Telegram get silently skipped (the dispatcher's documented behaviour). The 24h re-alert window prevents a flapping integration from paging on every failure: alertedAt is stamped on the trip, cleared by the next success, and re-trips only after 24h on the same streak. The flap-resistance is covered by status.test.ts (commit4db72a8) and the integration-status.test.ts case landing in the next commit. Tests: +7 unit (formatAdminAlertPayload) on top of the +16 already guarding the threshold/window state machine. 116 / 890 unit pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>