Skip to content

Prevent self upgrade on Homebrew installs#340

Merged
kindermax merged 1 commit intomasterfrom
codex/implement-issue-338
Apr 25, 2026
Merged

Prevent self upgrade on Homebrew installs#340
kindermax merged 1 commit intomasterfrom
codex/implement-issue-338

Conversation

@kindermax
Copy link
Copy Markdown
Collaborator

@kindermax kindermax commented Apr 25, 2026

Summary

  • Block lets self upgrade when the running binary is Homebrew-managed
  • Reuse the existing Homebrew path detection already used by update notifications
  • Add a unit test covering the Cellar install path and update the changelog

Testing

  • go test ./internal/upgrade
  • go test ./...
  • lets test-bats

Summary by Sourcery

Block self-upgrade for Homebrew-managed installations and document the change.

Bug Fixes:

  • Prevent lets self upgrade from overwriting Homebrew-managed Homebrew Cellar installs.

Documentation:

  • Update changelog to note the fix for Homebrew-managed self-upgrades.

Tests:

  • Add unit test ensuring Homebrew-managed binaries are not self-upgraded and no download occurs.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 25, 2026

Reviewer's Guide

Prevents lets self upgrade from modifying Homebrew-managed binaries by detecting Homebrew Cellar install paths before upgrade, returning a clear error instructing users to use brew upgrade, while adding a regression test and updating the changelog.

Updated class diagram for BinaryUpgrader Homebrew detection

classDiagram
  class RepoRegistry {
    <<interface>>
    +GetLatestRelease(ctx Context) string
    +DownloadBinary(ctx Context, version string) BinaryData
  }

  class BinaryUpgrader {
    -RepoRegistry registry
    -string currentVersion
    -string binaryPath
    +BinaryUpgrader(reg RepoRegistry, currentVersion string) BinaryUpgrader
    +Upgrade(ctx Context) error
  }

  class HomebrewDetection {
    +isHomebrewInstall(binaryPath string) bool
  }

  BinaryUpgrader --> RepoRegistry : uses
  BinaryUpgrader --> HomebrewDetection : calls isHomebrewInstall
Loading

File-Level Changes

Change Details Files
Block self-upgrade when running from a Homebrew-managed Cellar install and surface a user-facing error that points to the correct brew upgrade command.
  • Short-circuit the upgrade flow if the current binary path is detected as a Homebrew install using existing Homebrew detection logic.
  • Return a formatted error indicating Homebrew installs must be upgraded via brew upgrade lets-cli/tap/lets instead of performing a download or file replacement.
  • Ensure the registry lookup and binary replacement logic is skipped for Homebrew installs.
internal/upgrade/upgrade.go
Add regression coverage for Homebrew Cellar installs to ensure they are not modified by self-upgrade and that no download occurs.
  • Introduce a new subtest that creates a fake Homebrew Cellar directory structure and writes a mock lets binary at the expected path.
  • Instantiate BinaryUpgrader with the Homebrew-like binary path and assert that Upgrade returns an error containing the suggested brew upgrade command.
  • Verify that the binary contents remain at the original version and that the expected download file does not exist after the attempted upgrade.
internal/upgrade/upgrade_test.go
Document the new Homebrew self-upgrade protection behavior.
  • Add an Unreleased changelog entry describing that lets self upgrade no longer overwrites Homebrew-managed installs and references the associated issue.
docs/docs/changelog.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kindermax kindermax marked this pull request as ready for review April 25, 2026 16:15
@kindermax kindermax merged commit 96c2fb2 into master Apr 25, 2026
5 checks passed
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider extracting the brew upgrade lets-cli/tap/lets string into a shared constant so it’s not duplicated between the implementation and the test and is easier to change if the tap name ever changes.
  • If callers might need to handle the Homebrew case specially, you could introduce a sentinel error (e.g., ErrHomebrewInstall) instead of relying on matching the error message text.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the `brew upgrade lets-cli/tap/lets` string into a shared constant so it’s not duplicated between the implementation and the test and is easier to change if the tap name ever changes.
- If callers might need to handle the Homebrew case specially, you could introduce a sentinel error (e.g., `ErrHomebrewInstall`) instead of relying on matching the error message text.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant