Skip to content

Commit 6af8cd6

Browse files
Fix the vendored unwind of a platform gem (#2174) (#2175)
* Start the vendored gem unwind platform fix Claims #2174: the vendored unwind judges only the ruby-platform build of an unwound gem, so a precompiled platform build that a hosted scan replaced stays patched. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQwRPCRjnzyQ3rqcZr * Test the vendored unwind of a platform gem A gem locked as precompiled platform gems that a hosted scan patched and a vendored run then took over keeps its patched installed copy after rollback, remove and vendor --revert (#2174). The takeover leg of the platform prebuild capstone fails on that until the unwind follows the lock's builds. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQwRPCRjnzyQ3rqcZr * Refresh platform builds on a vendored gem unwind After a vendored unwind put a gem back on its upstream entry, the refresh looked only for the ruby-platform installed copy (<name>-<version>). A gem vendored from prebuilt platform gems is installed as <name>-<version>-<platform>, so a copy a hosted scan had replaced with the patched build stayed in the gem home: the app kept loading the patch, and bundle pristine failed on the restored checksum. Look for the builds the restored lock names instead, as the refresh that follows already does, and fall back to the ruby-platform gem when the lock names none. Fixes #2174 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQwRPCRjnzyQ3rqcZr * Name platform archives on a vendored gem unwind The vendored unwind's check of Bundler's cache dir judged only <name>-<version>.gem, and stopped when the lock had no ruby-platform entry: always, for a gem vendored from prebuilt platform gems. A patched <name>-<version>-<platform>.gem that a bundle cache took under the hosted pin went unnamed, and the next install took it first. Judge the archive of every build the restored lock names, as the hosted restore does, with one warning per archive. Refs #2174 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQwRPCRjnzyQ3rqcZr * Judge the ruby archive beside platform builds Review follow-ups to the vendored unwind's cache dir check: - A gem whose lock names platform builds alone still has its <name>-<version>.gem judged, as the hosted restore judges it. A gem none of whose builds can be judged stays silent. - The takeover e2e leg counts the stale-cache warnings and asserts the archive was judged patched, not unchecked. - CLI_CONTRACT.md states the archive shapes once for the whole upstream_gem_stale_cache row. Refs #2174 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQwRPCRjnzyQ3rqcZr --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6579162 commit 6af8cd6

7 files changed

Lines changed: 417 additions & 54 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

‎crates/socket-patch-cli/src/commands/gem_refresh.rs‎

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,14 +1241,16 @@ pub(crate) async fn after_vendored_unwind(
12411241
unwound: &[String],
12421242
records: &BTreeMap<String, PatchRecord>,
12431243
) -> RestoreRefresh {
1244+
use socket_patch_core::patch::redirect::upstream::gem_upstream;
1245+
12441246
let mut installed: BTreeSet<String> = BTreeSet::new();
1245-
// A vendored gem is the ruby-platform gem: a platform build installed
1246-
// beside it was never the vendored copy's stand-in.
1247-
let ruby_builds: Vec<(String, String)> = unwound
1248-
.iter()
1249-
.filter_map(|purl| Some((purl.clone(), GemBuild::ruby(purl)?.leaf)))
1250-
.collect();
1251-
for copy in installed_builds(common, &ruby_builds).await {
1247+
// The builds the restored lock names: a gem vendored from prebuilt
1248+
// platform gems is back on its platform entries, and the copy Bundler
1249+
// loads again is `<name>-<version>-<platform>` (#2174). Reading the
1250+
// lock asks no registry.
1251+
let lock = gem_upstream(&common.cwd, &BTreeMap::new(), true).await;
1252+
let builds = build_leaves(&named_builds(&lock, unwound), |_| true);
1253+
for copy in installed_builds(common, &builds).await {
12521254
if copy.archive.is_file() || holds_patch(&copy, records).await {
12531255
installed.insert(copy.purl);
12541256
}
@@ -1268,6 +1270,26 @@ pub(crate) async fn after_vendored_unwind(
12681270
.await
12691271
}
12701272

1273+
/// The builds of each gem of `gems` that are this project's: the ones the
1274+
/// restored lock (`upstream`) names. A lock that names none (it could not
1275+
/// be read) leaves the ruby-platform gem, the one build an unwind looked
1276+
/// at before platform builds were followed.
1277+
fn named_builds(
1278+
upstream: &socket_patch_core::patch::redirect::upstream::GemUpstream,
1279+
gems: &[String],
1280+
) -> BTreeMap<String, Vec<GemBuild>> {
1281+
let mut named = BTreeMap::new();
1282+
for (purl, builds) in gems.iter().zip(upstream.builds(gems)) {
1283+
let builds = if builds.is_empty() {
1284+
GemBuild::ruby(purl).into_iter().collect()
1285+
} else {
1286+
builds
1287+
};
1288+
named.insert(purl.clone(), builds);
1289+
}
1290+
named
1291+
}
1292+
12711293
async fn refresh_restored(
12721294
common: &GlobalArgs,
12731295
restored: &[String],
@@ -1308,19 +1330,7 @@ async fn refresh_restored(
13081330
// The restored lock, read once, and one registry client for every
13091331
// lookup below.
13101332
let upstream = gem_upstream(&common.cwd, staged, common.offline).await;
1311-
// The builds of each restored gem that are this project's: the ones the
1312-
// restored lock names. A lock that names none (it could not be read)
1313-
// leaves the ruby-platform gem, the one build an unwind looked at
1314-
// before platform builds were followed.
1315-
let mut named: BTreeMap<String, Vec<GemBuild>> = BTreeMap::new();
1316-
for (purl, builds) in gems.iter().zip(upstream.builds(&gems)) {
1317-
let builds = if builds.is_empty() {
1318-
GemBuild::ruby(purl).into_iter().collect()
1319-
} else {
1320-
builds
1321-
};
1322-
named.insert(purl.clone(), builds);
1323-
}
1333+
let named = named_builds(&upstream, &gems);
13241334
// A lock names a platform build for every platform the project
13251335
// supports, and this machine holds one of them: only a platform build
13261336
// that is installed in a gem home Bundler uses or (in [`Scope::All`])

‎crates/socket-patch-cli/src/commands/vendored_backend/mod.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ fn is_gem(ecosystem: &str) -> bool {
387387
socket_patch_core::vendor::jvm::layout::ledger_ecosystem(ecosystem) == "gem"
388388
}
389389

390-
/// Name a patched `<name>-<version>.gem` left in Bundler's cache dir once
391-
/// the vendored ledger entry of `ecosystem` for `base_purl` is unwired: a
390+
/// Name each patched `<name>-<version>[-<platform>].gem` left in Bundler's
391+
/// cache dir once the vendored ledger entry of `ecosystem` for `base_purl`
392+
/// is unwired: a
392393
/// `bundle cache` taken while a hosted pin was live keeps it there through
393394
/// the takeover, and bundler installs from it again once the lock is back
394395
/// on upstream. The hosted unwind raises the same warning.
@@ -402,7 +403,7 @@ pub(crate) async fn push_gem_stale_cache(
402403
if !is_gem(ecosystem) {
403404
return;
404405
}
405-
if let Some((code, detail)) =
406+
for (code, detail) in
406407
socket_patch_core::patch::redirect::upstream::gem_stale_cache_after_unwind(
407408
root, base_purl, offline,
408409
)

0 commit comments

Comments
 (0)