fix: canonicalize prefix paths before comparison to handle symlinked venvs (Fixes #358)#359
fix: canonicalize prefix paths before comparison to handle symlinked venvs (Fixes #358)#359karthiknadig merged 5 commits intomainfrom
Conversation
Test Coverage Report (Linux)
Coverage increased! Great work! |
Performance Report (Linux) ✅
Legend
|
Performance Report (Windows) ✅
Legend
|
Test Coverage Report (Windows)
Coverage increased! Great work! |
There was a problem hiding this comment.
Pull request overview
This PR fixes a false positive "Prefix is incorrect" telemetry warning that occurs when a venv's prefix path is a symlink. The issue arose because the telemetry validation code compared prefix paths directly without resolving symlinks, causing symlinked paths to be flagged as incorrect even though they point to the same directory.
Changes:
- Canonicalize both discovered and resolved prefix paths before comparison to resolve symlinks
- Wrap canonicalized paths in
norm_case()to handle Windows UNC prefix (\\?\) added bycanonicalize - Use fallback to original path if canonicalization fails (e.g., path no longer exists)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
crates/pet-telemetry/src/lib.rs:53
- The canonicalization approach in the telemetry module differs from the pattern used in
crates/pet-env-var-path/src/lib.rswhere Unix-specific canonicalization is applied selectively. Innormalize_search_path, canonicalize is only called on Unix (to handle merged-usr symlinks) but not on Windows (to preserve junction tracking for tools like Scoop). Here, canonicalize is called on both platforms. While wrapping with norm_case handles the Windows UNC prefix issue, consider documenting why this approach is correct for prefix paths specifically, or whether Windows junction paths in venv prefixes could cause similar issues to those mentioned in issue #187 for Scoop.
let invalid_prefix = if let Some(ref env_prefix) = env.prefix {
let resolved_prefix = resolved.prefix.clone()?;
// Canonicalize both paths to handle symlinks — a venv prefix like
// /usr/local/venvs/myvenv may be a symlink to /usr/local/venvs/versioned/myvenv-1.0.51,
// and sys.prefix returns the resolved target. Without this, the comparison
// produces a false positive "Prefix is incorrect" warning. (See #358)
// Wrap in norm_case to handle Windows UNC prefix (`\\?\`) from canonicalize.
let env_canonical =
norm_case(std::fs::canonicalize(env_prefix).unwrap_or(env_prefix.clone()));
let resolved_canonical =
norm_case(std::fs::canonicalize(&resolved_prefix).unwrap_or(resolved_prefix));
env_canonical != resolved_canonical
…sertions, pin tempfile version
Performance Report (macOS)
Legend
|
Fix false positive "Prefix is incorrect" telemetry warning when a venv prefix path is a symlink.
norm_case()to handle Windows\\?\UNC prefix fromcanonicalizeFixes #358