Skip to content

Use Markdig for Aspire CLI docs rendering#16342

Open
davidfowl wants to merge 1 commit intomainfrom
davidfowl/markdig-docs-rendering
Open

Use Markdig for Aspire CLI docs rendering#16342
davidfowl wants to merge 1 commit intomainfrom
davidfowl/markdig-docs-rendering

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

Description

Replace the Aspire CLI docs rendering path with a Markdig-backed parser for DisplayMarkdown(...) so aspire docs can render richer markdown reliably in interactive terminals while still producing readable plain-text output for redirected/non-interactive streams.

This change keeps the scope narrow by routing only the docs display/plain-text conversion path through Markdig and leaving the older ConvertToSpectre(...) helper in place for unrelated callers. It also fixes nested list indentation, avoids duplicating bare URLs in plain-text output, adds broader regression coverage, adds a deterministic CLI E2E docs smoke test, and confirms the CLI still publishes and runs under NativeAOT.

Fixes #16339

Validation:

  • dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj -- --filter-class "*.DocsCacheTests" --filter-class "*.DocsFetcherTests" --filter-class "*.DocsIndexServiceTests" --filter-class "*.ConsoleInteractionServiceTests" --filter-class "*.MarkdownToSpectreConverterTests" --filter-class "*.DocsCommandTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • ASPIRE_E2E_ARCHIVE=/tmp/aspire-e2e.tar.gz dotnet test tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj -- --filter-method "*.DocsCommand_RendersInteractiveMarkdownFromLocalSource" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • dotnet publish src/Aspire.Cli/Aspire.Cli.csproj -r osx-arm64 -c Debug

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?

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 20:33
@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 -- 16342

Or

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

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 updates Aspire CLI’s docs/markdown display path to use a Markdig-based parser for DisplayMarkdown(...), improving fidelity for richer markdown (tables, nested lists, autolinks) in interactive terminals while keeping a readable plain-text fallback for redirected/non-interactive output.

Changes:

  • Add a Markdig-backed markdown parsing/rendering path via MarkdownToSpectreConverter.ConvertToRenderable(...) and route ConsoleInteractionService.DisplayMarkdown(...) through it.
  • Extend markdown conversion test coverage (tables, autolinks, nested list indentation, quoted structured content).
  • Add a deterministic CLI E2E smoke test for interactive aspire docs get rendering from a local docs source.
Show a summary per file
File Description
src/Aspire.Cli/Utils/MarkdownToSpectreConverter.cs Introduces Markdig parsing and a renderable-based Spectre output path (including table support).
src/Aspire.Cli/Interaction/ConsoleInteractionService.cs Switches DisplayMarkdown interactive rendering from markup strings to Spectre renderables.
src/Aspire.Cli/Aspire.Cli.csproj Adds Markdig dependency to Aspire CLI.
tests/Aspire.Cli.Tests/Utils/MarkdownToSpectreConverterTests.cs Adds regression coverage for tables, autolinks, nested lists, and quote/code/link scenarios.
tests/Aspire.Cli.Tests/Interaction/ConsoleInteractionServiceTests.cs Strengthens assertions for markdown display and adds an interactive table rendering test.
tests/Aspire.Cli.Tests/Commands/DocsCommandTests.cs Adds a rich-markdown docs regression test and makes the test docs index service more configurable.
tests/Aspire.Cli.EndToEnd.Tests/DocsCommandE2ETests.cs Adds an E2E interactive rendering smoke test for aspire docs get.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 3

Comment on lines +399 to +400
var linkText = string.IsNullOrEmpty(text) ? url.EscapeMarkup() : text;
return $"[cyan][link={url}]{linkText}[/][/]";
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

When constructing Spectre hyperlink markup, the link target should be escaped (e.g., with Markup.Escape / EscapeMarkup) before placing it in the [link=...] attribute. Currently the raw URL is inserted, so a URL containing ']' (or other markup-sensitive characters) can break markup parsing or allow unintended markup injection from docs content.

Suggested change
var linkText = string.IsNullOrEmpty(text) ? url.EscapeMarkup() : text;
return $"[cyan][link={url}]{linkText}[/][/]";
var escapedUrl = url.EscapeMarkup();
var linkText = string.IsNullOrEmpty(text) ? escapedUrl : text;
return $"[cyan][link={escapedUrl}]{linkText}[/][/]";

Copilot uses AI. Check for mistakes.
{
var repoRoot = CliE2ETestHelpers.GetRepoRoot();
var strategy = CliInstallStrategy.Detect();
var workspace = TemporaryWorkspace.Create(output);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

TemporaryWorkspace implements IDisposable and is responsible for deleting the on-disk workspace on success. This test creates a workspace without disposing it, which will leak temp directories across runs (unless preserved). Use a using declaration or otherwise ensure it gets disposed at the end of the test.

Suggested change
var workspace = TemporaryWorkspace.Create(output);
using var workspace = TemporaryWorkspace.Create(output);

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +211
var executionContext = new CliExecutionContext(new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-runtimes")), new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-logs")), "test.log");
var interactionService = CreateInteractionService(console, executionContext);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The test uses fixed paths under Path.GetTempPath() ("aspire-test-runtimes" / "aspire-test-logs"). Using shared fixed temp directories can cause cross-test interference when tests run in parallel or when prior runs leave state behind. Prefer a unique temp subdirectory per test run (e.g., Directory.CreateTempSubdirectory()) and create runtime/log directories under it.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 73 recordings uploaded (commit 8d1c053)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ 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
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ 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_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
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ 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 #24688968338

ListBlock list => RenderListToPlainText(list),
CodeBlock codeBlock => GetRawCodeText(codeBlock).TrimEnd('\r', '\n'),
MarkdigTable table => RenderTableToPlainText(table),
_ => string.Empty
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are these all the types that need to be handled?

Is the list complete? Is skipping unknown items the right thing to do?

return builder.ToString();
}

private static string RenderListItem(ListItemBlock item, string prefix, int continuationIndent, Func<Block, string> blockRenderer)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are creating a lot of throw away strings. Should we just be passing in the StringBuilder into these private methods?

}
}

private static string IndentBlock(string content, string prefix)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IndentedTextWriter?

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.

Consider using Markdig for Aspire CLI docs rendering

3 participants