datadog-ci 1.23.1 → 1.23.2

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: d28b3d81843fefd07c4b75b21cfb7e9ffc288525e3368ce5752e209d43276e64
4
- data.tar.gz: 3dbd4a467c2e2cee7ebea4cdfdc0487bba97f74d7672eaae729f4c00a2094d3c
3
+ metadata.gz: 660ce0996ea0998e1074ca1f3671b00b74659b31520486c0fec7f850cf619c40
4
+ data.tar.gz: b3fa584967668ee53d4f66b9c4963236b1fbe58367f4833bf1436064a5112773
5
5
  SHA512:
6
- metadata.gz: 3d6cd831349cac64cf1abb7a80490dca5c94a503febf632cf2678bde4a5ef440fd6ecf6172ba870887d7c49e169f81cc82a2410a9acd4f9a40847062bcfcdfea
7
- data.tar.gz: 5c84eede97a6985e858d0acade39b2457f38362afa837277d95b40a4372e89f1f5128005a94141d3799d324a0642ddb46c4aaaa93c5f160e5d79b5dbc3d530d9
6
+ metadata.gz: 8c99eab8f2b7f6367627746f94cb1338e77000791f89a96767f23572c43d13d96384b7f9b85c494d64bbef34dbbc0659123b31df14976a1de973075ce7bcb657
7
+ data.tar.gz: 5eab6749fe723823f6bcade1f946e9669924b3299219b7a9e67c1db1b8ac12483ffb910aedbd4be145839dd7a17ac0527d95ec36358cd2f2cee82387b6d136b9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.23.2] - 2025-11-18
4
+
5
+ ### Added
6
+ * Test discovery mode for minitest ([#418][])
7
+
8
+ ### Changed
9
+ * DDTest integration, tests discovery: change format of tests.json file ([#416][])
10
+
11
+ ### Fixed
12
+ * Fix: rename wrong test.retry_reason value for Auto Test Retries feature ([#425][])
13
+
3
14
  ## [1.23.1] - 2025-10-14
4
15
 
5
16
  ========== Changelog ==========
@@ -537,7 +548,8 @@ Currently test suite level visibility is not used by our instrumentation: it wil
537
548
 
538
549
  - Ruby versions < 2.7 no longer supported ([#8][])
539
550
 
540
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.23.1...main
551
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.23.2...main
552
+ [1.23.2]: https://github.com/DataDog/datadog-ci-rb/compare/v1.23.1...v1.23.2
541
553
  [1.23.1]: https://github.com/DataDog/datadog-ci-rb/compare/v1.23.0...v1.23.1
542
554
  [1.23.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.22.1...v1.23.0
543
555
  [1.22.1]: https://github.com/DataDog/datadog-ci-rb/compare/v1.22.0...v1.22.1
@@ -763,4 +775,7 @@ Currently test suite level visibility is not used by our instrumentation: it wil
763
775
  [#402]: https://github.com/DataDog/datadog-ci-rb/issues/402
764
776
  [#407]: https://github.com/DataDog/datadog-ci-rb/issues/407
765
777
  [#410]: https://github.com/DataDog/datadog-ci-rb/issues/410
766
- [#414]: https://github.com/DataDog/datadog-ci-rb/issues/414
778
+ [#414]: https://github.com/DataDog/datadog-ci-rb/issues/414
779
+ [#416]: https://github.com/DataDog/datadog-ci-rb/issues/416
780
+ [#418]: https://github.com/DataDog/datadog-ci-rb/issues/418
781
+ [#425]: https://github.com/DataDog/datadog-ci-rb/issues/425
@@ -96,6 +96,14 @@ module Datadog
96
96
  # timecop configuration
97
97
  configure_time_providers(settings)
98
98
 
99
+ # first check if we are in test discovery mode and configure library accordingly
100
+ # @type ivar @test_discovery: Datadog::CI::TestDiscovery::Component
101
+ @test_discovery = TestDiscovery::Component.new(
102
+ enabled: settings.ci.test_discovery_enabled,
103
+ output_path: settings.ci.test_discovery_output_path
104
+ )
105
+ @test_discovery.disable_features_for_test_discovery!(settings)
106
+
99
107
  # Configure Datadog::Tracing module
100
108
 
101
109
  # No need not use 128-bit trace ids for test visibility,
@@ -115,13 +123,6 @@ module Datadog
115
123
 
116
124
  settings.tracing.test_mode.writer_options = trace_writer_options
117
125
 
118
- # @type ivar @test_discovery: Datadog::CI::TestDiscovery::Component
119
- @test_discovery = TestDiscovery::Component.new(
120
- enabled: settings.ci.test_discovery_enabled,
121
- output_path: settings.ci.test_discovery_output_path
122
- )
123
- @test_discovery.disable_features_for_test_discovery!(settings)
124
-
125
126
  @git_tree_upload_worker = build_git_upload_worker(settings, test_visibility_api)
126
127
  @ci_remote = Remote::Component.new(
127
128
  library_settings_client: build_library_settings_client(settings, test_visibility_api),
@@ -10,7 +10,7 @@ module Datadog
10
10
  return nil if method.nil?
11
11
 
12
12
  test_suite_name = test_suite_name(klass, method)
13
- source_file, line_number = extract_source_location_from_class(klass)
13
+ source_file, line_number = extract_runnable_source_location(klass, method)
14
14
 
15
15
  test_suite_tags = if source_file
16
16
  {
@@ -32,11 +32,7 @@ module Datadog
32
32
  end
33
33
 
34
34
  def self.test_suite_name(klass, method_name)
35
- source_location = extract_source_location_from_class(klass)&.first
36
- # if we are in anonymous class, fallback to the method source location
37
- if source_location.nil?
38
- source_location, = klass.instance_method(method_name).source_location
39
- end
35
+ source_location = extract_runnable_source_location(klass, method_name)&.first
40
36
 
41
37
  # According to https://github.com/DataDog/datadog-ci-rb/issues/386
42
38
  # the source file path coould be relative when using minitest mixins.
@@ -54,6 +50,14 @@ module Datadog
54
50
  "#{klass.name} at #{source_file_path}"
55
51
  end
56
52
 
53
+ def self.extract_runnable_source_location(klass, method_name)
54
+ source_location = extract_source_location_from_class(klass)
55
+ if source_location.nil? || source_location.empty?
56
+ return klass.instance_method(method_name).source_location
57
+ end
58
+ source_location
59
+ end
60
+
57
61
  def self.parallel?(klass)
58
62
  klass.ancestors.include?(::Minitest::Parallel::Test) ||
59
63
  (defined?(::Minitest::Queue) && ::Minitest.singleton_class.ancestors.include?(::Minitest::Queue))
@@ -54,6 +54,16 @@ module Datadog
54
54
  result
55
55
  end
56
56
 
57
+ def run(*args)
58
+ if datadog_configuration[:enabled] && test_discovery_component.enabled?
59
+ ::Minitest.seed = 1
60
+ discover_tests
61
+
62
+ return true
63
+ end
64
+ super
65
+ end
66
+
57
67
  private
58
68
 
59
69
  def datadog_integration
@@ -71,6 +81,33 @@ module Datadog
71
81
  def test_retries_component
72
82
  Datadog.send(:components).test_retries
73
83
  end
84
+
85
+ def test_discovery_component
86
+ Datadog.send(:components).test_discovery
87
+ end
88
+
89
+ def discover_tests
90
+ test_discovery_component.start
91
+
92
+ ::Minitest::Runnable.runnables.each do |test_class|
93
+ test_class.runnable_methods.each do |test_method|
94
+ test_suite_name = Helpers.test_suite_name(test_class, test_method)
95
+
96
+ source_path = Helpers.extract_runnable_source_location(test_class, test_method)&.first
97
+ source_path = Git::LocalRepository.relative_to_root(source_path) if source_path
98
+
99
+ test_discovery_component.record_test(
100
+ name: test_method,
101
+ suite: test_suite_name,
102
+ parameters: nil,
103
+ module_name: Ext::FRAMEWORK,
104
+ source_file: source_path
105
+ )
106
+ end
107
+ end
108
+
109
+ test_discovery_component.finish
110
+ end
74
111
  end
75
112
  end
76
113
  end
@@ -19,8 +19,8 @@ module Datadog
19
19
 
20
20
  module InstanceMethods
21
21
  def run(*args)
22
- return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled]
23
22
  return super unless datadog_configuration[:enabled]
23
+ return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled]
24
24
 
25
25
  test_suite_span = test_visibility_component.start_test_suite(datadog_test_suite_name) if ci_queue?
26
26
 
@@ -129,37 +129,6 @@ module Datadog
129
129
  )
130
130
  end
131
131
 
132
- def datadog_unskippable?
133
- !!metadata[CI::Ext::Test::ITR_UNSKIPPABLE_OPTION]
134
- end
135
-
136
- private
137
-
138
- def fetch_top_level_example_group
139
- example_group = metadata[:example_group]
140
- parent_example_group = example_group[:parent_example_group]
141
-
142
- return example_group unless parent_example_group
143
-
144
- res = parent_example_group
145
- while (parent = res[:parent_example_group])
146
- res = parent
147
- end
148
- res
149
- end
150
-
151
- def datadog_integration
152
- CI::Contrib::Instrumentation.fetch_integration(:rspec)
153
- end
154
-
155
- def datadog_configuration
156
- Datadog.configuration.ci[:rspec]
157
- end
158
-
159
- def datadog_test_suite_description
160
- @datadog_test_suite_description ||= fetch_top_level_example_group[:description]
161
- end
162
-
163
132
  def datadog_test_name
164
133
  return @datadog_test_name if defined?(@datadog_test_name)
165
134
 
@@ -195,6 +164,41 @@ module Datadog
195
164
  )
196
165
  end
197
166
 
167
+ def datadog_unskippable?
168
+ !!metadata[CI::Ext::Test::ITR_UNSKIPPABLE_OPTION]
169
+ end
170
+
171
+ def datadog_test_suite_source_file_path
172
+ Git::LocalRepository.relative_to_root(metadata[:rerun_file_path])
173
+ end
174
+
175
+ private
176
+
177
+ def fetch_top_level_example_group
178
+ example_group = metadata[:example_group]
179
+ parent_example_group = example_group[:parent_example_group]
180
+
181
+ return example_group unless parent_example_group
182
+
183
+ res = parent_example_group
184
+ while (parent = res[:parent_example_group])
185
+ res = parent
186
+ end
187
+ res
188
+ end
189
+
190
+ def datadog_integration
191
+ CI::Contrib::Instrumentation.fetch_integration(:rspec)
192
+ end
193
+
194
+ def datadog_configuration
195
+ Datadog.configuration.ci[:rspec]
196
+ end
197
+
198
+ def datadog_test_suite_description
199
+ @datadog_test_suite_description ||= fetch_top_level_example_group[:description]
200
+ end
201
+
198
202
  def test_visibility_component
199
203
  Datadog.send(:components).test_visibility
200
204
  end
@@ -32,10 +32,7 @@ module Datadog
32
32
  end
33
33
 
34
34
  def new_configuration
35
- settings = Configuration::Settings.new
36
- # if we are running in test discovery mode, we are most likely running in dry run - we need to allow it
37
- settings.dry_run_enabled = true if test_discovery_component&.enabled?
38
- settings
35
+ Configuration::Settings.new
39
36
  end
40
37
 
41
38
  def patcher
@@ -16,9 +16,17 @@ module Datadog
16
16
 
17
17
  module InstanceMethods
18
18
  def run_specs(*args)
19
- return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled]
20
19
  return super unless datadog_configuration[:enabled]
21
20
 
21
+ if test_discovery_component.enabled?
22
+ discover_tests
23
+
24
+ # don't run the tests, we just needed to discover them and now we can return
25
+ return
26
+ end
27
+
28
+ return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled]
29
+
22
30
  test_session = test_visibility_component.start_test_session(
23
31
  tags: {
24
32
  CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
@@ -61,6 +69,30 @@ module Datadog
61
69
  def test_visibility_component
62
70
  Datadog.send(:components).test_visibility
63
71
  end
72
+
73
+ def test_discovery_component
74
+ Datadog.send(:components).test_discovery
75
+ end
76
+
77
+ def discover_tests
78
+ test_discovery_component.start
79
+
80
+ examples = ::RSpec.world.all_examples
81
+
82
+ examples.each do |example|
83
+ next if example.metadata[:skip]
84
+
85
+ test_discovery_component.record_test(
86
+ name: example.datadog_test_name,
87
+ suite: example.datadog_test_suite_name,
88
+ parameters: example.datadog_test_parameters,
89
+ module_name: Ext::FRAMEWORK,
90
+ source_file: example.datadog_test_suite_source_file_path
91
+ )
92
+ end
93
+
94
+ test_discovery_component.finish
95
+ end
64
96
  end
65
97
  end
66
98
  end
@@ -156,7 +156,7 @@ module Datadog
156
156
  # possible reasons why a test was retried
157
157
  module RetryReason
158
158
  RETRY_DETECT_FLAKY = "early_flake_detection"
159
- RETRY_FAILED = "auto_test_retries"
159
+ RETRY_FAILED = "auto_test_retry"
160
160
  RETRY_FLAKY_FIXED = "attempt_to_fix"
161
161
  RETRY_EXTERNAL = "external"
162
162
 
@@ -10,6 +10,7 @@ require_relative "packfiles"
10
10
 
11
11
  require_relative "../ext/telemetry"
12
12
  require_relative "../utils/telemetry"
13
+ require_relative "../utils/test_run"
13
14
 
14
15
  module Datadog
15
16
  module CI
@@ -33,6 +34,11 @@ module Datadog
33
34
  return
34
35
  end
35
36
 
37
+ if Utils::TestRun.test_optimization_data_cached?
38
+ Datadog.logger.debug("DDTest cache found, git upload already done by DDTest tool, skipping git upload")
39
+ return
40
+ end
41
+
36
42
  Datadog.logger.debug { "Uploading git tree for repository #{repository_url}" }
37
43
 
38
44
  latest_commits = LocalRepository.git_commits
@@ -60,6 +60,12 @@ module Datadog
60
60
  get_tag(Ext::Test::TAG_TEST_MODULE_ID)
61
61
  end
62
62
 
63
+ # Name of the running test module this test belongs to.
64
+ # @return [String] the name of the test module.
65
+ def test_module_name
66
+ get_tag(Ext::Test::TAG_MODULE)
67
+ end
68
+
63
69
  # Span id of the running test session this test belongs to.
64
70
  # @return [String] the span id of the test session.
65
71
  def test_session_id
@@ -216,9 +222,7 @@ module Datadog
216
222
 
217
223
  # @internal
218
224
  def datadog_skip_reason
219
- if in_test_discovery_mode?
220
- Ext::Test::SkipReason::TEST_DISCOVERY_MODE
221
- elsif skipped_by_test_impact_analysis?
225
+ if skipped_by_test_impact_analysis?
222
226
  Ext::Test::SkipReason::TEST_IMPACT_ANALYSIS
223
227
  elsif disabled? || quarantined?
224
228
  Ext::Test::SkipReason::TEST_MANAGEMENT_DISABLED
@@ -227,7 +231,7 @@ module Datadog
227
231
 
228
232
  # @internal
229
233
  def should_skip?
230
- in_test_discovery_mode? || skipped_by_test_impact_analysis? || (disabled? && !attempt_to_fix?)
234
+ skipped_by_test_impact_analysis? || (disabled? && !attempt_to_fix?)
231
235
  end
232
236
 
233
237
  # @internal
@@ -240,16 +244,6 @@ module Datadog
240
244
  get_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) == "true"
241
245
  end
242
246
 
243
- # @internal
244
- def in_test_discovery_mode?
245
- !!@in_test_discovery_mode
246
- end
247
-
248
- # @internal
249
- def mark_test_discovery_mode!
250
- @in_test_discovery_mode = true
251
- end
252
-
253
247
  private
254
248
 
255
249
  def record_test_result(datadog_status)
@@ -48,7 +48,7 @@ module Datadog
48
48
  settings.ci.impacted_tests_detection_enabled = false
49
49
  end
50
50
 
51
- def on_test_session_start
51
+ def start
52
52
  return unless @enabled
53
53
 
54
54
  if @output_path.nil? || @output_path&.empty?
@@ -67,7 +67,7 @@ module Datadog
67
67
  @buffer_mutex.synchronize { @buffer.clear }
68
68
  end
69
69
 
70
- def on_test_session_end
70
+ def finish
71
71
  return unless @enabled
72
72
 
73
73
  @buffer_mutex.synchronize do
@@ -75,19 +75,13 @@ module Datadog
75
75
  end
76
76
  end
77
77
 
78
- def on_test_started(test)
79
- return unless @enabled
80
-
81
- # Mark test as being in test discovery mode so it will be skipped
82
- # even if we are not running in dry run mode.
83
- test.mark_test_discovery_mode!
84
-
78
+ def record_test(name:, suite:, module_name:, parameters:, source_file:)
85
79
  test_info = {
86
- "name" => test.name,
87
- "suite" => test.test_suite_name,
88
- "sourceFile" => test.source_file,
89
- "suiteSourceFile" => test.test_suite&.source_file,
90
- "fqn" => test.datadog_test_id
80
+ "name" => name,
81
+ "suite" => suite,
82
+ "module" => module_name,
83
+ "parameters" => parameters,
84
+ "suiteSourceFile" => source_file
91
85
  }
92
86
 
93
87
  Datadog.logger.debug { "Discovered test: #{test_info}" }
@@ -20,6 +20,11 @@ module Datadog
20
20
  end
21
21
 
22
22
  def call
23
+ Datadog::Core.log_deprecation do
24
+ "Skippable percentage command is deprecated and will be removed in 2.0. Use DDTest tool instead." \
25
+ "More information: https://github.com/DataDog/ddtest "
26
+ end
27
+
23
28
  return 0.0 if @failed
24
29
 
25
30
  require_rspec!
@@ -24,6 +24,11 @@ module Datadog
24
24
  end
25
25
 
26
26
  def call
27
+ Datadog::Core.log_deprecation do
28
+ "Skippable percentage command is deprecated and will be removed in 2.0. Use DDTest tool instead." \
29
+ "More information: https://github.com/DataDog/ddtest "
30
+ end
31
+
27
32
  return 0.0 if @failed
28
33
 
29
34
  Datadog.configure do |c|
@@ -273,8 +273,6 @@ module Datadog
273
273
  # Signal Remote::Component to configure the library.
274
274
  # Note that it will call this component back (unfortunate circular dependency).
275
275
  remote.configure(test_session)
276
-
277
- test_discovery&.on_test_session_start
278
276
  end
279
277
 
280
278
  # intentionally empty
@@ -310,8 +308,6 @@ module Datadog
310
308
  test_optimisation.start_coverage(test)
311
309
 
312
310
  test_retries.record_test_started(test)
313
-
314
- test_discovery&.on_test_started(test)
315
311
  end
316
312
 
317
313
  def on_test_session_finished(test_session)
@@ -321,8 +317,6 @@ module Datadog
321
317
 
322
318
  Telemetry.event_finished(test_session)
323
319
 
324
- test_discovery&.on_test_session_end
325
-
326
320
  Utils::FileStorage.cleanup
327
321
  end
328
322
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "json"
4
4
  require_relative "file_storage"
5
+ require_relative "test_run"
5
6
  require_relative "../ext/dd_test"
6
7
 
7
8
  module Datadog
@@ -22,7 +23,7 @@ module Datadog
22
23
  # Load component state
23
24
  def load_component_state
24
25
  # Check for DDTest cache first
25
- if Dir.exist?(Ext::DDTest::TESTOPTIMIZATION_CACHE_PATH)
26
+ if TestRun.test_optimization_data_cached?
26
27
  Datadog.logger.debug { "DDTest cache found" }
27
28
  return true if restore_state_from_datadog_test_runner
28
29
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "etc"
4
4
 
5
+ require_relative "../ext/dd_test"
6
+
5
7
  module Datadog
6
8
  module CI
7
9
  module Utils
@@ -42,6 +44,10 @@ module Datadog
42
44
 
43
45
  @virtual_cpu_count = ::Etc.nprocessors
44
46
  end
47
+
48
+ def self.test_optimization_data_cached?
49
+ Dir.exist?(Ext::DDTest::TESTOPTIMIZATION_CACHE_PATH)
50
+ end
45
51
  end
46
52
  end
47
53
  end
@@ -5,7 +5,7 @@ module Datadog
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 23
8
- PATCH = 1
8
+ PATCH = 2
9
9
  PRE = nil
10
10
  BUILD = nil
11
11
  # PRE and BUILD above are modified for dev gems during gem build GHA workflow
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.23.1
4
+ version: 1.23.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.