Skip to content

Commit b910e57

Browse files
Copilotbaronfel
andauthored
Fix first-run experience output interfering with completion commands (#50454)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: baronfel <[email protected]>
1 parent 84f317f commit b910e57

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

.github/copilot-instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Coding Style and Changes:
66
Testing:
77
- Large changes should always include test changes.
88
- The Skip parameter of the Fact attribute to point to the specific issue link.
9+
- To run tests in this repo:
10+
- Use the repo-local dotnet instance: `./.dotnet/dotnet`
11+
- For MSTest-style projects: `dotnet test path/to/project.csproj --filter "FullyQualifiedName~TestName"`
12+
- For XUnit test assemblies: `dotnet exec artifacts/bin/redist/Debug/TestAssembly.dll -method "*TestMethodName*"`
13+
- Examples:
14+
- `dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter "Name~ItShowsTheAppropriateMessageToTheUser"`
15+
- `dotnet exec artifacts/bin/redist/Debug/dotnet.Tests.dll -method "*ItShowsTheAppropriateMessageToTheUser*"`
916

1017
Output Considerations:
1118
- When considering how output should look, solicit advice from baronfel.

src/Cli/dotnet/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ private static void ConfigureDotNetForFirstTimeUse(
389389
var environmentPath = EnvironmentPathFactory.CreateEnvironmentPath(isDotnetBeingInvokedFromNativeInstaller, environmentProvider);
390390
_ = new DotNetCommandFactory(alwaysRunOutOfProc: true);
391391
var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
392-
var reporter = Reporter.Output;
392+
var reporter = Reporter.Error;
393393
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
394394
firstTimeUseNoticeSentinel,
395395
aspNetCertificateSentinel,

test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public void UsingDotnetForTheFirstTimeWithNonVerbsDoesNotPrintEula()
103103
.StartWith(firstTimeNonVerbUseMessage);
104104
}
105105

106-
[WindowsOnlyFact]
106+
[Fact]
107107
public void ItShowsTheAppropriateMessageToTheUser()
108108
{
109109

110110
var expectedVersion = GetDotnetVersion();
111-
_fixture.FirstDotnetVerbUseCommandResult.StdOut
111+
_fixture.FirstDotnetVerbUseCommandResult.StdErr
112112
.Should()
113113
.ContainVisuallySameFragment(string.Format(
114114
Configurer.LocalizableStrings.FirstTimeMessageWelcome,
@@ -118,6 +118,30 @@ public void ItShowsTheAppropriateMessageToTheUser()
118118
.And.NotContain("Restore completed in");
119119
}
120120

121+
[WindowsOnlyFact]
122+
public void FirstRunExperienceMessagesShouldGoToStdErr()
123+
{
124+
// This test ensures that first-run experience messages go to stderr,
125+
// not stdout, to avoid interfering with completion commands and other
126+
// tools that parse stdout. See: https://github.com/dotnet/sdk/issues/50444
127+
var expectedVersion = GetDotnetVersion();
128+
129+
// StdErr should contain first-run messages
130+
_fixture.FirstDotnetVerbUseCommandResult.StdErr
131+
.Should()
132+
.ContainVisuallySameFragment(string.Format(
133+
Configurer.LocalizableStrings.FirstTimeMessageWelcome,
134+
DotnetFirstTimeUseConfigurer.ParseDotNetVersion(expectedVersion),
135+
expectedVersion))
136+
.And.ContainVisuallySameFragment(Configurer.LocalizableStrings.FirstTimeMessageMoreInformation);
137+
138+
// StdOut should NOT contain first-run messages (they should only be in stderr)
139+
_fixture.FirstDotnetVerbUseCommandResult.StdOut
140+
.Should()
141+
.NotContain("Welcome to .NET")
142+
.And.NotContain("Write your first app");
143+
}
144+
121145
[Fact]
122146
public void ItCreatesAFirstUseSentinelFileUnderTheDotDotNetFolder()
123147
{
@@ -164,7 +188,7 @@ public void ItShowsTheTelemetryNoticeWhenInvokingACommandAfterInternalReportInst
164188

165189
var expectedVersion = GetDotnetVersion();
166190

167-
result.StdOut
191+
result.StdErr
168192
.Should()
169193
.ContainVisuallySameFragment(string.Format(
170194
Configurer.LocalizableStrings.FirstTimeMessageWelcome,

0 commit comments

Comments
 (0)