From 0e89007733fec6d12b8dc76ac789f982993a91f5 Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Thu, 25 Jun 2026 17:50:11 -0400 Subject: [PATCH] Generate codecov-result.json for CI Codecov uploads were failing with "Found 0 coverage files to report" because coverage/codecov-result.json was never written. The test workers run with DEFER_COVERAGE set, which swaps in the minimal SimpleFormatter, so SimpleCov::Formatter::Codecov never runs during the test processes. The finalize task test:coverage_gaps merged the results but never invoked the Codecov formatter, so no file existed for the pinned CLI to upload. This commit modifies the test process so, when running in CI, we write coverage/codecov-result.json from the merged result in test:coverage_gaps. We call the gem's inner Codecov::SimpleCov::Formatter directly rather than SimpleCov::Formatter::Codecov, since the latter also invokes the gem's deprecated built-in network uploader; we upload separately with a pinned, hash-verified CLI and want only the file-writing half. Co-Authored-By: David A. Wheeler Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: David A. Wheeler --- lib/tasks/default.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tasks/default.rake b/lib/tasks/default.rake index 199557877..df919fe09 100644 --- a/lib/tasks/default.rake +++ b/lib/tasks/default.rake @@ -954,6 +954,22 @@ task 'test:coverage_gaps' do puts "Combined Coverage: #{result.covered_percent.round(2)}%" + # In CI, write coverage/codecov-result.json from the merged result so the + # Codecov CLI (see .circleci/config.yml) has a file to upload. This MUST + # happen here, not in test_helper.rb: the test workers run with + # DEFER_COVERAGE set, which swaps in the minimal SimpleFormatter, so the + # Codecov formatter never runs during the test processes. The merged + # result is only complete once all parallel + system test runs finish. + # + # We call the gem's inner Codecov::SimpleCov::Formatter directly rather + # than SimpleCov::Formatter::Codecov, because the latter also invokes the + # gem's deprecated built-in network uploader. We upload separately with a + # pinned, hash-verified CLI, so we want ONLY the file-writing half here. + if ENV['CI'] + require 'codecov' + Codecov::SimpleCov::Formatter.new.format(result) + end + # Iterate through files using SimpleCov's own 'missed_lines' logic # to report what we missed. gaps_found = false