Skip to content

Stream aspire ls results in interactive mode#17113

Open
davidfowl wants to merge 11 commits into
mainfrom
davidfowl/streaming-ls
Open

Stream aspire ls results in interactive mode#17113
davidfowl wants to merge 11 commits into
mainfrom
davidfowl/streaming-ls

Conversation

@davidfowl
Copy link
Copy Markdown
Collaborator

Description

aspire ls could look blank in interactive terminals until the full workspace search completed, which made large repositories feel hung and made cancellation feel delayed. This change streams discovered AppHost candidates into the live table as validation completes, so users get visible progress while discovery continues.

The implementation keeps machine-readable output stable: --format json, debug output, and non-interactive output still emit one final payload after discovery. The discovery pipeline now accepts an optional progress callback, reports candidates safely from parallel validation, checks cancellation before expensive fallback work, and terminates in-flight child git processes when Ctrl+C is requested because canceling WaitForExitAsync does not stop the process.

User-facing usage

aspire ls
aspire ls --format json

Validation

git --no-pager diff --check

dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.LsCommandTests" --filter-class "*.AppHostCandidateFinderTests" --filter-class "*.GitRepositoryTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"

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

Stream discovered AppHost candidates in interactive table mode while preserving stable JSON output. Make cancellation more responsive by checking cancellation during discovery and terminating in-flight git processes when Ctrl+C is requested.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 15, 2026 01:52
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 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 -- 17113

Or

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

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

This PR improves the aspire ls interactive experience by streaming discovered AppHost candidates into a live-updating display as validation completes, reducing the “blank/hung” feel in large repositories and making cancellation more responsive. It also adds cancellation checks to avoid expensive fallback work after Ctrl+C and ensures child git processes are terminated when cancellation is requested.

Changes:

  • Add an optional progress callback to the AppHost discovery pipeline and use it to drive live updates in interactive aspire ls.
  • Add cancellation checks in discovery and kill in-flight git child processes on cancellation.
  • Update test fakes and CLI tests to cover live streaming and cancellation scenarios, and harden profiling-activity assertions for parallel test execution.
Show a summary per file
File Description
tests/Aspire.Cli.Tests/TestServices/TestProjectLocator.cs Extends test project locator to support progress-callback discovery.
tests/Aspire.Cli.Tests/TestServices/TestInteractionService.cs Records renderables/live-renderables and cancellation display for new ls behaviors.
tests/Aspire.Cli.Tests/TestServices/NoProjectFileProjectLocator.cs Updates signature to match new IProjectLocator optional progress callback.
tests/Aspire.Cli.Tests/Git/GitRepositoryTests.cs Makes profiling-activity test resilient to parallel execution via unique session id filtering.
tests/Aspire.Cli.Tests/Commands/SecretCommandTests.cs Updates test IProjectLocator implementation signature.
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs Updates test IProjectLocator implementations signature.
tests/Aspire.Cli.Tests/Commands/LsCommandTests.cs Adds interactive streaming + cancellation tests; adjusts profiling assertions; updates JSON/table expectations.
tests/Aspire.Cli.Tests/Commands/ExtensionInternalCommandTests.cs Updates test IProjectLocator implementations signature.
tests/Aspire.Cli.Tests/Commands/ExecCommandTests.cs Updates test IProjectLocator implementations signature.
src/Aspire.Cli/Projects/ProjectLocator.cs Adds optional onCandidateFound callback and reports validated candidates from parallel validation.
src/Aspire.Cli/Projects/AppHostCandidateFinder.cs Adds early/late cancellation checks to avoid unnecessary enumeration/fallback work.
src/Aspire.Cli/Git/GitRepository.cs Registers cancellation callback to terminate spawned git processes; reads stdout/stderr concurrently.
src/Aspire.Cli/Commands/LsCommand.cs Implements live-updating interactive ls rendering via DisplayLiveAsync; refactors table building; adds cancellation handling.
src/Aspire.Cli/Commands/DashboardRunCommand.cs Minor simplification of stderr callback wiring.

Copilot's findings

Comments suppressed due to low confidence (2)

