Skip to content

Honor NO_COLOR env var in TerminalOutputDevice (#8825)#8831

Merged
Evangelink merged 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/no-color-support
Jun 5, 2026
Merged

Honor NO_COLOR env var in TerminalOutputDevice (#8825)#8831
Evangelink merged 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/no-color-support

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Fixes #8825.

Adds support for the de-facto cross-tool NO_COLOR environment variable in TerminalOutputDevice. When NO_COLOR is set with any non-empty value, MTP suppresses ANSI escape sequences in terminal output, matching the behavior of the existing --no-ansi flag and LLM environment detection.

Precedence (unchanged ordering, NO_COLOR slotted in)

  1. --ansi on -> ForceAnsi (wins over everything, including NO_COLOR)
  2. --ansi off -> NoAnsi
  3. --no-ansi OR NO_COLOR set OR LLM env detected -> NoAnsi
  4. CI detected -> SimpleAnsi
  5. default -> AnsiIfPossible

Trade-off note

The NO_COLOR spec strictly only forbids ANSI color codes. This PR maps NO_COLOR to MTP's NoAnsi mode, which also disables cursor movement / live progress, matching what --no-ansi does. 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 a SimpleAnsiNoColor mode without breaking this contract.

Tests

Three new acceptance tests in AnsiOptionTests:

  • NoColorEnvVar_NonEmpty_DisablesAnsiOutput -- in a (mocked) CI env with --ansi auto, setting NO_COLOR=1 produces output with no ESC.
  • NoColorEnvVar_Empty_IsIgnored -- empty NO_COLOR is a no-op per spec; SimpleAnsi ESC still emitted.
  • NoColorEnvVar_OverriddenByExplicitAnsiOn -- --ansi on overrides NO_COLOR.

NO_COLOR was added to WellKnownEnvironmentVariables.ToSkipEnvironmentVariables so an ambient developer/CI value cannot leak into other acceptance tests.


Part of the agent/LLM-efficient test output effort tracked in #8824.

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

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 TerminalOutputDevice ANSI-mode resolution to treat non-empty NO_COLOR as AnsiMode.NoAnsi (below explicit --ansi on|off, alongside --no-ansi and LLM detection).
  • Add acceptance coverage for NO_COLOR (non-empty disables ANSI, empty is ignored, --ansi on overrides).
  • Prevent ambient NO_COLOR from 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

@Evangelink Evangelink enabled auto-merge (squash) June 5, 2026 07:30
@Evangelink Evangelink merged commit 930f592 into microsoft:main Jun 5, 2026
27 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/no-color-support branch June 5, 2026 07:56
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.

Honor NO_COLOR environment variable in MTP terminal output

3 participants