Skip to content

Honor requested test architectures - #17143

Merged
Evangelink merged 7 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/fix-test-architectures
Jul 22, 2026
Merged

Evangelink merged 7 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/fix-test-architectures

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

  • defer TestArchitectures initialization until the SDK has finalized .NET Framework platform settings and infer the actual apphost or dotnet host architecture
  • pass the requested architecture to VSTest and select exact architecture-specific hosts for framework-dependent xUnit, xUnit v3, and MTP/MSTest runs
  • reject fixed-host architecture mismatches instead of running the same executable under misleading result names
  • document the runner-specific behavior and add structural plus execution-level MSBuild regression coverage

Fixes #16003

Validation

  • Build.cmd -test -projects src\Microsoft.DotNet.Arcade.Sdk.Tests\Microsoft.DotNet.Arcade.Sdk.Tests.csproj -configuration Debug
  • Build.cmd -configuration Release -test

Make VSTest and xUnit select the requested architecture, validate fixed-host runners before execution, and defer architecture inference until the SDK has finalized .NET Framework platform settings.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Honor resolved apphost RIDs, preserve custom run commands, select matching framework-dependent hosts, validate fixed .NET Framework executables, and add behavioral MSBuild coverage.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Copilot AI review requested due to automatic review settings July 17, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates Arcade SDK test infrastructure to honor TestArchitectures by selecting architecture-appropriate test hosts (or failing fast when that isn’t possible), and adds documentation + regression tests to lock in the new behavior. This aligns the reported test environment with the actual host architecture and prevents misleading “x86”/“x64” result naming when the same host is reused.

Changes:

  • Defer TestArchitectures initialization until execution time and infer the “built” (host/apphost) architecture, then validate requested-vs-built mismatches for fixed-host runners.
  • Pass the requested architecture through to VSTest (dotnet test --arch ...) and select architecture-specific dotnet hosts for framework-dependent xUnit, xUnit v3, and Microsoft.Testing.Platform when applicable.
  • Add MSBuild structural + execution-level tests and update documentation to describe runner-specific architecture behavior/constraints.
Show a summary per file
File Description
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets Opts into architecture mismatch validation and selects an architecture-specific dotnet host for default dotnet runs.
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.Runner.targets Selects architecture-specific dotnet host for Core xUnit runs and adds validation/erroring for unsupported arch scenarios.
src/Microsoft.DotNet.Arcade.Sdk/tools/VSTest.targets Passes requested architecture into dotnet test via --arch.
src/Microsoft.DotNet.Arcade.Sdk/tools/Tests.targets Defers TestArchitectures initialization, computes built/default architectures, and adds mismatch validation for fixed-host runners.
src/Microsoft.DotNet.Arcade.Sdk/tools/Microsoft.Testing.Platform/Microsoft.Testing.Platform.targets Opts into architecture mismatch validation and selects an architecture-specific dotnet host for default dotnet runs.
src/Microsoft.DotNet.Arcade.Sdk.Tests/TestArchitecturesTests.cs Adds regression tests validating target file structure and one execution-level behavior for apphost-driven defaults.
Documentation/ArcadeSdk.md Documents updated TestArchitectures defaults and runner-specific limitations/expectations.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 4

Use architecture-generic mismatch guidance and distinguish unknown host roots from missing architecture-specific dotnet installations.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Copilot AI review requested due to automatic review settings July 17, 2026 19:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new

Copilot AI review requested due to automatic review settings July 20, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 1

@Evangelink
Evangelink enabled auto-merge July 20, 2026 09:01
Ensure the test project collection releases loaded project state and file handles even when the behavioral assertion fails.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Copilot AI review requested due to automatic review settings July 20, 2026 09:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

Comments suppressed due to low confidence (3)

src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets:32

  • $(_ArchitectureSpecificDotNetTool) is only assigned when $(_DotNetHostRoot) is non-empty. Since MSBuild properties persist across batched target invocations, a previous batch can leave a stale value here, causing the later mismatch errors to report the wrong state (e.g., skipping the “path cannot be determined” case). Initialize the property to empty before the conditional assignment so each batch computes it deterministically.
      <_DotNetExecutableName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetExecutableName>
      <_ArchitectureSpecificDotNetTool Condition="'$(_DotNetHostRoot)' != ''">$([System.IO.Path]::Combine('$(_DotNetHostRoot)', '$(_TestArchitecture)', '$(_DotNetExecutableName)'))</_ArchitectureSpecificDotNetTool>

src/Microsoft.DotNet.Arcade.Sdk/tools/Microsoft.Testing.Platform/Microsoft.Testing.Platform.targets:20

  • $(_ArchitectureSpecificDotNetTool) is set conditionally, but MSBuild properties can carry over between batched RunTests executions. If $(_DotNetHostRoot) is empty for a later batch, the property can retain a previous non-empty value and trigger the wrong error path. Reset it to empty before the conditional assignment.
      <_DotNetExecutableName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetExecutableName>
      <_ArchitectureSpecificDotNetTool Condition="'$(_DotNetHostRoot)' != ''">$([System.IO.Path]::Combine('$(_DotNetHostRoot)', '$(_TestArchitecture)', '$(_DotNetExecutableName)'))</_ArchitectureSpecificDotNetTool>

src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.Runner.targets:34

  • $(_ArchitectureSpecificDotNetTool) is only assigned when $(_DotNetHostRoot) is non-empty. Because RunTests is batched over @(TestToRun) and MSBuild properties persist across batches, a stale value can carry over and make the host-selection and error conditions behave incorrectly. Clear it before the conditional assignment (similar to how _TestRunner is explicitly reset).
      <_DotNetExecutableName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetExecutableName>
      <_ArchitectureSpecificDotNetTool Condition="'$(_DotNetHostRoot)' != ''">$([System.IO.Path]::Combine('$(_DotNetHostRoot)', '$(_TestArchitecture)', '$(_DotNetExecutableName)'))</_ArchitectureSpecificDotNetTool>
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new

Copy the exact Arcade SDK targets inspected by TestArchitecturesTests into the test payload so the tests do not depend on a repository checkout in Helix.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Copilot AI review requested due to automatic review settings July 21, 2026 13:13
@Evangelink

Copy link
Copy Markdown
Member Author

CI investigation result: this was PR-related, not flaky.

Both failed builds (#1515428 and #1517435) consistently failed Microsoft.DotNet.Arcade.Sdk.Tests.dll on macOS arm64, Linux x64, and Windows x64. The new TestArchitecturesTests class initialized its target path by searching for the repository root, but Helix runs from a standalone payload without the checkout, causing Unable to locate the Arcade repository root before all six tests executed.

Fixed in 9cbfd454b by copying the exact five target files into the test payload and loading them from AppContext.BaseDirectory. The packaged payload contains all targets and all six TestArchitecturesTests pass when run directly from the built output.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 1

Default non-apphost .NET Core tests to DotNetToolArchitecture regardless of RuntimeIdentifier or PlatformTarget, with behavioral coverage for the documented contract.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1c1e5e2a-70de-4b38-b7c9-9cb041de9262
Copilot AI review requested due to automatic review settings July 21, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 0 new

@Evangelink
Evangelink merged commit 78f90ac into dotnet:main Jul 22, 2026
10 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 23, 2026
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.

Revise how TestArchitectures is used by test infrastructure

3 participants