ITADN

[test-improver] test: MSTEST0061 — add edge case tests for OSPlatform.Create and mobile OS platforms

#9808Opengithub-actions[bot] 创建于 2026-07-09
type/test-gaptype/automationagentic-workflows
## Goal and rationale Add tests for previously untested code paths in `UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzer` (MSTEST0061). The analyzer has two distinct code paths for extracting the OS platform name from `RuntimeInformation.IsOSPlatform()` calls: - **Property reference path**: `OSPlatform.Windows`, `OSPlatform.Linux`, etc. — already tested - **`OSPlatform.Create()` path**: `OSPlatform.Create("Windows")` — not previously tested Additionally, `OperatingSystem.Is*()` methods for mobile/embedded platforms (iOS, Android, tvOS, etc.) were not tested. These map to platform names that have **no corresponding `OperatingSystems` enum value**, meaning the analyzer fires but the fixer cannot produce a code fix. ## Approach Four new tests in `UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests`: | Test | Code Path | Fix? | |------|-----------|------| | `WhenOSPlatformCreateWithKnownPlatform_Diagnostic` | `OSPlatform.Create("Windows")` → `TryGetOSPlatformFromIsOSPlatformCall` Create branch | ✅ fixes to `[OSCondition(OperatingSystems.Windows)]` | | `WhenOSPlatformCreateWithUnknownPlatform_Diagnostic` | `OSPlatform.Create("CustomOS")` → Create branch, no `OperatingSystems` mapping | ❌ analyzer fires, fixer does nothing | | `WhenOperatingSystemIsIOS_Diagnostic` | `OperatingSystem.IsIOS()` → maps to `"iOS"`, no `OperatingSystems.iOS` | ❌ analyzer fires, fixer does nothing | | `WhenOperatingSystemIsAndroid_Diagnostic` | `OperatingSystem.IsAndroid()` → maps to `"Android"`, no `OperatingSystems.Android` | ❌ analyzer fires, fixer does nothing | ## Trade-offs The `WhenOSPlatformCreateWithUnknownPlatform_Diagnostic` and mobile-platform tests confirm that the fixer silently does nothing for unsupported platforms (returns the original document unchanged). This is a known limitation — a future improvement could suppress the code action when no mapping exists. ## Test Status All 27 tests in `UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests` pass: ``` Test run summary: Passed! total: 27, failed: 0, succeeded: 27, skipped: 0 ``` ## Reproducibility ```bash ./build.sh --restore dotnet run --project test/UnitTests/MSTest.Analyzers.UnitTests -f net8.0 --no-build -- \ --filter "ClassName~UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests" ``` > [!WARNING] > <details> > <summary>Firewall blocked 1 domain</summary> > > 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: > > ```yaml > network: > allowed: > - defaults > - "southcentralus0.in.applicationinsights.azure.com" > ``` > > See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information. > > </details> > 🤖 **Automated content by GitHub Copilot.** Generated by the [Test Improver](https://github.com/microsoft/testfx/actions/runs/29057048445/agentic_workflow) workflow. · 323.7 AIC · ⌖ 15.8 AIC · ⊞ 13K · [◷]( · [◷](https://github.com/search?q=repo%3Amicrosoft%2Ftestfx+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests)) > <details> <summary>Add this agentic workflows to your repo</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.65, model: claude-sonnet-4.6, id: 29057048445, workflow_id: test-improver, run: https://github.com/microsoft/testfx/actions/runs/29057048445 --> <!-- 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/mstest0061-edge-cases-52785e4e63cda568`. > > **[Click here to create the pull request](https://github.com/microsoft/testfx/compare/main...test-assist/mstest0061-edge-cases-52785e4e63cda568?expand=1&title=%5Btest-improver%5D%20test%3A%20MSTEST0061%20%E2%80%94%20add%20edge%20case%20tests%20for%20OSPlatform.Create%20and%20mobile%20OS%20platforms)** 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 (166 of 166 lines)</summary> ```diff From 03fee88fa8dbe794cdfb2500706f0d0702482e4d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 23:33:07 +0000 Subject: [PATCH] =?UTF-8?q?test:=20MSTEST0061=20=E2=80=94=20add=20edge=20c?= =?UTF-8?q?ase=20tests=20for=20OSPlatform.Create=20and=20mobile=20OS=20pla?= =?UTF-8?q?tforms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add four tests covering previously untested code paths in UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzer: 1. WhenOSPlatformCreateWithKnownPlatform_Diagnostic — exercises the OSPlatform.Create("Windows") branch in TryGetOSPlatformFromIsOSPlatformCall. The fixer maps 'Windows' to OperatingSystems.Windows and applies the fix. 2. WhenOSPlatformCreateWithUnknownPlatform_Diagnostic — exercises the same OSPlatform.Create() branch with a custom platform name ('CustomOS') that has no OperatingSystems enum mapping; the analyzer fires but the fixer produces no change. 3. WhenOperatingSystemIsIOS_Diagnostic — exercises the OperatingSystem.IsIOS() branch of TryGetOSPlatformFromOperatingSystemCall. Maps to 'iOS', which has no OperatingSystems enum value; analyzer fires, fixer has no fix. 4. WhenOperatingSystemIsAndroid_Diagnostic — same as above for IsAndroid(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ibuteInsteadOfRuntimeCheckAnalyzerTests.cs | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests.cs index 9df03cf..5b5173c 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests.cs @@ -815,4 ... (truncated) ``` </details>
0 条评论