Skip to content

[test-improver] Add edge-case tests for SharedFileSystemPathInTestAnalyzer delete/move operations #10299

Description

@github-actions

Goal and Rationale

Adds 3 missing test cases for MSTEST0077 (SharedFileSystemPathInTestAnalyzer) covering mutation operations that were not previously exercised: File.Delete, Directory.Delete, and Directory.Move.

The analyzer has complex per-method path-role logic: Copy only flags the destination, Move flags both source and destination (both are mutations), Replace flags the destination and backup. The Delete paths for both File and Directory were conspicuously missing from the test suite — tests only covered CreateDirectory, Copy, Move (for File), Replace, OpenWrite, and WriteAllText variants.

Approach

Added 3 [TestMethod] tests to SharedFileSystemPathInTestAnalyzerTests:

  1. WhenTestMethodDeletesFileWithConstantPath_DiagnosticFile.Delete("shared.txt") in a parallelized test class should be flagged.
  2. WhenTestMethodDeletesDirectoryWithConstantPath_DiagnosticDirectory.Delete("shared-dir") should be flagged.
  3. WhenTestMethodMovesDirectory_BothSourceAndDestAreDiagnosticDirectory.Move("source-dir", "dest-dir") should be flagged; both paths are mutated (source is removed, destination is created), and the analyzer reports the first constant mutated path found.

Test Status

✅ Build succeeded, all 21 SharedFileSystemPath tests pass (0 failures).

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • southcentralus0.in.applicationinsights.azure.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "southcentralus0.in.applicationinsights.azure.com"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Test Improver workflow. · sonnet46 176.5 AIC · ⌖ 15 AIC · ⊞ 13.6K · [◷]( · )
Comment /test-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/test-improver.md@main

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch test-assist/shared-filesystem-delete-tests-4ec1c826fe306fe3.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (119 of 119 lines)
From bf6e2437485098b02d01bc0958a969adf624b260 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 28 Jul 2026 23:25:21 +0000
Subject: [PATCH] test: add edge-case tests for
 SharedFileSystemPathInTestAnalyzer delete/move operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add 3 new tests for MSTEST0077 covering previously untested mutation operations:
- File.Delete with constant path → Diagnostic
- Directory.Delete with constant path → Diagnostic
- Directory.Move with constant source and destination → Diagnostic (first mutated path arg reported)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 ...SharedFileSystemPathInTestAnalyzerTests.cs | 87 +++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs
index def0bb2..ab381cf 100644
--- a/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs
+++ b/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs
@@ -493,4 +493,91 @@ await VerifyCS.VerifyAnalyzerAsync(
                 .WithLocation(0)
                 .WithArguments("setup.txt"));
     }
+
+    [TestMethod]
+    public async Task WhenTestMethodDeletesFileWithConstantPath_Diagnostic()
+    {
+        // File.Delete is a mutating operation: removing a shared file by constant path
+        // is a race condition under method-level parallelization.
+        string code = """
+            using System.IO;
+            using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+            [assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)]
+
+            [TestClass]
+            public class MyTestClass
+            {
+                [TestMethod]
+                public void MyTest
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions