Skip to content

Add HTTP command result support for AppHost HTTP commands - #15664

Merged
David Fowler (davidfowl) merged 7 commits into
mainfrom
davidfowl/issue-8729-command-results
Apr 10, 2026
Merged

David Fowler (davidfowl) merged 7 commits into
mainfrom
davidfowl/issue-8729-command-results

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Mar 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds HTTP command result support for AppHost HTTP commands so response bodies can be surfaced in the CLI, dashboard, and generated polyglot SDKs.

This change:

  • introduces HttpCommandResultMode and HttpCommandOptions.ResultMode
  • exports the HTTP command result metadata through ATS using HttpCommandExportOptions so generated SDKs can surface the same behavior
  • keeps the generated TypeScript API flat when a capability already has a single DTO options parameter
  • adds direct unit tests for GetDefaultHttpCommandResultAsync plus integration coverage through WithHttpCommand
  • updates the Stress sample to expose distinct auto, json, and text HTTP command result scenarios
  • refreshes the affected TypeScript, Python, Go, Java, and Rust code-generation snapshots

During review, the temporary ATS DTO rename support was removed. DTO names continue to come from the CLR type name.

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?

@github-actions

github-actions Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

🚀 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"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

return response.IsSuccessStatusCode
? CommandResults.Success()
: CommandResults.Failure($"Request failed with status code {response.StatusCode}");
return await GetDefaultHttpCommandResultAsync(response, commandOptions, context.CancellationToken).ConfigureAwait(false);

Copilot AI Mar 28, 2026

Copy link

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.
@davidfowl
David Fowler (davidfowl) force-pushed the davidfowl/issue-8729-command-results branch 3 times, most recently from 81db386 to abf2a0b Compare March 28, 2026 05:43
@davidfowl David Fowler (davidfowl) changed the title Add ATS support for HTTP command results Add HTTP command result support for ATS and polyglot SDKs Mar 28, 2026
@davidfowl David Fowler (davidfowl) changed the title Add HTTP command result support for ATS and polyglot SDKs Add HTTP command result support for AppHost HTTP commands Mar 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

{
var (_, optionalParams) = SeparateParameters(cap.Parameters);
if (optionalParams.Count > 0)
if (optionalParams.Count > 0 && !TryGetDirectOptionsParameter(optionalParams, out _))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this impact existing generated apis? Not sure if the tests have run so far since there is a conflict, it will tell.

Maybe something to handle in other languages too ... if not now we should file something to remember.

return builder;
}

[AspireExport("withHttpCommand", Description = "Adds an HTTP resource command")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update tests/polyglotapphosts to add a usage to validate the generated sdk compiles. (ask copilot to do it)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the 3 languages

}

[Fact]
public void ScanAssembly_HostingAssembly_ExportsWithHttpCommandCapabilityWithAtsFriendlyOptions()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure this is useful, as long as we have a usage in the tests/polyglotapphosts at least

@davidfowl
David Fowler (davidfowl) force-pushed the davidfowl/issue-8729-command-results branch from 24cb9f8 to 93a7f97 Compare April 3, 2026 18:12
…hHttpCommand usage

- Dispose HttpResponseMessage in finally block after GetCommandResult or
  default result logic to avoid holding open connections
- Add withHttpCommand usage to all 3 polyglot validation apphosts
  (TypeScript, Java, Python) to validate generated SDK compiles

Co-authored-by: Copilot <[email protected]>
Regenerate TwoPassScanningGeneratedAspire verified snapshots for all
5 code generation languages (TypeScript, Java, Python, Rust, Go) to
reflect upstream API changes merged into main.

Co-authored-by: Copilot <[email protected]>
… snapshots

- Update CommandResults.Success() call to use new 3-arg API (message, result, format)
- Migrate test assertions from Result/ResultFormat/ErrorMessage to Data.Value/Data.Format/Message
- Regenerate codegen snapshot files for Go, Rust, Python, TypeScript after rebase

Co-authored-by: Copilot <[email protected]>
@davidfowl
David Fowler (davidfowl) force-pushed the davidfowl/issue-8729-command-results branch from 6d6f30e to a97c34e Compare April 10, 2026 19:53
@github-actions

Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

…ters

Apply TryGetDirectOptionsParameter in interface/context/wrapper method
generation so that methods with a single DTO 'options' parameter use
the actual DTO type (e.g., HttpCommandExportOptions) instead of a
generated options interface name (e.g., WithHttpCommandOptions) that
was never defined.

Co-authored-by: Copilot <[email protected]>
@davidfowl
David Fowler (davidfowl) enabled auto-merge (squash) April 10, 2026 23:53
@davidfowl
David Fowler (davidfowl) merged commit 82625bc into main Apr 10, 2026
532 of 535 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 58 recordings uploaded (commit 6db4b22)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AllPublishMethodsBuildDockerImages ▶️ 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
DashboardRunWithOtelTracesReturnsNoTraces ▶️ 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
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24268519500

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

4 participants