Fix Pipenv venv discovery settings view (#645, #546) - #654
Mikola Lysenko (mikolalysenko) wants to merge 10 commits into
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Agent mode and hosted stale-install checks now find the venv Pipenv really uses in two cases where they used to miss it, patch the system interpreter instead, and let VEX attest not_affected: - WORKON_HOME, PIPENV_CUSTOM_VENV_NAME or PIPENV_VENV_IN_PROJECT set in the project's .env (or PIPENV_DOTENV_LOCATION), which every Pipenv command loads before it picks the venv (#546). - An explicit "not in project" setting next to a ./.venv directory. Only Pipenv 2023.11.14+ skips ./.venv then; 2018.11 to 2023.10.24 still use it, so both venvs are now patched (#645). Assisted-by: Claude Code:claude-opus-5-5
Scan-level regressions for both fixes: a .env-named venv is scanned (and PIPENV_DONT_LOAD_ENV turns that off), and an explicit "not in project" setting now scans ./.venv as well as the WORKON_HOME venv. The Pipenv compatibility doc describes the new discovery rules. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
The new .env test removed the whole WORKON_HOME on Windows, where site-packages sits one level shallower, so the .env-named venv went with it. .env values now decode exactly python-dotenv's escapes, so a backslash in a quoted Windows path is kept as written. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
|
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting: Preview (dec35ec829)diff --git a/crates/socket-patch-cli/tests/in_process_python_envs.rs b/crates/socket-patch-cli/tests/in_process_python_envs.rs
--- a/crates/socket-patch-cli/tests/in_process_python_envs.rs
+++ b/crates/socket-patch-cli/tests/in_process_python_envs.rs
@@ -689,7 +689,7 @@
project.join(".env"),
format!(
"export WORKON_HOME=\"{}\"\nPIPENV_CUSTOM_VENV_NAME=proj-env # named\n",
- workon.display()
+ workon.display().to_string().replace('\\', "\\\\")
),
)
.unwrap();
diff --git a/crates/socket-patch-core/src/crawlers/python_crawler.rs b/crates/socket-patch-core/src/crawlers/python_crawler.rs
--- a/crates/socket-patch-core/src/crawlers/python_crawler.rs
+++ b/crates/socket-patch-core/src/crawlers/python_crawler.rs
@@ -3545,9 +3545,10 @@
"HOME",
tmp.path().join("home").to_string_lossy().into_owned(),
)]);
+ let base_escaped = base.replace('\\', "\\\\");
for dotenv in [
format!("WORKON_HOME={base}/elsewhere\n"),
- format!("# venvs\nexport WORKON_HOME=\"{base}/elsewhere\" # here\n"),
+ format!("# venvs\nexport WORKON_HOME=\"{base_escaped}/elsewhere\" # here\n"),
format!("WORKON_HOME='{base}/elsewhere'\n"),
format!("BASE={base}\nWORKON_HOME=${{BASE}}/elsewhere # comment\n"),
] {You can send follow-ups to the cloud agent here. |
|
Ready for review — head
Reviewers: the change is in Pipenv venv discovery. It now reads Generated by Claude Code |
|
Codex follow-up review of The first fixes preserve native modern dotenv bindings and interpolation, including single-quoted and multiline values, and apply the active-environment decision within each settings view. Relative and empty active paths retain the verified behavior. The remaining compatibility gap is now corrected with explicit Pipenv 2018.11.26 and 2020.11.15 shell profiles. The 2018 parser resolves the complete file mapping with process values first and its shell sets Verified on the exact committed source:
335 successful checks, 7 skipped, and 8 successful workflows (1 additional workflow skipped). Bugbot is clear on this commit; no unresolved review threads or new actionable findings. Ready for review has been restored. GitHub still requires the normal human approval before merge. |
|
BugBot review Please review the dotenv parsing and per-view active-environment correction on |
|
BugBot review Please review the native Pipenv 2018/2020 cached-shell discovery correction on |
Resolve the find_local_venv_site_packages_with conflict by keeping this branch's early Pipenv return (Pipenv's VIRTUAL_ENV decision now lives in pipenv_project_site_packages per settings view) and taking main's new poetry_project_site_packages flow; the non-Poetry VIRTUAL_ENV branch no longer needs a Pipenv guard since Pipenv projects return earlier. Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
1 similar comment
|
bugbot run Generated by Claude Code |
Brings in the vex_consumed alias test fix (#849) that the red test/test-release/coverage jobs were waiting on. Co-Authored-By: Claude <noreply@anthropic.com>
Main's spawn_env_hygiene ratchet (#850) rejects new bare binary spawns; the two dotenv-view spawns in in_process_redirect_pipenv.rs now start from the shared hermetic builder and keep their own PIPENV_* and venv scrubs on top. Co-Authored-By: Claude <noreply@anthropic.com>
The modern dotenv and process settings views passed WORKON_HOME through unjoined, so a relative value resolved against socket-patch's own cwd instead of the project Pipenv runs from (the legacy cached view already joined it). Under --cwd that missed the project's venv. Join it to the project directory in the shared helper, as the legacy path does. Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3ceb956. Configure here.
|
Burn-down agent: labeled Ready for review at
Generated by Claude Code |

LLM Description written by Claude Code:claude-opus-5-5
Fixes #645
Fixes #546
Summary
Agent mode, and the hosted stale-install check, now find the venv a Pipenv project actually uses in two cases they used to miss. In both, socket-patch fell through to the system interpreter, patched that instead, and let
vexattestnot_affectedwhile the venv Pipenv runs stayed vulnerable.Root cause
pipenv_project_site_packages(crates/socket-patch-core/src/crawlers/python_crawler.rs) chose the venv from settings that don't match what the installed Pipenv sees:.envsettings (orPIPENV_DOTENV_LOCATION) before selecting an environment, unless loading is disabled. Parser behavior and the timing of cached settings differ between current commands and the supported 2018/2020 shells, so a process-only or single dotenv view can miss the installed environment../.venv". Only Pipenv 2023.11.14+ does that. Releases 2018.11 through 2023.10.24 use an existing./.venvdirectory whatever the setting says, and only 2026.2+ reads the Pipfile[pipenv] venv_in_projectkey.Fix
./.venvdirectory exists, any setting other than an explicit "in project" now returns both the WORKON_HOME venv and./.venv, so the venv any Pipenv release uses gets patched.docs/testing/pipenv-compatibility.mddescribes the new rules.Known over-approximation: if
.envsays "in project" and the project also has a WORKON_HOME venv, that venv is patched too, because the environment-only view still returns it. It belongs to the same project, so this is harmless.Verification against real Pipenv
pipenv --venv, with both a./.venvdirectory and$WORKON_HOME/custompresent:PIPENV_VENV_IN_PROJECT=0p/.venvwh/custom.envPIPENV_CUSTOM_VENV_NAME=custom(no.venv)wh/customwh/customwh/customTests (red → green)
Per issue:
pipenv_venv_in_project_settings_decide_about_dot_venv(core unit) coversPIPENV_VENV_IN_PROJECT=0/false/Off/no,PIPENV_NO_VENV_IN_PROJECT=1, the Pipfile key, and the case where only.venvexists.pipenv_explicit_not_in_project_still_scans_dot_venv(scan level,in_process_python_envs.rs).pipenv_dotenv_settings_move_the_venvcovers a custom venv name in.env,WORKON_HOMEin.envin each python-dotenv syntax,PIPENV_DONT_LOAD_ENV, andPIPENV_DOTENV_LOCATION.pipenv_dotenv_venv_in_project_is_honoured.dotenv_parsing_follows_python_dotenv, including Windows paths.pipenv_dotenv_settings_pick_the_scanned_venv(scan level).I ran the new tests on top of
mainfirst, with the parser stubbed to return nothing.dotenv_parsing_follows_python_dotenv,pipenv_dotenv_settings_move_the_venvandpipenv_venv_in_project_settings_decide_about_dot_venvFAILED. With the fix, all 63python_crawlertests pass. I changed the existing #334 tests that asserted "explicit false skips./.venv" to expect the corrected behaviour. The guard against a strayvenv/directory is kept.Local runs:
cargo clippy --workspace --all-features -- -D warnings: clean.cargo test --workspace --all-features --no-fail-fast: all passed except 12 fault-injection tests (*_write_failure_*,*unremovable*,relax_loop_must_not_traverse_symlinked_root). They depend onchmodand fail only because the sandbox runs as root. None of them touches Python discovery, and CI runs them as non-root.cargo fmt --all -- --checkalready fails onmain(~500 diffs; CI has no fmt step). The lines this PR adds are rustfmt-clean, and I didn't reformat unrelated code.bf91b10: all 335 checks green (6 skipped by design). That includestest (windows-latest), which first failed on a Windows-only bug in the new test's fixture, fixed inbf91b10. Bugbot's one finding (backslash escapes in quoted Windows paths) is fixed and resolved, and its re-review found no new issues.npm/,pypi/,gem/) are needed, since discovery lives in core.🤖 Generated with Claude Code
Note
Medium Risk
Changes which Python site-packages get scanned and patched for Pipenv projects; incorrect discovery could miss vulnerabilities or target the wrong venv, but scope is limited to Pipenv discovery logic with extensive regression tests.
Overview
Pipenv venv discovery now mirrors how Pipenv actually picks an environment, fixing agent scans and hosted stale-install checks that used to fall through to the wrong interpreter (#546, #645).
Discovery runs earlier for Pipenv projects and no longer relies on process env alone. It reads the project
.env(orPIPENV_DOTENV_LOCATION, unlessPIPENV_DONT_LOAD_ENV) with a python-dotenv–style parser plus a 2018 legacy parser, then unions several native timing profiles (current dotenv + process, and cached 2018/2020 shell views) soWORKON_HOME,PIPENV_CUSTOM_VENV_NAME, activeVIRTUAL_ENV, and in-project flags match what different Pipenv releases see. RelativeWORKON_HOMEis resolved from the project directory (not the CLI process cwd).For #645, an explicit “not in project” no longer universally drops
./.venv: when both WORKON_HOME and./.venvexist, both are scanned (WORKON_HOME first) because only Pipenv 2023.11.14+ ignores.venvin that case; older releases still use it.Tests expand scan-level, redirect/VEX, and
python_crawlerunit coverage for dotenv syntax, legacy shellWORKON_HOME, and the revised in-project behavior.docs/testing/pipenv-compatibility.mddocuments the new settings views and version-dependent./.venvbehavior.Reviewed by Cursor Bugbot for commit 3ceb956. Configure here.
Review follow-up on
d8356ae2: all three reported discovery findings are corrected. Modern dotenv binding/interpolation and per-view active-environment selection are preserved. Native-proven 2018 and 2020 shell profiles now retain their own parser, cached settings and active-prefix timing; discovery includes their project environments without scanning unrelated venvs. Verified with 162 repository tests, seven hosted stale-install regression cases, 18 real native environment cases, 34 legacy and 58 modern parser cases, targeted Clippy and independent review. Ready to merge as-is from this review. 335 successful checks, 7 skipped, and 8 successful workflows (1 additional workflow skipped). Bugbot is clear on this commit; no unresolved review threads or new actionable findings.Generated by Claude Code