Skip to content

fix(image): one-cycle pre-commit->prek compat shim + upgrade-time reference scan - #896

Merged
c-vigo merged 7 commits into
devfrom
bugfix/881-precommit-compat-path
Jul 7, 2026
Merged

c-vigo merged 7 commits into
devfrom
bugfix/881-precommit-compat-path

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

  • 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 execs ${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)
    • The 0.4.0 image retired the Python pre-commit for prek (#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

  • Tests pass locally (just test)
  • 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 (vig-os/devcontainer#881)
prek 0.3.11

Full hook suite: just precommit exit 0, 52 hooks passed, 0 failed.

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 (stacked on fix(workspace): preserve the consumer .pre-commit-config.yaml on upgrade #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

c-vigo added 7 commits July 7, 2026 14:02
…g.yaml

RED for #878: upgrading a workspace whose .pre-commit-config.yaml carries a
global exclude block and a per-hook exclude must keep the consumer file
verbatim, print a diff hint against the template, and warn (non-fatally)
when the preserved config does not validate under prek.

Refs: #878
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
RED for #881: the image must answer 'pre-commit --version' via a prek
compat shim with a stderr deprecation notice, and init-workspace --force
must warn file:line when preserved files (justfile.project, .githooks/,
.pre-commit-config.yaml) still invoke the retired pre-commit binary,
without false positives on the config filename, pre-commit-hooks repo
URLs, YAML stage names, comments, or prek itself.

Refs: #881
…iles on upgrade

The 0.4.0 image retired the Python pre-commit for prek (#778), but
consumer files preserved on upgrade still invoke it and exit 127:
field-validated on EXOPET/vault, where the preserved justfile.project
precommit recipe and repo-managed .githooks scripts broke every commit.

Image side: a writeShellScriptBin pre-commit shim in imageTools
dispatches to prek (drop-in for run-style invocations) with a one-line
stderr deprecation notice; DEPRECATED, removed in 0.5.

Upgrade side: init-workspace --force scans the post-scaffold
justfile.project, .githooks/ scripts and .pre-commit-config.yaml for
invocation-shaped pre-commit references and warns with file:line,
non-fatally, pointing at MIGRATION.md. The command-word pattern plus
comment/stage-name filters keep the config filename, pre-commit-hooks
repo URLs, pre-commit.com links, YAML stage names and prek from
tripping it.

Refs: #881
…ebang gotcha

MIGRATION.md step 3 now covers the full rename surface (justfile
recipes, repo-owned .githooks scripts, hook entries, CI configs), the
one-cycle lifespan of the image shim (removed in 0.5) and the NixOS
/bin/bash shebang gotcha in old-scaffold .githooks; CHANGELOG Unreleased
Fixed entry added (mirror synced).

Refs: #881
@c-vigo
c-vigo merged commit 6d559ae into dev Jul 7, 2026
15 checks passed
@c-vigo
c-vigo deleted the bugfix/881-precommit-compat-path branch July 7, 2026 12:35
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