Repository navigation
Commit e146e03
Support hosted and vendored PDM patches (#243)
* Support hosted and vendored PDM patches on a shared pdm.lock rewriter
Adds hosted PDM redirects and refactors the vendored PDM backend onto one
validated `pdm.lock` rewriter (`utils/pdm_lock.rs`). Hosted `scan --mode hosted`
rewrites the target `[[package]]` to the hosted wheel URL + patched SHA-256
(`redirect_pdm_lock_package`); vendored wires the same unit to a committed
wheel. Both support the legacy `[metadata.files]` table and `extras` entries,
preserve line endings and non-canonical spacing, are idempotent, and leave
`pyproject.toml` / `content_hash` untouched. Supported lock formats are `2`
(PDM 0.12-1.4) and `4.3`-`4.5.1` (PDM 2.8+); `3.1` / `4.0`-`4.2` (PDM 1.8-2.7)
and unknown formats are refused before any write.
Hardening beyond the original change:
- Hosted lock-only checkouts are discovered and redirected: the lock inventory
now reads `pdm.lock` (discovery-only, mirroring poetry). Vendored keeps
refusing a lock-only checkout since PDM installs into `__pypackages__`, which
the crawler does not probe.
- A re-scan after an external `pdm lock` rebases the ledger's edits onto the
relocked text. PDM un-patches AND may reflow line endings (CRLF -> LF) on
relock, so for the pdm edit kind the rebase adopts the fresh `original` (the
relocked registry fragment); poetry's relock keeps the patch and keeps its
older original, so its path is unchanged.
- When several Python lockfiles coexist, `uv.lock` and `poetry.lock` drive
hosted PyPI redirects ahead of `pdm.lock`; a leftover `pdm.lock` neither
blocks a live redirect nor is falsely attested. The same predicate gates the
redirect dispatch and the hosted confirmation filter.
Adds byte-exact `pdm-native` fixtures and CLI-level hosted regression tests
(lock-only redirect + attest + rollback, legacy `[metadata.files]`, and
relock-reflow convergence).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* docs, matrix harness, and CI for PDM patch compatibility
Documents hosted PDM support (ecosystems.md, hosted-production-e2e.md,
CLI_CONTRACT.md new codes, CHANGELOG) and adds the per-release matrix:
docs/testing/pdm-compatibility.md with a generated table, scripts/backtest-pdm.py
(real PDM releases via uv, hosted/vendored/agent, installed-byte verification,
tamper rejection, relock convergence, rollback), and
.github/workflows/pdm-compatibility.yml (Linux/Windows/macOS).
Measured 0.12-2.29 across 17 shapes x 3 modes: 523 pass, 268 refused as
expected (identity-losing 3.1/4.0-4.2, forked two-version locks, non-default
lock filenames), 46 unsupported (`__pypackages__` agent/vendored, a documented
layout limitation), 0 failures.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Harden PDM patches: 14 correctness fixes from an adversarial review
A 12-finder review (42 confirmed findings) plus a real-PDM verification pass
surfaced correctness gaps beyond the initial three. Fixes, each verified
against real PDM binaries:
Confirmation / attestation (false-success class):
- Refuse a lock whose `strategy` lacks `inherit_metadata` (lock_version
4.4.1/4.5.x) — PDM 2.12-2.23 re-resolves such a lock and cannot match a
rewritten `url`/`path` source (CandidateNotFound); read the 4.3 boolean
strategy spelling (`cross_platform`/`static_urls`) that PDM 2.8-2.9 write.
- A `pdm.lock` refusal now vetoes the sibling pypi rewriters only for a package
the lock CONTAINS but refuses, never one it simply lacks (which a
`requirements.txt`/pylock legitimately installs) — the old veto silently
dropped those redirects.
- An inactive `pdm.lock` (a `uv.lock`/`poetry.lock` drives) no longer feeds the
substring confirmation probe, so an untouched uv/poetry project cannot report
a bogus `redirected: 1`.
- Emit `redirect_pdm_stale_install_risk` for PDM < 2.11 locks (2/4.3/4.4), which
do not reinstall over an already-installed same-version package.
- A marker/multi-target lock holding one package at several versions is refused
with an accurate, ordering-independent message (hosted and vendored).
Vendored integrity:
- Refuse a symlinked `pdm.lock` before wire/revert (the rename-over would
replace the link and strand its target) — mirrors the uv/hosted guards.
- Require a real sha256 in the pre-flight hash guard so a non-sha256 lock is
refused before the wheel is built.
- Refuse a `pdm add`/partial-relock unit that kept the patched hash but lost the
vendored `path`, so a stale patched hash is never recorded as the registry
original.
- Supersede a prior Socket-hosted `url` (rotated token / new uuid, same origin
and wheel leaf) in place instead of refusing it as foreign.
- Fix the version-mismatch refusal to print the plain version, not `Some("…")`.
Fragments / keys:
- Give the recorded package fragment a trailing boundary so a lock_version-2
pristine fragment is not a prefix of the rewritten one (replay convergence).
- Key legacy `[metadata.files]` by PDM's `safe_name().lower()` (dots preserved),
so dotted-name packages in format-2 locks are found.
Docs: PDM 2.8.0 writes an indistinguishable `4.3` lock but shares the
identity-loss bug, so the supported floor is 2.8.1; the docker vendored e2e
awk counter now matches the inline `files` shape.
Adds unit tests for the strategy gate, multi-version fork, URL supersede,
dotted-name key, absent-package veto skip, stale advisory, symlink guard and
the non-sha256 pre-flight refusal.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 07a6b88 commit e146e03
35 files changed
Lines changed: 33000 additions & 369 deletions
File tree
- .github/workflows
- crates
- socket-patch-cli
- src/commands/scan
- tests
- socket-patch-core
- src
- patch/redirect
- utils
- vendor
- tests/fixtures/pdm-native
- docs
- testing
- pdm-compatibility
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
91 | 118 | | |
92 | 119 | | |
93 | 120 | | |
| |||
0 commit comments