fix(scripts): make dev-setup.sh check Python, core.hooksPath and the installed hooks #15

Merged
Defame1297 merged 6 commits from fix/dev-setup-robustness into main 2026-10-25 20:38:05 +00:00
Owner

What changed (head 9dfec11, main at f271730 merged in)

scripts/dev-setup.sh:

  • requires Python >= 3.11 (ansible-core 2.19); KAMINO_PYTHON (default python3) selects the interpreter, with a clear error when it is missing or too old;
  • derives the repository from the script's own location, never from the caller's working directory;
  • rebuilds a .venv made by an older Python;
  • errors clearly if pre-commit install did not install the pre-commit/commit-msg hooks;
  • the repository path written into the installed hooks is shell-quoted with printf %q (decision: quote rather than refuse; a path with spaces, quotes, a backtick, $HOME and $(touch ...) works and the injected command does not run);
  • core.hooksPath: a value that points elsewhere, or a global/system value, fails up front with an explanation. Repo-local values that all resolve to this repository's own hooks directory (or are empty) are lifted for the install and restored afterwards. Any local value counts as present, including an empty or a trailing empty one. The values are read NUL-delimited (git config --local -z --get-all in a while read -d '' loop, no mapfile) and restored element by element, so a value containing a newline survives byte for byte. The EXIT/INT/TERM traps are installed before the unset, and the restore is idempotent;
  • the usage comment notes that readlink -f/-m are GNU (macOS >= 12.3, or coreutils). No bash 3.2 claim is made: the code avoids bash 4 features but was not run on 3.2.
    Changelog fragment says the same (an own-hooks repo-local setting is lifted and restored; only a foreign or global value fails).
  • tests/scripts/test_dev_setup.py (new, 14 tests). The "Test the repository scripts" lint step and the tests/scripts build_ignore line now come from main (#16); this branch no longer adds its own copy.

Verified

  • shellcheck: clean on the script.
  • 14 unit tests in tests/scripts/test_dev_setup.py, hermetic (temp dirs, GIT_CONFIG_GLOBAL and HOME in a temp dir, stub python/pip/pre-commit): normal run, idempotent rerun, own absolute and relative hooksPath, foreign hooksPath, global hooksPath (local value restored), multi-valued restore, newline value (compared with git config --local -z --get-all, also after a failing pre-commit), empty and trailing-empty value, restore when pre-commit fails, run from another repository leaves it untouched, crafted path a b $(touch PWNED) "q" touch PWNED2 $HOME (the generated hook still runs, PATH starts with the venv, nothing was executed). Against the previous script 4 of these fail (newline, empty, trailing empty, crafted path).
  • On the merged tree python3 -I -m unittest discover -s tests/scripts runs 48 tests (main's 34 plus these 14), all pass.
  • ansible-test sanity --test pep8 --test pylint --test shebang run locally on the new test file: clean.
  • CI at head 9dfec11, steps observed: Build job (checkout, baked tooling check, Build the Collection, galaxy-importer, ansible-test sanity) success; Lint job (pre-commit, Check image pins, Check image versions were bumped, "Test the repository scripts", gitleaks scan, Conventional Commits) success.

Not verified

  • bash 3.2 / macOS (not available; no claim made); a real pre-commit install and a real pip install (stubs in the tests); rebuild-on-older-Python against a real old interpreter; a real global hooksPath on a machine (simulated with GIT_CONFIG_GLOBAL).

🤖 Generated with Claude Code

## What changed (head 9dfec11, main at f271730 merged in) scripts/dev-setup.sh: - requires Python >= 3.11 (ansible-core 2.19); `KAMINO_PYTHON` (default `python3`) selects the interpreter, with a clear error when it is missing or too old; - derives the repository from the script's own location, never from the caller's working directory; - rebuilds a .venv made by an older Python; - errors clearly if `pre-commit install` did not install the pre-commit/commit-msg hooks; - the repository path written into the installed hooks is shell-quoted with `printf %q` (decision: quote rather than refuse; a path with spaces, quotes, a backtick, `$HOME` and `$(touch ...)` works and the injected command does not run); - `core.hooksPath`: a value that points elsewhere, or a global/system value, fails up front with an explanation. Repo-local values that all resolve to this repository's own hooks directory (or are empty) are lifted for the install and restored afterwards. Any local value counts as present, including an empty or a trailing empty one. The values are read NUL-delimited (`git config --local -z --get-all` in a `while read -d ''` loop, no `mapfile`) and restored element by element, so a value containing a newline survives byte for byte. The EXIT/INT/TERM traps are installed before the unset, and the restore is idempotent; - the usage comment notes that `readlink -f/-m` are GNU (macOS >= 12.3, or coreutils). No bash 3.2 claim is made: the code avoids bash 4 features but was not run on 3.2. Changelog fragment says the same (an own-hooks repo-local setting is lifted and restored; only a foreign or global value fails). - `tests/scripts/test_dev_setup.py` (new, 14 tests). The "Test the repository scripts" lint step and the `tests/scripts` build_ignore line now come from main (#16); this branch no longer adds its own copy. ## Verified - shellcheck: clean on the script. - 14 unit tests in `tests/scripts/test_dev_setup.py`, hermetic (temp dirs, `GIT_CONFIG_GLOBAL` and `HOME` in a temp dir, stub python/pip/pre-commit): normal run, idempotent rerun, own absolute and relative hooksPath, foreign hooksPath, global hooksPath (local value restored), multi-valued restore, newline value (compared with `git config --local -z --get-all`, also after a failing pre-commit), empty and trailing-empty value, restore when pre-commit fails, run from another repository leaves it untouched, crafted path `a b $(touch PWNED) "q" `touch PWNED2` $HOME` (the generated hook still runs, PATH starts with the venv, nothing was executed). Against the previous script 4 of these fail (newline, empty, trailing empty, crafted path). - On the merged tree `python3 -I -m unittest discover -s tests/scripts` runs 48 tests (main's 34 plus these 14), all pass. - `ansible-test sanity --test pep8 --test pylint --test shebang` run locally on the new test file: clean. - CI at head 9dfec11, steps observed: Build job (checkout, baked tooling check, Build the Collection, galaxy-importer, `ansible-test sanity`) success; Lint job (pre-commit, Check image pins, Check image versions were bumped, "Test the repository scripts", gitleaks scan, Conventional Commits) success. ## Not verified - bash 3.2 / macOS (not available; no claim made); a real `pre-commit install` and a real pip install (stubs in the tests); rebuild-on-older-Python against a real old interpreter; a real global hooksPath on a machine (simulated with `GIT_CONFIG_GLOBAL`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Claude added 1 commit 2026-10-25 18:21:00 +00:00
fix(scripts): make dev-setup.sh check Python, core.hooksPath and the installed hooks
Lint / lint (pull_request) Successful in 5s
Build / build (pull_request) Successful in 8s
4ed03b508a
Require Python 3.11+ (PYTHON selects the interpreter), rebuild a virtualenv made
by an older Python, exit early when core.hooksPath is set, fail clearly when a
hook was not installed, and resolve the hook path with --path-format=absolute.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Defame1297 added 1 commit 2026-10-25 18:49:52 +00:00
fix(dev-setup): derive the repository from the script, rename PYTHON to KAMINO_PYTHON
Molecule / molecule (pull_request) Skipped
Build / build (pull_request) Successful in 9s
Lint / lint (pull_request) Successful in 7s
19faa49a4c
The script took its repository from the caller's working directory, so running it
from another repository could create or remove that repository's .venv. It now
resolves its own location (symlinks included) and uses git -C for every call.
The interpreter variable is KAMINO_PYTHON, and the usage comment no longer claims it
always selects the venv interpreter. A core.hooksPath that resolves to the
repository's own hooks directory is lifted for the install and restored; any
other value is still rejected.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Defame1297 added 1 commit 2026-10-25 19:14:46 +00:00
fix(dev-setup): install the restore trap first and fail clearly on a global hooksPath
Molecule / molecule (pull_request) Skipped
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 6s
74a5a0739b
Install the EXIT/INT/TERM traps before core.hooksPath is lifted, make the
restore idempotent, and save and restore every local value of a
multi-valued setting in order. When a global or system value still applies
after the local one is lifted, print the script's own message and exit 1
before pre-commit runs. Note that readlink -f/-m are GNU.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Defame1297 added 1 commit 2026-10-25 19:52:35 +00:00
fix(dev-setup): quote the hook path, read core.hooksPath NUL-safely and lift an empty value
Molecule / molecule (pull_request) Skipped
Build / build (pull_request) Successful in 8s
Lint / lint (pull_request) Successful in 7s
72e9813394
The repository path is shell-quoted (printf %q) where it is written into the
installed hooks, so a path with spaces, quotes or $(...) is data. The local
core.hooksPath values are read with -z and compared and restored element by
element, so a value with a newline survives; the loop avoids mapfile. Any local
value, including an empty or trailing empty one, is lifted for the install and
restored. tests/scripts/test_dev_setup.py covers it with stub tools in throwaway
repositories, and lint.yml now runs tests/scripts.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Defame1297 added 1 commit 2026-10-25 20:22:56 +00:00
merge: bring main into fix/dev-setup-robustness and keep one script-test step
Molecule / molecule (pull_request) Skipped
Build / build (pull_request) Successful in 13s
Lint / lint (pull_request) Successful in 10s
9dfec118a2
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Defame1297 added 1 commit 2026-10-25 20:34:55 +00:00
Merge branch 'main' into fix/dev-setup-robustness
Molecule / molecule (pull_request) Skipped
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 9s
76da009d12
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-10-25 20:35:05 +00:00
Defame1297 merged commit 7d5fd73ce1 into main 2026-10-25 20:38:05 +00:00
Defame1297 deleted branch fix/dev-setup-robustness 2026-10-25 20:38:05 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#15