Repository navigation
Description
[agent] Found by the architecture refactor routine while running the uv workspace reader against uv (lead L212). Checked on main at cd7c5c5.
Problem
A uv workspace root may list a member that sits inside another member:
[tool.uv.workspace]
members = ["app", "app/plugins/*"]From the root, uv treats app/plugins/p1 like any other member: uv workspace list shows it (0.11.32), the root's uv.lock names it under [manifest] members and locks its dependencies, and uv sync --all-packages installs them from that lock (uv 0.4.30, 0.6.17, 0.8.24 and 0.11.32).
The reader in utils/uv_workspace.rs walks up from the project and ends the walk at the first ancestor pyproject.toml that has a [project] table and no workspace table. For app/plugins/p1 that ancestor is app, the other member. So the reader finds no workspace, the #1138 refusal does not fire, and both modes rewrite the member and report success. The root's uv.lock still pins the upstream release for it.
Real uv 0.11.32, a root with the two members above, p1 on the hatchling backend with dependencies = ["six==1.16.0"], the root locked and synced by uv before the run. The binary of cd7c5c5, a stand-in patch API and vendor service (the ones mode_migration_pypi uses), each command run from the member:
Root's members, the run's directory |
The member's own uv.lock |
Command | Result | Written | Root uv lock --check after |
Root uv sync --all-packages --frozen after, then the member's import of six |
|---|---|---|---|---|---|---|
["app", "plugins/*"], from plugins/p1 (control) |
none | scan --mode hosted |
exit 1, redirect_workspace_lockfile_elsewhere |
nothing | — | — |
| the same (control) | none | vendor |
exit 1, pypi_uv_workspace_unsupported |
nothing | exit 0 | — |
["app", "app/plugins/*"], from app/plugins/p1 |
none | vendor |
exit 0, success, applied |
the member's pyproject.toml, as a Hatch project (six @ {root:uri}/.socket/vendor/pypi/<uuid>/…whl#sha256=…) |
exit 1 | exit 0, the upstream six |
| the same | none | scan --mode hosted |
exit 0, success, applied |
the member's pyproject.toml (six @ <patch host>/…whl#sha256=…) |
not shown (the stand-in had stopped) | exit 0, the upstream six |
| the same | written by uv lock in the member |
vendor |
exit 0, success |
the member's pyproject.toml ([tool.uv.sources]) and the member's uv.lock |
exit 1 | exit 0, the upstream six |
| the same | written by uv lock in the member |
scan --mode hosted |
exit 0, success |
the same two files | not run | exit 0, the upstream six |
["../shared"], the root at repo/main, from repo/shared |
none | vendor |
exit 0, success |
the member's pyproject.toml, as a Hatch project |
exit 1 | exit 0, the upstream six |
After each run in bold, at the root:
$ uv lock --check
error: The lockfile at `uv.lock` needs to be updated, but `--check` was provided.
$ uv sync --all-packages --locked
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided.
$ uv sync --all-packages --frozen && uv run --frozen --all-packages python -c 'import p1'
six 1.16.0 UPSTREAM (unpatched)
From the member, after the third row, socket-patch vendor --check exits 0 ("committed artifact and wiring verified"), and socket-patch vex writes one not_affected statement with the product pkg:pypi/p1@0.1.0 (run with a vulnerability added to the fixture's record, which has none).
This is what #1138 reported for a plain member ("the root uv.lock went stale, uv sync --frozen installed the unpatched release"), in a layout its fix leaves open. The docs say a run from the workspace root is refused too, and a run from a member that is not nested is (the controls), so the nested members are the directories of such a workspace where a run writes.
Who it hurts: a uv workspace that lists a member inside another member, or beside the root through ../, when a scan or vendor runs from that member. The run says success. A CI that installs from the root with --locked then fails; one that installs with --frozen passes and ships the unpatched release. A plain uv sync at the root re-locks and does pick the patched wheel up; after the third row the new root lock names that wheel by an absolute path (source = { path = "/…/app/plugins/p1/.socket/vendor/pypi/<uuid>/…whl" }), which is what uv makes of the Hatch {root:uri} reference.
The shape is in published projects. The root pyproject.toml in the sdist of apache-airflow 3.4.0 lists 141 members, among them dev and, inside it, dev/breeze, dev/mypy and dev/registry.
What uv lists
uv has two views of such a directory, and they differ:
From the root (uv workspace list --paths, the root's uv.lock) |
From the directory itself | |
|---|---|---|
a member under another member (app/plugins/p1) |
a member | alone: uv stops at app, and uv lock there writes a uv.lock of its own |
a member under a pyproject.toml that holds only tool settings |
a member | alone |
a member listed through ../ |
a member | alone |
a member reached through a symlink (packages/link) |
a member | alone |
The reader follows the second view for the first row, and the first view for the second row (it walks past a pyproject.toml with no [project] table and refuses). The refusal's own reason is the first view: the root's lock installs the directory.
The reader alone against uv 0.11.32, over 1,500 generated workspaces (uv loads 1,035; 7,732 directories with a pyproject.toml; member and exclude patterns in the spellings uv reads: literals, *, ?, classes, **, ./, a trailing /):
| Project directories | Count | The reader calls it a member |
|---|---|---|
the root lists it, no [project] ancestor below the root |
1,057 | 1,056 |
the root lists it, under a [project] ancestor |
324 | 0 |
| the root does not list it | 5,519 | 9 |
The one miss in the first row is a directory apps under exclude = ["apps/**"] (uv's ** does not match the directory itself). The 9 in the last row are refusals of a directory uv leaves out: 8 under an exclude such as tools/*/*, where uv's * crosses /, and apps itself under members = ["apps/**"]. Those take the safe side.
With the three lines of the [project] rule removed (a trial build, not pushed), the same 1,500 workspaces give 324 of 324 in the second row. The last row goes from 9 to 52: 51 of them sit under an exclude pattern whose wildcard uv lets cross /. uv matches an exclude pattern against the whole path, so exclude = ["tools/b*"] leaves out tools/b and tools/b/plugins/q alike (run on uv 0.11.32); the reader matches it one component at a time. On main the [project] rule hides most of that difference, so the fix has to read exclude the way uv does.
Evidence on main
#1138's test (uv_workspace_hatch_member_is_refused_in_both_modes) over a nested member, appended to crates/socket-patch-cli/tests/mode_migration_pypi.rs (the text is below). Its first case is the existing layout and passes; the second fails:
$ cargo test -p socket-patch-cli --test mode_migration_pypi uv_workspace_member_nested
thread 'uv_workspace_member_nested_in_a_member_is_refused_in_both_modes' panicked at crates/socket-patch-cli/tests/mode_migration_pypi.rs:
assertion `left == right` failed: packages/b/plugins/p hosted: {
"command": "scan",
"status": "success",
…
"redirect": { "mode": "hosted", "rewrittenFiles": [ "pyproject.toml" ] }
}
left: 0
right: 1
test result: FAILED. 0 passed; 1 failed
With the [project] rule removed it passes, and so do the suite's 22 other tests whose name holds uv_.
The test
/// A member the root lists inside another listed member is installed from
/// the root's `uv.lock` like any member, so both modes refuse a run from it.
#[tokio::test]
async fn uv_workspace_member_nested_in_a_member_is_refused_in_both_modes() {
const HATCHLING: &str = "[project]\nname = \"p\"\nversion = \"0.1.0\"\nrequires-python = \">=3.9\"\ndependencies = [\"six==1.16.0\"]\n\n[build-system]\nrequires = [\"hatchling\"]\nbuild-backend = \"hatchling.build\"\n";
for (members, rel) in [
("[\"packages/*\"]", "packages/a"),
("[\"packages/*\", \"packages/b/plugins/*\"]", "packages/b/plugins/p"),
] {
let (_tmp, ws) = project();
std::fs::write(
ws.join("pyproject.toml"),
format!("[project]\nname = \"root\"\nversion = \"0.1.0\"\nrequires-python = \">=3.9\"\n\n[tool.uv.workspace]\nmembers = {members}\n"),
)
.unwrap();
std::fs::write(
ws.join("uv.lock"),
"version = 1\nrequires-python = \">=3.9\"\n\n[manifest]\nmembers = [\"b\", \"p\", \"root\"]\n",
)
.unwrap();
std::fs::create_dir_all(ws.join("packages/b")).unwrap();
std::fs::write(
ws.join("packages/b/pyproject.toml"),
"[project]\nname = \"b\"\nversion = \"0.1.0\"\nrequires-python = \">=3.9\"\n",
)
.unwrap();
let dir = ws.join(rel);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("pyproject.toml"), HATCHLING).unwrap();
let site = dir.join("../empty-venv/lib/python3.11/site-packages");
let dist_info = site.join("six-1.16.0.dist-info");
std::fs::create_dir_all(&dist_info).unwrap();
std::fs::write(
dist_info.join("METADATA"),
"Metadata-Version: 2.1\nName: six\nVersion: 1.16.0\n",
)
.unwrap();
std::fs::write(site.join("six.py"), ORIG).unwrap();
let before = tree(&ws);
let server = MockServer::start().await;
mount_hosted_api(&server, true).await;
let (code, env) = hosted_scan(&dir, &server);
assert_eq!(code, 1, "{rel} hosted: {env:#}");
assert_eq!(
env["error"]["code"], "redirect_workspace_lockfile_elsewhere",
"{rel} hosted: {env:#}"
);
assert_eq!(tree(&ws), before, "{rel}: hosted wrote nothing");
stage_manifest(&dir);
let (code, env) = run_cli(&dir, &["vendor"], &[]);
assert_ne!(code, 0, "{rel} vendored: {env:#}");
assert!(
env.to_string().contains("pypi_uv_workspace_unsupported"),
"{rel} vendored: {env:#}"
);
assert_eq!(tree(&ws), before, "{rel}: vendored wrote nothing");
}
}Where
- The
[project]rule inwalk: an ancestor with a[project]table and no workspace returnsUngoverned. - [Its unit test](
https://github.com/SocketDev/socket-patch/blob/cd7c5c56e3e0049a5c06260c354a597b8f07658b/crates/socket-patch-core/src/utils/uv_workspace.rs#L223-L251),an_intermediate_project_is_a_boundary, uses a root withmembers = ["**"]. uv does not load that root ("Workspace member…/app/examplesis missing apyproject.toml(matches:**)"; in a checkout it stops at.git/hooks). With the two directories listed by name (["app", "app/examples/*"]) uv's root listsapp/examples/demo. - The docs sentence: "a member listed by the nearest ancestor
[tool.uv.workspace] members(no standalone[project]in between) installs from the root'suv.lock". A listed member with a[project]in between installs from the root's lock too. - The two callers:
hosted/governing_root.rs(refusal) andvendor/pypi.rs(detect_pypi_flavor).
It is the class #1138 closed. The rule came in a follow-up of that fix (2a11629, #1335): "An ancestor pyproject.toml with a [project] table and no workspace ends uv's walk … and uv does not install it from an outer workspace. The walk kept climbing, so a recursive members glob could refuse a project uv treats as standalone." The first half is uv's view from the directory. The second does not hold when the outer workspace lists the directory, and that is the only case in which the rule changes the answer: a directory the root does not list is not a member with or without it.
The other walks already take the root's view. The npm-family one keeps climbing past a manifest that lists nothing (package_json_workspace_root, with the test "The nearest ancestor that lists the member is its root, past an intermediate package.json that does not"). For the ../ row, the Hatch reader looks for a root in every project of the checkout (22162d7, #1724: "Hatch lets a root list a member beside it through a ../ spec"). The uv reader stops at the first project and only walks up.
Planned fix
- In
walk, drop the[project]rule: the nearest ancestor that declares[tool.uv.workspace]decides, whateverpyproject.tomlfiles lie between. Three production lines go; the unit test takes a layout uv loads and expects the root. - Match
excludethe way uv does, with wildcards and classes that cross/, so that step 1 does not refuse a directory under an excluded one. About 20 production lines besideglob_matches. - For a member listed through
../: look for a workspace root among the checkout's other projects, the wayutils/hatch_workspace.rsdoes, inside the same read boundary. About 60 production lines; it can be a second PR. - The parenthesis in
docs/testing/uv-compatibility.md.
Behavior change: redirect_workspace_lockfile_elsewhere / pypi_uv_workspace_unsupported (exit 1, nothing written) where the run now writes the member and says success. CLI_CONTRACT.md names the refusal for "a uv workspace pyproject.toml above" and does not mention the [project] rule.
One question for a maintainer. A nested member that has a uv.lock of its own works from its own directory: uv run there reads that lock, and after the fifth row uv sync --frozen in the member installs the patched wheel. The plan refuses it like the others, because the root's lock lists it as well and goes stale. The other reading is to write there and warn that the root's lock needs uv lock. The first is the rule #1138 set ("refused whatever locks it holds"); say so if the second is wanted.
Not run
- The hosted rows against a live patch host after the scan (the stand-in stops with the test), so the root's
uv lock --checkis shown for vendored mode only. uv syncwithout--all-packagesat the root,uv run --package, and a root that depends on the nested member through[tool.uv.sources].- A symlinked member through the binary (the reader was run on it: not a member).
- The older uv releases beyond
uv lockat the root and in the member. - Windows and macOS.
Generated by Claude Code
Activity
refactor: L212 filed as #2516 (uv nested member)