6060 Commits

Author SHA1 Message Date
Sam Ford
473f448b22
OnSystem: handle non-macOS current_os values
The `OnSystem.os_condition_met?` method only handles Linux and macOS
values for the current OS, so this fails when testing with a generic
OS. This shortcoming is only being surfaced now because there weren't
any tests for `OnSystem` before.

This addresses the issue by accounting for macOS values (`:macos` or
a symbol from `MacOSVersion::SYMBOLS`) and returning `false` for any
other values (`:linux`, `:generic`, etc.).
2025-06-08 10:13:40 -04:00
Sam Ford
8350b8a43a
MacOSRequirement: add #highest_allowed method
This adds a `#highest_allowed` method to `MacOSRequirement`, so we can
easily identify the highest supported macOS version that a requirement
allows, if any.

This can be used when producing a minimal set of supported macOS
versions that meet requirements in `UsesOnSystem.macos_requirements`.
One of the intended use cases for this is to identify which macOS
versions we could simulate to work with all variations of a cask that
uses macOS on_system blocks.
2025-06-08 10:13:40 -04:00
Sam Ford
01825acabd
UsesOnSystem: Collect macOS requirements
When determining macOS requirements for a cask, we may need to
reference requirements from related on_system blocks (e.g.,
`on_monterey :or_older`, `on_ventura`, `on_sonoma :or_newer`) when
`depends_on macos` isn't adequate.

Sometimes casks specify different `depends_on macos` values in macOS
on_system blocks but that value is only set when the cask is loaded
in an environment that satisfies the on_system block's requirements.
There are other casks that contain macOS on_system blocks and use
`depends_on macos` outside of the on_system blocks but it may only
use the macOS version of the lowest on_system block (e.g.,
`>= :monterey`), which isn't sufficient if the cask's values vary
based on macOS version.

To be able to simulate macOS versions that meet the requirements of
all the on_system blocks in a cask, we need to collect the macOS
requirements in a way that doesn't require OS simulation. This is also
something that's easy to do in on_system methods, so this adds a
`macos_requirements` array to `UsesOnSystem`, containing
`MacOSRequirement` objects created from the cask's macOS on_system
block conditions.
2025-06-08 00:57:22 -04:00
Sam Ford
3df8f70511
OnSystem: Add UsesOnSystem class
This adds a `UsesOnSystem` class to `OnSystem`, containing boolean
instance variables to indicate which types of on_system methods are
used in a formula or cask. This is intended as a replacement for
`@on_system_blocks_exist`, which doesn't allow us to determine what
kinds of on_system calls were used. This provides more granularity
but we can still use `@uses_on_system.present?` to determine whether
any on_system calls were used (and this doubles as a `nil` check in
`Formula`, as the `self.class` instance variable has to use a nilable
type).

The `UsesOnSystem` instance variables cover the current
`ARCH_OPTIONS` and `BASE_OS_OPTIONS`. At the moment, we mostly need
to tell whether there are macOS/Linux or Intel/ARM on_system calls,
so I've omitted instance variables for specific macOS version until
we have a need for them.

As a practical example, if you wanted to determine whether a cask
uses Linux on_system calls, you can call
`cask.uses_on_system.linux?`. The `linux` boolean will be `true` if
the cask has an `on_linux` block, an `on_system` block (which requires
Linux), or uses `os linux: ...`. This is something that would be
challenging to determine from outside of `OnSystem` but it's
relatively easy to collect the information in `OnSystem` methods and
make it available like this.
2025-06-07 17:58:12 -04:00
Sam Ford
bafa2ec126
OnSystem: add tests
`OnSystem` is exercised by other tests that include its modules but
this adds some baseline tests to ensure some of these methods work as
expected when tested in isolation. Between these added tests and
existing tests, we should have 100% coverage when run on Homebrew/brew
CI.
2025-06-06 15:09:35 -04:00
Mike McQuaid
ff710f8191
Improve completions (and elisp) output in caveats
Instead of repeatedly outputting the same identical messages across
multiple packages and repeating them all for every package after they
were all installed: just output the identical messages in the final
caveats output instead.
2025-06-06 17:09:28 +01:00
Mike McQuaid
5fe43ed3f2
brew (bundle|) sh: use user's configuration but override prompts.
This was more painful that I expected but will allow `brew bundle sh`
and `brew sh` to use the user's configuration but use our custom prompt
for Bash and ZSH.
2025-06-05 15:43:34 +01:00
Mike McQuaid
e825ceea0a
Merge pull request #20041 from Homebrew/mcp_server
Add `brew mcp-server`: a MCP server for Homebrew.
2025-06-04 07:58:01 +00:00
Rylan Polster
c03f70f1dc
Refactor OnSystem and SimulateSystem bottle tag handling 2025-06-03 11:57:17 -04:00
Mike McQuaid
76c4eb60ee
test/cmd: add more shell tests.
This should help ensure that these don't regress.
2025-06-03 15:24:19 +01:00
Mike McQuaid
f9471f9591
Add brew mcp-server: a MCP server for Homebrew.
Add a new `brew mcp-server` command for a Model Context Protocol (MCP)
server for Homebrew. This integrates with AI/LLM tools like Claude,
Claude Code and Cursor.

It currently supports the calls needed/used by the MCP Inspector and
Cursor (where I've tested it).

It provides as `tools` the subcommands output by `brew help` but should
be fairly straightforward to add more in future.

It is implemented in a slightly strange way (a standalone Ruby command
called from a shell command) as MCP servers need a faster startup time
than a normal Homebrew Ruby command allows and fail if they don't get
it.

There are a few Ruby libraries available but, given how relatively
simplistic the implementation is, it didn't feel worthwhile to use and
vendor them.
2025-06-03 15:22:33 +01:00
Rylan Polster
0f03757e8f
Shard JSON API by OS/Arch combination 2025-06-02 23:06:02 -04:00
Eric Knibbe
cd6777fc73
audits: quote and reword problem description text 2025-05-30 23:49:26 -04:00
Mike McQuaid
2131d70265
workflows/pkg-installer: fix release upload.
- Get the release tag from the installer path.
- Remove unnecessary `gh` installation.
- Remove failing test that I can't fix.
2025-05-27 11:47:00 +01:00
Bo Anderson
418a771d12
bundle: add support for selective cleanup 2025-05-23 06:19:01 +01:00
Mike McQuaid
4aa7f83954
dev-cmd/bump-formula-pr: use Formatter.truncate.
Add new `Formatter.truncate` method, tests and use it.
2025-05-21 17:02:18 +01:00
Eric Knibbe
5027a9d2f2
cask/audit: skip audit_rosetta on Intel-only casks & OSes 2025-05-21 10:14:08 -04:00
Colin Dean
d5b3ae095c
Prohibit non-ASCII characters in URLs, nudge toward punycode
Inspired by curl's blog post, [Detecting malicious Unicode][1], this likely captures most if not all cases and nudges the user toward supplying IDNs with punycode.

A possible improvement would be telling the user exactly what punycode domain to use instead, but that may require another library as I can't quickly find something built into the Ruby stdlib that handles punycode encoding.

[1]: https://daniel.haxx.se/blog/2025/05/16/detecting-malicious-unicode/

Co-authored-by: Štefan Baebler <319826+stefanb@users.noreply.github.com>
2025-05-21 12:42:07 +01:00
Sam Ford
95abc7360b
Bitbucket: update generated urls
The `Bitbucket` strategy checks download or tag pages but the content
is now fetched separately on page load, so the strategy is failing for
all related formulae. This updates the generated strategy URLs to
fetch the page content instead, which works as expected.
2025-05-19 12:13:49 -04:00
Sean Molenaar
107120e4d8
Merge pull request #19880 from Moisan/audit_bitbucket_patch
patches audit: bitbucket patches should use api
2025-05-15 12:45:30 +00:00
Bo Anderson
288984bb0f
bundle/dsl: combine cask_args calls 2025-05-09 08:06:06 +01:00
Patrick Linnane
c6a2fa335d
brew style --fix 2025-05-05 14:35:08 -07:00
Bo Anderson
7617ac135f
Merge pull request #19888 from Homebrew/remove-es-kibana-refs
formula_auditor: remove elasticsearch and kibana refs
2025-05-04 04:38:15 +00:00
Sam Ford
53c0780d85
shared_audits_spec: guard against nil value
The return value from `eol_data` can be `nil`, so we should use a
safe navigation operator before `#dig`.
2025-05-03 20:49:53 -04:00
Sam Ford
98b919f672
shared_audits_spec: use generic JSON values
This updates `eol_json_text` to use generic values (instead of values
from nodejs) and to omit some unused fields.
2025-05-03 20:48:20 -04:00
Daeho Ro
2493be79cc
utils/shared_audits: add eol_data test 2025-05-04 02:10:08 +09:00
Rui Chen
9c2ac58709
formula_auditor: remove elasticsearch and kibana refs
Signed-off-by: Rui Chen <rui@chenrui.dev>
2025-05-03 10:58:13 -04:00
Bo Anderson
ae58b3ef21
services: try multiple domains when stopping 2025-05-02 06:19:53 +01:00
Thierry Moisan
84704c5587
patches audit: bitbucket patches should use api 2025-05-01 22:53:42 -04:00
botantony
91f328950f test/fixtures: fix cask JSON fixture
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-29 18:04:59 +02:00
botantony
9ff2abbcdf no_autobump!: rename no_autobump_msg field to no_autobump_message
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-29 18:04:59 +02:00
botantony
1fcacdc2dc formula/cask DSL: add no_autobump! method
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-29 18:04:59 +02:00
Issy Long
6c11916cbc
Bump some files to Sorbet typed: strict 2025-04-27 22:45:44 +01:00
botantony
2a03f2059c
completions: fix tests
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-22 22:31:45 +02:00
Mike McQuaid
c9a7b62b1d
Homebrew 4.5 deprecations/disables/removals
The usual cycle of deprecating, disabling, and removing things in
Homebrew major/minor releases.
2025-04-22 17:15:23 +01:00
botantony
4fa1355be0 deprecate!/disable!: remove non-typed replacement field
Signed-off-by: botantony <antonsm21@gmail.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2025-04-21 21:13:25 +02:00
botantony
ca447e1ce9 deprecate!/disable!: replacement_formula/replacement_cask fields
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-21 21:13:25 +02:00
botantony
e594e7e0bb deprecate!/disable!: allow to specify replacement type
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-21 21:13:25 +02:00
Bo Anderson
3049d21ca0
test/cask/dsl/container_spec: fix test failure with Ruby 3.4 2025-04-16 17:10:10 +01:00
Mike McQuaid
66902cb3ad
spec_helper: cleanup VSCode/Cursor test files. 2025-04-14 15:32:42 +01:00
Patrick Linnane
86f56c8bd5
test/dev-cmd/tap-new_spec: use --no-git to avoid auth prompt
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2025-04-12 19:15:07 -07:00
Mike McQuaid
359b68f827
Improve brew bundle exec/env/sh environment handling
- Rather than maintaining a list of Homebrew environment variables to
  delete, delete all Homebrew (and Portable Ruby) internal variables
  that won't be used by other tools.
- When exporting variables, only export variables that have changed.
- When exporting PATH-like variables, ensure the PATH is appending to
  the existing path rather than replacing it and ensure we only include
  newly added paths.
2025-04-10 15:23:02 +01:00
Sam Ford
7b2d84337e
cmd/upgrade: fix output regex in test
The "upgrades with asking for user prompts with dependants checks"
test for `cmd/upgrade` has been failing on CI. The regex in the test
doesn't match expected output because the negative lookaheads aren't
working as expected. The intention is to make sure that the names
aren't repeated (i.e., second shouldn't match first, third shouldn't
match first or second) but the negative lookaheads should be
_inside_ the second/third capture group for this to work as intended.

