Repository navigation
feat: add per-clone site configuration and initializer hook - #1938
Merged
Merged
Conversation
gerchowl
force-pushed
the
feature/1930-site-init-hook
branch
from
October 27, 2026 09:11
f4ec6ab to
db645a9
Compare
gerchowl
force-pushed
the
feature/1930-site-init-hook
branch
from
October 27, 2026 11:01
db645a9 to
de44133
Compare
14 of 22 tasks
gerchowl
force-pushed
the
feature/1930-site-init-hook
branch
from
October 29, 2026 01:14
de44133 to
3013943
Compare
gerchowl
added a commit
that referenced
this pull request
Oct 29, 2026
## Description Add the ADR §10 default-on site leak-check hook. A clone without private patterns exits silently; configured clones scan staged changes or selected working-tree files through gitleaks and publish only file, line and rule ID. ## Type of Change - [x] `feat` -- New feature - [x] `fix` -- Bug fix - [ ] `docs` -- Documentation only - [ ] `chore` -- Maintenance task - [ ] `refactor` -- Code restructuring - [x] `test` -- Adding or updating tests - [ ] `ci` -- CI/CD pipeline changes - [ ] `build` -- Build system or dependency changes - [ ] `revert` -- Reverts a previous commit - [ ] `style` -- Code style ### Modifiers - [ ] Breaking change (`!`) ## Changes Made - Resolve `DEVKIT_LEAK_PATTERNS` before `.site/leak-patterns.toml`. Use merged S4's public `vig_utils.site_config.validate_patterns` and preserve its safe error messages with exit 2. The S4 ADR amendment defines the single pattern-file contract; a missing selected file is a silent no-check without fallback. - Materialize raw blobs from the index for added, copied, modified, renamed and type-changed paths. Use Git's NUL-delimited metadata only for path selection, with no external diff or textconv; stream raw blobs through one `git cat-file --batch` process, avoiding checkout filters and per-blob process creation. Staged, filename and all-files modes then share one gitleaks directory scanner. - Cover full index content at changed paths, including pure renames; skip deleted and untouched paths. Filename mode skips NUL-containing inputs to enforce the text-hook contract, while direct staged and all-files scans include those bytes. - Scan selected site bindings and repository ignore files as data. Isolate gitleaks 8.30.1's automatic source-ignore loading by scanning a root `.gitleaksignore` separately; the private config remains explicit. - Define the default-on text/symlink hook once in `nix/hooks.nix` and mirror both portable configs. Pin gitleaks in Nix-generated hooks, and publish only file, line and rule ID. Document scan boundaries, printed paths, linked worktrees and intentional exceptions. - Pass `--` in every hook definition before filenames; reject help-looking CLI options and disable option abbreviation. Real installed-hook commits cover `-h`, `--help`, `--he` and `--all-files` filenames. - Own private snapshots in one cleanup routine on success, findings, errors and signals. Block SIGINT/SIGTERM/SIGHUP before deleting, restore the previous mask/handlers, and honour pending signals only after deletion with a conventional exit code and no traceback. Identify unreadable pattern files and report input read/materialization errors using only safe path metadata. - Scan symlink link text as regular snapshot content in staged, filename and all-files modes, without following targets. Select links through `types: []` plus `types_or: [text, symlink]`, clearing the hook runner's default file-only filter. Preserve raw link text, including repeated separators, and apply path rules to link names. ## Changelog Entry ### Added - **Site leak-check hook** ([#1932](#1932)) - Enable private gitleaks rules for staged and working-tree scans, with silent success when no site patterns exist and redacted finding diagnostics. - Prevent repository ignore/config bypasses, scan force-added site bindings, and reject present pattern files without usable rules. - Stream raw index snapshots, including type changes, through one Git batch reader despite Git attributes; share S4's safe pattern validation. - Block option-looking filename bypasses, clean private snapshots on termination, and report filesystem failures with paths and OS reasons without file contents. - Scan symlink link text without reading targets and finish snapshot cleanup despite repeated termination signals. ## Testing - [x] Targeted tests pass locally; the brief reserves full-suite execution for CI. - [x] Manual testing performed (describe below) ### Manual Testing Details - Round-six RED: `pytest tests/test_site_leak_check.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1932-r6 -q` inside the Nix environment with worktree `PYTHONPATH` first exited 1: 9 failed / 112 passed. Tests were committed before implementation. - GREEN inside `nix develop`: `PYTHONPATH="$PWD/packages/vig-utils/src" uv run --with pytest-xdist pytest tests/test_site_leak_check.py tests/test_hardcoded_endpoints.py packages/vig-utils/tests/test_site_config.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1932-r6 -q` exited 0: 379 passed. - Both regular-file ↔ symlink type changes are staged as Git status T and must flag the new raw index blob. A 256-file test verifies exact binary content and exactly one batch reader, preventing per-blob process regressions. - Cleanup tests pause deterministically after the scanner has exited and before deletion. They deliver SIGTERM followed 10 ms later by SIGHUP in staged and all-files modes, across clean, findings and scanner-error exits. Deletion must complete before a conventional signal exit; no private tree or traceback remains. - Cleanup mask mutation: querying the mask instead of blocking termination signals makes the strengthened test fail (exit 1). After restoring production code, all 6 cleanup cases passed (exit 0), explicitly asserting SIGINT/SIGTERM/SIGHUP are blocked inside deletion. - Earlier validator, symlink target-isolation, installed-hook option filename, attributes/textconv/smudge, redaction, ignore/config bypass, gitlink/stage/path guard, rename and NUL-boundary regressions remain covered. - Commits run inside `nix develop` with hooks enabled. Container and Nix evaluation suites are reserved for CI. ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation accordingly (tool README and migration guidance) - [x] I have updated `CHANGELOG.md` in the `Unreleased` section - [x] My changes generate no new warnings or errors - [x] I have added tests that prove my feature works - [x] New and existing targeted unit tests pass locally with my changes - [x] Any dependent changes have been merged and published (S4 #1938) ## Additional Notes Rebased onto S3 (#1949) and S4 (#1938). Conflict resolution preserved both S3 and S6 changelog entries in `CHANGELOG.md` and `assets/workspace/.devcontainer/CHANGELOG.md`, and preserved all S3/S4/S6 amendments in `docs/rfcs/ADR-site-agnostic-projects.md`. S6 consumes S4's public pattern validator; the S4 ADR amendment remains the single rule definition. Rule IDs and matching file paths must be safe for public logs. The snapshot scanner never follows symlink targets; independently selected regular files are scanned normally. Refs: #1932
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
check-site-configandsite-initfor per-worktree site bindings. Both commands resolve the git toplevel from any subdirectory and refuse outside git. Initialization discovers trusted external tools or writes an unbound template, validates staged files, then publishes them.Type of Change
feat-- New featurefix-- Bug fixdocs-- Documentation onlychore-- Maintenance task (deps, config, etc.)refactor-- Code restructuring (no behavior change)test-- Adding or updating testsci-- CI/CD pipeline changesbuild-- Build system or dependency changesrevert-- Reverts a previous commitstyle-- Code style (formatting, whitespace)Modifiers
!) -- This change breaks backward compatibilityChanges Made
just site-initrecipe while preservinghelpas the default; ignore.site/and.aws/in scaffolds..site/changes recursively and refuse symlinks/special files. Clean staging and newly created empty directories after failure; enforce--forcebefore publishing.validate_patterns(path: Path) -> Nonefor S6. Its self-contained pattern rule is recorded once in the ADR Amendments: case-insensitive keys without ambiguous variants, at least one usable id-plus-regex/path rule, no extend, missing files mean no check. Pattern values are never checked as site credentials or exposed in errors.Changelog Entry
Added
Testing
RED: final-round regression suite, 91 failed and 48 passed (exit 1); tests committed before fixes. Additional userinfo field-name regression: 1 failed and 4 passed (exit 1), also committed before its fix.
GREEN after rebase:
PYTHONPATH="$PWD/packages/vig-utils/src" uv run --with pytest-xdist pytest packages/vig-utils/tests/test_site_config.py -n 4 --basetemp="$HOME/.cache/devkit-pytest/1930": 139 passed (exit 0).Commit hooks run in
nix develop: formatting, lint, security, documentation and manifest checks passed. CI checks run on the pushed head.Tests pass locally (
just test)Manual testing performed (describe below)
Manual Testing Details
Checklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
Initializers are trusted external programs, not sandboxed processes. Recursive metadata checks detect changed entries but cannot prevent arbitrary writes or an initializer restoring metadata. This limit is documented in ADR §9. S6 coordination: #1950 (comment).
Refs: #1930