Skip to content

Fix gem remedy naming a mode that refuses too (#2151) - #2160

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-gem-not-visible-remedy
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-gem-not-visible-remedy

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 #2151

Summary

In a gem library (Gemfile with gemspec), a patched gem that only the gemspec declares is skipped by hosted mode with redirect_gem_declaration_not_visible. The warning told the user to "patch it with --mode vendored or --mode agent". Vendored mode refuses the same gem for the same reason, exits 1 and named no way out. This PR changes message text and docs only; no run writes anything different.

  • Hosted warning: names a literal gem line or --mode agent. --mode vendored is gone.
  • Vendored refusal (gemfile_declaration_not_editable, "as a direct dependency"): now ends with its way out, one literal gem "<name>" line (above gemspec when the Gemfile has that directive) or --mode agent. It does not name hosted mode.
  • Both remedies say the line goes in place of any other gem call that declares the gem. See "Review finding" below for why.
  • docs/ecosystems.md and CLI_CONTRACT.md say the same. The docs sentence that promised vendored mode for every gem hosted mode skips now points at vendored mode's own refusals.

After the change:

Warning: Gemfile.lock lists rack-test as a direct dependency, but Gemfile declares it somewhere the rewriter cannot edit (an `eval_gemfile`d file, a loop, a gemspec); adding a second declaration would make bundler refuse the Gemfile — redirect skipped (declare it with a literal `gem "rack-test"` line in Gemfile, in place of any other `gem` call that declares it, or patch it with `--mode agent`)

Error: Cannot vendor pkg:gem/rack-test@2.1.0: Gemfile.lock lists "rack-test" as a direct dependency, but the Gemfile declares it somewhere the line grammar cannot edit (an `eval_gemfile`d file, a loop, a gemspec); refusing to append a second declaration (bundler hard-fails on duplicates); declare it with one literal `gem "rack-test"` line above `gemspec` in the Gemfile, in place of any other `gem` call that declares it, or patch rack-test with `--mode agent`

Root cause

Both modes refuse a gem the lock lists under DEPENDENCIES when they can find no gem line for it, because the line they would add is a second declaration. The hosted text was written before vendored mode had that gate, and the earlier pass that gave the vendored refusals a remedy (#2091) missed this one.

Why "above gemspec"

With a line below gemspec, Bundler 2.7+ merges the gemspec's development requirement into it, and vendored mode then refuses the gem for that (its existing refusal, which already says "move the declaration above gemspec"). Naming the place up front saves the user that second refusal. The hint is only given when the Gemfile's gemspec directives can be read.

Review finding fixed in the second commit

/code-review high pointed out that for an eval_gemfiled file or a loop, a user who adds a literal line next to the hidden gem call gets it pinned by the next run, and Bundler refuses a Gemfile whose two declarations of a gem differ. I confirmed that on Bundler 4.0.18 (gem "rack", "3.2.8" plus an eval_gemfiled gem "rack", "~> 3.1" fails bundle lock; two identical lines do not). The old hosted text had the same gap. Both remedies now say the line replaces the hidden call.

Evidence

Test Covers
vendor::gem::tests::direct_dependency_declared_out_of_sight_refuses_instead_of_appending vendored refusal text for eval_gemfile, a loop, gemspec (LF and CRLF, with path:), and a variable named gemspec (no hint)
patch::redirect::tests::gemfile_direct_dependency_declared_out_of_sight_is_not_appended and the refusal table test next to it hosted warning names agent mode and the literal line, never vendored mode
e2e gem_vendor_gemspec_only_dependency_refusal_names_remedies_that_work (new) the issue's project on real Bundler: refusal, then the gem line above gemspec vendors and installs frozen, reverts byte for byte; then apply (agent mode) patches the installed gem with the Gemfile untouched
e2e gem_vendor_refuses_an_eval_gemfile_direct_dep (extended) moving the declaration into the Gemfile vendors and installs frozen

The commit "Test the remedies of a gem declared out of sight" holds the tests alone and fails (2 unit tests and the new e2e test); the two commits after it make them pass.

Local runs, Ruby 3.3.6:

  • cargo test -p socket-patch-core: pass (7947 unit tests).
  • cargo test -p socket-patch-cli --test e2e_vendor_gem_build --test e2e_redirect_gem_build -- --ignored on Bundler 4.0.18: pass.
  • The two e2e tests above on Bundler 2.5.23 and 2.2.33: pass.
  • cargo clippy --locked -p socket-patch-core -p socket-patch-cli --all-features -- -D warnings (the form CI runs): clean. With --all-targets clippy reports errors in test code on main as well; none are in lines this PR touches.

CI on 0831ba5: ci-ok and clippy green, Bugbot found no issues, no open review thread.

Not fixed here

  • Other hosted gem warnings (redirect_gem_unrecognized_declaration, redirect_gem_source_option) still name --mode vendored for some declarations vendored mode refuses too, for example group(:test) { gem "rack" } or a git: option. That is the same kind of dead end with a different cause per shape, found by the review and not covered by Hosted gem scan sends a gemspec-declared gem to --mode vendored, which refuses it for the same reason and names no remedy #2151. It needs its own issue.
  • The vendored "direct dependency" refusal also fires for a parenthesized gem( call whose name is on a later line, which hosted mode can edit. The message blames an eval_gemfile, a loop or a gemspec there, as it did before.

https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f


Generated by Claude Code

Assisted-by: Claude Code:claude-fable-5-2
A gem the lock lists as a direct dependency but the Gemfile
declares in a gemspec, an eval_gemfile'd file or a loop is refused
by hosted and by vendored mode for the same reason. These tests pin
that the hosted warning names no mode that refuses the gem as well,
that the vendored refusal names its ways out, and (against real
Bundler) that both of those work when followed. They fail until the
next commit (#2151).

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f
A gem the lock lists as a direct dependency but the Gemfile
declares out of sight (a gemspec, an eval_gemfile'd file, a loop)
is refused by hosted and by vendored mode for the same reason:
either would add a second declaration, and Bundler refuses the
Gemfile. The hosted warning still sent the user to --mode vendored,
which exits 1 on the same gem, and the vendored refusal named no way
out.

The hosted warning now names the literal gem line and --mode agent
only. The vendored refusal names one literal gem line (above
`gemspec` where the Gemfile has that directive, since a line below
it is refused next for the merged requirement) or --mode agent. The
docs and the CLI contract say the same.

Fixes #2151

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f
Review of the previous commit: for a gem declared in an
eval_gemfile'd file or a loop, a literal line added next to the
hidden gem call would be pinned by the next run (an exact version
and path: in vendored mode, source: in hosted mode), and Bundler
refuses a Gemfile whose two declarations of a gem differ. Both
remedies now say the line stands in place of any other gem call
that declares the gem, and the end-to-end test follows that for an
eval_gemfile'd declaration.

The vendored refusal no longer says "above gemspec" for a Gemfile
whose gemspec directives cannot be read, which may have none. The
docs no longer say vendored mode can patch every gem a hosted
warning names it for.

Refs #2151

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 19, 2026 10:11
@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
User-facing error and documentation text only; gem redirect/vendoring behavior when a declaration is out of sight is unchanged aside from clearer remedies.

Overview
Fixes #2151: when a gem is a direct dependency declared only out of sight (eval_gemfile, loops, or gemspec), hosted mode already skipped with redirect_gem_declaration_not_visible but suggested --mode vendored, which fails for the same reason with no useful remedy.

Hosted redirect (redirect_gem_declaration_not_visible) now tells users to add one literal gem line in place of the hidden declaration, or use --mode agent—no vendored mention.

Vendored mode gains shared remedy text via out_of_sight_declaration_remedy (including above gemspec when that directive is visible), appended to gemfile_declaration_not_editable for the direct-dependency case; it does not suggest hosted mode for this shape.

Docs (CLI_CONTRACT.md, docs/ecosystems.md) match the new wording and note that vendored mode refuses these gems too.

Tests cover message content in redirect/mod.rs and vendor/gem.rs, extend the eval_gemfile e2e to prove the literal-line remedy vendors cleanly, and add an e2e capstone for gemspec-only deps (vendor after declaring above gemspec, or apply in agent mode).

Reviewed by Cursor Bugbot for commit 0831ba5. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0831ba5. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver (head 0831ba5)

What it does: this fixes #2151. Take a gem that only a gemspec (or an eval_gemfiled file, or a loop) declares, but that the lock lists as a direct dependency. Hosted mode's warning for it pointed to --mode vendored, which refuses the same gem for the same reason. Now both hosted mode's warning and vendored mode's refusal name remedies that work: a literal gem "<name>" line in place of the hidden declaration (above gemspec when the Gemfile has one), or --mode agent. This PR changes message text and docs only, plus tests.

Risk: low. No run writes anything different. Only two error and warning strings change, and out_of_sight_declaration_remedy adds one read-only parse of the Gemfile's gemspec directives. When that parse fails, the "above gemspec" hint is simply left out.

Look here:

Verified:

Changes I made: none.

Open questions: none blocking. The description's "Not fixed here" section lists two related dead ends in other gem warnings that need their own issue.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed at 0831ba5. Message and docs text only; matches the Expected section of #2151. The hosted warning no longer names --mode vendored, and the vendored refusal gains a remedy from a read-only parse that drops the hint when the parse fails. Non-blocking: other hosted warnings still name --mode vendored for shapes vendored mode refuses (listed in the PR body as out of scope).

Merged via the queue into main with commit b99db4c Nov 19, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-not-visible-remedy branch November 19, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hosted gem scan sends a gemspec-declared gem to --mode vendored, which refuses it for the same reason and names no remedy

3 participants