Skip to content

Re-introduce Base#format and Collection#format to fix Rails 7.1 tests#2412

Merged
joelhawksley merged 10 commits intomainfrom
re_add_format
Aug 5, 2025
Merged

Re-introduce Base#format and Collection#format to fix Rails 7.1 tests#2412
joelhawksley merged 10 commits intomainfrom
re_add_format

Conversation

@camertron
Copy link
Copy Markdown
Contributor

@camertron camertron commented Aug 2, 2025

What are you trying to accomplish?

ViewComponent's tests suddenly started failing in CI a few days ago. This PR is the result of my investigation, and should repair the build. It does four things:

  1. Conditionally adds the ViewComponent::Base#format method back for Rails 7.1 only.
  2. Checks all lockfiles in the gemfiles/ directory in to source control.
  3. Constrains Rails versions in gemfiles to only allow the patch version to vary, eg. ~> 7.1.0 instead of ~> 7.1.
  4. Alters the allocations helper to accept a range since I couldn't get it to pass consistently.

What approach did you choose and why?

First, I performed a git bisect and discovered the test failures started happening under Rails 7.1 after this PR was merged. Strangely, the the same tests passed when the PR was originally created, so I tried to run them on my laptop. I was unable to reproduce a passing test suite.

Further investigation revealed that gemfiles/rails_7.1.gemfile contains perhaps too loose a version constraint on Rails:

gem "rails", "~> 7.1"

Although I was not able to determine the root cause for certain, here's my current hypothesis:

  1. Since there is no lockfile under version control for gemfiles/rails_7.1.gemfile, the Ruby setup action always computes a new one before installing gems. Before [v4] Remove unnecessary #format definitions, which returned nil #2233 was created, the loose version constraint caused the Rails 7.1 build to use Rails 7.2 instead, which is not prone to the failure. This bundle was cached by GitHub Actions.
  2. At some point, a new version of another (unknown) gem ViewComponent depends on was released. This secondary gem pinned the Rails version to 7.1, which in turn caused certain tests to fail. There is evidence for this. I tried to run bundle install numerous times on main, both with and without a lockfile, but bundler always installed Rails 7.1. This indicates to me that some other dependency must be influencing the Rails version somehow. Strangely however, I was also able to force Rails 7.2 to install by updating the version constraint to ~> 7.2. So actually maybe we've run into a bug in bundler 😅
  3. Ruby 3.2.9 was released around the same time we started to notice the test failures. Since the ruby/setup Action uses the Ruby version to build the cache key, it is likely our bundle cache was invalidated when new builds started running. These new builds would have used Rails 7.1 instead of 7.2.

@camertron camertron changed the title Build Re-introduce Base#format and Collection#format to fix Rails 7.1 tests Aug 2, 2025
@camertron camertron marked this pull request as ready for review August 5, 2025 05:55
@joelhawksley joelhawksley enabled auto-merge August 5, 2025 18:39
@joelhawksley joelhawksley merged commit 0bac1e3 into main Aug 5, 2025
17 checks passed
@joelhawksley joelhawksley deleted the re_add_format branch August 5, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants