Skip to content

Commit 8c22dc4

Browse files
hsbtclaude
authored andcommitted
[ruby/rubygems] Report the gemrc cooldown from bundle config
The gemrc value takes part in resolving the cooldown but is not one of the config layers, so `bundle config get cooldown` answered that nothing was configured, then exited 1, while the cooldown was in force. It is listed like a stored credential now, which is the other value the config files do not hold. ruby/rubygems@3d5179cd52 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent c709569 commit 8c22dc4

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

lib/bundler/cli/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def run
9797
confirm(name)
9898
end
9999

100-
if current_value.nil? && !Bundler.settings.credential_stored?(name)
100+
if current_value.nil? && !Bundler.settings.stored_outside_config_files?(name)
101101
exit 1
102102
else
103103
return

lib/bundler/settings.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def all_including_stored_credentials
187187
# The listing comes from the globally selected store, but a host can name
188188
# its own, so keep only the keys the per-host lookup agrees are set.
189189
keys.select! {|key| credential_stored?(key) }
190+
keys << "cooldown" if gemrc_cooldown_days
190191

191192
all.union(keys).sort
192193
end
@@ -258,10 +259,27 @@ def pretty_values_for(exposed_key)
258259
locations << "Set for the current user (#{global_config_file}): #{printable_value(value, exposed_key).inspect}"
259260
end
260261

262+
# The gemrc cooldown sits outside the priority order too. It is not one
263+
# of the layers, it raises whatever they resolve to. See #cooldown_for.
264+
if key == key_for(:cooldown) && (days = gemrc_cooldown_days)
265+
line = "Set in the RubyGems configuration as `:cooldown:`: #{days}"
266+
line += ". The longer of that and the top value applies" unless locations.empty?
267+
locations << line
268+
end
269+
261270
return ["You have not configured a value for `#{exposed_key}`"] if locations.empty?
262271
locations
263272
end
264273

274+
##
275+
# True when +name+ has a configured value Settings#[] cannot see. A
276+
# credential in the store is one, and so is the RubyGems `:cooldown:`
277+
# setting that #cooldown_for raises the config layers to.
278+
279+
def stored_outside_config_files?(name)
280+
credential_stored?(name) || (key_for(name) == key_for(:cooldown) && !gemrc_cooldown_days.nil?)
281+
end
282+
265283
##
266284
# True when +name+'s credential lives in the credential store. The secret
267285
# itself is never returned: callers only need to know the setting exists,
@@ -441,6 +459,14 @@ def gemrc_cooldown
441459
nil
442460
end
443461

462+
# The gemrc cooldown as a usable number of days, or nil. A value that is
463+
# not one takes no part in the resolution, so nothing reports it as
464+
# configured either.
465+
466+
def gemrc_cooldown_days
467+
cooldown_settings.days(rubygems_cooldown)
468+
end
469+
444470
def configs
445471
@configs ||= {
446472
temporary: @temporary,

spec/bundler/bundler/settings_spec.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,73 @@
136136
end
137137
end
138138

139+
describe "#pretty_values_for" do
140+
it "reports a gemrc cooldown that no Bundler layer configures" do
141+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, 7)
142+
143+
expect(settings.pretty_values_for(:cooldown)).to eq(
144+
["Set in the RubyGems configuration as `:cooldown:`: 7"]
145+
)
146+
end
147+
148+
it "explains the max rule only when a Bundler layer configures one too" do
149+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, 7)
150+
settings.set_local :cooldown, "3"
151+
152+
expect(settings.pretty_values_for(:cooldown).last).to eq(
153+
"Set in the RubyGems configuration as `:cooldown:`: 7. The longer of that and the top value applies"
154+
)
155+
end
156+
157+
it "leaves out a gemrc value that takes no part in the resolution" do
158+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, "abc")
159+
allow(Bundler.ui).to receive(:warn)
160+
161+
expect(settings.pretty_values_for(:cooldown)).to eq(["You have not configured a value for `cooldown`"])
162+
end
163+
164+
it "says nothing about RubyGems when it configures no cooldown" do
165+
allow(Gem.configuration).to receive(:each)
166+
167+
expect(settings.pretty_values_for(:cooldown)).to eq(["You have not configured a value for `cooldown`"])
168+
end
169+
end
170+
171+
describe "#stored_outside_config_files?" do
172+
it "is true for a cooldown only the gemrc configures" do
173+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, 7)
174+
175+
expect(settings.stored_outside_config_files?(:cooldown)).to be true
176+
end
177+
178+
it "is false for a gemrc value that takes no part in the resolution" do
179+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, "abc")
180+
allow(Bundler.ui).to receive(:warn)
181+
182+
expect(settings.stored_outside_config_files?(:cooldown)).to be false
183+
end
184+
185+
it "is false for another key the gemrc knows nothing about" do
186+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, 7)
187+
188+
expect(settings.stored_outside_config_files?(:jobs)).to be false
189+
end
190+
end
191+
192+
describe "#all_including_stored_credentials" do
193+
it "lists a cooldown only the gemrc configures" do
194+
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, 7)
195+
196+
expect(settings.all_including_stored_credentials).to include("cooldown")
197+
end
198+
199+
it "leaves it out when the gemrc configures none" do
200+
allow(Gem.configuration).to receive(:each)
201+
202+
expect(settings.all_including_stored_credentials).not_to include("cooldown")
203+
end
204+
end
205+
139206
describe "#rubygems_cooldown" do
140207
it "warns once when the gemrc value is not a number" do
141208
allow(Gem.configuration).to receive(:each).and_yield(:cooldown, "abc")

0 commit comments

Comments
 (0)