Skip to content

Commit 20150bd

Browse files
Fix vendoring a hosted gem whose patch was superseded (#2129) (#2143)
* Start fix for superseded hosted gem takeover Refs #2129. Empty commit that opens the draft PR; the failing test and the fix follow. Assisted-by: Claude Code:claude-fable-5-2 * Test vendoring a hosted gem on a superseded patch Two failing hermetic cases for #2129: a hosted-pinned gem whose installed copy holds an older patch's bytes must be vendored at the newer patch, and a native gem in that state must be refused for its extension. Both report package_not_installed today. 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_011f9aeT7HWFSwgbuzoQv6kJ * Vendor a hosted gem whose patch was superseded A gem on a hosted patch has that patch's bytes installed. Once a newer patch is published, those bytes match neither side of the new record, so the vendored variant probe skipped the gem and the run reported it as package_not_installed, though it is installed and the dry run previewed success. A sole gem candidate under a live hosted pin now passes the probe with its installed dir as the source. The gem backend takes no file from that dir (the copy is the service's build) and still reads its name and gemspec, so a platform gem or a native extension is refused for what it is. PyPI got the matching exemption earlier. Fixes #2129 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_011f9aeT7HWFSwgbuzoQv6kJ * Test the hosted-gem gate at judge; share mocks Review follow-ups: a unit test drives CandidateGates::judge for a hosted-pinned gem (with and without an older ledger entry), and the suite's API mocks take the patch uuid so the newer-patch fixture reuses them instead of copying them. 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_011f9aeT7HWFSwgbuzoQv6kJ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 26d112f commit 20150bd

2 files changed

Lines changed: 334 additions & 23 deletions

File tree

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

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,8 +2860,8 @@ impl StagedSource {
28602860
/// story after a hosted scan (#1105): `uv sync` / `poetry install` from
28612861
/// the hosted lock installs a hosted patch's bytes, whichever generation
28622862
/// the pin names now. The pin names no release variant, so it only answers
2863-
/// for a sole candidate; gems keep their installed dir, which the gem
2864-
/// backend reads to refuse a platform gem.
2863+
/// for a sole candidate. A gem in that state is not superseded but
2864+
/// [`hosted_gem_install`]: it keeps its installed dir.
28652865
fn superseded_install(
28662866
ledger: &VendorState,
28672867
candidate: &str,
@@ -2876,6 +2876,22 @@ fn superseded_install(
28762876
&& matches!(Ecosystem::from_purl(candidate), Some(Ecosystem::Pypi)))
28772877
}
28782878

2879+
/// Whether an installed gem that fails `candidate`'s variant probe is still
2880+
/// `candidate` itself, under a live hosted pin (#2129): a hosted scan or a
2881+
/// `bundle install` from the hosted lock put a hosted patch's bytes there,
2882+
/// and the patch has since been superseded, so they match neither side of
2883+
/// this record. The gem backend takes no file of the installed copy (the
2884+
/// vendored copy is the service's build), so the candidate goes on with
2885+
/// its installed dir as the source: the backend still reads that dir's
2886+
/// name and gemspec to refuse a platform gem or a native extension. As for
2887+
/// PyPI, the pin names no release variant, so it only answers for a sole
2888+
/// candidate.
2889+
fn hosted_gem_install(candidate: &str, sole_candidate: bool, hosted_pinned: bool) -> bool {
2890+
sole_candidate
2891+
&& hosted_pinned
2892+
&& matches!(Ecosystem::from_purl(candidate), Some(Ecosystem::Gem))
2893+
}
2894+
28792895
/// The stand-in source of a superseded install (see [`superseded_install`]),
28802896
/// relative to the project root: a path that never exists, so the backend
28812897
/// takes the pristine artifact from the lock, the registry or the service
@@ -3004,16 +3020,22 @@ impl<'a> CandidateGates<'a> {
30043020
if !variant_matches_installed(Some(
30053021
&verify_file_patch(dir, file, info).await.status,
30063022
)) {
3007-
if !superseded_install(
3008-
ledger,
3009-
candidate,
3010-
record,
3011-
group.candidates.len() == 1,
3012-
(self.hosted_pinned)(candidate),
3013-
) {
3014-
return CandidateVerdict::Skip;
3023+
let sole_candidate = group.candidates.len() == 1;
3024+
let hosted_pinned = (self.hosted_pinned)(candidate);
3025+
// The hosted gem is asked first: it goes on from
3026+
// its installed dir, whatever the ledger records.
3027+
if !hosted_gem_install(candidate, sole_candidate, hosted_pinned) {
3028+
if !superseded_install(
3029+
ledger,
3030+
candidate,
3031+
record,
3032+
sole_candidate,
3033+
hosted_pinned,
3034+
) {
3035+
return CandidateVerdict::Skip;
3036+
}
3037+
superseded = true;
30153038
}
3016-
superseded = true;
30173039
}
30183040
}
30193041
} else if group.candidates.len() > 1
@@ -5453,6 +5475,75 @@ mod plan_gate_tests {
54535475
));
54545476
}
54555477

