Skip to content

Fix CloneWithUpdatedSource mutating this instead of the clone#9581

Merged
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/shiny-fiesta
Jul 3, 2026
Merged

Fix CloneWithUpdatedSource mutating this instead of the clone#9581
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/shiny-fiesta

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #9573

TestMethod.CloneWithUpdatedSource(string source) (and by extension UnitTestElement.CloneWithUpdatedSource) assigned the new source and cleared MethodInfo on this rather than on the returned clone. As a result, the "updated-source" clone kept the old source/MethodInfo, while the shared original element was mutated as a side effect.

Change

var clone = (TestMethod)MemberwiseClone();
clone.AssemblyName = source;   // was: AssemblyName = source;
clone.MethodInfo = null;       // was: MethodInfo = null;
return clone;

UnitTestElement.CloneWithUpdatedSource delegates to this method, so it is fixed transitively.

Build passes with 0 warnings/errors.

Fixes #9573

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 14:21
@Evangelink Evangelink enabled auto-merge (squash) July 3, 2026 14:23
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 3, 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.

Pull request overview

Fixes an object-model cloning bug in the MSTest adapter platform services layer where TestMethod.CloneWithUpdatedSource mutated the original TestMethod instance instead of the returned clone, causing the clone to retain stale source/MethodInfo while introducing side effects on the shared original.

Changes:

  • Update CloneWithUpdatedSource to assign AssemblyName on the cloned instance.
  • Update CloneWithUpdatedSource to clear MethodInfo on the cloned instance (not on this).
Show a summary per file
File Description
src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/TestMethod.cs Corrects CloneWithUpdatedSource to mutate the clone rather than the original instance.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

@Evangelink Evangelink disabled auto-merge July 3, 2026 15:09
@Evangelink Evangelink merged commit 4d655f1 into main Jul 3, 2026
31 of 35 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/shiny-fiesta branch July 3, 2026 15:09
github-actions Bot added a commit that referenced this pull request Jul 4, 2026
- Add --report-azdo-groups/--report-azdo-annotations toggles (#9542) to Platform changelog
- Add re-print errored assemblies in end-of-run recap (#9545) to Platform changelog
- Add server-initiated session cancellation (#9549) to Platform changelog
- Add fix for CloneWithUpdatedSource mutating this (#9581) to MSTest changelog

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Evangelink added a commit that referenced this pull request Jul 5, 2026
…9613)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Evangelink added a commit that referenced this pull request Jul 8, 2026
- #9670 stays in MSTest 4.3.0 since it's being backported to rel/4.3 (only #9581 remains under 4.4.0).
- Add new 2.3.0 stable HtmlReport and experimental (1.0.0-alpha.26357.13) extension packages (CtrfReport, GitHubActionsReport, JUnitReport, Logging, PackagedApp, VideoRecorder) to the MTP 2.3.0 artifacts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

CloneWithUpdatedSource mutates this instead of the returned clone

3 participants