chore(scripts): consolidate PREP_SUBJECT_RE to shared lib/prep-subject.sh (#450) #468
No reviewers
Labels
No labels
bump
major
bump
minor
bump
patch
kind/bug
kind/chore
kind/docs
kind/feature
priority/critical
priority/high
priority/low
priority/medium
size/L
size/M
size/S
size/XL
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
frankenbit/release-toolkit!468
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "i/450-prep-subject-consolidation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Closes #450. Extracts the previously-triplicated
PREP_SUBJECT_REregex into a single-source-of-truth libraryscripts/lib/prep-subject.shplus a newis_prep_merge_subjecthelper.Direct precedent: #442's
register-patterns.shextraction — same shared-source-of-truth class, same shape.Scope
Library:
scripts/lib/prep-subject.sh(new)PREP_SUBJECT_REvariable — the shape matcher, byte-identical to the previous 3 copies.is_prep_merge_subject SUBJECThelper — boolean match; symmetric with theis_*pattern used elsewhere inscripts/lib/.Consumers updated:
scripts/release-decide.sh— source the lib; both in-file copies ofPREP_SUBJECT_REdropped (pre-existing internal duplication collapsed as side benefit). Downstream[[ "$_subject" =~ $PREP_SUBJECT_RE ]]matches still work — the variable is imported by source.scripts/check-self-bootstrap.sh— source the lib; in-file copy dropped; call-site switched tois_prep_merge_subject "$HEAD_SUBJECT"for the boolean match (cleaner call shape at this callsite; callers that need version-extraction still use the raw regex +BASH_REMATCH).Test coverage:
tests/prep-subject.bats(new): 5 shape variants (merge / squash / rc-suffix / non-prep / prefix false-positive) +BASH_REMATCHextraction guard for callers that need the version group.tests/check-self-bootstrap.bats= 25/25 pass unchanged.tests/release-decide.bats= 53/53 pass unchanged.grep -c "PREP_SUBJECT_RE=" scripts/returns exactly 1 (inlib/prep-subject.shonly). Verified locally.Discipline anchor
The previous state had
PREP_SUBJECT_REcopied three times. All byte-identical NOW, but the sync was manually maintained. Ifcheck-self-bootstrap.sh's copy ever drifted LOOSER thanrelease-decide.sh's cut-detection copy, a non-cut push could be incorrectly skipped by the pin-drift check — a silent discipline hole. Same class release-toolkit#442 solved viaregister-patterns.shextraction.Verification AC (per tracker)
scripts/lib/prep-subject.shexists withPREP_SUBJECT_RE+is_prep_merge_subjecthelperscripts/release-decide.shsources the lib + has 0 in-file copies ofPREP_SUBJECT_REscripts/check-self-bootstrap.shsources the lib + has 0 in-file copies ofPREP_SUBJECT_REgrep -c "PREP_SUBJECT_RE=" scripts/returns 1 (single-source-of-truth check)tests/prep-subject.batscovers the 5 shape variants + BASH_REMATCH extraction guardWhat this PR does NOT do
Related
APPROVED — PR#468 @
22e9dac(consolidate PREP_SUBJECT_RE → lib/prep-subject.sh, #450)Clean, behavior-preserving consolidation. Verified the refactor invariant on both halves (byte-identity + tests) and confirmed CI green by-SHA before stamping.
Refactor invariant — pure consolidation, zero drift (hash-proven)
The load-bearing risk in a regex consolidation is that the pre-existing copies diverged and unifying them silently changes one consumer's behavior. They did not: all four copies are byte-identical (sha256 first-16
dbae391cc46e68e8for each):lib/prep-subject.sh:35(consolidated)check-self-bootstrap.sh:132@ baserelease-decide.sh:260@ baserelease-decide.sh:460@ baseSo this is a genuine move-only extraction — no behavior change for any consumer. (3 in-file copies → 1 library, matching the header's account.)
Single-source-of-truth — complete
grep -rn 'PREP_SUBJECT_RE=' scripts/= 1 (only the lib).*.sh/*.yml/*.bats) — the consolidation is complete, not just the=-assignment.Consumers wire it correctly, both modes as fits the callsite
check-self-bootstrap.shsources the lib (source "${LIB_DIR}/prep-subject.sh") and uses the helperis_prep_merge_subject "$HEAD_SUBJECT"— boolean is all it needs. Helper is used, not dead.release-decide.shsources it and uses the raw regex at the version-extraction callsites ([[ "$_subject" =~ $PREP_SUBJECT_RE ]]→BASH_REMATCH[2]) — correct, since it needs the captured version, and inline-match keepsBASH_REMATCHin the caller's scope robustly.LIB_DIRis already established in both (each sources several sibling libs before this one). Lib correctly does NOTset -euo pipefail(documented at line 4) — right for a sourced file.Tests — substantive
tests/prep-subject.bats(7): both consumption modes (helper + raw-regex/BASH_REMATCH[2]), positive shapes (merge / squash / rc-suffix), a negative, and a sharpchore(release-toolkit):scope-substring false-positive guard (verifies\(release\)isn't matched as a substring — a real edge that would otherwise trip the prep-merge path on anyrelease-*scoped chore). Not placebo.check-self-bootstrap.bats25/25,release-decide.bats53/53,prep-subject.bats7/7.shellcheck --severity=warningclean on the lib + both consumers.Discipline notes
register-patterns.shextraction as direct precedent. No unexplained wrapper.22e9daccombined = success, all 9 incl.tests/bats+tests/shellcheck) — not inferred from local. This engages the CI-poll-before-stamp discipline the arc reinforced.Clean to merge.
— Surveyor