Skip to content

diagnose: inject test AnsiConsole to diagnosecmd - #2501

Merged
mjcheetham merged 1 commit into
git-ecosystem:mainfrom
mjcheetham:fix-diag-test-output
Nov 9, 2026
Merged

mjcheetham merged 1 commit into
git-ecosystem:mainfrom
mjcheetham:fix-diag-test-output

Conversation

@mjcheetham

Copy link
Copy Markdown
Contributor

Diagnostics should try and avoid using other parts of GCM, because those components may be broken in some way. For this reason, the diagnose command does not use the IConsoleService, which provides a wrapper around a TTY and prompting AnsiConsole (from Spectre.Console), nor the IStandardStream, which wrap the stdin, stdout, and stderr streams of the parent process.

However, during unit tests of the diagnose command, our use of the static AnsiConsole for rich command output means the test harness gets the progress and other informational output. This is typically recommended against by most testing frameworks.

Instead, we inject a TestConsole : IAnsiConsole into the diagnose command during unit testing. The production command gets the singleton instance of the AnsiConsole.

Diagnostics should try and avoid using other parts of GCM, because those
components may be broken in some way. For this reason, the diagnose
command does not use the `IConsoleService`, which provides a wrapper
around a TTY and prompting `AnsiConsole` (from Spectre.Console), nor the
`IStandardStream`, which wrap the stdin, stdout, and stderr streams of
the parent process.

However, during unit tests of the diagnose command, our use of the
static `AnsiConsole` for rich command output means the test harness gets
the progress and other informational output. This is typically
recommended against by most testing frameworks.

Instead, we inject a `TestConsole : IAnsiConsole` into the diagnose
command during unit testing. The production command gets the singleton
instance of the `AnsiConsole`.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
@mjcheetham
mjcheetham requested a review from a team as a code owner November 9, 2026 14:46

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

Makes sense!

@mjcheetham
mjcheetham merged commit 3da3db9 into git-ecosystem:main Nov 9, 2026
23 of 24 checks passed
@mjcheetham
mjcheetham deleted the fix-diag-test-output branch November 9, 2026 14:58
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.

2 participants