From 3df113bb6bcfa9ebe2f22048893a195989cdab55 Mon Sep 17 00:00:00 2001 From: TristanKruse Date: Mon, 26 Oct 2026 11:02:04 +0100 Subject: [PATCH] Enforce coverage thresholds on runtime library files only --- CHANGELOG.md | 2 ++ CONTRIBUTING.md | 7 ++++++- spec/ci/coverage_scope_spec.rb | 37 ++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 3 +++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 spec/ci/coverage_scope_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc8edc..68c7178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ - Reuse source-entry file status instead of repeating separate directory and file probes. - Validate version/changelog/lock consistency in CI and require prepared release metadata before RubyGems publication. +- Enforce the unchanged coverage thresholds on runtime library source only, with a real-report + regression check that excludes loaded specs, benchmarks, and scripts from the denominator. - Apply bounded project-root `.archignore` exclusions consistently to dependency graphs and metrics, with cache invalidation, cross-platform glob handling, and configuration safety checks. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4592879..88bdeac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,12 @@ bundle exec rake docs gem build archunit.gemspec --strict ~~~ -The coverage suite enforces at least 98% line and 90% branch coverage. The documentation task builds +The coverage suite enforces at least 98% line and 90% branch coverage on every `lib/**/*.rb` runtime +file, including unloaded files. Specs, benchmarks, and development scripts do not contribute to +the enforced denominator. A subprocess regression test verifies the actual filtered report and +thresholds without merging its partial probe execution into the full suite. Native symlink tests +may be skipped on Windows accounts without link privileges; Linux CI exercises those scenarios. +The documentation task builds the complete site, checks the public API guide, rejects unrendered Markdown, and validates internal links. diff --git a/spec/ci/coverage_scope_spec.rb b/spec/ci/coverage_scope_spec.rb new file mode 100644 index 0000000..fea9087 --- /dev/null +++ b/spec/ci/coverage_scope_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'json' +require 'open3' +require 'rbconfig' + +RSpec.describe 'the enforced coverage scope' do + it 'includes every runtime file, excludes loaded tooling, and preserves coverage thresholds' do + root = File.expand_path('../..', __dir__) + # Inspect the real settings in a separate process without merging its partial execution into + # the parent suite's coverage result. Only the full parent run enforces the percentage gate. + probe = <<~RUBY + require 'json' + require 'rspec/core' + require_relative 'spec/spec_helper' + SimpleCov.use_merging false + SimpleCov.at_exit {} + require_relative 'benchmark/extraction' + settings = SimpleCov.minimum_coverage + files = SimpleCov.result.files.map(&:filename) + puts JSON.generate(files: files, minimums: settings, loaded: $LOADED_FEATURES) + RUBY + stdout, stderr, status = Open3.capture3( + { 'COVERAGE' => 'true' }, RbConfig.ruby, '-Ilib', '-e', probe, chdir: root + ) + expect(status.success?).to be(true), stderr + result = JSON.parse(stdout) + expected = Dir.glob(File.join(root, 'lib/**/*.rb')).map { |path| File.expand_path(path) } + normalize = ->(paths) { paths.map { |path| path.tr('\\', '/') }.sort } + expect(normalize.call(result.fetch('files'))).to eq(normalize.call(expected)) + loaded_tools = %w[spec/spec_helper.rb benchmark/extraction.rb].map do |path| + File.join(root, path).tr('\\', '/') + end + expect(normalize.call(result.fetch('loaded'))).to include(*loaded_tools) + expect(result.fetch('minimums')).to eq('line' => 98, 'branch' => 90) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 90c2146..be51e88 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,9 +3,12 @@ if ENV['COVERAGE'] == 'true' require 'simplecov' + library_prefix = "#{File.expand_path('../lib', __dir__).tr('\\', '/')}/" SimpleCov.start do + root File.expand_path('..', __dir__) enable_coverage :branch track_files 'lib/**/*.rb' + add_filter { |source| !source.filename.tr('\\', '/').start_with?(library_prefix) } minimum_coverage line: 98, branch: 90 end end