Skip to content

refactor(ruff-format): simplify the pre-commit check and the PostToolBatch hook - #15257

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14723

Summary

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

Simplified the two ruff-format scripts with no behavior change. ruff-check.sh drops the venv_dirs array for a plain conditional loop, folds the pyproject.toml test in governed() to one line, and routes both Ruff report runs through one collect() helper that keeps the exact 'ruff failed:' / 'ruff failed on <path>:' messages and exit 1. ruff-format.sh drops a redundant global RUFF_BIN initialization (the per-root loop resets it before use), folds the PATH fallback and its skip into one branch, and runs the check and format passes in one cd'd subshell instead of two. Added the required ruff-format patch fragment.

Not verified

  • ruff-check.test.sh, ruff-format.test.sh and ruff-format-end-of-turn.test.sh were not run directly in this lane (only the named wrappers run); left to the PR's CI
  • tidy: passes 1-3 ran with no edits needed; passes 4-5 (write-for-humans, ai-slop fix) skipped on the changelog fragment because its body is the exact text the issue's acceptance criterion requires
  • CI-only checks (cant-fail-scan, hook-slow-shapes, silent-skips, editorconfig and the rest check-affected lists as CI only) left to the PR's CI
  • ci-status green is a PR check, left to the PR's CI

Fix

  • plugins/ruff-format/git-hooks/ruff-check.sh: venv lookup without the conditional array; governed() pyproject test on one line; shared collect() helper for the two Ruff report runs
  • plugins/ruff-format/hooks/ruff-format.sh: removed the redundant top-level RUFF_BIN=""; PATH fallback folded into one branch; check and format in one subshell with a single cd
  • .changes/ruff-format/work-resolve-issue-issue-14723-42956273815-1-03135800.md: patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 4ea0df5:

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

The run reports:

  • check-changelog-fragments: all 19 fragments valid (run before and after tidy)
  • check-changed-skills: no changed skills, nothing to gate (run before and after tidy)
  • check-affected: 13 passed, 6 skipped (ruff: no .py changed; typos not installed; three validate-plugins steps that run checked-tree code; changed-skills) over 3 changed files (run before and after tidy)
  • fresh-context review subagent over the whole diff: no behavior difference in outputs, exit codes, printed text or flags; only theoretical divergences (an empty git path, $root vanishing between the two ruff runs whose output is discarded)
  • grep of tests reading the scripts' source: ruff-format.test.sh extracts ruff_venv_bin_here() by sed, which this change leaves untouched
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42956273815

Left out: the items under Not verified.

Related

#14723

Merge-Risk: max=MEDIUM demote=false head=4ea0df52c26b7615fcc80320a54f0de21821c339 rubric=8.4.1 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 4ea0df52c26b7615fcc80320a54f0de21821c339: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read every hunk of all 3 changed files and checked each one against the unchanged code around it. None of the changed files is on a trusted path.

plugins/ruff-format/git-hooks/ruff-check.sh

  • Venv lookup: the old version filled an array only when git ls-files printed nothing. The new if wraps the same loop over the same two paths, in the same order, with the same break. It behaves the same way.
  • governed(): the pyproject test is now one [[ -f ]] && grep && return 0 line. The script runs with set -uo pipefail and no -e, so a false test just falls through, as the if form did.
  • collect(): it runs in the main shell, so its exit 1 still ends the script. "${PIPESTATUS[1]}" is expanded before the call, so it still holds Ruff's status rather than git show's. "${2:+ on $2}" prints exactly ruff failed: on the files run and ruff failed on <path>: on the deleted-file runs. The path is passed as an argument, not as part of the format string. No function named collect exists in check-lib.sh, so nothing is overridden.