src/Aspire.Cli/Commands/LsCommand.cs:244

  • CandidateAppHostDisplayInfo no longer includes RelativePath, which changes the aspire ls --format json payload shape (previously tests validated relativePath). The PR description states machine-readable output remains stable, so this is either an unintended breaking change or the description/tests need updating. Consider keeping relativePath in the JSON model (even if the interactive table no longer shows it) to preserve compatibility.
internal sealed class CandidateAppHostDisplayInfo
{
    public required string Path { get; init; }

    public required string Language { get; init; }

    public required string Status { get; init; }
}

tests/Aspire.Cli.Tests/Commands/LsCommandTests.cs:132

  • This test no longer validates the presence/value of relativePath in the JSON output for aspire ls. If JSON output is intended to stay stable (per PR description), keep asserting RelativePath so a payload/schema regression is caught by tests.

        var jsonOutput = string.Join(string.Empty, textWriter.Logs);
        var candidateAppHosts = JsonSerializer.Deserialize(jsonOutput, JsonSourceGenerationContext.RelaxedEscaping.ListCandidateAppHostDisplayInfo);
        Assert.NotNull(candidateAppHosts);

        Assert.Collection(candidateAppHosts,
            first =>
            {
                Assert.Equal(appHostPath1, first.Path);
                Assert.Equal(KnownLanguageId.CSharp, first.Language);
                Assert.Equal("buildable", first.Status);
            },
            second =>
            {
                Assert.Equal(appHostPath2, second.Path);
                Assert.Equal(KnownLanguageId.TypeScript, second.Language);
                Assert.Equal("possibly-unbuildable", second.Status);
            });
  • Files reviewed: 14/14 changed files
  • Comments generated: 1

Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl
Copy link
Copy Markdown
Collaborator Author

Thanks for the summary. This is an overview rather than actionable feedback, so no changes are needed here.

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

davidfowl and others added 3 commits May 18, 2026 09:37
# Conflicts:
#	tests/Aspire.Cli.Tests/Git/GitRepositoryTests.cs
Add streaming JSON support for aspire ls, refactor project discovery to async streams, and document CLI machine-readable output formats.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The CLI no longer registers an exec command, so these stray tests only exercise parser errors and fail CI across all OSes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JamesNK
Copy link
Copy Markdown
Member

JamesNK commented May 18, 2026

I ran this in aspire with --stream --format json and the first line was: {"type":"started"}. That doesn't seem right.

Edit: Ah, and there is a type=complete at the end. So there is a mini-protocol here, not just writing JSON output line-by-line. That's different from what we do elsewhere where streaming with JSON is just the JSON content except LDJSON instead of one array.

Why is this streaming different than other places?

Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
davidfowl and others added 3 commits May 19, 2026 10:27
Replace the live interactive ls table with a dynamic status that reports directories searched and AppHosts found, then render the final table once discovery completes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts:
#	tests/Aspire.Cli.Tests/TestServices/TestInteractionService.cs
Emit one AppHost candidate per NDJSON line for aspire ls --format json --stream instead of using a custom event protocol.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl
Copy link
Copy Markdown
Collaborator Author

@JamesNK accepted. There was not a good reason for ls to be different here; the event wrapper was just an over-modeled way to represent start/complete/cancel.

I changed aspire ls --format json --stream to emit one AppHost candidate object per NDJSON line, matching the non-streaming array item shape and the rest of the CLI. Empty or canceled streams now emit no protocol records, and the spec/tests are updated.

@davidfowl
Copy link
Copy Markdown
Collaborator Author

AI went off the rails 😄

davidfowl and others added 2 commits May 19, 2026 19:11
Document that streaming JSON output emits content items as NDJSON instead of lifecycle protocol events.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Inject TimeProvider into LsCommand so interactive status refresh cadence can be validated with fake time.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
Comment thread src/Aspire.Cli/Commands/LsCommand.cs Outdated
Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

Nice work — the streaming architecture (Channels → IAsyncEnumerable → NDJSON), interactive Spectre.Console spinner, and process kill-on-cancellation all look solid. Two minor notes left as inline comments (one dead resource string, one pre-existing _inStatus pattern).

Comment thread src/Aspire.Cli/Interaction/ConsoleInteractionService.cs Outdated
Comment thread src/Aspire.Cli/Resources/SharedCommandStrings.resx
Clean up dead resources, make AppHost candidate ordering culture-invariant, use file links for table paths, and fix status fallback state handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl
Copy link
Copy Markdown
Collaborator Author