This updated regex should work as expected. I manually tested it
using the output from CI to make sure that it matches when no formula
names are repeated (e.g., `Formulae (3): testball, testball4,
testball5`) and does not match if formula names are repeated (e.g.,
`Formulae (3): testball5, testball4, testball5`).
2025-04-09 12:56:06 -04:00
Bo Anderson
f2513965e8
Revert "Revert "bundle: handle simultaneous exec --services better""
This reverts commit 94db0b2f3408280e20ca3888ed5c91672ab4fca2.
2025-04-07 14:10:42 +01:00
Bo Anderson
52a7b67ba5
Revert "Revert "services: add loaded_file data""
This reverts commit 76901b1352d776a0fb53696b0e61eed420186b0c.
2025-04-07 14:05:39 +01:00
Sam Ford
b7065d5fcf
bump-cask-pr: extract system_options generation
This extracts the logic for generating the `system_options` array in
the `replace_version_and_checksum` method into a separate
`generate_system_options` method. This logic is becoming more complex
(after recent changes) and manually testing it is a pain, so this
change is intended to allow us to add tests. The tests added here
provide 100% coverage for the method.
2025-04-06 10:58:46 -04:00
Mike McQuaid
0d6de643f8
Merge pull request #19706 from Homebrew/revert-19703-bundle-exec-simultaneous-services
Revert "bundle: handle simultaneous `exec --services` better"
2025-04-04 14:47:04 +00:00
Mike McQuaid
94db0b2f34
Revert "bundle: handle simultaneous exec --services better" 2025-04-04 15:30:47 +01:00
Sam Ford
8d52d9b3fc
livecheck: add tests for delegates
This adds tests for the livecheck DSL's `version` and `arch`
delegates. This doesn't affect test coverage but it ensures that the
methods work as expected in `livecheck` blocks.
2025-04-04 09:17:32 -04:00
Sam Ford
97cce36779
Make os available in cask livecheck blocks
Casks now support an `os` DSL method, similar to `arch`. This makes
it available in `livecheck` blocks, like we do with `arch`.
2025-04-04 09:17:32 -04:00