Skip to content

refactor(apply-patch): fold duplicated diff, refusal, size and landing steps into helpers - #14195

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14102-42508825695-1
Nov 8, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14102

Summary

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

Simplified .github/scripts/apply-patch/apply-patch.mjs and kept its behavior: duplicated code in push and pushMerge now goes through small helpers in the same file. Those are diffEntries for the six git diff-tree calls, firstRefusal for the two refusal loops, oversizeBlobs for the two blob-size checks, fieldsAndPath for the four tab-record parsers, blobText for the two content rules, and landed for the write-then-read-back tail. The two near-identical escalation regexes became one, and modeAt's branch order is simpler. The other four listed files were reviewed and left unchanged: retry-fetch.mjs must stay byte-equal to its copies in pr-unblock/ and work-resolve-issue/, which are listed in other chunks, and deny-rules.mjs, predicates.mjs and protected-paths.mjs had no change that kept their printed errors and future-edit semantics the same. The duplication is gone, but the file is 9 lines longer (103 added, 94 removed), mostly comments on the new helpers.

Not verified

  • node --test for .github/scripts/apply-patch/apply-patch.test.mjs and deny-rules.test.mjs was not run: the lane allows no node command, and the review subagent's attempt was denied. Left to the PR's CI
  • retry-fetch.mjs, deny-rules.mjs, predicates.mjs and protected-paths.mjs were reviewed and left unchanged. retry-fetch.mjs must stay identical to its copies in pr-unblock/ and work-resolve-issue/ (out of scope as other chunks' files). Using loadRules in deny-rules.mjs would change the error printed…
  • tidy skipped: the change is under .github/, a listed shared path
  • ci-status green on the PR: left to the PR's CI

Fix

  • .github/scripts/apply-patch/apply-patch.mjs: merged ESCALATED_LINE/ESCALATED_REASON into one ESCALATED regex read through an escalations() helper (escalatedChecks, rungUpEscalation and heldEscalation keep their exports and results; rungUpEscalation drops a length comparison that was always true);…

Verification

The runner ran each check from the base copy against 959d5c2:

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

The run reports:

  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-changelog-fragments: all 2 changelog fragments under .changes/ valid (no fragment needed: .github/scripts is not a plugin)
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-changed-skills: no changed skills, nothing to gate
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-affected: 8 passed, 8 skipped, the rest CI-only
  • fresh-context review subagent compared each hunk against HEAD: no behavior difference found (same return values, errors, log lines, git/API call order, exported names and REFUSALS key order; push's escalate("<kind>") literal set, which apply-patch.test.mjs scans from source, is unchanged). On…
  • git-read diff --numstat HEAD: 1 file, 103 added and 94 removed lines, within the 400-line and 15-file cap
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42508825695

Left out: the items under Not verified.

Related

#14102

Merge-Risk: max=HIGH demote=true head=959d5c2f8c82bbfdc502ff58eb0b0fb3ba7c7d2e rubric=8.1.2 rater=claude-opus-5-5 checker=claude-opus-5-5

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

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #14195 (refactor of apply-patch.mjs)

No security issues found.

.github/scripts/apply-patch/apply-patch.mjs is on the trusted-path list, so I read every hunk of its change and the gates it touches. These are the patch-refusal checks, blob-size caps, credential-leak scan, conflict-marker and workflow checks, escalation parsing that feeds the rung-up and held stops, and the branch write with its read-back. Each new helper does the same thing as the code it replaces:

  • One escalation regex (ESCALATED) instead of two: both old regexes matched the same lines and only captured different groups. So the reasons.length === escalatedChecks(text).length comparison that rungUpEscalation dropped was always true. heldEscalation and rungUpEscalation read the same reasons as before.
  • firstRefusal: checks the same entries in the same order (renames as rename-into-refused first, then entries, then reaching entries in push). It stops at the first refusal and gives the same kind and why. Both refusal loops still run before any blob, tree or commit is written.
  • oversizeBlobs: applies the same per-blob limit (!(size <= MAX_BLOB_BYTES), so a NaN size still fails) and the same total limit. Both call sites still escalate as invalid.
  • landed: keeps the old behaviour of land plus the read-back. A write that succeeds still has to read back the same commit or it throws. A 422 is still treated as superseded only on a target whose ref can move and when a re-read shows another valid commit. Any other error still throws.
  • modeAt branch reorder: same results for a missing item, a non-tree in the middle of the path and a non-blob at the end.
  • fieldsAndPath, diffEntries, blobText, SHA256, let names;: these produce the same values as the inline code they replace. The default --no-renames and the explicit -M --diff-filter=R flags are passed through unchanged. names is still set to [] in the catch.

No trust control is widened: no change to who is trusted, to token scope, to the kill switch, to merge holds or to what untrusted text reaches a lane. No instruction surface or plugin manifest is touched. There is no prior finding to repeat.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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

Code review: no findings

This PR refactors .github/scripts/apply-patch/apply-patch.mjs (a trusted path, so I read every hunk). It closes #14102. I checked each hunk against the base behavior and found no change in behavior:

  • One escalation regex. ESCALATED_LINE and ESCALATED_REASON became one regex, ESCALATED. The old patterns differed only in which group they captured, so both matched the same lines. That means reasons.length === escalatedChecks(text).length was always true, and removing it from rungUpEscalation changes nothing. escalatedChecks and heldEscalation return the same results as before.
  • modeAt reorder. It still returns null for a missing item, for a non-tree in the middle of the path, and for a final item that is not a blob. It returns the mode only for a final item that is a blob.
  • land became landed. The read-back after the write moved into the helper. It runs in the same order, against the same ref, and throws the same message as before. The superseded path logs the same line and returns superseded. In pushMerge it is still inside the try/finally.
  • diffEntries, firstRefusal, oversizeBlobs, fieldsAndPath, blobText. Each builds the same git argument lists, checks refusals in the same order, and returns the same kinds and messages. fieldsAndPath(record)[1] in mergeFrom keeps the old result for a record with no tab (the whole record). pushMerge no longer declares written, and nothing below that point used it.
  • Source-scanning tests. The tests in apply-patch.test.mjs that pull the escalate("<kind>") literals out of push's body still find empty, not-applied, protected-path and invalid. The new helpers sit outside the slice those tests read.

Closing issue #14102 acceptance criteria:

  • Behavior unchanged, same exported names, no file renamed or deleted: met, judging by the hunk-by-hunk reading above. The existing apply-patch.test.mjs suite covers these paths: escalations, superseded/422 landing, oversize blobs, refusals and the merge push.
  • The diff edits only the listed files: met (only apply-patch.mjs changed).
  • Within 400 lines and 15 files: met (1 file; the PR states 103 added and 94 removed).
  • ci-status green: not verified by me. I ran no tests (this lane has no shell). The PR also says node --test was not run. This criterion is left to CI.

No .claude/rules file covers this path, and no plugin manifest changed.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 959d5c2

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-14195-959d5c2f8c82bbfdc502ff58eb0b0fb3ba7c7d2e, expires on 2026-12-08.

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 8, 2026
Merged via the queue into main with commit 8935ce5 Nov 8, 2026
66 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14102-42508825695-1 branch November 8, 2026 19:08
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 8935ce550fce7c6e46b78265730565857510fa02; 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 .github: apply-patch

0 participants