Skip to content

Fix MSTEST0082 follow-up gaps - #10637

Open
Amaury Levé (Evangelink) wants to merge 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/fix-mstest0082-followups
Open

Fix MSTEST0082 follow-up gaps#10637
Amaury Levé (Evangelink) wants to merge 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/fix-mstest0082-followups

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Follow-up to #10508 addressing substantive review findings that remained after merge.

Changes

  • Resolve the active MSTest framework from each applied [TestClass], so aliased v3/v4 references no longer disable MSTEST0082.
  • Restrict canonical attribute detection to the known MSTest framework assemblies, avoiding false positives from namespace/name lookalikes.
  • Mirror adapter discovery for generic method definitions and invalid TestContext properties.
  • Share exact runtime TestContext property validation with DependsOnShouldBeValidAnalyzer.
  • Clarify remediation when a custom MSTest attribute is defined in a separate assembly.
  • Add regression coverage for aliased frameworks, legacy TestContext, lookalike attributes, uninferable generic tests, and separate custom-attribute libraries.

Validation

  • Targeted InheritedMemberFromDifferentMSTestVersionAnalyzerTests: 61 passed.
  • Full MSTest.Analyzers.UnitTests net8.0 suite: 1,788 passed.
  • Targeted project builds for net8.0 and net472 with 0 errors.

Resolve MSTest framework identity per test class, mirror adapter TestContext and generic discovery behavior, reject lookalike attributes, and clarify custom attribute remediation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8aa70d5a-57df-47a6-b5dc-addbffedea90
Copilot AI balanced review requested due to automatic review settings August 18, 2026 11:13

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

Improves MSTEST0082 accuracy across aliased frameworks, runtime discovery edge cases, and custom attributes.

Changes:

  • Resolve canonical MSTest attributes only from recognized framework assemblies.
  • Align generic-method and TestContext validation with adapter behavior.
  • Add regressions and clarify localized remediation guidance.
Show a summary per file
File Description
src/Analyzers/MSTest.Analyzers/InheritedMemberFromDifferentMSTestVersionAnalyzer.cs Refines framework and discovery detection.
src/Analyzers/MSTest.Analyzers/DependsOnShouldBeValidAnalyzer.cs Uses shared TestContext validation.
src/Analyzers/MSTest.Analyzers/Helpers/FixtureUtils.cs Adds shared runtime-compatible validation.
src/Analyzers/MSTest.Analyzers/Resources.resx Clarifies custom-attribute remediation.
src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf Synchronizes Czech localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf Synchronizes German localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf Synchronizes Spanish localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf Synchronizes French localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf Synchronizes Italian localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf Synchronizes Japanese localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf Synchronizes Korean localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf Synchronizes Polish localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf Synchronizes Portuguese localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf Synchronizes Russian localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf Synchronizes Turkish localization source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf Synchronizes Simplified Chinese source.
src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf Synchronizes Traditional Chinese source.
test/UnitTests/MSTest.Analyzers.UnitTests/InheritedMemberFromDifferentMSTestVersionAnalyzerTests.cs Adds edge-case regression coverage.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 18/18 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Build failure analysis

Outcome: All 6 primary build legs (Linux Debug/Release, macOS Debug/Release, Windows Debug/Release) failed to compile with identical errors. Both Windows acceptance-test legs compiled cleanly (no errors), so the failure is isolated to the build/compile stage, not test execution.

Root cause

Two IDE code-style analyzer diagnostics are configured as build-breaking errors (EnforceCodeStyleInBuild/.editorconfig severity) and are triggered by this PR's new test-helper code in:

test/UnitTests/MSTest.Analyzers.UnitTests/InheritedMemberFromDifferentMSTestVersionAnalyzerTests.cs

Line Code Message
2896 IDE0022 Use expression body for method
2954 IDE0303 (×2) Collection initialization can be simplified

Both offending lines are new/modified in this PR (visible in the diff hunks @@ -2611,10 +2893,15 @@ and @@ -2658,6 +2945,41 @@), so this is not a pre-existing/flaky issue — it's introduced by the PR's added helper methods AddLegacyFrameworkBaseProject(SolutionState, string) and AddAliasedLegacyFrameworkBaseLibrary.

Suggested fixes

  1. Line 2896 — the method body is a single statement, so IDE0022 wants it expression-bodied:

    private static void AddLegacyFrameworkBaseProject(SolutionState testState, string libraryCode)
        => AddAdditionalProject(testState, LegacyFrameworkAssemblyName, libraryCode);
  2. Line 2954ImmutableArray.Create("legacy") can be simplified to a collection expression:

    legacyFramework.WithProperties(legacyFramework.Properties.WithAliases(["legacy"])));

See inline review comments for exact diff suggestions.

Build overview

  • All 6 build legs report the same 3 errors + a generic "Build failed." (Windows legs show each duplicated across two TFMs/configs in one binlog).
  • Both application-model acceptance-test legs (7_0, 7_1) show zero errors — confirming the compile failure, not a test/Helix issue, is the root cause.
  • Verified PR head SHA is unchanged (0af457a4aedefb6b66b2854bb46bc27fc44b980c) at time of posting.

🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · auto · 199.4 AIC · ⌖ 2.1 AIC · ⊞ 11.6K · [◷]( · )

@github-actions github-actions Bot 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.

🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · auto · 199.4 AIC · ⌖ 2.1 AIC · ⊞ 11.6K ·

libraryProject.Sources.Add(("LegacyBase.cs", libraryCode));
testState.AdditionalProjects.Add(LegacyFrameworkAssemblyName, libraryProject);
testState.AdditionalProjectReferences.Add(LegacyFrameworkAssemblyName);
AddAdditionalProject(testState, LegacyFrameworkAssemblyName, libraryCode);

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.

Build error (IDE0022 — Use expression body for method): this single-statement method body is flagged as a build-breaking code-style violation in CI (all 6 build legs failed on this).

Suggested change
AddAdditionalProject(testState, LegacyFrameworkAssemblyName, libraryCode);
private static void AddLegacyFrameworkBaseProject(SolutionState testState, string libraryCode)
=> AddAdditionalProject(testState, LegacyFrameworkAssemblyName, libraryCode);

MetadataReference baseLibrary = EmitAssembly("BaseLibrary", baseLibraryCode, legacyFramework);

test.TestState.AdditionalReferences.Add(
legacyFramework.WithProperties(legacyFramework.Properties.WithAliases(ImmutableArray.Create("legacy"))));

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.

Build error (IDE0303 — Collection initialization can be simplified): ImmutableArray.Create("legacy") triggers a build-breaking code-style diagnostic. Simplify to a collection expression:

Suggested change
legacyFramework.WithProperties(legacyFramework.Properties.WithAliases(ImmutableArray.Create("legacy"))));
legacyFramework.WithProperties(legacyFramework.Properties.WithAliases(["legacy"])));

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.

2 participants