fix(setup): leave a shared absolute VENV in place #51

Merged
claudiomaradonna merged 3 commits from fix/setup-shared-venv into main 2026-11-16 14:03:10 +01:00
Collaborator

Why

make setup builds the Python toolchain castrum's gates and playbooks
run from (ansible-core, ansible-lint, molecule, the collections), and
contributors and coding agents run it to prepare every new checkout or
worktree. A container image can instead bake that toolchain once,
outside any checkout, and export VENV with its path, so that every
checkout in the container shares it, as CONTRIBUTING.md § Setup
describes.

In such a container, make setup removed the shared toolchain before
rebuilding it from the network. Every other checkout of the container
lost its tools until the rebuild finished, and for good when it failed,
such as offline; agents ran it for each worktree they opened. Under
Claude Code's sandbox, which keeps the path read-only, setup failed
with exit 2 instead, which is how it showed up.

Two alternatives were set aside: refusing every absolute VENV, which
would stop make VENV=/some/path setup from building a toolchain
outside the checkout as it does today; and telling agents to skip
setup there, which this change makes unnecessary, since setup is now
safe there.

What changed

Before, make setup with an absolute VENV always ran
rm -rf $(VENV) and rebuilt it. Now, when that VENV already holds an
executable bin/ansible-lint, the same test make check makes, setup
leaves it in place, clears only the checkout's .ansible caches, and
says so: setup: using the shared toolchain in <VENV>, left in place.
A relative VENV, such as the default .venv, and an absolute VENV
without that executable are removed and rebuilt as before.

The test is a Make conditional in the Makefile's setup target. The
new gate tests/gates/check_setup_shared_venv.sh, run by make check,
checks setup's commands with make -n, its first commit pinning the
rebuild that stays. CONTRIBUTING.md § Setup and § Gates describe both.

How to verify

Have Git, GNU Make and Python 3.12 or later; nothing is installed, and
the stub stands in for a shared toolchain.

D=$(mktemp -d)
git clone https://git.unitoo.it/claudiomaradonna/castrum.git "$D/castrum" && cd "$D/castrum"
mkdir -p "$D/shared/bin" && printf '#!/bin/sh\n' > "$D/shared/bin/ansible-lint" && chmod +x "$D/shared/bin/ansible-lint"
make -n setup VENV="$D/shared" | grep 'rm -rf'

On main, setup would remove the shared toolchain:

rm -rf <tmp>/shared .ansible roles/hardening-basic/.ansible

Then on the branch, for real:

git fetch origin fix/setup-shared-venv && git switch --detach FETCH_HEAD
make setup VENV="$D/shared"; ls "$D/shared/bin"
rm -rf .ansible roles/hardening-basic/.ansible
setup: using the shared toolchain in <tmp>/shared, left in place - run 'make check'
ansible-lint

make setup exits 0 and the stub is still there.

Checks: make check passed on every commit of the branch and on the
tip; the gate's shared-toolchain check fails on main at
"setup removes the shared toolchain", and its pins pass there.
make VENV=.venv setup still builds a checkout venv from scratch.
Not tried: make test, since podman was missing where the change was
made; the change touches no role or scenario.

Considerations

  • A shared toolchain no longer takes pin changes through make setup:
    rebuilding it means removing it or rebuilding the image, as
    CONTRIBUTING.md now says.
  • The gate reads make -n output, so it sees only conditions Make
    decides; moving the test into the recipe's shell would need the gate
    revised.
