Skip to content

refactor(guardrails): simplify the git-hooks entry scripts - #15151

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14470-42880169025-1
Nov 10, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14470-42880169025-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14470

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Behavior-preserving simplification of the guardrails git-hook scripts. pre-push-content.sh (commit_ranges) and reference-verify.sh (narrow_to_branch) now call check-lib.sh's existing checks_intersect_ranges in place of two inline copies of the same awk program. reference-verify.sh folds its duplicated worktree remove/prune into one if/else, content-scan.sh collapses two case blocks of the home-directory test into one [[ ]] condition (the "$home/" alternative was already covered by "$home"/*), and commit-msg-convention.sh drops a redundant empty-argument test that [ -f "" ] already covers. pre-commit-content.sh had nothing to simplify that stays inside the file without cross-file dedupe, which the issue puts out of scope, so it is unchanged. Moving code between files (the shared declined-key block, the remote default, added_only/added_lines) is left to the restructuring pass.

Not verified

  • The guardrails test suites (reference-verify.test.sh, pre-push-content.test.sh, pre-commit-content.test.sh, commit-msg-convention.test.sh) were not run here: the lane runs only its named wrappers. Left to the PR's CI.
  • ci-status green is a PR CI check, left to the PR's CI.
  • Tidy: the four git-hook script rows were dropped as GLOBAL HARD exclusions (local git-hook chain scripts; content-scan.sh is the secret scan), and the markdown passes made no edit because the fragment's one line is the text the issue mandates verbatim.
  • review-venue.txt was absent, so the review ran locally in one fresh-context subagent.
  • The working tree lists untracked .bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc at the checkout root. This run did not create them (they look like sandbox mount points) and they are not part of this change; leave them out of the patch.

Fix

  • plugins/guardrails/git-hooks/pre-push-content.sh: commit_ranges calls checks_intersect_ranges instead of an inline copy of its awk program
  • plugins/guardrails/git-hooks/reference-verify.sh: narrow_to_branch calls checks_intersect_ranges instead of an inline copy; the tip-worktree block is one if/else with a single remove and prune
  • plugins/guardrails/git-hooks/content-scan.sh: content_scan_init's home-directory test is one [[ ]] condition instead of two case blocks
  • plugins/guardrails/git-hooks/commit-msg-convention.sh: dropped the redundant [ -n "$msg_file" ] test
  • plugins/guardrails/git-hooks/reference-verify.test.sh: the narrowing-awk failure shim's marker is now the helper's program text (f[n]), since the inline program with p[n] is gone
  • .changes/guardrails/work-resolve-issue-issue-14470-42880169025-1-1302317f.md: patch fragment, ### Changed: Internal simplification, no behavior change.

Verification

The runner ran each check from the base copy against d7d4da9:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

Left out: the items under Not verified.

Related

#14470

