Skip to content

Commit f8cf609

Browse files
Restore the uv 0.2 pins hosted mode writes (#2014)
* Restore the uv 0.2 pins hosted mode writes Hosted mode rewires uv 0.2 `[[distribution]]` locks (uv < 0.2.35) in all three of their grammars, but the hosted unwind refused every such pin ("which grammar this lock follows is not derivable"), so `rollback`, `remove` and `scan` could not undo what hosted wrote. The grammar is derivable: it is the same evidence the rewrite follows. The entry's own hosted source keeps its spelling (`"direct+<url>"` vs `{ url }`), and the lock's other registry packages show the registry, the artifact shape (`[distribution.sdist]` / `[[distribution.wheel]]` sub-tables vs inline `sdist` / `wheels`) and the artifact keys. So the unwind now restores these entries like `[[package]]` ones: - the source goes back to `"registry+<R>"` or `{ registry = R }` in the entry's spelling; - artifacts are re-derived from PyPI in the siblings' shape, with uv <= 0.2.5's `wheel` key and its sub-table order (sdist before the entry's `[[distribution.dependencies]]`, wheels after); - dependents' references, inline or `[[distribution.dependencies]]` tables with string sources, are pointed back. The paired pyproject is restored as before. Vendored still refuses these locks (no portable local wheel spelling), unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Prove the uv 0.2 unwind faithful, refuse what it can't restore Review fixes for the uv 0.2 `[[distribution]]` hosted unwind, checked against real `uv lock` output from uv 0.1.45 to 0.2.35: - Every one of those releases records every file of a release on every platform, so a pure-Python 3 release re-derives faithfully in all three grammars. The tests now round-trip real 0.1.45, 0.2.5, 0.2.15, 0.2.16, 0.2.18 and 0.2.34 locks (tests/fixtures/upstream/uv-0.2). - uv <= 0.2.5 write an entry's sdist and wheel sub-tables before its dependency tables; the unwind had the wheel after them. - uv 0.2.18-0.2.22 write an inline sdist before inline dependencies, 0.2.23-0.2.34 after them, and nothing else in the lock tells them apart. The order is read off another registry entry carrying both; without one the rewrite refuses to wire the entry and the unwind refuses to restore it. - uv 0.2.12-0.2.27 apply an exclude-newer cutoff from [tool.uv], a project or user uv.toml, or UV_EXCLUDE_NEWER without recording it; 0.2.28-0.2.33 record it at the lock's top level. The unwind refuses on any of them for the inline grammar (and on the top-level key), and the rewrite refuses a lock whose project sets one. - One grammar detector in utils/python_lock.rs serves both directions: the entry's own artifacts decide, then any other entry's (the rewrite's whole-text search is gone). - Sources are restored through UvSource in their own spelling, a standard [distribution.source] table included, with accurate errors; artifact_tables reuses table_likes. Docs: CLI_CONTRACT.md and docs/testing/uv-compatibility.md describe the restore, the refusals and the measured boundaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Don't treat exclude-newer-package as a uv 0.2 lock cutoff sets_exclude_newer matched every key starting with exclude-newer, so a project setting exclude-newer-package (a per-package cutoff, or a false exemption) made hosted rewrite and the uv 0.2 unwind refuse every inline [[distribution]] pin. uv 0.2.12-0.2.27, the releases whose unrecorded cutoff this guards against, predate that key and ignore it, so only the global exclude-newer cutoff blocks those locks. The pyproject [options] path in upstream/uv.rs already excluded the key the same way. Found by Cursor Bugbot on ab4f0f8. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQKNTJYztmYaJaAEsc * Refuse to wire uv locks whose exclude-newer the unwind refuses Second review round, plus the known follow-up. - A uv lock that records an `exclude-newer` cutoff for the package (a global one under `[options]` or, for uv 0.2.28-0.2.33, at the top level, or an `exclude-newer-package` naming it) was still wired by hosted mode, though the unwind always refuses such a pin. The rewrite now refuses it (`redirect_uv_lock_unsupported`), for `[[package]]` and `[[distribution]]` locks alike. One classifier, `upstream::lock_cutoff`, serves the rewrite and the unwind. - The rewrite's project-settings cutoff check for `[[distribution]]` locks re-implemented uv settings discovery and missed the settings file above the root (`UV_ANCESTOR_CONFIG_KEY`) the unwind reads. It now uses `pylock_uv_settings` / `root_uv_settings`, computed once per run rather than per dep. - The sdist / inline-dependencies refusal ran before the not-applicable checks, turning an entry the rewrite does not touch (a non-registry, non-direct source) into a hard refusal. It now runs after them. - docs/testing/uv-compatibility.md no longer contradicts itself on which release files a 0.2.x lock records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 57923a3 commit f8cf609

22 files changed

Lines changed: 1549 additions & 110 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ v5.0 replaces v4's per-purl reverts and whole-ledger reverse replay (`revert_rem
12681268
* **vlt** — `vlt-lock.json`: slot [2] from the registry's `dist.integrity`, slot [3] per the lock's own convention (see the vlt hosted-mode contract); every hosted instance of the pin together.
12691269
* **cargo** — `Cargo.lock` back on crates.io (source + the sparse index's checksum, `SOCKET_CRATES_INDEX`). When the lock already holds a crates.io block for the same `name@version` (a later dependent locked its own copy, #679), the Socket block merges into it instead: it is dropped (with a v1 lock's `[metadata]` line), and dependents' references take the spelling cargo writes, so no duplicate block is left that cargo cannot parse (#863), and no index lookup is needed; every `Cargo.toml` declaration loses its `registry = "socket-patch-<uuid>"` pin (the shorthand the rewriter produced collapses back); every `[registries.socket-patch-<uuid>]` block no manifest or lock still references leaves the project cargo config — including a superseded patch generation's block an earlier re-pin left behind (#864). A declaration it cannot unpin refuses.
12701270
* **golang** — the hosted `replace` (in the root `go.mod`, an in-root workspace member's `go.mod`, or `go.work`) and the socket module's sum lines (its `go.sum`, `go.work.sum`, and for a `go.work` pin each in-root member's `go.sum`) go; the upstream module's two go.sum lines come back: for a `go.mod` pin into the `go.sum` beside it; for a `go.work` pin, which leaves the members' pair in place, only when no sum file holds them, into each sum file that held the socket pair, else `go.work.sum`. A `go.work.sum` left empty is removed; hashed from the module proxy (`SOCKET_GOPROXY`, else `GOPROXY` / `GONOPROXY` / `GOPRIVATE` as go reads them) and cross-checked against the checksum database (`SOCKET_GOSUMDB_URL`, else `sum.golang.org` unless `GOSUMDB=off` / `GONOSUMDB` / `GOPRIVATE` say go would not ask it). A `replace` the user had before the hosted run is not recorded anywhere, so the restore lands on the plain upstream module.
1271-
* **pypi** — `Pipfile.lock`, `requirements.txt` (+ in-root `-r` includes), Hatch PEP 508 direct references (`pyproject.toml` / `hatch.toml`), `poetry.lock`, `pdm.lock`, `uv.lock`, PEP 723 script locks and PEP 751 `pylock*.toml` (+ the paired `pyproject.toml` / script metadata): hashes re-derived from PyPI's JSON API (`SOCKET_PYPI_JSON_API`). A restored `requirements.txt` line gets `--hash` options only when the file is in pip's hash-checking mode. The mode is read off the file's other requirement lines (an `-e` / `--editable` line means unhashed). When every requirement is a hosted pin, it is read off the hosted line itself (`--hash` vs a `#sha256=` url fragment) (#410). Refused: a `static_urls` `pdm.lock` whose project installs from an index other than PyPI (a `[[tool.pdm.source]]` in the sibling `pyproject.toml`, a project `pypi.url` (`.pdm.toml`, then `pdm.toml`), or, with neither, another package's file URL in the lock off PyPI's file host), since restoring PyPI's file URLs would make `pdm sync` bypass that index (#413); a `pdm.lock` without `cross_platform`, or a uv / script / pylock lock, whose release has a wheel that is not pure Python 3 (which files the lock keeps is not re-derivable); a uv lock whose options filter files (`exclude-newer`, `no-binary`, `no-build`, or an `exclude-newer-package` cutoff for the restored package; one of `false` exempts it from the global cutoff here and in pylocks, as in uv) (#1604); a pylock from `uv pip compile` whose header command line (`--no-build`, `--only-binary`, `--no-binary`, `--exclude-newer`, `--exclude-newer-package`) or uv settings (the nearest `uv.toml`, else a pyproject's `[tool.uv]` / `[tool.uv.pip]`, then the user's and the system's `uv.toml` unless `UV_NO_CONFIG` is set, merged as uv does with `[pip]` over the top level; none under `--no-config`, and any `--config-file` refuses; `UV_CONFIG_FILE` or `UV_EXCLUDE_NEWER` set in the restoring environment also refuses, since the header does not record uv's environment) filter the restored package's files, or whose header records no `uv pip compile` command line (`--no-header`, `UV_CUSTOM_COMPILE_COMMAND`), since uv 0.9.16 records only the files those filters let through (#1613); a uv lock whose other registry packages name no registry, several, or one other than PyPI's simple index; a pylock whose other registry packages show neither an `index` nor (as `uv pip compile` writes them) only PyPI files with none, which restores the entry without an `index` too; uv 0.2 `[[distribution]]` locks. Restored artifact fields keep the spelling the lock's other entries show, including the `upload_time` that uv 0.6.15–0.6.17 write. A restored pylock entry's `upload-time`s are whole seconds, as uv writes them, unless the lock's other entries show fractions. Its artifacts come back in the TOML spelling the other entries use: uv's inline `wheels = [{ … }]`, or the standard tables `pip lock` writes (`[[packages.wheels]]` with a `[packages.wheels.hashes]` sub-table, `[packages.sdist]`). A `pip lock` file (`created-by = "pip"`) records only the artifact pip selected, so the entry is restored with only the release's wheel (its sdist when it has none), and a release with several wheels is refused. A transitive `override-dependencies` entry hosted mode added is removed (`upstream_uv_override_removed`). Hosted mode keeps no ledger, so it marks the entry it adds with a `# socket-patch hosted: …` comment line above it and removes only a marked entry; a user's own `<name>==<version>` override (which the hosted rewrite reuses rather than adding a second one) is kept, and the lock's `[manifest] overrides` record of it gets its specifier back.
1271+
* **pypi** — `Pipfile.lock`, `requirements.txt` (+ in-root `-r` includes), Hatch PEP 508 direct references (`pyproject.toml` / `hatch.toml`), `poetry.lock`, `pdm.lock`, `uv.lock`, PEP 723 script locks and PEP 751 `pylock*.toml` (+ the paired `pyproject.toml` / script metadata): hashes re-derived from PyPI's JSON API (`SOCKET_PYPI_JSON_API`). A restored `requirements.txt` line gets `--hash` options only when the file is in pip's hash-checking mode. The mode is read off the file's other requirement lines (an `-e` / `--editable` line means unhashed). When every requirement is a hosted pin, it is read off the hosted line itself (`--hash` vs a `#sha256=` url fragment) (#410). Refused: a `static_urls` `pdm.lock` whose project installs from an index other than PyPI (a `[[tool.pdm.source]]` in the sibling `pyproject.toml`, a project `pypi.url` (`.pdm.toml`, then `pdm.toml`), or, with neither, another package's file URL in the lock off PyPI's file host), since restoring PyPI's file URLs would make `pdm sync` bypass that index (#413); a `pdm.lock` without `cross_platform`, or a uv / script / pylock lock, whose release has a wheel that is not pure Python 3 (which files the lock keeps is not re-derivable); a uv lock whose options filter files (`exclude-newer`, `no-binary`, `no-build`, or an `exclude-newer-package` cutoff for the restored package; one of `false` exempts it from the global cutoff here and in pylocks, as in uv) (#1604); a pylock from `uv pip compile` whose header command line (`--no-build`, `--only-binary`, `--no-binary`, `--exclude-newer`, `--exclude-newer-package`) or uv settings (the nearest `uv.toml`, else a pyproject's `[tool.uv]` / `[tool.uv.pip]`, then the user's and the system's `uv.toml` unless `UV_NO_CONFIG` is set, merged as uv does with `[pip]` over the top level; none under `--no-config`, and any `--config-file` refuses; `UV_CONFIG_FILE` or `UV_EXCLUDE_NEWER` set in the restoring environment also refuses, since the header does not record uv's environment) filter the restored package's files, or whose header records no `uv pip compile` command line (`--no-header`, `UV_CUSTOM_COMPILE_COMMAND`), since uv 0.9.16 records only the files those filters let through (#1613); a uv lock whose other registry packages name no registry, several, or one other than PyPI's simple index; a pylock whose other registry packages show neither an `index` nor (as `uv pip compile` writes them) only PyPI files with none, which restores the entry without an `index` too. Restored artifact fields keep the spelling the lock's other entries show, including the `upload_time` that uv 0.6.15–0.6.17 write. A uv 0.2 `[[distribution]]` lock (uv 0.1.45–0.2.34) is restored like a `[[package]]` one, in the grammar the hosted rewrite wrote the entry in, which is the entry's own: its source keeps its spelling (a string `"direct+…"` back to `"registry+…"`, uv ≤ 0.2.17, or an inline table), its artifacts their grammar (`[distribution.sdist]` / `[[distribution.wheel]]` sub-tables, uv ≤ 0.2.5, or inline), and dependents' references, inline or `[[distribution.dependencies]]` tables, are pointed back. Refused there: an entry with an sdist and inline `dependencies` when no other registry entry of the lock carries both (uv 0.2.18–0.2.22 and 0.2.23–0.2.34 order them differently; hosted mode refuses to wire such an entry, `redirect_uv_lock_unsupported`); and, for the inline-artifact grammar, an `exclude-newer` cutoff the lock does not record: the project's settings (`uv.toml`, else the pyproject's `[tool.uv]`), the user's or system `uv.toml`, or `UV_EXCLUDE_NEWER` (uv 0.2.12–0.2.27 apply these without recording them; hosted mode refuses to wire a lock whose project sets one). A cutoff uv 0.2.28–0.2.33 recorded at the lock's top level refuses like an `[options]` one. A cutoff passed to uv 0.2.6–0.2.27 only on the command line leaves no trace and cannot be detected. A restored pylock entry's `upload-time`s are whole seconds, as uv writes them, unless the lock's other entries show fractions. Its artifacts come back in the TOML spelling the other entries use: uv's inline `wheels = [{ … }]`, or the standard tables `pip lock` writes (`[[packages.wheels]]` with a `[packages.wheels.hashes]` sub-table, `[packages.sdist]`). A `pip lock` file (`created-by = "pip"`) records only the artifact pip selected, so the entry is restored with only the release's wheel (its sdist when it has none), and a release with several wheels is refused. A transitive `override-dependencies` entry hosted mode added is removed (`upstream_uv_override_removed`). Hosted mode keeps no ledger, so it marks the entry it adds with a `# socket-patch hosted: …` comment line above it and removes only a marked entry; a user's own `<name>==<version>` override (which the hosted rewrite reuses rather than adding a second one) is kept, and the lock's `[manifest] overrides` record of it gets its specifier back.
12721272
* **gem** — `Gemfile.lock` / `gems.locked` + `Gemfile` / `gems.rb`: the spec moves back into the upstream `GEM` section (or the Socket remote leaves a merged section), the `source "<patch registry>" do … end` block is undone (also when a superseding hosted re-scan on a lock with no `CHECKSUMS` section has moved that block to the newer patch of the same name and version while the lock still pins the older one; several such blocks are refused), the `CHECKSUMS` entry is re-pinned from the rubygems.org compact index (`SOCKET_RUBYGEMS_URL`) and the `DEPENDENCIES` pin loses its `!`, unless the declaration comes back inside the user's own `source "…" do` block (Bundler writes the `!` for any dependency declared in one, rubygems.org included), where the `!` stays. The declaration's original constraint is not recorded, so it comes back as the exact pin `gem "<name>", "<version>"`. A transitive gem (one the manifest never declared) gets an appended block with a blank line before it; the restore removes that block, its blank line and the `DEPENDENCIES` entry, so the pair comes back byte for byte. An appended block with no blank line before it (written by a release before this one) can't be told apart from an in-place rewrite, so it still comes back as the exact pin. Refused: an ambiguous upstream section, an upstream remote other than rubygems.org. The manifest pair can't make a committed bundler cache upstream: a `<name>-<version>.gem` left in Bundler's cache dir that isn't the upstream archive is named by `upstream_gem_stale_cache`, never deleted.
12731273
* **composer** — `composer.lock`: `dist` and the deleted `source` block from packagist's composer v2 metadata (`SOCKET_PACKAGIST_URL`). Refused unless the entry is packagist-sourced and packagist still serves the lock's `dist.reference` for the version.
12741274
* **maven** — `pom.xml` (the `-socket.<hex8>` version suffix, the added `<repository>` / `<dependencyManagement>` entry) and the `.mvn/maven.config` / `.mvn/checksums/checksums.sha256` lines hosted mode writes: **no network**, so it restores under `--offline` too. `.mvn` files holding anything else keep the resolver lines (`maven_trusted_checksums_left`).

‎crates/socket-patch-core/src/hosted/engine.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ pub fn wheel_targets<'a>(
13561356
files: &BTreeMap<String, String>,
13571357
) -> Vec<(&'a DepOverride, &'a str)> {
13581358
use crate::utils::python_lock::{ArtifactSource, PythonLockSession};
1359-
let mut probes: Option<Vec<(&str, PythonLockSession)>> = None;
1359+
let mut probes: Option<Vec<PythonLockSession>> = None;
13601360
let mut out = Vec::new();
13611361
for dep in candidates
13621362
.iter()
@@ -1381,14 +1381,13 @@ pub fn wheel_targets<'a>(
13811381
.filter(|(path, _)| {
13821382
*path == "uv.lock" || crate::utils::python_lock::is_script_lock_name(path)
13831383
})
1384-
.map(|(_, text)| (text.as_str(), PythonLockSession::new(text)))
1384+
.map(|(_, text)| PythonLockSession::new(text))
13851385
.collect()
13861386
})
13871387
.iter()
1388-
.any(|(text, session)| {
1388+
.any(|session| {
13891389
matches!(
13901390
session.plan(
1391-
text,
13921391
&dep.name,
13931392
&dep.version,
13941393
ArtifactSource::Url(&dep.artifact_url),

0 commit comments

Comments
 (0)