Replace custom RemoveSpectreFormatting with Spectre.Console's Markup.Remove#18209
Replace custom RemoveSpectreFormatting with Spectre.Console's Markup.Remove#18209JamesNK wants to merge 2 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18209Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18209" |
There was a problem hiding this comment.
Pull request overview
This PR replaces a custom regex-based RemoveSpectreFormatting() extension method with Spectre.Console's built-in Markup.Remove() static method across the CLI codebase. The change improves correctness (proper handling of escaped brackets and nested tags) and reduces maintenance of a custom regex pattern.
Changes:
- Replaced all usages of
StringUtils.RemoveSpectreFormatting()withMarkup.Remove()across three files - Removed the
RemoveSpectreFormattingextension method, itsGeneratedRegex, thepartialmodifier, and theSystem.Text.RegularExpressionsusing fromStringUtils.cs
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Aspire.Cli/Utils/StringUtils.cs | Removed the RemoveSpectreFormatting extension method, associated regex, partial modifier, and regex using |
| src/Aspire.Cli/Interaction/ExtensionInteractionService.cs | Replaced 17 call sites from .RemoveSpectreFormatting() to Markup.Remove(...) |
| src/Aspire.Cli/Interaction/ConsoleInteractionService.cs | Replaced 1 call site from .RemoveSpectreFormatting() to Markup.Remove(...) |
| src/Aspire.Cli/Backchannel/ExtensionBackchannel.cs | Replaced 2 call sites from .RemoveSpectreFormatting() to Markup.Remove(...) |
PR Testing ReportPR Information
Artifact Version Verification
Changes AnalyzedFiles Changed
Change Categories
Test Scenarios ExecutedScenario 1: Unit TestsObjective: Verify all CLI unit tests pass with the replacement Results: 4106 tests executed, 0 failed, 4080 succeeded, 26 skipped Scenario 2: Template Creation (aspire-starter)Objective: Exercise DisplayMessage/ShowStatus paths that use Markup.Remove Steps:
Observations:
Scenario 3: Error Display (invalid apphost path)Objective: Verify error display through Markup.Remove renders cleanly Steps:
Observations:
Scenario 4: Doctor CommandObjective: Exercise multiple status/warning/success display paths Steps:
Observations:
Summary
Overall Result✅ PR VERIFIED Low-risk internal refactoring. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
@adamint The VS Code E2E tests have failed 6 times on this PR. Please fix them. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
❓ CLI E2E Tests unknown — 114 passed, 0 failed, 3 unknown (commit View all recordings
📹 Recordings uploaded automatically from CI run #27551911405 |
…in choice label throws InvalidOperationException Tests that Markup.Remove throws InvalidOperationException when a choice formatter returns text with unescaped ']' characters, which was previously silently stripped by the regex-based RemoveSpectreFormatting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Summary
Replace the custom
RemoveSpectreFormatting()extension method with Spectre.Console's built-inMarkup.Remove()static method.Changes
StringUtils.RemoveSpectreFormatting()withMarkup.Remove()acrossExtensionInteractionService.cs,ConsoleInteractionService.cs, andExtensionBackchannel.csRemoveSpectreFormattingextension method and itsGeneratedRegexfromStringUtils.cspartialmodifier andSystem.Text.RegularExpressionsusing fromStringUtils.csMotivation
Markup.Remove()is the official Spectre.Console API for stripping markup tags. It properly handles edge cases (escaped brackets, nested tags) that the simple regex\[[^\]]+\]could miss. Using the built-in method reduces maintenance burden and improves correctness.Testing
All 4106 CLI tests pass.