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
6 changes: 4 additions & 2 deletions src/Aspire.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,10 @@ internal static async Task DisplayFirstTimeUseNoticeIfNeededAsync(IServiceProvid
var sentinel = serviceProvider.GetRequiredService<IFirstTimeUseNoticeSentinel>();
var isFirstRun = !sentinel.Exists();

// Show banner if explicitly requested OR on first run (unless suppressed by noLogo)
if (showBanner || (isFirstRun && !noLogo))
var hostEnvironment = serviceProvider.GetRequiredService<ICliHostEnvironment>();

// Show banner if explicitly requested OR on first run (unless suppressed by noLogo or non-interactive output)
if (showBanner || (isFirstRun && !noLogo && hostEnvironment.SupportsInteractiveOutput))
{
var bannerService = serviceProvider.GetRequiredService<IBannerService>();
await bannerService.DisplayBannerAsync(cancellationToken);
Expand Down
41 changes: 41 additions & 0 deletions tests/Aspire.Cli.Tests/Commands/RootCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,47 @@ public async Task InformationalFlag_DoesNotCreateSentinel_OnSubsequentFirstRun()
Assert.True(sentinel.WasCreated);
}

[Fact]
public async Task FirstTimeUseNotice_BannerNotDisplayedInNonInteractiveEnvironment()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var sentinel = new TestFirstTimeUseNoticeSentinel { SentinelExists = false };
var bannerService = new TestBannerService();

var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options =>
{
options.FirstTimeUseNoticeSentinelFactory = _ => sentinel;
options.BannerServiceFactory = _ => bannerService;
options.CliHostEnvironmentFactory = _ => TestHelpers.CreateNonInteractiveHostEnvironment();
});
var provider = services.BuildServiceProvider();

await Program.DisplayFirstTimeUseNoticeIfNeededAsync(provider, []);

Assert.False(bannerService.WasBannerDisplayed);
Assert.True(sentinel.WasCreated);
}

[Fact]
public async Task Banner_DisplayedWithExplicitBannerFlag_InNonInteractiveEnvironment()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var sentinel = new TestFirstTimeUseNoticeSentinel { SentinelExists = true }; // Not first run
var bannerService = new TestBannerService();

var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options =>
{
options.FirstTimeUseNoticeSentinelFactory = _ => sentinel;
options.BannerServiceFactory = _ => bannerService;
options.CliHostEnvironmentFactory = _ => TestHelpers.CreateNonInteractiveHostEnvironment();
});
var provider = services.BuildServiceProvider();

await Program.DisplayFirstTimeUseNoticeIfNeededAsync(provider, [CommonOptionNames.Banner]);

Assert.True(bannerService.WasBannerDisplayed);
}

[Fact]
public void SetupCommand_NotAvailable_WhenBundleIsNotAvailable()
{
Expand Down
Loading