diff --git a/src/Aspire.Cli/Commands/UpdateCommand.cs b/src/Aspire.Cli/Commands/UpdateCommand.cs index 5e9f7716959..ba135960dff 100644 --- a/src/Aspire.Cli/Commands/UpdateCommand.cs +++ b/src/Aspire.Cli/Commands/UpdateCommand.cs @@ -270,7 +270,10 @@ private async Task ExecuteSelfUpdateAsync(ParseResult parseResult, Cancella // for future 'aspire new' and 'aspire init' commands. if (string.IsNullOrEmpty(channel)) { - var channels = new[] { PackageChannelNames.Stable, PackageChannelNames.Staging, PackageChannelNames.Daily }; + var isStagingEnabled = _features.IsFeatureEnabled(KnownFeatures.StagingChannelEnabled, false); + var channels = isStagingEnabled + ? new[] { PackageChannelNames.Stable, PackageChannelNames.Staging, PackageChannelNames.Daily } + : new[] { PackageChannelNames.Stable, PackageChannelNames.Daily }; channel = await InteractionService.PromptForSelectionAsync( "Select the channel to update to:", channels, diff --git a/tests/Aspire.Cli.Tests/Commands/UpdateCommandTests.cs b/tests/Aspire.Cli.Tests/Commands/UpdateCommandTests.cs index 7879770275f..15421cbac10 100644 --- a/tests/Aspire.Cli.Tests/Commands/UpdateCommandTests.cs +++ b/tests/Aspire.Cli.Tests/Commands/UpdateCommandTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections; using System.Runtime.InteropServices; using Aspire.Cli.Backchannel; using Aspire.Cli.Commands; @@ -903,6 +904,94 @@ public async Task UpdateCommand_SelfUpdate_WhenCancelled_DisplaysCancellationMes Assert.Equal(ExitCodeConstants.InvalidCommand, exitCode); } + [Fact] + public async Task UpdateCommand_SelfUpdate_WhenStagingFeatureFlagDisabled_DoesNotShowStagingChannel() + { + using var workspace = TemporaryWorkspace.Create(outputHelper); + + IEnumerable? capturedChoices = null; + + var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options => + { + options.InteractionServiceFactory = _ => new TestInteractionService() + { + PromptForSelectionCallback = (prompt, choices, formatter, ct) => + { + capturedChoices = choices; + return PackageChannelNames.Stable; + } + }; + + options.CliDownloaderFactory = _ => new TestCliDownloader(workspace.WorkspaceRoot) + { + DownloadLatestCliAsyncCallback = (channel, ct) => + { + var archivePath = Path.Combine(workspace.WorkspaceRoot.FullName, "test-cli.tar.gz"); + File.WriteAllText(archivePath, "fake archive"); + return Task.FromResult(archivePath); + } + }; + }); + + var provider = services.BuildServiceProvider(); + + var command = provider.GetRequiredService(); + var result = command.Parse("update --self"); + + await result.InvokeAsync().DefaultTimeout(); + + Assert.NotNull(capturedChoices); + var channelList = capturedChoices.Cast().ToList(); + Assert.DoesNotContain(PackageChannelNames.Staging, channelList); + Assert.Contains(PackageChannelNames.Stable, channelList); + Assert.Contains(PackageChannelNames.Daily, channelList); + } + + [Fact] + public async Task UpdateCommand_SelfUpdate_WhenStagingFeatureFlagEnabled_ShowsStagingChannel() + { + using var workspace = TemporaryWorkspace.Create(outputHelper); + + IEnumerable? capturedChoices = null; + + var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options => + { + options.EnabledFeatures = [KnownFeatures.StagingChannelEnabled]; + + options.InteractionServiceFactory = _ => new TestInteractionService() + { + PromptForSelectionCallback = (prompt, choices, formatter, ct) => + { + capturedChoices = choices; + return PackageChannelNames.Stable; + } + }; + + options.CliDownloaderFactory = _ => new TestCliDownloader(workspace.WorkspaceRoot) + { + DownloadLatestCliAsyncCallback = (channel, ct) => + { + var archivePath = Path.Combine(workspace.WorkspaceRoot.FullName, "test-cli.tar.gz"); + File.WriteAllText(archivePath, "fake archive"); + return Task.FromResult(archivePath); + } + }; + }); + + var provider = services.BuildServiceProvider(); + + var command = provider.GetRequiredService(); + var result = command.Parse("update --self"); + + await result.InvokeAsync().DefaultTimeout(); + + Assert.NotNull(capturedChoices); + var channelList = capturedChoices.Cast().ToList(); + Assert.Contains(PackageChannelNames.Staging, channelList); + Assert.Contains(PackageChannelNames.Stable, channelList); + Assert.Contains(PackageChannelNames.Daily, channelList); + } + [Fact] public async Task UpdateCommand_SelfOption_IsAvailableAndParseable() {