## Why `make setup` builds the Python toolchain castrum's gates and playbooks run from (ansible-core, ansible-lint, molecule, the collections), and contributors and coding agents run it to prepare every new checkout or worktree. A container image can instead bake that toolchain once, outside any checkout, and export `VENV` with its path, so that every checkout in the container shares it, as `CONTRIBUTING.md` § Setup describes. In such a container, `make setup` removed the shared toolchain before rebuilding it from the network. Every other checkout of the container lost its tools until the rebuild finished, and for good when it failed, such as offline; agents ran it for each worktree they opened. Under Claude Code's sandbox, which keeps the path read-only, setup failed with exit 2 instead, which is how it showed up. Two alternatives were set aside: refusing every absolute `VENV`, which would stop `make VENV=/some/path setup` from building a toolchain outside the checkout as it does today; and telling agents to skip setup there, which this change makes unnecessary, since setup is now safe there. ## What changed Before, `make setup` with an absolute `VENV` always ran `rm -rf $(VENV)` and rebuilt it. Now, when that `VENV` already holds an executable `bin/ansible-lint`, the same test `make check` makes, setup leaves it in place, clears only the checkout's `.ansible` caches, and says so: `setup: using the shared toolchain in <VENV>, left in place`. A relative `VENV`, such as the default `.venv`, and an absolute `VENV` without that executable are removed and rebuilt as before. The test is a Make conditional in the `Makefile`'s `setup` target. The new gate `tests/gates/check_setup_shared_venv.sh`, run by `make check`, checks setup's commands with `make -n`, its first commit pinning the rebuild that stays. `CONTRIBUTING.md` § Setup and § Gates describe both. ## How to verify Have Git, GNU Make and Python 3.12 or later; nothing is installed, and the stub stands in for a shared toolchain. ```bash D=$(mktemp -d) git clone https://git.unitoo.it/claudiomaradonna/castrum.git "$D/castrum" && cd "$D/castrum" mkdir -p "$D/shared/bin" && printf '#!/bin/sh\n' > "$D/shared/bin/ansible-lint" && chmod +x "$D/shared/bin/ansible-lint" make -n setup VENV="$D/shared" | grep 'rm -rf' ``` On `main`, setup would remove the shared toolchain: ```text rm -rf <tmp>/shared .ansible roles/hardening-basic/.ansible ``` Then on the branch, for real: ```bash git fetch origin fix/setup-shared-venv && git switch --detach FETCH_HEAD make setup VENV="$D/shared"; ls "$D/shared/bin" ``` ```text rm -rf .ansible roles/hardening-basic/.ansible setup: using the shared toolchain in <tmp>/shared, left in place - run 'make check' ansible-lint ``` `make setup` exits 0 and the stub is still there. Checks: `make check` passed on every commit of the branch and on the tip; the gate's shared-toolchain check fails on `main` at "setup removes the shared toolchain", and its pins pass there. `make VENV=.venv setup` still builds a checkout venv from scratch. Not tried: `make test`, since podman was missing where the change was made; the change touches no role or scenario. ## Considerations - A shared toolchain no longer takes pin changes through `make setup`: rebuilding it means removing it or rebuilding the image, as `CONTRIBUTING.md` now says. - The gate reads `make -n` output, so it sees only conditions Make decides; moving the test into the recipe's shell would need the gate revised.
make setup removes and rebuilds a relative VENV, or an absolute one
that holds no toolchain, along with the checkout's .ansible caches.
No test guarded that; pin it before setup learns to leave a shared
toolchain in place.
An absolute VENV can name a toolchain a container image bakes for
every checkout and worktree it holds, and agents prepare each new
worktree with make setup. Setup removed that toolchain and rebuilt it
from the network, taking the tools from every other checkout meanwhile;
under Claude Code's sandbox it failed on the read-only path instead.

Setup now leaves an absolute VENV that already holds ansible-lint in
place, clearing only the checkout's .ansible caches. A relative VENV,
or an absolute one without a toolchain, is rebuilt as before.
docs(contributing): say setup keeps a shared VENV
All checks were successful
check / check (pull_request) Successful in 20m4s
d688e454aa
The Setup section said a container's checkouts share the image's
toolchain with no setup of their own, while agents prepare every
worktree with make setup. Say what setup now does there, and how to
rebuild such a toolchain.
claudiomaradonna deleted branch fix/setup-shared-venv 2026-11-16 14:03:19 +01:00
Sign in to join this conversation.
No description provided.