gitlab_quality-test_tooling 3.24.0 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/exe/test-coverage +4 -21
- data/lib/gitlab_quality/test_tooling/code_coverage/click_house/per_test_coverage_table.rb +4 -12
- data/lib/gitlab_quality/test_tooling/code_coverage/click_house/test_health_risk_aggregation.sql +1 -1
- data/lib/gitlab_quality/test_tooling/code_coverage/per_test_coverage_data.rb +1 -14
- data/lib/gitlab_quality/test_tooling/code_coverage/per_test_coverage_exporter.rb +12 -68
- data/lib/gitlab_quality/test_tooling/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff650582bdf348bfcd7522ba8c9fe600398e088c208cbffc18c43d2178845172
|
|
4
|
+
data.tar.gz: e789f064c876d4b4deeb64bb5e0011721c345a2ec8a1956b772d45010ae9cae5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c0492ef7963771582f48c3bc49746cb2df0ccc3e328ae57a76c7816013b5454deb33a6c871b89753746ae0e9f2e359d78d01452e41f1a5073ede0ebc6a967c8d
|
|
7
|
+
data.tar.gz: 593081e642b306e6584e827cb6c35ae7ccf98405488c4c14d91dfd16d5afe83b579b4682ff5039447acde49be5a5a9e8864d28187e500730a28d1c9d3296ed93
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
gitlab_quality-test_tooling (3.
|
|
4
|
+
gitlab_quality-test_tooling (3.25.0)
|
|
5
5
|
activesupport (>= 7.0)
|
|
6
6
|
amatch (~> 0.4.1)
|
|
7
7
|
csv (~> 3.0)
|
|
@@ -273,7 +273,7 @@ GEM
|
|
|
273
273
|
pstore (0.2.1)
|
|
274
274
|
public_suffix (7.0.5)
|
|
275
275
|
racc (1.8.1)
|
|
276
|
-
rack (3.2.
|
|
276
|
+
rack (3.2.9)
|
|
277
277
|
rainbow (3.1.1)
|
|
278
278
|
rake (13.2.1)
|
|
279
279
|
rb-fsevent (0.11.2)
|
data/README.md
CHANGED
|
@@ -249,7 +249,7 @@ Usage: exe/feature-readiness-evaluation [options]
|
|
|
249
249
|
Runs in one of three modes:
|
|
250
250
|
|
|
251
251
|
- **Full coverage-metrics export** (default, no `--per-test-coverage` / `--run-aggregation`): reads the LCOV report, Crystalball test map, and test reports, then exports the coverage-metrics table. Requires the full argument set.
|
|
252
|
-
- **Per-test coverage** (`--per-test-coverage GLOB`): inserts per-test rows into `code_coverage.test_coverage_per_file` and runs the daily `test_health_risk` aggregation unless `--skip-aggregation`. Needs only the `--clickhouse-*` options; `--test-reports` and `--
|
|
252
|
+
- **Per-test coverage** (`--per-test-coverage GLOB`): inserts per-test rows into `code_coverage.test_coverage_per_file` and runs the daily `test_health_risk` aggregation unless `--skip-aggregation`. Needs only the `--clickhouse-*` options; `--jest-quarantine-file` is optional. `--test-reports` and `--clickhouse-shared-database` are accepted and ignored in this mode.
|
|
253
253
|
- **Aggregation only** (`--run-aggregation`): runs the daily `test_health_risk` aggregation and exits. Needs only the `--clickhouse-*` options. Pair with `--skip-aggregation` on batched per-test inserts to aggregate once at the end instead of once per batch.
|
|
254
254
|
|
|
255
255
|
```shell
|
data/exe/test-coverage
CHANGED
|
@@ -70,9 +70,8 @@ options = OptionParser.new do |opts|
|
|
|
70
70
|
'Per-test coverage mode. Glob for per-test coverage JSON/NDJSON files. ' \
|
|
71
71
|
'Inserts rows into code_coverage.test_coverage_per_file and runs the daily ' \
|
|
72
72
|
'test_health_risk aggregation unless --skip-aggregation. Needs only the ' \
|
|
73
|
-
'--clickhouse-* options; --
|
|
74
|
-
'
|
|
75
|
-
'since category ownership is read from the shared database. ' \
|
|
73
|
+
'--clickhouse-* options; --jest-quarantine-file is optional. --test-reports ' \
|
|
74
|
+
'and --clickhouse-shared-database are accepted and ignored in this mode. ' \
|
|
76
75
|
'(e.g., "tmp/per-test-coverage-*.ndjson")') do |pattern|
|
|
77
76
|
params[:per_test_coverage] = pattern
|
|
78
77
|
end
|
|
@@ -135,16 +134,7 @@ mode =
|
|
|
135
134
|
clickhouse_required = [:clickhouse_url, :clickhouse_database, :clickhouse_username]
|
|
136
135
|
full_export_required =
|
|
137
136
|
[:test_reports, :coverage_report, :test_map, :responsibility_patterns, :clickhouse_shared_database] + clickhouse_required
|
|
138
|
-
|
|
139
|
-
# rows (--test-reports present), so require the shared database exactly then.
|
|
140
|
-
per_test_enriching = mode == :per_test && params[:test_reports]
|
|
141
|
-
required_params =
|
|
142
|
-
case mode
|
|
143
|
-
when :full_export
|
|
144
|
-
full_export_required
|
|
145
|
-
else
|
|
146
|
-
per_test_enriching ? clickhouse_required + [:clickhouse_shared_database] : clickhouse_required
|
|
147
|
-
end
|
|
137
|
+
required_params = mode == :full_export ? full_export_required : clickhouse_required
|
|
148
138
|
|
|
149
139
|
unless params.any? && (required_params - params.keys).none?
|
|
150
140
|
puts "Missing argument(s). Required arguments are: #{required_params}\nPassed arguments are: #{params}\n"
|
|
@@ -158,12 +148,7 @@ if clickhouse_password.to_s.strip.empty?
|
|
|
158
148
|
exit 1
|
|
159
149
|
end
|
|
160
150
|
|
|
161
|
-
non_empty_params =
|
|
162
|
-
if mode == :full_export || per_test_enriching
|
|
163
|
-
clickhouse_required + [:clickhouse_shared_database]
|
|
164
|
-
else
|
|
165
|
-
clickhouse_required
|
|
166
|
-
end
|
|
151
|
+
non_empty_params = mode == :full_export ? clickhouse_required + [:clickhouse_shared_database] : clickhouse_required
|
|
167
152
|
|
|
168
153
|
non_empty_params.each do |param|
|
|
169
154
|
next unless params[param].to_s.strip.empty?
|
|
@@ -204,8 +189,6 @@ when :per_test
|
|
|
204
189
|
GitlabQuality::TestTooling::CodeCoverage::PerTestCoverageExporter.new(
|
|
205
190
|
coverage_glob: params[:per_test_coverage],
|
|
206
191
|
clickhouse: clickhouse_data,
|
|
207
|
-
clickhouse_shared_database: params[:clickhouse_shared_database],
|
|
208
|
-
test_reports: params[:test_reports],
|
|
209
192
|
jest_quarantine_file: params[:jest_quarantine_file],
|
|
210
193
|
skip_aggregation: params.fetch(:skip_aggregation, false)
|
|
211
194
|
).run
|
|
@@ -43,7 +43,7 @@ module GitlabQuality
|
|
|
43
43
|
# :source_file [String]
|
|
44
44
|
# :covered_lines [Array<Integer>] line numbers covered by this test on this file
|
|
45
45
|
# :total_lines [Integer] executable lines in the source file
|
|
46
|
-
# :
|
|
46
|
+
# :captured_sha [String, optional]
|
|
47
47
|
# @return [void]
|
|
48
48
|
def push(data) # rubocop:disable Metrics/AbcSize
|
|
49
49
|
return logger.warn("#{LOG_PREFIX} No data found, skipping ClickHouse export!") if data.empty?
|
|
@@ -93,7 +93,7 @@ module GitlabQuality
|
|
|
93
93
|
false
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
def sanitized_data_record(record)
|
|
96
|
+
def sanitized_data_record(record)
|
|
97
97
|
sanitized_lines = sanitize_lines(record[:covered_lines])
|
|
98
98
|
|
|
99
99
|
# `valid_covered_lines?` only checks the raw input is a non-empty
|
|
@@ -116,10 +116,6 @@ module GitlabQuality
|
|
|
116
116
|
source_file: record[:source_file],
|
|
117
117
|
covered_lines: sanitized_lines,
|
|
118
118
|
total_lines: record[:total_lines].to_i,
|
|
119
|
-
feature_category: record[:feature_category] || '',
|
|
120
|
-
group: record[:group] || '',
|
|
121
|
-
stage: record[:stage] || '',
|
|
122
|
-
section: record[:section] || '',
|
|
123
119
|
captured_sha: record[:captured_sha].to_s
|
|
124
120
|
}
|
|
125
121
|
end
|
|
@@ -129,7 +125,7 @@ module GitlabQuality
|
|
|
129
125
|
def build_insert_sql(rows_sql)
|
|
130
126
|
<<~SQL
|
|
131
127
|
INSERT INTO #{full_table_name}
|
|
132
|
-
(timestamp, ci_project_path, test_file, source_file, covered_lines, total_lines,
|
|
128
|
+
(timestamp, ci_project_path, test_file, source_file, covered_lines, total_lines, captured_sha)
|
|
133
129
|
VALUES
|
|
134
130
|
#{rows_sql.join(",\n")}
|
|
135
131
|
SQL
|
|
@@ -163,7 +159,7 @@ module GitlabQuality
|
|
|
163
159
|
# `sanitized_data_record`). Values are positive integers within
|
|
164
160
|
# MAX_LINE_NUMBER; no defensive validation is repeated here because
|
|
165
161
|
# this method is on the hot path (every row in every batch).
|
|
166
|
-
def build_row_sql(record)
|
|
162
|
+
def build_row_sql(record)
|
|
167
163
|
line_array = "[#{record[:covered_lines].join(',')}]"
|
|
168
164
|
timestamp_str = record[:timestamp].iso8601(3)
|
|
169
165
|
"(" \
|
|
@@ -173,10 +169,6 @@ module GitlabQuality
|
|
|
173
169
|
"'#{escape(record[:source_file])}', " \
|
|
174
170
|
"bitmapBuild(CAST(#{line_array} AS Array(UInt32))), " \
|
|
175
171
|
"#{record[:total_lines]}, " \
|
|
176
|
-
"'#{escape(record[:feature_category])}', " \
|
|
177
|
-
"'#{escape(record[:group])}', " \
|
|
178
|
-
"'#{escape(record[:stage])}', " \
|
|
179
|
-
"'#{escape(record[:section])}', " \
|
|
180
172
|
"'#{escape(record[:captured_sha])}'" \
|
|
181
173
|
")"
|
|
182
174
|
end
|
|
@@ -44,8 +44,6 @@ module GitlabQuality
|
|
|
44
44
|
# lines across all examples in the same test file, takes the max
|
|
45
45
|
# total_lines
|
|
46
46
|
# - drops rows with empty bitmaps (file imported but no line hit)
|
|
47
|
-
# - enriches with feature_category / group / stage / section when test
|
|
48
|
-
# metadata is provided
|
|
49
47
|
class PerTestCoverageData
|
|
50
48
|
# Raised when a coverage artifact can't be parsed. Wraps the underlying
|
|
51
49
|
# `JSON::ParserError` or `Errno::ENOENT` so callers outside the
|
|
@@ -61,17 +59,13 @@ module GitlabQuality
|
|
|
61
59
|
EXCLUDED_SOURCE_PREFIXES = %w[vendor/].freeze
|
|
62
60
|
|
|
63
61
|
# @param coverage_files [Array<String>] paths to per-test coverage JSON artifacts
|
|
64
|
-
# @param tests_to_categories [Hash<String, Array<String>>] test_file => [feature_category]
|
|
65
|
-
# @param feature_categories_to_teams [Hash<String, Hash>] category => {group:, stage:, section:}
|
|
66
62
|
# @param captured_sha [String] the git SHA the coverage was captured against; attached to
|
|
67
63
|
# every emitted row so downstream delta-capture jobs can ask
|
|
68
64
|
# `SELECT max(captured_sha) FROM code_coverage.test_coverage_per_file` to find the
|
|
69
65
|
# previous successful capture point. Defaults to '' when unknown.
|
|
70
66
|
# @raise [ParseError] if a coverage file is missing or contains invalid JSON
|
|
71
|
-
def initialize(coverage_files,
|
|
67
|
+
def initialize(coverage_files, captured_sha: '')
|
|
72
68
|
@coverage_files = Array(coverage_files)
|
|
73
|
-
@tests_to_categories = tests_to_categories
|
|
74
|
-
@feature_categories_to_teams = feature_categories_to_teams
|
|
75
69
|
@captured_sha = captured_sha.to_s
|
|
76
70
|
end
|
|
77
71
|
|
|
@@ -105,18 +99,11 @@ module GitlabQuality
|
|
|
105
99
|
end
|
|
106
100
|
|
|
107
101
|
aggregated.map do |(test_file, source_file), agg|
|
|
108
|
-
category = @tests_to_categories[test_file]&.first || ''
|
|
109
|
-
team = @feature_categories_to_teams[category] || {}
|
|
110
|
-
|
|
111
102
|
{
|
|
112
103
|
test_file: test_file,
|
|
113
104
|
source_file: source_file,
|
|
114
105
|
covered_lines: agg[:covered_lines].to_a.sort,
|
|
115
106
|
total_lines: agg[:total_lines],
|
|
116
|
-
feature_category: category,
|
|
117
|
-
group: team[:group] || '',
|
|
118
|
-
stage: team[:stage] || '',
|
|
119
|
-
section: team[:section] || '',
|
|
120
107
|
captured_sha: @captured_sha
|
|
121
108
|
}
|
|
122
109
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'json'
|
|
4
3
|
require 'logger'
|
|
5
4
|
|
|
6
5
|
module GitlabQuality
|
|
@@ -12,10 +11,9 @@ module GitlabQuality
|
|
|
12
11
|
#
|
|
13
12
|
# Unlike the full coverage-metrics export, this path needs only ClickHouse
|
|
14
13
|
# credentials and the per-test coverage glob, not the LCOV report, the
|
|
15
|
-
# Crystalball test map, or the responsibility patterns.
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
# report JSON, otherwise those columns stay blank.
|
|
14
|
+
# Crystalball test map, or the responsibility patterns. Test file
|
|
15
|
+
# categories live in `test_metrics.test_file_categories`, so rows carry no
|
|
16
|
+
# category, group, stage or section.
|
|
19
17
|
#
|
|
20
18
|
# `skip_aggregation` lets a batched caller insert without re-running the
|
|
21
19
|
# table-wide aggregation on every batch. The streaming export invokes this
|
|
@@ -23,16 +21,18 @@ module GitlabQuality
|
|
|
23
21
|
# aggregation once at the end.
|
|
24
22
|
class PerTestCoverageExporter
|
|
25
23
|
# @param clickhouse [Hash] connection params (:url, :database, :username, :password)
|
|
26
|
-
# @param
|
|
27
|
-
#
|
|
24
|
+
# @param test_reports [String, nil] ignored
|
|
25
|
+
# @param clickhouse_shared_database [String, nil] ignored
|
|
26
|
+
#
|
|
27
|
+
# Both are accepted because the gitlab-org/gitlab CI jobs still pass the
|
|
28
|
+
# matching flags. Remove them once those jobs stop.
|
|
29
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
|
28
30
|
def initialize(
|
|
29
31
|
coverage_glob:, clickhouse:, clickhouse_shared_database: nil,
|
|
30
32
|
test_reports: nil, jest_quarantine_file: nil,
|
|
31
33
|
captured_sha: ENV.fetch('CI_COMMIT_SHA', ''), skip_aggregation: false, logger: nil)
|
|
32
34
|
@coverage_glob = coverage_glob
|
|
33
35
|
@clickhouse = clickhouse
|
|
34
|
-
@clickhouse_shared_database = clickhouse_shared_database
|
|
35
|
-
@test_reports = test_reports
|
|
36
36
|
@jest_quarantine_file = jest_quarantine_file
|
|
37
37
|
@captured_sha = captured_sha.to_s
|
|
38
38
|
@skip_aggregation = skip_aggregation
|
|
@@ -42,6 +42,7 @@ module GitlabQuality
|
|
|
42
42
|
# a debug logger explicitly when they need the SQL.
|
|
43
43
|
@logger = logger || ::Logger.new($stdout, level: ::Logger::INFO)
|
|
44
44
|
end
|
|
45
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
|
45
46
|
|
|
46
47
|
# @return [void]
|
|
47
48
|
def run
|
|
@@ -68,18 +69,10 @@ module GitlabQuality
|
|
|
68
69
|
|
|
69
70
|
private
|
|
70
71
|
|
|
71
|
-
attr_reader :coverage_glob, :clickhouse, :
|
|
72
|
-
:jest_quarantine_file, :captured_sha, :skip_aggregation, :logger
|
|
72
|
+
attr_reader :coverage_glob, :clickhouse, :jest_quarantine_file, :captured_sha, :skip_aggregation, :logger
|
|
73
73
|
|
|
74
74
|
def insert(coverage_files)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
data = PerTestCoverageData.new(
|
|
78
|
-
coverage_files,
|
|
79
|
-
tests_to_categories: tests_to_categories,
|
|
80
|
-
feature_categories_to_teams: feature_categories_to_teams,
|
|
81
|
-
captured_sha: captured_sha
|
|
82
|
-
)
|
|
75
|
+
data = PerTestCoverageData.new(coverage_files, captured_sha: captured_sha)
|
|
83
76
|
|
|
84
77
|
ClickHouse::PerTestCoverageTable.new(**clickhouse_credentials).push(data.as_db_table)
|
|
85
78
|
end
|
|
@@ -133,55 +126,6 @@ module GitlabQuality
|
|
|
133
126
|
)
|
|
134
127
|
end
|
|
135
128
|
|
|
136
|
-
# `tests_to_categories` comes from the test report JSON; without it, rows
|
|
137
|
-
# carry blank categories. The category-to-team map is a ClickHouse read,
|
|
138
|
-
# so only build both when there are reports to enrich.
|
|
139
|
-
def resolve_categories
|
|
140
|
-
return [{}, {}] unless test_reports
|
|
141
|
-
|
|
142
|
-
# Comma-separated patterns, mirroring Artifacts#test_reports.
|
|
143
|
-
patterns = test_reports.split(',').map(&:strip).reject(&:empty?)
|
|
144
|
-
report_files = Dir.glob(patterns)
|
|
145
|
-
return [{}, {}] if report_files.empty?
|
|
146
|
-
|
|
147
|
-
[tests_to_categories_from(report_files), feature_categories_to_teams]
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# Category to group/stage/section, read from `category_owners` in the shared
|
|
151
|
-
# database, the same source the full coverage export uses. The shared copy is
|
|
152
|
-
# refreshed by sync-category-owners; the legacy `code_coverage.category_owners`
|
|
153
|
-
# stopped updating in December 2025, so reading it would drop every category
|
|
154
|
-
# added since. `owner_records` gives string-keyed values; PerTestCoverageData
|
|
155
|
-
# reads symbol keys.
|
|
156
|
-
def feature_categories_to_teams
|
|
157
|
-
if clickhouse_shared_database.to_s.strip.empty?
|
|
158
|
-
raise ArgumentError,
|
|
159
|
-
'clickhouse_shared_database is required to enrich per-test rows with category owners'
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
shared_credentials = clickhouse_credentials.merge(database: clickhouse_shared_database)
|
|
163
|
-
|
|
164
|
-
ClickHouse::CategoryOwnersTable.new(**shared_credentials).owner_records.transform_values do |owner|
|
|
165
|
-
{ group: owner["group"], stage: owner["stage"], section: owner["section"] }
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def tests_to_categories_from(report_files)
|
|
170
|
-
report_files.each_with_object({}) do |file, combined|
|
|
171
|
-
# Category enrichment is optional, so a malformed or vanished report
|
|
172
|
-
# shouldn't abort the per-test insert (the rows are the point). Warn
|
|
173
|
-
# and skip the file, leaving those tests with blank categories.
|
|
174
|
-
begin
|
|
175
|
-
report = TestReport.new(JSON.parse(File.read(file)))
|
|
176
|
-
rescue JSON::ParserError, Errno::ENOENT => e
|
|
177
|
-
logger.warn("#{ClickHouse::LOG_PREFIX} Skipping unreadable test report #{file}: #{e.message}")
|
|
178
|
-
next
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
combined.merge!(report.tests_to_categories) { |_, old_val, new_val| (old_val + new_val).uniq }
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
129
|
def clickhouse_credentials
|
|
186
130
|
clickhouse.merge(logger: logger)
|
|
187
131
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gitlab_quality-test_tooling
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitLab Quality
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-12-
|
|
11
|
+
date: 2026-12-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: climate_control
|