Skip to content

Unify ApplicationStateGuard across copies (#9316)#9329

Merged
Evangelink merged 9 commits into
mainfrom
fix/9316-dedup-applicationstateguard
Jun 22, 2026
Merged

Unify ApplicationStateGuard across copies (#9316)#9329
Evangelink merged 9 commits into
mainfrom
fix/9316-dedup-applicationstateguard

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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.

…9316)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 22, 2026 09:25

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 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 return UnreachableException for 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

Comment thread src/Platform/Microsoft.Testing.Platform/Helpers/ApplicationStateGuard.cs Outdated

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 ✅ — UnreachableException polyfill in src/Polyfills/UnreachableException.cs (guarded #if !NETCOREAPP) is glob-included by all four affected projects, so the type change compiles on net462, netstandard2.0, and all UWP/WinUI targets.
  • Backward Compatibility ✅ — Unreachable() is internal in all four classes; no public API surface changed.
  • Test Coverage ✅ — No existing test catches InvalidOperationException from a path routed through ApplicationStateGuard.Unreachable(). The one test that uses Unreachable() 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.

Comment thread src/Platform/Microsoft.Testing.Platform/Helpers/ApplicationStateGuard.cs Outdated
Copilot AI and others added 6 commits June 22, 2026 13:34
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>
Copilot AI review requested due to automatic review settings June 22, 2026 11:35

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: 9/9 changed files
  • Comments generated: 8

…ess alias, normalize encoding

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jun 22, 2026
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>
Copilot AI review requested due to automatic review settings June 22, 2026 12:33
@Evangelink
Evangelink merged commit 009410c into main Jun 22, 2026
14 of 21 checks passed
@Evangelink
Evangelink deleted the fix/9316-dedup-applicationstateguard branch June 22, 2026 12:36

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: 20/20 changed files
  • Comments generated: 4

Comment on lines +4 to +5
/* 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. */
Comment on lines +4 to +5
/* 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. */
Comment on lines +4 to +5
/* 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>
@Evangelink

Copy link
Copy Markdown
Member Author

🧪 Test quality grade — PR #9329

3 test methods graded (all modified) across 3 files. Distribution: 2 × C, 1 × A. Both C-grade tests use the broad Assert.Throws<Exception> / Assert.ThrowsAsync<Exception> catch required by cross-assembly polyfill constraints — the rubric mechanically flags this as High → C ceiling; the A-grade test avoids the broad-catch pattern entirely and scores cleanly.

ΔTestGradeBandNotes
mod ConfigurationExtensionsTests.
ConfigurationExtensions_
TestedMethod_
ThrowsArgumentNullException
C 70–79 Assert.Throws(Exception) (High → C ceiling) is intentional — follow-up FullName check makes it specific.
mod StopPoliciesServiceTests.
RegisterOnMaxFailedTestsCallbackAsync_
ThrowsIfNotTestHost
C 70–79 Assert.ThrowsAsync(Exception) (High → C); narrowed by type-name check; foreach over 2 roles could be [DataRow].
mod ApplicationStateGuardTests.
Unreachable_
ReturnsUnreachableException
A 90–100 No issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 Automated content 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 Grade Tests on PR (on open / sync) workflow. · 495 AIC · ⌖ 12.9 AIC · ⊞ 43.7K · [◷]( · )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code: ApplicationStateGuard utility class copied across 4 projects with behavioral divergence

4 participants