rspec_trunk_flaky_tests 0.12.1.pre.beta.1-arm64-darwin → 0.12.1.pre.beta.12-arm64-darwin

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45f0425cc78c2401f9e5cb60b3a027da0f47951eaa9a94a3a2a44e472cd68747
4
- data.tar.gz: f6bff613aefaaf1691ea9980d0b77f65f0a183dacc7108fe7e57604b7784c160
3
+ metadata.gz: 25c9b33903ad844202a9a2df2ae7757bf40da046c0eb94d5db5285fa2f4f0f62
4
+ data.tar.gz: 0571e6e35dcd0f65933fe0cb66b269ea8529572a0bfa8d1d6198316c62eff68c
5
5
  SHA512:
6
- metadata.gz: dc80d2f70d6b1e7ed1e6f52586cf4ab5c35cee784a8acc7af742f4528b2ce0afa46929ca1b8dbb1dd201013c1f86d4218d0f25fb6fdf669fc446ddc9ef52f815
7
- data.tar.gz: 6931066bdf58084b4795100acfca30eaf3d28a6cd9b2bf9c76c47d46c3e8b484c79c436b31c411bbe1e450c917552cf40f346806f1e863e3439821a069384635
6
+ metadata.gz: 9d344e20114b9c15092889af629be28785b14d1ae2dac43fd1ca2bde90b9d8cee80fcb7c0c127c8a90dfa1e35cfdfdeb3e9ea00e596d8c84e43ce2bc6048e24a
7
+ data.tar.gz: 7d40284107364e9a20dc0d38462bedd75eafd656cc03045af2d5c99f64c75c629c33d7245f0fde69ebbda05c7cbb4376029e2b6a29e9500cfa95c1f080df0c69
@@ -4,5 +4,31 @@ begin
4
4
  ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
5
5
  require_relative "rspec_trunk_flaky_tests/#{ruby_version}/rspec_trunk_flaky_tests"
6
6
  rescue LoadError
7
- require_relative 'rspec_trunk_flaky_tests/rspec_trunk_flaky_tests'
7
+ begin
8
+ require_relative 'rspec_trunk_flaky_tests/rspec_trunk_flaky_tests'
9
+ rescue LoadError
10
+ raise LoadError, <<~MSG
11
+ Could not load the native extension for rspec_trunk_flaky_tests.
12
+
13
+ You are using the pure ruby variant of this gem, which is a placeholder
14
+ that exists so that Gemfile.lock files with `PLATFORMS ruby` can resolve
15
+ this dependency. It does not include a precompiled native extension.
16
+
17
+ Precompiled native gems are available for:
18
+ x86_64-linux, aarch64-linux, arm64-darwin, x86_64-darwin
19
+
20
+ If you are on a supported platform and seeing this error, make sure
21
+ bundler is selecting the native variant for your platform:
22
+
23
+ bundle lock --add-platform #{RUBY_PLATFORM}
24
+ bundle install
25
+
26
+ If you are on an unsupported platform, this gem cannot be used in your
27
+ environment. Please open an issue at:
28
+ https://github.com/trunk-io/analytics-cli/issues
29
+
30
+ Current platform: #{RUBY_PLATFORM}
31
+ Current Ruby version: #{RUBY_VERSION}
32
+ MSG
33
+ end
8
34
  end
@@ -16,6 +16,7 @@
16
16
  # TRUNK_REPO_HEAD_BRANCH - HEAD branch name
17
17
  # TRUNK_REPO_HEAD_COMMIT_EPOCH - HEAD commit timestamp (seconds since epoch)
18
18
  # TRUNK_REPO_HEAD_AUTHOR_NAME - HEAD commit author name
19
+ # TRUNK_PR_NUMBER - PR number, if uploading from a PR (normally inferred from CI environment variables)
19
20
  #
20
21
  # Optional environment variables for configuration:
21
22
  # TRUNK_CODEOWNERS_PATH - Path to CODEOWNERS file
@@ -25,6 +26,7 @@
25
26
  # TRUNK_DRY_RUN - Set to 'true' to save bundle locally instead of uploading
26
27
  # TRUNK_USE_UNCLONED_REPO - Set to 'true' for uncloned repo mode
27
28
  # TRUNK_LOCAL_UPLOAD_DIR - Directory to save test results locally (disables upload)
