Repository navigation
fix(workspace): preserve the consumer .pre-commit-config.yaml on upgrade - #895
Merged
Merged
Conversation
The scaffold upgrade replaced .pre-commit-config.yaml wholesale, silently dropping the repo-specific global exclude: block and per-hook exclude: keys (field-validated on hyrr: the hook suite rewrote ~45 data files it must never touch and detect-private-key false-flagged PEM marker literals). The consumer owns the file, like justfile.project (#877): it joins PRESERVE_FILES, the upgrade prints a diff against the incoming template so hook-stack evolution stays visible, and a prek validate-config gate warns (non-fatally) when the preserved config would break every commit in the new image. Refs: #878
11 of 13 tasks
c-vigo
added a commit
that referenced
this pull request
Jul 7, 2026
…erence scan (#896) ## Description Closes #881. **Stacked on #895** (branched from `bugfix/878-preserve-precommit-config`; this PR shows only its own commits once #895 merges). Field evidence (EXOPET/vault, 0.3.5 → 0.4.0): the 0.4.0 image ships `prek` only (#778), but consumer files preserved on upgrade still invoke `pre-commit` and exit 127 — the preserved `justfile.project` `precommit:` recipe and the repo-managed `.githooks/{pre-commit,commit-msg,prepare-commit-msg}` hooks broke every commit in-image. Even a repaired justfile cannot save a consumer whose own hook scripts call the removed tool, so the fix has an image half and an upgrade half. ## Type of Change - [x] `fix` -- Bug fix ### Modifiers - [ ] Breaking change (`!`) -- This change breaks backward compatibility ## Changes Made **(a) Image compat shim, one release cycle** (`flake.nix`, `imageTools`): - A `writeShellScriptBin "pre-commit"` shim that prints a one-line deprecation notice to **stderr** (stdout stays clean for pipelines) and `exec`s `${prek}/bin/prek "$@"` — prek is drop-in for `run`-style invocations. Marked `DEPRECATED — remove in 0.5 (#881)`. Image-only (`imageTools`, not `devTools`), so the dev-shell, home modules, and the parity gate are untouched. **(b) Upgrade-time scan** (`assets/init-workspace.sh`, alongside the #877/#878 guards): - After the scaffold, `init-workspace --force` scans the post-scaffold `justfile.project`, all `.githooks/` files, and `.pre-commit-config.yaml` for invocation-shaped `pre-commit` references and warns **non-fatally** with `file:line`, pointing at `prek`, the shim's one-cycle lifespan, and the MIGRATION.md checklist. - False-positive handling: the pattern only matches `pre-commit` framed as a command word (start/whitespace/shell punctuation on both sides), so the `.pre-commit-config.yaml` filename (leading `.`), `pre-commit/pre-commit-hooks` repo URLs (leading `/`), `pre-commit.com` links (trailing `.`), and `prek` never trip it; comment lines and YAML stage-name list items (`- pre-commit`) are filtered. Scanning post-scaffold state means fresh scaffolds and rsync-refreshed template hooks (which call `prek`) are silent by construction. **Docs**: MIGRATION.md upgrade-checklist step 3 rewritten — full rename surface (justfile recipes, repo-owned `.githooks` beyond the shipped three, hook `entry:` lines, CI configs), the shim's 0.4.x-only lifespan, and the NixOS `#!/bin/bash` → `#!/usr/bin/env bash` shebang gotcha in old-scaffold hooks. ## Changelog Entry ### Fixed - **`pre-commit` binary dropped without a compat path — preserved consumer recipes and `.githooks` calling it break** ([#881](#881)) - The 0.4.0 image retired the Python `pre-commit` for `prek` ([#778](#778)), but files preserved on upgrade still invoke it and exit 127 (field-validated on a 0.3.5 → 0.4.0 consumer: the preserved `justfile.project` `precommit` recipe and repo-managed `.githooks` scripts broke every commit). The image now ships a **deprecated one-cycle `pre-commit → prek` shim** (stderr notice, removed in 0.5) so consumer hook scripts keep working while they migrate. - `init-workspace --force` scans the post-scaffold `justfile.project`, `.githooks/` scripts and `.pre-commit-config.yaml` for invocation-shaped `pre-commit` references and warns (non-fatally) with `file:line`, pointing at the MIGRATION.md rename checklist — which now also covers the NixOS `#!/bin/bash` shebang gotcha in old-scaffold `.githooks`. ## Testing - [x] Tests pass locally (`just test`) - [x] Manual testing performed (describe below) TDD, both halves RED-committed first: - bats: `upgrade warns file:line when preserved files still invoke pre-commit (#881)` RED (`not ok`) → GREEN; plus stock-scaffold and false-positive no-hit guards. Full `init-workspace.bats` suite: **75/75 ok**. - image: `test_pre_commit_compat_shim` RED against the pre-shim locally built image (`exit 127: pre-commit: command not found` — the exact field failure) → GREEN after rebuild. `TestDevelopmentTools`: **24 passed**. ### Manual Testing Details ``` $ podman run --rm ghcr.io/vig-os/devcontainer:dev bash -lc 'pre-commit --version' pre-commit: deprecated compat shim, dispatching to prek — rename your invocation; the shim is removed in 0.5 (#881) prek 0.3.11 ``` Full hook suite: `just precommit` exit 0, 52 hooks passed, 0 failed. ## 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 (edit `docs/templates/`, then run `just docs`) - [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and pasted the entry above) - [x] My changes generate no new warnings or errors - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published (**stacked on #895**, review in progress) ## Additional Notes - The shim is deliberately a bridge, not a supported path: the deprecation notice is the consumer-visible removal deadline (0.5), cross-referenced in the flake comment and MIGRATION.md. - `test_pre_commit_installed` no longer asserts `pre-commit` absence (superseded by the shim test for this one cycle); re-add the absence assertion when the shim is removed in 0.5. Refs: #881
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
Closes #878
The scaffold upgrade (
init-workspace.sh --force) replaced the consumer's.pre-commit-config.yamlwholesale — it was not inPRESERVE_FILES— silently dropping repo-specific configuration: the globalexclude:block (hyrr: physics data tables, generated schemas, jupytext pairs — post-upgrade the hook suite "fixed" ~45 files it must never touch) and per-hookexclude:keys (hyrr: thedetect-private-keyexclusion for a file carrying PEM marker literals → false positive).Design decision
Chosen: preserve-with-managed-warning, the first option listed on the issue and the one consistent with the #877 precedent (#891): the consumer owns the file.
.pre-commit-config.yamljoinsPRESERVE_FILES, and the upgrade adds two non-fatal guards:prek validate-config(prek ships indevTools, so it is on PATH in the image and the dev-shell); a config the runner cannot load breaks every commit in the new image, so the installer warns loudly, pointing at the exact command. Same philosophy as the fix(workspace): scaffold upgrade strands base recipes — justfile.project is preserved but now owns sync/precommit/test, breaking the shipped ci.yml #877just --listparse gate: probe with the real tool, warn, never fail the scaffold.No
.bak-upgradebackup file is needed: under preserve, the consumer's data is never touched, and the diff output carries the template side.Why not replace-but-carry-over (rewrite from template, re-apply consumer
exclude:/files:keys):pythonEnvis python3.14 + vig-utils (rich) + pip-licenses — no PyYAML;devToolscarries noyq. A structured merge would need a new image dependency for one upgrade step, and a regex/awk-based merge would risk corrupting exactly the file it must protect (block scalars, nested hook maps).exclude:/files:keys would drop those just as silently as today's wholesale replacement.justfile.projectprecedent (fix(workspace): scaffold upgrade strands base recipes — justfile.project is preserved but now owns sync/precommit/test, breaking the shipped ci.yml #877/fix(workspace): repair preserved justfile.project with missing base recipes on upgrade #891) deliberately made these team-owned, customizable files; the hook config is the same class — the issue exists precisely because repos must customize it.Implications for #881 and template-driven hook evolution
A pure preserve means hook-stack evolution (runner migrations, compat fixes like
default_language_version: python3.14#803 ortypos --force-exclude#859, new hooks) no longer arrives automatically — a consumer upgrading from a pre-prek scaffold keeps a pre-prek-era config. This PR mitigates that with the always-printed template diff plus the MIGRATION.md step, and the design keeps the #881 path open rather than harder: the new post-scaffold guard block is the natural hook point for future surgical repairs on the preserved file (#877-style), e.g. an upgrade-time scan/rewrite of retiredpre-commitinvocations in preserved files, or a targeted key repair once a YAML-capable tool is in the toolchain. Config-side, prek is a drop-in reader of.pre-commit-config.yaml, so preserved configs keep loading; thepre-commitbinary references that #881 covers live injustfile.project/.githooks, which were already preserved before this PR — #881's scope is unchanged.Changes Made
assets/init-workspace.sh:.pre-commit-config.yamladded toPRESERVE_FILES(with the fix(workspace): scaffold upgrade replaces .pre-commit-config.yaml, silently clobbering repo-specific hook config #878 rationale comment, mirroring the neighboring entries).PRECOMMIT_CONFIG_PREEXISTEDrecorded pre-scaffold (same pattern asJUSTFILE_PROJECT_PREEXISTED).prek validate-configrejects the preserved file; silent for stock consumers;prekabsence is tolerated.tests/bats/init-workspace.bats: four new end-to-end tests (customizations survive verbatim; diff hint printed with template content visible; no hint when the file matches the template; invalid preserved config warns and stays preserved). TDD: RED committed first, then GREEN.docs/MIGRATION.md: new step 2 in the 0.3.x upgrade checklist describing the preservation, the diff review, and theprek validate-configcheck.CHANGELOG.md(+ hook-synced.devcontainermirror): Unreleased/Fixed entry.Type of Change
fix-- Bug fixModifiers
!)Changelog Entry
Fixed
.pre-commit-config.yaml, silently clobbering repo-specific hook config (#878).pre-commit-config.yamlwholesale, dropping the repo-specific globalexclude:block and per-hookexclude:keys — the hook suite then rewrote data files it must never touch and false-flagged PEM marker literals. The file is now preserved on upgrade (likejustfile.project, #877).init-workspace --forceprints a diff of the preserved file against the incoming template so consumers can fold changes in deliberately, and warns (non-fatally) when the preserved config does not parse underprek validate-config— a config the runner cannot load breaks every commit in the new image.Testing
bats tests/bats/init-workspace.bats(72 ok), full hook suite green (just precommit)Manual Testing Details
Ran
init-workspace.sh --forceagainst a temp workspace carrying a hyrr-shaped.pre-commit-config.yaml(globalexclude: ^data/stopping/|\.dat$+detect-private-keyper-hook exclude): the consumer file survived verbatim, the installer printed the "yours was kept" banner with the full unified diff against the template, and the scaffold completed successfully. A second run on a stock (template-identical) workspace printed no warning.Checklist
CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)