gitlab_quality-test_tooling 2.0.0 → 2.1.0

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: 4a5b20eb9951ec812418e3b1f5774674419d29961fabf4710f32e71d7a7f6c73
4
- data.tar.gz: 7ec895c4672772ef7801cf1fa864c87d1f76b59f2834434658f13e7c64cc0615
3
+ metadata.gz: 69b4478a8c7af86d2dae63c79d0924037feb673486f1ae6f15d5617121a0b9f4
4
+ data.tar.gz: 9a7f797d54687a515d834cfe0585bca7b87f5a28cd33000d5c06ebea292de56e
5
5
  SHA512:
6
- metadata.gz: f013d08976015caf80341b6aa86ecbb1b7198adeac56911dc89a9e3958a78a8001c065cb7a777ed8248109fd72d5b2109a577692c494ad785a3f55e0296c2be3
7
- data.tar.gz: 66be21506f82e4cbf566216f546308df9e1607aaa709792f35c9053c117da2a2845abb376fe88ff743790a0d5006a6d71e2ee2b9365f109b50772367a6c2bf8a
6
+ metadata.gz: 50206a9f212b2d78ab38b8433ffb5f22864e8a322b6065b6492a9023104e2caf0097042c8935c913f7d16de982fd3fb04a8438d294865f61caac84eee60d943e
7
+ data.tar.gz: 1267891667d8bf81617843d65ea6cd9bee2aef24007a2dc53ba92d970529f771dcbf8b8209aba7d59531f40ffac2e2c549444441dcae123c8e70bac1c0d417e7
data/.tool-versions CHANGED
@@ -1 +1,2 @@
1
1
  ruby 3.2.5
2
+ lefthook 1.7.14
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab_quality-test_tooling (2.0.0)
4
+ gitlab_quality-test_tooling (2.1.0)
5
5
  activesupport (>= 7.0, < 7.2)
6
6
  amatch (~> 0.4.1)
7
7
  fog-google (~> 1.24, >= 1.24.1)
@@ -302,6 +302,8 @@ GEM
302
302
  binding_of_caller
303
303
  rspec-parameterized-core (< 2)
304
304
  rspec-support (3.13.1)
305
+ rspec_junit_formatter (0.6.0)
306
+ rspec-core (>= 2, < 4, != 2.12.0)
305
307
  rubocop (1.62.1)
306
308
  json (~> 2.3)
307
309
  language_server-protocol (>= 3.17.0)
@@ -407,6 +409,7 @@ DEPENDENCIES
407
409
  pry-byebug (= 3.10.1)
408
410
  rake (~> 13.0)
409
411
  rspec (~> 3.12)
412
+ rspec_junit_formatter (~> 0.6.0)
410
413
  simplecov (~> 0.22)
411
414
  simplecov-cobertura (~> 2.1)
412
415
  solargraph (~> 0.41)
data/README.md CHANGED
@@ -177,6 +177,20 @@ Usage: exe/failed-test-issues [options]
177
177
  -h, --help Show the usage
