data_shifter 0.3.1 → 0.3.2.1

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: 1568faec72d1ca39a77cc6fa884293bc0320a14d3451188cc3e64d93ac4084cd
4
- data.tar.gz: fbc54ed6c02befcd7aef52b2f1d82b470144c52b1748db362ec6733be2fe0f42
3
+ metadata.gz: a2c27a241f01fd293278fdd45a9b8d5961d3a9ba304a95f657fd591ab5e2b4d6
4
+ data.tar.gz: 4db9925bd3e55bc8420bab92d9ed92a9e86e868ac0a1151f00b5245bace24319
5
5
  SHA512:
6
- metadata.gz: e890c867409768503d140de8f4ab781d2caca51438b336aa954dced6991bd129d6930c25148e6553f63fa39168b247960e7fc304187802e84d17fa83eec10d44
7
- data.tar.gz: 50fe503f813721a6c098081e6055aba2dca1980e0e593c979928a39e088e912d0af1ced7181220a9fed2531eed113b0b036bea436ce2d116131138f307062913
6
+ metadata.gz: 151626dbec0bae6d652a71cfcf814ccd79ee442211275dcfa4e62a8d0de04838376a6c67385826f3c4320126ef28d2ac37889e61d59b12f2d29a794296cc921d
7
+ data.tar.gz: 2a696741fbfde60b730cc29470b4c47063813cd2dd3995726961c1405283f32e38203659625c56316d5dd5d06abe3bb251ad455a96d298ec1f38129e558bb4e0
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@
4
4
 
5
5
  * N/A
6
6
 
7
+ ## [0.3.2.1]
8
+
9
+ * [Bugfix] Dry-run Sidekiq guard restores the previous `Sidekiq::Testing` mode (`fake!`, `inline!`, or `disable!`) instead of always calling `disable!`, which leaked global state and could leave later specs enqueueing work to real Redis.
10
+
11
+ ## [0.3.2]
12
+
13
+ * [Bugfix] Rake tasks exit quietly after a failed shift run when the shift already printed its failure summary; failures before that summary are still reported on stderr. Replaces rescuing only `Axn::Failure`, which missed most re-raised exceptions from `run!`.
14
+ * [Changed] Setup failures (load, constantize, etc.) print a short framed report on stderr with rake task, file path (relative to `Rails.root`), exception, and a Rails-cleaned backtrace (capped) instead of a full `Exception#full_message` dump.
15
+
7
16
  ## [0.3.1]
8
17
 
9
18
  * [Bugfix] No longer swallowing unexpected exceptions (errors in *loading* a data shift still need to be reported). No change to handling of exceptions raised while *running* a shift.
data/README.md CHANGED
@@ -114,7 +114,7 @@ In **dry run** mode, DataShifter automatically blocks or fakes these side effect
114
114
  | **HTTP** | Blocked via WebMock (`disable_net_connect!`). Allow specific hosts with `allow_external_requests [...]` or `DataShifter.config.allow_external_requests`. |
115
115
  | **ActionMailer** | `perform_deliveries = false` (restored after run). |
116
116
  | **ActiveJob** | Queue adapter set to `:test` (restored after run). |
117
- | **Sidekiq** | `Sidekiq::Testing.fake!` (restored with `disable!` after run). Only applied if `Sidekiq::Testing` is already loaded. |
117
+ | **Sidekiq** | `Sidekiq::Testing.fake!` for the run; previous mode (`fake!`, `inline!`, or `disable!`) is restored after. Only applied if `Sidekiq::Testing` is already loaded. |
118
118
 
119
119
  **Guarding other side effects:** For anything we don't cover (e.g. another service, or allowed HTTP that mutates), use e.g. `return if dry_run?` in your shift. DB changes are always rolled back in dry run; only non-DB side effects need this.
120
120
 
data/Rakefile CHANGED
@@ -4,9 +4,7 @@ require "bundler/gem_tasks"
4
4
  require "rubocop/rake_task"
5
5
 
6
6
  task :spec do
7
- Dir.chdir("spec/dummy_app") do
8
- sh "BUNDLE_GEMFILE=Gemfile bundle exec rspec spec/"
9
- end
7
+ sh "bundle exec rspec"
10
8
  end
11
9
 