Thanks! Addressed both remaining notes in ca35295: removed the dead HeaderRelativePath resources and fixed the pre-existing _inStatus fallback-state issue.

@github-actions
Copy link
Copy Markdown
Contributor

CLI E2E Tests unknown — 94 passed, 0 failed, 2 unknown (commit ca35295)

View all recordings
Status Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View recording
AddPackageWhileAppHostRunningDetached ▶️ View recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View recording
AgentInitCommand_DefaultSelection_InstallsDefaultSkills ▶️ View recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View recording
AllPublishMethodsBuildDockerImages ▶️ View recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View recording
AspireInitSingleFileAppHostRunsViaDotnetRunAppHost ▶️ View recording
AspireInitWithExistingAppHostDirRecreatesMissingNuGetConfigAndPreservesFiles ▶️ View recording
AspireInitWithSolutionFileGeneratesAppHostThatBuildsAgainstChannelHive ▶️ View recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View recording
AspireUpdateRemovesOrphanAppHostPackageVersionWhenSdkAlreadyCurrent ▶️ 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
CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View recording
DeployK8sBasicApiService ▶️ View recording
DeployK8sWithExternalHelmChart ▶️ View recording
DeployK8sWithGarnet ▶️ View recording
DeployK8sWithMongoDB ▶️ View recording
DeployK8sWithMySql ▶️ View recording
DeployK8sWithPostgres ▶️ View recording
DeployK8sWithRabbitMQ ▶️ View recording
DeployK8sWithRedis ▶️ View recording
DeployK8sWithSqlServer ▶️ View recording
DeployK8sWithValkey ▶️ View recording
DeployTypeScriptAppToKubernetes ▶️ View recording
DescribeCommandResolvesReplicaNames ▶️ View recording
DescribeCommandShowsRunningResources ▶️ View recording
DetachFormatJsonProducesValidJson ▶️ View recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View recording
DoListStepsShowsPipelineSteps ▶️ View recording
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ 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
InteractiveCSharpInitCreatesExpectedFiles ▶️ View recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View recording
JavaScriptHostingApisRunFromTypeScriptAppHost ▶️ View recording
LatestCliCanStartStableChannelAppHost ▶️ View recording
LatestCliCanStartStableChannelTypeScriptAppHost ▶️ View recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View recording
LogLevelTrace_ProducesTraceEntriesInCliLogFile ▶️ View recording
LogsCommandShowsResourceLogs ▶️ View recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View recording
OtelLogsReturnsStructuredLogsFromStarterAppIsolated ▶️ View recording
PsCommandListsRunningAppHost ▶️ View recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View recording
ResourceCommand_FailedExecution_DisplaysAppHostLogPathAndLogContainsEntries ▶️ View recording
ResourceCommand_FailsWhenInteractionServiceIsRequired ▶️ View recording
ResourceCommand_SetAndDeleteParameterUpdatesDescribeOutput ▶️ View recording
RestoreGeneratesSdkFiles ▶️ View recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View recording
RunPublishFailureScenarioAsync ▶️ View recording
RunReportsSyntaxErrorsForDotNetAppHost ▶️ View recording
RunReportsSyntaxErrorsForTypeScriptAppHost ▶️ View recording
SecretCrudOnDotNetAppHost ▶️ View recording
SecretCrudOnTypeScriptAppHost ▶️ View recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View recording
StartReportsSyntaxErrorsForDotNetAppHost ▶️ View recording
StartReportsSyntaxErrorsForTypeScriptAppHost ▶️ View recording
StopAllAppHostsFromAppHostDirectory ▶️ View recording
StopJavaPolyglotAppHostUsingApphostDirectory ▶️ View recording
StopNonInteractiveSingleAppHost ▶️ View recording
StopTypeScriptPolyglotAppHostUsingApphostDirectory ▶️ View recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View recording
UpdateProjectChannelToStable_TypeScript_PicksUpStablePackages ▶️ View recording

📹 Recordings uploaded automatically from CI run #26168791131

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.

3 participants