From 0b99d742baf9f92171772b47dfd1aabce085c6d3 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 16 Nov 2026 14:36:12 -0500 Subject: [PATCH 1/2] Keep three tests off machine state Three test-only fixes. No product code changes. A Maven crawler unit test counted the machine's caches. `project_mode_crawl_keeps_only_the_projects_graph` wanted exactly 3 packages from a global crawl. A global crawl also reads the Coursier and Ivy caches the process environment names (HOME, COURSIER_CACHE and the JVM option sources), which `JvmEnv` does not pin, so the count depended on the machine: with one package in a Coursier cache under HOME it is 4 and the test fails. The test now looks up the three packages of its own repository in the result. It still fails if a global crawl is scoped to the project, because the package that another project cached would be missing. The CLI tests' patch service missed a Go module's directory on Windows. `prebuilt_common::source_dir` picks the directory a Go module's archive is packed from by comparing each listed directory, as text, with the purl's `@`. A module path has a `/` in it and Windows lists the module cache with `\`, so nothing matched and the service served the stand-in of `package_layout` in silence: a `go.mod` and the patched files, none of the module's own. The comparison now normalizes the separator. A self-test passes `\`-separated and `\\?\`-prefixed directories as text, so it fails without the fix on every platform. The self-update fixture names a binary that is too large to serve. `make_served_binary` serves the built `socket-patch` as the release payload, and the updater refuses an extracted binary above 256 MiB (`MAX_BINARY_BYTES`). A build above the cap failed every test that serves it with "exceeds the 268435456-byte cap", far from the cause; #2071 fixed one such build. The fixture now asserts the size first and says which setting to change. Checked on macOS arm64: - The Maven test before and after the change, with HOME as it is, with an empty HOME and with a HOME that holds a one-package Coursier cache. Before, the third run fails with 4 != 3. After, all three pass, and so do the 72 tests of the module. - The new self-test fails with the separator fix taken out (it gets the stand-in, `project/missing`) and passes with it in each of the 78 test targets that compile `prebuilt_common`. - Every test that is not ignored in the 72 of those targets that need no Docker and in the three targets that compile `update_fixture` (`self_update_e2e`, `self_update_failures_e2e`, `update`): 2623 pass. Two old-toolchain tests of `e2e_vendor_cargo_build` fail the same way without this change on that machine, whose rustup holds an x86_64 toolchain it cannot execute. Left out: nothing ran on Windows, where every Go fixture whose module cache the service lists is now packed from the module's own directory in place of the stand-in. That needs a Windows run of the CLI suites. The global crawl still reads the Coursier and Ivy caches of the process environment; that is the product's behaviour and is unchanged. Co-Authored-By: Claude Fable 5.2 --- .../tests/common/update_fixture.rs | 18 ++++++++++++- .../tests/prebuilt_common/mod.rs | 27 +++++++++++++++++++ .../src/crawlers/maven_crawler.rs | 19 +++++++++---- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/crates/socket-patch-cli/tests/common/update_fixture.rs b/crates/socket-patch-cli/tests/common/update_fixture.rs index 4e8884359..75032b76f 100644 --- a/crates/socket-patch-cli/tests/common/update_fixture.rs +++ b/crates/socket-patch-cli/tests/common/update_fixture.rs @@ -209,10 +209,26 @@ pub fn real_binary_hash() -> String { /// is the canary that fails loudly if a platform stops tolerating this. pub fn make_served_binary() -> (Vec, bool) { let mut bytes = std::fs::read(real_binary()).expect("read real binary"); + // The updater rejects an extracted binary above 256 MiB + // (`MAX_BINARY_BYTES` in core/src/update/download.rs). A test build + // that outgrows it fails every test that serves it with "exceeds the + // ...-byte cap", far from the cause: name the cause here. It happened + // to the coverage build, which keeps every function of every + // dependency (ci.yml builds it with `CARGO_PROFILE_DEV_DEBUG=0`). + const UPDATER_BINARY_CAP: usize = 256 * 1024 * 1024; + const TRAILER: &[u8] = b"\nSOCKET-PATCH-E2E-TRAILER-0123456789abcdef0123456789abcdef\n"; + assert!( + bytes.len() + TRAILER.len() <= UPDATER_BINARY_CAP, + "the built socket-patch binary is {} bytes, above the updater's \ + {UPDATER_BINARY_CAP}-byte cap on a downloaded binary, so it cannot \ + be served as a release payload: build this profile with less debug \ + info (CARGO_PROFILE_DEV_DEBUG=0)", + bytes.len() + ); if cfg!(target_os = "macos") { (bytes, false) } else { - bytes.extend_from_slice(b"\nSOCKET-PATCH-E2E-TRAILER-0123456789abcdef0123456789abcdef\n"); + bytes.extend_from_slice(TRAILER); (bytes, true) } } diff --git a/crates/socket-patch-cli/tests/prebuilt_common/mod.rs b/crates/socket-patch-cli/tests/prebuilt_common/mod.rs index 1033c8375..d4a47c7ac 100644 --- a/crates/socket-patch-cli/tests/prebuilt_common/mod.rs +++ b/crates/socket-patch-cli/tests/prebuilt_common/mod.rs @@ -480,8 +480,11 @@ fn source_dir(root: &Path, paths: &[PathBuf], purl: &str) -> PathBuf { .is_dir() } "cargo" | "gem" => leaf == format!("{name}-{version}"), + // The purl spells the module path with `/`, whatever the + // platform separates the cache's directories with. "golang" => dir .to_string_lossy() + .replace('\\', "/") .ends_with(&format!("{name}@{version}")), "maven" => { let jar = format!("{}-{version}.jar", name.rsplit('/').next().unwrap()); @@ -797,6 +800,30 @@ mod prebuilt_common_selftests { assert_eq!(args, ["scan", "--json"]); } + /// A purl spells a Go module path with `/`, and Windows lists the + /// module cache with `\` (behind `\\?\` when the cache path was + /// canonicalized). Under either separator the module's directory is + /// the archive source: without it the fixture serves the stand-in of + /// `package_layout`, which holds the patched files and none of the + /// module's own. + #[test] + fn a_go_module_directory_is_found_under_either_path_separator() { + let purl = "pkg:golang/example.com/m@v1.0.0"; + let root = Path::new("project"); + for found in [ + "/tmp/modcache/example.com/m@v1.0.0", + r"C:\Temp\modcache\example.com\m@v1.0.0", + r"\\?\C:\Temp\modcache\example.com\m@v1.0.0", + ] { + let listed = ["/tmp/modcache/example.com/m@v1.0.1", found].map(PathBuf::from); + let source = source_dir(root, &listed, purl); + assert_eq!(source, PathBuf::from(found), "{found}"); + } + // Another version of the module is not its source. + let other = [PathBuf::from(r"C:\Temp\modcache\example.com\m@v1.0.1")]; + assert_eq!(source_dir(root, &other, purl), root.join("missing")); + } + #[test] fn files21_layout_routes_and_install_detection() { assert!(is_sha1_dir("0a1b") && is_sha1_dir(&"f".repeat(40))); diff --git a/crates/socket-patch-core/src/crawlers/maven_crawler.rs b/crates/socket-patch-core/src/crawlers/maven_crawler.rs index 20acf2921..373c853db 100644 --- a/crates/socket-patch-core/src/crawlers/maven_crawler.rs +++ b/crates/socket-patch-core/src/crawlers/maven_crawler.rs @@ -2741,11 +2741,20 @@ mod tests { global: true, ..local }; - assert_eq!( - purls(MavenCrawler::new().crawl_all_with(&global, &env).await).len(), - 3, - "a global crawl is not scoped" - ); + // A global crawl also reads the Coursier and Ivy caches of the + // machine running the suite (they are not part of `JvmEnv`), so the + // pinned repository's packages are looked up, not counted. + let found = purls(MavenCrawler::new().crawl_all_with(&global, &env).await); + for purl in [ + "pkg:maven/junit/junit@4.13.2", + "pkg:maven/org.apache.commons/commons-lang3@3.12.0", + "pkg:maven/org.hamcrest/hamcrest-core@1.3", + ] { + assert!( + found.iter().any(|p| p == purl), + "a global crawl is not scoped: {purl} is missing from {found:?}" + ); + } } #[tokio::test] From b09019c4d79b8489d69c7b8a2ee3409fad3765cc Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 16 Nov 2026 16:29:35 -0500 Subject: [PATCH 2/2] Tighten the three test fixes after review - The Maven global-crawl assertion keeps only the packages whose path is under the test's own repository and compares them with the three expected purls exactly, so the machine's Coursier and Ivy caches cannot satisfy or break it and an extra or duplicate package is caught. - The fixture server matches a Go module directory from a path-component boundary, so the directory of a module on a longer host (sigs.k8s.io/x for k8s.io/x) is no longer taken. - It applies Go's case escaping to the module path and the version before comparing, so a purl with an upper-case letter finds its directory (github.com/Azure is github.com/!azure in the module cache). - It prints one line naming the purl and the cache when it archives the package_layout stand-in although the test handed over a cache for that ecosystem; this stays a notice because two tests of vendor_rerun_no_network_e2e hand over a Cargo home without the crate on purpose. - The served-binary size assertion checks the bytes as served, so the trailer counts only where it is appended and the check is the updater's own on every platform. - That assertion reads the updater's MAX_BINARY_BYTES, now #[doc(hidden)] pub, in place of a second hard-coded copy, and its message names the cause for any profile. Co-Authored-By: Claude Fable 5.2 --- .../tests/common/update_fixture.rs | 38 ++-- .../tests/prebuilt_common/mod.rs | 207 ++++++++++++++++-- .../src/crawlers/maven_crawler.rs | 29 +-- .../socket-patch-core/src/update/download.rs | 4 +- 4 files changed, 226 insertions(+), 52 deletions(-) diff --git a/crates/socket-patch-cli/tests/common/update_fixture.rs b/crates/socket-patch-cli/tests/common/update_fixture.rs index 75032b76f..314a66cd8 100644 --- a/crates/socket-patch-cli/tests/common/update_fixture.rs +++ b/crates/socket-patch-cli/tests/common/update_fixture.rs @@ -21,6 +21,7 @@ use wiremock::{Mock, MockServer, ResponseTemplate}; use socket_patch_cli::commands::update::UPDATE_TARGET; use socket_patch_core::update::asset_name_for_target; +use socket_patch_core::update::download::MAX_BINARY_BYTES; /// A TCP endpoint nothing listens on (port 9 = discard, never bound on a /// dev host): any request the child makes fails fast and loudly, so a @@ -209,28 +210,27 @@ pub fn real_binary_hash() -> String { /// is the canary that fails loudly if a platform stops tolerating this. pub fn make_served_binary() -> (Vec, bool) { let mut bytes = std::fs::read(real_binary()).expect("read real binary"); - // The updater rejects an extracted binary above 256 MiB - // (`MAX_BINARY_BYTES` in core/src/update/download.rs). A test build - // that outgrows it fails every test that serves it with "exceeds the - // ...-byte cap", far from the cause: name the cause here. It happened - // to the coverage build, which keeps every function of every - // dependency (ci.yml builds it with `CARGO_PROFILE_DEV_DEBUG=0`). - const UPDATER_BINARY_CAP: usize = 256 * 1024 * 1024; - const TRAILER: &[u8] = b"\nSOCKET-PATCH-E2E-TRAILER-0123456789abcdef0123456789abcdef\n"; + let byte_distinct = !cfg!(target_os = "macos"); + if byte_distinct { + bytes.extend_from_slice(b"\nSOCKET-PATCH-E2E-TRAILER-0123456789abcdef0123456789abcdef\n"); + } + // The updater rejects an extracted binary above `MAX_BINARY_BYTES`. A + // test build that outgrows it fails every test that has the updater + // extract these bytes with "exceeds the ...-byte cap", far from the + // cause: name the cause here, with the updater's own comparison on the + // bytes as served. It happened to the coverage build, which keeps + // every function of every dependency (ci.yml builds it with + // `CARGO_PROFILE_DEV_DEBUG=0`). assert!( - bytes.len() + TRAILER.len() <= UPDATER_BINARY_CAP, - "the built socket-patch binary is {} bytes, above the updater's \ - {UPDATER_BINARY_CAP}-byte cap on a downloaded binary, so it cannot \ - be served as a release payload: build this profile with less debug \ - info (CARGO_PROFILE_DEV_DEBUG=0)", + bytes.len() as u64 <= MAX_BINARY_BYTES, + "the socket-patch binary this fixture serves is {} bytes, above the \ + updater's {MAX_BINARY_BYTES}-byte cap on an extracted binary, so it \ + cannot be a release payload: the build carries too much debug info \ + for this fixture (for the dev profile, build with \ + CARGO_PROFILE_DEV_DEBUG=0)", bytes.len() ); - if cfg!(target_os = "macos") { - (bytes, false) - } else { - bytes.extend_from_slice(TRAILER); - (bytes, true) - } + (bytes, byte_distinct) } // ── Archive + SHA256SUMS builders ────────────────────────────────────── diff --git a/crates/socket-patch-cli/tests/prebuilt_common/mod.rs b/crates/socket-patch-cli/tests/prebuilt_common/mod.rs index d4a47c7ac..5b638cbf1 100644 --- a/crates/socket-patch-cli/tests/prebuilt_common/mod.rs +++ b/crates/socket-patch-cli/tests/prebuilt_common/mod.rs @@ -86,17 +86,25 @@ impl Server { fn project_with_bind(root: &Path, env: &[(&str, &str)], docker: bool) -> Self { let root = root.to_path_buf(); - let extra: Vec<_> = env + // Each cache the test hands over, with the purl type it holds. + let extra: Vec = env .iter() - .filter_map(|(k, v)| match *k { - "CARGO_HOME" | "GOMODCACHE" | "MAVEN_REPO_LOCAL" | "NUGET_PACKAGES" - | "GEM_HOME" | "VIRTUAL_ENV" | "BUNDLE_PATH" => Some(PathBuf::from(v)), - // The explicit JVM caches (`jvm_env::EXPLICIT`) are served - // as maven2 repositories from their `files-2.1` trees. - "GRADLE_USER_HOME" => Some(PathBuf::from(v).join(GRADLE_FILES21)), - "GRADLE_RO_DEP_CACHE" => Some(PathBuf::from(v).join(RO_FILES21)), - // sbt: "COURSIER_CACHE" => … - _ => None, + .filter_map(|(k, v)| { + let dir = PathBuf::from(v); + Some(match *k { + "CARGO_HOME" => ("cargo", dir), + "GOMODCACHE" => ("golang", dir), + "MAVEN_REPO_LOCAL" => ("maven", dir), + "NUGET_PACKAGES" => ("nuget", dir), + "GEM_HOME" | "BUNDLE_PATH" => ("gem", dir), + "VIRTUAL_ENV" => ("pypi", dir), + // The explicit JVM caches (`jvm_env::EXPLICIT`) are served + // as maven2 repositories from their `files-2.1` trees. + "GRADLE_USER_HOME" => ("maven", dir.join(GRADLE_FILES21)), + "GRADLE_RO_DEP_CACHE" => ("maven", dir.join(RO_FILES21)), + // sbt: "COURSIER_CACHE" => … + _ => return None, + }) }) .collect(); let (ready_tx, ready_rx) = mpsc::channel(); @@ -140,7 +148,11 @@ pub async fn mount_project(server: &MockServer, root: &Path) { mount_project_with_roots(server, root, Vec::new()).await; } -async fn mount_project_with_roots(server: &MockServer, root: &Path, extra: Vec) { +/// A package cache a test handed to the fixture server: the purl type it +/// holds, and its directory. +type CacheRoot = (&'static str, PathBuf); + +async fn mount_project_with_roots(server: &MockServer, root: &Path, extra: Vec) { let mut records = std::fs::read(root.join(".socket/manifest.json")) .ok() .and_then(|b| serde_json::from_slice::(&b).ok()) @@ -166,8 +178,8 @@ async fn mount_project_with_roots(server: &MockServer, root: &Path, extra: Vec

= extra.iter().map(|(_, dir)| dir.clone()).collect(); + roots.extend(repositories.iter().cloned()); let paths = list_dirs(&roots); let mut metadata = MAVEN_METADATA .get_or_init(Default::default) @@ -248,6 +260,11 @@ async fn mount_project_with_roots(server: &MockServer, root: &Path, extra: Vec

PathBuf { .is_dir() } "cargo" | "gem" => leaf == format!("{name}-{version}"), - // The purl spells the module path with `/`, whatever the - // platform separates the cache's directories with. - "golang" => dir - .to_string_lossy() - .replace('\\', "/") - .ends_with(&format!("{name}@{version}")), + "golang" => is_go_module_dir(dir, name, &version), "maven" => { let jar = format!("{}-{version}.jar", name.rsplit('/').next().unwrap()); if dir.join(&jar).is_file() { @@ -510,6 +522,68 @@ fn source_dir(root: &Path, paths: &[PathBuf], purl: &str) -> PathBuf { root.join("missing") } +/// Whether `dir` is where Go's module cache keeps `module@version`: the +/// path's last components spell the module path and the version, both +/// case-escaped, starting at a component boundary (the directory of +/// `sigs.k8s.io/x` is not that of `k8s.io/x`). The purl spells the module +/// path with `/`, whatever the platform separates the cache's directories +/// with. +fn is_go_module_dir(dir: &Path, module: &str, version: &str) -> bool { + let wanted = format!("{}@{}", go_case_escape(module), go_case_escape(version)); + dir.to_string_lossy() + .replace('\\', "/") + .strip_suffix(&wanted) + .is_some_and(|before| before.is_empty() || before.ends_with('/')) +} + +/// Go's module cache spells an upper-case ASCII letter as `!` and its +/// lower-case form (`github.com/Azure` is `github.com/!azure`), in a module +/// path and in a version alike. The same rule as the product's +/// `socket_patch_core::crawlers::go_crawler::encode_module_path`, written +/// out here so the fixture does not take the rule from the code under test. +fn go_case_escape(text: &str) -> String { + let mut escaped = String::with_capacity(text.len()); + for ch in text.chars() { + if ch.is_ascii_uppercase() { + escaped.push('!'); + } + escaped.push(ch.to_ascii_lowercase()); + } + escaped +} + +/// The line the fixture server prints when it archives the stand-in of +/// `package_layout` for `purl` although the test handed it a cache for +/// that ecosystem; `None` when no such cache was handed over (the +/// stand-in is then the intended source). It is printed once per package +/// of a project: a later server for the same project serves the archive +/// already published. The stand-in holds the patched files and none of +/// the package's own, so a package that is installed and that `source_dir` +/// failed to find shows up far away, as a build that misses a file: the +/// line names the cause in that test's output. It is a notice and not a +/// failure because two tests hand over, on purpose, a Cargo home that +/// holds no crate, for a crate that is locked or patched and not +/// installed (`vendor_rerun_no_network_e2e`). +fn stand_in_notice(purl: &str, handed: &[CacheRoot]) -> Option { + let kind = purl + .trim_start_matches("pkg:") + .split('/') + .next() + .unwrap_or_default(); + let caches: Vec = handed + .iter() + .filter(|(holds, _)| *holds == kind) + .map(|(_, dir)| dir.display().to_string()) + .collect(); + (!caches.is_empty()).then(|| { + format!( + "prebuilt fixture: {purl} was not found in the project or under the cache \ + handed over ({}); serving the stand-in of package_layout", + caches.join(", ") + ) + }) +} + pub async fn mount_view(server: &MockServer, view: &serde_json::Value, gemspec: Option<&[u8]>) { mount_view_from_source(server, view, gemspec, None).await; } @@ -824,6 +898,101 @@ mod prebuilt_common_selftests { assert_eq!(source_dir(root, &other, purl), root.join("missing")); } + /// The module path is matched from a path-component boundary: the + /// directory of a module on a longer host name (`sigs.k8s.io/x` beside + /// `k8s.io/x`) ends with the same text and is another module. + #[test] + fn a_go_module_on_a_longer_host_is_not_taken() { + let root = Path::new("project"); + for (purl, longer, own) in [ + ( + "pkg:golang/example.com/m@v1.0.0", + "/tmp/modcache/notexample.com/m@v1.0.0", + "/tmp/modcache/example.com/m@v1.0.0", + ), + ( + "pkg:golang/k8s.io/x@v0.1.0", + r"C:\Temp\modcache\sigs.k8s.io\x@v0.1.0", + r"C:\Temp\modcache\k8s.io\x@v0.1.0", + ), + ] { + let alone = [PathBuf::from(longer)]; + assert_eq!( + source_dir(root, &alone, purl), + root.join("missing"), + "{longer}" + ); + let both = [longer, own].map(PathBuf::from); + assert_eq!(source_dir(root, &both, purl), PathBuf::from(own), "{own}"); + } + // A listed path that is the module directory and nothing more. + let bare = [PathBuf::from("example.com/m@v1.0.0")]; + let purl = "pkg:golang/example.com/m@v1.0.0"; + assert_eq!(source_dir(root, &bare, purl), bare[0]); + } + + /// Go's module cache spells an upper-case letter as `!` and its + /// lower-case form, in the module path and in the version, and a purl + /// keeps the letter: the escaped directory is the module's. + #[test] + fn a_go_module_directory_is_found_under_its_case_escaped_name() { + assert_eq!( + go_case_escape("github.com/Azure/go-autorest"), + "github.com/!azure/go-autorest" + ); + assert_eq!(go_case_escape("v1.0.0-RC1"), "v1.0.0-!r!c1"); + assert_eq!(go_case_escape("example.com/m"), "example.com/m"); + let root = Path::new("project"); + for (purl, found) in [ + ( + "pkg:golang/github.com/Azure/go-autorest@v14.2.0%2Bincompatible", + "/tmp/modcache/github.com/!azure/go-autorest@v14.2.0+incompatible", + ), + ( + "pkg:golang/github.com/BurntSushi/toml@v1.3.2", + r"C:\Temp\modcache\github.com\!burnt!sushi\toml@v1.3.2", + ), + ( + "pkg:golang/example.com/m@v1.0.0-RC1", + "/tmp/modcache/example.com/m@v1.0.0-!r!c1", + ), + ] { + let listed = [PathBuf::from(found)]; + assert_eq!(source_dir(root, &listed, purl), listed[0], "{purl}"); + } + // The cache never holds the unescaped spelling; it is not matched. + let unescaped = [PathBuf::from( + "/tmp/modcache/github.com/Azure/go-autorest@v14.2.0", + )]; + let purl = "pkg:golang/github.com/Azure/go-autorest@v14.2.0"; + assert_eq!(source_dir(root, &unescaped, purl), root.join("missing")); + } + + /// The stand-in served for a package of an ecosystem the test handed a + /// cache over for is announced with the purl and every such cache; + /// with no cache for that ecosystem the stand-in is the intended + /// source and nothing is said. + #[test] + fn a_stand_in_served_despite_a_handed_cache_is_announced() { + let purl = "pkg:maven/com.example/lib@1.0.0"; + let (m2, gradle) = (PathBuf::from("m2-repo"), PathBuf::from("gradle-files")); + assert_eq!(stand_in_notice(purl, &[]), None); + assert_eq!(stand_in_notice(purl, &[("cargo", m2.clone())]), None); + let handed = [ + ("maven", m2), + ("golang", "modcache".into()), + ("maven", gradle), + ]; + let notice = stand_in_notice(purl, &handed).expect("two Maven caches were handed over"); + for part in [purl, "m2-repo", "gradle-files", "stand-in"] { + assert!(notice.contains(part), "{part} is missing from: {notice}"); + } + assert!( + !notice.contains("modcache") && !notice.contains('\n'), + "{notice}" + ); + } + #[test] fn files21_layout_routes_and_install_detection() { assert!(is_sha1_dir("0a1b") && is_sha1_dir(&"f".repeat(40))); diff --git a/crates/socket-patch-core/src/crawlers/maven_crawler.rs b/crates/socket-patch-core/src/crawlers/maven_crawler.rs index 373c853db..235b6be51 100644 --- a/crates/socket-patch-core/src/crawlers/maven_crawler.rs +++ b/crates/socket-patch-core/src/crawlers/maven_crawler.rs @@ -2742,19 +2742,22 @@ mod tests { ..local }; // A global crawl also reads the Coursier and Ivy caches of the - // machine running the suite (they are not part of `JvmEnv`), so the - // pinned repository's packages are looked up, not counted. - let found = purls(MavenCrawler::new().crawl_all_with(&global, &env).await); - for purl in [ - "pkg:maven/junit/junit@4.13.2", - "pkg:maven/org.apache.commons/commons-lang3@3.12.0", - "pkg:maven/org.hamcrest/hamcrest-core@1.3", - ] { - assert!( - found.iter().any(|p| p == purl), - "a global crawl is not scoped: {purl} is missing from {found:?}" - ); - } + // machine running the suite (they are not part of `JvmEnv`), so + // only the packages it reports from the pinned repository are + // compared, and those exactly. The repository is crawled before + // those caches and the first copy of a purl wins, so a copy of one + // of these in the machine's caches is never the one reported. + let mut pinned = MavenCrawler::new().crawl_all_with(&global, &env).await; + pinned.retain(|p| p.path.starts_with(&repo)); + assert_eq!( + purls(pinned), + [ + "pkg:maven/junit/junit@4.13.2", + "pkg:maven/org.apache.commons/commons-lang3@3.12.0", + "pkg:maven/org.hamcrest/hamcrest-core@1.3", + ], + "a global crawl is not scoped" + ); } #[tokio::test] diff --git a/crates/socket-patch-core/src/update/download.rs b/crates/socket-patch-core/src/update/download.rs index 02994b49b..4af121ea8 100644 --- a/crates/socket-patch-core/src/update/download.rs +++ b/crates/socket-patch-core/src/update/download.rs @@ -28,7 +28,9 @@ const MAX_ARCHIVE_BYTES: u64 = 256 * 1024 * 1024; /// Hard cap on the single extracted binary, enforced during streaming /// decompression so a decompression bomb can't balloon memory. -const MAX_BINARY_BYTES: u64 = 256 * 1024 * 1024; +/// Public only so the CLI's self-update test fixture shares the number. +#[doc(hidden)] +pub const MAX_BINARY_BYTES: u64 = 256 * 1024 * 1024; /// Prefix for staged-binary files in the destination directory. The /// start-of-run sweep removes stale ones (crash leftovers).