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
2 changes: 1 addition & 1 deletion src/Aspire.Cli/Commands/DescribeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell

await Task.WhenAll(dashboardUrlsTask, snapshotsTask).ConfigureAwait(false);

var dashboardBaseUrl = (await dashboardUrlsTask.ConfigureAwait(false))?.BaseUrlWithLoginToken;
var dashboardBaseUrl = TelemetryCommandHelpers.ExtractDashboardBaseUrl((await dashboardUrlsTask.ConfigureAwait(false))?.BaseUrlWithLoginToken);
var snapshots = await snapshotsTask.ConfigureAwait(false);

// Pre-resolve colors for all resource names so that assignment is
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static bool HasJsonContentType(HttpResponseMessage response)
/// <summary>
/// Extracts the base URL from a dashboard URL (removes /login?t=... path).
/// </summary>
private static string? ExtractDashboardBaseUrl(string? dashboardUrlWithToken)
internal static string? ExtractDashboardBaseUrl(string? dashboardUrlWithToken)
{
if (string.IsNullOrEmpty(dashboardUrlWithToken))
{
Expand Down
65 changes: 63 additions & 2 deletions tests/Aspire.Cli.Tests/Commands/DescribeCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,71 @@ public async Task DescribeCommand_Follow_TableFormat_DeduplicatesIdenticalSnapsh
Assert.Equal("[redis] Stopping", resourceLines[1]);
}

[Fact]
public async Task DescribeCommand_JsonFormat_StripsLoginPathFromDashboardUrl()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var outputWriter = new TestOutputTextWriter(outputHelper);
var provider = CreateDescribeTestServices(workspace, outputWriter, [
new ResourceSnapshot { Name = "redis", DisplayName = "redis", ResourceType = "Container", State = "Running" },
], dashboardUrlsState: new DashboardUrlsState
{
BaseUrlWithLoginToken = "http://localhost:18888/login?t=abcd1234"
});

var command = provider.GetRequiredService<RootCommand>();
var result = command.Parse("describe --format json");

var exitCode = await result.InvokeAsync().DefaultTimeout();

Assert.Equal(ExitCodeConstants.Success, exitCode);

var jsonOutput = string.Join("", outputWriter.Logs);
var deserialized = JsonSerializer.Deserialize(jsonOutput, ResourcesCommandJsonContext.RelaxedEscaping.ResourcesOutput);

Assert.NotNull(deserialized);
Assert.Single(deserialized.Resources);

Assert.Equal("http://localhost:18888/?resource=redis", deserialized.Resources[0].DashboardUrl);
}

[Fact]
public async Task DescribeCommand_Follow_JsonFormat_StripsLoginPathFromDashboardUrl()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var outputWriter = new TestOutputTextWriter(outputHelper);
var provider = CreateDescribeTestServices(workspace, outputWriter, [
new ResourceSnapshot { Name = "redis", DisplayName = "redis", ResourceType = "Container", State = "Running" },
], dashboardUrlsState: new DashboardUrlsState
{
BaseUrlWithLoginToken = "http://localhost:18888/login?t=abcd1234"
});

var command = provider.GetRequiredService<RootCommand>();
var result = command.Parse("describe --follow --format json");

var exitCode = await result.InvokeAsync().DefaultTimeout();

Assert.Equal(ExitCodeConstants.Success, exitCode);

var jsonLines = outputWriter.Logs
.Where(l => l.TrimStart().StartsWith("{", StringComparison.Ordinal))
.ToList();

Assert.NotEmpty(jsonLines);

var resource = JsonSerializer.Deserialize(jsonLines[0], ResourcesCommandJsonContext.Ndjson.ResourceJson);
Assert.NotNull(resource);

Assert.Equal("http://localhost:18888/?resource=redis", resource.DashboardUrl);
}

private ServiceProvider CreateDescribeTestServices(
TemporaryWorkspace workspace,
TestOutputTextWriter outputWriter,
List<ResourceSnapshot> resourceSnapshots,
bool disableAnsi = false)
bool disableAnsi = false,
DashboardUrlsState? dashboardUrlsState = null)
{
var monitor = new TestAuxiliaryBackchannelMonitor();
var connection = new TestAppHostAuxiliaryBackchannel
Expand All @@ -346,7 +406,8 @@ private ServiceProvider CreateDescribeTestServices(
AppHostPath = Path.Combine(workspace.WorkspaceRoot.FullName, "TestAppHost", "TestAppHost.csproj"),
ProcessId = 1234
},
ResourceSnapshots = resourceSnapshots
ResourceSnapshots = resourceSnapshots,
DashboardUrlsState = dashboardUrlsState
};
monitor.AddConnection("hash1", "socket.hash1", connection);

Expand Down
Loading