Skip to content

Fix DistributedApplicationTestingBuilder dashboard with dynamic ports - #17729

Merged
David Fowler (davidfowl) merged 2 commits into
mainfrom
fix/testing-builder-dashboard-unsecured-transport
May 31, 2026
Merged

David Fowler (davidfowl) merged 2 commits into
mainfrom
fix/testing-builder-dashboard-unsecured-transport

Conversation

@JamesNK

@JamesNK James Newton-King (JamesNK) commented May 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #17622

Summary

When DistributedApplicationTestingBuilder enables the dashboard (either explicitly or by default in the future), the resource service gRPC host fails to start if the endpoint uses a loopback IP with port 0 (dynamic port). This is because Kestrel's ListenLocalhost(0) throws "Dynamic port binding is not supported when binding to localhost."

Changes

DistributedApplicationFactory.cs

  • Default AllowUnsecuredTransport to true in testing scenarios. The testing builder defaults dashboard URLs to HTTP, but TransportOptionsValidator rejects HTTP without this flag.

DashboardServiceHost.cs

  • When the resource service endpoint host is a parseable loopback IP (e.g. 127.0.0.1, ::1), use Listen(IPAddress, port) directly instead of ListenLocalhost(port). This supports port 0 for dynamic binding.
  • Keep ListenLocalhost for localhost / *.localhost hostnames (which bind both IPv4+IPv6 but don't support port 0).
  • Throw ArgumentException for non-local addresses.
  • Remove the internal static IsLocalResourceServiceEndpoint method (replaced by inline logic and a private IsLocalhostOrLocalhostTld helper).

Tests

  • Add DashboardEnabledInTestingBuilderShouldWorkWithDynamicPorts - verifies dashboard starts with default dynamic port configuration.
  • Add LoopbackWithDynamicPorts theory - verifies explicit 127.0.0.1:0 and [::1]:0 endpoints work.
  • Add NonLocalResourceServiceEndpointThrows - verifies non-local addresses are rejected.
  • Remove IsLocalResourceServiceEndpoint_ReturnsExpectedResult test (method no longer exists).

@github-actions

github-actions Bot commented May 30, 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 -- 17729

Or

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

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

Fixes DistributedApplicationTestingBuilder startup failures when the Aspire dashboard is enabled and the testing defaults use http:// endpoints, by defaulting ASPIRE_ALLOW_UNSECURED_TRANSPORT to true in the testing factory and adding a regression test that waits for the dashboard resource to become healthy.

Changes:

  • Default ASPIRE_ALLOW_UNSECURED_TRANSPORT=true in DistributedApplicationFactory.PreConfigureBuilderOptions to avoid TransportOptionsValidator failures with HTTP defaults.
  • Add a Docker-gated regression test that enables the dashboard and waits for the aspire-dashboard resource to become healthy.
  • Include shared AsyncTestHelpers in the test project to use DefaultTimeout(...)/TestConstants.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs Adds regression test for dashboard-enabled testing builder scenarios.
tests/Aspire.Hosting.Testing.Tests/Aspire.Hosting.Testing.Tests.csproj Links shared AsyncTestHelpers.cs into the test project.
src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs Defaults ASPIRE_ALLOW_UNSECURED_TRANSPORT to true for testing builder defaults that use HTTP.

@davidfowl

Copy link
Copy Markdown
Collaborator

James Newton-King (@JamesNK) target release/13.4

@JamesNK James Newton-King (JamesNK) changed the title Fix DistributedApplicationTestingBuilder failing when dashboard enabled with dynamic ports Fix DistributedApplicationTestingBuilder dashboard with dynamic ports May 30, 2026
@JamesNK James Newton-King (JamesNK) added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 30, 2026
…ed with dynamic ports

When users set DisableDashboard = false on DistributedApplicationTestingBuilder,
the TransportOptionsValidator rejected the HTTP URLs that the testing builder
defaults (http://localhost:8080, http://localhost:4317) because
ASPIRE_ALLOW_UNSECURED_TRANSPORT was not set.

Fix: Set AllowUnsecuredTransport = true by default in PreConfigureBuilderOptions,
since all URLs are already defaulted to HTTP.

Add a regression test that enables the dashboard and verifies it becomes healthy.

Fixes #17622
@JamesNK
James Newton-King (JamesNK) force-pushed the fix/testing-builder-dashboard-unsecured-transport branch from 53a6b58 to 5cb3e2e Compare May 30, 2026 15:00
@JamesNK

Copy link
Copy Markdown
Member Author

/backport to release/13.4

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.4 (link to workflow run)

@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.

@JamesNK
James Newton-King (JamesNK) force-pushed the fix/testing-builder-dashboard-unsecured-transport branch from 3f17cf3 to 20c2b87 Compare May 31, 2026 01:10
@github-actions

Copy link
Copy Markdown
Contributor

❓ CLI E2E Tests unknown — 110 passed, 0 failed, 2 unknown (commit 20c2b87)

View all recordings
Status Test Recording Job Artifacts
✅ AddPackageInteractiveWhileAppHostRunningDetached Recording #78690760617 Logs
✅ AddPackageWhileAppHostRunningDetached Recording #78690760617 Logs
✅ AgentCommands_AllHelpOutputs_AreCorrect Recording #78690760665 Logs
✅ AgentInitCommand_DefaultSelection_InstallsDefaultSkills Recording #78690760665 Logs
✅ AgentInitCommand_MigratesDeprecatedConfig Recording #78690760665 Logs
✅ AgentInitCommand_NonInteractive_BundleOnlySkillsBeyondCliCatalog_AreInstallable Recording #78690760665 Logs
✅ AgentMcpListStructuredLogsReturnsLogsFromStarterApp Recording #78690760683 Logs
✅ AgentMcpListStructuredLogsReturnsLogsFromStarterApp_DevLocalhost Recording #78690760683 Logs
✅ AgentMcpListStructuredLogsReturnsLogsFromStarterApp_Isolated Recording #78690760683 Logs
✅ AllPublishMethodsBuildDockerImages Recording #78690760525 Logs
✅ AspireAddAndStartWorkAgainstLegacyAppHostTs Recording #78690760682 Logs
✅ AspireAddPackageVersionToDirectoryPackagesProps Recording #78690760516 Logs
✅ AspireInitSingleFileAppHostRunsViaDotnetRunAppHost Recording #78690760538 Logs
✅ AspireInitWithExistingAppHostDirRecreatesMissingNuGetConfigAndPreservesFiles Recording #78690760748 Logs
❔ AspireInitWithSolutionFileGeneratesAppHostThatBuildsAgainstChannelHive Recording #78690760748 Logs
✅ AspireStartUpdatesStaleTypeScriptAppHostPath Recording #78690760697 Logs
✅ AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps Recording #78690760516 Logs
✅ AspireUpdateRemovesOrphanAppHostPackageVersionWhenSdkAlreadyCurrent Recording #78690760516 Logs
✅ Banner_DisplayedOnFirstRun Recording #78690760776 Logs
✅ Banner_DisplayedWithExplicitFlag Recording #78690760776 Logs
✅ Banner_NotDisplayedWithNoLogoFlag Recording #78690760776 Logs
✅ CertificatesClean_RemovesCertificates Recording #78690760685 Logs
✅ CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate Recording #78690760685 Logs
✅ CertificatesTrust_WithUntrustedCert_TrustsCertificate Recording #78690760685 Logs
✅ ConfigSetGet_CreatesNestedJsonFormat Recording #78690760556 Logs
✅ CreateAndRunAspireStarterProject Recording #78690760722 Logs
✅ CreateAndRunAspireStarterProjectWithBundle Recording #78690760731 Logs
✅ CreateAndRunEmptyAppHostProject Recording #78690760733 Logs
✅ CreateAndRunJavaEmptyAppHostProject Recording #78690760768 Logs
✅ CreateAndRunJsReactProject Recording #78690760614 Logs
✅ CreateAndRunPolyglotAppHostWithDevLocalhostUrls Recording #78690760722 Logs
✅ CreateAndRunPythonReactProject Recording #78690760787 Logs
✅ CreateAndRunTypeScriptEmptyAppHostProject Recording #78690760611 Logs
✅ CreateAndRunTypeScriptStarterProject Recording #78690760621 Logs
✅ CreateJavaAppHostWithViteApp Recording #78690760684 Logs
✅ CreateTypeScriptAppHostWithViteApp_AllowsGuestAppPackageManagerToDiffer Recording #78690760701 Logs
✅ CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain Recording #78690760701 Logs
✅ DashboardRunWithAgentMcpListTracesReturnsNoTraces Recording #78690760631 Logs
✅ DashboardRunWithAgentMcpListTracesReturnsNoTraces_DevLocalhost Recording #78690760631 Logs
✅ DashboardRunWithOtelTracesReturnsNoTraces Recording #78690760631 Logs
✅ DashboardRunWithOtelTracesReturnsNoTraces_DevLocalhost Recording #78690760631 Logs
✅ DeployK8sBasicApiService Recording #78690760566 Logs
✅ DeployK8sWithExternalHelmChart Recording #78690760744 Logs
✅ DeployK8sWithGarnet Recording #78690760691 Logs
✅ DeployK8sWithMongoDB Recording #78690760725 Logs
✅ DeployK8sWithMySql Recording #78690760554 Logs
✅ DeployK8sWithPostgres Recording #78690760792 Logs
✅ DeployK8sWithRabbitMQ Recording #78690760783 Logs
✅ DeployK8sWithRedis Recording #78690760773 Logs
✅ DeployK8sWithSqlServer Recording #78690760779 Logs
✅ DeployK8sWithValkey Recording #78690760646 Logs
✅ DeployTypeScriptAppToKubernetes Recording #78690760736 Logs
✅ DescribeCommandResolvesReplicaNames Recording #78690760781 Logs
✅ DescribeCommandShowsRunningResources Recording #78690760781 Logs
✅ DetachFormatJsonProducesValidJson Recording #78690760717 Logs
✅ DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance Recording #78690760717 Logs
✅ DoPublishAndDeployListStepsWork Recording #78690760789 Logs
✅ DocsCommand_RendersInteractiveMarkdownFromLocalSource Recording #78690760745 Logs
✅ DoctorCommand_DetectsDeprecatedAgentConfig Recording #78690760665 Logs
✅ DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain Recording #78690760675 Logs
✅ DoctorCommand_WithSslCertDir_ShowsTrusted Recording #78690760675 Logs
✅ DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted Recording #78690760675 Logs
✅ GatewayWithoutExternalEndpoint_FailsPublishWithGuidance Recording #78690760793 Logs
✅ GeneratedAspireDevScript_StartsWatchMode_WithConfiguredToolchain Recording #78690760701 Logs
✅ GlobalMigration_HandlesCommentsAndTrailingCommas Recording #78690760556 Logs
✅ GlobalMigration_HandlesMalformedLegacyJson Recording #78690760556 Logs
✅ GlobalMigration_PreservesAllValueTypes Recording #78690760556 Logs
✅ GlobalMigration_SkipsWhenNewConfigExists Recording #78690760556 Logs
✅ GlobalSettings_MigratedFromLegacyFormat Recording #78690760556 Logs
✅ IngressWithoutExternalEndpoint_FailsPublishWithGuidance Recording #78690760793 Logs
✅ InitTypeScriptAppHost_AugmentsExistingViteRepoInWorkspaceSubdirectory Recording #78690760701 Logs
✅ InteractiveCSharpInitCreatesExpectedFiles Recording #78690760782 Logs
✅ InvalidAppHostPathWithComments_IsHealedOnRun Recording #78690760780 Logs
✅ JavaScriptHostingApisRunFromTypeScriptAppHost Recording #78690760525 Logs
✅ LatestCliCanStartStableChannelAppHost Recording #78690760722 Logs
✅ LatestCliCanStartStableChannelTypeScriptAppHost Recording #78690760722 Logs
✅ LegacySettingsMigration_AdjustsRelativeAppHostPath Recording #78690760697 Logs
✅ LogsCommandShowsResourceLogs Recording #78690760535 Logs
✅ OtelLogsReturnsStructuredLogsFromStarterApp Recording #78690760686 Logs
✅ OtelLogsReturnsStructuredLogsFromStarterAppIsolated Recording #78690760686 Logs
✅ PsCommandListsRunningAppHost Recording #78690760774 Logs
✅ PsFormatJsonOutputsOnlyJsonToStdout Recording #78690760774 Logs
✅ PublishJavaScriptPatternsGeneratesExpectedDockerComposeArtifacts Recording #78690760775 Logs
✅ PublishWithConfigureEnvFileUpdatesEnvOutput Recording #78690760775 Logs
✅ PublishWithDockerComposeServiceCallbackSucceeds Recording #78690760775 Logs
✅ PublishWithoutOutputPathUsesAppHostDirectoryDefault Recording #78690760775 Logs
✅ ResourceCommand_FailedExecution_DisplaysAppHostLogPathAndLogContainsEntries Recording #78690760790 Logs
✅ ResourceCommand_SetAndDeleteParameterUpdatesDescribeOutput Recording #78690760790 Logs
✅ RestoreGeneratesSdkFiles Recording #78690760550 Logs
✅ RestoreGeneratesSdkFiles_WithConfiguredToolchain Recording #78690760562 Logs
✅ RestoreRefreshesGeneratedSdkAfterAddingIntegration Recording #78690760562 Logs
✅ RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes Recording #78690760754 Logs
✅ RunFromParentDirectory_UsesExistingConfigNearAppHost Recording #78690760688 Logs
✅ RunReportsSyntaxErrorsForDotNetAppHost Recording #78690760737 Logs
✅ RunReportsSyntaxErrorsForTypeScriptAppHost Recording #78690760737 Logs
✅ SecretCrudOnDotNetAppHost Recording #78690760726 Logs
✅ SecretCrudOnTypeScriptAppHost Recording #78690760634 Logs
✅ StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels Recording #78690760777 Logs
✅ StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets Recording #78690760523 Logs
✅ StartReportsSyntaxErrorsForDotNetAppHost Recording #78690760737 Logs
✅ StartReportsSyntaxErrorsForTypeScriptAppHost Recording #78690760737 Logs
✅ StopAllAppHostsFromAppHostDirectory Recording #78690760724 Logs
✅ StopJavaPolyglotAppHostUsingApphostDirectory Recording #78690760628 Logs
✅ StopNonInteractiveSingleAppHost Recording #78690760724 Logs
✅ StopTypeScriptPolyglotAppHostUsingApphostDirectory Recording #78690760598 Logs
✅ StopWithNoRunningAppHostExitsSuccessfully Recording #78690760617 Logs
✅ TypeScriptAppHostRunDoesNotDeadlockWhenLazyOptionsInvokeAsyncCallback Recording #78690760611 Logs
✅ UnAwaitedChainsCompileWithAutoResolvePromises Recording #78690760562 Logs
❔ UpdateProjectChannelToStable_CSharpEmptyAppHost_PreservesAspireConfigChannel Recording #78690760700 Logs
✅ UpdateProjectChannelToStable_CSharpSingleFileInit_PreservesAspireConfigChannel Recording #78690760700 Logs
✅ UpdateProjectChannelToStable_TypeScriptSingleFileInit_PreservesAspireConfigChannel Recording #78690760700 Logs
✅ UpdateProjectChannelToStable_TypeScript_PreviewsStablePackagesAndPreservesChannel Recording #78690760700 Logs

📹 Recordings uploaded automatically from CI run #26699662675

@davidfowl
David Fowler (davidfowl) merged commit b7e74f5 into main May 31, 2026
312 checks passed
@davidfowl
David Fowler (davidfowl) deleted the fix/testing-builder-dashboard-unsecured-transport branch May 31, 2026 02:24
@github-actions github-actions Bot added this to the 13.5 milestone May 31, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → bug_fix_restores_documented_behavior

No signals triggered (signal_count: 0). This PR is a bug fix that corrects internal behavior in DashboardServiceHost.cs and DistributedApplicationFactory.cs to make the DistributedApplicationTestingBuilder work correctly with dynamic ports when the dashboard is enabled. No new public API surface, CLI flags, configuration keys, environment variables, or user-facing options were introduced — the fix restores the implementation to match already-documented behavior for testing with the dashboard enabled.

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

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[13.4] DistributedApplicationTestingBuilder using dynamic dashboard port no longer passes.

4 participants