@@ -1070,15 +1070,18 @@ pub(super) async fn classify_overlap_takeover_with(
10701070 Some ( uuid) => liveness. redirect_record ( & purl, uuid) . await ,
10711071 None => discovery. wires_package ( & purl, WiringMode :: Hosted ) ,
10721072 } ;
1073+ // `None`: undecided (a JVM pom that cannot be read, or a tree still
1074+ // referenced without attestable wiring) — neither live nor dead.
10731075 let vendored_live = match vendor_by_purl. get ( & PurlKey :: new ( & purl) ) {
1074- Some ( entry) => liveness. vendor_entry ( entry) . await ,
1075- None => false ,
1076+ Some ( entry) => liveness. vendor_entry_state ( entry) . await ,
1077+ None => Some ( false ) ,
10761078 } ;
10771079 match ( hosted_live, vendored_live) {
1078- ( true , false ) => out. redirect . push ( purl) ,
1079- ( false , true ) => out. vendored . push ( purl) ,
1080- // Both (a half-migrated lock naming both) or neither (no rewire /
1081- // unreadable) does not prove a single direction — stay silent.
1080+ ( true , Some ( false ) ) => out. redirect . push ( purl) ,
1081+ ( false , Some ( true ) ) => out. vendored . push ( purl) ,
1082+ // Both (a half-migrated lock naming both), neither (no rewire)
1083+ // or an undecided vendored side (unreadable) does not prove a
1084+ // single direction — stay silent.
10821085 _ => { }
10831086 }
10841087 }
@@ -4671,6 +4674,118 @@ mod tests {
46714674 ) ;
46724675 }
46734676
4677+ // ---- maven: an undecided vendored claim is not a dead one -------------
4678+
4679+ const MAVEN_PURL : & str = "pkg:maven/org.slf4j/slf4j-api@1.7.36" ;
4680+ /// The vendored patch: another uuid than the hosted pin's, so its
4681+ /// suffixed version tells the two wirings apart.
4682+ const MAVEN_VENDORED_UUID : & str = "5c0ffee0-1d3a-4f6b-8c2d-7e5a9b1c3d5f" ;
4683+
4684+ fn maven_dep ( version : & str ) -> String {
4685+ format ! (
4686+ "<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId>\
4687+ <version>{version}</version></dependency>"
4688+ )
4689+ }
4690+
4691+ /// A root pom pinning slf4j-api to the hosted [`TAKEOVER_UUID`] patch,
4692+ /// with `extra` (a `<build>` section) inside the project.
4693+ async fn write_maven_hosted_pom ( root : & Path , extra : & str ) {
4694+ let pom = format ! (
4695+ "<?xml version=\" 1.0\" ?>\n <project xmlns=\" http://maven.apache.org/POM/4.0.0\" >\n \
4696+ <modelVersion>4.0.0</modelVersion>\n <groupId>com.example</groupId>\n \
4697+ <artifactId>app</artifactId>\n <version>1.0.0</version>\n \
4698+ <dependencies>\n {}\n </dependencies>\n <repositories>\n <repository>\n \
4699+ <id>socket-patch-{TAKEOVER_UUID}</id>\n \
4700+ <url>https://patch.socket.dev/patch-registry/maven/11111111-2222-4333-8444-555555555555/{TAKEOVER_UUID}/maven2</url>\n \
4701+ <releases>\n <enabled>true</enabled>\n \
4702+ <checksumPolicy>fail</checksumPolicy>\n </releases>\n </repository>\n \
4703+ </repositories>\n {extra}\n </project>\n ",
4704+ maven_dep( & format!( "1.7.36-socket.{}" , & TAKEOVER_UUID [ ..8 ] ) ) ,
4705+ ) ;
4706+ tokio:: fs:: write ( root. join ( "pom.xml" ) , pom) . await . unwrap ( ) ;
4707+ }
4708+
4709+ /// A vendored ledger whose one entry is a Maven reactor vendoring of
4710+ /// slf4j-api at [`MAVEN_VENDORED_UUID`].
4711+ async fn write_maven_vendor_ledger ( root : & Path ) {
4712+ let sv = format ! ( "1.7.36-socket.{}" , & MAVEN_VENDORED_UUID [ ..8 ] ) ;
4713+ let state = serde_json:: json!( {
4714+ "version" : 1 ,
4715+ "entries" : {
4716+ MAVEN_PURL : {
4717+ "ecosystem" : "maven" ,
4718+ "basePurl" : MAVEN_PURL ,
4719+ "uuid" : MAVEN_VENDORED_UUID ,
4720+ "artifact" : {
4721+ "path" : format!(
4722+ ".socket/vendor/maven2/org/slf4j/slf4j-api/{sv}/slf4j-api-{sv}.jar"
4723+ ) ,
4724+ } ,
4725+ "wiring" : [ {
4726+ "file" : "pom.xml" ,
4727+ "kind" : "maven_pom_fragment" ,
4728+ "action" : "added" ,
4729+ } ] ,
4730+ } ,
4731+ } ,
4732+ } ) ;
4733+ let dir = root. join ( ".socket/vendor" ) ;
4734+ tokio:: fs:: create_dir_all ( & dir) . await . unwrap ( ) ;
4735+ tokio:: fs:: write (
4736+ dir. join ( "state.json" ) ,
4737+ serde_json:: to_string_pretty ( & state) . unwrap ( ) ,
4738+ )
4739+ . await
4740+ . unwrap ( ) ;
4741+ }
4742+
4743+ /// A vendored Maven claim the reader cannot decide — a project file it
4744+ /// cannot read, or the vendored version left only where the build may
4745+ /// still resolve it from the tree (a build plugin's dependencies) —
4746+ /// is neither live nor dead: the `scan --prune` GC keeps it, so the
4747+ /// takeover classifier must not report it superseded (and tell the
4748+ /// user to remove it). Only a claim nothing references any more is.
4749+ #[ tokio:: test]
4750+ async fn maven_takeover_stays_silent_on_an_undecided_vendored_claim ( ) {
4751+ let vendored = format ! ( "1.7.36-socket.{}" , & MAVEN_VENDORED_UUID [ ..8 ] ) ;
4752+ let plugin = format ! (
4753+ "<build><plugins><plugin><groupId>p</groupId><artifactId>p</artifactId>\
4754+ <dependencies>{}</dependencies></plugin></plugins></build>",
4755+ maven_dep( & vendored)
4756+ ) ;
4757+ // Control: nothing references the vendored version — superseded.
4758+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
4759+ let root = tmp. path ( ) ;
4760+ write_maven_vendor_ledger ( root) . await ;
4761+ write_maven_hosted_pom ( root, "" ) . await ;
4762+ let takeover = classify_overlap_takeover ( & common_at ( root) , root) . await ;
4763+ assert_eq ! (
4764+ takeover. redirect,
4765+ vec![ MAVEN_PURL . to_string( ) ] ,
4766+ "{takeover:?}"
4767+ ) ;
4768+
4769+ // Left only in a build plugin's dependencies.
4770+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
4771+ let root = tmp. path ( ) ;
4772+ write_maven_vendor_ledger ( root) . await ;
4773+ write_maven_hosted_pom ( root, & plugin) . await ;
4774+ let takeover = classify_overlap_takeover ( & common_at ( root) , root) . await ;
4775+ assert_eq ! ( takeover, OverlapTakeover :: default ( ) ) ;
4776+
4777+ // A Maven config the reader cannot read (a directory).
4778+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
4779+ let root = tmp. path ( ) ;
4780+ write_maven_vendor_ledger ( root) . await ;
4781+ write_maven_hosted_pom ( root, "" ) . await ;
4782+ tokio:: fs:: create_dir_all ( root. join ( ".mvn/maven.config" ) )
4783+ . await
4784+ . unwrap ( ) ;
4785+ let takeover = classify_overlap_takeover ( & common_at ( root) , root) . await ;
4786+ assert_eq ! ( takeover, OverlapTakeover :: default ( ) ) ;
4787+ }
4788+
46744789 // ---- takeover DIRECTION follows the live lock, not the command ---------
46754790
46764791 /// Like [`write_vendor_ledger`] but each entry records wiring the
0 commit comments