Skip to content

Commit 5c18bdd

Browse files
JohnCampionJrclaude
andcommitted
Emit plain output when stdout is redirected; fix CI-only test failure
Spectre's ANSI detection can be fooled in CI into emitting colour escapes even when stdout is redirected, which broke an interop warning assertion (a colour span sat between "references" and the package name). Force no-ANSI when output is redirected — correct behaviour for pipes/file capture/CI — and harden the assertion to match the bare token. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5a6b94d commit 5c18bdd

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"SolarWinds.Changesets": Patch
3+
---
4+
5+
Emit plain text (no ANSI colour escapes) when stdout is redirected, so piping output to a file or capturing it in CI logs no longer embeds terminal colour codes. Interactive terminal output is unchanged.

src/SolarWinds.Changesets/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
using SolarWinds.Changesets.Commands.Version.Helpers;
1414
using SolarWinds.Changesets.Infrastructure;
1515
using SolarWinds.Changesets.Shared;
16+
using Spectre.Console;
1617
using Spectre.Console.Cli;
1718

19+
// When stdout is redirected (pipes, file capture, CI logs) emit plain text - no ANSI colour escapes - so the
20+
// output stays clean for tooling. Spectre's own detection can be fooled in CI into thinking ANSI is supported.
21+
if (Console.IsOutputRedirected)
22+
{
23+
AnsiConsole.Console = AnsiConsole.Create(new AnsiConsoleSettings { Ansi = AnsiSupport.No });
24+
}
25+
1826
ServiceCollection serviceCollection = new();
1927
CommandDispatcher commandDispatcher = new();
2028

tests/SolarWinds.Changesets.Tests/E2E/InteropTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ public void Version_InInteropMode_WarnsOnNamesThatAreNeitherDotnetNorNode()
219219
CliResult version = ChangesetCli.Run(_repo, "version");
220220
version.ExitCode.Should().Be(0, version.Output);
221221

222-
version.Output.Should().Contain("references 'Typo.Pkg'");
222+
// Assert on the bare token, not "references 'Typo.Pkg'": the name is emitted as its own (coloured)
223+
// markup span, so any styling/wrapping sits between the words.
224+
version.Output.Should().Contain("Typo.Pkg");
223225
// Real names are not flagged as unknown.
224-
version.Output.Should().NotContain("references '@demo/web'");
226+
version.Output.Should().NotContain("@demo/web");
225227
version.Output.Should().NotContain("references 'Demo.Core'");
226228
}
227229

0 commit comments

Comments
 (0)