@@ -760,6 +760,12 @@ pub struct Discovery {
760760 /// (#1445) ([`StaleSelector`]). Not refs and not contested wiring: the
761761 /// management commands retire them. Sorted, deduped.
762762 pub stale_selectors : Vec < StaleSelector > ,
763+ /// The operator's patch-server origins ([`DiscoverOptions::patch_server_origins`])
764+ /// this discovery classified urls with. Ledger liveness
765+ /// ([`Discovery::redirect_record_live`]) classifies the lock inventory's
766+ /// urls with the same origins, so a record discovery does not claim is
767+ /// judged by the one origin rule ([`crate::patch::redirect::hosted_patch_uuid`]).
768+ pub patch_server_origins : Vec < String > ,
763769}
764770
765771/// A Socket-hosted yarn berry `resolutions` selector whose lock entry is
@@ -1544,6 +1550,7 @@ async fn discover_with_ctx(mut ctx: DiscoverCtx<'_>) -> Discovery {
15441550 out. unattest_unwired_copies ( ) ;
15451551 out. recognized . extend ( ctx. take_recognized ( ) ) ;
15461552 out. read . extend ( ctx. take_read ( ) ) ;
1553+ out. patch_server_origins = ctx. patch_server_origins . to_vec ( ) ;
15471554 out. finalize ( ) ;
15481555 out
15491556}
@@ -2755,8 +2762,11 @@ impl Discovery {
27552762 /// `source "<patch registry>" do` block still declares the gem
27562763 /// ([`gem::gemfile_source_block_pins`]): live — bundler re-resolves
27572764 /// from it whatever the lock says;
2758- /// 1. a lock inventory entry for this purl whose resolved url carries
2759- /// the uuid: live;
2765+ /// 1. a lock inventory entry for this purl whose resolved url is a
2766+ /// Socket-hosted url for THIS uuid
2767+ /// ([`crate::patch::redirect::hosted_patch_uuid`] over Socket's host
2768+ /// and [`Discovery::patch_server_origins`]): live. A url on any other
2769+ /// host that merely contains the uuid is not a patch reference;
27602770 /// 2. a lock inventory entry that resolves the purl from somewhere ELSE
27612771 /// (a registry url, a crates.io-checksummed Cargo.lock source): dead
27622772 /// — the lock positively says the build fetches the unpatched
@@ -2823,10 +2833,12 @@ impl Discovery {
28232833 . iter ( )
28242834 . filter ( |e| lookup ( std:: slice:: from_ref ( * e) , purl) . is_some ( ) )
28252835 . collect ( ) ;
2826- if entries
2827- . iter ( )
2828- . any ( |e| e. resolved . as_deref ( ) . is_some_and ( |r| r. contains ( uuid) ) )
2829- {
2836+ if entries. iter ( ) . any ( |e| {
2837+ e. resolved . as_deref ( ) . is_some_and ( |r| {
2838+ crate :: patch:: redirect:: hosted_patch_uuid ( r, & self . patch_server_origins ) . as_deref ( )
2839+ == Some ( uuid)
2840+ } )
2841+ } ) {
28302842 return true ;
28312843 }
28322844 if entries. iter ( ) . any ( |e| resolves_elsewhere ( e) ) {
@@ -2929,9 +2941,10 @@ impl<'a> LedgerLiveness<'a> {
29292941 }
29302942}
29312943
2932- /// A lock inventory entry (already known NOT to carry the patch uuid in its
2933- /// resolved url) that positively resolves from a non-patch source: an
2934- /// explicit artifact url, or a crates.io Cargo.lock source (the registry
2944+ /// A lock inventory entry (already known NOT to resolve from the record's
2945+ /// patch: its resolved url, if any, is no Socket-hosted url for that uuid)
2946+ /// that positively resolves from somewhere else: an explicit artifact url
2947+ /// (another host, or another patch), or a crates.io Cargo.lock source (the registry
29352948/// view's [`SourceKind::CratesIo`]; Socket sparse sources carry no url in
29362949/// the inventory and so prove nothing either way). An entry with no url is
29372950/// the conventional registry for most formats but is also how the inventory
@@ -3900,12 +3913,13 @@ mod tests {
39003913 }
39013914
39023915 /// REGRESSION: step 2's negative evidence reads EVERY lock's instance.
3903- /// `uv.lock` routes six to a hosted wheel on a patch host outside the
3904- /// discovery allowlist (no `hosted_claim`), and a PEP 723 script lock
3905- /// that sorts first resolves the same six from PyPI. The collapsed
3906- /// inventory keeps only the script lock's instance, which made the
3907- /// record look resolved-elsewhere (dead) although the project lock still
3908- /// installs the patch.
3916+ /// `uv.lock` routes six to a hosted wheel on the operator's configured
3917+ /// patch server, which a discovery that holds no claim on the uuid
3918+ /// classifies with the run's origins, and a PEP 723 script lock that
3919+ /// sorts first resolves the same six from PyPI. The collapsed inventory
3920+ /// keeps only the script lock's instance, which made the record look
3921+ /// resolved-elsewhere (dead) although the project lock still installs
3922+ /// the patch.
39093923 #[ tokio:: test]
39103924 async fn a_script_lock_registry_instance_does_not_veto_the_hosted_project_lock ( ) {
39113925 let p = Project :: new ( ) ;
@@ -3964,6 +3978,19 @@ mod tests {
39643978 None ,
39653979 "host not allowlisted"
39663980 ) ;
3981+ // Without the origin, the internal host's url is no patch reference
3982+ // however much of the uuid it spells: dead.
3983+ let mut inventory = None ;
3984+ assert ! (
3985+ !discovery
3986+ . redirect_record_live( root, purl, UUID_A , & [ "uv.lock" ] , & mut inventory)
3987+ . await ,
3988+ "a uuid on an unconfigured host keeps nothing alive"
3989+ ) ;
3990+ let discovery = Discovery {
3991+ patch_server_origins : vec ! [ "https://patches.internal.example" . to_string( ) ] ,
3992+ ..Discovery :: default ( )
3993+ } ;
39673994 let mut inventory = None ;
39683995 assert ! (
39693996 discovery
@@ -4096,6 +4123,70 @@ mod tests {
40964123 assert ! ( !hosted_wiring_in_files( root, & [ "package-lock.json" ] , "not-a-uuid" ) . await ) ;
40974124 }
40984125
4126+ /// REGRESSION (P6): step 1 classifies a lock entry's resolved url with
4127+ /// the one origin rule ([`crate::patch::redirect::hosted_patch_uuid`]),
4128+ /// never by substring. A url on another host that merely spells the
4129+ /// record's uuid — even in Socket's own path shape — resolves the
4130+ /// package from somewhere else (step 2: dead), as does a Socket url for
4131+ /// ANOTHER patch whose path also carries the uuid (as its grant
4132+ /// token). A Socket-host url and a configured origin's url for the
4133+ /// record's uuid stay live.
4134+ #[ tokio:: test]
4135+ async fn liveness_matches_the_resolved_url_by_origin_not_substring ( ) {
4136+ let origin = "http://127.0.0.1:4545" ;
4137+ let purl = "pkg:npm/x@1.0.0" ;
4138+ let elsewhere =
4139+ format ! ( "https://evil.example/patch/npm/x/1.0.0/{TOKEN}/{UUID_A}/x-1.0.0.tgz" ) ;
4140+ let other_patch =
4141+ format ! ( "https://patch.socket.dev/patch/npm/x/1.0.0/{UUID_A}/{UUID_B}/x-1.0.0.tgz" ) ;
4142+ let socket = hosted_url ( "npm" , "x" , "1.0.0" , UUID_A , "x-1.0.0.tgz" ) ;
4143+ let configured = format ! ( "{origin}/patch/npm/x/1.0.0/{TOKEN}/{UUID_A}/x-1.0.0.tgz" ) ;
4144+ let with_origin = Discovery {
4145+ patch_server_origins : vec ! [ origin. to_string( ) ] ,
4146+ ..Discovery :: default ( )
4147+ } ;
4148+ for ( resolved, origins_discovery, live) in [
4149+ ( & elsewhere, & with_origin, false ) ,
4150+ ( & other_patch, & with_origin, false ) ,
4151+ ( & configured, & Discovery :: default ( ) , false ) ,
4152+ ( & socket, & Discovery :: default ( ) , true ) ,
4153+ ( & configured, & with_origin, true ) ,
4154+ ] {
4155+ let p = Project :: new ( ) ;
4156+ p. write (
4157+ "package-lock.json" ,
4158+ format ! (
4159+ r#"{{"lockfileVersion":3,"packages":{{"":{{}},"node_modules/x":{{"version":"1.0.0","resolved":"{resolved}"}}}}}}"#
4160+ ) ,
4161+ ) ;
4162+ let mut inventory = None ;
4163+ assert_eq ! (
4164+ origins_discovery
4165+ . redirect_record_live(
4166+ p. root( ) ,
4167+ purl,
4168+ UUID_A ,
4169+ & [ "package-lock.json" ] ,
4170+ & mut inventory,
4171+ )
4172+ . await ,
4173+ live,
4174+ "{resolved} (origins {:?})" ,
4175+ origins_discovery. patch_server_origins
4176+ ) ;
4177+ }
4178+ }
4179+
4180+ /// Discovery records the origins it classified with, for liveness.
4181+ #[ tokio:: test]
4182+ async fn discovery_carries_its_patch_server_origins ( ) {
4183+ let p = Project :: new ( ) . with_origin ( "http://127.0.0.1:4545" ) ;
4184+ assert_eq ! (
4185+ p. discover( ) . await . patch_server_origins,
4186+ vec![ "http://127.0.0.1:4545" . to_string( ) ]
4187+ ) ;
4188+ }
4189+
40994190 /// [`LedgerLiveness`]: the redirect ledger's edit files are sorted and
41004191 /// deduplicated, verdicts are the [`Discovery`] rule's, and the lock
41014192 /// inventory loads only when a verdict first needs it and then once per
0 commit comments