Skip to content

download_queue: print fetch heading to stderr when stdout is not a TTY - #23406

Open
carlocab wants to merge 2 commits into
mainfrom
download-queue-heading-stderr
Open

download_queue: print fetch heading to stderr when stdout is not a TTY#23406
carlocab wants to merge 2 commits into
mainfrom
download-queue-heading-stderr

Conversation

@carlocab

@carlocab carlocab commented Aug 3, 2026

Copy link
Copy Markdown
Member
  • 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 Fable xhigh with manual review and testing.


Running brew info --installed --json=v2 with a stale cache prints

==> Downloading Homebrew API data

to stdout, which breaks JSON parsing. Let's fix this the same way as #20980.

`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.
Copilot AI review requested due to automatic review settings August 3, 2026 13:05
@MikeMcQuaid

Copy link
Copy Markdown
Member

@carlocab any AI disclosure here?

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 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#fetch headings to stderr when @tty is 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 DownloadQueue construction time, but doesn't stub $stdout.tty? before calling enqueue (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.

Comment thread Library/Homebrew/test/download_queue_spec.rb
@carlocab

carlocab commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@carlocab any AI disclosure here?

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`.
@carlocab

carlocab commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@carlocab any AI disclosure here?

Done now!

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