Repository navigation
Labels
area/mtpMicrosoft.Testing.Platform core library.Microsoft.Testing.Platform core library.area/terminal-reporterConsole / terminal test reporter.Console / terminal test reporter.
Milestone
Description
Summary
Honor the NO_COLOR environment variable in the Microsoft.Testing.Platform terminal output. Today MTP only suppresses ANSI escape sequences via --no-ansi, --ansi off, or the LLMEnvironmentDetector (see src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs:147-184); it does not look at NO_COLOR at all.
Motivation
NO_COLORis the de-facto cross-tool convention for "I am piped/redirected/aren't a fan of color, please don't emit ANSI." Tools that honor it includegit,ripgrep,bat,gh,cargo, the .NET SDK itself, modern Node.js CLIs, and most coding-agent runtimes (Claude Code, Cursor, Codex, Aider).- Coding agents and CI systems commonly set
NO_COLOR=1rather than the MTP-specific--no-ansiflag. Today they get ANSI noise in failure output, which costs tokens and breaks log scraping. - The fix is small and matches existing precedence:
--ansi on|off|autostill wins, then--no-ansi, thenNO_COLOR, thenLLMEnvironmentDetector, then CI detection.
Proposed behavior
In TerminalOutputDevice.cs (resolution of AnsiMode):
explicit --ansi on -> AnsiMode.ForceAnsi
explicit --ansi off -> AnsiMode.NoAnsi
--no-ansi (no --ansi override) -> AnsiMode.NoAnsi
NO_COLOR env var is non-empty -> AnsiMode.NoAnsi (NEW)
LLMEnvironmentDetector matches -> AnsiMode.NoAnsi
in CI -> AnsiMode.SimpleAnsi
default -> AnsiMode.AnsiIfPossible
Per the NO_COLOR spec: "All command-line software which outputs text with ANSI color added should check for the presence of a NO_COLOR environment variable that, when present (regardless of its value), prevents the addition of ANSI color."
We treat any non-empty NO_COLOR value as enabling the behavior, matching the spec.
Notes
NO_COLORonly affects colors, not progress. Progress is independently controlled by--no-progressand the existing CI/LLM path that already forcesAnsiMode.NoAnsiwhich in turn disables progress. We could choose to also disable progress whenNO_COLORis set, but that's a separate decision — open question in the umbrella.- Should use the injected
IEnvironment.GetEnvironmentVariable("NO_COLOR")(not the staticEnvironment.GetEnvironmentVariable) so the behavior is unit-testable.
Acceptance criteria
- Setting
NO_COLOR(any non-empty value) to a process running MTP causes terminal output to be plain text (no ANSI escapes). --ansi onoverridesNO_COLOR(forces ANSI on).--ansi off,--no-ansi, and LLM-mode detection continue to work unchanged.- Unit test covers each precedence branch.
- No XLF / help / info changes needed (env vars aren't surfaced in
--help).
References
- Spec: https://no-color.org
- Umbrella: [RFC] Agent/LLM-efficient test output for Microsoft.Testing.Platform #8824
- Implementation site:
src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs(around lines 147-184) - Related: Add "no progress" and "no ANSI" environment variables #7647 (added
--no-ansi/--no-progressflags and LLM detection)
Metadata
Metadata
Assignees
Labels
area/mtpMicrosoft.Testing.Platform core library.Microsoft.Testing.Platform core library.area/terminal-reporterConsole / terminal test reporter.Console / terminal test reporter.
Activity
Evangelink commentedon Jun 4, 2026
Submitted PR #8831 implementing this.
Implementation note / trade-off -- the NO_COLOR spec strictly only forbids ANSI color codes. The PR maps
NO_COLORto MTP's existingNoAnsimode, which also disables cursor movement / live progress, matching what--no-ansidoes today. Rationale:SimpleAnsiNoColormode without breaking the contract added here.Precedence is preserved:
--ansi onstill wins overNO_COLOR.Honor NO_COLOR env var in TerminalOutputDevice (#8825) (#8831)
Drop policy enforcement; rely on instruction + native type field