Ignore gem options when resolving cookbook gem metadata - #52
Open
tas50 wants to merge 1 commit into
Open
Conversation
tas50
force-pushed
the
fix/cookbook-gem-options
branch
from
August 22, 2026 00:09
13db90a to
26519ca
Compare
A cookbook's gem metadata accepts the same trailing options Hash a Gemfile does, for example: gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] Chef passes those options through to a generated Gemfile, but ChefSpec handed them to Gem::Specification.find_by_name as if they were version requirements. Gem::Requirement then raised BadRequirementError, which is not rescued, so the whole converge failed for any cookbook, or dependent cookbook, using gem options. Drop the options Hash before resolving the gem. Fixes chefspec#1016 Signed-off-by: Tim Smith <tsmith84@proton.me>
tas50
force-pushed
the
fix/cookbook-gem-options
branch
from
August 22, 2026 00:20
26519ca to
9e3b941
Compare
Author
|
CI on this PR is red for an unrelated reason: main's bundle cannot be installed on Linux, which breaks every job before any test runs. That is fixed separately in #56, which is green across Ruby 3.1 to 3.4. This PR should go green once #56 lands and this branch is rebased. Locally, against a working bundle, this branch passes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes chefspec#1016
Problem
A cookbook's gem metadata accepts the same trailing options Hash a Gemfile does:
Chef::Cookbook::Metadata#gemstores the raw args, and Chef writes them into a generated Gemfile wheregem(*args)handles the Hash natively. ChefSpec's override instead passes them toGem::Specification.find_by_nameas version requirements:Gem::Requirementthen raisesBadRequirementError, which therescue ::Gem::MissingSpecErrordoes not catch, so the whole converge fails:This also fires for a dependent cookbook's metadata, so it can break a run for a cookbook the author does not control.
Fix
Drop the options Hash before resolving, keeping only the version requirements.
Testing
Adds a
cookbook_gemsacceptance example whosemetadata.rbdeclares gems both with and without an options Hash.2 examples, 0 failures2 examples, 2 failures(BadRequirementError)197 examples, 0 failuresWorth noting separately: a gem restricted to platforms that do not match the current one now falls through to the existing "No matching version found" warning (chefspec#1015). Skipping non-matching platforms outright would be a reasonable follow-up.