coverband 5.2.6.rc.2 → 5.2.6.rc.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a0693cadfb1b345691f9994b565b05f06ebb1fb808bde8327cea50c192aee3f
4
- data.tar.gz: 1bcdb4b2bc3a346bfd5b74b2be5638cc286a88247c6ea1e2908ed4ef74e6e5d0
3
+ metadata.gz: 45ab4b4c0eec8a0b642cb2236bb4fbf4b3117ec6af3c4279b37236f360fbeab6
4
+ data.tar.gz: 07010dd790b47cecc8fd5318bc27ec779c8f801a33943694d794a6c23686723f
5
5
  SHA512:
6
- metadata.gz: 11392bc75a3b44770d2a33cdf1bcdff9ad0127ea715be57c5d2b7b2f5f4e4d50bda5caa394015239eaf03f9aab62dcdba647692cbf479ace08a9ec9ff0d06ead
7
- data.tar.gz: 652ad15638ed7da3d7a509c40eefe0f855e71e24843b98dc896213a3c7ba52ff88bcafba47fccff754e6dff25f76b145ce7bb8117f1f55afc8104e9de2233500
6
+ metadata.gz: 054ac7588139476dd9f0b51caa28023f037867eac12a89d523efa0ed220791e340a468f26a1fe5f67661986008449e492be2f005f948377f7d4e728604ed8c86
7
+ data.tar.gz: d1c38bb92fb95e3125cb25eb188cefce1efe86ce68932078cd75a4ae417dd1626263aa3849f45edd37d72cbd86ba72627b78271354c6d6ddd23648859c47e5cf
@@ -13,4 +13,5 @@ jobs:
13
13
  - name: Update diagram
14
14
  uses: githubocto/repo-visualizer@main
15
15
  with:
16
- excluded_paths: "ignore,.github"
16
+ excluded_paths: "ignore,.github"
17
+ branch: diagram
@@ -21,11 +21,11 @@ jobs:
21
21
  # removing jruby again to flaky
22
22
  # ruby: [2.3, 2.4, 2.5, 2.6, 2.7, "3.0", "3.1", jruby]
23
23
  # need to add support for multiple gemfiles
24
- ruby: ["2.7", "3.0", "3.1"]
24
+ ruby: ["2.7", "3.0", "3.1", "3.2"]
25
25
  redis-version: [4, 5, 6]
26
26
  runs-on: ${{ matrix.os }}-latest
27
27
  steps:
28
- - uses: actions/checkout@v2
28
+ - uses: actions/checkout@v3
29
29
  - uses: supercharge/redis-github-action@1.2.0
30
30
  - uses: ruby/setup-ruby@v1
31
31
  with:
