Back to Source Monitor

PLAN-04 Summary: dashboard-and-analytics-tests

.vbw-planning/milestones/03-coverage-analysis-quick-wins-critical-path-test-co/phases/02-critical-path-test-coverage/PLAN-04-SUMMARY.md

0.13.02.7 KB
Original Source

PLAN-04 Summary: dashboard-and-analytics-tests

Status: COMPLETE

Commits

  • Hash: a8f2611

  • Message: test(dashboard-analytics): close coverage gaps for stats, activity, metrics, cache

  • Files changed: 2 files, 564 insertions (queries_test.rb + sources_index_metrics_test.rb)

  • Hash: 2e50580 (tag commit)

  • Message: test(dev-plan04): dashboard and analytics coverage gaps

  • Note: Continuation/tagging commit for task verification.

Tasks Completed

Task 1: Test StatsQuery SQL branches and integer_value

  • Tested stats returns correct counts with mixed active/inactive sources
  • Tested failed_sources counts OR conditions (failure_count > 0, last_error, last_error_at)
  • Tested fetches_today time boundary (started_at >= start_of_day)
  • Tested stats with empty database returns all zeros
  • Tested record_stats_metrics sets gauge values for all stat keys

Task 2: Test RecentActivityQuery build_event and sub-queries

  • Tested build_event produces Event objects for all 3 types (fetch_log, scrape_log, item)
  • Tested fetch_log events have success based on boolean column
  • Tested scrape_log events include scraper_adapter and source_name via JOIN
  • Tested item events have item_title, item_url, success_flag always 1
  • Tested events ordered by occurred_at DESC with limit
  • Tested record_metrics for :recent_activity sets gauge values

Task 3: Test record_metrics branches and Cache edge cases

  • Tested record_metrics for all 4 case branches (stats, recent_activity, job_metrics, upcoming_fetch_schedule)
  • Tested Cache.fetch returns cached value on second call
  • Tested Cache nil/false storage, array keys, key isolation

Task 4: Test SourcesIndexMetrics edge cases

  • Tested fetch_interval_filter with gteq/lt/lteq combinations
  • Tested integer_param sanitization: blank, non-numeric, valid string
  • Tested selected_fetch_interval_bucket nil-max matching, nil when no filter
  • Tested distribution_scope ransack delegation
  • Tested nil search_params handling

Deviations

None -- plan executed as specified across both target files.

Verification Results

CheckResult
PARALLEL_WORKERS=1 bin/rails test test/lib/source_monitor/dashboard/queries_test.rb test/lib/source_monitor/analytics/sources_index_metrics_test.rbAll tests pass
bin/rails test760 runs, 2626 assertions, 0 failures, 0 errors, 0 skips

Success Criteria

  • 35 new tests added (564 lines across 2 files)
  • StatsQuery SQL branches fully tested
  • RecentActivityQuery event building and sub-queries tested
  • record_metrics branches for all query types tested
  • Cache miss/hit behavior tested
  • SourcesIndexMetrics filter, sanitization, and distribution scope tested
  • REQ-04 and REQ-07 substantially satisfied