fix(tools): uv, Poetry and Bundler run no repository or package code

SW
1h ago
+1484-102

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_failed turns it into Hold::Blocked(reason), the hold that already reports skipped updates, so the plan shows as Skipped with that reason. The reason is always the Count's own text, never tool output.
  • Runner::refusable_tool is held_tool plus 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, plus UV_NO_BUILD=1. UV_PYTHON gives the interpreter by version, so a .python-version that 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-build does 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 with UV_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.

  • So: before uv runs, the Count refuses when any pyproject.toml in the workspace declares non-empty dynamic. That means the project's own file, plus every one under an ancestor that declares [tool.uv.workspace]. A members or exclude glob that leaves the workspace root is also refused. A pyproject.toml that 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 through poetry.inspection.info.get_pep517_metadata, which uses poetry.utils.isolated_build.isolated_builder (an isolated env, build.ProjectBuilder and pyproject_hooks). Read from the installed poetry/inspection/info.py and poetry/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 poetry script's shebang, including the installer's /bin/sh trampoline, 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, and PluginManager.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.
  • 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 lock on a path dependency with a marker backend wrote the marker. Under the launcher it exited 86 at get_pep517_metadata and wrote no marker. --version without --no-plugins exits 86 at add_project_plugin_path.

Bundler

  • Mechanism: Bundler never sees the repository's Gemfile.
    • patchula_manager::render_gemfile rebuilds 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/platforms blocks and ruby lines are emitted.
    • bundle lock runs in a scratch directory under the run's driver, outside the checkout, with a copy of Gemfile.lock and any ruby file: sibling. Only Gemfile.lock is copied back.
  • Environment: BUNDLE_GEMFILE points at the rendered file, BUNDLE_APP_CONFIG at the Count's own directory, and GIT_ALLOW_PROTOCOL=none. BUNDLE_VERSION=system was verified in Ruby 4.0.9 / Bundler 4.0.20: bundler/settings.rb defaults BUNDLE_VERSION to lockfile, bundler/self_manager.rb returns early on "system", and man/bundle-config.1.ronn documents 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, a ruby file: outside the Gemfile's directory, and a lock with GIT, PATH or PLUGIN SOURCE sections.

Tests

  • Unit tests (patchula-tools):
    • workspace and dynamic-metadata refusals, with a dynamic project outside the workspace not counted
    • --no-build and UV_NO_BUILD/UV_PYTHON are 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 Gemfile and Gemfile.lock, outside the tree) and BUNDLE_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 Gemfile File.write line, 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_locks and real_bundler_relocks_offline pass 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 warnings on 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.md are rewritten. threat-model.md and the npm/Yarn/dotnet parts belong to the other branch.
  • renovate/compatibility.md and departures.md are not touched, since my docs scope was guide/lockfiles.md and guide/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.toml needs 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 dynamic project with tool.uv.package = false is refused too.