diff --git a/CHANGELOG.md b/CHANGELOG.md index 7242232..7b4fe76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,11 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed +- **`OptionsHelper.Assign` ignores computed properties.** It infers the path an assignment set by + comparing two seeded copies of the options, and counted every get-only leaf as set because it can + never be seeded. A kit with `[EndpointUrl]` or `[ResourceUrl]` carries a `ResourceKitUrl`, whose + `IsAbsolute` is computed, so every `Assign(o => ...)` on that host kit threw "Found + n candidate paths". Get-only leaves are now skipped: they can be neither assigned nor configured. - **`[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 diff --git a/package.json b/package.json index 715e31c..4c82a84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aspire-resourcekit", - "version": "2.2.1", + "version": "2.2.2", "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/", diff --git a/src/src/ResourceKit/OptionsHelper.cs b/src/src/ResourceKit/OptionsHelper.cs index 25f7155..0a7b693 100644 --- a/src/src/ResourceKit/OptionsHelper.cs +++ b/src/src/ResourceKit/OptionsHelper.cs @@ -535,6 +535,17 @@ var property in a.GetType() var av = property.GetValue(a); var bv = property.GetValue(b); + var isLeaf = + TryGetScalarSentinel(property.PropertyType, 1, out _) + || property.PropertyType == typeof(string) + || property.PropertyType == typeof(object); + + // A get-only leaf (a computed value such as ResourceKitUrl.IsAbsolute) cannot be seeded, so it + // is always equal across the two copies; it can be neither assigned nor configured, so it is + // never the path an assignment set. + if (isLeaf && property.SetMethod is null) + continue; + if (TryGetScalarSentinel(property.PropertyType, 1, out _)) { if (Equals(av, bv)) diff --git a/src/tests/ResourceKit.UnitTests/OptionsHelperTests.cs b/src/tests/ResourceKit.UnitTests/OptionsHelperTests.cs index 2ee0725..d66bf97 100644 --- a/src/tests/ResourceKit.UnitTests/OptionsHelperTests.cs +++ b/src/tests/ResourceKit.UnitTests/OptionsHelperTests.cs @@ -553,8 +553,30 @@ public async Task Environment_GivenResourceKitMode_EmitsEnumMemberName() await Assert.That(envVars[expectedKey]).IsEqualTo("LocalDevelopment"); } + // A kit with [EndpointUrl] carries a ResourceKitUrl option, whose IsAbsolute is computed. A + // get-only property can be neither assigned nor configured, so it is never a candidate path. + [Test] + public async Task Assign_GivenOptionsWithAComputedProperty_IgnoresIt() + { + // Arrange + + // Act + var args = OptionsHelper.Assign(static c => c.UseDbGate = false).Build(); + + // Assert + await Assert.That(args.Length).IsEqualTo(1); + await Assert.That(args[0]).IsEqualTo("--Url:UseDbGate=false"); + } + sealed class ModeOptions { public ResourceKitMode Mode { get; set; } } + + sealed class UrlOptions + { + public bool UseDbGate { get; set; } = true; + + public ResourceKitUrl Https { get; set; } = new() { Endpoint = "https", DisplayText = "API" }; + } }