From ee906e855f7991006db64e6e90b92ebae5472240 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 09:22:33 +0000 Subject: [PATCH 1/4] Start fix for gem not-visible remedy (#2151) Assisted-by: Claude Code:claude-fable-5-2 From ef1ac5e1a11cc9800e16e2015b962e8f70859220 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 09:31:32 +0000 Subject: [PATCH 2/4] Test the remedies of a gem declared out of sight 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 Claude-Session: https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f --- .../tests/e2e_vendor_gem_build.rs | 156 ++++++++++++++++++ .../src/patch/redirect/mod.rs | 25 ++- crates/socket-patch-core/src/vendor/gem.rs | 18 +- 3 files changed, 197 insertions(+), 2 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs b/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs index c1e7641b7..dc0f16aa5 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs @@ -2366,6 +2366,162 @@ fn gem_vendor_gemspec_dev_dependency_refuses_or_installs_frozen() { ); } +/// #2151: a gem only the gemspec declares (a development dependency of a +/// gem library) is refused, and both ways out the refusal names work when +/// followed. Hosted mode's warning used to send the user here, where the +/// refusal named no way out at all. With the literal `gem` line above +/// `gemspec` the gem vendors and installs frozen; with the Gemfile left as +/// it was, agent mode patches the installed gem. +#[test] +#[ignore = "host capstone: shells out to a real bundler >= 1.17; the unpinned `test` job \ + skips it, the e2e job runs it with a pinned toolchain via --ignored"] +fn gem_vendor_gemspec_only_dependency_refusal_names_remedies_that_work() { + let Some((_tmp, proj, _bundler, purl)) = staged_rack_project("gemspec-only dependency") else { + return; + }; + let version = purl.rsplit('@').next().unwrap(); + let hidden = "source \"https://rubygems.org\"\n\ngemspec\n"; + let cwd = proj.to_str().unwrap(); + let vendor = |proj: &Path| run_socket(proj, &["vendor", "--json", "--offline", "--cwd", cwd]); + let locked = |proj: &Path| { + let lock = std::fs::read_to_string(proj.join("Gemfile.lock")).unwrap(); + locked_gem_version(&lock, DEP) + }; + + gemspec_library(&proj, hidden); + assert_eq!(locked(&proj).as_deref(), Some(version), "test premise"); + let lock_before = std::fs::read(proj.join("Gemfile.lock")).unwrap(); + let (code, stdout, stderr) = vendor(&proj); + assert_ne!( + code, 0, + "vendor must refuse.\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + let env = parse_json_envelope(&stdout); + let event = env["events"] + .as_array() + .unwrap() + .iter() + .find(|e| e["purl"] == purl) + .unwrap_or_else(|| panic!("an event for {purl}: {env}")); + assert_eq!( + event["errorCode"], "gemfile_declaration_not_editable", + "event: {event}" + ); + let error = event["error"].as_str().unwrap_or_default(); + assert!( + error.contains("one literal `gem \"rack\"` line above `gemspec`") + && error.contains("`--mode agent`"), + "the refusal names its ways out: {event}" + ); + assert!( + !error.contains("--mode hosted"), + "hosted mode refuses this gem for the same reason: {event}" + ); + assert_eq!( + std::fs::read_to_string(proj.join("Gemfile")).unwrap(), + hidden + ); + assert_eq!( + std::fs::read(proj.join("Gemfile.lock")).unwrap(), + lock_before + ); + assert!( + !proj.join(".socket/vendor/gem").exists(), + "no vendored copy is written" + ); + + // The first way out: one literal `gem` line above `gemspec`. + let declared = "source \"https://rubygems.org\"\n\ngem \"rack\"\n\ngemspec\n"; + gemspec_library(&proj, declared); + assert_eq!(locked(&proj).as_deref(), Some(version), "test premise"); + let lock_declared = std::fs::read(proj.join("Gemfile.lock")).unwrap(); + let (code, stdout, stderr) = vendor(&proj); + assert_eq!( + code, 0, + "vendor failed with the remedy followed.\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + let env = parse_json_envelope(&stdout); + assert_eq!(env["summary"]["applied"], 1, "{env}"); + let wired = std::fs::read_to_string(proj.join("Gemfile.lock")).unwrap(); + let install = bundle(&proj, &["install"], true); + assert!( + install.status.success(), + "frozen install of the vendored pair failed:\n{wired}\n{}", + String::from_utf8_lossy(&install.stderr) + ); + assert_eq!( + std::fs::read_to_string(proj.join("Gemfile.lock")).unwrap(), + wired, + "the frozen install keeps the lock byte-identical" + ); + let gem_path = |proj: &Path| { + let probe = bundle( + proj, + &[ + "exec", + "ruby", + "-e", + "print Gem.loaded_specs.fetch(\"rack\").full_gem_path", + ], + true, + ); + assert!( + probe.status.success(), + "rack must load:\n{}", + String::from_utf8_lossy(&probe.stderr) + ); + String::from_utf8_lossy(&probe.stdout).into_owned() + }; + let loaded = gem_path(&proj); + assert!( + loaded.contains(".socket/vendor/gem/"), + "rack must load from the vendored path ({purl}), got {loaded:?}" + ); + let (code, stdout, stderr) = run_socket(&proj, &["vendor", "--revert", "--json", "--cwd", cwd]); + assert_eq!( + code, 0, + "revert failed.\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + assert_eq!( + std::fs::read_to_string(proj.join("Gemfile")).unwrap(), + declared, + "revert restores the Gemfile byte-identical" + ); + assert_eq!( + std::fs::read(proj.join("Gemfile.lock")).unwrap(), + lock_declared, + "revert restores Gemfile.lock byte-identical" + ); + + // The second way out: agent mode, with the Gemfile as it was. + gemspec_library(&proj, hidden); + assert_eq!(locked(&proj).as_deref(), Some(version), "test premise"); + let installed_rb = PathBuf::from(gem_path(&proj)).join("lib/rack.rb"); + let marker = "SOCKET-PATCH-VENDOR-E2E-MARKER"; + assert!( + !std::fs::read_to_string(&installed_rb) + .unwrap() + .contains(marker), + "the installed gem starts unpatched (test premise)" + ); + let (code, stdout, stderr) = run_socket(&proj, &["apply", "--json", "--offline", "--cwd", cwd]); + assert_eq!( + code, 0, + "agent mode failed.\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + assert!( + std::fs::read_to_string(&installed_rb) + .unwrap() + .contains(marker), + "agent mode patches the installed gem" + ); + assert_eq!( + std::fs::read_to_string(proj.join("Gemfile")).unwrap(), + hidden, + "agent mode leaves the Gemfile alone" + ); +} + /// #1808: a CRLF `Gemfile.lock` (a Git for Windows `autocrlf` checkout, or /// `eol=crlf`; bundler keeps CRLF on purpose) vendors like an LF one. The /// dry run and the wet run both succeed, the wired lock keeps CRLF on every diff --git a/crates/socket-patch-core/src/patch/redirect/mod.rs b/crates/socket-patch-core/src/patch/redirect/mod.rs index ebcc01a76..a51f5085f 100644 --- a/crates/socket-patch-core/src/patch/redirect/mod.rs +++ b/crates/socket-patch-core/src/patch/redirect/mod.rs @@ -19212,10 +19212,22 @@ mod tests { assert_eq!(warning_codes(&r), vec![code], "{decl}: {:?}", r.warnings); let detail = &r.warnings[0].detail; assert!(detail.contains(why), "{decl}: {detail}"); + // #2151: vendored mode refuses a declaration out of sight for + // the same reason, so that refusal does not name it. + let remedy = match code { + "redirect_gem_declaration_not_visible" => "--mode agent", + "redirect_gem_dependency_not_locked" => "bundle lock", + _ => "--mode vendored", + }; assert!( - detail.contains("--mode vendored") || detail.contains("bundle lock"), + detail.contains(remedy), "{decl}: the refusal names a remedy: {detail}" ); + assert_eq!( + detail.contains("--mode vendored"), + remedy == "--mode vendored", + "{decl}: {detail}" + ); } // An opaque last argument the lock shows to be a version requirement // is no options hash: the option goes after it. @@ -20444,6 +20456,8 @@ mod tests { for gemfile in [ "source \"https://rubygems.org\"\neval_gemfile \"Gemfile.common\"\n", "source \"https://rubygems.org\"\n%w[rack].each { |g| gem g, \"~> 3.1\" }\n", + // A gem only the gemspec declares (a development dependency). + "source \"https://rubygems.org\"\n\ngemspec\n", ] { let mut files = BTreeMap::new(); files.insert("Gemfile".to_string(), gemfile.to_string()); @@ -20462,6 +20476,15 @@ mod tests { "{gemfile}: {:?}", r.warnings ); + // #2151: every way out the warning names works. Vendored mode + // refuses the gem for the same reason, so it is not one. + let detail = &r.warnings[0].detail; + assert!( + detail.contains("a literal `gem \"rack\"` line in Gemfile") + && detail.contains("`--mode agent`"), + "{gemfile}: {detail}" + ); + assert!(!detail.contains("vendored"), "{gemfile}: {detail}"); } // Control: a genuinely transitive gem (absent from DEPENDENCIES) is // still appended. diff --git a/crates/socket-patch-core/src/vendor/gem.rs b/crates/socket-patch-core/src/vendor/gem.rs index 30881a61c..1c88920a8 100644 --- a/crates/socket-patch-core/src/vendor/gem.rs +++ b/crates/socket-patch-core/src/vendor/gem.rs @@ -7599,7 +7599,8 @@ mod tests { } /// #482: a DIRECT dependency declared where the line grammar cannot see - /// it (`eval_gemfile`, a loop) is listed under the lock's DEPENDENCIES. + /// it (`eval_gemfile`, a loop, a gemspec) is listed under the lock's + /// DEPENDENCIES. /// Appending the managed block would declare it twice and bundler /// refuses every install, so the plan must refuse before any write. #[tokio::test] @@ -7607,12 +7608,27 @@ mod tests { for gemfile in [ "source \"https://rubygems.org\"\n\ngem \"puma\"\neval_gemfile \"Gemfile.common\"\n", "source \"https://rubygems.org\"\n\ngem \"puma\"\n%w[rack].each { |g| gem g, \"~> 3.1\" }\n", + // A gem only the gemspec declares (a development dependency). + "source \"https://rubygems.org\"\n\ngem \"puma\"\ngemspec\n", + "source \"https://rubygems.org\"\r\n\r\ngem \"puma\"\r\ngemspec path: \"gems/mylib\"\r\n", ] { let (_tmp, root, installed, blobs, record) = fixture(gemfile, LOCK_DIRECT).await; let (code, detail) = unwrap_refused(run_vendor(&root, &blobs, &installed, &record, false).await); assert_eq!(code, "gemfile_declaration_not_editable", "{gemfile}"); assert!(detail.contains("direct dependency"), "{detail}"); + // #2151: the refusal names its way out, and no mode that + // refuses the gem as well (hosted mode does, for this reason). + assert!( + detail.contains("one literal `gem \"rack\"` line"), + "{detail}" + ); + assert_names_other_modes(&detail, &["agent"]); + assert_eq!( + detail.contains("above `gemspec`"), + gemfile.contains("\ngemspec"), + "{detail}" + ); assert!(!root.join(".socket").exists()); assert_eq!( tokio::fs::read_to_string(root.join(GEMFILE)).await.unwrap(), From 7f933c5630f1bba95aad6377098a5d3f6f63bd19 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 09:58:12 +0000 Subject: [PATCH 3/4] Fix gem remedy naming a mode that refuses too 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 Claude-Session: https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- .../src/patch/redirect/mod.rs | 5 ++- crates/socket-patch-core/src/vendor/gem.rs | 41 +++++++++++++++++-- docs/ecosystems.md | 8 ++-- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 0b8d58656..292ad6af6 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -408,7 +408,7 @@ The rewriter reads a fixed set of candidate files from the project root: the npm **Non-UTF-8 candidate files (#721)**: the rewriters edit UTF-8 text only. A candidate file that exists but is not UTF-8 (for example a UTF-16 `requirements.txt`, which is what Windows PowerShell 5.1's `pip freeze >` writes and which pip installs from) is never read as absent. When a candidate of its ecosystem could rewrite it, the run is refused with `candidate_file_unreadable` (exit 1, `--dry-run` included), the message names the file, and nothing is written; the remedy is to re-save the file as UTF-8. Two exceptions keep their own refusals. A Gradle build file the Gradle planner reaches gets that planner's per-build refusal (`redirect_gradle_build_file_unreadable`, exit 0) and the rest of the run goes ahead, and with no readable Gradle build a stray Gradle file (a lock, a nested script) is never rewritten, so it does not refuse the run, while a non-UTF-8 root `settings.gradle(.kts)` or `build.gradle(.kts)` still refuses it (it may be the build itself). An unreadable `socket-patch.sbt` is refused with `redirect_sbt_owned_file_unreadable`. A vendored→hosted takeover checks this before it reverts anything, so a refused run leaves the vendored wiring, ledger entry and artifact byte-identical. Vendored mode likewise refuses a non-UTF-8 `requirements.txt` or `-r` include by name (`pypi_no_requirements`) instead of wiring around it. Lock-only discovery reads `requirements.txt` and its in-root `-r` includes the way pip decodes them (a UTF-16 or UTF-32 byte-order mark selects that encoding), so such a project's pins are still found instead of reporting "No packages found". -**Gem hosted wiring**: for a gem the manifest (`Gemfile` / `gems.rb`) declares, hosted mode appends ONE option to the user's own declaration, `, source: ""`, after its last argument, and changes nothing else of it: version requirement(s), quote style, other options, trailing comment, position, enclosing `group` / `platforms` / `install_if` block and indentation stay byte for byte. This covers a parenthesized call (the option goes inside the parentheses), a declaration continued over several lines (after the last argument, on its line), several version requirements, `%w` / symbol option values, a trailing `if` / `unless` / `while` / `until` / `rescue` modifier (the option goes before the modifier) and a declaration followed by another statement after a `;`. For a gem the manifest does not declare (a transitive dependency: the lock's `DEPENDENCIES` does not list it) hosted mode adds exactly one line at the end of the manifest, `gem "", "", source: "", require: false # added by socket-patch (transitive dependency)`, after one blank line, in the file's own line ending and keeping whether the file ends on one. `require: false` keeps `Bundler.require` from loading a gem it did not load before the line existed; the marker comment is what tells the unwind the whole line is socket-patch's. **The lock always follows** (the pair is what the Bundler that wrote the lock writes for that manifest, so frozen / deployment installs accept it as committed): on a lock written by Bundler ≥ 2.2 the gem's spec moves to a `GEM` section of its own whose `remote:` is the index URL (sections ordered as Bundler orders them); on a lock written by Bundler 1.17–2.1 the index URL joins the `remote:` lines of the one merged `GEM` section, in the order Bundler derives from the manifest's sources; the `DEPENDENCIES` entry keeps the requirement the manifest declares and gains `!` (a transitive gem gets ` (= )!`); and where the lock has a `CHECKSUMS` section the gem's entry is set to the patched artifact's sha256. A lock with no `CHECKSUMS` section (Bundler < 2.6) is converged the same way and pins the gem by source alone; the run reports that ONCE, naming the gems, as `redirect_gem_no_checksums_section`. A lock does not record which Bundler installs it, only which one wrote it (`BUNDLED WITH`), so the pair is converged for that one; when it is the merged layout of Bundler < 2.2, which later Bundlers deprecate and from 2.5 on refuse under frozen / deployment mode, the run that writes the lock adds `redirect_gem_merged_lock_layout` naming the Bundler the pair is for. **Never a half-applied pair**: each gem is planned on a copy of the pair and committed only when the planned manifest and lock agree about it (the manifest gives it the index URL as its one source; the lock resolves it from a `GEM` section naming that remote, with a source-pinned `DEPENDENCIES` entry). A gem whose declaration cannot take the option, or whose lock cannot follow, is refused with neither file changed for it, and the warning's detail gives the reason and the way out: `redirect_gem_unrecognized_declaration` (the declaration cannot be edited in place — a heredoc or `do` block among its arguments, code before it on its line, a string spanning lines, a last argument that is not a literal and may be an options hash: it is taken for a version requirement only when the lock shows one requirement per positional argument, every other positional is a single quoted string, and the manifest has no `gemspec` directive, whose own requirement for the gem bundler folds into the lock entry, …), `redirect_gem_source_option` (it already selects a source: a `source:` / `git:` / `github:` / `path:` option or one a `**opts` splat may hold, a declaration inside a `source` / `git` / `github` / `path` block, a `DEPENDENCIES` entry that is already source-pinned, or a lock that resolves the gem from a `GIT` / `PATH` section), `redirect_gem_declared_more_than_once`, `redirect_gem_declaration_not_visible` (a direct dependency declared in an `eval_gemfile`d file, a loop or a gemspec), `redirect_gem_dependency_not_locked` (declared, but the lock's `DEPENDENCIES` does not list it), `redirect_gem_lock_unconvergeable` (no `BUNDLED WITH` section to say which layout the lock's Bundler accepts, or a merged Bundler < 2.2 section whose remotes the manifest's sources do not explain) and `redirect_gem_inconsistent_plan` (the self-check above failed; a bug guard, never expected). A re-scan recognizes its own option (the grant-token and patch-uuid path levels of the URL rotate, so they are matched as wildcards) and refreshes the URL in place, in the manifest and the lock together; a re-scan of an unchanged project writes nothing. A lock reverted or regenerated without its manifest (the option still there, the lock back on the registry) is converged again by the next hosted scan. **Pins written by socket-patch 5.0 / 5.1** used a `source "" do … end` block in the declaration's place and, on a lock with no `CHECKSUMS` section, left the lock alone. That form is never written any more but stays recognized everywhere (re-scan, `list`, `vex`, `rollback` / `remove`, the takeovers): a re-scan keeps the block as it is, refreshes its URL like the option's, and converges a lock that never followed it; only where that lock cannot be converged does the run still warn `redirect_gem_frozen_install`. Human mode prints one line after the summary naming the declarations changed, e.g. ``Added `source:` to 3 gem declarations in Gemfile (puma, rack, and rexml); added 1 line for the transitive dependency nokogiri.`` **Update hold**: a gem wired this way has the patch registry as its only source, and that source serves the one patched version, so `bundle outdated` no longer lists the gem and `bundle update` cannot move it (a range requirement included) until its pin is rolled back. When a run newly wires at least one gem (an option appended or a line added, not a refreshed URL), human mode prints one more stdout line under that one, naming those gems once each: ``Bundler now takes rack from its Socket patch source only, which serves the patched version and no other: `bundle outdated` no longer lists it and `bundle update` cannot move it. To move it to a newer release, run `socket-patch rollback pkg:gem/rack@3.1.8`, then `bundle update rack`, then `socket-patch scan` again.`` The rollback step always names a purl (the gem's own for one gem, the shape `pkg:gem/@` for several), never a bare `rollback`, which would unwind every patch; after `get` the last step reads "then patch the new version the same way"; `--dry-run` words the first sentence as what the run would hold and prints no steps. `--json` and `--silent` output are unchanged (no warning code). Pinned against real Bundler by `tests/e2e_redirect_gem_build.rs`. See `docs/ecosystems.md` ("Ruby gems: hosted mode") for the user-facing description. +**Gem hosted wiring**: for a gem the manifest (`Gemfile` / `gems.rb`) declares, hosted mode appends ONE option to the user's own declaration, `, source: ""`, after its last argument, and changes nothing else of it: version requirement(s), quote style, other options, trailing comment, position, enclosing `group` / `platforms` / `install_if` block and indentation stay byte for byte. This covers a parenthesized call (the option goes inside the parentheses), a declaration continued over several lines (after the last argument, on its line), several version requirements, `%w` / symbol option values, a trailing `if` / `unless` / `while` / `until` / `rescue` modifier (the option goes before the modifier) and a declaration followed by another statement after a `;`. For a gem the manifest does not declare (a transitive dependency: the lock's `DEPENDENCIES` does not list it) hosted mode adds exactly one line at the end of the manifest, `gem "", "", source: "", require: false # added by socket-patch (transitive dependency)`, after one blank line, in the file's own line ending and keeping whether the file ends on one. `require: false` keeps `Bundler.require` from loading a gem it did not load before the line existed; the marker comment is what tells the unwind the whole line is socket-patch's. **The lock always follows** (the pair is what the Bundler that wrote the lock writes for that manifest, so frozen / deployment installs accept it as committed): on a lock written by Bundler ≥ 2.2 the gem's spec moves to a `GEM` section of its own whose `remote:` is the index URL (sections ordered as Bundler orders them); on a lock written by Bundler 1.17–2.1 the index URL joins the `remote:` lines of the one merged `GEM` section, in the order Bundler derives from the manifest's sources; the `DEPENDENCIES` entry keeps the requirement the manifest declares and gains `!` (a transitive gem gets ` (= )!`); and where the lock has a `CHECKSUMS` section the gem's entry is set to the patched artifact's sha256. A lock with no `CHECKSUMS` section (Bundler < 2.6) is converged the same way and pins the gem by source alone; the run reports that ONCE, naming the gems, as `redirect_gem_no_checksums_section`. A lock does not record which Bundler installs it, only which one wrote it (`BUNDLED WITH`), so the pair is converged for that one; when it is the merged layout of Bundler < 2.2, which later Bundlers deprecate and from 2.5 on refuse under frozen / deployment mode, the run that writes the lock adds `redirect_gem_merged_lock_layout` naming the Bundler the pair is for. **Never a half-applied pair**: each gem is planned on a copy of the pair and committed only when the planned manifest and lock agree about it (the manifest gives it the index URL as its one source; the lock resolves it from a `GEM` section naming that remote, with a source-pinned `DEPENDENCIES` entry). A gem whose declaration cannot take the option, or whose lock cannot follow, is refused with neither file changed for it, and the warning's detail gives the reason and the way out: `redirect_gem_unrecognized_declaration` (the declaration cannot be edited in place — a heredoc or `do` block among its arguments, code before it on its line, a string spanning lines, a last argument that is not a literal and may be an options hash: it is taken for a version requirement only when the lock shows one requirement per positional argument, every other positional is a single quoted string, and the manifest has no `gemspec` directive, whose own requirement for the gem bundler folds into the lock entry, …), `redirect_gem_source_option` (it already selects a source: a `source:` / `git:` / `github:` / `path:` option or one a `**opts` splat may hold, a declaration inside a `source` / `git` / `github` / `path` block, a `DEPENDENCIES` entry that is already source-pinned, or a lock that resolves the gem from a `GIT` / `PATH` section), `redirect_gem_declared_more_than_once`, `redirect_gem_declaration_not_visible` (a direct dependency declared in an `eval_gemfile`d file, a loop or a gemspec; vendored mode refuses it for the same reason, so the way out is a literal `gem` line or `--mode agent`), `redirect_gem_dependency_not_locked` (declared, but the lock's `DEPENDENCIES` does not list it), `redirect_gem_lock_unconvergeable` (no `BUNDLED WITH` section to say which layout the lock's Bundler accepts, or a merged Bundler < 2.2 section whose remotes the manifest's sources do not explain) and `redirect_gem_inconsistent_plan` (the self-check above failed; a bug guard, never expected). A re-scan recognizes its own option (the grant-token and patch-uuid path levels of the URL rotate, so they are matched as wildcards) and refreshes the URL in place, in the manifest and the lock together; a re-scan of an unchanged project writes nothing. A lock reverted or regenerated without its manifest (the option still there, the lock back on the registry) is converged again by the next hosted scan. **Pins written by socket-patch 5.0 / 5.1** used a `source "" do … end` block in the declaration's place and, on a lock with no `CHECKSUMS` section, left the lock alone. That form is never written any more but stays recognized everywhere (re-scan, `list`, `vex`, `rollback` / `remove`, the takeovers): a re-scan keeps the block as it is, refreshes its URL like the option's, and converges a lock that never followed it; only where that lock cannot be converged does the run still warn `redirect_gem_frozen_install`. Human mode prints one line after the summary naming the declarations changed, e.g. ``Added `source:` to 3 gem declarations in Gemfile (puma, rack, and rexml); added 1 line for the transitive dependency nokogiri.`` **Update hold**: a gem wired this way has the patch registry as its only source, and that source serves the one patched version, so `bundle outdated` no longer lists the gem and `bundle update` cannot move it (a range requirement included) until its pin is rolled back. When a run newly wires at least one gem (an option appended or a line added, not a refreshed URL), human mode prints one more stdout line under that one, naming those gems once each: ``Bundler now takes rack from its Socket patch source only, which serves the patched version and no other: `bundle outdated` no longer lists it and `bundle update` cannot move it. To move it to a newer release, run `socket-patch rollback pkg:gem/rack@3.1.8`, then `bundle update rack`, then `socket-patch scan` again.`` The rollback step always names a purl (the gem's own for one gem, the shape `pkg:gem/@` for several), never a bare `rollback`, which would unwind every patch; after `get` the last step reads "then patch the new version the same way"; `--dry-run` words the first sentence as what the run would hold and prints no steps. `--json` and `--silent` output are unchanged (no warning code). Pinned against real Bundler by `tests/e2e_redirect_gem_build.rs`. See `docs/ecosystems.md` ("Ruby gems: hosted mode") for the user-facing description. **Gem stale-install guard (the canonical narrative; other mentions point here)**: the gem hosted rewrite is pure Gemfile/lock text, and Bundler keeps a gem it already holds whatever source the lock names. So after the rewrite a hosted run looks for the gems the project already has on disk, replaces the project's own stale copies with the patched gem itself, and warns about the rest. The unwind (`rollback`, `remove`, a withdrawn-patch restore) does the same in the other direction. Exit code and `status` never change: a refresh that cannot be done leaves everything as it was and falls back to the warning. diff --git a/crates/socket-patch-core/src/patch/redirect/mod.rs b/crates/socket-patch-core/src/patch/redirect/mod.rs index a51f5085f..fb2357b61 100644 --- a/crates/socket-patch-core/src/patch/redirect/mod.rs +++ b/crates/socket-patch-core/src/patch/redirect/mod.rs @@ -8256,7 +8256,8 @@ fn plan_gem_redirect( // Not declared where the rewriter can see it, yet bundler resolved // it as a DIRECT dependency: the Gemfile declares it out of sight // (`eval_gemfile`, a loop, a gemspec). Adding a line would declare - // it twice (#482). + // it twice (#482). Vendored mode refuses the gem for the same + // reason, so the way out names agent mode alone (#2151). return Err(refuse( "redirect_gem_declaration_not_visible", format!( @@ -8264,7 +8265,7 @@ fn plan_gem_redirect( 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 \"{name}\"` line in \ - {gemfile_name}, or patch it with `--mode vendored` or `--mode agent`)" + {gemfile_name}, or patch it with `--mode agent`)" ), )); } else { diff --git a/crates/socket-patch-core/src/vendor/gem.rs b/crates/socket-patch-core/src/vendor/gem.rs index 1c88920a8..eebb2db36 100644 --- a/crates/socket-patch-core/src/vendor/gem.rs +++ b/crates/socket-patch-core/src/vendor/gem.rs @@ -306,7 +306,7 @@ pub async fn gem_vendor_target_preflight( .ok()?, }; plan_gemfile_edit(&gemfile_text, &name, &version, ©_rel) - .and_then(|plan| refuse_append_of_direct_dependency(plan, &lock_text, &name)) + .and_then(|plan| refuse_append_of_direct_dependency(plan, &gemfile_text, &lock_text, &name)) .and_then(|plan| { let after = apply_gemfile_plan(&gemfile_text, &plan); gemspec_merge_refusal(project_root, &after, &lock_text, &name, &version) @@ -579,8 +579,14 @@ fn gem_edits( } // ── Gemfile edit plan (refusals before any write) ──────────────────── let plan = match plan_gemfile_edit(&prelude.gemfile_text, name, version, &prelude.copy_rel) - .and_then(|plan| refuse_append_of_direct_dependency(plan, &prelude.lock_text, name)) - { + .and_then(|plan| { + refuse_append_of_direct_dependency( + plan, + &prelude.gemfile_text, + &prelude.lock_text, + name, + ) + }) { Ok(p) => p, Err(detail) => { return Err(Box::new(refused( @@ -1635,8 +1641,11 @@ fn plan_gemfile_edit( /// declares it somewhere the line grammar cannot see (`eval_gemfile`, a /// loop, a gemspec). The managed block would declare it a second time and /// bundler refuses every install (#482). Every other plan passes through. +/// `gemfile_text` is the Gemfile the plan was made for; the refusal reads +/// it to word its way out ([`out_of_sight_declaration_remedy`]). fn refuse_append_of_direct_dependency( plan: GemfilePlan, + gemfile_text: &str, lock_text: &str, name: &str, ) -> Result { @@ -1647,12 +1656,36 @@ fn refuse_append_of_direct_dependency( "Gemfile.lock lists \"{name}\" 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)" + duplicates); {}", + out_of_sight_declaration_remedy(gemfile_text, name) )); } Ok(plan) } +/// The way out of [`refuse_append_of_direct_dependency`] (#2151): a `gem` +/// line the line grammar can edit, or agent mode. Hosted mode is not named: +/// it refuses the gem for the same reason +/// (`redirect_gem_declaration_not_visible`). +/// +/// Where the Gemfile has a `gemspec` directive (or one that cannot be +/// read), the line goes above it: a gemspec development dependency on the +/// gem merged into a line below the directive is refused next +/// ([`gemspec_merge_refusal`]). +fn out_of_sight_declaration_remedy(gemfile_text: &str, name: &str) -> String { + let above_gemspec = crate::formats::gem::gemspec::gemspec_directives(gemfile_text) + .map_or(true, |directives| !directives.is_empty()); + let place = if above_gemspec { + " above `gemspec`" + } else { + "" + }; + format!( + "declare it with one literal `gem \"{name}\"` line{place} in the Gemfile, or patch \ + {name} with `--mode agent`" + ) +} + /// Looser "declared at all?" probe — the redirect rewriter's `declared_re` /// twin. True when a non-comment line is a `gem` call (the keyword followed /// by anything but an identifier character) whose arguments quote the exact diff --git a/docs/ecosystems.md b/docs/ecosystems.md index 2e0c021f6..b2a04b2f0 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -2040,12 +2040,13 @@ wire is skipped, neither file changes for it, and the warning says why and what | `redirect_gem_unrecognized_declaration` | its declaration cannot be edited in place: a heredoc or a `do` block among its arguments, other code before it on its line, a last argument that may be an options hash (`gem "rack", OPTS`). Write it as one `gem "", …` call with literal arguments on a line of its own. | | `redirect_gem_source_option` | the declaration already selects a source (`source:`, `git:`, `github:`, `path:`, a `**opts` splat that may hold one), sits inside a `source` / `git` / `github` / `path` block, or the lock resolves the gem from a `GIT` / `PATH` section. Bundler allows one source per gem. | | `redirect_gem_declared_more_than_once` | the Gemfile declares it more than once. Merge the declarations into one. | -| `redirect_gem_declaration_not_visible` | the lock lists it as a direct dependency, but it is declared where the scan cannot edit: an `eval_gemfile`d file, a loop, a gemspec. | +| `redirect_gem_declaration_not_visible` | the lock lists it as a direct dependency, but it is declared where the scan cannot edit: an `eval_gemfile`d file, a loop, a gemspec. Declare it with a literal `gem ""` line in the Gemfile, or patch it with `--mode agent`. Vendored mode refuses it for the same reason. | | `redirect_gem_dependency_not_locked` | the Gemfile declares it and the lock's `DEPENDENCIES` does not list it. Run `bundle lock` and re-run. | | `redirect_gem_lock_unconvergeable` | the lock cannot be brought in line with the Gemfile: it has no `BUNDLED WITH` section to say which layout its Bundler accepts, or a Bundler < 2.2 lock lists its sources in an order the Gemfile's `source` lines do not explain. Run `bundle lock` with your current Bundler and re-run. | | `redirect_gem_platform_unsupported` | the lock holds a platform-specific build of the gem (`nokogiri (1.16.0-x86_64-linux)`); the patch registry serves the `ruby` platform gem only. | -`--mode vendored` or `--mode agent` can still patch a gem hosted mode skips. +`--mode agent` can still patch a gem hosted mode skips, and so can `--mode vendored` where the +warning names it. **Undoing it.** `rollback` and `remove` take the option (or the added line) off again and restore the lock: the pair is the pre-scan pair byte for byte, with LF or CRLF line endings. @@ -2150,12 +2151,13 @@ mode warns `redirect_gem_version_not_locked`, vendored mode reports a `skipped` Vendored mode rewrites one top-level `gem` line to a `path:` source, and Bundler builds nothing for a path-sourced gem. It refuses a gem that doesn't fit and changes nothing for it; the other -gems of the run are still vendored, and the run exits 1. These three refusals name another mode +gems of the run are still vendored, and the run exits 1. These four refusals name another mode that can patch the gem: | Code | The gem | What the error offers | |---|---|---| | `gemfile_declaration_not_editable` ("is indented") | is declared inside a block: `group :test do`, `platforms … do`, a conditional. Every Rails Gemfile declares its development and test gems this way. | Move the declaration to the top level (for a plain `group` block the error spells the option that replaces it, `group: :test`), or patch the gem with `--mode hosted`, which edits a declaration where it is. Inside a `source`, `git`, `github` or `path` block hosted mode refuses the gem too, and the error names `--mode agent`. | +| `gemfile_declaration_not_editable` ("as a direct dependency") | is a direct dependency the Gemfile declares out of sight: in a gemspec (a gem library's development dependency), an `eval_gemfile`d file, a loop. | Declare it with one literal `gem ""` line in the Gemfile (above `gemspec`, where the Gemfile has that directive), or patch the gem with `--mode agent`. Hosted mode refuses the gem too. | | `native_extensions_unsupported` | builds a native extension (puma, bootsnap). | `--mode hosted` or `--mode agent`. Both build the extension. Only `--mode agent` when the declaration picks the gem's source (a `source`, `git`, `github` or `path` block or option), which hosted mode refuses. | | `platform_gem_unsupported` | is installed as a precompiled platform build (`nokogiri-1.18.3-x86_64-linux-gnu`). | `--mode agent`. Hosted mode refuses a precompiled build too. | From 0831ba54fa79869294cd3cbb95b42a8bc04947e7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 10:11:48 +0000 Subject: [PATCH 4/4] Say the literal gem line replaces a hidden one 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 Claude-Session: https://claude.ai/code/session_011f9aePcxbHH9zFcxrD7z4f --- .../tests/e2e_vendor_gem_build.rs | 50 +++++++++++++++++++ .../src/patch/redirect/mod.rs | 14 ++++-- crates/socket-patch-core/src/vendor/gem.rs | 36 +++++++++---- docs/ecosystems.md | 8 +-- 4 files changed, 90 insertions(+), 18 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs b/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs index dc0f16aa5..dff961856 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs @@ -1791,6 +1791,56 @@ fn gem_vendor_refuses_an_eval_gemfile_direct_dep() { String::from_utf8_lossy(&install.stderr) ); } + + // #2151: the refusal names its way out, and following it works. The + // literal line takes the hidden declaration's place: left next to it, + // the vendored pin would be a second declaration that differs, which + // bundler refuses. + let error = event["error"].as_str().unwrap_or_default(); + assert!( + error.contains( + "one literal `gem \"rack\"` line in the Gemfile, in place of any other `gem` call \ + that declares it" + ) && error.contains("`--mode agent`"), + "the refusal names its ways out: {event}" + ); + assert!( + !error.contains("--mode hosted"), + "hosted mode refuses this gem for the same reason: {event}" + ); + std::fs::write(proj.join("Gemfile.common"), "# shared gems\n").unwrap(); + std::fs::write( + proj.join("Gemfile"), + "source \"https://rubygems.org\"\n\ngem \"rack\", \"~> 3.1\"\neval_gemfile \"Gemfile.common\"\n", + ) + .unwrap(); + let relock = bundle(&proj, &["install"], false); + assert!( + relock.status.success(), + "the Gemfile installs with the remedy followed (test premise):\n{}", + String::from_utf8_lossy(&relock.stderr) + ); + let (code, stdout, stderr) = run_socket( + &proj, + &[ + "vendor", + "--json", + "--offline", + "--cwd", + proj.to_str().unwrap(), + ], + ); + assert_eq!( + code, 0, + "vendor failed with the remedy followed.\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + assert_eq!(parse_json_envelope(&stdout)["summary"]["applied"], 1); + let install = bundle(&proj, &["install"], true); + assert!( + install.status.success(), + "frozen install of the vendored pair failed:\n{}", + String::from_utf8_lossy(&install.stderr) + ); } /// A static `file://` rubygems source serving one empty gem, diff --git a/crates/socket-patch-core/src/patch/redirect/mod.rs b/crates/socket-patch-core/src/patch/redirect/mod.rs index fb2357b61..026dd2437 100644 --- a/crates/socket-patch-core/src/patch/redirect/mod.rs +++ b/crates/socket-patch-core/src/patch/redirect/mod.rs @@ -8257,7 +8257,10 @@ fn plan_gem_redirect( // it as a DIRECT dependency: the Gemfile declares it out of sight // (`eval_gemfile`, a loop, a gemspec). Adding a line would declare // it twice (#482). Vendored mode refuses the gem for the same - // reason, so the way out names agent mode alone (#2151). + // reason, so the way out names agent mode alone (#2151). The + // literal line replaces a `gem` call out of sight: next to it, + // the line's `source:` option gives the gem two sources and + // bundler refuses the manifest. return Err(refuse( "redirect_gem_declaration_not_visible", format!( @@ -8265,7 +8268,8 @@ fn plan_gem_redirect( 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 \"{name}\"` line in \ - {gemfile_name}, or patch it with `--mode agent`)" + {gemfile_name}, in place of any other `gem` call that declares it, or patch \ + it with `--mode agent`)" ), )); } else { @@ -20481,8 +20485,10 @@ mod tests { // refuses the gem for the same reason, so it is not one. let detail = &r.warnings[0].detail; assert!( - detail.contains("a literal `gem \"rack\"` line in Gemfile") - && detail.contains("`--mode agent`"), + detail.contains( + "a literal `gem \"rack\"` line in Gemfile, in place of any other `gem` \ + call that declares it" + ) && detail.contains("`--mode agent`"), "{gemfile}: {detail}" ); assert!(!detail.contains("vendored"), "{gemfile}: {detail}"); diff --git a/crates/socket-patch-core/src/vendor/gem.rs b/crates/socket-patch-core/src/vendor/gem.rs index eebb2db36..525dcc91a 100644 --- a/crates/socket-patch-core/src/vendor/gem.rs +++ b/crates/socket-patch-core/src/vendor/gem.rs @@ -1665,24 +1665,31 @@ fn refuse_append_of_direct_dependency( /// The way out of [`refuse_append_of_direct_dependency`] (#2151): a `gem` /// line the line grammar can edit, or agent mode. Hosted mode is not named: -/// it refuses the gem for the same reason -/// (`redirect_gem_declaration_not_visible`). +/// it refuses a gem declared in a gemspec, an `eval_gemfile`d file or a +/// loop for the same reason (`redirect_gem_declaration_not_visible`). /// -/// Where the Gemfile has a `gemspec` directive (or one that cannot be -/// read), the line goes above it: a gemspec development dependency on the -/// gem merged into a line below the directive is refused next -/// ([`gemspec_merge_refusal`]). +/// The line stands in place of a `gem` call that declares the gem out of +/// sight, never next to it: the rewrite gives the line an exact version +/// and a `path:`, and bundler refuses a Gemfile whose two declarations of +/// a gem differ. A gemspec's development dependency is no `gem` call and +/// stays. +/// +/// Where the Gemfile has a `gemspec` directive, the line goes above it: a +/// gemspec development dependency on the gem merged into a line below the +/// directive is refused next ([`gemspec_merge_refusal`]). A Gemfile whose +/// directives cannot be read gets no such hint, which would not help it: +/// that refusal cannot tell either way and names hosted mode. fn out_of_sight_declaration_remedy(gemfile_text: &str, name: &str) -> String { let above_gemspec = crate::formats::gem::gemspec::gemspec_directives(gemfile_text) - .map_or(true, |directives| !directives.is_empty()); + .is_ok_and(|directives| !directives.is_empty()); let place = if above_gemspec { " above `gemspec`" } else { "" }; format!( - "declare it with one literal `gem \"{name}\"` line{place} in the Gemfile, or patch \ - {name} with `--mode agent`" + "declare it with one literal `gem \"{name}\"` line{place} in the Gemfile, in place \ + of any other `gem` call that declares it, or patch {name} with `--mode agent`" ) } @@ -7644,6 +7651,9 @@ mod tests { // A gem only the gemspec declares (a development dependency). "source \"https://rubygems.org\"\n\ngem \"puma\"\ngemspec\n", "source \"https://rubygems.org\"\r\n\r\ngem \"puma\"\r\ngemspec path: \"gems/mylib\"\r\n", + // No directive: a variable of that name, which a loop reads. + "source \"https://rubygems.org\"\n\ngem \"puma\"\ngemspec_file = Gem::Specification.load(\"x.gemspec\")\ngemspec_file.development_dependencies.each { |d| gem d.name }\n", + "source \"https://rubygems.org\"\n\ngem \"puma\"\nspec = Gem::Specification.load(\"x.gemspec\")\n\ngemspec = spec\ngemspec.development_dependencies.each { |d| gem d.name }\n", ] { let (_tmp, root, installed, blobs, record) = fixture(gemfile, LOCK_DIRECT).await; let (code, detail) = @@ -7657,9 +7667,15 @@ mod tests { "{detail}" ); assert_names_other_modes(&detail, &["agent"]); + // The line replaces a `gem` call out of sight: next to it, + // the vendored pin would be a second, differing declaration. + assert!( + detail.contains("in place of any other `gem` call that declares it"), + "{detail}" + ); assert_eq!( detail.contains("above `gemspec`"), - gemfile.contains("\ngemspec"), + gemfile.contains("\ngemspec\n") || gemfile.contains("\ngemspec path:"), "{detail}" ); assert!(!root.join(".socket").exists()); diff --git a/docs/ecosystems.md b/docs/ecosystems.md index b2a04b2f0..31775967b 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -2040,13 +2040,13 @@ wire is skipped, neither file changes for it, and the warning says why and what | `redirect_gem_unrecognized_declaration` | its declaration cannot be edited in place: a heredoc or a `do` block among its arguments, other code before it on its line, a last argument that may be an options hash (`gem "rack", OPTS`). Write it as one `gem "", …` call with literal arguments on a line of its own. | | `redirect_gem_source_option` | the declaration already selects a source (`source:`, `git:`, `github:`, `path:`, a `**opts` splat that may hold one), sits inside a `source` / `git` / `github` / `path` block, or the lock resolves the gem from a `GIT` / `PATH` section. Bundler allows one source per gem. | | `redirect_gem_declared_more_than_once` | the Gemfile declares it more than once. Merge the declarations into one. | -| `redirect_gem_declaration_not_visible` | the lock lists it as a direct dependency, but it is declared where the scan cannot edit: an `eval_gemfile`d file, a loop, a gemspec. Declare it with a literal `gem ""` line in the Gemfile, or patch it with `--mode agent`. Vendored mode refuses it for the same reason. | +| `redirect_gem_declaration_not_visible` | the lock lists it as a direct dependency, but it is declared where the scan cannot edit: an `eval_gemfile`d file, a loop, a gemspec. Declare it with a literal `gem ""` line in the Gemfile, in place of any other `gem` call that declares it (a gemspec's development dependency stays), or patch it with `--mode agent`. Vendored mode refuses it for the same reason. | | `redirect_gem_dependency_not_locked` | the Gemfile declares it and the lock's `DEPENDENCIES` does not list it. Run `bundle lock` and re-run. | | `redirect_gem_lock_unconvergeable` | the lock cannot be brought in line with the Gemfile: it has no `BUNDLED WITH` section to say which layout its Bundler accepts, or a Bundler < 2.2 lock lists its sources in an order the Gemfile's `source` lines do not explain. Run `bundle lock` with your current Bundler and re-run. | | `redirect_gem_platform_unsupported` | the lock holds a platform-specific build of the gem (`nokogiri (1.16.0-x86_64-linux)`); the patch registry serves the `ruby` platform gem only. | -`--mode agent` can still patch a gem hosted mode skips, and so can `--mode vendored` where the -warning names it. +`--mode agent` can still patch a gem hosted mode skips. `--mode vendored` can too, unless it +refuses the gem itself (see "Ruby gems: gems vendored mode refuses"). **Undoing it.** `rollback` and `remove` take the option (or the added line) off again and restore the lock: the pair is the pre-scan pair byte for byte, with LF or CRLF line endings. @@ -2157,7 +2157,7 @@ that can patch the gem: | Code | The gem | What the error offers | |---|---|---| | `gemfile_declaration_not_editable` ("is indented") | is declared inside a block: `group :test do`, `platforms … do`, a conditional. Every Rails Gemfile declares its development and test gems this way. | Move the declaration to the top level (for a plain `group` block the error spells the option that replaces it, `group: :test`), or patch the gem with `--mode hosted`, which edits a declaration where it is. Inside a `source`, `git`, `github` or `path` block hosted mode refuses the gem too, and the error names `--mode agent`. | -| `gemfile_declaration_not_editable` ("as a direct dependency") | is a direct dependency the Gemfile declares out of sight: in a gemspec (a gem library's development dependency), an `eval_gemfile`d file, a loop. | Declare it with one literal `gem ""` line in the Gemfile (above `gemspec`, where the Gemfile has that directive), or patch the gem with `--mode agent`. Hosted mode refuses the gem too. | +| `gemfile_declaration_not_editable` ("as a direct dependency") | is a direct dependency the Gemfile declares out of sight: in a gemspec (a gem library's development dependency), an `eval_gemfile`d file, a loop. | Declare it with one literal `gem ""` line in the Gemfile (above `gemspec`, where the Gemfile has that directive), in place of any other `gem` call that declares it, or patch the gem with `--mode agent`. Hosted mode refuses a gem declared in those places too. | | `native_extensions_unsupported` | builds a native extension (puma, bootsnap). | `--mode hosted` or `--mode agent`. Both build the extension. Only `--mode agent` when the declaration picks the gem's source (a `source`, `git`, `github` or `path` block or option), which hosted mode refuses. | | `platform_gem_unsupported` | is installed as a precompiled platform build (`nokogiri-1.18.3-x86_64-linux-gnu`). | `--mode agent`. Hosted mode refuses a precompiled build too. |