This improves the load time of most brew commands. For an example of
one of the simplest commands this speeds up:
Without Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
Time (mean ± σ): 525.0 ms ± 35.8 ms [User: 229.9 ms, System: 113.1 ms]
Range (min … max): 465.3 ms … 576.6 ms 10 runs
Benchmark 2: git checkout optimise_requires; brew help
Time (mean ± σ): 383.3 ms ± 25.1 ms [User: 133.0 ms, System: 72.1 ms]
Range (min … max): 353.0 ms … 443.6 ms 10 runs
Summary
git checkout optimise_requires; brew help ran
1.37 ± 0.13 times faster than git checkout master; brew help
```
With Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
Time (mean ± σ): 386.0 ms ± 30.9 ms [User: 130.2 ms, System: 93.8 ms]
Range (min … max): 359.5 ms … 469.3 ms 10 runs
Benchmark 2: git checkout optimise_requires; brew help
Time (mean ± σ): 330.2 ms ± 32.4 ms [User: 93.4 ms, System: 73.0 ms]
Range (min … max): 302.9 ms … 413.9 ms 10 runs
Summary
git checkout optimise_requires; brew help ran
1.17 ± 0.15 times faster than git checkout master; brew help
```
The `#page_headers` and `#page_content` methods in
`Livecheck::Strategy` will fetch a URL using our default user agent
but if the request fails it will retry with the `:browser` user agent.
[For context, it was added as an interim measure to make URLs work
that require a different user agent but I aim to remove it in the
future in favor of specifying the user agent in a `livecheck` block
(so we don't make unnecessary requests that we know will fail).]
`Cask::Audit#audit_livecheck_https_availability` checks the
`livecheck` block URL but it only does so using our default user
agent (i.e., it calls `#validate_url_for_https_availability` which
calls `Utils::Curl#curl_check_http_content` which has a `user_agents:
[:default]` parameter). Due to this behavioral mismatch, it's possible
for a `livecheck` block to work but for this cask audit to fail.
This addresses the issue by adding `user_agents: [:default, :browser]`
to the arguments the audit uses, which aligns its behavior with
livecheck's.
Fixes edge cases where nested containers are used. Extraction for auditing artifacts did not pull the secondary container, which tried to audit the container instead of the contents.
I previously introduced a finalizer method in `Cask::Audit` to remove
the created `@tmpdir` once it's no longer needed but the existing
approach produces a `finalizer references object to be finalized`
warning when `brew audit` is run. I didn't see this warning when I
was originally testing it but now it reliably appears.
This reworks the finalizer to define it within the
`#extract_artifacts` method and use `@tmpdir` as the target object.
`Cask::Audit#extract_artifacts` is used in the `#audit_signing` and
`#cask_plist_min_os` methods to create a directory in `/tmp` and
extract cask artifacts without duplicating the work if it's already
done. However, due to how this is set up, `tmpdir` isn't removed
afterward and the extracted artifacts will take up disk space until
the `tmp` directory is cleaned up. As a result, running
`brew audit --strict --online` locally can chew through disk space
and it may not be clear to the user where their free space has gone.
This adds a finalizer method to `Cask::Audit` to remove the created
`@tmpdir` (if any) once it's no longer needed. There may be a better
way of addressing the issue but this works for now without having to
restructure how these audits work.
This got updated recently in 42a42c96acc5193dbb6e321ff2aaecceb00e48a4
to split out the livecheck audits and as a result of that the type
signature for the #validate_url_for_https_availablity method got updated.
This did not account for the possibility that the livecheck url was nil.
I've added a nil check here since it makes no sense to try and validate
a nil url and we have nil checks for the other two http availability
audits already. Plus, the livecheck blocks are audited thoroughly already
for syntax.
At the moment, Microsoft Office and related casks fail audit due to
failure to fetch a product homepage from the main Microsoft site
(https://www.microsoft.com/) served by Akamai CDN.
The failure is severe and weird: no status code is received as the
connection is reset.
The analysis revealed the issue is linked to `User-Agent` and
`Accept-Language` headers parsing. Homebrew uses involved user agent
strings and has language hardcoded as `en`.
The simplest workaround is to use a simple user agent string when checking
homepage availability if the cask is in an audit exceptions list.
Merging this would fix Microsoft Office updates (including
https://github.com/Homebrew/homebrew-cask/pull/162671)
This was not returning the full name correctly for e.g. anything in
Homebrew/homebrew-fonts.
While we're here, fix up a few other places where `tap.core_cask_tap?`
can be used more appropriately.