Skip to content

Add [StackTraceHidden] to MTP and MSTest adapter test execution plumbing#8854

Merged
Evangelink merged 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/stack-trace-hidden-mtp
Jun 5, 2026
Merged

Add [StackTraceHidden] to MTP and MSTest adapter test execution plumbing#8854
Evangelink merged 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/stack-trace-hidden-mtp

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Follow-up to #8853 (assertion internals) and continues addressing @Youssef1313's feedback on #8826:

Why not use StackTraceHidden instead of trying to alter stack trace manually.

This PR annotates the MTP and MSTest adapter test execution plumbing types that always sit between the user test method and the top of a failure stack trace, so the runtime omits their frames from the public StackTrace surface.

Types annotated with [StackTraceHidden]

Microsoft.Testing.Platform hosts (Microsoft.Testing.Platform.Hosts):

  • CommonHost (abstract base)
  • ConsoleTestHost
  • ServerTestHost
  • TestHostControlledHost
  • TestHostControllersTestHost

VSTest bridge (Microsoft.Testing.Extensions.VSTestBridge):

  • VSTestBridgedTestFrameworkBase
  • SynchronizedSingleSessionVSTestBridgedTestFramework

MSTest adapter (Microsoft.VisualStudio.TestPlatform.MSTestAdapter / MSTest.TestAdapter):

  • MSTestBridgedTestFramework
  • MSTestExecutor
  • TestExecutionManager
  • UnitTestRunner
  • TestMethodRunner
  • TestMethodInfo (annotated on one partial; applies to all sibling partials via attribute merging)

Scope rationale

Kept narrow to types explicitly mentioned in #8826 plus the immediate execution wrappers between user code and reporter. Broader sweeps (e.g. all internals in Microsoft.Testing.Platform) are intentionally avoided to:

  • preserve extension authors' ability to debug their own extension code (extension contract types are not annotated),
  • avoid hiding frames that may carry genuine diagnostic value.

Notes / out of scope

  • Compiler-generated MoveNext / closure frames inside annotated async/iterator methods may still leak — a known [StackTraceHidden] runtime limitation. The rendering-layer filter proposed in Filter MTP/MSTest internal stack frames from terminal failure output #8826 may still be needed to handle those plus frames in types we don't own (e.g. VSTest object model).
  • Public exception types and the TestApplication public entry point are intentionally not annotated.

Validation

  • .\build.cmd -c Debug succeeds with 0 warnings / 0 errors.
  • The attribute is metadata-only; no runtime semantic impact beyond stack trace rendering.

Follow-up to PR microsoft#8853 (addressed assertion internals) and continues addressing @Youssef1313's feedback on microsoft#8826: use [StackTraceHidden] instead of trying to filter stack frames manually at the rendering layer.

Annotates the test execution plumbing types that always sit between the user test method and the top of a failure stack trace, so the runtime omits their frames from the public StackTrace surface:

Microsoft.Testing.Platform hosts (Microsoft.Testing.Platform.Hosts):
- CommonHost (abstract base)
- ConsoleTestHost
- ServerTestHost
- TestHostControlledHost
- TestHostControllersTestHost

VSTest bridge (Microsoft.Testing.Extensions.VSTestBridge):
- VSTestBridgedTestFrameworkBase
- SynchronizedSingleSessionVSTestBridgedTestFramework

MSTest adapter (Microsoft.VisualStudio.TestPlatform.MSTestAdapter / MSTest.TestAdapter):
- MSTestBridgedTestFramework
- MSTestExecutor
- TestExecutionManager
- UnitTestRunner
- TestMethodRunner
- TestMethodInfo (partial; applies to all sibling partials via attribute merging)

Scope rationale: kept narrow to types explicitly mentioned in microsoft#8826 plus the immediate execution wrappers between user code and reporter (per rubber-duck review). Broader sweeps (e.g. all internals in Microsoft.Testing.Platform) are intentionally avoided to (a) preserve extension authors' ability to debug their own extension code and (b) avoid hiding frames that may carry genuine diagnostic value.

Notes / out of scope:
- Compiler-generated MoveNext/closure frames inside annotated async/iterator methods may still leak — known [StackTraceHidden] limitation; the rendering-layer filter proposed in microsoft#8826 may still be needed to handle those plus types we don't own.
- Public exception types and the TestApplication public entry point are intentionally not annotated.

Build: .\build.cmd -c Debug succeeds with 0 warnings / 0 errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 5, 2026 09:31
@Evangelink Evangelink enabled auto-merge (squash) June 5, 2026 09:33

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 applies [StackTraceHidden] to key Microsoft.Testing.Platform (MTP) host and MSTest adapter execution “plumbing” types so that user-facing failure stack traces omit these framework frames, reducing noise between the user’s test/production code and the failure site.

Changes:

  • Annotate MTP host implementations (and their common base) with [StackTraceHidden].
  • Annotate VSTest bridge base types used in the bridged execution path with [StackTraceHidden].
  • Annotate MSTest adapter execution types that commonly appear in failure stack traces with [StackTraceHidden].
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs Hide common host base frames from stack traces.
src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs Hide console host frames from stack traces.
src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs Hide server host frames from stack traces.
src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControlledHost.cs Hide controlled-host wrapper frames from stack traces.
src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs Hide controller host frames from stack traces.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/VSTestBridgedTestFrameworkBase.cs Hide bridged framework base frames from stack traces.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/SynchronizedSingleSessionVSTestAndTestAnywhereAdapter.cs Hide single-session bridged framework frames from stack traces.
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs Hide adapter unit test runner frames from stack traces.
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs Hide adapter test-method runner frames from stack traces.
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodInfo.cs Hide adapter test-method info frames from stack traces (via partial).
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.cs Hide adapter execution manager frames from stack traces.
src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs Hide MSTest executor frames from stack traces.
src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestBridgedTestFramework.cs Hide MSTest bridged framework frames from stack traces.

Copilot's findings

  • Files reviewed: 13/13 changed files
  • Comments generated: 0

@Evangelink Evangelink merged commit 9d1394a into microsoft:main Jun 5, 2026
27 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/stack-trace-hidden-mtp branch June 5, 2026 11:38
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.

3 participants