From 05b36d140650012236535579c4070a04972c52fd Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 13:29:23 +0000 Subject: [PATCH 1/3] Start bundle clean test fix for Bundler 1.x (#2115) Assisted-by: Claude Code:claude-fable-5-2 From ab7c58fa5f836568636b6f791a5523acc9723dd2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 13:34:41 +0000 Subject: [PATCH 2/3] Fix bundle clean assertion on Bundler 1.x The nightly gem leg runs Bundler 1.17.3 on Ruby 3.1. There bundle clean prints 'Removing rack (3.2.8)', exits 0 and leaves the directory: the FileUtils copy Bundler vendors before 2.1 calls Dir.entries(path, {}), Ruby >= 3.0 rejects the positional hash, and rm_rf swallows the error. The step added with #2081 asserted the directory was gone, so it failed on that leg every time. The test now asserts on every Bundler that bundle clean names the leftover as stale. On Bundler < 2.1 with Ruby >= 3.0 it checks the directory is still there and removes it by hand, so the lock and vex checks after it still run. Every other pair keeps the original assertion. Fixes #2115 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aePEeutq9i2gda491Vn --- .../tests/common/bundler_e2e.rs | 16 +++++++++ .../tests/e2e_vendor_gem_build.rs | 33 ++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/crates/socket-patch-cli/tests/common/bundler_e2e.rs b/crates/socket-patch-cli/tests/common/bundler_e2e.rs index 37f425757..bed5b8f61 100644 --- a/crates/socket-patch-cli/tests/common/bundler_e2e.rs +++ b/crates/socket-patch-cli/tests/common/bundler_e2e.rs @@ -68,6 +68,17 @@ impl Bundler { argv.extend(["--local".into(), key.into(), value.into()]); argv } + + /// `bundle clean` on this bundler, run by a Ruby of major version + /// `ruby_major`, names a stale gem directory (`Removing rack (3.2.8)`), + /// exits 0 and leaves the directory on disk. The FileUtils copy bundler + /// vendors before 2.1 lists a directory with `Dir.entries(path, {})`; + /// Ruby >= 3.0 rejects the positional hash, and `rm_rf` swallows the + /// error. Stale files (`cache/*.gem`, `specifications/*.gemspec`) are + /// still deleted. + pub fn clean_leaves_directories(&self, ruby_major: u32) -> bool { + !self.at_least(2, 1) && ruby_major >= 3 + } } /// Parse `bundle --version` stdout: `Bundler version 2.7.2` (bundler < 4) @@ -188,5 +199,10 @@ mod bundler_e2e_selftest { b.config_local_args("path", "vendor/bundle"), ["config", "set", "--local", "path", "vendor/bundle"] ); + let b1 = parse_version("Bundler version 1.17.3").unwrap(); + assert!(b1.clean_leaves_directories(3) && !b1.clean_leaves_directories(2)); + assert!(old.clean_leaves_directories(3)); + let fixed = parse_version("Bundler version 2.1.4").unwrap(); + assert!(!fixed.clean_leaves_directories(3) && !b.clean_leaves_directories(3)); } } 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 6cc86ed8e..dab19c4aa 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs @@ -783,12 +783,37 @@ fn gem_vendor_fresh_checkout_bundle_install_and_revert() { String::from_utf8_lossy(&clean.stdout), String::from_utf8_lossy(&clean.stderr), ); - let cleaned_gem_dir = cleaned.join(gem_dir.strip_prefix(&proj).unwrap()); + let clean_out = String::from_utf8_lossy(&clean.stdout).into_owned(); assert!( - !cleaned_gem_dir.exists(), - "`bundle clean` must remove the leftover {}", - cleaned_gem_dir.display() + clean_out.contains(&format!("Removing {DEP} ({version})")), + "`bundle clean` must name the leftover as stale (bundler {}):\n{clean_out}", + bundler.version ); + let cleaned_gem_dir = cleaned.join(gem_dir.strip_prefix(&proj).unwrap()); + let ruby_major: u32 = api + .split('.') + .next() + .and_then(|major| major.parse().ok()) + .unwrap_or_else(|| panic!("unparseable ruby api version {api:?}")); + if bundler.clean_leaves_directories(ruby_major) { + // #2115: this bundler cannot delete a directory on this Ruby (see + // `clean_leaves_directories`), so finish its removal by hand. The + // assertion keeps this arm from outliving the defect. + assert!( + cleaned_gem_dir.exists(), + "bundler {} on Ruby {api} removed {}: `clean_leaves_directories` is out of date", + bundler.version, + cleaned_gem_dir.display() + ); + std::fs::remove_dir_all(&cleaned_gem_dir).unwrap(); + } else { + assert!( + !cleaned_gem_dir.exists(), + "`bundle clean` must remove the leftover {} (bundler {}, Ruby {api})", + cleaned_gem_dir.display(), + bundler.version + ); + } assert_eq!( std::fs::read(cleaned.join("Gemfile.lock")).unwrap(), lock_wired, From 71f0fce6d74c571a1feaffb5388996e7fc2c36b5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 13:41:52 +0000 Subject: [PATCH 3/3] Pin what vex reports while the leftover stays Review of the first commit: the stdout check is only needed where bundle clean fails to delete, so it moves into that arm and the other Bundler legs no longer depend on Bundler's wording. On the affected pair the test now also runs vex before removing the directory by hand and asserts vendored_tree_out_of_sync is still reported, so the test shows what a user on that pair sees. The helper's doc comment names the call each Bundler line makes. Refs #2115 Assisted-by: Claude Code:claude-fable-5-2 --- .../tests/common/bundler_e2e.rs | 12 ++-- .../tests/e2e_vendor_gem_build.rs | 72 +++++++++++-------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/crates/socket-patch-cli/tests/common/bundler_e2e.rs b/crates/socket-patch-cli/tests/common/bundler_e2e.rs index bed5b8f61..e159b5526 100644 --- a/crates/socket-patch-cli/tests/common/bundler_e2e.rs +++ b/crates/socket-patch-cli/tests/common/bundler_e2e.rs @@ -71,11 +71,13 @@ impl Bundler { /// `bundle clean` on this bundler, run by a Ruby of major version /// `ruby_major`, names a stale gem directory (`Removing rack (3.2.8)`), - /// exits 0 and leaves the directory on disk. The FileUtils copy bundler - /// vendors before 2.1 lists a directory with `Dir.entries(path, {})`; - /// Ruby >= 3.0 rejects the positional hash, and `rm_rf` swallows the - /// error. Stale files (`cache/*.gem`, `specifications/*.gemspec`) are - /// still deleted. + /// exits 0 and leaves it on disk unless it is empty. The FileUtils copy + /// bundler vendors before 2.1 lists a directory with a positional + /// options hash (`Dir.entries(path, {})` in 1.17, `Dir.children(path, + /// opts)` in 2.0); Ruby >= 3.0 rejects it, so the directory's contents + /// are never visited and `rm_rf` swallows the failed `rmdir`. 2.1 passes + /// `**opts`. Stale files (`cache/*.gem`, `specifications/*.gemspec`) + /// are still deleted. pub fn clean_leaves_directories(&self, ruby_major: u32) -> bool { !self.at_least(2, 1) && ruby_major >= 3 } 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 dab19c4aa..17a8c6f4b 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs @@ -783,28 +783,59 @@ fn gem_vendor_fresh_checkout_bundle_install_and_revert() { String::from_utf8_lossy(&clean.stdout), String::from_utf8_lossy(&clean.stderr), ); - let clean_out = String::from_utf8_lossy(&clean.stdout).into_owned(); - assert!( - clean_out.contains(&format!("Removing {DEP} ({version})")), - "`bundle clean` must name the leftover as stale (bundler {}):\n{clean_out}", - bundler.version - ); let cleaned_gem_dir = cleaned.join(gem_dir.strip_prefix(&proj).unwrap()); + let vex_cleaned = || { + let (code, stdout, stderr) = run_socket( + &cleaned, + &[ + "vex", + "--json", + "--cwd", + cleaned.to_str().unwrap(), + "--output", + cleaned.join("out.vex.json").to_str().unwrap(), + "--product", + "pkg:gem/app@1.0.0", + ], + ); + assert_eq!(code, 0, "vex failed.\nstdout:\n{stdout}\nstderr:\n{stderr}"); + let env = parse_json_envelope(&stdout); + assert_eq!(env["status"], "success", "envelope: {env}"); + env + }; + let out_of_sync = |env: &serde_json::Value| { + env["warnings"] + .as_array() + .is_some_and(|w| w.iter().any(|w| w["code"] == "vendored_tree_out_of_sync")) + }; let ruby_major: u32 = api .split('.') .next() .and_then(|major| major.parse().ok()) .unwrap_or_else(|| panic!("unparseable ruby api version {api:?}")); if bundler.clean_leaves_directories(ruby_major) { - // #2115: this bundler cannot delete a directory on this Ruby (see - // `clean_leaves_directories`), so finish its removal by hand. The - // assertion keeps this arm from outliving the defect. + // #2115: this bundler decides to remove the leftover and cannot + // delete a non-empty directory on this Ruby (see + // `clean_leaves_directories`). The two assertions keep this arm from + // outliving the defect; `vex` keeps warning for as long as the + // directory is there. Then finish the removal by hand. + let clean_out = String::from_utf8_lossy(&clean.stdout); + assert!( + clean_out.contains(&format!("Removing {DEP} ({version})")), + "`bundle clean` must name the leftover as stale (bundler {}):\n{clean_out}", + bundler.version + ); assert!( cleaned_gem_dir.exists(), "bundler {} on Ruby {api} removed {}: `clean_leaves_directories` is out of date", bundler.version, cleaned_gem_dir.display() ); + let env = vex_cleaned(); + assert!( + out_of_sync(&env), + "the leftover this `bundle clean` could not delete is still reported: {env}" + ); std::fs::remove_dir_all(&cleaned_gem_dir).unwrap(); } else { assert!( @@ -819,27 +850,10 @@ fn gem_vendor_fresh_checkout_bundle_install_and_revert() { lock_wired, "`bundle clean` must leave Gemfile.lock byte-identical" ); - let (code, stdout, stderr) = run_socket( - &cleaned, - &[ - "vex", - "--json", - "--cwd", - cleaned.to_str().unwrap(), - "--output", - cleaned.join("out.vex.json").to_str().unwrap(), - "--product", - "pkg:gem/app@1.0.0", - ], - ); - assert_eq!(code, 0, "vex failed.\nstdout:\n{stdout}\nstderr:\n{stderr}"); - let env = parse_json_envelope(&stdout); - assert_eq!(env["status"], "success", "envelope: {env}"); + let env = vex_cleaned(); assert!( - env["warnings"] - .as_array() - .is_none_or(|w| w.iter().all(|w| w["code"] != "vendored_tree_out_of_sync")), - "nothing is out of sync after `bundle clean`: {env}" + !out_of_sync(&env), + "nothing is out of sync once the leftover is gone: {env}" ); // 7. REVERT PROOF: both halves of the pair edit byte-restored, artifacts