Skip to content

Add polyglot exports for Aspire.Hosting.Python#14960

Merged
davidfowl merged 1 commit intorelease/13.2from
sebros/polyglot-python
Mar 5, 2026
Merged

Add polyglot exports for Aspire.Hosting.Python#14960
davidfowl merged 1 commit intorelease/13.2from
sebros/polyglot-python

Conversation

@sebastienros
Copy link
Copy Markdown
Contributor

Related to #14069

Adds [AspireExport] attributes to Aspire.Hosting.Python public extension methods and includes the TypeScript ValidationAppHost playground.

Replaces #14897 (rebased on release/13.2).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 5, 2026 01:06
@sebastienros sebastienros added this to the 13.2 milestone Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14960

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14960"

@sebastienros sebastienros requested a review from davidfowl March 5, 2026 01:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes Aspire.Hosting.Python public extension methods to the polyglot capability system via [AspireExport] and adds a TypeScript “ValidationAppHost” playground to exercise the generated TypeScript SDK.

Changes:

  • Added [AspireExport] attributes to Python hosting extension methods for polyglot exports.
  • Added a TypeScript ValidationAppHost playground (TS config + example apphost).
  • Added generated TypeScript SDK modules (transport/base/aspire) and codegen hash metadata.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs Adds [AspireExport] metadata for Python-related builder extension methods.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/tsconfig.json Configures TypeScript compilation settings for the ValidationAppHost playground.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/package.json Defines Node/TS dependencies and scripts for running the playground.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/apphost.ts Adds a TS apphost that invokes the new exported Python capabilities.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/apphost.run.json Adds run profile configuration for the playground.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/.modules/transport.ts Implements the JSON-RPC transport, handle wrapping, callbacks, and cancellation plumbing.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/.modules/base.ts Adds base SDK types (ReferenceExpression, collection wrappers) used by generated code.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/.modules/aspire.ts Adds generated TypeScript SDK bindings for capabilities, including Python exports.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/.modules/.codegen-hash Tracks the generator output hash for the SDK modules.
playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/.aspire/settings.json Declares Aspire tooling settings for running the TS apphost and package mapping.
Files not reviewed (1)
  • playground/polyglot/TypeScript/Aspire.Hosting.Python/ValidationAppHost/package-lock.json: Language not supported

Comment on lines +469 to +472
async toJSON(): Promise<MarshalledHandle> {
const handle = await this._ensureHandle();
return handle.toJSON();
}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toJSON() is declared async and returns a Promise. JSON.stringify() (and most JSON-RPC serializers) will not await toJSON(), which can result in {} or an incorrect payload on the wire. Make toJSON() synchronous (returning a MarshalledHandle), and expose a separate toHandle()/resolve() method for async resolution if needed (or ensure the handle is eagerly resolved before the object can be serialized).

Suggested change
async toJSON(): Promise<MarshalledHandle> {
const handle = await this._ensureHandle();
return handle.toJSON();
}
/**
* Resolves and returns the underlying handle in marshalled form.
* Use this method when you need to asynchronously obtain a value
* suitable for transport or manual JSON serialization.
*/
async toHandle(): Promise<MarshalledHandle> {
const handle = await this._ensureHandle();
return handle.toJSON();
}
/**
* Synchronous JSON representation.
*
* This method cannot perform asynchronous handle resolution, so it will
* throw if called directly. Call {@link toHandle} first and serialize
* the returned value instead.
*/
toJSON(): MarshalledHandle {
throw new Error(
'AspireDict.toJSON() is synchronous and cannot resolve handles. ' +
'Call await dict.toHandle() to obtain a serializable handle first.'
);
}

Copilot uses AI. Check for mistakes.
Comment on lines +310 to +314
toJSON(): MarshalledHandle {
if (this._resolvedHandle) {
return this._resolvedHandle.toJSON();
}
return this._handleOrContext.toJSON();
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the list handle requires resolution via _getterCapabilityId, toJSON() falls back to serializing _handleOrContext (the context handle), not the actual list handle. If an AspireList instance is ever passed as an argument to a capability, this will send the wrong handle type/value and can break server-side invocation. Consider removing toJSON() from AspireList (forcing explicit list operations only), or ensure AspireList always stores/uses a real list handle (eagerly resolve on creation) so toJSON() is always correct.

Suggested change
toJSON(): MarshalledHandle {
if (this._resolvedHandle) {
return this._resolvedHandle.toJSON();
}
return this._handleOrContext.toJSON();
toJSON(): MarshalledHandle {
if (!this._resolvedHandle) {
throw new Error(
'AspireList handle is not yet resolved and cannot be serialized. ' +
'Use explicit list operations (e.g., toArray) instead of passing AspireList directly.'
);
}
return this._resolvedHandle.toJSON();

Copilot uses AI. Check for mistakes.
Comment on lines +332 to +333
let currentClient: AspireClient | null = null;

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentClient is a mutable singleton shared across the module and overwritten on each AspireClient.connect(). If multiple clients are created (or reconnect logic is added later), cancellation requests can be routed to the wrong connection. A safer design is to associate cancellation registration with a specific AspireClient instance (e.g., move the cancellation registry onto the client, or pass the client into registerCancellation() and store per-client registries).

Copilot uses AI. Check for mistakes.
Comment on lines +361 to +365
// Set up the abort listener
const onAbort = () => {
// Send cancel request to host
if (currentClient?.connected) {
currentClient.cancelToken(cancellationId).catch(() => {
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentClient is a mutable singleton shared across the module and overwritten on each AspireClient.connect(). If multiple clients are created (or reconnect logic is added later), cancellation requests can be routed to the wrong connection. A safer design is to associate cancellation registration with a specific AspireClient instance (e.g., move the cancellation registry onto the client, or pass the client into registerCancellation() and store per-client registries).

Suggested change
// Set up the abort listener
const onAbort = () => {
// Send cancel request to host
if (currentClient?.connected) {
currentClient.cancelToken(cancellationId).catch(() => {
// Capture the client at registration time to avoid using a later, different client.
const clientForCancellation = currentClient;
// Set up the abort listener
const onAbort = () => {
// Send cancel request to host
if (clientForCancellation?.connected) {
clientForCancellation.cancelToken(cancellationId).catch(() => {

Copilot uses AI. Check for mistakes.
Comment on lines +481 to +482
currentClient = this;

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentClient is a mutable singleton shared across the module and overwritten on each AspireClient.connect(). If multiple clients are created (or reconnect logic is added later), cancellation requests can be routed to the wrong connection. A safer design is to associate cancellation registration with a specific AspireClient instance (e.g., move the cancellation registry onto the client, or pass the client into registerCancellation() and store per-client registries).

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,19 @@
{
"name": "validationapphost",
"version": "1.0.0",
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this appears to be a playground/sample package, consider adding \"private\": true to avoid accidental npm publish (especially because the name is fairly generic).

Suggested change
"version": "1.0.0",
"version": "1.0.0",
"private": true,

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit c216a2c:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ❌ Upload failed
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AgentInitCommand_WithMalformedMcpJson_ShowsErrorAndExitsNonZero ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ❌ Upload failed
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ❌ Upload failed
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22697326569

@davidfowl davidfowl merged commit 1f6bbfe into release/13.2 Mar 5, 2026
390 checks passed
@davidfowl davidfowl deleted the sebros/polyglot-python branch March 5, 2026 04:36
@dotnet-policy-service dotnet-policy-service bot modified the milestone: 13.2 Mar 5, 2026
eerhardt pushed a commit to eerhardt/aspire that referenced this pull request Mar 7, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI pushed a commit that referenced this pull request Mar 10, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants