Honor NO_COLOR env var in TerminalOutputDevice (#8825)#8831
Merged
Evangelink merged 1 commit intoJun 5, 2026
Conversation
Adds support for the de-facto cross-tool NO_COLOR convention (https://no-color.org). When the NO_COLOR environment variable is set with any non-empty value, MTP now disables ANSI escape sequences in terminal output, matching the behavior of the existing `--no-ansi` flag and the LLM environment detection. Precedence is preserved: * `--ansi on` -> ForceAnsi (wins over everything, incl. NO_COLOR) * `--ansi off` -> NoAnsi * `--no-ansi` OR NO_COLOR set OR LLM env detected -> NoAnsi * CI detected -> SimpleAnsi * default -> AnsiIfPossible Adds three acceptance tests covering: NO_COLOR non-empty disables ANSI, empty NO_COLOR is ignored per spec, and `--ansi on` overrides NO_COLOR. Adds NO_COLOR to the TestHost env-var skip-list so ambient settings cannot leak into other acceptance tests. Fixes microsoft#8825 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for the cross-tool NO_COLOR environment variable to Microsoft.Testing.Platform’s terminal output, ensuring ANSI escape sequences are suppressed when NO_COLOR is set (unless explicitly overridden by --ansi on). This aligns MTP behavior with common CLI ecosystem conventions while preserving the existing precedence rules.
Changes:
- Update
TerminalOutputDeviceANSI-mode resolution to treat non-emptyNO_COLORasAnsiMode.NoAnsi(below explicit--ansi on|off, alongside--no-ansiand LLM detection). - Add acceptance coverage for
NO_COLOR(non-empty disables ANSI, empty is ignored,--ansi onoverrides). - Prevent ambient
NO_COLORfrom leaking into other acceptance tests by filtering it out in test infrastructure environment propagation.
Show a summary per file
| File | Description |
|---|---|
| src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs | Honors non-empty NO_COLOR by selecting AnsiMode.NoAnsi unless explicitly overridden by --ansi on. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AnsiOptionTests.cs | Adds acceptance tests validating NO_COLOR behavior and precedence vs --ansi on / CI auto-detection. |
| test/Utilities/Microsoft.Testing.TestInfrastructure/WellKnownEnvironmentVariables.cs | Adds NO_COLOR to the “skip/clear ambient env vars” list to avoid test flakiness from developer/CI shells. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 0
JanKrivanek
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8825.
Adds support for the de-facto cross-tool
NO_COLORenvironment variable inTerminalOutputDevice. WhenNO_COLORis set with any non-empty value, MTP suppresses ANSI escape sequences in terminal output, matching the behavior of the existing--no-ansiflag and LLM environment detection.Precedence (unchanged ordering, NO_COLOR slotted in)
--ansi on->ForceAnsi(wins over everything, includingNO_COLOR)--ansi off->NoAnsi--no-ansiORNO_COLORset OR LLM env detected ->NoAnsiSimpleAnsiAnsiIfPossibleTrade-off note
The NO_COLOR spec strictly only forbids ANSI color codes. This PR maps
NO_COLORto MTP'sNoAnsimode, which also disables cursor movement / live progress, matching what--no-ansidoes. This is the user-intuitive behavior most CLIs converge on in practice, and keeps the change tight. If a future user wants "live progress without color" specifically, a follow-up could introduce aSimpleAnsiNoColormode without breaking this contract.Tests
Three new acceptance tests in
AnsiOptionTests:NoColorEnvVar_NonEmpty_DisablesAnsiOutput-- in a (mocked) CI env with--ansi auto, settingNO_COLOR=1produces output with no ESC.NoColorEnvVar_Empty_IsIgnored-- emptyNO_COLORis a no-op per spec;SimpleAnsiESC still emitted.NoColorEnvVar_OverriddenByExplicitAnsiOn----ansi onoverridesNO_COLOR.NO_COLORwas added toWellKnownEnvironmentVariables.ToSkipEnvironmentVariablesso an ambient developer/CI value cannot leak into other acceptance tests.Part of the agent/LLM-efficient test output effort tracked in #8824.