Skip to content

Commit c76ed80

Browse files
committed
Don't hold the hatch uv var in a parallel test
The first version of uv_path_env_counts_only_when_a_guard_holds_it held HATCH_ENV_TYPE_VIRTUAL_UV_PATH with an EnvGuard. Other utils::hatch tests are not #[serial], so while the guard was live they saw uv switched on: uv_sources_refuse_project_rewrites_under_the_uv_installer failed 2-3 times in 100 loops of `utils::hatch` on a clean env. Even an empty-value guard leaked, because EnvGuard's drop restores the previous value before it releases the key. The test now only checks that an unguarded host value stays hidden; the uv branch itself is covered by the direct uv_source_names(.., true) asserts. utils::hatch now passes 300/300 loops clean and 100/100 with the host var set. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeR2MHrmJ9Fh9wmm3X1
1 parent 52db0e1 commit c76ed80

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

  • crates/socket-patch-core/src/utils

‎crates/socket-patch-core/src/utils/hatch.rs‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,13 +1739,15 @@ mod tests {
17391739
.contains("pip installer"));
17401740
}
17411741

1742-
/// `HATCH_ENV_TYPE_VIRTUAL_UV_PATH` turns on the uv refusals with no file
1743-
/// setting, and in the unit tests only a guarded value counts: a
1744-
/// developer's own uv path must not refuse the pip-installer fixtures.
1742+
/// In the unit tests a host `HATCH_ENV_TYPE_VIRTUAL_UV_PATH` is hidden,
1743+
/// so a developer's own uv path can't refuse the pip-installer fixtures.
1744+
/// The test never holds the key with an `EnvGuard`: the other hatch
1745+
/// tests run in parallel and would see uv switched on, even for the
1746+
/// instant a guard's drop restores the host value before releasing the
1747+
/// key (`uv_source_names(.., true)` covers that branch directly).
17451748
#[test]
17461749
#[serial_test::serial]
1747-
fn uv_path_env_counts_only_when_a_guard_holds_it() {
1748-
use crate::test_env::EnvGuard;
1750+
fn uv_path_env_hides_the_host_value() {
17491751
const KEY: &str = "HATCH_ENV_TYPE_VIRTUAL_UV_PATH";
17501752
let url = "https://patch.test/six-1.16.0-py2.py3-none-any.whl";
17511753
let inputs = files(
@@ -1755,17 +1757,6 @@ mod tests {
17551757
std::env::set_var(KEY, "/host/uv");
17561758
assert!(!uv_path_override(), "host value hidden");
17571759
assert!(rewrite(&inputs, "six", "1.16.0", url).is_ok());
1758-
{
1759-
let _uv = EnvGuard::set(KEY, "/usr/bin/uv");
1760-
assert!(uv_path_override());
1761-
assert!(rewrite(&inputs, "six", "1.16.0", url)
1762-
.unwrap_err()
1763-
.contains("[tool.uv.sources]"));
1764-
}
1765-
{
1766-
let _empty = EnvGuard::set(KEY, "");
1767-
assert!(!uv_path_override(), "an empty value is unset");
1768-
}
17691760
match host {
17701761
Some(value) => std::env::set_var(KEY, value),
17711762
None => std::env::remove_var(KEY),

0 commit comments

Comments
 (0)