29
+ # TRUNK_QUARANTINED_TESTS_DISK_CACHE_TTL_SECS - Time to cache quarantined tests on disk (in seconds)
28
30
  # DISABLE_RSPEC_TRUNK_FLAKY_TESTS - Set to 'true' to completely disable Trunk
29
31
  #
30
32
  require 'rspec/core'
@@ -64,7 +66,8 @@ end
64
66
 
65
67
  def knapsack_detector_command?
66
68
  command_line = "#{$PROGRAM_NAME} #{ARGV.join(' ')}".strip
67
- command_line.include?('knapsack_pro:rspec_test_example_detector')
69
+ command_line.include?('knapsack_pro:rspec_test_example_detector') ||
70
+ command_line.include?('knapsack_pro:queue:rspec:initialize')
68
71
  end
69
72
 
70
73
  def trunk_disabled
@@ -72,8 +75,9 @@ def trunk_disabled
72
75
  ENV['TRUNK_ORG_URL_SLUG'].nil? || ENV['TRUNK_API_TOKEN'].nil?
73
76
  end
74
77
 
75
- # we want to cache the test report so we can add to it as we go and reduce the number of API calls
78
+ # we want to cache the test report in memory so we can add to it as we go and reduce the number of API calls
76
79
  $test_report = TestReport.new('rspec', "#{$PROGRAM_NAME} #{ARGV.join(' ')}", nil)
80
+ $failure_encountered_and_quarantining_disabled = false
77
81
 
78
82
  module RSpec
79
83
  module Core
@@ -85,20 +89,34 @@ module RSpec
85
89
  # RSpec uses the existance of an exception to determine if the test failed
86
90
  # We need to override this to allow us to capture the exception and then
87
91
  # decide if we want to fail the test or not
88
- # trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength,rubocop/Naming/AccessorMethodName)
92
+ # trunk-ignore(rubocop/Naming/AccessorMethodName)
89
93
  def set_exception(exception)
90
94
  return set_exception_core(exception) if metadata[:pending]
91
95
  return set_exception_core(exception) if trunk_disabled
92
96
  return set_exception_core(exception) if metadata[:retry_attempts]&.positive?
93
97
 
98
+ handle_quarantine_check(exception)
99
+ end
100
+
101
+ # trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength)
102
+ def handle_quarantine_check(exception)
94
103
  id = generate_trunk_id
95
104
  name = full_description
96
105
  parent_name = example_group.metadata[:description]
97
106
  parent_name = parent_name.empty? ? 'rspec' : parent_name
98
107
  file = escape(metadata[:file_path])
99
108
  classname = file.sub(%r{\.[^/.]+\Z}, '').gsub('/', '.').gsub(/\A\.+|\.+\Z/, '')
100
- puts "Test failed, checking if it can be quarantined: `#{location}`".yellow
101
- if $test_report.is_quarantined(id, name, parent_name, classname, file)
109
+ unless $failure_encountered_and_quarantining_disabled
110
+ puts "Test failed, checking if it can be quarantined: `#{location}`".yellow
111
+ end
112
+ is_quarantined_result = $test_report.is_quarantined(id, name, parent_name, classname, file)
113
+ if is_quarantined_result.quarantining_disabled_for_repo
114
+ unless $failure_encountered_and_quarantining_disabled
115
+ puts 'Quarantining is disabled for this repo, no failures will be quarantined'.yellow
116
+ $failure_encountered_and_quarantining_disabled = true
117
+ end
118
+ set_exception_core(exception)
119
+ elsif is_quarantined_result.test_is_quarantined
102
120
  # monitor the override in the metadata
103
121
  metadata[:quarantined_exception] = exception
104
122
  puts "Test is quarantined, overriding exception: #{exception}".green
@@ -168,9 +186,40 @@ module RSpec
168
186
  end
169
187
  end
170
188
 
189
+ def format_exception_message(exception)
190
+ case exception
191
+ when RSpec::Core::MultipleExceptionError
192
+ # MultipleExceptionError contains multiple exceptions in @exceptions array
193
+ messages = exception.all_exceptions.map { |e| "#{e.class}: #{e.message}" }
194
+ "#{exception.class}: #{messages.join(' | ')}"
195
+ else
196
+ exception.to_s
197
+ end
198
+ end
199
+
200
+ # trunk-ignore(rubocop/Metrics/MethodLength)
201
+ def format_exception_backtrace(exception)
202
+ case exception
203
+ when RSpec::Core::MultipleExceptionError
204
+ # Collect backtraces from all nested exceptions
205
+ backtraces = exception.all_exceptions.map do |e|
206
+ if e.backtrace && !e.backtrace.empty?
207
+ "#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
208
+ else
209
+ "#{e.class}: #{e.message}"
210
+ end
211
+ end
212
+ backtraces.join("\n\n")
213
+ else
214
+ exception.backtrace&.join("\n") || ''
215
+ end
216
+ end
217
+
171
218
  # TrunkAnalyticsListener is a class that is used to listen to the execution of the Example class
