Skip to content

Honor resource command confirmations in CLI#16669

Open
maddymontaquila wants to merge 1 commit intomainfrom
fix-cli-resource-command-confirmation
Open

Honor resource command confirmations in CLI#16669
maddymontaquila wants to merge 1 commit intomainfrom
fix-cli-resource-command-confirmation

Conversation

@maddymontaquila
Copy link
Copy Markdown
Contributor

Description

Make aspire resource <resource> <command> honor resource command confirmation messages before executing commands. The CLI now reads ConfirmationMessage from resource snapshots, prompts before invoking commands that require confirmation, and supports --non-interactive as an explicit automation override that accepts the confirmation without prompting.

This also flows confirmation metadata through the AppHost backchannel and CLI resource JSON model, updates the generated Aspire agent skill guidance, and adds focused CLI tests for confirmed, declined, and non-interactive command execution.

Validation:

  • dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.ResourceCommandHelperTests" --filter-class "*.ResourceCommandTests" --filter-class "*.ResourceSnapshotMapperTests" --filter-class "*.AgentInitCommandTests" --filter-class "*.CommonAgentApplicatorsTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • dotnet build /t:UpdateXlf src\Aspire.Cli\Aspire.Cli.csproj

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Flow resource command confirmation metadata through the backchannel and prompt before executing confirmed commands from aspire resource. Add --non-interactive as an explicit confirmation override for automation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 1, 2026 19:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

🚀 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 -- 16669

Or

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

@maddymontaquila maddymontaquila added this to the 13.4 milestone May 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 makes aspire resource <resource> <command> honor per-command confirmation metadata emitted by the AppHost. The CLI now reads a ConfirmationMessage from resource snapshots, prompts the user before executing confirmed commands, and introduces a --non-interactive automation override intended to accept confirmations without prompting.

Changes:

  • Flow a new ConfirmationMessage field from Hosting backchannel snapshots through the CLI resource JSON model.
  • Add confirmation gating to ResourceCommandHelper prior to invoking backchannel command execution.
  • Add/extend CLI unit tests, update skill guidance docs, and update localization resources for the new option description.

Reviewed changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/TestServices/TestAppHostAuxiliaryBackchannel.cs Adds handler/call-count support to validate whether commands were executed in tests.
tests/Aspire.Cli.Tests/Commands/ResourceCommandTests.cs Adds a parsing/invocation test for --non-interactive on resource.
tests/Aspire.Cli.Tests/Commands/ResourceCommandHelperTests.cs Adds coverage for confirmed/declined/non-interactive confirmation flows.
tests/Aspire.Cli.Tests/Backchannel/ResourceSnapshotMapperTests.cs Verifies ConfirmationMessage is mapped into CLI resource JSON.
src/Shared/Model/Serialization/ResourceJson.cs Extends ResourceCommandJson with ConfirmationMessage.
src/Aspire.Hosting/Backchannel/BackchannelDataTypes.cs Extends ResourceSnapshotCommand with ConfirmationMessage.
src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs Flows ConfirmationMessage into snapshot RPC payloads.
src/Aspire.Cli/Commands/ResourceCommandHelper.cs Adds confirmation lookup + prompt prior to executing resource commands.
src/Aspire.Cli/Commands/ResourceCommand.cs Adds --non-interactive option and passes a confirmation binding to helper methods.
src/Aspire.Cli/Backchannel/ResourceSnapshotMapper.cs Maps ConfirmationMessage into ResourceCommandJson.
src/Aspire.Cli/Resources/ResourceCommandStrings.resx Adds localized string for --non-interactive description.
src/Aspire.Cli/Resources/ResourceCommandStrings.Designer.cs Adds strongly-typed accessor for the new resource string.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.cs.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.de.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.es.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.fr.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.it.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.ja.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.ko.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.pl.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.pt-BR.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.ru.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.tr.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.zh-Hans.xlf Adds NonInteractiveOptionDescription translation unit.
src/Aspire.Cli/Resources/xlf/ResourceCommandStrings.zh-Hant.xlf Adds NonInteractiveOptionDescription translation unit.
.agents/skills/aspire/references/resource-management.md Updates agent guidance to mention confirmation prompts and --non-interactive.
Files not reviewed (1)
  • src/Aspire.Cli/Resources/ResourceCommandStrings.Designer.cs: Language not supported

Comment on lines +36 to +39
private static readonly Option<bool> s_nonInteractiveOption = new("--non-interactive")
{
Description = ResourceCommandStrings.NonInteractiveOptionDescription
};
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

--non-interactive is already defined as a recursive global option on RootCommand (see RootCommand.NonInteractiveOption). Adding a second Option<bool>("--non-interactive") on ResourceCommand can create ambiguous binding depending on where the flag appears (e.g. aspire --non-interactive resource ... may bind to the root option while this code reads the resource-scoped option), which would break the intended auto-confirm behavior in non-interactive runs. Consider removing the resource-scoped option and instead using RootCommand.NonInteractiveOption for PromptBinding.Create(...) (or introduce a distinct option name for the resource-confirmation override).

Suggested change
private static readonly Option<bool> s_nonInteractiveOption = new("--non-interactive")
{
Description = ResourceCommandStrings.NonInteractiveOptionDescription
};
private static readonly Option<bool> s_nonInteractiveOption = RootCommand.NonInteractiveOption;

Copilot uses AI. Check for mistakes.
return null;
}

var command = resources[0].Commands.FirstOrDefault(c => string.Equals(c.Name, commandName, StringComparison.OrdinalIgnoreCase));
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

GetConfirmationMessageAsync looks up the command by name but doesn't consider the command state. If a command exists but is Disabled/Hidden, the CLI will still prompt for confirmation and then the backchannel execution will fail anyway, which is a confusing flow. Consider filtering to State == "Enabled" (or whatever enabled value is expected) before prompting, or skipping confirmation when the command isn't executable.

Suggested change
var command = resources[0].Commands.FirstOrDefault(c => string.Equals(c.Name, commandName, StringComparison.OrdinalIgnoreCase));
var command = resources[0].Commands.FirstOrDefault(c =>
string.Equals(c.Name, commandName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(c.State, "Enabled", StringComparison.OrdinalIgnoreCase));

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

🎬 CLI E2E Test Recordings — 76 recordings uploaded (commit facce15)

View all recordings
Status Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InteractiveCSharpInitCreatesExpectedFiles ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LatestCliCanStartStableChannelAppHost ▶️ View Recording
LatestCliCanStartStableChannelTypeScriptAppHost ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterAppCore ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #25229282820

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.

2 participants