fix(tools): uv, Poetry and Bundler run no repository or package code
Stacked on #345 (base fix/tools-sandbox). Scope: uv, Poetry and Bundler. npm, Yarn, dotnet, git transport for Node and the threat-model rewrite are on fix/no-exec-node-dotnet, which is also stacked on #345.
The rule: code a repository chose never runs on the Count's machine, and package code counts as repository-chosen. What can be locked without running code is still locked. An update whose lock can't be is skipped with a standing reason on the dashboard and in the report. It is never written with a stale lock, and lockfile maintenance is skipped the same way.
The refusal path (shared)
patchula_lockfiles::Failure::Refused(String)is the error the lockfile layer returns when it refuses.Plan::lockfiles_failedturns it intoHold::Blocked(reason), the hold that already reports skipped updates, so the plan shows asSkippedwith that reason. The reason is always the Count's own text, never tool output.Runner::refusable_toolisheld_toolplus a classifier. The classifier decides whether a tool's failure means "stopped before running code", and it runs before any credentialed output is withheld.- Whichever of the two stacked PRs lands second reconciles this path.
uv
-
Mechanism:
uv lock --no-build, plusUV_NO_BUILD=1.UV_PYTHONgives the interpreter by version, so a.python-versionthat names a path can't pick another one. -
Flags verified against uv 0.13.6 (
uv lock --help):--no-build Don't build source distributions [env: UV_NO_BUILD=]and-p, --python [env: UV_PYTHON=]. -
Finding (contradicts the design note):
--no-builddoes not stop uv building the workspace's own packages. With a marker backend, uv 0.13.6 built and ran it for:- a root project with
dynamic = ["dependencies"] - a root project with
dynamic = ["version"]only - a workspace member with dynamic metadata
It also did so with
--no-build-package <root>and withUV_NO_BUILD_ISOLATION=1. Path and editable dependencies, sdists from an index, and a root with no[build-system]were refused by uv itself. Static workspace members with a[build-system]were not built. - a root project with
-
So: before uv runs, the Count refuses when any
pyproject.tomlin the workspace declares non-emptydynamic. That means the project's own file, plus every one under an ancestor that declares[tool.uv.workspace]. Amembersorexcludeglob that leaves the workspace root is also refused. Apyproject.tomlthat doesn't parse fails the run before uv reads it. -
uv's own "Building source distributions … is disabled", "building from source is disabled" and "has no usable wheels" answers become refusals.
Poetry
- No setting stops builds during
poetry lock. Poetry 2.5.1 builds throughpoetry.inspection.info.get_pep517_metadata, which usespoetry.utils.isolated_build.isolated_builder(an isolated env,build.ProjectBuilderand pyproject_hooks). Read from the installedpoetry/inspection/info.pyandpoetry/utils/isolated_build.py. - Mechanism: Poetry runs only as
python -I poetry_guard.py <version> lock --no-interaction --no-plugins ….- The launcher finds Poetry's interpreter from the
poetryscript's shebang, including the installer's/bin/shtrampoline, and re-execs itself there with-I. - It checks that the installed Poetry is exactly the expected version.
- It replaces these with a function that calls
os._exit(86), so Poetry can't catch it:pyproject_hooks._impl.BuildBackendHookCaller._call_hook,build._builder.ProjectBuilder.__init__,poetry.utils.isolated_build.isolated_builder,poetry.inspection.info.get_pep517_metadata,poetry.installation.chef.Chef.prepare, andPluginManager.load_plugins/add_project_plugin_path/ensure_project_plugins. - It replaces every alias other modules already imported, then starts Poetry's
main. - If a guarded name is missing or the version differs, it exits 87 and Poetry never runs.
- The launcher finds Poetry's interpreter from the
- A repository that pins a Poetry version other than the default (2.5.1, the version the canary covers) is refused before anything runs.
- Verified by hand on the VM: plain
poetry lockon a path dependency with a marker backend wrote the marker. Under the launcher it exited 86 atget_pep517_metadataand wrote no marker.--versionwithout--no-pluginsexits 86 atadd_project_plugin_path.
Bundler
- Mechanism: Bundler never sees the repository's Gemfile.
patchula_manager::render_gemfilerebuilds the Gemfile from the existing strict Gemfile grammar. The grammar's values now keep literal contents, so they can be written back.- Only
source,gem,group/platformsblocks andrubylines are emitted. bundle lockruns in a scratch directory under the run's driver, outside the checkout, with a copy ofGemfile.lockand anyruby file:sibling. OnlyGemfile.lockis copied back.
- Environment:
BUNDLE_GEMFILEpoints at the rendered file,BUNDLE_APP_CONFIGat the Count's own directory, andGIT_ALLOW_PROTOCOL=none.BUNDLE_VERSION=systemwas verified in Ruby 4.0.9 / Bundler 4.0.20:bundler/settings.rbdefaultsBUNDLE_VERSIONtolockfile,bundler/self_manager.rbreturns early on"system", andman/bundle-config.1.ronndocuments it. - Refused:
gemspec,path:/git:/github:/other forge gems,git_source,plugin,eval_gemfile,install_if, any line the grammar does not read (Ruby code,=begin,__END__, multi-line calls), an unclosed block, aruby file:outside the Gemfile's directory, and a lock withGIT,PATHorPLUGIN SOURCEsections.
Tests
- Unit tests (patchula-tools):
- workspace and dynamic-metadata refusals, with a dynamic project outside the workspace not counted
--no-buildandUV_NO_BUILD/UV_PYTHONare set; uv build answers become refusals and other failures stay errors- Poetry runs only under the guard (checks the launcher text and arguments); exit 86 and 87 are refusals and exit 1 is an error; a repository Poetry pin is refused
- the rendered Gemfile, its scratch directory (only
GemfileandGemfile.lock, outside the tree) andBUNDLE_VERSION/GIT_ALLOW_PROTOCOL - each Bundler refusal
- a refusal holds the plan instead of failing it
- Unit tests (patchula-manager): the renderer output, and each refused form.
- Real-tool canaries (
test:tools):real_uv_never_builds_a_package_directly_or_transitively: a dynamic workspace package, a path dependency with a marker backend, and the same package as an sdist on a find-links index reached through another package. All three refused, no marker.real_poetry_never_builds_a_package_directly_or_transitively: the path dependency directly, and the sdist through another path package. Both refused with exit 86, no marker.real_bundler_never_evaluates_repository_ruby: a GemfileFile.writeline,gemspec, a path gem and a git gem whose gemspec writes the marker. All refused, no marker.- The existing
real_uv_and_poetry_regenerate_python_locksandreal_bundler_relocks_offlinepass through the new paths.
- On the VM: patchula-tools unit tests (158 passed), the five real uv/Poetry/Bundler tests, the patchula-manager, -update and -lockfiles tests, engine
state_parity, and clippy-D warningson tools, manager, update, lockfiles and engine. - Bumped the extract, files, config, config-files, catalog and catalog-controls state versions.
Dropped / not done here
- Scanner item 5 (the threat model contradicts the lockfile guide) is only half addressed here. The uv/Poetry/Bundler parts of the danger box and the partitions paragraph in
guide/lockfiles.mdare rewritten.threat-model.mdand the npm/Yarn/dotnet parts belong to the other branch. renovate/compatibility.mdanddepartures.mdare not touched, since my docs scope wasguide/lockfiles.mdandguide/managers.md. The other branch or a follow-up should note that the Count refuses these locks where Renovate runs the tools.
Follow-ups
- Bundler resolves registry gems from compact index or Marshal specs, which RubyGems loads through its safe Marshal loader; worth stating in the threat model.
- A Poetry version bump in
defaults.tomlneeds the guard's entry points rechecked. The canary fails closed (exit 87) if a name is missing, but a new build path would not show up as a missing name. - uv's refusal of first-party packages is an over-approximation: a
dynamicproject withtool.uv.package = falseis refused too.