172
219
  # it generates and submits the final test reports
173
220
  class TrunkAnalyticsListener
221
+ MAX_TEXT_FIELD_SIZE = 8_000
222
+
174
223
  def initialize
175
224
  @testreport = $test_report
176
225
  end
@@ -181,6 +230,9 @@ class TrunkAnalyticsListener
181
230
 
182
231
  # trunk-ignore(rubocop/Metrics/MethodLength)
183
232
  def close(_notification)
233
+ if $failure_encountered_and_quarantining_disabled
234
+ puts 'Note: Quarantining is disabled for this repo. Test failures were not quarantined.'.yellow
235
+ end
184
236
  if ENV['TRUNK_LOCAL_UPLOAD_DIR']
185
237
  saved = @testreport.try_save(ENV['TRUNK_LOCAL_UPLOAD_DIR'])
186
238
  if saved
@@ -200,8 +252,15 @@ class TrunkAnalyticsListener
200
252
 
201
253
  # trunk-ignore(rubocop/Metrics/CyclomaticComplexity,rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength)
202
254
  def add_test_case(example)
203
- failure_message = example.exception.to_s if example.exception
204
- failure_message = example.metadata[:quarantined_exception].to_s if example.metadata[:quarantined_exception]
255
+ exception = example.exception || example.metadata[:quarantined_exception]
256
+ failure_message = ''
257
+ backtrace = ''
258
+ if exception
259
+ failure_message = format_exception_message(exception)
260
+ backtrace = format_exception_backtrace(exception)
261
+ end
262
+ failure_message = failure_message[0...MAX_TEXT_FIELD_SIZE] if failure_message.length > MAX_TEXT_FIELD_SIZE
263
+ backtrace = backtrace[0...MAX_TEXT_FIELD_SIZE] if backtrace.length > MAX_TEXT_FIELD_SIZE
205
264
  # TODO: should we use concatenated string or alias when auto-generated description?
206
265
  name = example.full_description
207
266
  file = escape(example.metadata[:file_path])
@@ -226,7 +285,7 @@ class TrunkAnalyticsListener
226
285
  parent_name = example.example_group.metadata[:description]
227
286
  parent_name = parent_name.empty? ? 'rspec' : parent_name
228
287
  @testreport.add_test(id, name, classname, file, parent_name, line, status, attempt_number,
229
- started_at, finished_at, failure_message || '', is_quarantined)
288
+ started_at, finished_at, failure_message || '', backtrace || '', is_quarantined)
230
289
  end
231
290
  end
232
291
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_trunk_flaky_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1.pre.beta.1
4
+ version: 0.12.1.pre.beta.12
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Trunk Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-19 00:00:00.000000000 Z
11
+ date: 2026-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -52,11 +52,13 @@ files:
52
52
  - lib/rspec_trunk_flaky_tests/3.2/rspec_trunk_flaky_tests.bundle
53
53
  - lib/rspec_trunk_flaky_tests/3.3/rspec_trunk_flaky_tests.bundle
54
54
  - lib/rspec_trunk_flaky_tests/3.4/rspec_trunk_flaky_tests.bundle
55
+ - lib/rspec_trunk_flaky_tests/4.0/rspec_trunk_flaky_tests.bundle
55
56
  - lib/trunk_spec_helper.rb
56
57
  homepage: https://docs.trunk.io/flaky-tests/get-started/frameworks/rspec
57
58
  licenses:
58
59
  - MIT
59
- metadata: {}
60
+ metadata:
61
+ source_code_uri: https://github.com/trunk-io/analytics-cli/tree/main/rspec-trunk-flaky-tests
60
62
  post_install_message:
61
63
  rdoc_options: []
62
64
  require_paths:
@@ -68,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
70
  version: '3.0'
69
71
  - - "<"
70
72
  - !ruby/object:Gem::Version
71
- version: 3.5.dev
73
+ version: 4.1.dev
72
74
  required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  requirements:
74
76
  - - ">="