Skip to content

Add ATS support for HTTP command results#15664

Open
davidfowl wants to merge 3 commits intomainfrom
davidfowl/issue-8729-command-results
Open

Add ATS support for HTTP command results#15664
davidfowl wants to merge 3 commits intomainfrom
davidfowl/issue-8729-command-results

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented Mar 28, 2026

Description

Adds HTTP command result support so AppHost commands can describe how HTTP responses should be surfaced in exported metadata and generated language projections.

This change:

  • introduces HttpCommandResultMode and HttpCommandOptions
  • exports ATS-friendly HTTP command metadata for withHttpCommand
  • keeps the TypeScript API flat when a capability already has a single DTO options parameter
  • updates the stress sample usage
  • refreshes the affected TypeScript, Python, Go, Java, and Rust code-generation snapshots

During review, the temporary ATS DTO rename support was removed. DTO names now continue to come from the CLR type name, and the HTTP command export shape uses a dedicated HttpCommandExportOptions type instead of attribute-based renaming.

Fixes #8729

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings March 28, 2026 03:25
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 28, 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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15664

Or

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

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

Adds ATS-friendly support for surfacing HTTP command response bodies as command results, enabling exported metadata + generated polyglot projections to describe response handling (JSON/text/auto/none).

Changes:

  • Introduces HttpCommandResultMode and HttpCommandOptions.ResultMode, plus default logic to capture/format HTTP response bodies when opted in.
  • Adds an ATS-specific withHttpCommand export with an ATS-friendly DTO (HttpCommandExportOptions) and updates ATS scanning/codegen to respect [AspireDto(Name=...)].
  • Updates stress playground endpoints and refreshes TypeScript/Go/Java/Python/Rust generation snapshots and tests.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Aspire.Hosting.Tests/WithHttpCommandTests.cs Adds unit tests for result-mode behavior and content-type inference.
tests/Aspire.Hosting.RemoteHost.Tests/AtsCapabilityScannerTests.cs Validates withHttpCommand capability export shape + DTO surface.
src/Aspire.Hosting/ApplicationModel/HttpCommandOptions.cs Adds HttpCommandResultMode, ResultMode, and the ATS DTO for export options.
src/Aspire.Hosting/ResourceBuilderExtensions.cs Implements default result capture logic and adds ATS export withHttpCommand.
src/Aspire.Hosting/Ats/AspireDtoAttribute.cs Adds Name to control exported DTO naming.
src/Aspire.TypeSystem/AttributeDataReader.cs Adds parsing support for [AspireDto] data (including Name).
src/Aspire.Hosting.RemoteHost/AtsCapabilityScanner.cs Uses parsed DTO name when producing ATS DTO type info.
src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs Uses scanned DTO names for TS interfaces + supports “direct options DTO” parameters.
src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs Uses scanned DTO names for Python DTOs.
playground/Stress/Stress.AppHost/Program.cs Adds sample HTTP commands demonstrating result modes.
playground/Stress/Stress.ApiService/Program.cs Adds endpoints returning JSON/text to exercise the new result modes.
tests/**/Snapshots/.verified. Updates polyglot SDK/codegen snapshots to include the new capability, DTO, and enum.
Comments suppressed due to low confidence (1)

src/Aspire.Hosting/ResourceBuilderExtensions.cs:2431

  • XML doc has a typo: "succesful" should be "successful".
    /// is not specified, the command will be considered succesful if the response status code is in the 2xx range. Set

var dtoAttr = AttributeDataReader.GetAspireDtoData(type);
var typeId = AtsTypeMapping.DeriveTypeId(type);
var typeName = type.Name;
var typeName = dtoAttr?.Name ?? type.Name;
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

AspireDtoAttribute.Name is described as optional; if it’s set to an empty/whitespace string, this will currently override type.Name and can lead to empty/invalid DTO type names in generated SDKs. Consider treating null/empty/whitespace as "not specified" (or validating and throwing) before using it for typeName.

Suggested change
var typeName = dtoAttr?.Name ?? type.Name;
var typeName = dtoAttr?.Name is string name && !string.IsNullOrWhiteSpace(name)
? name
: type.Name;

Copilot uses AI. Check for mistakes.
/// <para>
/// The <see cref="HttpCommandOptions.GetCommandResult"/> callback will be invoked after the response is received to determine the result of the command invocation. If this callback
/// is not specified, the command will be considered succesful if the response status code is in the 2xx range.
/// is not specified, the command will be considered succesful if the response status code is in the 2xx range. Set
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

XML doc has a typo: "succesful" should be "successful".

This issue also appears on line 2431 of the same file.

Suggested change
/// is not specified, the command will be considered succesful if the response status code is in the 2xx range. Set
/// is not specified, the command will be considered successful if the response status code is in the 2xx range. Set

Copilot uses AI. Check for mistakes.
return response.IsSuccessStatusCode
? CommandResults.Success()
: CommandResults.Failure($"Request failed with status code {response.StatusCode}");
return await GetDefaultHttpCommandResultAsync(response, commandOptions, context.CancellationToken).ConfigureAwait(false);
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The HTTP response is used to compute the command result but is never disposed. To avoid holding open the underlying connection/content stream, consider disposing the HttpResponseMessage in a finally after either GetCommandResult completes or the default result logic runs.

Copilot uses AI. Check for mistakes.
}

/// <summary>
/// Optional configuration for resource HTTP commands added with <see cref="ResourceBuilderExtensions.WithHttpCommand{TResource}(Aspire.Hosting.ApplicationModel.IResourceBuilder{TResource}, string, string, string?, string?, Aspire.Hosting.ApplicationModel.HttpCommandOptions?)"/>."/>
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The XML documentation appears malformed due to an extra "/> at the end of the <see .../> tag, which can trigger CS1570/CS1574 warnings (and potentially fail the build if treated as errors). Please fix the <see cref="..."/> usage so the summary is well-formed XML.

Suggested change
/// Optional configuration for resource HTTP commands added with <see cref="ResourceBuilderExtensions.WithHttpCommand{TResource}(Aspire.Hosting.ApplicationModel.IResourceBuilder{TResource}, string, string, string?, string?, Aspire.Hosting.ApplicationModel.HttpCommandOptions?)"/>."/>
/// Optional configuration for resource HTTP commands added with <see cref="ResourceBuilderExtensions.WithHttpCommand{TResource}(Aspire.Hosting.ApplicationModel.IResourceBuilder{TResource}, string, string, string?, string?, Aspire.Hosting.ApplicationModel.HttpCommandOptions?)"/>.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl force-pushed the davidfowl/issue-8729-command-results branch from 81db386 to abf2a0b Compare March 28, 2026 05:43
davidfowl and others added 2 commits March 27, 2026 22:45
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit 02f236b)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
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 #23678701893

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.

HttpCommands / Commands should have a way to provide result / copy it to clipboard

2 participants