Back to Source Monitor

PLAN-05 Summary: scraping-and-broadcasting-tests

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

0.13.03.7 KB
Original Source

PLAN-05 Summary: scraping-and-broadcasting-tests

Status: COMPLETE

Commits

  • Hash: e497891

  • Message: test(scraping-broadcasting): close coverage gaps for bulk scraper and broadcaster

  • Files changed: 2 files, 816 insertions (broadcaster_test.rb new, bulk_source_scraper_test.rb extended)

  • Hash: 66b8df2 (tag commit)

  • Message: test(dev-plan05): close coverage gaps for bulk scraper and broadcaster

  • Note: This commit also contained Plan 03 (configuration-tests) work; see PLAN-03-SUMMARY.md.

Tasks Completed

Task 1: Test BulkSourceScraper disabled and invalid selection paths

  • Tested scraping_enabled: false returns error result with failure_details
  • Tested Result struct methods: success?, partial?, error?, rate_limited?
  • Tested normalize_selection with symbol, string, whitespace, uppercase, nil, invalid
  • Tested selection_label with valid and invalid selection values

Task 2: Test BulkSourceScraper batch limiting and determine_status

  • Tested apply_batch_limit respects max_bulk_batch_size from config
  • Tested determine_status returns :success, :partial, :error based on counts
  • Tested determine_status :partial when only already_enqueued > 0
  • Tested without_inflight excludes items with in-flight scrape_status
  • Tested unknown enqueuer status handling

Task 3: Test Broadcaster setup and broadcast_source/broadcast_item

  • Created new test file: test/lib/source_monitor/realtime/broadcaster_test.rb
  • Tested setup! registers after_fetch_completed and after_item_scraped callbacks
  • Tested setup! idempotent (no double-registration)
  • Tested broadcast_source returns early when turbo_available? is false
  • Tested broadcast_source returns early when source is nil after reload
  • Tested broadcast_source calls broadcast_source_row and broadcast_source_show
  • Tested broadcast_item calls Turbo::StreamsChannel with correct target/partial
  • Tested broadcast_item rescues errors and logs them

Task 4: Test Broadcaster toast broadcasting and event handlers

  • Tested broadcast_toast returns early when turbo_available? is false or message blank
  • Tested broadcast_toast calls Turbo::StreamsChannel.broadcast_append_to
  • Tested handle_fetch_completed broadcasts source and toast for each status
  • Tested broadcast_fetch_toast for "fetched", "not_modified", "failed" statuses
  • Tested handle_item_scraped broadcasts item, source, and toast
  • Tested broadcast_item_toast for success and failed statuses

Task 5: Test Broadcaster helpers

  • Tested reload_record returns nil for nil input, original record on reload error
  • Tested turbo_available? true/false based on Turbo::StreamsChannel defined
  • Tested register_callback no double-registration
  • Tested log_error swallows errors from logger itself
  • Tested broadcast_source_row and broadcast_source_show rescue and log errors

Deviations

IDDescriptionImpact
DEVN-01Commit 66b8df2 bundled Plan 03 (configuration) and Plan 05 (scraping/broadcasting) workNo functional impact; both sets of tests pass independently

Verification Results

CheckResult
PARALLEL_WORKERS=1 bin/rails test test/lib/source_monitor/scraping/bulk_source_scraper_test.rb test/lib/source_monitor/realtime/broadcaster_test.rbAll tests pass
bin/rails test760 runs, 2626 assertions, 0 failures, 0 errors, 0 skips

Success Criteria

  • 15 new BulkSourceScraper tests (270 lines) + 35 new Broadcaster tests (546 lines)
  • BulkSourceScraper disabled/invalid/batch/status paths tested
  • Broadcaster setup, broadcasting, toast, and event handlers tested
  • Broadcaster error swallowing and helper methods tested
  • REQ-05 and REQ-06 substantially satisfied