Skip to content

feat: add per-clone site configuration and initializer hook - #1938

Merged
gerchowl merged 8 commits into
devfrom
feature/1930-site-init-hook
Oct 29, 2026
Merged

gerchowl merged 8 commits into
devfrom
feature/1930-site-init-hook

Conversation

@gerchowl

@gerchowl gerchowl commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add check-site-config and site-init for 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 feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

  • Add the managed just site-init recipe while preserving help as the default; ignore .site/ and .aws/ in scaffolds.
  • Validate schema v1, active-site lookup, credential restrictions and bound location forms. Reject whitespace/control characters, unsafe file URIs, invalid S3 bucket names and reserved site names; errors name fields without exposing values.
  • Anchor discovery, staging and lookup to the resolved git worktree root, including linked worktrees. Exclude relative and in-tree PATH directories and resolved executable targets.
  • Detect .site/ changes recursively and refuse symlinks/special files. Clean staging and newly created empty directories after failure; enforce --force before publishing.
  • Expose validate_patterns(path: Path) -> None for 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.
  • Record the ADR §8/§9 clarification: empty locations are valid unbound bindings with notices; consumers must refuse unbound bindings with actionable errors.

Changelog Entry

Added

  • Per-clone site bindings and initializer hook (#1930)
    • Validate site configuration and initialize bindings from PATH or an unbound template.
    • Discover only external initializers, validate supported location forms, and accept gitleaks pattern definitions separately from site bindings.
    • Anchor site operations to the git worktree, reject unsafe locations and reserved names, inspect recursive writes, and share self-contained pattern validation with the leak checker.

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

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

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

@gerchowl
gerchowl force-pushed the feature/1930-site-init-hook branch from f4ec6ab to db645a9 Compare October 27, 2026 09:11
@gerchowl
gerchowl force-pushed the feature/1930-site-init-hook branch from db645a9 to de44133 Compare October 27, 2026 11:01
@gerchowl gerchowl mentioned this pull request Oct 27, 2026
14 of 22 tasks
@gerchowl
gerchowl force-pushed the feature/1930-site-init-hook branch from de44133 to 3013943 Compare October 29, 2026 01:14
@gerchowl
gerchowl merged commit cd5df04 into dev Oct 29, 2026
16 checks passed
@gerchowl
gerchowl deleted the feature/1930-site-init-hook branch October 29, 2026 01:27
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant