Fix banner crash when stdout is redirected#17443
Conversation
When --banner was explicitly passed, the condition bypassed the SupportsInteractiveOutput check. Spectre.Console's Live display then tried to set Console.CursorVisible on an invalid handle, throwing IOException. The fix ensures SupportsInteractiveOutput is always required for the animated banner, even when explicitly requested via --banner.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17443Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17443" |
There was a problem hiding this comment.
Pull request overview
Fixes a CLI crash when --banner is used while stdout is redirected by ensuring the banner is only shown when ICliHostEnvironment.SupportsInteractiveOutput is true (the Spectre.Console Live banner requires valid console handles).
Changes:
- Updates the banner-display condition to always require
SupportsInteractiveOutput, even when--banneris explicitly passed. - Adjusts/extends unit tests to cover explicit
--bannerbehavior in non-interactive environments and to force an interactive host environment in tests that expect the banner.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Aspire.Cli/Program.cs | Tightens banner gating so animated banner only runs in interactive output environments. |
| tests/Aspire.Cli.Tests/Commands/RootCommandTests.cs | Updates tests to reflect the new interactive-output requirement for --banner and adds coverage for the redirected/non-interactive scenario. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
❓ CLI E2E Tests unknown — 96 passed, 0 failed, 5 unknown (commit View all recordings
📹 Recordings uploaded automatically from CI run #26361816430 |
|
✅ No documentation update needed. docs_required → already documented by name Triggered signal (1): The This PR is a bug fix: it ensures the animated banner is only shown when |
Description
When
--bannerwas explicitly passed and stdout was redirected (e.g.,aspire --version --banner > test.txt), the CLI crashed withSystem.IO.IOException: The handle is invalidbecause Spectre.Console'sLivedisplay tried to setConsole.CursorVisibleon an invalid handle.The root cause was that the
showBannerflag bypassed theSupportsInteractiveOutputcheck in the OR condition. The fix ensuresSupportsInteractiveOutputis always required for the animated banner, even when explicitly requested via--banner.Fixes #17410
Checklist