Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/socket-patch-cli/tests/common/bundler_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ 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 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
}
}

/// Parse `bundle --version` stdout: `Bundler version 2.7.2` (bundler < 4)
Expand Down Expand Up @@ -188,5 +201,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));
}
}
89 changes: 64 additions & 25 deletions crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,37 +784,76 @@ fn gem_vendor_fresh_checkout_bundle_install_and_revert() {
String::from_utf8_lossy(&clean.stderr),
);
let cleaned_gem_dir = cleaned.join(gem_dir.strip_prefix(&proj).unwrap());
assert!(
!cleaned_gem_dir.exists(),
"`bundle clean` must remove the leftover {}",
cleaned_gem_dir.display()
);
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 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!(
!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,
"`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
Expand Down
Loading