.vbw-planning/milestones/03-coverage-analysis-quick-wins-critical-path-test-co/phases/02-critical-path-test-coverage/PLAN-04.md
Close the coverage gaps in lib/source_monitor/dashboard/queries.rb (66 uncovered lines) and lib/source_monitor/analytics/sources_index_metrics.rb (34 uncovered lines). The existing tests cover caching, basic stats, recent_activity events, job_metrics with stub, and upcoming_fetch_schedule groups. This plan targets the remaining uncovered branches: StatsQuery SQL generation and integer_value, RecentActivityQuery's build_event and the three sub-queries, record_metrics branches for each query type, Cache miss/hit paths, SourcesIndexMetrics' fetch_interval_filter with various param combinations, integer_param sanitization, distribution_scope with ransack, and selected_fetch_interval_bucket matching logic.
Decomposition rationale: Dashboard::Queries and SourcesIndexMetrics share a read-only analytics theme and can be covered in a single plan without file conflicts. Their combined gap (100 lines) is manageable in 4 tasks. The queries_test.rb file already has good infrastructure (count_sql_queries helper, setup with delete_all).
Trade-offs considered:
test/lib/source_monitor/dashboard/queries_test.rbbin/rails test test/lib/source_monitor/dashboard/queries_test.rb -n /stats_query|failed_sources|fetches_today|stats_metrics/i exits 0test/lib/source_monitor/dashboard/queries_test.rbbin/rails test test/lib/source_monitor/dashboard/queries_test.rb -n /recent_activity_query|build_event|event_type|event_order/i exits 0test/lib/source_monitor/dashboard/queries_test.rbbin/rails test test/lib/source_monitor/dashboard/queries_test.rb -n /record_metrics|cache_behavior|measure_instrument/i exits 0test/lib/source_monitor/analytics/sources_index_metrics_test.rbbin/rails test test/lib/source_monitor/analytics/sources_index_metrics_test.rb -n /fetch_interval_filter|integer_param|selected_bucket|distribution_scope/i exits 0bin/rails test test/lib/source_monitor/dashboard/queries_test.rb exits 0bin/rails test test/lib/source_monitor/analytics/sources_index_metrics_test.rb exits 0COVERAGE=1 bin/rails test test/lib/source_monitor/dashboard/queries_test.rb test/lib/source_monitor/analytics/sources_index_metrics_test.rb shows both files with >80% branch coveragebin/rails test exits 0 (no regressions)