Skip to content

Convert DotnetCommand tests with "new" to DotnetNewCommand#52697

Merged
marcpopMSFT merged 2 commits intomainfrom
copilot/convert-dotnetcommand-tests
Feb 3, 2026
Merged

Convert DotnetCommand tests with "new" to DotnetNewCommand#52697
marcpopMSFT merged 2 commits intomainfrom
copilot/convert-dotnetcommand-tests

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Tests using DotnetCommand for dotnet new operations were not enforcing ephemeral hive usage, causing intermittent test failures. DotnetNewCommand enforces hive configuration at construction time.

Changes

Converted 7 instances across 4 test files:

  • Microsoft.DotNet.PackageInstall.Tests/EndToEndToolTests.cs (3)
  • dotnet-new.IntegrationTests/DotnetNewInstallTests.cs (2)
  • dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs (1)
  • dotnet.Tests/CommandTests/Run/RunFileTests.cs (1)

Pattern

- new DotnetCommand(Log, "new", "tool-manifest")
+ new DotnetNewCommand(Log, "tool-manifest")
+     .WithVirtualHive()
      .WithWorkingDirectory(testDirectory.Path)
      .Execute()

DotnetNewCommand automatically prepends "new" and requires explicit hive configuration via WithVirtualHive(), WithCustomHive(), or WithoutCustomHive() before execution.

Original prompt

This section details on the original issue you should resolve

<issue_title>Convert all DotnetCommand tests that call "new" to DotnetNewCommand</issue_title>
<issue_description>We constantly see issues where the new command failes and needs to use the ephemeral hive. We should try to catch this in the dotnetcommand constructor and fail (if args[0] == "new") and convert all existing tests over so that we can enforce the ephemeral hives.</issue_description>

<agent_instructions>Look for tests that call DotnetCommand and do a new operation in that command. Likely they explicitly call out to the ephemeral hive. Try to move these tests over to use the DotnetNewCommand implementation instead. It should be very simple.

Example:

  •            new DotnetCommand(_log, "new", "console", "-o", path, "-n", "myconsole").Execute().Should().Pass();
    

becomes

  •             new DotnetNewCommand(_log, "console", "-o", path, "-n", "myconsole").Execute().Should().Pass();
    

if it has ephermeral hive, you can use WithVirtualHive()
</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@marcpopMSFT No rush on this but I thought this could be the next test update you do now that most tests are upgraded to the current target framework. Let me know if you have questions.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
@marcpopMSFT
Copy link
Member

Quick search of the repo shows those four test files have all of the DotnetCommand "new" entries so I think this PR is correct.

@marcpopMSFT marcpopMSFT marked this pull request as ready for review February 2, 2026 23:59
@marcpopMSFT marcpopMSFT requested a review from a team as a code owner February 2, 2026 23:59
Copilot AI review requested due to automatic review settings February 2, 2026 23:59
Copy link
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

This PR converts 7 test instances from using DotnetCommand for dotnet new operations to using the dedicated DotnetNewCommand class. This ensures ephemeral hive configuration is enforced at construction time, preventing intermittent test failures caused by missing hive configuration.

Changes:

  • Converted 7 DotnetCommand instances calling "new" to use DotnetNewCommand with explicit WithVirtualHive() configuration
  • Ensures all dotnet new test operations use ephemeral hive to avoid test interference

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Converted 1 instance in Precedence_NuGetTool test to use DotnetNewCommand with virtual hive
test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs Converted 1 instance in SameAsTemplate test to use DotnetNewCommand with virtual hive
test/dotnet-new.IntegrationTests/DotnetNewInstallTests.cs Converted 2 instances in CanInstallToPathWithAt test to use DotnetNewCommand with virtual hive
test/Microsoft.DotNet.PackageInstall.Tests/EndToEndToolTests.cs Converted 3 instances across multiple tests (InstallAndRunToolLocal, InstallAndRunNativeAotLocalTool, InstallToolWithHigherFrameworkAsLocalToolShowsAppropriateError) to use DotnetNewCommand with virtual hive

Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Do we have an idea of how often this is causing failures? Should we backport it to other branches?

@marcpopMSFT
Copy link
Member

Nice! Do we have an idea of how often this is causing failures? Should we backport it to other branches?

We had problems a few years ago with the hive used in the tests but we haven't seen this recently afaik. At the time, v-wuzhai made a pass over the tests but there were a few more tests that ended up using DotnetCommand since that change. There was an existing tracking bug that never got closed so I just had copilot clean up the rest. We could potentially try to flag it as a failure if you use new with a root command but probably not worth it.

@marcpopMSFT
Copy link
Member

/ba-g templating macos leg has been disabled

@marcpopMSFT marcpopMSFT merged commit dafcba7 into main Feb 3, 2026
28 of 30 checks passed
@marcpopMSFT marcpopMSFT deleted the copilot/convert-dotnetcommand-tests branch February 3, 2026 17:40
@dsplaisted
Copy link
Member

We could potentially try to flag it as a failure if you use new with a root command but probably not worth it.

If we have an easy way to add a build check for this, then I think we should do it. I don't think we have an easy way to add custom build checks though. @baronfel?

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.

Convert all DotnetCommand tests that call "new" to DotnetNewCommand

4 participants