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
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ worse, lets a warm cache silently serve unpatched bytes):
| npm / pnpm | `packages[].resolution.integrity` (sha512) | recomputed from the tarball; the versioned `pnpm.overrides` selector pins exactly the patched version |
| npm / bun | the packages-entry trailing `sha512-…` | recomputed from the tarball; tamper fails the frozen install on Bun ≥ 1.3.10 (URL/local tarball tuples are verified from 1.3.10, registry 4-tuples from 1.2.0 — so on 1.1.39–1.3.9 a hosted or vendored rewrite removes digest enforcement for the patched package; see `docs/testing/bun-compatibility.md`) |
| npm / vlt | node slot [2] (sha512), slot [3] (resolved) | a `file` node carries none: the committed directory is the artifact, verified against the ledger's file inventory (`vendor_inventory_mismatch` on a planted, removed or changed file); integrity-less by vlt's design, like every `file:` directory dependency |
| gem | `CHECKSUMS` section (bundler ≥ 2.6 opt-in) | the vendored gem's entry rewritten to bundler's own path-gem form (bare `name (ver)`, sha256 token stripped) so re-locks stay byte-stable; original line in the ledger. A gem vendored as platform gems has one entry per platform (`name (ver-platform)`): each is made bare, and each original line is in the ledger |
| gem | `CHECKSUMS` section (bundler ≥ 2.6 opt-in) | the vendored gem's entry rewritten to bundler's own path-gem form (bare `name (ver)`, sha256 token stripped) so re-locks stay byte-stable; original line in the ledger. A gem vendored as platform gems has one entry per platform (`name (ver-platform)`): each is made bare, and each original line is in the ledger. A platform removed from the lock after vendoring (`bundle lock --remove-platform <platform>` drops its spec entry and its `CHECKSUMS` line) is not drift: the revert puts back the entries of the platforms still locked and nothing of the removed one, which is the lock Bundler writes for that removal on the registry lock |
| pypi / uv | `wheels[].hash`, `sdist.hash`, requires-dist specifiers | single `{filename, hash: sha256-of-our-wheel}`; sdist dropped; dropped specifiers ledgered for revert |
| pypi / poetry | `files = [{file, hash}]` (2.x) / `[metadata.files]` entry (1.0/1.1) / `[metadata.hashes]` entry (0.12) | replaced with a single `{file, hash: sha256-of-our-wheel}` (or the bare hash for 0.12) in the generation's own table (Poetry ≥ 1.4 verifies the artifact against one listed hash; older writers are flagged `pypi_poetry_integrity_unverified`; stale registry hashes removed) |
| pypi / pdm | `[[package]].files[]` hashes | replaced with our wheel's sha256; hash-less locks refused (`pypi_pdm_lock_no_hashes`) |
Expand Down
72 changes: 72 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 @@ -2948,6 +2948,11 @@ async fn service_requests(server: &MockServer) -> usize {
/// 7. `vendor --revert` restores the Gemfile and the lock byte for byte
/// (the registry CHECKSUMS tokens included) and removes the trees.
///
/// Before the revert, a copy of the vendored project drops one platform
/// with `bundle lock --remove-platform`: it still installs frozen, and
/// `rollback` restores the lock bundler writes for that removal on the
/// registry lock (#2283).
///
/// Run for a gem the Gemfile declares, and for one it only reaches through
/// another gem (wired by the managed block).
#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -3451,6 +3456,73 @@ async fn platform_gems_capstone(bundler: &bundler_e2e::Bundler, declared: &str)
drop(update);
std::fs::write(&manifest_path, manifest).unwrap();

// A platform the project drops after the gem is vendored (#2283):
// `bundle lock --remove-platform` takes it out of the wired lock,
// which still installs frozen, and `rollback` then gives back the lock
// the same bundler writes for that removal on the registry lock.
let dropped = foreign[1].as_str();
let dropped_entry = format!("{PLAT} ({PLAT_VERSION}-{dropped})");
let remove_platform = |root: &Path| {
let out = bundle(root, &["lock", "--remove-platform", dropped], false);
assert!(
out.status.success(),
"`bundle lock --remove-platform {dropped}` failed in {}:\n{}",
root.display(),
String::from_utf8_lossy(&out.stderr)
);
std::fs::read_to_string(root.join("Gemfile.lock")).unwrap()
};
let registry = base.join("registry-removed");
std::fs::create_dir_all(&registry).unwrap();
std::fs::write(registry.join("Gemfile"), &gemfile_before).unwrap();
std::fs::write(registry.join("Gemfile.lock"), &lock_before).unwrap();
common::fs_tree::copy_tree(&proj.join(".bundle"), &registry.join(".bundle"));
let lock_removed = remove_platform(&registry);
let removed = base.join("vendored-removed");
common::fs_tree::copy_tree(&proj, &removed);
// Bundler 2.5 and later drop the platform's spec entries with it; an
// older one keeps them, in the registry lock and in the wired one
// alike, and the rollback then restores every entry as before.
let wired_removed = remove_platform(&removed);
assert!(
wired_removed.starts_with(&format!("PATH\n remote: {copy_rel}\n"))
&& wired_removed.contains(&dropped_entry) == lock_removed.contains(&dropped_entry),
"the wired lock loses what the registry lock loses (test premise):\n{wired_removed}"
);
let ci = bundle(&removed, &["install"], true);
assert!(
ci.status.success(),
"the vendored pair must install frozen without the removed platform.\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&ci.stdout),
String::from_utf8_lossy(&ci.stderr),
);
let (code, stdout, stderr) = run_socket(
&removed,
&[
"rollback",
"--yes",
"--json",
"--offline",
"--cwd",
removed.to_str().unwrap(),
],
);
assert_eq!(
code, 0,
"rollback after a removed platform failed.\nstdout:\n{stdout}\nstderr:\n{stderr}"
);
assert_eq!(
std::fs::read_to_string(removed.join("Gemfile.lock")).unwrap(),
lock_removed,
"rollback must give back the registry lock without the removed platform"
);
assert_eq!(
std::fs::read(removed.join("Gemfile")).unwrap(),
gemfile_before,
"rollback must restore the Gemfile byte for byte"
);
assert!(!removed.join(".socket/vendor").exists());

// 7. Revert: both files byte for byte, every tree gone.
let (code, stdout, stderr) = run_socket(
&proj,
Expand Down
Loading
Loading