fix: update monitor.status for private location monitors (#2496) master
* fix: update monitor.status for private location monitors Private location monitors were not updating the monitor.status field when checks failed/recovered, causing the dashboard to always show them as 'active' even when failing. The cloud checker updates monitor.status on status transitions, but the private location handler (updateStatusPrivate) only updated the privateLocationMonitorStatus table without touching monitor.status. This fix adds the same monitor.status update logic to all three status transition cases (error, degraded, active) to match the cloud checker behavior. Fixes dashboard status display and 'Failing'/'Normal' counts for private location monitors. * fix: add missing inArray import from drizzle-orm * ci: apply automated fixes * fix: only update monitor status from private locations for private-only monitors * ci: apply automated fixes * feat: add incident creation and resolution for private location monitors * feat: add multi-location threshold logic to private location status updates - Query all private location statuses for a monitor - Require >=50% agreement OR single location before updating monitor.status - Matches cloud checker threshold behavior (affectedCount >= total/2 || total === 1) - Fix redundant null check in hasCloudRegions Addresses Claude review feedback: prevents single location from overwriting monitor.status when multiple locations are attached to a monitor. * test: add coverage for multi-location threshold logic - Add private-only monitor fixture (no cloud regions) - Add 3 private locations for threshold testing - Test 1: Threshold met (2/3 locations agree) → status updates - Test 2: Threshold not met (1/3 location) → status unchanged - Test 3: Cloud+private monitors → status unchanged by private reports Addresses Claude review feedback: ensures new code path has regression tests. * ci: apply automated fixes * fix: use total attached locations for threshold check - Query privateLocationToMonitors to get total ATTACHED locations - Use attachedLocations.length instead of reportedLocations.length - This ensures threshold uses 3 attached locations, not just 1 reported - Also removed invalid autoResolved property from audit log metadata Fixes test failure and TypeScript error. * fix: gate notifications with threshold check - Only trigger notifications when threshold is met - Prevents multiple alerts when locations report below threshold - Applies to alert, degraded, and recovery notifications Fixes test failure: assertSpyCalls expected 1 but got 2 * fix: preserve notification behavior for cloud+private monitors - Changed gate from AND to OR: hasCloudRegions || shouldUpdateMonitorStatus - Cloud+private monitors: always trigger notifications (original behavior) - Private-only monitors: only trigger when threshold met (new behavior) Fixes 4 failing tests that use monitors with cloud regions. * fix: address 5 violations in private location handling V1 (P1): Filter status query to only attached locations - Prevents detached location stale status from counting toward threshold - Added inArray filter on attachedLocationIds V2 (P1): Gate incident creation with threshold check - Only create incidents when threshold met for private-only monitors - Prevents premature incident creation (1/3 errors) V3 (P2): Pass incident ID to notifications - Capture incident ID in error and recovery cases - Pass to triggerNotifications for provider context V4 (P1): Gate incident resolution with threshold check - Only resolve when threshold met and monitor recovered - Prevents premature incident closure (1/3 recovery) Test (P2): Add PRIVATE_ONLY_MONITOR_ID cleanup to afterEach - Prevents test data leakage between tests * fix: resolve compilation errors in private location handler - Move incidentId declaration outside switch to fix redeclaration error - Filter null values from attachedLocationIds for inArray type safety - Fixes TS2451 (redeclaration) and TS2769 (inArray type mismatch) * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>