Skip to content

Preserve the default AppHost for explicit runs - #19394

Open
Adam Ratzman (adamint) wants to merge 14 commits into
microsoft:mainfrom
adamint:adamint/fix-apphost-config-persistence
Open

Preserve the default AppHost for explicit runs#19394
Adam Ratzman (adamint) wants to merge 14 commits into
microsoft:mainfrom
adamint:adamint/fix-apphost-config-persistence

Conversation

@adamint

Copy link
Copy Markdown
Member

Description

Running aspire run --apphost <alternate> currently replaces the configured appHost.path, so the next bare aspire run unexpectedly uses the alternate AppHost.

This makes a direct --apphost selection invocation-scoped when a valid default already exists. Extension user selections and interactive selections from a directory still update the default, while missing or deleted defaults are still established or replaced.

Related to #19080, which covered explicit VS Code launch configurations but not direct CLI --apphost usage.

User-facing usage

aspire run --apphost Secondary/apphost.cs

If aspire.config.json points to Primary/apphost.cs, this runs the secondary AppHost without changing the configured primary AppHost.

Validation:

  • Aspire.Cli.Tests: 5,027 total, 4,993 passed, 34 platform skips, 0 failed
  • Targeted Aspire.Cli build: 0 warnings, 0 errors
  • Manual detached run launched Secondary/apphost.cs; the config remained Primary/apphost.cs before the run, after startup, and after stopping

Fixes # (issue)

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

Adam Ratzman and others added 2 commits August 14, 2026 13:01
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 270b31f3-8e18-4d54-ba74-ba62a82630ca
Keep extension and interactive selections persistent while treating direct CLI selections as invocation-scoped.

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

Copilot-Session: 270b31f3-8e18-4d54-ba74-ba62a82630ca
@github-actions

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 -- 19394

Or

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

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

Makes explicit CLI --apphost selections invocation-scoped while preserving valid configured defaults.

Changes:

  • Distinguishes explicit targets from prompted or extension-origin selections.
  • Preserves, establishes, or replaces defaults according to selection origin and validity.
  • Adds regression tests for each persistence scenario.
Show a summary per file
File Description
src/Aspire.Cli/Projects/ProjectLocator.cs Implements selection-aware default preservation.
tests/Aspire.Cli.Tests/Projects/ProjectLocatorTests.cs Covers preservation, replacement, and prompt behavior.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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.

I reviewed the AppHost selection and config-persistence flow end to end, including direct and ambient resolution, detached child launches, the VS Code extension handoff, and the focused regression coverage.

I found two concrete config-persistence issues: one regression in detached ambient launches and one remaining gap for --apphost commands entered in the Aspire terminal.

Comment thread src/Aspire.Cli/Projects/ProjectLocator.cs
Comment thread src/Aspire.Cli/Projects/ProjectLocator.cs Outdated
Adam Ratzman and others added 7 commits August 17, 2026 18:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Copilot AI review requested due to automatic review settings August 18, 2026 01:53

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.

Review details

  • Files reviewed: 16/16 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread src/Aspire.Cli/Projects/ProjectLocator.cs Outdated
Comment thread src/Aspire.Cli/Commands/AppHostLauncher.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Copilot AI review requested due to automatic review settings August 18, 2026 02:08

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.

Review details

  • Files reviewed: 16/16 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread extension/src/server/interactionService.ts
Comment thread src/Aspire.Cli/Projects/ProjectLocator.cs
Adam Ratzman added 2 commits August 18, 2026 00:55
Adds RunWithExplicitAlternateAppHost_PreservesExistingDefault, which runs
`aspire run --apphost Alternate/apphost.cs` against a workspace whose
aspire.config.json points at a different AppHost, then asserts the config is
byte-for-byte unchanged and no local config was created beside the alternate.

The alternate AppHost is patched to write a marker file. Without that, a silent
fallback to the configured Primary AppHost would leave the config untouched and
pass the persistence assertion vacuously.

GetAspireRunCommand now takes optional additional arguments so the new test
inherits the ASPIRE_CLI_START_TIMEOUT budget that AspireRunReadyTimeout assumes.

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

Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
The existing coverage stops on either side of VS Code's two-stage debug
configuration resolution: the InteractionService test stubs startDebugging, and
the AspireDebugSession tests hand-build a configuration that already carries
`explicit-cli`. Neither proves the origin survives the resolver boundary, where
ensureAppHostSelectionOrigin backfills an absent origin with
`explicit-launch-configuration` and AspireDebugSession then omits `--apphost`
for a directory target.

The new test runs the real InteractionService, both real resolver stages with a
JSON clone between them, and a real AspireDebugSession, asserting the spawned
CLI receives `--apphost <directory>` and the explicit-cli origin environment.
Reverting the AspireDebugSession condition fails it.

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

Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Copilot AI review requested due to automatic review settings August 18, 2026 04:55

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.

Review details

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Adam Ratzman and others added 2 commits August 18, 2026 01:14
main added a required `vscode.Memento` parameter to
AspireDebugConfigurationProvider, so the two-argument construction in the
new resolver-stage test no longer compiles against the merged tree.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e30157e-5245-4f06-a696-1516f9cd8f9e
Copilot AI review requested due to automatic review settings August 18, 2026 05:18

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.

Review details

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants