diff --git a/CHANGELOG.md b/CHANGELOG.md index 1612a07..25eacd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - [BUGFIX: example](https://github.com/fastruby/next_rails/pull/) +- [BUGFIX: Compare mode now checks only buckets the current process ran, fixing parallel test support](https://github.com/fastruby/next_rails/pull/179) - [FEATURE: Add `deprecations merge` command to combine parallel CI shards](https://github.com/fastruby/next_rails/pull/177) - [FEATURE: Add parallel CI support for DeprecationTracker](https://github.com/fastruby/next_rails/pull/176) - [CHORE: Add Ruby 4.0 to the test matrix](https://github.com/fastruby/next_rails/pull/178) diff --git a/README.md b/README.md index 1612974..d0c51e0 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ RSpec.configure do |config| end ``` -When `node_index` is set, the tracker writes to a shard file (e.g. `deprecation_warning.shitlist.node-0.json`) instead of the canonical file. +The `node_index` option is only used in save mode. When set, the tracker writes to a shard file (e.g. `deprecation_warning.shitlist.node-0.json`) instead of the canonical file. Compare mode does not support `node_index` and will raise an error if passed—compare should only run after merging shards on the final canonical shitlist. #### Merging shards @@ -200,9 +200,9 @@ DEPRECATION_TRACKER=save CI_NODE_INDEX=$NODE bundle exec rspec # 2. Merge phase — fan-in step, runs once after all nodes finish deprecations merge --delete-shards -# 3. Compare phase — each parallel node checks its buckets -# against the merged canonical file -DEPRECATION_TRACKER=compare CI_NODE_INDEX=$NODE bundle exec rspec +# 3. Compare phase — each parallel node checks only its own buckets +# against the merged canonical file (no CI_NODE_INDEX needed) +DEPRECATION_TRACKER=compare bundle exec rspec ``` ### `deprecations` command diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index c171090..08379c6 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -141,6 +141,9 @@ def initialize(shitlist_path, transform_message = nil, mode = :save, node_index: @transform_message = transform_message || -> (message) { message } @deprecation_messages = {} @mode = mode ? mode.to_sym : :save + if @mode == :compare && node_index + raise ArgumentError, "node_index cannot be used with compare mode" + end @node_index = node_index end @@ -180,14 +183,8 @@ def compare stored = read_json(shitlist_path) changed_buckets = [] - buckets_to_check = if parallel? - # In parallel mode, only check buckets that this node actually ran - normalized_deprecation_messages.select { |bucket, _| deprecation_messages.key?(bucket) } - else - normalized_deprecation_messages - end - buckets_to_check.each do |bucket, messages| + normalized_deprecation_messages.each do |bucket, messages| if stored[bucket] != messages changed_buckets << bucket end diff --git a/spec/deprecation_tracker_spec.rb b/spec/deprecation_tracker_spec.rb index 24fd311..193afd0 100644 --- a/spec/deprecation_tracker_spec.rb +++ b/spec/deprecation_tracker_spec.rb @@ -361,7 +361,7 @@ def self.behavior end describe "#compare" do - it "only checks buckets that this node ran" do + it "only checks buckets that this process ran (without node_index)" do # Set up canonical shitlist with two buckets setup_tracker = DeprecationTracker.new(shitlist_path) setup_tracker.bucket = "bucket 1" @@ -370,21 +370,27 @@ def self.behavior setup_tracker.add("b") setup_tracker.save - # Parallel node only runs bucket 2 with matching deprecations - tracker = DeprecationTracker.new(shitlist_path, nil, :compare, node_index: "0") + # Process only runs bucket 2 with matching deprecations, no node_index needed + tracker = DeprecationTracker.new(shitlist_path, nil, :compare) tracker.bucket = "bucket 2" tracker.add("b") expect { tracker.compare }.not_to raise_error end - it "raises when this node's buckets have changed" do + it "raises error when node_index is passed with compare mode" do + expect do + DeprecationTracker.new(shitlist_path, nil, :compare, node_index: "0") + end.to raise_error(ArgumentError, "node_index cannot be used with compare mode") + end + + it "raises when this process's buckets have changed" do setup_tracker = DeprecationTracker.new(shitlist_path) setup_tracker.bucket = "bucket 1" setup_tracker.add("a") setup_tracker.save - tracker = DeprecationTracker.new(shitlist_path, nil, :compare, node_index: "0") + tracker = DeprecationTracker.new(shitlist_path, nil, :compare) tracker.bucket = "bucket 1" tracker.add("different")