data/README.md CHANGED
@@ -207,9 +207,9 @@ config.ignore += ['config/application.rb',
207
207
  'config/boot.rb',
208
208
  'config/puma.rb',
209
209
  'config/schedule.rb',
210
- 'bin/*',
211
- 'config/environments/*',
212
- 'lib/tasks/*']
210
+ 'bin/.*',
211
+ 'config/environments/.*',
212
+ 'lib/tasks/.*']
213
213
  ```
214
214
 
215
215
  **Ignoring Custom Gem Locations:** Note, if you have your gems in a custom location under your app folder you likely want to add them to `config.ignore`. For example, if you have your gems not in a default ignored location of `app/vendor` but have them in `app/gems` you would need to add `gems/*` to your ignore list.
@@ -437,7 +437,7 @@ What is the coverage data in Redis?
437
437
 
438
438
  A diagram of the code.
439
439
 
440
- ![Visualization of this repo](./diagram.svg)
440
+ ![Visualization of this repo](https://raw.githubusercontent.com/danmayer/coverband/diagram/diagram.svg)
441
441
 
442
442
  ## Logo
443
443
 
data/changes.md CHANGED
@@ -1,6 +1,11 @@
1
1
  ### Coverband 5.2.6
2
2
 
3
+ __NOTE: the current RCs include below, but this might turn into coverband 6.0__
4
+
3
5
  - add support for translation keys
6
+ - refactor non Coverage.so based trackers
7
+ - adds CSP report support (thanks @jwg2s)
8
+ - add JSON reporter (thanks @mark-davenport-fountain)
4
9
 
5
10
  ### Coverband 5.2.5
6
11
 
@@ -11,7 +11,8 @@ module Coverband
11
11
  :view_tracker, :defer_eager_loading_data,
12
12
  :track_routes, :route_tracker,
13
13
  :track_translations, :translations_tracker,
14
- :trackers
14
+ :trackers, :csp_policy
15
+
15
16
  attr_writer :logger, :s3_region, :s3_bucket, :s3_access_key_id,
16
17
  :s3_secret_access_key, :password, :api_key, :service_url, :coverband_timeout, :service_dev_mode,
17
18
  :service_test_mode, :process_type, :track_views, :redis_url,
@@ -82,6 +83,7 @@ module Coverband
82
83
  @all_root_paths = nil
83
84
  @all_root_patterns = nil
84
85
  @password = nil
86
+ @csp_policy = false
85
87
 
86
88
  # coverband service settings
87
89
  @api_key = nil
@@ -205,7 +207,10 @@ module Coverband
205
207
  # Don't allow the ignore to override things like gem tracking
206
208
  ###
207
209
  def ignore=(ignored_array)
210
+ ignored_array.map { |ignore_str| Regexp.new(ignore_str) }
208
211
  @ignore = (@ignore + ignored_array).uniq
212
+ rescue RegexpError
213
+ logger.error "an invalid regular expression was passed in, ensure string are valid regex patterns #{ignored_array.join(",")}"
209
214
  end
210
215
 
211
216
  def current_root
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Outputs data in json format similar to what is shown in the HTML page
4
+ # Top level and file level coverage numbers
5
+ module Coverband
6
+ module Reporters
7
+ class JSONReport < Base
8
+ attr_accessor :filtered_report_files
9
+
10
+ def initialize(store, options = {})
11
+ coverband_reports = Coverband::Reporters::Base.report(store, options)
12
+ self.filtered_report_files = self.class.fix_reports(coverband_reports)
13
+ end
14
+
15
+ def report
16
+ report_as_json
17
+ end
18
+
19
+ private
20
+
21
+ def report_as_json
22
+ result = Coverband::Utils::Results.new(filtered_report_files)
23
+ source_files = result.source_files
24
+ {
25
+ **coverage_totals(source_files),
26
+ files: coverage_files(result, source_files)
27
+ }.to_json
28
+ end
29
+
30
+ def coverage_totals(source_files)
31
+ {
32
+ total_files: source_files.length,
33
+ lines_of_code: source_files.lines_of_code,
34
+ lines_covered: source_files.covered_lines,
35
+ lines_missed: source_files.missed_lines,
36
+ covered_strength: source_files.covered_strength,
37
+ covered_percent: source_files.covered_percent
38
+ }
39
+ end
40
+
41
+ # Using a hash indexed by file name for quick lookups
42
+ def coverage_files(result, source_files)
43
+ source_files.each_with_object({}) do |source_file, hash|
44
+ hash[source_file.short_name] = {
45
+ never_loaded: source_file.never_loaded,
46
+ runtime_percentage: result.runtime_relevant_coverage(source_file),
47
+ lines_of_code: source_file.lines.count,
48
+ lines_covered: source_file.covered_lines.count,
49
+ lines_missed: source_file.missed_lines.count,
50
+ covered_percent: source_file.covered_percent,
51
+ covered_strength: source_file.covered_strength
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -13,6 +13,22 @@ module Coverband
13
13
  class Web
14
14
  attr_reader :request
15
15
 
16
+ CSP_HEADER = [
17
+ "default-src 'self' https: http:",
18
+ "child-src 'self'",
19
+ "connect-src 'self' https: http: wss: ws:",
20
+ "font-src 'self' https: http:",
21
+ "frame-src 'self'",
22
+ "img-src 'self' https: http: data:",
23
+ "manifest-src 'self'",
24
+ "media-src 'self'",
25
+ "object-src 'none'",
26
+ "script-src 'self' https: http: 'unsafe-inline'",
27
+ "style-src 'self' https: http: 'unsafe-inline'",
28
+ "worker-src 'self'",
29
+ "base-uri 'self'"
30
+ ].join("; ").freeze
31
+
16
32
  def init_web
17
33
  full_path = Gem::Specification.find_by_name("coverband").full_gem_path
18
34
  @static = Rack::Static.new(self,
@@ -58,26 +74,28 @@ module Coverband
58
74
  when %r{\/clear}
59
75
  clear
60
76
  else
61
- [404, {"Content-Type" => "text/html"}, ["404 error!"]]
77
+ [404, coverband_headers, ["404 error!"]]
62
78
  end
63
79
  else
64
80
  case request_path_info
65
81
  when /.*\.(css|js|gif|png)/
66
82
  @static.call(env)
67
83
  when %r{\/settings}
68
- [200, {"Content-Type" => "text/html"}, [settings]]
84
+ [200, coverband_headers, [settings]]
69
85
  when %r{\/view_tracker_data}
70
- [200, {"Content-Type" => "text/json"}, [view_tracker_data]]
86
+ [200, coverband_headers(content_type: "text/json"), [view_tracker_data]]
71
87
  when %r{\/enriched_debug_data}
72
- [200, {"Content-Type" => "text/json"}, [enriched_debug_data]]
88
+ [200, coverband_headers(content_type: "text/json"), [enriched_debug_data]]
73
89
  when %r{\/debug_data}
74
- [200, {"Content-Type" => "text/json"}, [debug_data]]
90
+ [200, coverband_headers(content_type: "text/json"), [debug_data]]
75
91
  when %r{\/load_file_details}
76
- [200, {"Content-Type" => "text/json"}, [load_file_details]]
92
+ [200, coverband_headers(content_type: "text/json"), [load_file_details]]
93
+ when %r{\/json}
94
+ [200, coverband_headers(content_type: "text/json"), [json]]
77
95
  when %r{\/$}
78
- [200, {"Content-Type" => "text/html"}, [index]]
96
+ [200, coverband_headers, [index]]
79
97
  else
80
- [404, {"Content-Type" => "text/html"}, ["404 error!"]]
98
+ [404, coverband_headers, ["404 error!"]]
81
99
  end
82
100
  end
83
101
  end
@@ -93,6 +111,10 @@ module Coverband
93
111
  open_report: false).report
94
112
  end
95
113
 
114
+ def json
115
+ Coverband::Reporters::JSONReport.new(Coverband.configuration.store).report
116
+ end
117
+
96
118
  def settings
97
119
  Coverband::Utils::HTMLFormatter.new(nil, base_path: base_path).format_settings!
98
120
  end
@@ -174,6 +196,14 @@ module Coverband
174
196
 
175
197
  private
176
198
 
199
+ def coverband_headers(content_type: "text/html")
200
+ web_headers = {
201
+ "Content-Type" => content_type
202
+ }
203
+ web_headers["Content-Security-Policy-Report-Only"] = CSP_HEADER if Coverband.configuration.csp_policy
204
+ web_headers
205
+ end
206
+
177
207
  # This method should get the root mounted endpoint
178
208
  # for example if the app is mounted like so:
179
209
  # mount Coverband::Web, at: '/coverage'
@@ -5,5 +5,5 @@
5
5
  # use format "4.2.1.rc.1" ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3
6
6
  ###
7
7
  module Coverband
8
- VERSION = "5.2.6.rc.2"
8
+ VERSION = "5.2.6.rc.4"
9
9
  end
data/lib/coverband.rb CHANGED
@@ -137,6 +137,7 @@ module Coverband
137
137
  require "coverband/utils/lines_classifier"
138
138
  require "coverband/utils/results"
139
139
  require "coverband/reporters/html_report"
140
+ require "coverband/reporters/json_report"
140
141
  init_web
141
142
  end
142
143
  end
data/roadmap.md CHANGED
@@ -6,51 +6,51 @@
6
6
  - [redis bitmaps](http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/)
7
7
  - [redis bitfield](https://stackoverflow.com/questions/47100606/optimal-way-to-store-array-of-integers-in-redis-database)
8
8
  - Add support for [zadd](http://redis.io/topics/data-types-intro) so one could determine single call versus multiple calls on a line, letting us determine the most executed code in production.
9
+ - Changes and updates to Ruby Coverage Library that helps support templates
10
+ - https://github.com/ioquatix/covered
11
+ - https://github.com/simplecov-ruby/simplecov/pull/1037
12
+ - Consider A Coverband Pro / Option to run coverband service locally
13
+ - review how humperdink / e70 track translations, particularly how humperdink uses dirty sets with redis, for perf improvements for trackers
14
+ - https://github.com/livingsocial/humperdink
15
+ - https://github.com/sergioisidoro/e7o/blob/master/lib/e7o.rb
16
+ - Possible Cross Application Support to track library usage?
17
+ - Reducing differences between coverband local and coverband service
9
18
 
10
- ### Coverband Future...
19
+ ### Coverband Next...
11
20
 
12
21
  Will be the fully modern release that drops maintenance legacy support in favor of increased performance, ease of use, and maintainability.
13
22
 
14
- - Release will be aimed as significantly simplifying ease of use
15
- - near zero config setup for Rails apps
16
- - add built-in support for easy loading via Railties
17
- - built in support for activejob, sidekiq, and other common frameworks
18
- - reduced configuration options
19
- - support oneshot
20
- - drop middleware figure out a way to kick off background without middelware
23
+ - look at adding a DB tracker
24
+ - defaults to oneshot for coverage
25
+ - possibly splits coverage and all other covered modules
26
+ - drop middleware figure out a way to kick off background without middelware, possibly use similar process forking detection to humperdink
27
+ - https://github.com/livingsocial/humperdink/blob/master/lib/humperdink/fork_savvy_redis.rb
21
28
  - options on reporting
22
29
  - background reporting
23
30
  - or middleware reporting
24
31
  - Support for file versions
25
32
  - md5 or release tags
26
33
  - add coverage timerange support
27
- - Drop Simplecov dependency
28
34
  - improved web reporting
29
35
  - lists current config options
30
36
  - eventually allow updating remote config
31
37
  - full theming
32
- - list redis data dump for debugging
38
+ - list redis data dump for debugging (refactor built in debug support)
33
39
  - additional adapters: Memcache, S3, and ActiveRecord
34
40
  - add articles / podcasts like prontos readme https://github.com/prontolabs/pronto
35
- - Add detailed Gem usage report, if we collect and send gem usage we can give percentage of gem code used, which should help application developers know when to remove gem dependencies (0%) or perhaps inline single methods for little usage (using <= 5%) for example.
36
- - add meta data information first seen last recorded to the coverage report views (probably need to drop simplecov for that).
41
+ - add meta data information first seen last recorded to the coverage report views (per file / per method?).
37
42
  - more details in this issue: https://github.com/danmayer/coverband/issues/118
38
- - Make good video on setup, install, usage
39
43
  - See if we can add support for views / templates
40
44
  - using this technique https://github.com/ioquatix/covered
41
45
  - Better default grouping (could use groups features for gems for rails controllers, models, lib, etc)
42
46
  - Improved logging for easier debugging and development
43
47
  - drop the verbose mode and better support standard logger levels
44
- - Possibly setup a build assets system
45
- - my JS rules expanded the compressed JS at the top of application.js, basically we want to stitch together JS
46
- - I guess we could also load multiple JS files as most of the JS is just default compressed JS and a tiny amount of actual app JS.
47
- - lazy load for Coverband results
48
- - view layer file coverage
48
+ - redo the logger entirely
49
+ - redo config system and allow live config updates via webui
49
50
  - move all code to work with relative paths leaving only stdlib Coverage working on full paths
50
- - add gem_safe_lists to track only some gems
51
- - add gem_details_safe list to report on details on some gems
52
- - - display gems that are in loaded with 0 coverage, thanks @kbaum
53
51
 
54
- # Alpha / Beta / Release Candidates
52
+ # Out of Scope
55
53
 
56
- ### Coverband 5.?.?
54
+ It is important for a project to not only know what problems it is trying to solve, but what things are out of scope. We will start to try to document that here:
55
+
56
+ * We have in the past tried to add coverage tracking for all gems, this added a lot of complexity and compuation overhead and slowed things down to much. It also was of less value than we had hoped. There are alterntative ways to instrument a shared library to track across multiple applications, and single application gem utilization is easier to handle in a one of basis. It is unlikely we will support that again.
@@ -38,6 +38,16 @@ class BaseTest < Minitest::Test
38
38
  assert_equal expected, Coverband.configuration.ignore
39
39
  end
40
40
 
41
+ test "ignore catches regex errors" do
42
+ Coverband.configuration.logger.expects(:error).with("an invalid regular expression was passed in, ensure string are valid regex patterns *invalidRegex*")
43
+ Coverband.configure do |config|
44
+ config.ignore = ["*invalidRegex*"]
45
+ end
46
+ Coverband::Collectors::Coverage.instance.reset_instance
47
+ expected = Coverband::Configuration::IGNORE_DEFAULTS << "config/environments"
48
+ assert_equal expected, Coverband.configuration.ignore
49
+ end
50
+
41
51
  test "ignore" do
42
52
  Coverband::Collectors::Coverage.instance.reset_instance
43
53
  assert !Coverband.configuration.ignore.first.nil?
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("../../test_helper", File.dirname(__FILE__))
4
+
5
+ class ReportJSONTest < Minitest::Test
6
+ def setup
7
+ super
8
+ @store = Coverband.configuration.store
9
+ Coverband.configure do |config|
10
+ config.store = @store
11
+ config.root = fixtures_root
12
+ config.ignore = ["notsomething.rb", "lib/*"]
13
+ end
14
+ mock_file_hash
15
+ end
16
+
17
+ test "includes totals" do
18
+ @store.send(:save_report, basic_coverage)
19
+
20
+ json = Coverband::Reporters::JSONReport.new(@store).report
21
+ parsed = JSON.parse(json)
22
+ expected_keys = ["total_files", "lines_of_code", "lines_covered", "lines_missed", "covered_strength", "covered_percent"]
23
+ assert expected_keys - parsed.keys == []
24
+ end
25
+
26
+ test "honors ignore list" do
27
+ @store.send(:save_report, basic_coverage)
28
+
29
+ json = Coverband::Reporters::JSONReport.new(@store).report
30
+ parsed = JSON.parse(json)
31
+ expected_files = ["app/controllers/sample_controller.rb", "app/models/user.rb"]
32
+ assert_equal parsed["files"].keys, expected_files
33
+ end
34
+
35
+ test "includes metrics for files" do
36
+ @store.send(:save_report, basic_coverage)
37
+
38
+ json = Coverband::Reporters::JSONReport.new(@store).report
39
+ parsed = JSON.parse(json)
40
+
41
+ expected_keys = ["never_loaded", "runtime_percentage", "lines_of_code", "lines_covered", "lines_missed", "covered_percent", "covered_strength"]
42
+
43
+ assert_equal parsed["files"].length, 2
44
+ parsed["files"].keys.each do |file|
45
+ assert_equal parsed["files"][file].keys, expected_keys
46
+ end
47
+ end
48
+ end
data/test/test_helper.rb CHANGED
@@ -33,6 +33,7 @@ require "coverband/utils/source_file"
33
33
  require "coverband/utils/lines_classifier"
34
34
  require "coverband/utils/results"
35
35
  require "coverband/reporters/html_report"
36
+ require "coverband/reporters/json_report"
36
37
  require "webmock/minitest"
37
38
 
38
39
  require_relative "unique_files"
@@ -93,13 +94,13 @@ Mocha::Configuration.prevent(:stubbing_non_existent_method)
93
94
  def test(name, &block)
94
95
  test_name = "test_#{name.gsub(/\s+/, "_")}".to_sym
95
96
  defined = begin
96
- instance_method(test_name)
97
+ instance_method(test_name)
97
98
  rescue
98
99
  false
99
- end
100
+ end
100
101
  raise "#{test_name} is already defined in #{self}" if defined
101
102
 
102
- if block_given?
103
+ if block
103
104
  define_method(test_name, &block)
104
105
  else
105
106
  define_method(test_name) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.6.rc.2
4
+ version: 5.2.6.rc.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-05 00:00:00.000000000 Z
12
+ date: 2023-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: benchmark-ips
@@ -315,6 +315,7 @@ files:
315
315
  - lib/coverband/reporters/base.rb
316
316
  - lib/coverband/reporters/console_report.rb
317
317
  - lib/coverband/reporters/html_report.rb
318
+ - lib/coverband/reporters/json_report.rb
318
319
  - lib/coverband/reporters/web.rb
319
320
  - lib/coverband/utils/absolute_file_converter.rb
320
321
  - lib/coverband/utils/configuration_template.rb
@@ -396,6 +397,7 @@ files:
396
397
  - test/coverband/reporters/base_test.rb
397
398
  - test/coverband/reporters/console_test.rb
398
399
  - test/coverband/reporters/html_test.rb
400
+ - test/coverband/reporters/json_test.rb
399
401
  - test/coverband/reporters/web_test.rb
400
402
  - test/coverband/utils/absolute_file_converter_test.rb
401
403
  - test/coverband/utils/dead_methods_test.rb
@@ -556,6 +558,7 @@ test_files:
556
558
  - test/coverband/reporters/base_test.rb
557
559
  - test/coverband/reporters/console_test.rb
558
560
  - test/coverband/reporters/html_test.rb
561
+ - test/coverband/reporters/json_test.rb
559
562
  - test/coverband/reporters/web_test.rb
560
563
  - test/coverband/utils/absolute_file_converter_test.rb
561
564
  - test/coverband/utils/dead_methods_test.rb