Skip to content

[code-simplifier] Simplify RedundantTestMethodAttributeAnalyzer named-argument lookups - #11304

Merged
Amaury Levé (Evangelink) merged 6 commits into
mainfrom
code-simplifier/redundant-test-method-attribute-analyzer-49b5906d3e2a4a9c
Sep 16, 2026
Merged

Amaury Levé (Evangelink) merged 6 commits into
mainfrom
code-simplifier/redundant-test-method-attribute-analyzer-49b5906d3e2a4a9c

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Consolidate three duplicated foreach loops over AttributeData.NamedArguments (searching for a single named argument by key) into a shared TryGetNamedArgument helper, reused by HasNonEmptyConditionIgnoreMessage, GetNamedIntArgument, and TryGetIgnoreMessage.

Fixes #11303

Consolidate three duplicated foreach loops over AttributeData.NamedArguments
(searching for a single named argument by key) into a shared
TryGetNamedArgument helper, reused by HasNonEmptyConditionIgnoreMessage,
GetNamedIntArgument, and TryGetIgnoreMessage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 15, 2026 14:03
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 15, 2026

@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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Summary

This PR is a small, self-contained internal refactor of RedundantTestMethodAttributeAnalyzer.cs. It consolidates three duplicated "find named argument by key" loops (HasNonEmptyConditionIgnoreMessage, GetNamedIntArgument, TryGetIgnoreMessage) into a single shared TryGetNamedArgument helper, and converts two methods to expression-bodied members. No public API surface, resources, or behavior-affecting logic paths are touched.

Semantic equivalence verified: Attribute named-argument keys are unique per attribute usage, so TryGetNamedArgument's "return on first key match" is equivalent to each original loop's per-key scan. The fallback behavior when a matched value's runtime type doesn't match the expected type (int in GetNamedIntArgument, string in the IgnoreMessage cases) is preserved identically (falls through to the default/prior value), matching the original implementations exactly.

Verdict by Dimension

# Dimension Verdict
1 Algorithmic Correctness Clean — refactor is behavior-preserving; traced all 3 call sites against original loops
2 Threading & Concurrency N/A — no shared mutable state introduced
3 Public API Surface N/A — all changed members are private static
4 Backward Compatibility N/A — internal analyzer implementation detail only
5 Performance Clean — marginal improvement (single shared helper, same O(n) scan)
6 Cross-TFM Correctness Clean — no TFM-specific constructs used
7 IPC Contract Stability N/A
8 Localization N/A — no resource/string changes
9 Test Coverage Clean — pure refactor of existing, already-tested logic; no new branches introduced that would require new tests
10 Security N/A
11 Explicit vs. Implicit Clean — TryGetNamedArgument is a clear, idiomatic Try* pattern
12 Simplicity Improvement — reduces duplication, more concise expression-bodied members
13–22 (Analyzers/design/style/etc.) N/A / clean — no findings

Findings

None. No inline comments were necessary — the change is a straightforward, verified-equivalent internal refactor with no functional, API, or style concerns.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 15, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 15, 2026

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 review overview

🟡 Changes recommended

The helper currently returns the first matching IgnoreMessage, changing existing behavior for duplicate entries.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite (auto)
Findings: 1 Medium severity

Note

Copilot is running an experiment and ran this review at Lite.

Open (1)
What changed in this PR

This pull request centralizes named-argument lookups in RedundantTestMethodAttributeAnalyzer.

Changes:

  • Adds shared TryGetNamedArgument logic.
  • Reuses it across condition, retry, and ignore-message handling.
  • Requires preserving the previous last-match behavior for duplicate IgnoreMessage entries.
File Summary
src/​Analyzers/​MSTest.Analyzers/​RedundantTestMethodAttributeAnalyzer.cs Consolidates duplicated named-argument lookup logic.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 15, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 15, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 15, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Sep 15, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 15, 2026 15:41
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Sep 15, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 15, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Sep 15, 2026

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 review overview

🟡 Changes recommended

Preserve the previous typed lookup behavior in GetNamedIntArgument.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite (auto)
Findings: 1 Medium severity

Note

Copilot is running an experiment and ran this review at Lite.

Open (1)
Resolved since last review (1)

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 15, 2026
Copilot AI review requested due to automatic review settings September 16, 2026 16:23
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 16, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Sep 16, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Sep 16, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Sep 16, 2026

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 review overview

🟢 Approval recommended

The only finding is a minor test-count update.

Review effort: Lite (auto)
Findings: None

Note

Copilot is running an experiment and ran this review at Lite.

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 16, 2026 16:31

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 review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite (auto)
Findings: None

Note

Copilot is running an experiment and ran this review at Lite.

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings September 16, 2026 17:34
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Sep 16, 2026

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 review overview

🟢 Approval recommended

No blocking issues were identified; remaining feedback is a minor validation-count clarification.

Review effort: Lite (auto)
Findings: None

Note

Copilot is running an experiment and ran this review at Lite.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Final test-triage resolution — Azure Pipelines build 1599689

Analysis is final (completed build, analysisMode: full).

Signature: MtpServerClientCancellationAcceptanceTests.RunTestsAsync_WhenCanceledAfterTestStarts_TestObservesTestContextCancellationAndShutsDownCleanly failed only on the Windows Release leg with:

System.IO.IOException: The process cannot access the file 'C:\Users\cloudtest\AppData\Local\Temp\mtp-cancellation-signal-0559b99a96964ed39d9ae415ef375773.txt' because it is being used by another process.

The same test passed on the Linux Release and MacOS Release legs in this same build, so the failure is isolated to Windows file-handle contention around the cancellation-signal temp file rather than a cross-platform product regression.

Confidence: Moderate. The stack trace shows the failure originates from opening the signal file (AsyncWindowsFileStreamStrategy ctor), consistent with a race between the test process and the spawned MTP host process both touching the same temp file without a sharing mode/retry — a plausible test-harness race rather than a product defect, but not proven without a second occurrence.

History: Checked up to 12 prior completed builds (main branch, 30-day window; history.incomplete=true due to artifact-download-failed/download-budget-exhausted, so absence of prior occurrences is not conclusive). Every retrieved sample for this test passed (durations ~1.8–2.6s), with no prior failure signature matching this one. This is a single occurrence tied only to the current PR, with no corroborating historical recurrence.

Decision: Per the persistent-failure threshold, this does not warrant a new issue (only one occurrence, no cross-build recurrence, no existing matching issue found in a search of open/closed issues for this test/class/signal-file name). Recommend a maintainer re-run the Windows leg to confirm this was a transient file-locking race; if it recurs on an unrelated commit/build, it should be escalated then.

No corresponding issue created; other build legs for this PR are unaffected (candidateCount 94, only 1 failure/retry signal, 0 diagnostics).

🤖 Automated content by GitHub Copilot. Generated by the Pipeline Test Triage workflow. · copilot · auto · 49 AIC · ⌖ 5.41 AIC · ⊞ 9.4K

@Evangelink
Amaury Levé (Evangelink) merged commit d18b0b4 into main Sep 16, 2026
31 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the code-simplifier/redundant-test-method-attribute-analyzer-49b5906d3e2a4a9c branch September 16, 2026 20:58
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Sep 16, 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.

[code-simplifier] Simplify RedundantTestMethodAttributeAnalyzer named-argument lookups

3 participants