Repository navigation
feat(workspace): reconcile a preserved pre-commit config on upgrade - #1665
Merged
Merged
Conversation
Failing tests for the two divergences a preserved .pre-commit-config.yaml cannot heal on its own: a retired block that breaks (the pre-#1170 pymarkdown hook) and a hook the consumer never received (actionlint, #1660). Case 1 pins the byte-exact gate from both sides -- the historical block folds, while a consumer-customized exclude and a Renovate-bumped rev fall through to the #1652 warning untouched. Case 2 pins the PREVIOUS_PIN version gate, the DEVKIT_FEATURES_DISABLED opt-out, the already-present/no-pin/no-anchor refusals, the template position and the opt-out sentinels the inserted block must carry. Also pins the preview contract (report the rewrite, suppress the hand-fold notice for a block the run repairs) and the devkit-upgrade.yml channel that carries the report into the adoption PR. Refs: #1654
The reconciliation writes through a temp file; renaming it over the target (what sed -i does) hands the consumer mktemp's 0600 and silently de-group-reads a tracked file. Refs: #1654
A preserved .pre-commit-config.yaml (#878) protects the consumer's customizations and blocks template evolution with them. #1652 made the two resulting divergences visible; this repairs them, with a separate evidence gate per case and nothing else in the file touched. Fold: a block the template retired BECAUSE it breaks is replaced by the current template's hook for the same id, gated on a byte-identical match against the historical template text -- the only proof that the bytes being overwritten are devkit's own output. An extended exclude: or a Renovate-bumped rev: declines the fold and keeps the #1652 warning. First row: the pre-#1170 jackdewinter/pymarkdown block, which breaks the devkit-upgrade commit step itself, so those repos never reach a PR where the warning could be read. Insert: a hook an older tree never received lands at its template position, gated the way retired_paths gates a prune (#1348) -- only when PREVIOUS_PIN predates the release that first shipped it, so the consumer never had the chance to decline. It fires at most once per repo, which keeps a later hand-deletion durable (#1651), and DEVKIT_FEATURES_DISABLED is honoured first. First row: actionlint (#1660). Both read the block from the RENDERED template, preferring the sentinel range so an inserted block stays excisable by its feature opt-out; both report on the machine channel #1652 opened, which devkit-upgrade.yml lifts into the step summary and its own adoption-PR section; and --preview reports the planned rewrite instead of telling the consumer to hand-fold what the run repairs. Refs: #1654
Both branches appended a render function to the same region of assets/init-workspace.sh, so the conflict was adjacency, not semantics: reconcile_preserved_hooks and render_release_optout are independent and both are kept whole, with their call sites intact. Refs: #1654
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.
What
One reconciliation pass over a preserved
.pre-commit-config.yaml, run as apost-copy render in
assets/init-workspace.sh. Two cases, two evidence gates,one report channel.
Case 1 — fold a retired block. A block the template retired because it
breaks is replaced by the current template's hook for the same id, gated on a
byte-identical match against the historical template text. First row: the
pre-#1170
jackdewinter/pymarkdownblock, whoselanguage: pythonvenv skewsagainst the flake interpreter and fails the
devkit-upgrade.ymlcommit stepitself — so those repos never reach a PR where #1652's warning could be read.
Case 2 — insert a hook the consumer never received. A hook an older tree
never got lands at its template position, gated on
PREVIOUS_PINpredating therelease that first shipped it (the mirror of
retired_prune_paths(), #1348) andon
DEVKIT_FEATURES_DISABLED. First row:actionlint(#1660).Everything else in the consumer's file is untouched: global and per-hook
exclude:patterns, ordering, comments, and the file's own mode.Field evidence
Run against the real consumer configs on the maintainer's machine — this is what
settled the strictness question:
exclude:extended with vendored-doc pathsFolding the third would have deleted the consumer's exception list. That is the
whole reason the gate is a byte-match and not a
repo:-line match.The resulting hunk on a real config (fold + insert in one upgrade):
The six open questions
Full rationale in the
## Designcomment on #1654; the decisions:1. Opt-in knob, or default-on for byte-exact matches only? — Default-on, no
new knob, both cases. Case 1's byte-match is the gate, and a knob would have
to be set by the repos that cannot run the upgrade far enough to read the notice.
Case 2's durable opt-out already exists (
DEVKIT_FEATURES_DISABLED, #1660);a second knob would split the opt-out surface.
2.
init-workspace.shordevkit-upgrade.yml? —init-workspace.sh, as asixth member of the render family that already
seds this preserved file(#1642, #1282/#1633, #1431, #1432, #1660). Decisive:
devkit-upgrade.ymlcommitsin the project shell with the hooks running, so the repair must be in the
tree before the commit step; and every other upgrade path funnels through the
same script. The workflow only lifts the report lines.
3. Case 2: is the version gate enough? — Yes, because the ambiguity the
issue names cannot actually arise and the gate is paired with a one-shot
property. A repo pinned before the introducing release cannot have deleted a
hook devkit never shipped it, so "skipped several versions" is exactly the "never
had it" case. The insert fires at most once — the same run advances the pin
past that release — so a later hand-deletion is permanent (#1651 holds). The one
residual shape (hand-added then removed, still pinned low) is covered by
DEVKIT_FEATURES_DISABLED. No--adopt-hooksflag: the population furthestbehind is the automated lane, which runs no flags. Five gates in all: semver-shaped
pin present → pin predates the release → feature group not disabled → hook absent
from the file → template ships the block and the anchor is locatable.
4. Where does the block come from? — The rendered template, never
re-derived, through one extractor (
hook_block_range) used for both cases andboth files. It prefers the
# >>> devkit:<id>/# <<< devkit:<id>range #1660introduced and falls back to the structural
- repo:entry when a block carriesno sentinels. Preferring the sentinels is load-bearing beyond exactness: an
inserted
actionlintblock without them would be invisible torender_actionlint_optout, silently outliving the opt-out. The pass is the first.pre-commit-config.yamltouch of the upgrade, so the knob renders below applyto whatever it writes.
5. Insert position? — Defined position, never append. After the end of the
repo entry holding the block's template predecessor hook, derived from the
template (so a template reorder moves it), because hook order is observable for
formatter hooks that rewrite files. No anchor in the consumer's file ⇒ skip with
a notice, not a guess; the #878 diff stays the fallback.
6. One pass or two PRs? — One pass, one PR, two gates, two markers. They
share the extractor, the write path, the report channel and the tests. What stays
separate is the reporting, because the two ask for different actions:
devkit-upgrade.ymlcarries them under "the upgrade rewrote your preservedconfig — review the hunk", distinct from the existing
preserved-hook-drift:section ("the upgrade could not deliver this").
Two calls beyond the six
--previewhonesty. The pass has a plan mode: the preview reports theplanned fold/insert (like the
DEVKIT_LICENSEand trunk sections already do)and suppresses the
preserved-hook-drift:line for a block the runrepairs — otherwise the preview would tell the consumer to hand-fold something
the upgrade fixes for them.
instead of renaming a temp file onto it; a rename would hand the consumer
mktemp's0600. Caught by its own failing test before the fix.Table seeds and their limits
deliberately unlisted (no consumer is pinned that far back); they fall through
to the Upgrade can't fold hook fixes into a preserved .pre-commit-config.yaml — warn on the pre-#1170 jackdewinter/pymarkdown block #1652 warning, which is the safe direction.
1.16.0 actionlint actionlint. [FEATURE] Ship actionlint to consumers: the workflow-lint hook plus a managed actionlint.yaml config #1660 sits unreleased in## Unreleasedand is a
feat, so the next minor is where it ships. If the train renumbers,this row moves with it — a too-high number only under-inserts, and the
"hook already present" gate makes a wrong-direction miss a no-op.
Verification
test_image/test_integrationare excluded locally (lagging local:devimage, not this branch) and left to CI.
The bats
actionlintgate caught a real SC2016 on the new PR-bodyprintf(backticks as Markdown code spans) that
just precommitdoes not see — fixedwith the same
# shellcheck disablethe sibling line carries.Tests
tests/test_scaffold_preserved_hooks.py(new, 21 cases) drives the realinit-workspace.shagainst seeded consumer trees: the fold fires on the exactblock and declines on a customized
exclude:and a Renovate-bumpedrev:; theinsert honours the version gate, the feature opt-out, an already-present hook, a
missing pin and a missing anchor; the block lands at its template position and
keeps its sentinels; the preview reports and writes nothing; a stock upgrade
reconciles nothing. Plus two workflow-shape cases in
tests/test_workflow_devkit_upgrade.py.Out of scope
.vig-osknob (Q1/Q3 above).drift id this pass repairs.
Refs: #1654