ITADN

[test-improver] Add coverage for untested File.* mutation methods in SharedFileSystemPathInTestAnalyzer (MSTEST0077)

#10422Closedgithub-actions[bot] 创建于 19 天前
type/test-gaptype/automationagentic-workflows
## Goal and Rationale `SharedFileSystemPathInTestAnalyzer` (MSTEST0077) maintains an explicit allowlist of `File.*` mutation methods in `IsMutatingFileSystemMethod`. While the core scenarios (`WriteAllText`, `Delete`, `Move`, `Copy`, `Replace`, `OpenWrite`) were tested, a large subset of the allowlist had no tests: **Untested methods discovered:** - Void: `AppendAllText`, `AppendAllLines`, `WriteAllBytes`, `WriteAllLines`, `SetAttributes`, `SetCreationTime`, `SetCreationTimeUtc`, `SetLastAccessTime`, `SetLastAccessTimeUtc`, `SetLastWriteTime`, `SetLastWriteTimeUtc`, `Encrypt`, `Decrypt` - Non-void: `AppendText`, `CreateText`, `CreateSymbolicLink` Without tests, these could be silently removed from the allowlist without detection. ## Approach Added two data-driven test methods to `SharedFileSystemPathInTestAnalyzerTests.cs`: 1. **`WhenTestMethodCallsVoidFileMutationMethodWithConstantPath_Diagnostic`** — covers 13 void-returning `File.*` methods. Each row verifies the analyzer fires on the constant path argument when `[Parallelize]` is in effect. 2. **`WhenTestMethodCallsNonVoidFileMutationMethodWithConstantPath_Diagnostic`** — covers 3 non-void-returning methods (`AppendText`, `CreateText`, `CreateSymbolicLink`) using `_ =` discard to avoid compiler warnings. Both tests verify the constant path value reported in the diagnostic message. ## Coverage Impact No measurable line-coverage change (the analyzer code paths were already reachable via existing tests). The value is **allowlist regression coverage**: each data row pins a specific method name in the analyzer's string list. ## Trade-offs - Minimal maintenance burden: data rows only need updating if method names in the allowlist change - Async variants (`AppendAllTextAsync`, etc.) are excluded because they return `Task` and using them without `await` in a void method produces CS4014, which the test harness rejects as an unexpected diagnostic ## Reproducibility ```sh ./build.sh -test --projects "$(pwd)/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj" ``` ## Test Status Not run locally (requires .NET SDK 11 preview). The tests follow the same data-driven pattern as the existing `WhenTestMethodSetsDirectoryTimestampWithConstantPath_Diagnostic` test, which was already accepted and merged. > 🤖 **Automated content by GitHub Copilot.** Generated by the [Test Improver](https://github.com/microsoft/testfx/actions/runs/30861659309/agentic_workflow) workflow. · sonnet46 · 299.8 AIC · ⌖ 15.5 AIC · ⊞ 13.7K · [◷]( · [◷](https://github.com/search?q=repo%3Amicrosoft%2Ftestfx+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests)) > <sub>Comment <em>/test-assist</em> to run again</sub> > <details> <summary><sub>Add this agentic workflow to your repo</sub></summary> To install this agentic workflow, run ``` gh aw add githubnext/agentics/workflows/test-improver.md@main ``` </details> <!-- gh-aw-agentic-workflow: Test Improver, engine: copilot, version: 1.0.75, model: claude-sonnet-4.6, id: 30861659309, workflow_id: test-improver, run: https://github.com/microsoft/testfx/actions/runs/30861659309 --> <!-- gh-aw-workflow-id: test-improver --> <!-- gh-aw-workflow-call-id: microsoft/testfx/test-improver --> --- > [!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-fs-path-more-file-methods-2aa3f37e37225175`. > > **[Click here to create the pull request](https://github.com/microsoft/testfx/compare/main...test-assist/shared-fs-path-more-file-methods-2aa3f37e37225175?expand=1&title=%5Btest-improver%5D%20Add%20coverage%20for%20untested%20File.*%20mutation%20methods%20in%20SharedFileSystemPathInTestAnalyzer%20(MSTEST0077))** To fix the permissions issue, go to **Settings** → **Actions** → **General** and enable **Allow GitHub Actions to create and approve pull requests**. See also: [gh-aw FAQ](https://github.github.com/gh-aw/reference/faq/#why-is-my-create-pull-request-workflow-failing-with-github-actions-is-not-permitted-to-create-or-approve-pull-requests) <details><summary>Show patch preview (120 of 120 lines)</summary> ```diff From 8cd48c67d357c86ccad40492b590adfb6b23059d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 23:25:22 +0000 Subject: [PATCH] test: add coverage for untested File.* mutation methods in SharedFileSystemPathInTestAnalyzer Pin the IsMutatingFileSystemMethod allowlist with data-driven tests for the following File.* methods that were listed in the analyzer but had no corresponding test cases: Void-returning (new WhenTestMethodCallsVoidFileMutationMethodWithConstantPath_Diagnostic): AppendAllText, AppendAllLines, WriteAllBytes, WriteAllLines, SetAttributes, SetCreationTime, SetCreationTimeUtc, SetLastAccessTime, SetLastAccessTimeUtc, SetLastWriteTime, SetLastWriteTimeUtc, Encrypt, Decrypt Non-void-returning, using discard (new WhenTestMethodCallsNonVoidFileMutationMethodWithConstantPath_Diagnostic): AppendText, CreateText, CreateSymbolicLink Each test verifies that the analyzer fires on the constant path argument when [Parallelize] is in effect, and pins the expected path string reported in the diagnostic message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...SharedFileSystemPathInTestAnalyzerTests.cs | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs index 4c47c3e..e98f8f0 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/SharedFileSystemPathInTestAnalyzerTests.cs @@ -850,4 +850,83 @@ await VerifyCS.VerifyAnalyzerAsync( .WithLocation(0) .WithArguments("setup.txt")); } + + [DataRow("AppendAllText", "\"shared.log\", \"entry\"")] + [DataRow("AppendAllLines", "\"shared.log\", new[] { \"line\" }")] + [DataRow("WriteAllBytes", ... (truncated) ``` </details>
关闭于 19 天前 0 条评论