Skip to content

Fix TypeScript AppHost generated port ranges - #16629

Merged
Eric Erhardt (eerhardt) merged 2 commits into
microsoft:mainfrom
eerhardt:eerhardt/fix-typescript-apphost-dashboard-ports
May 1, 2026
Merged

Fix TypeScript AppHost generated port ranges#16629
Eric Erhardt (eerhardt) merged 2 commits into
microsoft:mainfrom
eerhardt:eerhardt/fix-typescript-apphost-dashboard-ports

Conversation

@eerhardt

Copy link
Copy Markdown
Member

Description

Fixes #16626

TypeScript AppHost scaffolding could generate dashboard, OTLP, and resource-service profile ports from a broad range that overlaps the Windows ephemeral port range. When that happened, DCP could fail to bind the configured dashboard HTTPS proxy while Aspire still reported that unreachable URL.

This consolidates the safe AppHost profile port ranges into a shared generator used by CLI templates, aspire init, and TypeScript AppHost scaffolding. The TypeScript scaffold now uses the same non-ephemeral bands as the other generation paths, and the regression test parses generated apphost.run.json to verify those ports stay out of the Windows ephemeral range.

Validation: Not run locally; restore.cmd was still installing the local SDK in the background when this PR was created.

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?

Use a shared AppHost profile port generator for CLI templates, init, and TypeScript AppHost scaffolding so generated dashboard and service profile ports avoid the Windows ephemeral range. Add regression coverage for the generated TypeScript apphost.run.json ports.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

This PR fixes TypeScript AppHost scaffolding occasionally generating dashboard/OTLP/resource-service ports in the Windows ephemeral range, which could prevent DCP from binding the dashboard HTTPS proxy and lead to Aspire reporting an unreachable dashboard URL. It centralizes “safe” profile port generation into a shared generator and applies it consistently across CLI templates, aspire init, and TypeScript scaffolding, with a regression test to keep the ports out of the ephemeral range.

Changes:

  • Introduced AppHostProfilePortGenerator (shared source-linked utility) to generate profile ports from known non-ephemeral ranges.
  • Updated TypeScript AppHost scaffolding, CLI templates, and aspire init to use the shared port generator.
  • Added a TypeScript scaffolding regression test that parses apphost.run.json and asserts generated ports remain below the Windows ephemeral range and within the expected bands.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/TypeScriptLanguageSupportTests.cs Adds a regression test that parses generated apphost.run.json and validates ports are within the safe ranges and below the Windows ephemeral range.
src/Shared/AppHostProfilePortGenerator.cs Adds the shared port-range constants and generator returning an AppHostProfilePorts record struct.
src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptLanguageSupport.cs Switches TypeScript scaffold port generation to use AppHostProfilePortGenerator.Generate(...).
src/Aspire.Hosting.CodeGeneration.TypeScript/Aspire.Hosting.CodeGeneration.TypeScript.csproj Source-links the new shared generator into the TypeScript codegen assembly.
src/Aspire.Cli/Templating/CliTemplateFactory.cs Replaces local/random port-range logic with the shared port generator for CLI templates.
src/Aspire.Cli/Commands/InitCommand.cs Uses the shared generator when writing default profiles during thin aspire init.
src/Aspire.Cli/Aspire.Cli.csproj Source-links the new shared generator into the CLI assembly.

@github-actions

github-actions Bot commented Apr 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 -- 16629

Or

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

@eerhardt
Eric Erhardt (eerhardt) enabled auto-merge (squash) May 1, 2026 17:00
@eerhardt

Copy link
Copy Markdown
Member Author

/backport to release/13.3

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

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

@eerhardt
Eric Erhardt (eerhardt) merged commit dafe7db into microsoft:main May 1, 2026
568 of 571 checks passed
@eerhardt
Eric Erhardt (eerhardt) deleted the eerhardt/fix-typescript-apphost-dashboard-ports branch May 1, 2026 17:42
@github-actions github-actions Bot added this to the 13.4 milestone May 1, 2026
Nell Shamrell-Harrington (nellshamrell) pushed a commit to nellshamrell/aspire that referenced this pull request May 18, 2026
* Fix TypeScript AppHost generated port ranges

Use a shared AppHost profile port generator for CLI templates, init, and TypeScript AppHost scaffolding so generated dashboard and service profile ports avoid the Windows ephemeral range. Add regression coverage for the generated TypeScript apphost.run.json ports.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* PR feedback

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 1, 2026
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.

TypeScript AppHost can generate dashboard ports in Windows ephemeral range

3 participants