GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Poetry venv discovery to match Poetry (#327, #329) by mikolalysenko · Pull Request #330 · SocketDev/socket-patch

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Sep 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Fixes #327
Fixes #329

Summary

scan --mode agent now finds the virtualenv Poetry actually installed into in four cases it used to miss. In each case the scan had fallen back to the wrong interpreter, skipped the patch as package_not_installed, and exited 0:

  • a nameless package-mode = false project;
  • a Poetry 2 project that sets both [project].name and [tool.poetry].name;
  • an explicit virtualenvs.in-project = false next to a stray ./.venv;
  • every default Windows project.

Changes, all in crates/socket-patch-core/src/crawlers/python_crawler.rs:

  • Env name: poetry_project_names returns candidates in poetry-core's order: [project].name (2.x), then [tool.poetry].name, then non-package-mode. The first candidate that has a <name>-<hash>-py* dir on disk wins, so a Poetry 1.8 project (which ignores [project]) still finds its legacy-named env.
  • In-project precedence: find_local_venv_site_packages asks Poetry's layered config first, following EnvManager.use_in_project_venv: an explicit in-project decides, and only when it is unset does an existing ./.venv count. When Poetry wouldn't use ./.venv, its out-of-tree env is probed before ./.venv and ./venv. Those stay as fallbacks when Poetry has no env.
  • Windows hash: poetry_normalized_cwd goes through the new windows_normcase, which strips the \\?\ / \\?\UNC\ verbatim prefix as Python's realpath does, then lowercases. Pipenv's path normalization now shares the same strip_windows_verbatim_prefix helper.
  • Docs: docs/testing/poetry-compatibility.md ("Mode notes") and a CHANGELOG Fixed entry.

The existing unit test poetry_project_names_prefer_tool_poetry_and_return_both_spellings asserted the old, wrong precedence. It is replaced by poetry_project_names_follow_poetry_core_precedence.

Root cause

find_poetry_virtualenv_site_packages rebuilds Poetry's virtualenv location without running Poetry, and it differed from Poetry in three places:

  • It took the env name from [tool.poetry].name first and had no non-package-mode fallback. poetry-core 2.x's Factory uses project.get("name") or poetry_config.get("name", "non-package-mode"), and 1.9 uses local_config.get("name", "non-package-mode").
  • It let ./.venv win unconditionally, even when Poetry's config said in-project = false.
  • It hashed std::fs::canonicalize(cwd), which on Windows is \\?\C:\…. Poetry hashes normcase(realpath(cwd)), which has no such prefix.

Not in scope: the issues also point out that the scan exits 0 when the patch is skipped as package_not_installed. That's how agent mode handles any package that isn't installed, not something specific to Poetry. With discovery fixed, the patch applies in each of these cases.

Merge with v5 consolidation (#277), 2026-10-01

#277 landed on main and conflicted in python_crawler.rs and CHANGELOG.md. Merge commit df6cfba:

  • find_local_venv_site_packages: kept this PR's Poetry-aware order. main had kept the old order, which probes .venv/venv first and Poetry only when they're empty, so taking main's side would bring Agent-mode scan misses Poetry's venv for nameless non-package-mode projects, [project].name overrides, and in-project = false with a stray .venv, and still exits 0 #327 case 3 back. The doc comment was updated to match.
  • CHANGELOG.md: added the Poetry entry to main's consolidated ### Fixed list. The old NuGet <clear /> entry on this branch is dropped because main's consolidated list already covers it.
  • No other code on main computes Poetry env names. vendor/pypi_poetry.rs::load_poetry_project is the lock/manifest reader and doesn't do venv discovery.

Re-validation after the merge:

  • cargo test -p socket-patch-core --all-features --lib -- crawlers::python_crawler: 46 passed.
  • cargo clippy --workspace --all-features -- -D warnings: clean.
  • cargo fmt --all -- --check: this PR's code is clean. main itself has many pre-existing rustfmt diffs (e.g. apply.rs, scan/*.rs), and CI doesn't run fmt.
  • cargo test --workspace --all-features --no-fail-fast: 9328 passed, 12 failed. All 12 are sandbox-only write-failure or permission tests that fail because the sandbox runs as root (*_write_failure_*, *unremovable*, relax_loop_must_not_traverse_symlinked_root, …). None of them are in the crawler.
  • Poetry e2e locally (Poetry 2.1.1): vendored passed. Hosted failed only at rollback's GET https://pypi.org/pypi/six/1.16.0/json, because the binary's TLS stack doesn't trust the sandbox proxy CA (curl to the same URL returns 200). CI's e2e_vex_build poetry:: legs passed on df6cfba for 1.0.10, 1.1.15, 1.8.5, 2.0.1 and 2.4.3 (Linux) and 2.4.3 (macOS).
  • CI on df6cfba: all 314 checks finished: success, apart from 4 that were skipped by design (e2e-docker, canary, downgrade, …). That includes test (ubuntu/macos/windows-latest), test-release and clippy. Bugbot's review of df6cfba found no issues. No conflict with main.

Test evidence (original change)

Issue Case Regression test Red on main Green
#327 1. nameless package-mode = false poetry_project_names_follow_poetry_core_precedence, poetry_out_of_tree_virtualenvs_are_discovered_without_a_dot_venv (nameless step) ✅ fails ✅
#327 2. [project].name + [tool.poetry].name same two tests (pep-name step) ✅ fails ✅
#327 3. in-project = false + stray .venv poetry_out_of_tree_virtualenvs_are_discovered_without_a_dot_venv (in-project step) ✅ fails (returned proj/.venv/...) ✅
#329 Windows \\?\ hash windows_normcase_drops_the_verbatim_prefix_like_python_realpath; #[cfg(windows)] poetry_normalized_cwd_has_no_verbatim_prefix_on_windows ✅ fails ✅ (incl. CI test (windows-latest))
  • Real Poetry 2.3.3 (Linux): I created real envs with poetry env use. find_local_venv_site_packages returned exactly the env poetry env info -p reports for the nameless, both-names and in-project = false projects.
  • The npm wrapper only dispatches, so it needs no change. The PyPI and gem wrappers were removed in v5 prerelease: scan → vex → vendor workflow, hosted by default #277.

🤖 Generated with Claude Code

https://claude.ai/code/session_017mSDqYENPT34fbMjLSQzBg


Note

Medium Risk
Changes which Python site-packages agent mode targets for patching; mis-discovery would skip or mis-apply patches, though the change is read-only discovery with extensive regression tests.

Overview
Agent mode (scan --mode agent) now locates Poetry’s real out-of-tree virtualenv in setups where discovery used to pick the wrong interpreter, skip patches as package_not_installed, and still exit 0.

In python_crawler.rs, venv probe order mirrors Poetry’s EnvManager.use_in_project_venv: when Poetry would not use ./.venv (explicit virtualenvs.in-project = false, or no in-project dir), Poetry’s cache env is checked before local ./.venv / ./venv, so stray local dirs from other tools no longer shadow Poetry’s install.

Env naming follows poetry-core: [project] name (2.x), then [tool.poetry] name, then non-package-mode; the first candidate with a matching <name>-<hash>-py* directory wins (Poetry 1.8 still finds legacy-named envs).

On Windows, cwd hashing strips the \\?\ verbatim prefix from canonicalize, matching Python’s realpath/normcase (shared helper with Pipenv path normalization).

CHANGELOG and docs/testing/poetry-compatibility.md document the behavior; unit/integration tests cover the #327/#329 cases.

Reviewed by Cursor Bugbot for commit 50cde0a. Configure here.


Generated by Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@claude
Start fix for #327, #329
32adb67
Assisted-by: Claude Code:claude-opus-5-5
This was referenced Sep 30, 2026
Agent-mode scan misses Poetry's venv for nameless non-package-mode projects, [project].name overrides, and in-project = false with a stray .venv, and still exits 0 #327
Closed
Windows agent-mode scan never finds Poetry's default out-of-tree virtualenv, so patches are skipped and the scan exits 0 #329
Closed
@claude
Find Poetry's venv like Poetry does
a3c1ce4
Agent mode missed the virtualenv Poetry installed into for nameless
package-mode = false projects, Poetry 2 projects naming both
[project] and [tool.poetry], projects with in-project = false next
to a stray .venv, and every project on Windows. The scan then
skipped the patch and exited 0.

Pick the env name in poetry-core's order ([project].name, then
[tool.poetry].name, then non-package-mode), honour an explicit
in-project setting before ./.venv, and drop the \\?\ prefix before
hashing the cwd on Windows.

Fixes #327
Fixes #329

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review September 30, 2026 15:59
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Sep 30, 2026
View reviewed changes

@cursor cursor Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Sep 30, 2026
Agent-mode scan skips Pipenv's out-of-tree venv when the project has a stray venv/ directory or a .venv with PIPENV_VENV_IN_PROJECT=0, and still exits 0 #334
Closed
Hosted Hatch rewrite leaves an existing Hatch environment unpatched with no stale-install warning, and vex still attests not_affected #335
Closed
Fix npm VEX attesting packages with an unpatched bundled copy (#325) #337
Merged
Fix npm rewiring git/URL/file lock entries (#326) #345
Merged
Fix JSON writers dropping CRLF/BOM/indent (#324, #351) #357
Merged
Fix npm crawler missing relocated dependency stores (#359, #362) #365
Merged
@claude
Merge main (v5 consolidation) into poetry fix
df6cfba
Resolve conflicts with #277: keep Poetry-aware venv probe order in
find_local_venv_site_packages and add the Poetry entry to the
consolidated changelog.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Oct 1, 2026
View reviewed changes

@cursor cursor Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Oct 1, 2026
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

[burn-down agent] Ready for review on df6cfba: mergeable with current main (post-#277), CI all green (no failures; only path-filtered skips), Cursor Bugbot reviewed df6cfba with no new issues, no unresolved review threads. Labeled Ready for review.


Generated by Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mikolalysenko
Mikola Lysenko (mikolalysenko) enabled auto-merge (squash) October 1, 2026 03:14
@mikolalysenko Mikola Lysenko (mikolalysenko) mentioned this pull request Oct 1, 2026
In a --system-site-packages venv, pip keeps the base interpreter's unpatched copy after a hosted rewrite, no stale-install warning fires, and vex attests it as patched #409
Closed
Tanmay182003
Tanmay Singla (Tanmay182003) approved these changes Oct 1, 2026
View reviewed changes
@claude
Merge origin/main to resolve conflicts
50cde0a
Union the CHANGELOG Fixed entries from both sides.

Co-Authored-By: Claude <[email protected]>
@mikolalysenko
Mikola Lysenko (mikolalysenko) merged commit 5678b76 into main Oct 1, 2026
35 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-poetry-venv-discovery branch October 1, 2026 13:27
@mikolalysenko Mikola Lysenko (mikolalysenko) removed the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Oct 1, 2026
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 1, 2026
@claude
Merge origin/main into agent/fix-bundler-manifest-resolution
1ad573b
Keeps both CHANGELOG entries (gem manifest fix and the Poetry venv
fix from #330).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L6i4cQ51yarBFnFs2b8HRx
cursor[bot]
cursor Bot reviewed Oct 1, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 50cde0a. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 1, 2026
@claude
Merge main: keep Pipenv and Poetry venv discovery
cdcc2b3
#330 reordered Poetry venv discovery in the same function. Keep both:
a Pipenv project uses only the venv Pipenv resolves, then Poetry's
out-of-tree env when Poetry would not use ./.venv, then the generic
.venv / venv probes.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) mentioned this pull request Oct 1, 2026
Poetry with virtualenvs.in-project = true but no ./.venv keeps using its out-of-tree env, which socket-patch never probes: agent patches the global interpreter and hosted VEX falsely attests #476
Closed
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 1, 2026
@claude
poetry: run 5 (#476 filed, #330 verified on Linux, #328 partially fixed)
b85f5f6
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015S6JgBt7UbFe5cCPM9xbYp
This was referenced Oct 1, 2026
Fix Pipenv venv discovery order (#334, #384) #388
Merged
Fix Pipenv matrix flake on 503/DNS transport blips #419
Merged
With several Poetry envs for one project (poetry env use on two Python minors), agent mode patches the alphabetically first env instead of the one Poetry activated, and VEX attests not_affected #526
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@Tanmay182003 Tanmay Singla (Tanmay182003) Tanmay182003 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Windows agent-mode scan never finds Poetry's default out-of-tree virtualenv, so patches are skipped and the scan exits 0 Agent-mode scan misses Poetry's venv for nameless non-package-mode projects, [project].name overrides, and in-project = false with a stray .venv, and still exits 0

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mikolalysenko @Tanmay182003 @claude
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.