Skip to content

Commit 32a966d

Browse files
mlarrazclaude
andcommitted
Fix lockfile requirement preservation and orphaned deps test
Preserve the original dependency requirement from root deps when building ActivationRequests, so lockfiles correctly record constraints like "a (>= 1)" instead of bare "a". Update the orphaned dependencies test: PubGrub correctly backtracks from b-2 (missing c-2) to b-1 (has c-1), finding a valid solution that Molinillo's simpler backtracking missed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0c0c215 commit 32a966d

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

lib/rubygems/resolver.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ def resolve
171171
result = solver.solve
172172

173173
# Convert to Array<ActivationRequest>
174+
needed_by_name = @needed.group_by(&:name)
174175
result.filter_map do |package, version|
175176
next if Gem::PubGrub::Package.root?(package)
176177
spec = spec_for(package.to_s, version)
177-
dep_request = DependencyRequest.new(Gem::Dependency.new(package.to_s), nil)
178+
dep = needed_by_name[package.to_s]&.first || Gem::Dependency.new(package.to_s)
179+
dep_request = DependencyRequest.new(dep, nil)
178180
ActivationRequest.new(spec, dep_request)
179181
end
180182
rescue Gem::PubGrub::SolveFailure => e

test/rubygems/test_gem.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,9 @@ def test_activate_bin_path_raises_a_meaningful_error_if_a_gem_thats_finally_acti
328328

329329
install_specs c1, b1, b2, a1
330330

331-
# c2 is missing, and b2 which has it as a dependency will be activated, so we should get an error about the orphaned dependency
332-
333-
e = assert_raise Gem::UnsatisfiableDependencyError do
334-
load Gem.activate_bin_path("a", "exec", ">= 0")
335-
end
336-
337-
assert_equal "Unable to resolve dependency: 'b (>= 0)' requires 'c (= 2)'", e.message
331+
# c2 is missing, but the resolver backtracks from b2 to b1 which
332+
# works with c1, finding a valid solution despite partial installation
333+
load Gem.activate_bin_path("a", "exec", ">= 0")
338334
end
339335

340336
def test_activate_bin_path_in_debug_mode

0 commit comments

Comments
 (0)