12
10
  RuboCop::RakeTask.new
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/isolated_execution_state"
4
+
5
+ module DataShifter
6
+ module Internal
7
+ # Tracks whether Axn's on_error path already printed failure context (summary).
8
+ # Used by rake tasks to avoid duplicating setup failure output.
9
+ module RakeExceptionReporting
10
+ KEY = :data_shifter_rake_failure_summary_reported
11
+
12
+ module_function
13
+
14
+ def clear!
15
+ ActiveSupport::IsolatedExecutionState.delete(KEY)
16
+ end
17
+
18
+ def mark_failure_summary_reported!
19
+ ActiveSupport::IsolatedExecutionState[KEY] = true
20
+ end
21
+
22
+ def failure_summary_reported?
23
+ ActiveSupport::IsolatedExecutionState[KEY] == true
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ require_relative "colors"
6
+
7
+ module DataShifter
8
+ module Internal
9
+ # Formatted stderr output when a rake data:shift task fails before the shift summary (load, constantize, etc.).
10
+ module RakeSetupOutput
11
+ extend self
12
+
13
+ BACKTRACE_LIMIT = 12
14
+ DIVIDER = "=" * 60
15
+ SEPARATOR = "-" * 60
16
+
17
+ def print_failure(io:, exception:, file_path:, task_name:)
18
+ lines = filtered_backtrace(exception, file_path)
19
+ display = relative_display_path(file_path)
20
+
21
+ io.puts ""
22
+ io.puts Colors.red(DIVIDER, io:)
23
+ io.puts Colors.error("DATA SHIFT SETUP FAILED", io:)
24
+ io.puts Colors.dim(SEPARATOR, io:)
25
+ io.puts "Rake task: data:shift:#{task_name}"
26
+ io.puts "File: #{display}"
27
+ io.puts Colors.dim(SEPARATOR, io:)
28
+ io.puts Colors.error("#{exception.class}: #{exception.message}", io:)
29
+ if lines.any?
30
+ io.puts ""
31
+ io.puts Colors.dim("Backtrace:", io:)
32
+ lines.each { |line| io.puts Colors.dim(" #{line}", io:) }
33
+ end
34
+ io.puts Colors.red(DIVIDER, io:)
35
+ io.puts ""
36
+ end
37
+
38
+ private
39
+
40
+ def relative_display_path(file_path)
41
+ if defined?(Rails) && Rails.root
42
+ Pathname(file_path).relative_path_from(Rails.root).to_s
43
+ else
44
+ file_path.to_s
45
+ end
46
+ rescue ArgumentError
47
+ file_path.to_s
48
+ end
49
+
50
+ def filtered_backtrace(exception, file_path)
51
+ raw = exception.backtrace || []
52
+ cleaned =
53
+ if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) && Rails.backtrace_cleaner
54
+ Rails.backtrace_cleaner.clean(raw)
55
+ else
56
+ raw
57
+ end
58
+ lines = cleaned.map(&:to_s).reject(&:empty?).first(BACKTRACE_LIMIT)
59
+ return lines if lines.any?
60
+
61
+ needle = file_path.to_s
62
+ lines = raw.select { |ln| ln.start_with?(needle) || ln.include?("/data_shifts/") }.first(BACKTRACE_LIMIT)
63
+ return lines if lines.any?
64
+
65
+ raw.first(BACKTRACE_LIMIT)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -12,7 +12,7 @@ module DataShifter
12
12
  # production runs never load WebMock. On restore we revert to the previous state (enable!
13
13
  # or disable!) so e.g. specs that had WebMock enabled are not left with it disabled.
14
14
  # - ActionMailer / ActiveJob / Sidekiq: no extra loading; we only toggle existing config
15
- # for the duration of the block and restore in ensure, so impact is scoped to the run.
15
+ # for the duration of the block and restore in ensure (Sidekiq restores prior fake/inline/disable).
16
16
  module SideEffectGuards
17
17
  class << self
18
18
  # Applies side-effect guards, yields, then restores. Call only when running in dry run.
@@ -97,10 +97,23 @@ module DataShifter
97
97
  def apply_sidekiq(saved)
98
98
  return unless Sidekiq::Testing.respond_to?(:fake!)
99
99
 
100
+ saved[:sidekiq_testing_mode] = capture_sidekiq_testing_mode
100
101
  Sidekiq::Testing.fake!
101
102
  saved[:sidekiq] = true
102
103
  end
103
104
 
