Skip to content

fix(init): match devkit sentinel ids exactly - #1729

Merged
c-vigo merged 3 commits into
devfrom
bugfix/1727-sentinel-exact-id-match
Sep 26, 2026
Merged

c-vigo merged 3 commits into
devfrom
bugfix/1727-sentinel-exact-id-match

Conversation

@c-vigo

@c-vigo c-vigo commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Description

hook_block_range located a hook's # >>> devkit:<id> / # <<< devkit:<id> sentinels with an awk index() prefix match, so a sentinel whose id extends another id answered the shorter id's lookup: a consumer-bracketed # >>> devkit:shellcheck-composite-actions block was returned for a lookup of shellcheck. Found in the #1725 review; nothing in the template trips it today, but it is exactly what the #1725 fallback anchor (which walks predecessors such as shellcheck) and the feature excisions would silently mis-target the day someone sentinel-wraps a hook whose id is a prefix extension of another.

The sentinel branch now regex-matches only the marker's whole-line shape, extracts the token after devkit: up to the first whitespace, and compares it to the requested id as a string — the id is never interpolated into a regex, so a metacharacter in a hook id cannot change what matches. The template's opening sentinels carry trailing prose (# >>> devkit:actionlint — excised when …), which is why the token stops at whitespace rather than requiring end-of-line.

Same hazard, same fix, in the two feature excisions: render_actionlint_optout and render_release_optout used unanchored grep/sed ranges on # >>> devkit:actionlint / # >>> devkit:release, so …:actionlint-extra or …:release-notes pairs would have been deleted too. Both are now anchored at line start and require whitespace or end-of-line after the id (-E alternation, again because of the trailing prose). The structural branch's sweep stops are left id-agnostic on purpose: any sentinel must stop the comment sweep.

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

assets/init-workspace.sh

  • hook_block_range: sentinel(line, dir) awk function (whole-line marker shape, token extracted, string equality against "# " dir " devkit:" id); docstring updated — the prefix hazard is gone, the feature-gating reason for keeping ungrouped hooks un-sentinelled stays
  • render_actionlint_optout, render_release_optout: grep -qE '^[[:space:]]*# >>> devkit:<id>([[:space:]]|$)' guard and the matching sed -i -E range

tests/test_scaffold_preserved_hooks.py

  • _shell_function(name) harness lifting one function's verbatim text out of the script into a bash -c run (the script is not sourceable)
  • Five tests, four RED before the fix: a prefix-extended sentinel does not answer the shorter lookup (direct hook_block_range); the extending id still resolves to its own sentinel range; the anchor walk ignores a prefix-extended sentinel (upgrade-driven, pin 1.15.1 ⇒ actionlint lands after shellcheck, not after the composite block); the actionlint excision takes only its own pair (decoy actionlint-extra pair survives under the opt-out); the release excision takes only its own pair (real render_release_optout against a fixture justfile.gh with a decoy release-notes pair)

Changelog Entry

No changelog needed — the issue says so; no template sentinel triggers the prefix match today, so consumer-visible behaviour is unchanged.

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

  • End-to-end --force --no-prompts --mode both with DEVKIT_FEATURES_DISABLED=actionlint on a config carrying the template's real actionlint block plus a decoy # >>> devkit:actionlint-extra pair: only the real block removed (19 lines), decoy intact; DEVKIT_FEATURES_DISABLED=release still drops every devkit:release sentinel and prepare-release: recipe from justfile.gh
  • uv run pytest tests/test_scaffold_preserved_hooks.py tests/test_flake_hooks.py -q → 115 passed
  • bats -j 4 --filter '1660|1651|preserved|hook|1717|1725|optout|opt-out|release' tests/bats/init-workspace.bats → 66 ok; the one failure is the known environmental one (the [FEATURE] Ship actionlint to consumers: the workflow-lint hook plus a managed actionlint.yaml config #1660 opt-out test shells out to a bare python3 without PyYAML in the plain nix develop shell; green in CI)
  • shellcheck -x clean; prek run --all-files → 55 hooks passed

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

The issue's suggested end-of-line anchor would have broken the live actionlint excision because the template's opening sentinel carries trailing prose; "followed by whitespace or end-of-line" is the reading that matches the template, and the tests pin it.

Refs: #1727

The structural branch still builds its `- id:` pattern from the id; say
so rather than overstate what #1727 changed.

Refs: #1727
@c-vigo
c-vigo merged commit fd28aa5 into dev Sep 26, 2026
15 checks passed
@c-vigo
c-vigo deleted the bugfix/1727-sentinel-exact-id-match branch September 26, 2026 08:56
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