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
8 changes: 7 additions & 1 deletion src/Aspire.Cli/Commands/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
#endif

using Aspire.Cli.Bundles;
using Aspire.Cli.Commands.Sdk;
using Aspire.Cli.Configuration;
using Aspire.Cli.Interaction;
Expand Down Expand Up @@ -131,6 +132,7 @@ public RootCommand(
SdkCommand sdkCommand,
SetupCommand setupCommand,
ExtensionInternalCommand extensionInternalCommand,
IBundleService bundleService,
IFeatures featureFlags,
IInteractionService interactionService)
: base(RootCommandStrings.Description)
Expand Down Expand Up @@ -208,7 +210,11 @@ public RootCommand(
Subcommands.Add(agentCommand);
Subcommands.Add(telemetryCommand);
Subcommands.Add(docsCommand);
Subcommands.Add(setupCommand);

if (bundleService.IsBundle)
{
Subcommands.Add(setupCommand);
}

if (featureFlags.IsFeatureEnabled(KnownFeatures.ExecCommandEnabled, false))
{
Expand Down
29 changes: 29 additions & 0 deletions tests/Aspire.Cli.Tests/Commands/RootCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,33 @@ public async Task InformationalFlag_DoesNotCreateSentinel_OnSubsequentFirstRun()
Assert.True(sentinel.WasCreated);
}

[Fact]
public void SetupCommand_NotAvailable_WhenBundleIsNotAvailable()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper);
var provider = services.BuildServiceProvider();

var command = provider.GetRequiredService<RootCommand>();
var hasSetupCommand = command.Subcommands.Any(cmd => cmd.Name == "setup");

Assert.False(hasSetupCommand);
}

[Fact]
public void SetupCommand_Available_WhenBundleIsAvailable()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options =>
{
options.BundleServiceFactory = _ => new TestBundleService(isBundle: true);
});
var provider = services.BuildServiceProvider();

var command = provider.GetRequiredService<RootCommand>();
var hasSetupCommand = command.Subcommands.Any(cmd => cmd.Name == "setup");

Assert.True(hasSetupCommand);
}

}
21 changes: 20 additions & 1 deletion tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static IServiceCollection CreateServiceCollection(TemporaryWorkspace work
// Bundle layout services - return null/no-op implementations to trigger SDK mode fallback
// This ensures backward compatibility: no layout found = use legacy SDK mode
services.AddSingleton(options.LayoutDiscoveryFactory);
services.AddSingleton<IBundleService, NullBundleService>();
services.AddSingleton(options.BundleServiceFactory);
services.AddSingleton<BundleNuGetService>();

// AppHost project handlers - must match Program.cs registration pattern
Expand Down Expand Up @@ -501,6 +501,9 @@ public ISolutionLocator CreateDefaultSolutionLocatorFactory(IServiceProvider ser
// Layout discovery - returns null by default (no bundle layout), causing SDK mode fallback
public Func<IServiceProvider, ILayoutDiscovery> LayoutDiscoveryFactory { get; set; } = _ => new NullLayoutDiscovery();

// Bundle service - returns no-op implementation by default (no embedded bundle)
public Func<IServiceProvider, IBundleService> BundleServiceFactory { get; set; } = _ => new NullBundleService();

public Func<IServiceProvider, IMcpTransportFactory> McpServerTransportFactory { get; set; } = (IServiceProvider serviceProvider) =>
{
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
Expand Down Expand Up @@ -553,6 +556,22 @@ public Task<BundleExtractResult> ExtractAsync(string destinationPath, bool force
=> Task.FromResult<Layout.LayoutConfiguration?>(null);
}

/// <summary>
/// A configurable bundle service for testing bundle-dependent behavior.
/// </summary>
internal sealed class TestBundleService(bool isBundle) : IBundleService
{
public bool IsBundle => isBundle;

public Task EnsureExtractedAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;

public Task<BundleExtractResult> ExtractAsync(string destinationPath, bool force = false, CancellationToken cancellationToken = default)
=> Task.FromResult(isBundle ? BundleExtractResult.AlreadyUpToDate : BundleExtractResult.NoPayload);

public Task<Layout.LayoutConfiguration?> EnsureExtractedAndGetLayoutAsync(CancellationToken cancellationToken = default)
=> Task.FromResult<Layout.LayoutConfiguration?>(null);
}

internal sealed class TestOutputTextWriter : TextWriter
{
private readonly ITestOutputHelper _outputHelper;
Expand Down
Loading