utils/cpan: fail closed on non-CPAN and livecheck resources - #23529
Merged
Conversation
Signed-off-by: Patrick Linnane <patrick@linnane.io>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates Homebrew’s CPAN resource updater (brew update-perl-resources) to fail closed when a formula contains (a) any non-MetaCPAN resources or (b) CPAN resources that define livecheck blocks, preventing destructive in-place rewrites that would silently drop those stanzas.
Changes:
- Add preflight guards in
CPAN.update_perl_resources!that abort (unless--print-only) when non-CPAN resources or resourcelivecheckblocks are present. - Remove the prior “skip non-CPAN resources” behaviour that could still lead to those resources being deleted from the file during rewrite.
- Add/extend RSpec coverage to ensure the command exits before any MetaCPAN request or file modification in the guarded cases, while keeping
--print-onlybehaviour intact.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Library/Homebrew/utils/cpan.rb | Adds guardrails to abort updates when the formula contains non-CPAN resources or CPAN resource livecheck blocks (except in --print-only mode). |
| Library/Homebrew/test/utils/cpan_spec.rb | Adds regression tests covering failure-without-write for guarded cases and verifies --print-only still prints updated CPAN blocks. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CPAN.update_perl_resources!replaces the entire resource stanza group with the blocks it generates for MetaCPAN resources, so anything else living in that group is deleted. That means non-CPAN resources, andlivecheckblocks inside CPAN resources, were silently discarded by an in-place update.Eight homebrew-core formulae are affected.
gitloses itshtmlandmanresources,texlivemakes 45 MetaCPAN requests and then drops 4 non-CPAN resources, andlibbidrops 1.argus-clients,amtterm,help2man,exim, andlanraragieach lose thelivecheckblock on a CPAN resource.To reproduce:
The diff shows the
htmlandmanresource blocks removed.This adds two guards that fail closed before any MetaCPAN request or disk write, following the non-PyPI resource guard in
utils/pypi.rb.--print-onlyis unaffected and still prints the CPAN blocks it would generate. Note this is a user-visible change: the command now refuses on those eight formulae, where it previously succeeded destructively. Teaching it to skip and preserve those resources the wayutils/pypi.rbdoes is a follow-up; refusing is the safe intermediate state.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Code (Opus 5) drafted the implementation and tests; I reviewed the diff, verified each new test fails without the guards and passes with them, and ran
brew lgtmplus targeted specs.