Skip to content

Fix vendored PyPI routing for a package-less tool lock (#1114) - #2229

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-pypi-packageless-tool-lock
Nov 25, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-pypi-packageless-tool-lock

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Refs #1114

Summary

A Poetry or PDM project that declares no dependencies has a lock with no packages, and often installs its pins from requirements.txt. scan --mode vendored offered a package from requirements.txt, and vendor then refused it with pypi_poetry_lock_package_missing (or the PDM twin) and the remedy "run poetry lock first", which writes the same empty lock again.

vendor now wires requirements.txt in that project and leaves the lock alone.

Root cause

Two readers answered "which lock governs" by different rules. The lock inventory reads past a poetry.lock / pdm.lock that resolves no packages. The vendored router (detect_pypi_flavor) picked the lock because the file exists.

The change

  • detect_pypi_flavor skips a poetry.lock / pdm.lock when all of these hold: it is the only tool lock, it parses, it resolves no packages, and a root requirements.txt exists. The project then routes to the requirements wiring, the same as a project with the tool's marker and no lock.
  • The test is lock_inventory::pypi::tool_lock_resolves_nothing, which counts packages with the inventory's own reader.
  • Routing is unchanged in every other case: no requirements.txt (the tool's refusal names the lock), another tool lock present, a lock that does not parse, and a standalone pylock.toml / script lock that pins the package (it still outranks the tool lock).
  • CLI_CONTRACT.md: one sentence in the pypi_multiple_lockfiles row.
  • Two existing router tests used an empty file as a stand-in for a real poetry.lock / pdm.lock. They now hold a [[package]], which is the case they describe. No assertion in them changed.

Evidence

Test Before the fix After
mode_migration_pypi::packageless_tool_lock_beside_requirements_vendors_requirements (built binary: vendor, then vendor --revert) fails, errorCode: pypi_poetry_lock_package_missing passes
vendor::pypi::tests::packageless_tool_lock_beside_requirements_routes_to_requirements (router and inventory agree, Poetry and PDM) fails passes
vendor::pypi::tests::packageless_tool_lock_governs_without_a_requirements_fallback (the unchanged cases) passes passes

CI on the head commit (438ba5f): all 89 checks pass, including ci-ok and clippy. Bugbot found no issues.

Run locally:

  • cargo test -p socket-patch-core --lib: 8531 passed on the fix commit; the vendor:: tests (3199) re-run on the final commit.
  • cargo test -p socket-patch-cli suites mode_migration_pypi (84), e2e_vendor_pypi_build (34, 7 ignored), in_process_vendor_pypi_takeover (9), all passed; scan_requirements_lock_only, scan_vendor_requirements_unwired, vendor_eject_fresh_checkout, e2e_vex_vendor, in_process_python_envs, vendor_ledger_schema_e2e and vendor_revert_tamper_e2e passed on the fix commit.
  • cargo clippy --locked --workspace --all-features -- -D warnings (the CI command): clean. With --all-targets clippy reports 68 findings in test code on main; none are in a file this PR touches.

Review findings (/code-review high)

Fixed:

  • Skipping the lock before the standalone-lock step made a Pipfile + pylock.toml project refuse with pypi_pipenv_pylock_unsupported. The skip now applies after that step; covered by the "beside a pylock" case.
  • The router parsed the lock once per package. A lock with a [[package]] header is now answered by a substring search.
  • The predicate's docs claimed more sharing with the inventory than there is.

Not fixed, with the reason:

  • Vendored to hosted switch. The hosted Poetry and PDM rewriters refuse a lock with no packages, so scan --mode hosted over this project keeps it vendored (redirect_takeover_kept_vendored, exit 0, still patched). A direct hosted scan of the same project is refused the same way on main. Lock inventory and the vendored PyPI router disagree on which lock governs when poetry.lock or pdm.lock has no packages #1114 lists hosted mode as out of scope.
  • The lock gains a package later. After poetry add, the lock governs by presence again, and a re-run of vendor refuses a package that only requirements.txt holds. This is how main treats every populated tool lock beside a requirements.txt, and before this PR the same project failed that way on every run. Fixing it means routing by which file resolves the package, which is a larger change.
  • Remaining disagreement. A package-less lock beside another tool lock, and a lock that does not parse, still route by presence while the inventory reads past them. The lock-over-lock order is the presence table that hosted mode, the agent-mode crawler and vex share, so changing it here would split them.
  • vex diagnostic. vex prints "package is not an array of [[package]] tables" for Poetry's package = []. It is on main already and does not change the document.

Left on #1114

  • The remaining disagreement above.
  • The issue's proposal to replace the inventory's hand-written lock order with the shared table.

https://claude.ai/code/session_011f9aeTAXUPdQSke7V7yAPS


Generated by Claude Code

Refs #1114.

Assisted-by: Claude Code:claude-fable-5-2
A Poetry or PDM project whose lock resolves no packages and whose
pins live in requirements.txt must vendor through requirements.txt.
Today vendor routes to the tool lock and refuses the package.

Refs #1114.

Assisted-by: Claude Code:claude-fable-5-2
The vendored PyPI router picked a lone poetry.lock or pdm.lock by
presence, while the lock inventory reads past one that resolves no
packages to requirements.txt. Scan then offered a package that the
Poetry or PDM backend refused, with a remedy that writes the same
empty lock again.

A lone poetry.lock or pdm.lock that parses and resolves no packages
no longer governs beside a requirements.txt. Both sides decide that
with one predicate. Without a requirements.txt, beside another tool
lock, or when the lock does not parse, routing is unchanged.

Two router tests used an empty lock file as a stand-in for a real
lock. They now hold a package, which is what they meant to test.

Refs #1114.

Assisted-by: Claude Code:claude-fable-5-2
Review of the previous commit found that dropping the package-less
lock before the standalone-lock step changed a result: with a Pipfile
in the project, a pylock pinning the package was read as Pipenv's and
refused, where it was wired before. The skip now applies only after
the standalone locks are decided, so they rank above a tool lock
whatever it holds.

The package-less test also skips the parse for a lock that holds a
[[package]] header, so routing a populated lock costs one substring
search, and its docs say which reader it shares with the inventory.

Refs #1114.

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 25, 2026 02:11
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Scoped PyPI lock-selection fix for a narrow Poetry/PDM + requirements.txt layout; behavior elsewhere is explicitly preserved and heavily tested.

Overview
Fixes #1114: Poetry or PDM projects with no declared dependencies often keep an empty poetry.lock / pdm.lock but install from root requirements.txt. Scan already offered packages from requirements.txt, yet vendor still chose the tool lock and refused with pypi_poetry_lock_package_missing / pypi_pdm_lock_package_missing.

detect_pypi_flavor now treats a lone poetry.lock or pdm.lock that parses and resolves no packages as non-governing when requirements.txt exists, and routes vendoring to the requirements wiring (the lock file is left unchanged). tool_lock_resolves_nothing in the lock inventory module implements that predicate (fast path when [[package]] is present). Routing is unchanged when there is no requirements.txt, another tool lock is present, the lock does not parse, or a standalone pylock still outranks the tool lock.

Adds CLI contract wording for this case under pypi_multiple_lockfiles, plus integration and unit tests (including vendor / revert for Poetry and PDM fixtures).

Reviewed by Cursor Bugbot for commit 438ba5f. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 438ba5f. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
A Poetry or PDM project that declares no dependencies has a poetry.lock / pdm.lock with no packages and installs from requirements.txt. vendor used to route to the empty lock and refuse (pypi_poetry_lock_package_missing) a package scan had offered from requirements.txt. Now, when that lock is the only tool lock, parses, resolves nothing, and a root requirements.txt exists, vendor wires requirements.txt and leaves the lock alone, matching what the lock inventory already does.

Risk
Low. The new branch triggers only for that exact layout. A lock with a [[package]] header, a lock that does not parse, a second tool lock, or a missing requirements.txt all keep the old routing. The lock is read only when it is a regular file, so the FIFO guard still holds. Hosted mode is unchanged.

Look here

  • vendor/pypi.rs:340: the packageless_lock predicate (lone poetry/pdm lock + requirements.txt)
  • vendor/pypi.rs:489: where it applies, after the standalone pylock step, so a pylock still outranks it
  • [lock_inventory/pypi.rs:445](https://github.com/SocketDev/socket-patch/blob/438ba5f170680bdc09ed3bd29fe44856b1b17c9c/crates/socket-patch-core/src/vendor/lock_inventory/pypi.rs#L445): tool_lock_resolves_nothing, which uses the inventory's own package reader
  • vendor/pypi.rs:4564: tests for the cases where routing does not change
  • mode_migration_pypi.rs:377: end-to-end vendor then vendor --revert on the built binary, Poetry and PDM

Verified

  • Read the whole diff against main. present holds only the lone lock when the new branch fires, so clearing it drops no other lock's warning. The two existing router tests that switched from an empty file to a real [[package]] lock keep their assertions.
  • CHANGELOG.md is untouched. No unrelated edits or leftover debug code.
  • CI on 438ba5f17 is green, including ci-ok and clippy. No open review threads. Bugbot found nothing.

Changes I made
None.

Open questions
None blocking. The description lists the follow-ups that are out of scope and stay on #1114: a lock that later gains a package, and hosted mode.


Generated by Claude Code

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Reviewed; no major findings.

Merged via the queue into main with commit a96c2c6 Nov 25, 2026
89 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-pypi-packageless-tool-lock branch November 25, 2026 15:37
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 26, 2026
No PR this run: three routine PRs are open, so the run verified
issues and hunted one area on main at cfc870f.

L34 is new and filed as #2287: refusals and hosted warnings print
the credentials of a URL they quote from a lockfile. 29 of 170
runs over 17 projects print a planted token: Cargo and Yarn
classic in vendored mode, Yarn classic, Poetry and a requirements
direct reference in hosted mode. Vendor warnings redact in their
constructor since #1026; the three other message types do not.

#748, #595 and #1112 ran and change nothing a user sees, or only
what the contract states. #1114 is fixed in part by #2229. L35 is
new and out of charter: the vendored dry run does not predict a
refusal made after the download.

Assisted-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants