Skip to content

refactor(guardrails): simplify block-unresolved-pr-merge.sh - #15347

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14481-42976948954-1
Nov 11, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14481

Summary

Opened by the work-resolve-issue lane from work-resolve-issue/issue-14481-42976948954-1, which an earlier run left with commits and no report. A summary-only model pass read the branch's diff and the issue, changed nothing, and wrote:

This refactors plugins/guardrails/hooks/block-unresolved-pr-merge.sh without intended behavior change, and adds the required guardrails changelog fragment. It hoists a repeated REST route regex into a local variable. It collapses the -R branching for gh pr merge into one call. It adds a _bupm_block helper that prints the message lines plus the "Only the user can turn this guard off" note to stderr, emits the "blocked" telemetry and exits 2. The graphql-unresolvable, target-unresolvable, hold-label and final unresolved-threads blocks all use it. The thread listing loop now uses a single counter with a cap of 10. Message text, exit codes and telemetry forms appear unchanged. The diff edits only the one listed file plus the fragment, and touches no tests. It was not run here, so the CI status and a byte-identical output check are unverified. One subtle point for reviewers: the final block now prints the turn-off note after the "Fix:" line via the helper, which matches the previous order. The issue's acceptance items are otherwise covered. The diff contains no text that tries to steer a reviewer.

Fix

  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: _bupm_rest_path stores the merge route regex in a local route_re and uses it in both places
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: _bupm_command replaces the if/else on pre_repo with ${pre_repo:+-R "$pre_repo"}
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: new _bupm_block helper prints message lines and the turn-off note, emits telemetry and exits 2
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: _bupm_refuse and _bupm_refuse_target now call _bupm_block
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: the hold-label refusal uses _bupm_block
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: the unresolved-thread listing drops the _bupm_shown counter and caps output at 10 using _bupm_total
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh: the final block ends with _bupm_block "$BUPM_FORM" instead of a separate note, telemetry call and exit
  • .changes/guardrails: new patch fragment reading 'Internal simplification, no behavior change.'

Files the branch changes, from the compare listing; a denied path, which the merge lane refuses, is marked and listed first:

  • .changes/guardrails/work-resolve-issue-issue-14481-42976948954-1-a228f1e8.md
  • plugins/guardrails/hooks/block-unresolved-pr-merge.sh

Verification

The earlier run reported no checks here, and the summary pass ran none.

The runner ran each check from the base copy against 42491df:

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

The runner's leak scan read everything the branch changes since its merge base with the default branch and found nothing credential-shaped.

Left out: every check the earlier run would have reported; ci-status, pr-verify and the security review lane check the head before it merges.

Related

#14481

Merge-Risk: max=MEDIUM demote=false head=42491df6f9d83a668cc75baa82a80de21d359300 rubric=8.4.2 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-security-review reviewed 42491df6f9d83a668cc75baa82a80de21d359300: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15347 (refactor of block-unresolved-pr-merge.sh)

No security issues found.

This change refactors the guardrails PreToolUse hook that refuses PR merges when a PR has unresolved threads, change requests, failing checks or hold labels. A guard hook fails open if it exits with anything other than 2, or if it stops recognising a merge form. So I checked every changed hunk to confirm it still blocks exactly what it blocked before.

  • route_re hoist (L258–273). The regex is stored in single quotes and used unquoted on the right of =~, so it still works as a regex. Both match sites still use the same pattern as before.
  • ${pre_repo:+-R "$pre_repo"} (L533). :+ treats an empty value like an unset one, which matches the old [[ -n ]] test. The quoted inner "$pre_repo" stays one word, so a value with spaces or glob characters is not split or expanded. Every IFS= in the file is a command prefix (L763, 930, 996, 1030, 1039, 1094, 1109, 1130, 1188), not a global assignment, so the split on -R still happens with the default IFS. gh pr -R <repo> merge therefore still sends the same arguments to _bupm_gh_pr_merge.
  • _bupm_block helper (L782–790). It prints with a fixed '%s\n' format, so no format-string injection is added. Values the old code passed to %s ($1, repo/number, hold labels) now go in as arguments to that fixed format, which gives the same output. It still emits the same blocked telemetry form and then exit 2. Every call site runs at top level or in a function called at top level, with no subshell, so exit 2 still ends the hook.
    • Hold-label refusal (L936–939): [[ -z ... ]] || _bupm_block still refuses whenever _bupm_holds is non-empty.
    • Final verdict (L1200): same.
  • Thread-listing loop (L1188–1192). It only changes how many lines are shown, not whether the merge is blocked. The script runs set -uo pipefail without -e (L189), so a false ((...)) cannot end it early with a non-2 status.
  • Changelog fragment. Prose only; no security surface.

Trust controls: the hook is not under any TRUSTED PATHS glob, and the change widens no trusted-actor check, token scope, kill switch, merge hold or untrusted-text path. It deletes or softens no instruction text; the DATA-framing line for quoted thread text is unchanged. It touches no plugin manifest.

Embedded text: the PR description contains no directives aimed at the review.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

I found no problems in this pull request. I read every hunk of both changed files: the changelog fragment and plugins/guardrails/hooks/block-unresolved-pr-merge.sh. I also read the hook's surrounding code wherever the new code depends on it.

Behavior check against #14481

  • REST route regex (route_re). The regex now lives in a local variable and is matched unquoted, as [[ $p =~ $route_re ]]. That keeps it a regex, so both match sites behave as before.
  • ${pre_repo:+-R "$pre_repo"}. The script only ever sets IFS as a prefix on a single command (L763, L930, L1030 and others), so it stays at its default. The expansion therefore yields either nothing or exactly two words, -R and the repo, which is the same as the old if/else.
  • _bupm_block.
    • Every message line is now passed as an argument to printf '%s\n', not used as a format string. The old format strings had no % or \, so the printed text is identical.
    • Values substituted in ($1, $_bupm_holds, the repo and PR number) are still printed as data.
    • The telemetry forms are unchanged: graphql-unresolvable, $BUPM_FORM-unresolvable, $BUPM_FORM-hold-label and $BUPM_FORM.
    • The exit code is still 2.
    • In the final block the turn-off note still comes after the Fix: line.
    • The helper is defined (L784) before its first call (L795 onward).
    • SC2016 still covers the single-quoted $(...) text in _bupm_refuse_target.
  • Thread cap. ((++_bupm_total <= 10)) && printf prints the same first ten lines. ... and N more is printed only when there are more than 10, which matches the old _bupm_shown logic. The script runs set -uo pipefail without -e (L189), so the && lists that sometimes return non-zero have no side effect.
  • Changelog fragment. It matches the required body, ### Changed followed by "Internal simplification, no behavior change.", with bump: patch.
  • Scope. The diff stays within the listed file plus the fragment, and well under 400 lines.

Not verified by me. I could not run the hook or its tests. The author says check-changelog-fragments.sh and check-changed-skills.sh passed; that is unverified, and so is whether ci-status is green.

No plugin manifest changed. The PR context holds no embedded instructions aimed at the review lane.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 42491df

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-15347-42491df6f9d83a668cc75baa82a80de21d359300, expires on 2026-12-11.

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 11, 2026
Merged via the queue into main with commit 0ab45bd Nov 11, 2026
72 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14481-42976948954-1 branch November 11, 2026 12:06
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 0ab45bdafc5d7d5de55ed9aa808f4539de5eacd3; later checks count it verified from this comment.

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 block-unresolved-pr-merge.sh guardrails plugin code

0 participants