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
8 changes: 7 additions & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,13 @@ worse, lets a warm cache silently serve unpatched bytes):
* `vendor --revert` restores the originals (fragments that no longer match — a user re-resolved —
are left alone with a `vendor_lock_entry_drifted` warning; the drift-kept artifact and entry stay,
every backend alike — gem included as of v5.0, where a MISSING `Gemfile`/`Gemfile.lock` instead
warns `vendor_lockfile_missing` and still removes the artifact; composer / maven / nuget, whose
warns `vendor_lockfile_missing` and still removes the artifact, and where a fragment that cannot
be restored once neither `Gemfile` nor `Gemfile.lock` names the `.socket/vendor/gem/<uuid>` dir,
or a vendored copy of the gem under another patch uuid, in any spelling — the gem was dropped
with `bundle remove`, or moved to another release — is not drift: it warns
`vendor_lock_entry_removed`, both files stay as the user left them, and the artifact and entry
are removed, so `vendor --revert` / `rollback` / `remove` / `scan --prune` clean up after it (a
file of the two that cannot be read fails the revert, which keeps both); composer / maven / nuget, whose
whole-file wiring cannot tell a converged fragment from a drifted one, keep the artifact exactly
while the live `composer.lock` / `pom.xml` / `nuget.config` still names its
`.socket/vendor/<eco>/<uuid>` dir — a file that no longer references it is warned about and the
Expand Down
128 changes: 128 additions & 0 deletions crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,134 @@ fn gem_vendor_drops_positional_constraints() {
}
}

/// #2325: after the project drops a vendored gem (`bundle remove`) or moves
/// it to another release, nothing bundler reads names the vendored copy any
/// more. `vendor --check` reports the dead entry, and each undo command
/// then cleans it up: the copy and its ledger record go, the user's
/// Gemfile and Gemfile.lock stay byte for byte, a frozen install still
/// passes, and `vendor --check` is green again.
#[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_dropped_gem_is_cleaned_up_by_every_undo_command() {
// How the project drops the gem, and the command that cleans up.
let cases: [(&str, &[&str]); 4] = [
("remove", &["vendor", "--revert"]),
("remove", &["rollback"]),
("remove", &["remove", "--yes"]),
("upgrade", &["vendor", "--revert"]),
];
for (how, undo) in cases {
let what = format!("{how}, then `{}`", undo.join(" "));
let Some((_tmp, proj, _bundler, purl)) = staged_rack_project("dropped gem") else {
return;
};
let cwd = proj.to_str().unwrap();
let (code, stdout, stderr) =
run_socket(&proj, &["vendor", "--json", "--offline", "--cwd", cwd]);
assert_eq!(code, 0, "{what}: vendor failed.\n{stdout}\n{stderr}");
let uuid_dir = proj.join(".socket/vendor/gem").join(UUID);
assert!(uuid_dir.is_dir(), "{what}: vendored copy written");

// The user's edit, with real bundler.
let edit = match how {
// Bundler <= 2.1 edits only the Gemfile on `remove`; the
// install that follows re-locks, as it does for such a user.
"remove" => {
let remove = bundle(&proj, &["remove", DEP], false);
assert!(
remove.status.success(),
"{what}: `bundle remove` (test premise):\n{}",
String::from_utf8_lossy(&remove.stderr)
);
bundle(&proj, &["install"], false)
}
_ => {
let version = purl.rsplit('@').next().unwrap();
let other = if version == "3.1.8" { "3.1.9" } else { "3.1.8" };
std::fs::write(
proj.join("Gemfile"),
format!("source \"https://rubygems.org\"\n\ngem \"rack\", \"{other}\"\n"),
)
.unwrap();
bundle(&proj, &["install"], false)
}
};
assert!(
edit.status.success(),
"{what}: the user's bundler command (test premise):\n{}",
String::from_utf8_lossy(&edit.stderr)
);
let gemfile = std::fs::read(proj.join("Gemfile")).unwrap();
let lock = std::fs::read(proj.join("Gemfile.lock")).unwrap();
for file in [&gemfile, &lock] {
assert!(
!String::from_utf8_lossy(file).contains(".socket/vendor"),
"{what}: bundler left no reference to the vendored copy (test premise)"
);
}
let (code, stdout, stderr) = run_socket(&proj, &["vendor", "--check", "--cwd", cwd]);
assert!(
code == 1 && format!("{stdout}{stderr}").contains("wiring missing"),
"{what}: vendor --check reports the dead entry.\n{stdout}\n{stderr}"
);

// The clean-up.
let mut args: Vec<&str> = undo.to_vec();
if undo[0] != "vendor" {
args.push(&purl);
}
args.extend(["--json", "--cwd", cwd]);
let (code, stdout, stderr) = run_socket(&proj, &args);
assert_eq!(
code, 0,
"{what}: failed.\nstdout:\n{stdout}\nstderr:\n{stderr}"
);
let env = parse_json_envelope(&stdout);
assert_eq!(env["status"], "success", "{what}: {env}");
let all = format!("{stdout}{stderr}");
assert!(
!all.contains("drift"),
"{what}: a dropped gem is not reported as drift:\n{all}"
);

assert!(!uuid_dir.exists(), "{what}: the dead copy is removed");
let state = proj.join(".socket/vendor/state.json");
assert!(
!state.exists() || !std::fs::read_to_string(&state).unwrap().contains(UUID),
"{what}: the ledger record is dropped"
);
assert_eq!(
std::fs::read(proj.join("Gemfile")).unwrap(),
gemfile,
"{what}: the user's Gemfile is left alone"
);
assert_eq!(
std::fs::read(proj.join("Gemfile.lock")).unwrap(),
lock,
"{what}: the user's Gemfile.lock is left alone"
);
let install = bundle(&proj, &["install"], true);
assert!(
install.status.success(),
"{what}: a frozen install passes after the clean-up:\n{}",
String::from_utf8_lossy(&install.stderr)
);
// `remove` drops the manifest's patch too, so the audit has nothing
// left to hold the project to. The other two keep that patch, which
// the audit then reports as not vendored: no longer a dead entry.
let (code, stdout, stderr) = run_socket(&proj, &["vendor", "--check", "--cwd", cwd]);
let audit = format!("{stdout}{stderr}");
assert!(
!audit.contains("wiring missing") && !audit.contains(UUID),
"{what}: vendor --check no longer reports the dead entry:\n{audit}"
);
if undo[0] == "remove" {
assert_eq!(code, 0, "{what}: vendor --check is green again:\n{audit}");
}
}
}

/// #1821: vendoring over a CRLF Gemfile keeps every line CRLF (the rewired
/// `gem` line used to end in a bare LF), a real frozen install accepts the
/// result, and revert restores the Gemfile byte for byte.
Expand Down
Loading
Loading