5478+
/// #2129: a live hosted pin lets a sole gem candidate past a failed
5479+
/// variant probe with its installed dir as the source. Other ecosystems
5480+
/// and a gem with several variant records are not its business.
5481+
#[test]
5482+
fn hosted_pin_keeps_a_gem_install_as_the_source() {
5483+
let gem = "pkg:gem/rack@3.2.8";
5484+
assert!(hosted_gem_install(gem, true, true));
5485+
assert!(!hosted_gem_install(gem, false, true));
5486+
assert!(!hosted_gem_install(gem, true, false));
5487+
assert!(!hosted_gem_install("pkg:pypi/six@1.16.0", true, true));
5488+
}
5489+
5490+
/// #2129 at the gate: an installed gem that matches neither side of
5491+
/// the record is skipped, unless the lockfiles pin it hosted. Then it
5492+
/// is vendored from its installed dir (never the stand-in a superseded
5493+
/// install gets), even when the ledger also records it at an older
5494+
/// uuid, so the backend still sees the dir's name and gemspec.
5495+
#[tokio::test]
5496+
async fn judge_sends_a_hosted_gem_on_from_its_installed_dir() {
5497+
let tmp = tempfile::tempdir().unwrap();
5498+
let root = tmp.path();
5499+
let purl = "pkg:gem/rack@3.2.8";
5500+
let dir = root.join("gems/rack-3.2.8");
5501+
std::fs::create_dir_all(&dir).unwrap();
5502+
std::fs::write(dir.join("index.php"), "an older patch's bytes").unwrap();
5503+
let all_packages = vec![(purl.to_string(), StagedSource::Installed(dir))];
5504+
let records = HashMap::from([(purl.to_string(), record(UUID_B))]);
5505+
let none = HashSet::new();
5506+
let groups = candidate_groups(&all_packages, &HashMap::new());
5507+
let unpinned = gates(root, &records, &none);
5508+
let pinned = CandidateGates {
5509+
hosted_pinned: &|_| true,
5510+
..gates(root, &records, &none)
5511+
};
5512+
let mut older = VendorState::default();
5513+
older.entries.insert(
5514+
purl.to_string(),
5515+
VendorEntry::new(
5516+
"gem".to_string(),
5517+
purl.to_string(),
5518+
UUID_A.to_string(),
5519+
socket_patch_core::vendor::state::VendorArtifact {
5520+
yarn_berry10c0: None,
5521+
path: format!(".socket/vendor/gem/{UUID_A}/rack-3.2.8"),
5522+
sha256: String::new(),
5523+
size: None,
5524+
platform_locked: None,
5525+
file_inventory: None,
5526+
},
5527+
Vec::new(),
5528+
),
5529+
);
5530+
let fresh = VendorState::default();
5531+
5532+
assert!(matches!(
5533+
unpinned.judge(&fresh, &groups[0], purl).await,
5534+
CandidateVerdict::Skip
5535+
));
5536+
for ledger in [&fresh, &older] {
5537+
assert!(matches!(
5538+
pinned.judge(ledger, &groups[0], purl).await,
5539+
CandidateVerdict::Vendor {
5540+
superseded: false,
5541+
..
5542+
}
5543+
));
5544+
}
5545+
}
5546+
54565547
/// Gates with no vendored refusals, no hosted pins and no `--force`.
54575548
pub(super) fn gates<'a>(
54585549
root: &'a Path,

0 commit comments

Comments
 (0)