download_queue: print fetch heading to stderr when stdout is not a TTY - #23406
Open
carlocab wants to merge 2 commits into
Open
download_queue: print fetch heading to stderr when stdout is not a TTY#23406carlocab wants to merge 2 commits into
carlocab wants to merge 2 commits into
Conversation
`brew info --installed --json=v2` emits `==> Downloading Homebrew API data` to stdout when the API data needs (re)downloading, corrupting the JSON for anything parsing it (e.g. piping to `jq`). The heading was added in 284cd0e (#23381) as an unconditional `oh1`, regressing the intent of 43137fe (#20980), which moved the queue's non-TTY per-download report lines to stderr for exactly this reason. Print the heading to stderr when stdout is not a TTY so it stays off parsed stdout and on the same stream as those report lines. TTY behaviour is unchanged. Use `$stderr.puts oh1_title(...)` rather than `$stderr.oh1` as RSpec's `to_stderr` matcher replaces `$stderr` with a plain `StringIO` that lacks the `Utils::Output::Mixin` extension.
Member
|
@carlocab any AI disclosure here? |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes machine-readable command output corruption by ensuring DownloadQueue prints its fetch heading to stderr when stdout is not a TTY (e.g. brew info --json=v2 | jq), while leaving TTY behavior unchanged.
Changes:
- Route
DownloadQueue#fetchheadings to stderr when@ttyis false, keeping parsed stdout clean. - Add/adjust RSpec coverage to assert heading stream behavior (stderr for non-TTY, stdout for TTY).
- Update cask reinstall specs to expect the “Fetching downloads…” heading on stderr.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Library/Homebrew/download_queue.rb | Prints the fetch heading to stderr when stdout is non-TTY to avoid corrupting machine-readable stdout. |
| Library/Homebrew/test/download_queue_spec.rb | Adds specs covering heading output stream behavior for TTY vs non-TTY cases. |
| Library/Homebrew/test/cask/reinstall_spec.rb | Updates expectations so the fetch heading is asserted on stderr. |
Suppressed comments (1)
Library/Homebrew/test/download_queue_spec.rb:174
- This example also depends on stdout being non-TTY at
DownloadQueueconstruction time, but doesn't stub$stdout.tty?before callingenqueue(which instantiates the subject). On a real TTY this will print the heading to stdout, defeating the assertion.
it "keeps the heading off stdout when stdout is not a TTY" do
allow(retryable_download).to receive(:fetch).and_return(cached_download)
download_queue.enqueue(downloadable)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
Yes. Looks like my sandbox is misconfigured. Hang on. |
This addresses a Copilot review comment that is reachable when tests are run as `brew tests --debug`.
Member
Author
Done now! |
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.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Fable xhigh with manual review and testing.
Running
brew info --installed --json=v2with a stale cache printsto stdout, which breaks JSON parsing. Let's fix this the same way as #20980.