Skip to content

Commit 52230be

Browse files
committed
Let a shadowed [patch] Socket pin pin no hosted declaration
FALSE ATTESTATION (found reviewing #2019; fixed here, where `Shadow` lives): a root `[patch.crates-io]` Socket registry pin cargo ignores (a `[patch."<crates.io URL>"]` table replaces it, or the config redefines the key) still counted as pinning every crates.io declaration of the crate, so a member's plain declaration was taken as routed to the patch and the hosted ref attested while cargo builds crates.io. Such an entry stays a declaration (Socket's wiring is present, the ref stays) but is not live, and `route` only weighs live `[patch]` pins, as the vendored bypass check already weighs only honored entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1021784 commit 52230be

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

  • crates/socket-patch-core/src/vex/discover

‎crates/socket-patch-core/src/vex/discover/cargo.rs‎

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,14 @@ pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) {
221221
for patch in patch_entries(doc) {
222222
if let Some(reg) = patch.registry {
223223
let name = patch.name.to_string();
224-
decls
225-
.entry(name)
226-
.or_default()
227-
.push(Decl::patch(CARGO_TOML, patch.source, reg));
224+
// An entry cargo ignores (a crates.io URL table replaces
225+
// `[patch.crates-io]`; the config redefines the key) is
226+
// Socket's wiring still (the ref stays) but pins nothing.
227+
let mut decl = Decl::patch(CARGO_TOML, patch.source, reg);
228+
decl.live = shadow
229+
.as_ref()
230+
.is_none_or(|s| s.why(patch.source, patch.key, None).is_none());
231+
decls.entry(name).or_default().push(decl);
228232
}
229233
}
230234
decls
@@ -995,7 +999,7 @@ fn beside_the_pin(
995999
let patch_pins: Vec<(&str, String)> = regs
9961000
.iter()
9971001
.filter_map(|d| match &d.source {
998-
DeclSource::Patch(table) => Some((table.as_str(), d.socket_uuid()?)),
1002+
DeclSource::Patch(table) if d.live => Some((table.as_str(), d.socket_uuid()?)),
9991003
_ => None,
10001004
})
10011005
.collect();
@@ -2444,6 +2448,36 @@ mod tests {
24442448
p
24452449
}
24462450

2451+
/// Review on #2019 (round 2, fixed here where `Shadow` lives): a
2452+
/// `[patch.crates-io]` Socket pin that cargo ignores (a crates.io URL
2453+
/// table replaces it) pins no declaration: the member's crates.io
2454+
/// declaration is unpinned, so the ref is not attested.
2455+
#[tokio::test]
2456+
async fn a_shadowed_patch_pin_pins_no_declaration() {
2457+
let patch = format!(
2458+
"serde = \"1\"\n\n[patch.crates-io]\nserde = {{ registry = \"socket-patch-{UUID_A}\" }}\n"
2459+
);
2460+
let p = mixed_workspace(&patch, "serde = \"1\"", &[]);
2461+
let out = run(&p).await;
2462+
assert!(out.unattested.is_empty(), "{:#?}", out.unattested);
2463+
let shadowed = format!(
2464+
"{patch}\n[patch.\"https://github.com/rust-lang/crates.io-index\"]\nother = {{ path = \"other\" }}\n"
2465+
);
2466+
let p = mixed_workspace(&shadowed, "serde = \"1\"", &[]);
2467+
let out = run(&p).await;
2468+
assert_refs(
2469+
&out,
2470+
&[("pkg:cargo/serde@1.0.1", UUID_A, WiringMode::Hosted)],
2471+
);
2472+
assert!(
2473+
out.unattested
2474+
.iter()
2475+
.any(|u| u.kind == UnattestedKind::CargoUnpinnedDeclaration),
2476+
"{:#?}",
2477+
out.unattested
2478+
);
2479+
}
2480+
24472481
/// The one unattested mark of `out`, asserted to be the hosted serde
24482482
/// ref's [`UnattestedKind::CargoUnpinnedDeclaration`] naming `file`.
24492483
fn unpinned_mark<'a>(out: &'a Discovery, file: &str) -> &'a Unattested {

0 commit comments

Comments
 (0)