178
178
  ```
179
179
 
180
+ ### `exe/existing-test-health-issue`
181
+
182
+ ```shell
183
+ Purpose: Checks whether tests coming from the rspec JSON report files has an existing test health issue opened.
184
+ Usage: exe/existing-test-health-issue [options]
185
+ -i, --input-files INPUT_FILES JSON rspec-retry report files
186
+ -p, --project PROJECT Can be an integer or a group/project string
187
+ -t, --token TOKEN A valid access token with `api` scope and Maintainer permission in PROJECT
188
+ --health-problem-type PROBLEM_TYPE
189
+ Look for the given health problem type (failures, pass-after-retry, slow)
190
+ -v, --version Show the version
191
+ -h, --help Show the usage
192
+ ```
193
+
180
194
  ### `exe/flaky-test-issues`
181
195
 
182
196
  ```shell
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "optparse"
6
+
7
+ require_relative "../lib/gitlab_quality/test_tooling"
8
+
9
+ params = {}
10
+ HEALTH_PROBLEM_TYPES = GitlabQuality::TestTooling::Report::TestHealthIssueFinder::HEALTH_PROBLEM_TYPE_TO_LABEL.keys
11
+
12
+ options = OptionParser.new do |opts|
13
+ opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
14
+
15
+ opts.on('-i', '--input-files INPUT_FILES', String, 'JSON rspec-retry report files') do |input_files|
16
+ params[:input_files] = input_files
17
+ end
18
+
19
+ opts.on('-p', '--project PROJECT', String, 'Can be an integer or a group/project string') do |project|
20
+ params[:project] = project
21
+ end
22
+
23
+ opts.on('-t', '--token TOKEN', String, 'A valid access token with `api` scope and Maintainer permission in PROJECT') do |token|
24
+ params[:token] = token
25
+ end
26
+
27
+ opts.on("--health-problem-type PROBLEM_TYPE", String, "Look for the given health problem type (#{HEALTH_PROBLEM_TYPES.join(', ')})") do |value|
28
+ raise ArgumentError, "Invalid health problem type: #{value}. Valid options are: #{HEALTH_PROBLEM_TYPES.join(', ')}" unless HEALTH_PROBLEM_TYPES.include?(value)
29
+
30
+ params[:health_problem_type] = value
31
+ end
32
+
33
+ opts.on_tail('-v', '--version', 'Show the version') do
34
+ require_relative "../lib/gitlab_quality/test_tooling/version"
35
+ puts "#{$PROGRAM_NAME} : #{GitlabQuality::TestTooling::VERSION}"
36
+ exit
37
+ end
38
+
39
+ opts.on_tail('-h', '--help', 'Show the usage') do
40
+ puts "Purpose: Checks whether tests coming from the rspec JSON report files has an existing test health issue opened."
41
+ puts opts
42
+ exit
43
+ end
44
+
45
+ opts.parse(ARGV)
46
+ end
47
+
48
+ if params.any?
49
+ raise ArgumentError, "No health problem type given. Valid options are: #{HEALTH_PROBLEM_TYPES.join(', ')}" unless params.key?(:health_problem_type)
50
+
51
+ if GitlabQuality::TestTooling::Report::TestHealthIssueFinder.new(**params).found_existing_unhealthy_test_issue?
52
+ exit 0
53
+ else
54
+ exit 1
55
+ end
56
+ else
57
+ puts options
58
+ exit 1
59
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'json'
5
+
6
+ module GitlabQuality
7
+ module TestTooling
8
+ module Report
9
+ class TestHealthIssueFinder < ReportAsIssue
10
+ HEALTH_PROBLEM_TYPE_TO_LABEL = {
11
+ 'pass-after-retry' => 'test-health:pass-after-retry',
12
+ 'slow' => 'test-health:slow',
13
+ 'failures' => 'test-health:failures'
14
+ }.freeze
15
+
16
+ def initialize(health_problem_type: [], **kwargs)
17
+ super(**kwargs)
18
+
19
+ @health_problem_type = health_problem_type
20
+ end
21
+
22
+ def found_existing_unhealthy_test_issue?
23
+ issue_url = invoke!
24
+
25
+ !issue_url.nil? && !issue_url.empty?
26
+ end
27
+
28
+ def run!
29
+ existing_issue_found = nil
30
+
31
+ applicable_tests.each do |test|
32
+ issues = find_issues_by_hash(test_hash(test), state: 'opened', labels: search_labels)
33
+ next if issues.empty?
34
+
35
+ existing_issue_found = issues.first.web_url
36
+ puts "Found an existing test health issue of type #{health_problem_type} for test #{test.file}:#{test.line_number}: #{existing_issue_found}."
37
+ break
38
+ end
39
+
40
+ puts "Did not find an existing test health issue of type #{health_problem_type}." unless existing_issue_found
41
+
42
+ existing_issue_found
43
+ end
44
+
45
+ def applicable_tests
46
+ applicable_tests = []
47
+
48
+ TestResults::Builder.new(file_glob: files, token: token, project: project).test_results_per_file do |test_results|
49
+ applicable_tests = test_results.select { |test| test_is_applicable?(test) }
50
+ end
51
+
52
+ applicable_tests
53
+ end
54
+
55
+ private
56
+
57
+ attr_reader :health_problem_type
58
+
59
+ # Be mindful about the number of tests this method would return,
60
+ # as we will make at least one API request per test.
61
+ def test_is_applicable?(test)
62
+ expected_test_status =
63
+ case health_problem_type
64
+ when 'failures'
65
+ 'failed'
66
+ else
67
+ 'passed'
68
+ end
69
+
70
+ test.status == expected_test_status
71
+ end
72
+
73
+ def search_labels
74
+ ['test', HEALTH_PROBLEM_TYPE_TO_LABEL[health_problem_type]]
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GitlabQuality
4
4
  module TestTooling
5
- VERSION = "2.0.0"
5
+ VERSION = "2.1.0"
6
6
  end
7
7
  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: 2.0.0
4
+ version: 2.1.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: 2024-10-14 00:00:00.000000000 Z
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
194
  version: 3.7.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: rspec_junit_formatter
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.6.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.6.0
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: activesupport
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -400,6 +414,7 @@ description: A collection of test-related tools.
400
414
  email:
401
415
  - quality@gitlab.com
402
416
  executables:
417
+ - existing-test-health-issue
403
418
  - failed-test-issues
404
419
  - flaky-test-issues
405
420
  - generate-test-session
@@ -429,6 +444,7 @@ files:
429
444
  - LICENSE.txt
430
445
  - README.md
431
446
  - Rakefile
447
+ - exe/existing-test-health-issue
432
448
  - exe/failed-test-issues
433
449
  - exe/flaky-test-issues
434
450
  - exe/generate-test-session
@@ -477,6 +493,7 @@ files:
477
493
  - lib/gitlab_quality/test_tooling/report/results_in_issues.rb
478
494
  - lib/gitlab_quality/test_tooling/report/results_in_test_cases.rb
479
495
  - lib/gitlab_quality/test_tooling/report/slow_test_issue.rb
496
+ - lib/gitlab_quality/test_tooling/report/test_health_issue_finder.rb
480
497
  - lib/gitlab_quality/test_tooling/report/update_screenshot_path.rb
481
498
  - lib/gitlab_quality/test_tooling/runtime/env.rb
482
499
  - lib/gitlab_quality/test_tooling/runtime/logger.rb