Skip to content

utils/cpan: fail closed on non-CPAN and livecheck resources - #23529

Merged
MikeMcQuaid merged 1 commit into
mainfrom
cpan-fail-closed
Aug 14, 2026
Merged

utils/cpan: fail closed on non-CPAN and livecheck resources#23529
MikeMcQuaid merged 1 commit into
mainfrom
cpan-fail-closed

Conversation

@p-linnane

Copy link
Copy Markdown
Contributor

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, and livecheck blocks inside CPAN resources, were silently discarded by an in-place update.

Eight homebrew-core formulae are affected. git loses its html and man resources, texlive makes 45 MetaCPAN requests and then drops 4 non-CPAN resources, and libbi drops 1. argus-clients, amtterm, help2man, exim, and lanraragi each lose the livecheck block on a CPAN resource.

To reproduce:

brew update-perl-resources git
git -C "$(brew --repository homebrew/core)" diff Formula/g/git.rb
git -C "$(brew --repository homebrew/core)" checkout Formula/g/git.rb

The diff shows the html and man resource 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-only is 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 way utils/pypi.rb does is a follow-up; refusing is the safe intermediate state.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

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 lgtm plus targeted specs.


Signed-off-by: Patrick Linnane <patrick@linnane.io>
Copilot AI lite review requested due to automatic review settings August 14, 2026 18:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 resource livecheck blocks 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-only behaviour 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.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Aug 14, 2026
Merged via the queue into main with commit 38ee325 Aug 14, 2026
47 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the cpan-fail-closed branch August 14, 2026 19:31
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.

3 participants