Merge-Risk: max=MEDIUM demote=false head=d7d4da9ab027894d8d40c473447946e020e0f492 rubric=8.3.5 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed d7d4da9ab027894d8d40c473447946e020e0f492: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings. I read every hunk of all 6 changed files, plus the unchanged code the changed lines call. All four script edits keep the old behavior.

  • checks_intersect_ranges
    • pre-push-content.sh:84 and reference-verify.sh:166 now call the existing helper at check-lib.sh:426. Its awk program matches the removed inline copies; only the array name changed (p became f in reference-verify's copy). It takes the same two arguments in the same order.
    • The function's exit status is awk's, so local s=$? in narrow_to_branch still catches an awk failure.
    • Both scripts source check-lib.sh before calling it.
  • Tip-worktree if/else in reference-verify.sh:405-414. ! A || ! B is the same test as !(A && B), so a successful checkout still runs check_range and then cd "$top". A failed checkout still writes the blocking line. Both paths then do the same single remove and prune that the old continue branch did.
  • content-scan.sh:134. Inside [[ ]] the quoted "$home" is matched literally and /* matches an empty suffix, so "$home"/* also covers the old "$home/" case. The second test ("$home/" == "$PWD"/*) is a straight translation of the second case.
  • commit-msg-convention.sh. [ -f "" ] is false, so an empty argument still exits 0.
  • Test marker in reference-verify.test.sh:558. It now matches the helper's text. In pre-push mode, checks_merge_heads returns early, so narrow_to_branch is still the first awk call carrying that marker, and the test still exercises the same failure path.

Closing issue #14470 acceptance criteria

  • Behavior unchanged: met, by the analysis above. The existing reference-verify.test.sh cases and the other guardrails suites would catch a regression.
  • Diff touches only the listed files, the asserting test line, and a fragment: met. pre-commit-content.sh is unchanged, and the PR body explains why.
  • Within 400 changed lines and 15 files: met.
  • ci-status green: I can't check this from here. The author says the test suites weren't run in the lane run and were left to the PR's CI; that claim is unverified.
  • Fragment with bump: patch, ### Changed, and the required line: met.

Reusing an existing check-lib.sh helper is the "reuse of existing helpers" check the issue asks for. It doesn't move code between files, so the out-of-scope rule isn't broken.

No plugin manifest changed, so no manifest lines. There were no prior findings and no settled threads, and I found no embedded instructions in the PR context. I ran nothing: every check above comes from reading the code.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed d7d4da9ab027894d8d40c473447946e020e0f492: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15151, refactor(guardrails): simplify the git-hooks entry scripts

No security issues found. I read every hunk of all 6 changed files. This is a complete review, not a partial one. None of the files match a TRUSTED PATHS glob. The diff changes no plugin manifests and no standing instructions. It also widens no trust controls: no trusted-actor list, token scope, kill switch or merge hold is touched.

I checked that each change behaves exactly as before. These scripts are fail-closed scan hooks, so if a refactor silently turned one off, an unchecked secret or bad path could get pushed:

  • pre-push-content.sh commit_ranges and reference-verify.sh narrow_to_branch. Both now call checks_intersect_ranges. That helper already exists in the base check-lib.sh and is already used there by checks_changed_lines (check-lib.sh#L426-L432, #L461).
    • The helper's awk program is the same as the removed inline copies; only the array name changes, from p[] to f[].
    • It takes the same two file arguments in the same order, and its exit status is awk's.
    • In reference-verify.sh, local s=$? still captures awk's status, so a failed awk still fails the push (reference-verify.sh#L166-L173).
    • In pre-push-content.sh, the status was already ignored before this change, so nothing new is lost.
    • Any installed check-lib.sh that works with the base entries already defines this helper, so no installed copy can lack it.
  • reference-verify.sh tip worktree. The old if ! add || ! cd with its own remove, prune and continue became one if add && cd … else … fi, followed by a single remove and prune (#L405-L414).
    • The failure path still appends the blocking message to $out and cleans up the worktree.
    • Nothing came after the old cleanup inside the loop, so dropping continue changes nothing.
    • The script has no set -e, so check_range failing behaves as before.
  • content-scan.sh content_scan_init. The two case blocks became one [[ ]] condition. Each pattern keeps "$home" / "$PWD" quoted, so they match as literal text with a trailing /*. "$home"/* already matched "$home/", so scan_root is cleared in exactly the same cases as before.
  • commit-msg-convention.sh. Dropping [ -n "$msg_file" ] || exit 0 changes nothing: with an empty argument, [ -f "" ] is false and the script still exits 0.
  • reference-verify.test.sh only updates a test shim's marker text, and the changelog fragment is plain prose. Neither has any security surface.

The PR context contains no embedded text telling the review to pass, skip a check, drop a finding or post elsewhere.

critical-findings: 0

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head d7d4da9ab027894d8d40c473447946e020e0f492, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for d7d4da9

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15151-d7d4da9ab027894d8d40c473447946e020e0f492, expires on 2026-12-10.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit c57c802 Nov 10, 2026
64 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14470-42880169025-1 branch November 10, 2026 20:00
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.

Simplify the git-hooks guardrails plugin code

0 participants