Skip to content

Handle non-interactive interaction service availability for resource commands - #16973

Merged
James Newton-King (JamesNK) merged 6 commits into
microsoft:mainfrom
JamesNK:fix/interaction-service-noninteractive-resource-command
May 13, 2026
Merged

Handle non-interactive interaction service availability for resource commands#16973
James Newton-King (JamesNK) merged 6 commits into
microsoft:mainfrom
JamesNK:fix/interaction-service-noninteractive-resource-command

Conversation

@JamesNK

Copy link
Copy Markdown
Member

Summary

  • track non-interactive resource command execution in InteractionService using an AsyncLocal scope
  • make IInteractionService.IsAvailable return false during non-interactive CLI resource command execution
  • update EnsureServiceAvailable error text to clarify it can be unavailable in non-interactive CLI command contexts
  • add/adjust tests across hosting, CLI unit, and CLI E2E coverage

Changes

  • ResourceCommandService now scopes command execution with InteractionService.StartNonInteractiveScope() when NonInteractive is true
  • InteractionService now:
    • tracks non-interactive scope with AsyncLocal<bool>
    • checks scope in IsAvailable
    • has updated EnsureServiceAvailable exception message
  • Added/updated tests:
    • hosting tests for IsAvailable non-interactive scope behavior
    • hosting tests for non-interactive vs interactive command execution behavior
    • CLI unit test for resource command failure path with interaction service unavailable
    • new CLI end-to-end ResourceCommandTests that executes aspire resource against a command that prompts and fails due to EnsureServiceAvailable

Validation

  • 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=false

Fixes #16720

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.
@github-actions

github-actions Bot commented May 12, 2026

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 -- 16973

Or

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

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 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 in InteractionService that forces IsAvailable to false while active.
  • Scope resource command execution (ResourceCommandService) so command callbacks run under the non-interactive scope when NonInteractive=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.

Comment thread src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs
Comment thread src/Aspire.Hosting/InteractionService.cs Outdated
Comment thread tests/Aspire.Cli.EndToEnd.Tests/ResourceCommandTests.cs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@JamesNK James Newton-King (JamesNK) added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 12, 2026

@davidfowl David Fowler (davidfowl) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes me feel sick but it works

@JamesNK
James Newton-King (JamesNK) enabled auto-merge (squash) May 12, 2026 08:04
@github-actions

Copy link
Copy Markdown
Contributor

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.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

Matched test failure patterns (1 test)
  • Aspire.Cli.EndToEnd.Tests.KubernetesDeployWithSqlServerTests.DeployK8sWithSqlServer — Unable to access container registry during publish

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[13.3] Interaction Service is unaware if command is invoked from CLI

4 participants