From 5003425210b63af9fd9d88d151439ccc8c1e3af0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 23:44:18 +0000 Subject: [PATCH] Move USERPROFILE in Maven ~/.m2 fallback tests Nightly CI on main has failed test (windows-latest, 1) every night since 2026-10-30: get_maven_repo_paths_home_dot_m2_fallback returns [] instead of /.m2/repository. #1801 made Maven's user.home on Windows read USERPROFILE before HOME, as the JVM does, but the test only moved HOME, so the crawler looked in the runner's real profile. Run both HOME-fallback tests under NoJvmCaches::with_home, which points HOME and USERPROFILE at the test's directory, clears the other Maven/JVM variables and restores everything on drop, also when an assertion panics. The no-m2 test passed on the runner only because its real profile has no .m2. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_011f9aeRXDcg7ce8xkkpQdxf --- .../tests/crawler_maven_e2e.rs | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/crates/socket-patch-core/tests/crawler_maven_e2e.rs b/crates/socket-patch-core/tests/crawler_maven_e2e.rs index 138f65d76..f350084b8 100644 --- a/crates/socket-patch-core/tests/crawler_maven_e2e.rs +++ b/crates/socket-patch-core/tests/crawler_maven_e2e.rs @@ -20,8 +20,9 @@ fn options_at(root: &Path) -> CrawlerOptions { /// Keeps the machine's Coursier / Ivy caches out of a test that pins the /// exact repo list (a JVM marker or `--global` also crawls them): `HOME` -/// points at an empty directory and the variables naming a cache are unset -/// until drop, which restores them. Only inside `#[serial]` tests. +/// and `USERPROFILE` point at an empty directory and the variables naming +/// a cache are unset until drop, which restores them (also when the test +/// panics). Only inside `#[serial]` tests. struct NoJvmCaches { _home: tempfile::TempDir, saved: Vec<(&'static str, Option)>, @@ -51,6 +52,17 @@ impl NoJvmCaches { std::env::set_var("USERPROFILE", home.path()); Self { _home: home, saved } } + + /// [`Self::new`] with the account home at `home` instead. Both `HOME` + /// and `USERPROFILE` move: on Windows Maven's `user.home` is + /// `USERPROFILE` first, so a test that only moves `HOME` reads the + /// runner's real profile there. + fn with_home(home: &Path) -> Self { + let guard = Self::new(); + std::env::set_var("HOME", home); + std::env::set_var("USERPROFILE", home); + guard + } } impl Drop for NoJvmCaches { @@ -267,12 +279,9 @@ async fn get_maven_repo_paths_home_dot_m2_fallback() { .await .unwrap(); + let _home = NoJvmCaches::with_home(tmp.path()); let prev_local = std::env::var("MAVEN_REPO_LOCAL").ok(); - let prev_m2 = std::env::var("M2_HOME").ok(); - let prev_home = std::env::var("HOME").ok(); std::env::remove_var("MAVEN_REPO_LOCAL"); - std::env::remove_var("M2_HOME"); - std::env::set_var("HOME", tmp.path()); let crawler = MavenCrawler; let paths = crawler @@ -283,14 +292,6 @@ async fn get_maven_repo_paths_home_dot_m2_fallback() { if let Some(v) = prev_local { std::env::set_var("MAVEN_REPO_LOCAL", v); } - if let Some(v) = prev_m2 { - std::env::set_var("M2_HOME", v); - } - if let Some(v) = prev_home { - std::env::set_var("HOME", v); - } else { - std::env::remove_var("HOME"); - } // Production returns exactly the single resolved repo path — assert the // whole vec, not just membership, so a stray extra/wrong path also fails. @@ -338,12 +339,9 @@ async fn get_maven_repo_paths_global_mode_with_maven_repo_local() { #[serial] async fn get_maven_repo_paths_global_mode_no_m2_returns_empty() { let tmp = tempfile::tempdir().unwrap(); + let _home = NoJvmCaches::with_home(tmp.path()); // No .m2/ inside let prev_local = std::env::var("MAVEN_REPO_LOCAL").ok(); - let prev_m2 = std::env::var("M2_HOME").ok(); - let prev_home = std::env::var("HOME").ok(); std::env::remove_var("MAVEN_REPO_LOCAL"); - std::env::remove_var("M2_HOME"); - std::env::set_var("HOME", tmp.path()); // No .m2/ inside let crawler = MavenCrawler; let opts = CrawlerOptions { @@ -356,14 +354,6 @@ async fn get_maven_repo_paths_global_mode_no_m2_returns_empty() { if let Some(v) = prev_local { std::env::set_var("MAVEN_REPO_LOCAL", v); } - if let Some(v) = prev_m2 { - std::env::set_var("M2_HOME", v); - } - if let Some(v) = prev_home { - std::env::set_var("HOME", v); - } else { - std::env::remove_var("HOME"); - } assert!( paths.is_empty(),