plugins/ruff-format/hooks/ruff-format.sh

  • Top-level RUFF_BIN="" removed: nothing reads RUFF_BIN before the per-root loop sets RUFF_BIN="" (line 117). ruff_venv_bin_here only assigns it. ruff-format.test.sh:61 pulls out only ruff_venv_bin_here()…} with sed, and that range never included the removed line.
  • PATH fallback: command -v ruff || continue followed by RUFF_BIN=ruff covers the same two cases as the old && RUFF_BIN=ruff plus the [[ -n ]] || continue guard.
  • One subshell instead of two: if cd fails, both Ruff runs are skipped, as before. With no -e in the subshell, format still runs after a failing check. All output still goes to /dev/null, and the || : keeps the exit status at 0.

Closing issue #14723 acceptance criteria

  • Behavior is unchanged: I found no difference in outputs, exit codes, printed text or flags.
  • The diff edits only the listed files and changelog fragments: met.
  • The PR stays within 400 changed lines and 15 files: met.
  • Each touched plugin has a fragment whose body is ### Changed and "Internal simplification, no behavior change.": met. The fragment has bump: patch and exactly that body.
  • ci-status is green: left to the pull request's CI. I could not check it.

The author's own test runs and check-affected results are their claims; I did not verify them. I had no shell, so I ran none of the test suites.

No plugin manifest changed, so the manifest checks did not apply.

@github-actions

Copy link
Copy Markdown
Contributor

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

Security review: PR #15257, ruff-format refactor

I read every hunk of all 3 changed files and found no security issues. None of the files matches a trusted-path glob, and the diff touches no trust control, plugin manifest or standing instruction.

Each change, checked against what the base code did:

  • plugins/ruff-format/git-hooks/ruff-check.sh, venv lookup (L44-51). The base code skipped a .venv the repository commits by leaving venv_dirs empty. The new code skips it by wrapping the loop in the same git ls-files -- ':(literal).venv' check. A ruff binary that a cloned repository commits still never lands on PATH and is never run by the commit hook.
  • ruff-check.sh, governed() one-line && chain. The script runs set -uo pipefail with no -e (L38), so a failed test just falls through, as before.
  • ruff-check.sh, collect() helper. $? and ${PIPESTATUS[1]} are expanded as arguments before the call, so they still hold Ruff's own exit status. Exit status above 1 still exits 1, and the stderr text is unchanged. The $f path goes to printf as an argument, not as the format string.
  • plugins/ruff-format/hooks/ruff-format.sh, removed global RUFF_BIN="". The loop still resets RUFF_BIN="" for each root at L117, before ruff_venv_bin_here runs. That reset happens before any read, so a RUFF_BIN set in the environment can't choose the binary, and one root's venv binary can't be reused for another root. ruff_venv_bin_here (L73-84), including its committed-.venv check, is unchanged.
  • ruff-format.sh, single subshell (L126-130). cd "$root" || exit means neither Ruff command runs when cd fails, which matches the old cd && ... pair. Output is still discarded and the hook still always exits 0.
  • .changes/... fragment. A changelog text file; nothing in it runs.

The PR description contains no embedded instructions. The closing issue's body was left out by the wrapper.

Instruction exception register: not needed, because no standing instruction is deleted or narrowed.

critical-findings: 0

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 4ea0df52c26b7615fcc80320a54f0de21821c339. No person needs to act: a lane clears this reason, and the next scheduled run judges it again.

pr-merge's gate refuses its verifier verdict (verify:missing)

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 4ea0df5

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-15257-4ea0df52c26b7615fcc80320a54f0de21821c339, 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 36ffee3 Nov 11, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14723-42956273815-1 branch November 11, 2026 05:28
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 6, survived 1, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 86%; mutation score 86%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/ruff-format/git-hooks/ruff-check.sh 4 1 0 0 0 0
plugins/ruff-format/hooks/ruff-format.sh 2 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/ruff-format/git-hooks/ruff-check.sh:168 other productive input-gap

The run's summary has the full report.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 36ffee322f647d9c5dfaa7947ea93b81a3b05240; 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 git-hooks and hooks ruff-format plugin code

0 participants