Skip to content

Fix the hosted gem warning for a Gemfile with several top-level sources (#2162) - #2164

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-gem-hosted-multi-global-source-warning
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-gem-hosted-multi-global-source-warning

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2162

Summary

A Gemfile with more than one top-level source line makes Bundler 2.2 to 2.7 lock every gem in one GEM section that names every source. scan --mode hosted refuses such a gem (it writes nothing), but the warning blamed a "bundler < 2.2" lock and prescribed bundle lock, which writes the same lock again. The user went round in a loop.

The refusal is unchanged. For that Gemfile the warning now:

  • names the cause: "Gemfile has 2 top-level source lines";
  • names the remedy that works: keep the patched gem's source as the one top-level source, move each other one into a source "<url>" do … end block, then bundle lock and re-run;
  • offers --mode agent only. Vendored mode refuses a gem in a group block or with a native extension, and the hosted planner cannot tell either, so it is no longer offered here;
  • never prints the source URLs, which can carry credentials.

A stale multi-remote lock under a Gemfile with one top-level source keeps the old text: there bundle lock does rewrite the lock (checked on Bundler 2.5.22).

Root cause

converge_gem_lock_source reported any GEM section with several remotes as the layout of Bundler < 2.2, and its caller in plan_gem_redirect appended one fixed remedy without looking at the Gemfile.

Changes

  • formats/gem/hosted.rs: converge_gem_lock_source returns a typed LockRefusal that says when the multi-remote section is the reason. bundler_keeps_merged_section names the early 2.2 releases (below).
  • formats/gem/declarations.rs: top_level_source_count counts block-less source calls outside every other construct. A computed URL counts; a source inside a conditional or with a trailing if does not, since Bundler may never run it.
  • patch/redirect/mod.rs: the new wording, taken only when the refusal is the multi-remote one and the Gemfile has more than one top-level source.
  • docs/ecosystems.md and CLI_CONTRACT.md: the case is listed under redirect_gem_lock_unconvergeable.

No wrapper under npm/, pypi/ or gem/ holds this text.

Evidence

Real Bundler, run in this session:

Bundler Two top-level sources bundle lock after moving the second into a block
2.2.15, 2.2.18 one GEM section, two remotes still one section
2.2.25, 2.2.29, 2.2.31, 2.2.33 one section, two remotes one section per source
2.5.22 one section, two remotes; bundle lock leaves it byte for byte one section per source

Because of the first row, a lock written by a 2.2 release before 2.2.25 gets "then run bundle lock with bundler 2.2.25 or later". I did not run 2.2.19 to 2.2.24; they are taken to keep the section.

Tests (each fails on main, the first two shown red in the first commit):

  • gem_lock_of_a_gemfile_with_several_top_level_sources_names_the_block_remedy: locks as Bundler 2.5.22 and 2.6.9 write them, LF and CRLF, a gem in a group block, a computed second source, a URL with credentials.
  • gem_stale_multi_remote_lock_keeps_the_bundle_lock_remedy: one top-level source, a second source in a block, as a source: option, or in an if/else.
  • gem_lock_refused_for_another_reason_is_not_blamed_on_the_sources, gem_lock_of_an_early_bundler_2_2_names_a_bundler_that_splits_it, top_level_source_count_is_the_blockless_calls_outside_any_construct, bundler_keeps_merged_section_names_the_early_2_2_releases.
  • End to end, gem_hosted_two_top_level_sources_are_refused_with_the_block_remedy in e2e_redirect_gem_build: the refusal, bundle lock leaving the lock alone, then the remedy, a scan that wires the gem, and a frozen install. Passes on Bundler 2.5.22 and 2.2.33 here; fails without the fix. It skips on Bundler 4 (which refuses such a Gemfile) and below 2.2, so on this PR's Bundler 4 leg it prints SKIP and the nightly 2.2 to 2.7 legs run it.

Commands run locally: cargo test -p socket-patch-core --lib (8053 passed), cargo clippy --locked --workspace --all-features -- -D warnings (clean). cargo clippy --all-targets fails on main too (49 errors in test code of other modules); none are in lines this PR touches.

Review findings not fixed

  • Bundler itself can give one gem a source: option under two top-level sources and write a lock with that gem in a section of its own beside the two-remote section. Hosted mode could wire that directly. The issue calls it a feature outside the report, so the warning only says hosted mode "does not rewrite" such a lock. Worth a follow-up issue.
  • A second top-level source declared out of sight (eval_gemfile) or inside a conditional still gets the old text.

https://claude.ai/code/session_011f9aeQRcWGFNS21yTAxHto


Generated by Claude Code

Refs #2162

Assisted-by: Claude Code:claude-fable-5-2
A Gemfile with two top-level `source` lines makes Bundler 2.2 to 2.7
write one GEM section with two remotes. The hosted scan blames a
Bundler < 2.2 lock for it and prescribes a `bundle lock` that changes
nothing. The new test fails until the warning names the real cause.

Refs #2162

Assisted-by: Claude Code:claude-fable-5-2
A Gemfile with more than one top-level `source` line makes Bundler
2.2 to 2.7 lock every gem in one GEM section that names every source.
The hosted scan refused such a gem with a warning that blamed a
Bundler < 2.2 lock and prescribed `bundle lock`, which writes the same
lock again, so the user went round in a loop.

The refusal stays (nothing is written), but for that Gemfile the
warning now names the top-level sources as the cause and the remedy
that works: move each extra source into a `source "<url>" do ... end`
block, then `bundle lock`. It offers agent mode only, since vendored
mode refuses a gem in a group block or with a native extension, and
it does not print the source URLs, which can carry credentials. A
stale multi-remote lock under a one-source Gemfile keeps the
`bundle lock` remedy, which does rewrite it.

A real-Bundler case in e2e_redirect_gem_build covers the refusal and
the remedy on Bundler 2.2 to 2.7.

Fixes #2162

Assisted-by: Claude Code:claude-fable-5-2
Review follow-ups for the warning on a Gemfile with several top-level
sources:

- Count every block-less `source` call outside any other construct,
  a computed URL included, so a second source read from ENV gets the
  remedy too. A `source` in a conditional or with a trailing modifier
  is not counted: Bundler may never run it.
- Take the new wording only when the multi-remote section is why the
  lock was refused; any other reason is still reported as it is.
- Say hosted mode does not rewrite that lock, not that it cannot be
  done, and tell the user to keep the patched gem's source top-level.
- Bundler 2.2.15 and 2.2.18 keep the one section on `bundle lock`
  after the Gemfile is fixed (2.2.25 and later split it), so a lock
  written by an early 2.2 release names a Bundler that splits it.

Refs #2162

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 19, 2026 18:21
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Behavior change is limited to warning text and refusal detail for an already-blocked hosted gem path; no new writes or auth/data-path changes.

Overview
Fixes #2162: when hosted gem redirect hits a Bundler 2.2–2.7 lock with multiple remotes in one GEM section caused by several top-level source lines, redirect_gem_lock_unconvergeable no longer mislabels it as a Bundler < 2.2 layout or tells users to run a bare bundle lock that leaves the lock unchanged.

The planner now counts top-level sources via top_level_source_count, returns structured LockRefusal from converge_gem_lock_source, and emits guidance to restructure sources (one global source, others in source "…" do … end blocks), re-lock (calling out Bundler 2.2.25+ when an early 2.2 writer keeps the merged section), then rescan—or use --mode agent instead of vendored. Source URLs are omitted from messages to avoid leaking credentials.

Docs (CLI_CONTRACT.md, docs/ecosystems.md) and tests (unit + e2e gem_hosted_two_top_level_sources_are_refused_with_the_block_remedy) lock in the new behavior; stale single-source multi-remote locks still get the generic bundle lock remedy.

Reviewed by Cursor Bugbot for commit 425bcbd. Configure here.

Merged via the queue into main with commit 96211bd Nov 19, 2026
122 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-hosted-multi-global-source-warning branch November 19, 2026 20:59
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.

Hosted gem scan on a Gemfile with two top-level source lines blames a "bundler < 2.2" lock and prescribes bundle lock, which changes nothing

3 participants