diff --git a/src/Aspire.Cli/Commands/UpdateCommand.cs b/src/Aspire.Cli/Commands/UpdateCommand.cs index b177b538f49..20db126e622 100644 --- a/src/Aspire.Cli/Commands/UpdateCommand.cs +++ b/src/Aspire.Cli/Commands/UpdateCommand.cs @@ -271,7 +271,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 b0a1d1e1d41..f91fa76b24d 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; @@ -905,6 +906,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 TestConsoleInteractionService() + { + 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 TestConsoleInteractionService() + { + 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() {