Repository navigation
refactor(template): replace prek-autoupdate.sh with declarative update filters - #336
Merged
Merged
Conversation
Owner
Author
|
This change is part of the following stack: Change managed by git-spice. |
ApprovabilityVerdict: Needs human review 2 blocking correctness issues found. This template refactor adds a migration that deletes files from user projects during You can customize Macroscope's approvability policy. Learn more. |
…e filters prek 0.4.10 added project-level and per-repository tag filters to the `update` config (j178/prek#2354), which makes the shipped scripts/prek-autoupdate.sh wrapper redundant. The wrapper only ever protected the invocation that went through it. Verified against prek 0.4.11 in a throwaway repo: a bare `prek update` still rewrites lychee-v0.24.0 to `nightly` today, and lychee's own hook then rejects that mutable rev. Habitual `prek update`, CI, an editor integration or an agent all bypassed the script. Declaring the exclusion in prek.toml makes it unconditional: [update.repos."https://github.com/lycheeverse/lychee"] exclude_tags = ["nightly"] With the guard the same update resolves lychee-v0.24.2, and the block survives prek rewriting the config file during the update. minimum_prek_version rises to 0.4.10, and it is the load-bearing half. prek.toml is regenerated in full by migrations/sync_marked_sections.py (only extra-local-hooks is preserved), so it reaches projects updating from an older template. The pyproject `prek>=` floor does not: [dependency-groups] sits inside a template-preserve region, so an updating project keeps its own prek>=0.3.11. A too-old prek would ignore the [update] block entirely and silently reintroduce the bug, so the config fails loudly instead -- the same shape as the ruff required-version guard. copier update never deletes files, so a _migrations entry removes the orphaned script from existing projects. It refuses to delete a customised one: a project that edited the script had a reason to, and discarding that silently is worse than leaving an unreferenced file. Migrations now carry a T201 per-file-ignore. They run as bare python3 in the destination project, where the repo's logging setup does not exist and stdout is the only channel to the user; a migration that mutates files silently is worse than one that prints. Tests assert the config and the minimum_prek_version premise it depends on, replacing the assertions on the deleted script. The slow integration test now runs a bare `prek update` on a rendered project and asserts the resulting rev is still a versioned tag, so the outcome is covered and not just the configuration. DOT-504 stays open: lycheeverse/lychee#1601 is still unfixed as of 2026-07-29. Only the remediation got smaller. Closes DOT-616
ichoosetoaccept
force-pushed
the
prek-declarative-update
branch
from
July 29, 2026 08:32
4a007b7 to
2affc71
Compare
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.
Summary
Deletes
scripts/prek-autoupdate.shand replaces it with a declarative[update.repos]tag filter inprek.toml, available since prek 0.4.10.Why
lychee tags
nightlyas their GitHub "Latest" release, soprek updateresolves it as the newest tag and rewrites the pinned rev to a mutable one that lychee's own hook then rejects (lycheeverse/lychee#1601). The template shipped a wrapper script passing--repo-exclude-tagto work around it.The wrapper only protected the invocation that went through it. Verified against prek 0.4.11 in a throwaway repo:
prek updateresultlychee-v0.24.0→nightly[update.repos."…/lychee"] exclude_tags = ["nightly"]lychee-v0.24.0→lychee-v0.24.2A bare
prek updatestill flips the rev today. Habitualprek update, CI, an editor integration or an agent all bypassed the script. Moving the exclusion into the config makes it unconditional. The block also survives prek rewriting the file during the update.minimum_prek_versionis the load-bearing halfprek.tomlis regenerated in full bymigrations/sync_marked_sections.py(onlyextra-local-hooksis preserved), sominimum_prek_version = "0.4.10"reaches projects updating from an older template.The pyproject floor does not:
[dependency-groups]sits inside atemplate-preserveregion, so an updating project keeps its ownprek>=0.3.11. A too-old prek would ignore the[update]block entirely and silently reintroduce the bug. The config constraint fails loudly instead:Structurally the same guard as the ruff
required-versionadded in #333, for the same reason.Migration
copier updatenever deletes files, so a_migrationsentry removes the orphaned script from existing projects.It refuses to delete a script the user edited. The guard is an exact SHA-256 against every version the template shipped, not a substring match — a #336 review finding, and correct in both directions:
--cooldown-days 7second pass and contains no--repo-exclude-tagat all, so a marker-based guard flags every project generated before 0.40.0 as "customised" and leaves a pristine file behind with a warning.Hashing is exact here rather than approximate because the script carries no
.jinjasuffix — copier copies it verbatim, so the bytes are identical in every generated project. Line endings are normalised first so a Windows checkout withcore.autocrlf=truedoes not read as a customisation.Migration command quoting
Both
_migrationscommands now quote the interpolated script path.copier/_main.py:405setsshell=Truefor string-form commands and_copier_conf.src_pathis whatever the user passed tocopier copy, so an unquoted path containing a space splits into two arguments. The pre-existing 0.41.0 migration had the same latent bug and is fixed alongside.migrations/**T201 exemptionMigrations run as bare
python3in the destination project, where the repo's logging setup does not exist and stdout is the only channel to the user. A migration that mutates files silently is worse than one that prints. Same category as the existingextensions.pyexemption.Test plan
minimum_prek_versionenforcement confirmed to produce an actionable error naming both the required and installed versions.test_lychee_nightly_excluded_declarativelyreplacestest_prek_autoupdate_script_has_lychee_workaround, asserting the config and theminimum_prek_versionpremise it depends on.prek updateon a rendered project and asserts the resulting rev is still a versioned tag — the outcome, not just the configuration.186 passed.ruff check,ruff format --checkandty checkclean.Not closed by this
DOT-504 tracks removing the workaround once lycheeverse/lychee#1601 is fixed upstream. Re-confirmed still unfixed on 2026-07-29 — only the remediation got smaller.
Closes DOT-616