Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15856Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15856" |
There was a problem hiding this comment.
Pull request overview
This PR adds polyglot-safe endpoint mutation callback exports so TypeScript/Java/Python AppHosts can update already-created endpoints (e.g., auto-created http endpoints) by name without changing existing endpoint creation semantics.
Changes:
- Introduces
EndpointUpdateContextas an ATS-safe wrapper for mutating endpoint settings in polyglot callbacks. - Adds new exported mutation capabilities:
withEndpointCallback(...)andwithHttpEndpointCallback(...)(plus generated SDK surface updates). - Updates polyglot AppHost samples and codegen snapshots to validate the new callback APIs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts | Adds usage coverage for endpoint callback mutation APIs in TS AppHost sample. |
| tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py | Adds usage coverage for endpoint callback mutation APIs in Python AppHost sample. |
| tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java | Adds usage coverage for endpoint callback mutation APIs in Java AppHost sample. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts | Updates TS generated surface to include EndpointUpdateContext and callback methods/options. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt | Adds the new capability IDs to the TS codegen capability snapshot. |
| tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py | Updates Python generated surface to include EndpointUpdateContext and callback methods/kwargs. |
| tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java | Updates Java generated surface to include EndpointUpdateContext and callback methods/options. |
| src/Aspire.Hosting/ResourceBuilderExtensions.cs | Adds internal exported endpoint mutation methods and updates polyglot guidance/ignore reason text. |
| src/Aspire.Hosting/ApplicationModel/EndpointUpdateContext.cs | Introduces the new exported context wrapper type for endpoint mutation. |
...ire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🎬 CLI E2E Test Recordings — 55 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #23963660138 |
| } | ||
|
|
||
| [AspireExport(Description = "Updates an HTTP endpoint via callback")] | ||
| internal static IResourceBuilder<T> WithHttpEndpointCallback<T>(this IResourceBuilder<T> builder, Action<EndpointUpdateContext> callback, [EndpointName] string? name = null, bool createIfNotExists = true) where T : IResourceWithEndpoints |
There was a problem hiding this comment.
There's also WithHttpsEndpointCallback?
JamesNK
left a comment
There was a problem hiding this comment.
3 comments: 1 likely bug (missing WithHttpsEndpointCallback symmetry), 1 unnecessary complexity (reflection in test when InternalsVisibleTo is available), 1 minor (unrelated blank line removal).
| } | ||
|
|
||
| [AspireExport(Description = "Updates an HTTP endpoint via callback")] | ||
| internal static IResourceBuilder<T> WithHttpEndpointCallback<T>(this IResourceBuilder<T> builder, Action<EndpointUpdateContext> callback, [EndpointName] string? name = null, bool createIfNotExists = true) where T : IResourceWithEndpoints |
There was a problem hiding this comment.
There's WithEndpointCallback and WithHttpEndpointCallback here but no WithHttpsEndpointCallback. The public API has the symmetric trio (WithEndpoint / WithHttpEndpoint / WithHttpsEndpoint), so the callback surface should match.
The polyglot samples work around this by calling withEndpointCallback("callback-https", ...), but when createIfNotExists is true that creates a bare TCP endpoint (via WithEndpoint(endpointName, ...)) rather than one with scheme: "https" — so the created endpoint would have the wrong URI scheme and transport.
| using var builder = TestDistributedApplicationBuilder.Create(); | ||
|
|
||
| var container = builder.AddContainer("app", "image"); | ||
| var endpointUpdateContextType = typeof(ContainerResource).Assembly.GetType("Aspire.Hosting.ApplicationModel.EndpointUpdateContext", throwOnError: true)!; |
There was a problem hiding this comment.
This test uses Expression.Lambda, Assembly.GetType, and MethodInfo.Invoke to call WithHttpEndpointCallback, but all of that is unnecessary — Aspire.Hosting.csproj already grants InternalsVisibleTo to Aspire.Hosting.Tests, so both WithHttpEndpointCallback and EndpointUpdateContext are directly accessible.
This could be simplified to:
[Fact]
public void WithHttpEndpointCallbackCreatesHttpEndpointWhenMissing()
{
using var builder = TestDistributedApplicationBuilder.Create();
var container = builder.AddContainer("app", "image")
.WithHttpEndpointCallback(_ => { }, name: "callback-http");
var endpoint = container.Resource.Annotations.OfType<EndpointAnnotation>()
.Single(endpoint => string.Equals(endpoint.Name, "callback-http", EndpointAnnotationName));
Assert.Equal("http", endpoint.UriScheme);
Assert.Equal("http", endpoint.Transport);
Assert.Equal(ProtocolType.Tcp, endpoint.Protocol);
}| return builder; | ||
| } | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
Nit: The blank line between WithExternalHttpEndpoints and the GetEndpoint XML doc comment was removed — appears to be an unrelated formatting change.
Description
Add polyglot-safe endpoint mutation callbacks for AppHosts so existing endpoints can be updated by name without changing the creation semantics of
withEndpoint(...)orwithHttpEndpoint(...).This change introduces an ATS-safe
EndpointUpdateContextwrapper and exports separate callback-based mutation APIs:withEndpointCallback(...)withHttpEndpointCallback(...)These are generated into the TypeScript, Java, and Python AppHost surfaces and covered by the shared polyglot apphost samples. This enables scenarios like mutating an auto-created
httpendpoint, including the Vite endpoint case from the issue.Fixes #15854
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: