Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Aspire.Cli/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ private async Task<int> 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,
Expand Down
89 changes: 89 additions & 0 deletions tests/Aspire.Cli.Tests/Commands/UpdateCommandTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<RootCommand>();
var result = command.Parse("update --self");

await result.InvokeAsync().DefaultTimeout();

Assert.NotNull(capturedChoices);
var channelList = capturedChoices.Cast<string>().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<RootCommand>();
var result = command.Parse("update --self");

await result.InvokeAsync().DefaultTimeout();

Assert.NotNull(capturedChoices);
var channelList = capturedChoices.Cast<string>().ToList();
Assert.Contains(PackageChannelNames.Staging, channelList);
Assert.Contains(PackageChannelNames.Stable, channelList);
Assert.Contains(PackageChannelNames.Daily, channelList);
}

[Fact]
public async Task UpdateCommand_SelfOption_IsAvailableAndParseable()
{
Expand Down
Loading