Unify ApplicationStateGuard across copies (#9316)#9329
Conversation
…9316) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses #9316 by aligning the behavior of the duplicated ApplicationStateGuard.Unreachable() helpers across Platform, Adapter, TestFramework, and Analyzers so they consistently return UnreachableException (while Ensure() continues throwing InvalidOperationException). It also adds comments intended to document the intentional source-copy pattern across these layered projects.
Changes:
- Switch
ApplicationStateGuard.Unreachable()in Platform and Adapter copies to returnUnreachableExceptionfor consistency with TestFramework and Analyzers. - Add “source-copy / keep in sync” comments to all four copies, pointing at the Platform file as canonical.
Show a summary per file
| File | Description |
|---|---|
| src/TestFramework/TestFramework/Internal/ApplicationStateGuard.cs | Adds source-copy sync comment referencing the canonical Platform copy. |
| src/Platform/Microsoft.Testing.Platform/Helpers/ApplicationStateGuard.cs | Changes Unreachable() to return UnreachableException; adds source-copy sync comment. |
| src/Analyzers/MSTest.Analyzers/Helpers/ApplicationStateGuard.cs | Adds source-copy sync comment referencing the canonical Platform copy. |
| src/Adapter/MSTestAdapter.PlatformServices/Utilities/ApplicationStateGuard.cs | Changes Unreachable() to return UnreachableException; adds source-copy sync comment. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 1
Evangelink
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
| # | Dimension | Verdict |
|---|---|---|
| 17 | Documentation Accuracy | 🟢 1 NIT |
✅ 21/22 dimensions clean.
- Documentation — canonical Platform file's sync comment is self-referential (points to itself)
Notes on key dimensions checked:
- Cross-TFM Compatibility ✅ —
UnreachableExceptionpolyfill insrc/Polyfills/UnreachableException.cs(guarded#if !NETCOREAPP) is glob-included by all four affected projects, so the type change compiles onnet462,netstandard2.0, and all UWP/WinUI targets. - Backward Compatibility ✅ —
Unreachable()isinternalin all four classes; no public API surface changed. - Test Coverage ✅ — No existing test catches
InvalidOperationExceptionfrom a path routed throughApplicationStateGuard.Unreachable(). The one test that usesUnreachable()in the adapter unit tests (TestMethodRunnerTests.cs:399) uses it as an unreachable lambda, not in a catch assertion. - Algorithmic Correctness ✅ —
UnreachableException(System.Diagnostics.UnreachableException) is the canonical type for "should never execute" guards; the type change is semantically correct and does not weaken any invariant.
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
… polyfill type identity mismatch On non-NETCOREAPP TFMs (net462/net48) UnreachableException is an internal, per-assembly [Embedded] polyfill. Asserting via the generic type parameter compared against each test assembly's own copy and could fail due to type identity mismatch with the copy thrown from a referenced assembly. Capture the exception as the base Exception type and assert on GetType().FullName instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ess alias, normalize encoding Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve conflicts in ClassCleanupManager.cs (adopt main's AdapterApplicationStateGuard alias) and three UnreachableException assertions (keep typeof(...).FullName form). Regenerate TerminalResources xlf for new strings introduced on main. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| /* This file is intentionally copied across layered projects; keep it in sync with the canonical copy at | ||
| * src\Platform\Microsoft.Testing.Platform\Helpers\ApplicationStateGuard.cs. */ |
| /* This file is intentionally copied across layered projects; keep it in sync with the canonical copy at | ||
| * src\Platform\Microsoft.Testing.Platform\Helpers\ApplicationStateGuard.cs. */ |
| /* This file is intentionally copied across layered projects; keep it in sync with the canonical copy at | ||
| * src\Platform\Microsoft.Testing.Platform\Helpers\ApplicationStateGuard.cs. */ |
| <trans-unit id="Try"> | ||
| <source>try {0}</source> | ||
| <target state="new">try {0}</target> | ||
| <note>number or tries of the current test assembly when test assembly is being retried. {0} is number that starts at 1</note> |
🧪 Test quality grade — PR #93293 test methods graded (all modified) across 3 files. Distribution: 2 × C, 1 × A. Both C-grade tests use the broad
This advisory comment was generated automatically. Grades are heuristic
|
Fixes #9316. Updates the Platform and Adapter ApplicationStateGuard.Unreachable() copies to return UnreachableException, matching the TestFramework and Analyzer copies. All four projects already include the shared UnreachableException polyfill/global using, so no copy needed to stay on InvalidOperationException; Ensure() continues to throw InvalidOperationException. Adds source-copy comments pointing to the Platform canonical copy.