Handle non-interactive interaction service availability for resource commands - #16973
Conversation
Track non-interactive resource command execution in InteractionService via AsyncLocal and make IsAvailable reflect it. Update EnsureServiceAvailable error text for CLI non-interactive command context and add/adjust hosting, CLI unit, and CLI E2E coverage.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16973Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16973" |
There was a problem hiding this comment.
Pull request overview
This PR updates Aspire Hosting’s InteractionService and resource command execution so that resource commands executed in non-interactive CLI contexts can detect that prompting isn’t allowed (via IInteractionService.IsAvailable == false), and adds coverage across hosting, CLI unit, and CLI E2E tests.
Changes:
- Add an
AsyncLocal-backed non-interactive scope inInteractionServicethat forcesIsAvailabletofalsewhile active. - Scope resource command execution (
ResourceCommandService) so command callbacks run under the non-interactive scope whenNonInteractive=true. - Add/adjust hosting + CLI unit + CLI E2E tests for the non-interactive behavior and failure path.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs | Wraps command execution in a non-interactive scope when NonInteractive=true. |
| src/Aspire.Hosting/InteractionService.cs | Introduces AsyncLocal non-interactive scoping and updates the unavailable-service error message. |
| tests/Aspire.Hosting.Tests/InteractionServiceTests.cs | Adds tests for non-interactive scoping and AsyncLocal flow/nesting. |
| tests/Aspire.Hosting.Tests/ResourceCommandServiceTests.cs | Validates IsAvailable behavior during interactive vs non-interactive command execution. |
| tests/Aspire.Cli.Tests/Commands/ResourceCommandTests.cs | Adds CLI unit coverage for failure path when interaction service is unavailable. |
| tests/Aspire.Cli.EndToEnd.Tests/ResourceCommandTests.cs | Adds an E2E scenario verifying a resource command that requires prompting fails appropriately. |
|
Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
|
David Fowler (davidfowl)
left a comment
There was a problem hiding this comment.
Makes me feel sick but it works
|
Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
Matched test failure patterns (1 test)
|
adca9d0
into
microsoft:main
Summary
InteractionServiceusing anAsyncLocalscopeIInteractionService.IsAvailablereturnfalseduring non-interactive CLI resource command executionEnsureServiceAvailableerror text to clarify it can be unavailable in non-interactive CLI command contextsChanges
ResourceCommandServicenow scopes command execution withInteractionService.StartNonInteractiveScope()whenNonInteractiveistrueInteractionServicenow:AsyncLocal<bool>IsAvailableEnsureServiceAvailableexception messageIsAvailablenon-interactive scope behaviorResourceCommandTeststhat executesaspire resourceagainst a command that prompts and fails due toEnsureServiceAvailableValidation
dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj -- --filter-method "*.ResourceCommand_FailsWhenCommandUsesInteractionService" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"dotnet build tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj /p:TreatWarningsAsErrors=falseFixes #16720