From 8aa0675205c9ba567ecc9c8bd70d9cd8f63d796e Mon Sep 17 00:00:00 2001 From: Kieron Lanning Date: Fri, 20 Nov 2026 09:39:00 +0000 Subject: [PATCH 1/2] fix: endpoint urls leave aspire's hidden localhost copy alone --- CHANGELOG.md | 5 ++ docs/wiki/concepts/Groups-and-URLs.md | 7 +- src/src/ResourceKit/ResourceKitUrl.cs | 34 ++++++--- .../ResourceKitUrlTests.cs | 74 +++++++++++++++++++ 4 files changed, 107 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed84110..7242232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,11 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed +- **`[EndpointUrl]` no longer reveals Aspire's hidden `localhost` URL.** With a dev domain, Aspire shows + the dev-domain URL and keeps a details-only `localhost` copy of the same endpoint. `ResourceKitUrl.Apply` + set the display text and `SummaryAndDetails` on both, so the dashboard showed two links with the same + name, one of them on `localhost`. It now customises only the URLs Aspire shows (all of them when it + shows none), and a relative `[ResourceUrl]` resolves against the shown URL before the hidden copy. - **Aspire 17 migration guidance no longer loses `Projects.*` projects.** `Aspire.AppHost.Sdk` marked every `` `IsAspireProjectResource=true`; `Microsoft.NET.Sdk` does not, so a plain reference stops generating its `Projects.*` type and the project's path is lost. The migration skill diff --git a/docs/wiki/concepts/Groups-and-URLs.md b/docs/wiki/concepts/Groups-and-URLs.md index c4f9099..49aeca9 100644 --- a/docs/wiki/concepts/Groups-and-URLs.md +++ b/docs/wiki/concepts/Groups-and-URLs.md @@ -155,11 +155,14 @@ sealed partial class ExampleAPIKit { /* ... */ } - **`[ResourceUrl(name, url)]`** adds a link. - An absolute URL is shown as it is. - A relative URL is resolved against the endpoint named by `Endpoint`. Without one, it uses the - `https` endpoint, then the `http` endpoint, then the first endpoint. + `https` endpoint, then the `http` endpoint, then the first endpoint. Within an endpoint it uses the + URL the dashboard shows (the dev-domain address) before Aspire's details-only `localhost` copy. - Only **one** URL is added. This differs from Aspire's own `WithUrl("/health")`, which rewrites the path of *every* endpoint URL on the resource. - **`[EndpointUrl(endpoint)]`** changes the URL Aspire already shows for an endpoint: its `DisplayText` - and `DisplayLocation`. + and `DisplayLocation`. When a launch profile gives the endpoint a dev domain, Aspire also keeps a + details-only `localhost` copy of it; that copy is left hidden and unlabelled, so the dashboard shows + one link with your text. The copy is changed only when Aspire shows no URL for the endpoint. - A URL's name is the key for its options. An `[EndpointUrl]` is named after its endpoint in PascalCase, so `otlp-grpc` becomes `OtlpGrpc`. Names must be unique on a kit or group (SG0026). diff --git a/src/src/ResourceKit/ResourceKitUrl.cs b/src/src/ResourceKit/ResourceKitUrl.cs index 9e7fa7f..9b346e7 100644 --- a/src/src/ResourceKit/ResourceKitUrl.cs +++ b/src/src/ResourceKit/ResourceKitUrl.cs @@ -13,7 +13,9 @@ namespace Purview.Aspire.ResourceKit; /// /// /// A URL without a customises the URL Aspire already shows for , -/// changing its and . +/// changing its and . When Aspire also keeps a +/// details-only copy of that endpoint's URL (the localhost address beside a dev domain), the copy +/// is left as it is; it is customised only when Aspire shows no URL for the endpoint. /// /// /// The type is mutable so generated options can bind it from configuration, for example @@ -84,19 +86,24 @@ IList resourceUrls if (url.Url is null) { - var matched = false; - foreach (var endpointUrl in endpointUrls.Where(u => IsEndpoint(u, url.Endpoint))) + ResourceUrlAnnotation[] matches = [.. endpointUrls.Where(u => IsEndpoint(u, url.Endpoint))]; + if (matches.Length == 0) + { + unresolved.Add(url); + continue; + } + + // Aspire keeps a details-only copy of an endpoint's URL beside its dev-domain URL. Customise + // the URLs it shows; touch the hidden ones only when it shows none. + ResourceUrlAnnotation[] shown = [.. matches.Where(static u => IsShown(u))]; + foreach (var endpointUrl in shown.Length > 0 ? shown : matches) { - matched = true; if (url.DisplayText is not null) endpointUrl.DisplayText = url.DisplayText; endpointUrl.DisplayLocation = url.DisplayLocation; } - if (!matched) - unresolved.Add(url); - continue; } @@ -136,15 +143,20 @@ IList resourceUrls static ResourceUrlAnnotation? SelectBaseUrl(ResourceUrlAnnotation[] endpointUrls, string? endpoint) { + // Resolve against a URL the dashboard shows before a details-only copy of the same endpoint. + ResourceUrlAnnotation[] ordered = [.. endpointUrls.OrderBy(static u => IsShown(u) ? 0 : 1)]; + if (endpoint is not null) - return endpointUrls.FirstOrDefault(u => IsEndpoint(u, endpoint)); + return ordered.FirstOrDefault(u => IsEndpoint(u, endpoint)); // Prefer the https endpoint, then http, then any. - return endpointUrls.FirstOrDefault(static u => IsEndpoint(u, "https")) - ?? endpointUrls.FirstOrDefault(static u => IsEndpoint(u, "http")) - ?? endpointUrls.FirstOrDefault(); + return ordered.FirstOrDefault(static u => IsEndpoint(u, "https")) + ?? ordered.FirstOrDefault(static u => IsEndpoint(u, "http")) + ?? ordered.FirstOrDefault(); } + static bool IsShown(ResourceUrlAnnotation url) => url.DisplayLocation != UrlDisplayLocation.DetailsOnly; + static bool IsEndpoint(ResourceUrlAnnotation url, string? endpoint) => endpoint is not null && string.Equals(url.Endpoint?.EndpointName, endpoint, StringComparison.OrdinalIgnoreCase); diff --git a/src/tests/ResourceKit.UnitTests/ResourceKitUrlTests.cs b/src/tests/ResourceKit.UnitTests/ResourceKitUrlTests.cs index f058460..df19f03 100644 --- a/src/tests/ResourceKit.UnitTests/ResourceKitUrlTests.cs +++ b/src/tests/ResourceKit.UnitTests/ResourceKitUrlTests.cs @@ -100,6 +100,61 @@ public async Task Apply_GivenEndpointUrlWithoutUrl_CustomisesTheEndpointsUrl() await Assert.That(urls[1].DisplayText).IsNull(); } + // With a dev domain, Aspire shows the dev-domain URL and keeps a localhost copy of the same endpoint + // in the details only. Customising the endpoint must not reveal or relabel that copy, or the + // dashboard shows two links with one name, one of them on localhost. + [Test] + public async Task Apply_GivenEndpointUrlWithoutUrl_LeavesTheEndpointsHiddenUrlsAlone() + { + // Arrange + var urls = CreateDevDomainUrls(); + ResourceKitUrl url = new() { Endpoint = "https", DisplayText = "Web" }; + + // Act + var unresolved = ResourceKitUrl.Apply([url], urls); + + // Assert + await Assert.That(unresolved).IsEmpty(); + await Assert.That(urls[0].DisplayText).IsEqualTo("Web"); + await Assert.That(urls[0].DisplayLocation).IsEqualTo(UrlDisplayLocation.SummaryAndDetails); + await Assert.That(urls[1].DisplayText).IsNull(); + await Assert.That(urls[1].DisplayLocation).IsEqualTo(UrlDisplayLocation.DetailsOnly); + } + + // When Aspire shows no URL for the endpoint at all, the customisation is all there is to apply to. + [Test] + public async Task Apply_GivenEndpointUrlWhoseUrlsAreAllHidden_CustomisesThem() + { + // Arrange + var urls = CreateDevDomainUrls(); + urls[0].DisplayLocation = UrlDisplayLocation.DetailsOnly; + ResourceKitUrl url = new() { Endpoint = "https", DisplayText = "Web" }; + + // Act + ResourceKitUrl.Apply([url], urls); + + // Assert + await Assert.That(urls[0].DisplayText).IsEqualTo("Web"); + await Assert.That(urls[1].DisplayText).IsEqualTo("Web"); + await Assert.That(urls[1].DisplayLocation).IsEqualTo(UrlDisplayLocation.SummaryAndDetails); + } + + // A relative URL is built on the endpoint URL the dashboard shows, not on the hidden localhost copy. + [Test] + public async Task Apply_GivenRelativeUrl_ResolvesAgainstTheEndpointsShownUrl() + { + // Arrange + var urls = CreateDevDomainUrls(); + urls.Reverse(); + ResourceKitUrl url = new() { Url = "/health", Endpoint = "https" }; + + // Act + ResourceKitUrl.Apply([url], urls); + + // Assert + await Assert.That(urls[^1].Url).IsEqualTo("https://web.dev.localhost:7311/health"); + } + [Test] public async Task Apply_GivenDisabledUrl_SkipsIt() { @@ -205,6 +260,25 @@ static List CreateEndpointUrls() ]; } + // The pair Aspire computes for an endpoint whose launch profile gives it a dev domain. + static List CreateDevDomainUrls() + { + var builder = DistributedApplication.CreateBuilder(); + var container = builder.AddContainer("web", "image").WithHttpsEndpoint(port: 7311, name: "https"); + var https = container.GetEndpoint("https"); + + return + [ + new() { Url = "https://web.dev.localhost:7311", Endpoint = https }, + new() + { + Url = "https://localhost:7311", + Endpoint = https, + DisplayLocation = UrlDisplayLocation.DetailsOnly, + }, + ]; + } + sealed class TestHostKit : HostKitBase; sealed class UrlResourceKit(TestHostKit hostKit, IEnumerable urls) From 5e23f3c6f5ba4f14f37449a73c475c9890660839 Mon Sep 17 00:00:00 2001 From: Kieron Lanning Date: Fri, 20 Nov 2026 09:50:57 +0000 Subject: [PATCH 2/2] chore: bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c64a00..715e31c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aspire-resourcekit", - "version": "2.2.0", + "version": "2.2.1", "description": "Source-generator-powered framework for structuring .NET Aspire AppHost resource composition as strongly typed, test-friendly classes.", "keywords": [], "homepage": "https://purview.dev/projects/aspire-resourcekit/",