Skip to content

Fail cleanly when AppHost selection needs a prompt in non-interactive mode (#17619)#18297

Merged
radical merged 2 commits into
mainfrom
fix/17619-noninteractive-describe
Jun 18, 2026
Merged

Fail cleanly when AppHost selection needs a prompt in non-interactive mode (#17619)#18297
radical merged 2 commits into
mainfrom
fix/17619-noninteractive-describe

Conversation

@mitchdenny

Copy link
Copy Markdown
Member

Description

Fixes #17619aspire describe --non-interactive (and other backchannel commands) crashes by attempting an interactive AppHost-selection prompt when no AppHost can be unambiguously resolved.

Root cause

When AppHostConnectionResolver found multiple in-scope AppHosts, or only out-of-scope AppHosts, it always fell through to an interactive selection prompt. In non-interactive mode there is no console to prompt on, so the prompt threw instead of returning a clean error.

Fix

  • AppHostConnectionResolver now takes an ICliHostEnvironment and checks SupportsInteractiveInput before prompting:
    • Multiple in-scope AppHosts, non-interactive → returns an actionable error (MultipleAppHostsNonInteractive) with FailedToFindProject instead of throwing.
    • Only out-of-scope AppHosts, non-interactive → returns the standard "not found" error/exit code instead of an unexpected prompt failure.
  • Wired the ICliHostEnvironment through every caller (DescribeCommand, ExportCommand, LogsCommand, StopCommand, telemetry/MCP/resource/wait commands, and the terminal attach/ps commands).
  • Added a new MultipleAppHostsNonInteractive resource string (+ generated .xlf placeholders).

Tests

Adds AppHostConnectionResolverTests coverage for both non-interactive branches (only out-of-scope → not found; multiple in-scope → actionable error).

Split out of #18261 so each fix can be reviewed in isolation.

Fixes #17619

shauryalowkeygotaura and others added 2 commits June 18, 2026 08:58
…eractive mode

When no AppHost is found in the current directory but other AppHosts are
running on the system, commands like 'aspire describe --non-interactive'
fell through to an interactive selection prompt, which threw and surfaced
as 'An unexpected error occurred' with a generic exit code.

AppHostConnectionResolver now checks ICliHostEnvironment.SupportsInteractiveInput
before prompting:

- Only out-of-scope AppHosts running: returns the command's standard
  not-found error with CliExitCodes.FailedToFindProject.
- Multiple in-scope AppHosts: returns a new actionable error telling the
  user to pass --apphost, also with FailedToFindProject.

Fixes #17619

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 17, 2026 23:00
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18297

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18297"

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 a crash in aspire describe --non-interactive (and other backchannel commands) that occurred when the CLI attempted an interactive AppHost-selection prompt in non-interactive mode. The fix adds early detection of non-interactive mode in AppHostConnectionResolver and returns clean, actionable error messages instead of letting the prompt throw.

Changes:

  • Added non-interactive guards in AppHostConnectionResolver.ResolveConnectionAsync for two prompt paths (multiple in-scope AppHosts and only out-of-scope AppHosts), returning descriptive errors with CliExitCodes.FailedToFindProject.
  • Wired ICliHostEnvironment through CommonCommandServices and all 12 command call sites that construct AppHostConnectionResolver.
  • Added a new MultipleAppHostsNonInteractive resource string with all localization .xlf placeholders, and two targeted unit tests.
Show a summary per file
File Description
src/Aspire.Cli/Backchannel/AppHostConnectionResolver.cs Core fix: checks hostEnvironment.SupportsInteractiveInput before prompting; accepts new ICliHostEnvironment parameter
src/Aspire.Cli/Commands/CommonCommandServices.cs Adds ICliHostEnvironment hostEnvironment as a required constructor parameter with a public property
src/Aspire.Cli/Commands/DescribeCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/ExportCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/LogsCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/StopCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/ResourceCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/WaitCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/McpCallCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/McpToolsCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/TelemetryLogsCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/TelemetrySpansCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/TelemetryTracesCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/TerminalAttachCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Commands/TerminalPsCommand.cs Passes services.HostEnvironment to resolver
src/Aspire.Cli/Resources/SharedCommandStrings.resx New MultipleAppHostsNonInteractive resource string
src/Aspire.Cli/Resources/SharedCommandStrings.Designer.cs Generated property for new resource string
src/Aspire.Cli/Resources/xlf/*.xlf (13 files) Localization placeholders for the new string
tests/Aspire.Cli.Tests/Backchannel/AppHostConnectionResolverTests.cs Two new tests for non-interactive branches + updates existing tests with new parameter
tests/Aspire.Cli.Tests/NuGet/NuGetPackagePrefetcherTests.cs Adds 8th null! for the new CommonCommandServices parameter

Copilot's findings

Files not reviewed (1)
  • src/Aspire.Cli/Resources/SharedCommandStrings.Designer.cs: Generated file
  • Files reviewed: 31/32 changed files
  • Comments generated: 0

@JamesNK JamesNK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix. Both non-interactive prompt paths are correctly guarded, all call sites updated consistently, DI wiring is intact, and the two new tests cover both branches. No issues found.

@radical radical merged commit bf0c0ef into main Jun 18, 2026
342 checks passed
@radical radical deleted the fix/17619-noninteractive-describe branch June 18, 2026 00:54
@github-actions github-actions Bot added this to the 13.5 milestone Jun 18, 2026
@mitchdenny

Copy link
Copy Markdown
Member Author

PR Testing note — #18297 (merged)

This PR is already MERGED (bf0c0ef), so a fresh dogfood artifact isn't produced for it. Its non-interactive behavior was exercised incidentally while dogfood-testing the stacked #18298 build (which sits on top of this fix): every aspire describe … --non-interactive invocation in that run completed cleanly — no "Failed to read input in non-interactive mode" crash and no hang when AppHost selection would otherwise prompt. No issues observed.

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.

[bug] aspire describe --non-interactive crashes with 'An unexpected error occurred' when no AppHost in cwd

5 participants