105
+ def capture_sidekiq_testing_mode
106
+ if Sidekiq::Testing.respond_to?(:__test_mode)
107
+ Sidekiq::Testing.__test_mode
108
+ elsif Sidekiq::Testing.fake?
109
+ :fake
110
+ elsif Sidekiq::Testing.inline?
111
+ :inline
112
+ else
113
+ :disable
114
+ end
115
+ end
116
+
104
117
  def restore_guards(saved)
105
118
  if saved.delete(:webmock)
106
119
  (saved.delete(:webmock_was_enabled) ? WebMock.enable! : WebMock.disable!)
@@ -112,7 +125,18 @@ module DataShifter
112
125
 
113
126
  return unless saved.delete(:sidekiq)
114
127
 
115
- Sidekiq::Testing.disable!
128
+ restore_sidekiq_testing_mode(saved.delete(:sidekiq_testing_mode))
129
+ end
130
+
131
+ def restore_sidekiq_testing_mode(mode)
132
+ case mode
133
+ when :fake
134
+ Sidekiq::Testing.fake!
135
+ when :inline
136
+ Sidekiq::Testing.inline!
137
+ else
138
+ Sidekiq::Testing.disable!
139
+ end
116
140
  end
117
141
  end
118
142
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "axn"
4
3
  require "rails/railtie"
5
4
 
5
+ require_relative "internal/rake_setup_output"
6
+
6
7
  module DataShifter
7
8
  class Railtie < Rails::Railtie
8
9
  # Extract description DSL from shift file without loading it.
@@ -67,12 +68,15 @@ module DataShifter
67
68
  klass.run!
68
69
  rescue Interrupt
69
70
  exit(130)
70
- rescue Axn::Failure
71
- # run! re-raises after on_error :_print_summary; avoid Rake's duplicate backtrace.
72
- exit(1)
73
71
  rescue StandardError => e
74
- # Errors raised while loading the shift class still need to be reported
75
- warn e.full_message(highlight: false, order: :top)
72
+ unless Internal::RakeExceptionReporting.failure_summary_reported?
73
+ Internal::RakeSetupOutput.print_failure(
74
+ io: $stderr,
75
+ exception: e,
76
+ file_path:,
77
+ task_name:,
78
+ )
79
+ end
76
80
  exit(1)
77
81
  end
78
82
  end
@@ -59,7 +59,7 @@ module DataShifter
59
59
  around :_with_transaction_for_dry_run
60
60
  before :_reset_tracking
61
61
  on_success :_print_summary
62
- on_error :_print_summary
62
+ on_error :_print_summary_for_axn_error
63
63
 
64
64
  class_attribute :_transaction_mode, default: :single
65
65
  class_attribute :_progress_enabled, default: nil
@@ -253,6 +253,7 @@ module DataShifter
253
253
  end
254
254
 
255
255
  def _reset_tracking
256
+ Internal::RakeExceptionReporting.clear!
256
257
  @stats = { processed: 0, succeeded: 0, failed: 0, skipped: 0 }
257
258
  @errors = []
258
259
  @skip_reasons = Hash.new(0)
@@ -277,6 +278,11 @@ module DataShifter
277
278
  )
278
279
  end
279
280
 
281
+ def _print_summary_for_axn_error
282
+ _print_summary
283
+ Internal::RakeExceptionReporting.mark_failure_summary_reported!
284
+ end
285
+
280
286
  # --- Override points ---
281
287
 
282
288
  def collection
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DataShifter
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2.1"
5
5
  end
data/lib/data_shifter.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "data_shifter/version"
4
4
  require_relative "data_shifter/configuration"
5
5
  require_relative "data_shifter/errors"
6
+ require_relative "data_shifter/internal/rake_exception_reporting"
6
7
  require_relative "data_shifter/shift"
7
8
  require_relative "data_shifter/railtie"
8
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_shifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kali Donovan
@@ -121,6 +121,8 @@ files:
121
121
  - lib/data_shifter/internal/log_deduplicator.rb
122
122
  - lib/data_shifter/internal/output.rb
123
123
  - lib/data_shifter/internal/progress_bar.rb
124
+ - lib/data_shifter/internal/rake_exception_reporting.rb
125
+ - lib/data_shifter/internal/rake_setup_output.rb
124
126
  - lib/data_shifter/internal/record_utils.rb
125
127
  - lib/data_shifter/internal/side_effect_guards.rb
126
128
  - lib/data_shifter/internal/signal_handler.rb