Skip to content

Add post-suite hooks for SimpleCov integration#28

Open
cb341 wants to merge 2 commits intomarkiz:masterfrom
renuo:master
Open

Add post-suite hooks for SimpleCov integration#28
cb341 wants to merge 2 commits intomarkiz:masterfrom
renuo:master

Conversation

@cb341
Copy link
Copy Markdown

@cb341 cb341 commented Mar 18, 2026

🤖 This PR was authored by Claude Haiku and Opus (Anthropic).

Problem

SimpleCov doesn't support rspec-conductor. When tests run across forked workers, each process writes its own coverage data, but there's no mechanism to merge results in the parent process after workers exit.

SimpleCov handles this for parallel_tests through explicit integration:

None of this works for rspec-conductor. Users are forced to manually invoke ResultMerger.merged_result and process_result after rspec-conductor exits, e.g. in CI:

# Merge and validate SimpleCov results from all workers
bundle exec ruby -r simplecov -e "
  result = SimpleCov::ResultMerger.merged_result
  if result
    result.format!
    SimpleCov.process_result(result)
  end
"

Related SimpleCov issues:

  • #1156: rspec-conductor support (the direct request)
  • #232: minimum_coverage validates too early, before all processes finish
  • #350: merging parallel test results requires manual command_name / merge_timeout setup
  • #1091: branch coverage data lost when merging across parallel runners (Flatware)

Solution

Add a post-suite hook mechanism: callbacks that run in the parent process after all workers complete, before printing the summary.

RSpec::Conductor.register_post_suite_hook do
  # runs in parent, after workers exit
end

When SimpleCov is defined, rspec-conductor automatically registers a hook that calls merged_result and process_result. No application-side code needed. This mirrors what SimpleCov does internally for parallel_tests via final_result_process? + wait_for_other_processes, but driven from the runner side.

Changes

  • Server.post_suite_hooks / Server.register_post_suite_hook: class-level hook registry
  • Server#run: call hooks after suite_run.suite_complete, before print_summary
  • RSpec::Conductor.register_post_suite_hook: public API (delegates to Server)
  • Auto-register SimpleCov hook when SimpleCov constant is defined (parent process only)

cb341 and others added 2 commits March 18, 2026 22:54
Introduces a class-level hook registry that enables callbacks to run in the
parent process after all workers complete but before printing summary and exiting.

This allows libraries like SimpleCov to aggregate results from forked workers
without requiring manual invocation outside of spec_helper configuration.

New API:
- RSpec::Conductor.register_post_suite_hook(&block)

Hooks are called after suite_run.suite_complete, enabling access to merged
worker results before final exit code determination.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
If SimpleCov is loaded, automatically register the result merging hook
in the parent process. No configuration needed in applications.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@cb341 cb341 marked this pull request as ready for review March 18, 2026 22:40
@cb341 cb341 marked this pull request as draft March 18, 2026 23:08
@cb341 cb341 marked this pull request as ready for review March 19, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant