diff_test 0.3.0 → 0.4.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/README.md +41 -2
- data/lib/diff_test/configuration.rb +50 -8
- data/lib/diff_test/helper.rb +34 -1
- data/lib/diff_test/impacted_file_tracker.rb +11 -2
- data/lib/diff_test/integrations/active_record/integration.rb +28 -0
- data/lib/diff_test/integrations/active_record/test_fixtures_ext.rb +22 -0
- data/lib/diff_test/integrations/minitest/lifecycle.rb +55 -44
- data/lib/diff_test/integrations/rails_js/railtie.rb +1 -1
- data/lib/diff_test/should_run_decider.rb +3 -0
- data/lib/diff_test/test_execution.rb +3 -4
- data/lib/diff_test/test_suite_execution.rb +16 -25
- data/lib/diff_test/trackers/base.rb +10 -2
- data/lib/diff_test/trackers/constant.rb +63 -0
- data/lib/diff_test/trackers/ruby_file.rb +14 -3
- data/lib/diff_test/trackers/singleton_base.rb +10 -2
- data/lib/diff_test/version.rb +1 -1
- data/lib/diff_test.rb +12 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddeb2f4b0a8c3b760e6a548aecfe8fb72a0d4ae78d1e6234f6813729bca18d82
|
4
|
+
data.tar.gz: 23680b38854d9e07fb0d9c7fb982055653efe70aa6b4cc9c4e17e5d10168b172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9cdc48a24aeedd64dcab7ca29fb5db7495270c185fb9a3cfc172af12f499111a59bc8efecb787c5b32c6ba4e4cb77946bb7a7153ea27d084da5c6a235bbeb68
|
7
|
+
data.tar.gz: c655b85c2c21d5be0f1c1df04130ed996119f6a3a5213ef8ab7fb23b6d3bc7d4632ec2ae67d6013da6c2814c481ed5f8b51a5878c722069af2cd4e3730c32ae9
|
data/README.md
CHANGED
@@ -202,7 +202,46 @@ DiffTestWeb
|
|
202
202
|
|
203
203
|
|
204
204
|
# TODO
|
205
|
+
x Perforamnce
|
206
|
+
x Limit results
|
207
|
+
x Tests pass weh nwe are down
|
208
|
+
x Same key /workflow_id succeeds
|
209
|
+
x Unskippable branches
|
210
|
+
x Skip from branch/commit/author name
|
205
211
|
- Initialier/install script
|
206
212
|
- Set unskippable
|
207
|
-
|
208
|
-
-
|
213
|
+
x Wrap run_one_method ?
|
214
|
+
- skip setup hooks
|
215
|
+
- tracks stuff in before_setup as well
|
216
|
+
- path/skip setup_fixtures
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
46s - plain
|
223
|
+
50s - with rubyfile enable/disable clear
|
224
|
+
68s - with tracepoint but immediate next
|
225
|
+
118s - with tracepoint but push
|
226
|
+
424s - with tracepoint but processing like it should
|
227
|
+
186s - with tracepoint but processing like it should (Except c_call)
|
228
|
+
73s - just reading event.path inside breakpoint
|
229
|
+
|
230
|
+
|
231
|
+
18s - all skipped
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
test/services/zoom_webhook_event_processor_test.rb
|
236
|
+
06.00s - No Diff Test
|
237
|
+
|
238
|
+
41.15s - Diff Testc
|
239
|
+
37.52 - Diff Testc(only file)
|
240
|
+
13.52 - Diff Testc(only constant)
|
241
|
+
10.00 - Diff Testc(only tracepoint)
|
242
|
+
|
243
|
+
21.62s - Diff Test
|
244
|
+
20.08 - Diff Test (only file)
|
245
|
+
11.50 - Diff Test (only constant)
|
246
|
+
10.50 - Diff Test (only tracepoint)
|
247
|
+
12.68 - Diff Test (constant + file_in_project + add to set)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module DiffTest
|
2
2
|
class Configuration
|
3
3
|
attr_writer \
|
4
|
+
:enabled,
|
5
|
+
:run_on_main_branch,
|
4
6
|
:api_key,
|
5
7
|
:project_root,
|
6
8
|
:vendor_bundle_path,
|
@@ -19,9 +21,9 @@ module DiffTest
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def project_root
|
22
|
-
return @project_root if @project_root
|
24
|
+
return @project_root.freeze if @project_root
|
23
25
|
|
24
|
-
@project_root = ::Rails.root.to_s if defined?(::Rails)
|
26
|
+
@project_root = ::Rails.root.to_s.freeze if defined?(::Rails)
|
25
27
|
|
26
28
|
unless @project_root
|
27
29
|
raise "Please specify a project root in config/environments/test.rb using
|
@@ -35,9 +37,9 @@ module DiffTest
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def vendor_bundle_path
|
38
|
-
return @vendor_bundle_path if @vendor_bundle_path
|
40
|
+
return @vendor_bundle_path.freeze if @vendor_bundle_path
|
39
41
|
|
40
|
-
@vendor_bundle_path = File.join(project_root, 'vendor', 'bundle').to_s if defined?(::Rails)
|
42
|
+
@vendor_bundle_path = File.join(project_root, 'vendor', 'bundle').to_s.freeze if defined?(::Rails)
|
41
43
|
end
|
42
44
|
|
43
45
|
def project_files
|
@@ -111,6 +113,46 @@ module DiffTest
|
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
116
|
+
def enabled(&block)
|
117
|
+
if block_given?
|
118
|
+
@enabled = block
|
119
|
+
else
|
120
|
+
@enabled
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def integratable?
|
125
|
+
return false if ENV['DIFF_TEST_DISABLED'] == '1'
|
126
|
+
return false if defined?(::Rails) && !Rails.env.test?
|
127
|
+
return false if DiffTest::Helper.on_skipped_branch?
|
128
|
+
return false if DiffTest::Helper.on_skipped_commit?
|
129
|
+
|
130
|
+
true
|
131
|
+
end
|
132
|
+
|
133
|
+
def enabled?
|
134
|
+
if !integratable?
|
135
|
+
false
|
136
|
+
elsif DiffTest::Helper.on_main_branch? && !run_on_main_branch?
|
137
|
+
false
|
138
|
+
elsif @enabled.respond_to?(:call)
|
139
|
+
arity = @enabled.arity
|
140
|
+
args = []
|
141
|
+
args << DiffTest::Helper.branch_name if arity >= 1
|
142
|
+
args << DiffTest::Helper.committer_email if arity >= 2
|
143
|
+
args << DiffTest::Helper.commit_title if arity >= 3
|
144
|
+
@enabled.call(*args)
|
145
|
+
elsif @enabled.nil?
|
146
|
+
true
|
147
|
+
else
|
148
|
+
@enabled
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def run_on_main_branch?
|
153
|
+
@run_on_main_branch.nil? ? true : @run_on_main_branch
|
154
|
+
end
|
155
|
+
|
114
156
|
def auto_annotate_js_files?
|
115
157
|
case auto_annotate_js_files
|
116
158
|
when :ci
|
@@ -129,6 +171,10 @@ module DiffTest
|
|
129
171
|
@auto_annotate_js_files = value.nil? ? !!value : value
|
130
172
|
end
|
131
173
|
|
174
|
+
def base_api_url
|
175
|
+
@base_api_url || "https://diff-test.owaiskhan.me"
|
176
|
+
end
|
177
|
+
|
132
178
|
private
|
133
179
|
|
134
180
|
def file_matches_pattern?(file_path, pattern)
|
@@ -173,9 +219,5 @@ module DiffTest
|
|
173
219
|
File.file?(DiffTest::Helper.expand_path(file_path))
|
174
220
|
end.to_set
|
175
221
|
end
|
176
|
-
|
177
|
-
def base_api_url
|
178
|
-
@base_api_url || "https://diff-test.owaiskhan.me"
|
179
|
-
end
|
180
222
|
end
|
181
223
|
end
|
data/lib/diff_test/helper.rb
CHANGED
@@ -2,14 +2,19 @@ module DiffTest
|
|
2
2
|
module Helper
|
3
3
|
module_function
|
4
4
|
|
5
|
+
RELATIVE_PATH_FROM_PROJECT_ROOT_CACHE = {}
|
6
|
+
|
5
7
|
def test_id(test_file_path, test_name)
|
6
8
|
[test_file_path, test_name].join(':')
|
7
9
|
end
|
8
10
|
|
9
11
|
def relative_path_from_project_root(file_path)
|
12
|
+
value = RELATIVE_PATH_FROM_PROJECT_ROOT_CACHE[file_path]
|
13
|
+
return value unless value.nil?
|
14
|
+
|
10
15
|
raise 'Expected file_path to be an absolute path' unless file_path.start_with?('/')
|
11
16
|
|
12
|
-
Pathname.new(file_path).relative_path_from(DiffTest.configuration.project_root).to_s
|
17
|
+
RELATIVE_PATH_FROM_PROJECT_ROOT_CACHE[file_path] = Pathname.new(file_path).relative_path_from(DiffTest.configuration.project_root).to_s.freeze
|
13
18
|
end
|
14
19
|
|
15
20
|
def relative_const_source_path_from_project_root(const_name)
|
@@ -33,5 +38,33 @@ module DiffTest
|
|
33
38
|
def expand_path(file_path)
|
34
39
|
File.expand_path(file_path, DiffTest.configuration.project_root)
|
35
40
|
end
|
41
|
+
|
42
|
+
def on_main_branch?
|
43
|
+
branch_name == 'master' || branch_name == 'main'
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_skipped_branch?
|
47
|
+
branch_name.match?(/skip[\s\-_]*diff[\s\-_]*test/i)
|
48
|
+
end
|
49
|
+
|
50
|
+
def on_skipped_commit?
|
51
|
+
commit_title.match?(/skip[\s\-_]*diff[\s\-_]*test/i)
|
52
|
+
end
|
53
|
+
|
54
|
+
def rev_sha
|
55
|
+
@rev_sha ||= `git rev-parse HEAD`.strip
|
56
|
+
end
|
57
|
+
|
58
|
+
def commit_title
|
59
|
+
@commit_title ||= `git log -1 --pretty=%B`.strip
|
60
|
+
end
|
61
|
+
|
62
|
+
def branch_name
|
63
|
+
@branch_name ||= `git rev-parse --abbrev-ref HEAD`.strip
|
64
|
+
end
|
65
|
+
|
66
|
+
def committer_email
|
67
|
+
@committer_email ||= `git log -1 --pretty=%ae`.strip
|
68
|
+
end
|
36
69
|
end
|
37
70
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'file_hash_computer'
|
2
2
|
require_relative 'trackers/ruby_file'
|
3
3
|
require_relative 'trackers/js_file'
|
4
|
+
require_relative 'trackers/constant'
|
4
5
|
|
5
6
|
module DiffTest
|
6
7
|
class ImpactedFileTracker
|
@@ -9,6 +10,7 @@ module DiffTest
|
|
9
10
|
def initialize
|
10
11
|
@trackers = [
|
11
12
|
DiffTest::Trackers::RubyFile.new,
|
13
|
+
DiffTest::Trackers::Constant.new,
|
12
14
|
DiffTest::Trackers::JsFile.new
|
13
15
|
]
|
14
16
|
end
|
@@ -24,11 +26,18 @@ module DiffTest
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def start
|
27
|
-
trackers.each(&:
|
29
|
+
trackers.each(&:start)
|
28
30
|
end
|
29
31
|
|
30
32
|
def stop
|
31
|
-
trackers.each(&:
|
33
|
+
trackers.each(&:stop)
|
34
|
+
end
|
35
|
+
|
36
|
+
def pause(&block)
|
37
|
+
trackers.each(&:pause)
|
38
|
+
result = yield
|
39
|
+
trackers.each(&:resume)
|
40
|
+
result
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../integration'
|
2
|
+
require_relative 'test_fixtures_ext'
|
3
|
+
|
4
|
+
module DiffTest
|
5
|
+
module Integrations
|
6
|
+
module ActiveRecord
|
7
|
+
class Integration < DiffTest::Integrations::Integration
|
8
|
+
def gem_name
|
9
|
+
'activerecord'
|
10
|
+
end
|
11
|
+
|
12
|
+
def minimum_compatible_version
|
13
|
+
'5.0.0'
|
14
|
+
end
|
15
|
+
|
16
|
+
def loaded?
|
17
|
+
supported? &&
|
18
|
+
defined?(::ActiveRecord) && defined?(::ActiveRecord::TestFixtures) &&
|
19
|
+
defined?(::ActiveSupport) && defined?(::ActiveSupport::TestCase)
|
20
|
+
end
|
21
|
+
|
22
|
+
def integrate
|
23
|
+
::ActiveSupport::TestCase.include(DiffTest::Integrations::ActiveRecord::TestFixturesExt)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module DiffTest
|
2
|
+
module Integrations
|
3
|
+
module ActiveRecord
|
4
|
+
module TestFixturesExt
|
5
|
+
def self.included(base)
|
6
|
+
base.prepend(InstanceMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
private def setup_fixtures(*args, &block)
|
11
|
+
execution = DiffTest::TestExecution.current
|
12
|
+
return super unless execution
|
13
|
+
|
14
|
+
execution.impacted_file_tracker.pause do
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -7,68 +7,79 @@ module DiffTest
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module InstanceMethods
|
10
|
-
def
|
11
|
-
super
|
10
|
+
def run
|
11
|
+
return super unless DiffTest.configuration.enabled?
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
begin
|
14
|
+
unless DiffTest::TestSuiteExecution.current
|
15
|
+
tests = ::Minitest::Test.runnables.flat_map do |runnable|
|
16
|
+
next if runnable.runnable_methods.empty?
|
16
17
|
|
17
|
-
|
18
|
+
test_file_path = Helper.relative_const_source_path_from_project_root(runnable.name) rescue nil
|
19
|
+
next unless test_file_path
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
runnable.runnable_methods.map do |test_name|
|
22
|
+
DiffTest::Helper.test_id(test_file_path, test_name)
|
23
|
+
end
|
24
|
+
end.compact
|
23
25
|
|
24
|
-
|
26
|
+
DiffTest::TestSuiteExecution.find_or_create(tests)
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
at_exit do
|
29
|
+
DiffTest::TestSuiteExecution.current.save
|
30
|
+
end
|
28
31
|
end
|
32
|
+
rescue => e
|
33
|
+
DiffTest.error("An error ocurred while trying to create a test suite execution on DiffTest. Please report this issue.\nException: #{e}")
|
34
|
+
return super
|
29
35
|
end
|
30
36
|
|
31
|
-
|
37
|
+
DiffTest.error("DiffTest: Expected DiffTest::TestExecution to be nil, but was #{DiffTest::TestExecution.current}. Please report this issue.") if DiffTest::TestExecution.current
|
32
38
|
|
33
|
-
|
34
|
-
test_name = self.name
|
39
|
+
return super unless DiffTest::TestSuiteExecution.current.valid?
|
35
40
|
|
36
|
-
|
41
|
+
begin
|
42
|
+
test_file_path = Helper.relative_const_source_path_from_project_root(self.class.name) rescue nil
|
43
|
+
return super if test_file_path.nil?
|
44
|
+
test_name = self.name
|
37
45
|
|
38
|
-
|
39
|
-
DiffTest::
|
46
|
+
DiffTest::TestExecution.current = execution = DiffTest::TestExecution.new(test_file_path:, test_name:)
|
47
|
+
should_run = DiffTest::ShouldRunDecider.should_run?(execution.id, system_test: true)
|
48
|
+
DiffTest::TestSuiteExecution.current.ensure_application_eager_loaded! if should_run
|
49
|
+
rescue => e
|
50
|
+
DiffTest.error("An error ocurred while trying to create a test execution. Please report this issue.\nException: #{e}")
|
51
|
+
return super
|
52
|
+
end
|
53
|
+
|
54
|
+
if should_run
|
55
|
+
execution.start
|
56
|
+
super
|
40
57
|
else
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# But then since we skip here, we never reach the run_callbacks call because skip raises an exception.
|
47
|
-
run_callbacks(:setup)
|
58
|
+
# Skip raises an exception too, which is handled by `capture_exception`
|
59
|
+
time_it do
|
60
|
+
capture_exceptions do
|
61
|
+
skip("Impacted files have not changed. Skipping...")
|
62
|
+
end
|
48
63
|
end
|
49
|
-
|
64
|
+
::Minitest::Result.from(self)
|
50
65
|
end
|
51
66
|
ensure
|
52
|
-
execution
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
execution.passed!
|
67
|
+
if execution
|
68
|
+
if execution.should_run?
|
69
|
+
if skipped?
|
70
|
+
execution.skipped!
|
71
|
+
elsif passed?
|
72
|
+
execution.passed!
|
73
|
+
else
|
74
|
+
execution.failed!
|
75
|
+
end
|
76
|
+
execution.stop
|
63
77
|
else
|
64
|
-
execution.
|
78
|
+
execution.not_run!
|
79
|
+
execution.finish
|
65
80
|
end
|
66
|
-
|
67
|
-
execution.not_run!
|
81
|
+
DiffTest::TestExecution.current = nil
|
68
82
|
end
|
69
|
-
execution.stop
|
70
|
-
DiffTest::TestExecution.current = nil
|
71
|
-
super
|
72
83
|
end
|
73
84
|
end
|
74
85
|
end
|
@@ -4,7 +4,7 @@ module DiffTest
|
|
4
4
|
module RailsJs
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
initializer 'diff_test.middleware' do |app|
|
7
|
-
app.middleware.insert_before 0, DiffTest::Integrations::RailsJs::Middleware if
|
7
|
+
app.middleware.insert_before 0, DiffTest::Integrations::RailsJs::Middleware if DiffTest.configuration.enabled?
|
8
8
|
end
|
9
9
|
|
10
10
|
rake_tasks do
|
@@ -8,6 +8,8 @@ module DiffTest
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def should_run?(test_id, system_test:)
|
11
|
+
return true unless @test_executions_by_test
|
12
|
+
|
11
13
|
previous_test_executions = @test_executions_by_test[test_id] || []
|
12
14
|
|
13
15
|
# If there are any previous test executions run whose impacted files are the same as now
|
@@ -30,6 +32,7 @@ module DiffTest
|
|
30
32
|
false
|
31
33
|
end
|
32
34
|
|
35
|
+
return true if ENV['DIFF_TEST_ALWAYS_RUN'] == '1'
|
33
36
|
!has_previous_execution_with_no_impacted_changes
|
34
37
|
end
|
35
38
|
|
@@ -8,8 +8,7 @@ module DiffTest
|
|
8
8
|
@test_file_path = test_file_path
|
9
9
|
@test_name = test_name
|
10
10
|
@result = :queued
|
11
|
-
@started_at =
|
12
|
-
@stopped_at = Time.now
|
11
|
+
@started_at = @stopped_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
13
12
|
@impacted_file_tracker = DiffTest::ImpactedFileTracker.new
|
14
13
|
self.class.set(id, self)
|
15
14
|
end
|
@@ -34,12 +33,12 @@ module DiffTest
|
|
34
33
|
|
35
34
|
def start
|
36
35
|
@impacted_file_tracker.start
|
37
|
-
@started_at =
|
36
|
+
@started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
38
37
|
end
|
39
38
|
|
40
39
|
def stop
|
41
40
|
@impacted_file_tracker.stop
|
42
|
-
@stopped_at =
|
41
|
+
@stopped_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
43
42
|
finish
|
44
43
|
end
|
45
44
|
|
@@ -6,8 +6,13 @@ module DiffTest
|
|
6
6
|
def initialize(tests:)
|
7
7
|
@tests = tests.compact
|
8
8
|
@test_executions = []
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
+
def find_or_create_on_server
|
12
|
+
response = DiffTest::ApiClient.post("/test_suite_executions", body: payload)
|
13
|
+
raise "Failed to create test suite execution: #{response.inspect}" unless response.success?
|
14
|
+
raise "Failed to create test suite execution: #{response.inspect}" unless response['id'].present?
|
15
|
+
@id = response['id']
|
11
16
|
end
|
12
17
|
|
13
18
|
def previous_compatible_test_executions
|
@@ -25,12 +30,12 @@ module DiffTest
|
|
25
30
|
@test_executions << test_execution
|
26
31
|
end
|
27
32
|
|
28
|
-
def
|
29
|
-
|
33
|
+
def valid?
|
34
|
+
@id.present?
|
30
35
|
end
|
31
36
|
|
32
37
|
def save
|
33
|
-
save_test_execution_results_on_server
|
38
|
+
save_test_execution_results_on_server if valid?
|
34
39
|
end
|
35
40
|
|
36
41
|
def js_version_hash
|
@@ -47,6 +52,9 @@ module DiffTest
|
|
47
52
|
|
48
53
|
def self.find_or_create(tests)
|
49
54
|
self.current ||= new(tests:)
|
55
|
+
|
56
|
+
self.current.find_or_create_on_server
|
57
|
+
self.current
|
50
58
|
end
|
51
59
|
|
52
60
|
private
|
@@ -55,14 +63,9 @@ module DiffTest
|
|
55
63
|
@id || raise('Not created')
|
56
64
|
end
|
57
65
|
|
58
|
-
def find_or_create_on_server
|
59
|
-
response = DiffTest::ApiClient.post("/test_suite_executions", body: payload)
|
60
|
-
raise "Failed to create test suite execution: #{response.inspect}" unless response.success?
|
61
|
-
@id = response['id']
|
62
|
-
end
|
63
|
-
|
64
66
|
def save_test_execution_results_on_server
|
65
67
|
raise "Expected to have at least one test execution" if @test_executions.empty?
|
68
|
+
|
66
69
|
response = DiffTest::ApiClient.post("/test_suite_executions/#{id}/test_executions/bulk_create", body: { test_executions: @test_executions.map(&:save_payload) })
|
67
70
|
end
|
68
71
|
|
@@ -72,9 +75,9 @@ module DiffTest
|
|
72
75
|
project_version_hash: project_version_hash,
|
73
76
|
js_version_hash: js_version_hash,
|
74
77
|
all_js_files_annotated: all_js_files_annotated?,
|
75
|
-
rev_sha: rev_sha,
|
76
|
-
commit_title: commit_title,
|
77
|
-
branch_name: branch_name,
|
78
|
+
rev_sha: DiffTest::Helper.rev_sha,
|
79
|
+
commit_title: DiffTest::Helper.commit_title,
|
80
|
+
branch_name: DiffTest::Helper.branch_name,
|
78
81
|
ci_platform: DiffTest.configuration.ci_platform,
|
79
82
|
meta: meta,
|
80
83
|
}
|
@@ -95,18 +98,6 @@ module DiffTest
|
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
98
|
-
def rev_sha
|
99
|
-
@rev_sha ||= `git rev-parse HEAD`.strip
|
100
|
-
end
|
101
|
-
|
102
|
-
def commit_title
|
103
|
-
@commit_title ||= `git log -1 --pretty=%B`.strip
|
104
|
-
end
|
105
|
-
|
106
|
-
def branch_name
|
107
|
-
@branch_name ||= `git rev-parse --abbrev-ref HEAD`.strip
|
108
|
-
end
|
109
|
-
|
110
101
|
def meta
|
111
102
|
{}
|
112
103
|
end
|
@@ -7,11 +7,19 @@ module DiffTest
|
|
7
7
|
@impacted_files = Set.new
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def start
|
11
11
|
raise NotImplementedError
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def stop
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
def resume
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def pause
|
15
23
|
raise NotImplementedError
|
16
24
|
end
|
17
25
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
module DiffTest
|
3
|
+
module Trackers
|
4
|
+
class Constant < DiffTest::Trackers::Base
|
5
|
+
module ClassNewExtension
|
6
|
+
def new(...)
|
7
|
+
DiffTest::Trackers::Constant::REFERENCED_CONSTANTS.add(self) if DiffTest::Trackers::Constant.active
|
8
|
+
super(...)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
@@location_by_constant = {}
|
13
|
+
REFERENCED_CONSTANTS = Set.new
|
14
|
+
|
15
|
+
def self.active
|
16
|
+
@active
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.active=(value)
|
20
|
+
@active = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def start
|
24
|
+
REFERENCED_CONSTANTS.clear
|
25
|
+
self.class.active = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def stop
|
29
|
+
self.class.active= false
|
30
|
+
REFERENCED_CONSTANTS.each do |constant|
|
31
|
+
value = @@location_by_constant[constant]
|
32
|
+
|
33
|
+
if value.nil?
|
34
|
+
path = begin
|
35
|
+
DiffTest::Helper.const_source_path(constant.name)
|
36
|
+
rescue StandardError
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
path = false if !path || !DiffTest::Helper.file_in_project?(path)
|
41
|
+
path = DiffTest::Helper.relative_path_from_project_root(path) if path
|
42
|
+
value = @@location_by_constant[constant] = path
|
43
|
+
end
|
44
|
+
|
45
|
+
record(value) if value
|
46
|
+
end
|
47
|
+
REFERENCED_CONSTANTS.clear
|
48
|
+
end
|
49
|
+
|
50
|
+
def resume
|
51
|
+
self.class.active = true
|
52
|
+
end
|
53
|
+
|
54
|
+
def pause
|
55
|
+
self.class.active = false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class ::Class
|
62
|
+
prepend DiffTest::Trackers::Constant::ClassNewExtension
|
63
|
+
end
|
@@ -4,9 +4,10 @@ module DiffTest
|
|
4
4
|
class RubyFile < DiffTest::Trackers::Base
|
5
5
|
@@location_by_constant = {}
|
6
6
|
|
7
|
-
def
|
7
|
+
def initialize
|
8
|
+
super
|
8
9
|
@seen_constants = Set.new
|
9
|
-
@tracepoint = TracePoint.new(:call, :
|
10
|
+
@tracepoint = TracePoint.new(:call, :b_call) do |event|
|
10
11
|
if DiffTest::Helper.file_in_project?(event.path)
|
11
12
|
record(DiffTest::Helper.relative_path_from_project_root(event.path))
|
12
13
|
end
|
@@ -36,15 +37,25 @@ module DiffTest
|
|
36
37
|
record(path) if path
|
37
38
|
end
|
38
39
|
end
|
40
|
+
end
|
39
41
|
|
42
|
+
def start
|
40
43
|
@tracepoint.enable
|
41
44
|
end
|
42
45
|
|
43
|
-
def
|
46
|
+
def stop
|
44
47
|
@tracepoint.disable
|
45
48
|
@tracepoint = nil
|
46
49
|
@seen_constants = nil
|
47
50
|
end
|
51
|
+
|
52
|
+
def resume
|
53
|
+
@tracepoint.enable
|
54
|
+
end
|
55
|
+
|
56
|
+
def pause
|
57
|
+
@tracepoint.disable
|
58
|
+
end
|
48
59
|
end
|
49
60
|
end
|
50
61
|
end
|
@@ -31,13 +31,21 @@ module DiffTest
|
|
31
31
|
DiffTest::TestExecution.get(test_id).impacted_file_tracker.trackers.find { |tracker| tracker.class == self }.record(recordable_path)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def start
|
35
35
|
self.class.active_instances.add(self)
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def stop
|
39
39
|
self.class.active_instances.delete(self)
|
40
40
|
end
|
41
|
+
|
42
|
+
def resume
|
43
|
+
start
|
44
|
+
end
|
45
|
+
|
46
|
+
def pause
|
47
|
+
stop
|
48
|
+
end
|
41
49
|
end
|
42
50
|
end
|
43
51
|
end
|
data/lib/diff_test/version.rb
CHANGED
data/lib/diff_test.rb
CHANGED
@@ -7,8 +7,9 @@ require_relative 'diff_test/api_client'
|
|
7
7
|
require_relative 'diff_test/test_suite_execution'
|
8
8
|
require_relative 'diff_test/test_execution'
|
9
9
|
require_relative 'diff_test/impacted_file_tracker'
|
10
|
-
require_relative 'diff_test/integrations/minitest/integration'
|
11
10
|
require_relative 'diff_test/integrations/rails_js/integration'
|
11
|
+
require_relative 'diff_test/integrations/active_record/integration'
|
12
|
+
require_relative 'diff_test/integrations/minitest/integration'
|
12
13
|
|
13
14
|
module DiffTest
|
14
15
|
class Error < StandardError; end
|
@@ -23,9 +24,16 @@ module DiffTest
|
|
23
24
|
yield(configuration)
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
DiffTest
|
28
|
-
|
27
|
+
def self.error(message)
|
28
|
+
puts "DiffTest Error: #{message}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.integrate!
|
32
|
+
return unless configuration.integratable?
|
33
|
+
|
34
|
+
DiffTest::Integrations::RailsJs::Integration.instance.integrate_if_ready
|
35
|
+
DiffTest::Integrations::ActiveRecord::Integration.instance.integrate_if_ready
|
36
|
+
DiffTest::Integrations::Minitest::Integration.instance.integrate_if_ready
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diff_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owais
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- lib/diff_test/file_hash_computer.rb
|
57
57
|
- lib/diff_test/helper.rb
|
58
58
|
- lib/diff_test/impacted_file_tracker.rb
|
59
|
+
- lib/diff_test/integrations/active_record/integration.rb
|
60
|
+
- lib/diff_test/integrations/active_record/test_fixtures_ext.rb
|
59
61
|
- lib/diff_test/integrations/integration.rb
|
60
62
|
- lib/diff_test/integrations/minitest/integration.rb
|
61
63
|
- lib/diff_test/integrations/minitest/lifecycle.rb
|
@@ -72,6 +74,7 @@ files:
|
|
72
74
|
- lib/diff_test/test_execution.rb
|
73
75
|
- lib/diff_test/test_suite_execution.rb
|
74
76
|
- lib/diff_test/trackers/base.rb
|
77
|
+
- lib/diff_test/trackers/constant.rb
|
75
78
|
- lib/diff_test/trackers/js_file.rb
|
76
79
|
- lib/diff_test/trackers/ruby_file.rb
|
77
80
|
- lib/diff_test/trackers/singleton_base.rb
|