Coverage Analysis Purpose Raw coverage percentages answer "what code was executed?" — they don't answer what you actually need to know: - What tests should I write next? — ranked by risk and impact - Which uncovered code is risky vs. trivial? — CRAP scores separate the two - Why has coverage plateaued? — identify the files blocking further gains - Is this code safe to refactor? — complex + uncovered = dangerous to change This skill bridges that gap: from a bare .NET solution to a prioritized risk hotspot list, with no manual tool configuration required. When to Use Use this skill when the use…

-Quiet)\n }\n if ($alreadyIgnored) {\n Write-Host \"GITIGNORE_RECOMMENDATION:already-present\"\n } else {\n Write-Host \"GITIGNORE_RECOMMENDATION:$pattern\"\n }\n} else {\n Write-Host \"GITIGNORE_RECOMMENDATION:$pattern\"\n}\n```\n\n### Phase 2 — Test execution (skip when Cobertura XML already exists)\n\nRun only when no Cobertura XML is present. If the user already has coverage data, skip directly to Phase 3.\n\n#### Step 3: Detect coverage provider and run `dotnet test` with coverage collection\n\nBefore running tests, detect which coverage provider the test projects use. Projects may reference\n`Microsoft.Testing.Extensions.CodeCoverage` (Microsoft's built-in provider, common on .NET 9+) or\n`coverlet.collector` (open-source, the default in xUnit templates). The provider determines which\n`dotnet test` arguments to use — both produce Cobertura XML.\n\n```powershell\n# Detect coverage provider per test project\n$coverageProvider = \"unknown\" # will be set to \"ms-codecoverage\" or \"coverlet\"\n$msCodeCovProjects = @()\n$coverletProjects = @()\n$neitherProjects = @()\n\nforeach ($tp in $testProjects) {\n $hasMsCodeCov = Select-String -Path $tp.FullName -Pattern 'Microsoft\\.Testing\\.Extensions\\.CodeCoverage' -Quiet\n $hasCoverlet = Select-String -Path $tp.FullName -Pattern 'coverlet\\.collector' -Quiet\n if ($hasMsCodeCov) { $msCodeCovProjects += $tp }\n elseif ($hasCoverlet) { $coverletProjects += $tp }\n else { $neitherProjects += $tp }\n}\n\n# Determine the provider strategy\nif ($msCodeCovProjects.Count -gt 0 -and $coverletProjects.Count -eq 0) {\n $coverageProvider = \"ms-codecoverage\"\n Write-Host \"COVERAGE_PROVIDER:ms-codecoverage (ms:$($msCodeCovProjects.Count), none:$($neitherProjects.Count))\"\n} elseif ($coverletProjects.Count -gt 0 -and $msCodeCovProjects.Count -eq 0) {\n $coverageProvider = \"coverlet\"\n Write-Host \"COVERAGE_PROVIDER:coverlet (coverlet:$($coverletProjects.Count), none:$($neitherProjects.Count))\"\n} elseif ($msCodeCovProjects.Count -gt 0 -and $coverletProjects.Count -gt 0) {\n $coverageProvider = \"mixed-project\"\n Write-Host \"COVERAGE_PROVIDER:mixed-project (ms:$($msCodeCovProjects.Count), coverlet:$($coverletProjects.Count), none:$($neitherProjects.Count))\"\n} else {\n $coverageProvider = \"coverlet\"\n Write-Host \"COVERAGE_PROVIDER:none-detected — defaulting to coverlet\"\n}\n```\n\nIf any discovered test projects have no provider, add one based on the selected strategy:\n\n```powershell\nif ($coverageProvider -eq \"ms-codecoverage\" -and $neitherProjects.Count -gt 0) {\n Write-Host \"ADDING_MS_CODECOVERAGE:$($neitherProjects.Count) project(s)\"\n foreach ($tp in $neitherProjects) {\n dotnet add $tp.FullName package Microsoft.Testing.Extensions.CodeCoverage --no-restore\n Write-Host \" ADDED_MS_CODECOVERAGE:$($tp.FullName)\"\n }\n foreach ($tp in $neitherProjects) {\n dotnet restore $tp.FullName --quiet\n }\n}\n\nif (($coverageProvider -eq \"coverlet\" -or $coverageProvider -eq \"mixed-project\") -and $neitherProjects.Count -gt 0) {\n Write-Host \"ADDING_COVERLET:$($neitherProjects.Count) project(s)\"\n foreach ($tp in $neitherProjects) {\n dotnet add $tp.FullName package coverlet.collector --no-restore\n Write-Host \" ADDED:$($tp.FullName)\"\n }\n foreach ($tp in $neitherProjects) {\n dotnet restore $tp.FullName --quiet\n }\n}\n```\n\nLog each addition to the console so the developer sees what changed. Document the additions in the final report (see Output Format).\n\nRun one `dotnet test` per entry point for the selected strategy:\n\n- In `ms-codecoverage` or `coverlet` mode: run a single command for the solution entry (or one per test project if no `.sln` was found).\n- In `mixed-project` mode: run one command per test project, using that project's existing provider to avoid dual-provider conflicts.\n\n**Coverlet** (`coverlet.collector`):\n\n```powershell\n$rawDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\"\ndotnet test \"\u003cENTRY>\" `\n --collect:\"XPlat Code Coverage\" `\n --results-directory $rawDir `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include=\"[*]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=\"[*.Tests]*,[*.Test]*,[*Tests]*,[*Test]*,[*.Specs]*,[*.Testing]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.SkipAutoProps=true\n```\n\n**Microsoft CodeCoverage** (`Microsoft.Testing.Extensions.CodeCoverage`):\n\nThe command syntax depends on the .NET SDK version. In .NET 9, Microsoft.Testing.Platform arguments\nmust be passed after the `--` separator. In .NET 10+, `--coverage` is a top-level `dotnet test` flag.\n\n```powershell\n$rawDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\"\n\n# Detect SDK version for correct argument placement\n$sdkVersion = (dotnet --version 2>$null)\n$major = if ($sdkVersion -match '^(\\d+)\\.') { [int]$Matches[1] } else { 9 }\n\nif ($major -ge 10) {\n # .NET 10+: --coverage is a first-class dotnet test flag\n dotnet test \"\u003cENTRY>\" `\n --results-directory $rawDir `\n --coverage `\n --coverage-output-format cobertura `\n --coverage-output $rawDir\n} else {\n # .NET 9: pass Microsoft.Testing.Platform arguments after the -- separator\n dotnet test \"\u003cENTRY>\" `\n --results-directory $rawDir `\n -- --coverage --coverage-output-format cobertura --coverage-output $rawDir\n}\n```\n\n**Mixed-project mode** (`Microsoft.Testing.Extensions.CodeCoverage` + `coverlet.collector` in the same solution):\n\n```powershell\n$rawDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\"\n$sdkVersion = (dotnet --version 2>$null)\n$major = if ($sdkVersion -match '^(\\d+)\\.') { [int]$Matches[1] } else { 9 }\n\nforeach ($tp in $testProjects) {\n $hasMsCodeCov = Select-String -Path $tp.FullName -Pattern 'Microsoft\\.Testing\\.Extensions\\.CodeCoverage' -Quiet\n if ($hasMsCodeCov) {\n if ($major -ge 10) {\n dotnet test $tp.FullName --results-directory $rawDir --coverage --coverage-output-format cobertura --coverage-output $rawDir\n } else {\n dotnet test $tp.FullName --results-directory $rawDir -- --coverage --coverage-output-format cobertura --coverage-output $rawDir\n }\n } else {\n dotnet test $tp.FullName `\n --collect:\"XPlat Code Coverage\" `\n --results-directory $rawDir `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include=\"[*]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=\"[*.Tests]*,[*.Test]*,[*Tests]*,[*Test]*,[*.Specs]*,[*.Testing]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.SkipAutoProps=true\n }\n}\n```\n\nExit code handling:\n\n- **0** — all tests passed, coverage collected\n- **1** — some tests failed (coverage still collected — proceed with a warning)\n- **Other** — build failure; stop and report the error\n\nAfter the run, locate coverage files:\n\n```powershell\n$coberturaFiles = Get-ChildItem -Path (Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\") -Filter \"coverage.cobertura.xml\" -Recurse\nWrite-Host \"COBERTURA_COUNT:$($coberturaFiles.Count)\"\n$coberturaFiles | ForEach-Object { Write-Host \"COBERTURA:$($_.FullName)\" }\n$vsCovFiles = Get-ChildItem -Path (Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\") -Filter \"*.coverage\" -Recurse -ErrorAction SilentlyContinue\nif ($vsCovFiles) { Write-Host \"VS_BINARY_COVERAGE:$($vsCovFiles.Count)\" }\n```\n\nIf `COBERTURA_COUNT` is 0:\n\n- If `VS_BINARY_COVERAGE` > 0: warn the user — *\"Found .coverage files (VS binary format) but no Cobertura XML. These were likely produced by Visual Studio's built-in collector, which outputs a binary format by default. This skill needs Cobertura XML. Re-running with the detected provider configured for Cobertura output.\"* Then re-run the appropriate `dotnet test` command above (Coverlet or Microsoft CodeCoverage) with Cobertura format.\n- If no `.coverage` files either: stop and report — *\"Coverage files not generated. Ensure `dotnet test` completed successfully and check the build output for errors.\"*\n\n### Phase 3 — Analysis (sequential)\n\nRun the two bundled PowerShell scripts. Both are cheap and complete in seconds. **Do not** install or invoke ReportGenerator here — that belongs in optional Phase 5, after the user-facing summary has been delivered.\n\n#### Step 4: Calculate CRAP scores using the bundled script\n\nRun `scripts/Compute-CrapScores.ps1` (co-located with this SKILL.md). It reads all Cobertura XML files, applies `CRAP(m) = comp² × (1 − cov)³ + comp` per method, and returns the top-N hotspots as JSON.\n\nTo locate the script: find the directory containing this skill's `SKILL.md` file (the skill loader provides this context), then resolve `scripts/Compute-CrapScores.ps1` relative to it. If the script path cannot be determined, calculate CRAP scores inline using the formula below.\n\n```powershell\n& \"\u003cskill-directory>/scripts/Compute-CrapScores.ps1\" `\n -CoberturaPath @(\u003call COBERTURA file paths as array>) `\n -CrapThreshold \u003ccrap_threshold> `\n -TopN \u003ctop_n>\n```\n\nScript outputs: `OVERALL_LINE_COVERAGE:\u003cn>`, `OVERALL_BRANCH_COVERAGE:\u003cn>` (aggregated project-wide rates across all provided Cobertura files), `TOTAL_METHODS:\u003cn>`, `FLAGGED_METHODS:\u003cn>`, `HOTSPOTS:\u003cjson>` (top-N sorted by CrapScore descending). The OVERALL_* values are exactly what the Phase 4 summary needs for the \"Line Coverage\" / \"Branch Coverage\" rows — no separate XML parsing tool call is required.\n\n#### Step 5: Extract per-method coverage gaps\n\nRun `scripts/Extract-MethodCoverage.ps1` to get per-method coverage data for the Coverage Gaps table:\n\n```powershell\n& \"\u003cskill-directory>/scripts/Extract-MethodCoverage.ps1\" `\n -CoberturaPath @(\u003call COBERTURA file paths as array>) `\n -CoverageThreshold \u003cline_threshold> `\n -BranchThreshold \u003cbranch_threshold> `\n -Filter below-threshold\n```\n\nScript outputs: JSON array of methods below the coverage threshold, sorted by coverage ascending. Use this data to populate the Coverage Gaps by File table in the report.\n\n### Phase 4 — User-facing summary (MANDATORY — your next assistant response)\n\nAs soon as Phase 3 completes, **your immediately next assistant response must contain the user-facing analysis** — do not interleave any other tool calls before it. This is the response the user (and any judge) sees. Skipping or deferring this in favor of Phase 5 (ReportGenerator) is a hard failure.\n\nThe response must include, at minimum:\n\n1. Overall line and branch coverage — read directly from the `OVERALL_LINE_COVERAGE:` / `OVERALL_BRANCH_COVERAGE:` lines emitted by `Compute-CrapScores.ps1` (no extra Cobertura parsing required)\n2. The Risk Hotspots table built from `Compute-CrapScores.ps1` `HOTSPOTS:` output (CRAP scores, complexity, coverage)\n3. Identification of the highest-risk method(s) and what is blocking coverage\n4. 1–3 prioritized, specific recommendations (which method to test, expected CRAP/coverage impact)\n\nUse `references/output-format.md` verbatim for fixed headings, table structures, symbols, and emoji. Use `references/guidelines.md` for prioritization rules and style.\n\nIf Phase 5 has not yet run when you compose this summary, mark the `## 📁 Reports` section's HTML/Text/CSV/GitHub-markdown rows as `Not generated (optional — request HTML reports to enable)`. Only the `coverage-analysis.md` and raw Cobertura paths are guaranteed to exist.\n\nAttempt to save the same content to `TestResults/coverage-analysis/coverage-analysis.md` before delivering the response (use the editor's create/edit tool — do not shell out). If the file write fails, still deliver the summary and note the file-write failure explicitly.\n\n### Phase 5 — Optional: ReportGenerator HTML/CSV reports (post-summary)\n\nPhase 5 is **strictly optional** and runs **only after** Phase 4 has been delivered. Skip Phase 5 entirely when:\n\n- The user supplied existing Cobertura XML and only asked for analysis (the default for the existing-data path).\n- The user is diagnosing a coverage plateau or asking \"what's blocking me?\" — they want the answer, not a static-site report.\n- ReportGenerator is not already installed and you have no clear signal the user wants HTML reports.\n\nRun Phase 5 only when the user explicitly asks for HTML/CSV reports, or when the project flow requires them (e.g., a CI artifact upload step).\n\n#### Step 6: Verify or install ReportGenerator (only if running Phase 5)\n\n```powershell\n$rgAvailable = $false\n$rgCommand = Get-Command reportgenerator -ErrorAction SilentlyContinue\nif ($rgCommand) {\n $rgAvailable = $true\n Write-Host \"RG_INSTALLED:already-present\"\n} else {\n $rgToolPath = Join-Path \"\u003cCOVERAGE_DIR>\" \".tools\"\n dotnet tool install dotnet-reportgenerator-globaltool --tool-path $rgToolPath\n if ($LASTEXITCODE -eq 0) {\n $env:PATH = \"$rgToolPath$([System.IO.Path]::PathSeparator)$env:PATH\"\n $rgCommand = Get-Command reportgenerator -ErrorAction SilentlyContinue\n if ($rgCommand) {\n $rgAvailable = $true\n Write-Host \"RG_INSTALLED:true (tool-path: $rgToolPath)\"\n } else {\n Write-Host \"RG_INSTALLED:false\"\n Write-Host \"RG_INSTALL_ERROR:reportgenerator-not-available\"\n }\n } else {\n Write-Host \"RG_INSTALLED:false\"\n Write-Host \"RG_INSTALL_ERROR:reportgenerator-not-available\"\n }\n}\nWrite-Host \"RG_AVAILABLE:$rgAvailable\"\n```\n\nIf installation fails (no internet), keep `RG_AVAILABLE:false`, leave the existing user-facing summary as the final output, and note that HTML reports were skipped.\n\n#### Step 7: Generate HTML/CSV reports\n\n```powershell\n$reportsDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"reports\"\nif ($rgAvailable) {\n reportgenerator `\n -reports:\"\u003csemicolon-separated COBERTURA paths>\" `\n -targetdir:$reportsDir `\n -reporttypes:\"Html;TextSummary;MarkdownSummaryGithub;CsvSummary\" `\n -title:\"Coverage Report\" `\n -tag:\"coverage-analysis-skill\"\n\n Get-Content (Join-Path $reportsDir \"Summary.txt\") -ErrorAction SilentlyContinue\n} else {\n Write-Host \"REPORTGENERATOR_SKIPPED:true\"\n}\n```\n\nAfter Phase 5 completes successfully, you may follow up with a short message pointing the user to the generated HTML report (one paragraph, no need to repeat the summary).\n\n## Validation\n\n- Verify that at least one `coverage.cobertura.xml` file was generated after `dotnet test` (or already exists when the user supplied one)\n- Confirm the assistant response contained the CRAP/risk-hotspot table — saving the markdown file is secondary\n- Confirm `TestResults/coverage-analysis/coverage-analysis.md` was written and contains data\n- Spot-check one method's CRAP score: `comp² × (1 − cov)³ + comp` — a method with 100% coverage should have CRAP = complexity\n- If Phase 5 ran, verify `TestResults/coverage-analysis/reports/index.html` exists; otherwise the report file should mark HTML/Text/CSV rows as `Not generated`\n\n## Common Pitfalls\n\n- **No Cobertura XML generated** — the test project may lack a coverage provider. The skill auto-adds one, but if `dotnet add package` fails (offline/proxy), coverage collection silently produces nothing. Check for `.coverage` binary files as a fallback indicator.\n- **Test failures (exit code 1)** — coverage is still collected from passing tests. Do not abort; proceed with partial data and note the failures in the summary.\n- **Premature end before user-facing summary** — never start Phase 5 (ReportGenerator install/run) before the Phase 4 assistant response is delivered. The heavy `dotnet tool install` can crash the session or exhaust budget, leaving the user with no analysis even though the CRAP scores were already computed.\n- **ReportGenerator install failure** — if `dotnet tool install` fails (no internet) during Phase 5, leave the existing Phase 4 summary as the final output and note that HTML reports were skipped. Do not retry or block on the install.\n- **Method name mismatches in Cobertura** — async methods, lambdas, and local functions may have compiler-generated names. The scripts use the Cobertura method name/signature directly; verify against source if results look unexpected.\n- **Mixed coverage providers** — when a solution contains both Coverlet and Microsoft CodeCoverage projects, the skill runs per-project to avoid dual-provider conflicts. This is slower but correct.\n---","attachment_filenames":["references/guidelines.md","references/output-format.md"],"attachments":[{"filename":"references/guidelines.md","content":"# Guidelines\n\n**Don't modify source or production code.** The only permitted project file modifications are adding a coverage provider package to test projects that currently have no provider: `coverlet.collector` (coverlet/mixed modes) or `Microsoft.Testing.Extensions.CodeCoverage` (ms-codecoverage mode). Do not add a second provider to projects that already have one. Always log package additions and document revert commands in the report. Write all other output to `TestResults/coverage-analysis/` under the test project directory.\n\n**Always show and open the generated markdown report — but only after the assistant response with the CRAP/risk-hotspot summary has been delivered.** Saving and opening `TestResults/coverage-analysis/coverage-analysis.md` is a follow-up action; it must never delay the user-facing summary.\n\n**Don't generate new tests during the initial analysis run.** This skill surfaces where tests are needed. Test generation is a separate follow-up step outside the scope of this skill.\n\n**Use inline `dotnet test` arguments, not runsettings files.** Runsettings files require the developer to already know what they're doing — the whole point of this skill is that they shouldn't have to. Inline data collector args produce the same result with zero configuration.\n\n**Show the risk hotspots table even when all thresholds pass.** A project at 90% line coverage can still have a method with cyclomatic complexity 20 and 0% branch coverage. The thresholds measure averages; the hotspot table finds outliers. Don't hide it just because the summary looks green.\n\n**Always compute and surface CRAP scores.** The Risk Hotspots table is mandatory in every analysis output, whether analyzing pre-existing data, freshly collected data, or diagnosing a plateau. Never skip CRAP score computation — it is the primary differentiator between this skill and raw `dotnet test` coverage output.\n\n**Continue past test failures (exit code 1).** If some tests fail, coverage is still collected from the passing tests — partial data is better than no data. Note the failures in the summary and proceed. Aborting would leave the developer with nothing actionable.\n\n**Run `dotnet test` only once per entry point during normal flow.** When a solution is found, run it once against the solution. When no solution is found, run it once per test project. A single recovery rerun is allowed only if the first run produced no Cobertura XML and only `.coverage` binary output.\n\n**CRAP threshold of 30 is the default for a reason.** Scores above 30 are widely cited (by the original researchers) as \"needs immediate attention.\" Scores between 15 and 30 are moderate — flag them in the table but don't make them sound catastrophic. Scores ≤ 5 are generally fine.\n\n**Priority assignment for coverage gaps:**\n\n- **HIGH** — file has both a CRAP score above threshold AND coverage below threshold (the double failure is what makes it urgent)\n- **MED** — coverage below threshold OR CRAP score above threshold, but not both\n- **LOW** — coverage below threshold with all methods having complexity ≤ 2 (trivial code — missing coverage here is unlikely to hide real bugs)\n\n---\n\n## Coverage Intelligence — Going Beyond the Numbers\n\n**Prioritize uncovered code that is** complex (cyclomatic complexity > 5), on critical paths (auth, payment, data access, error handling), or changed frequently. **Deprioritize** trivial getters (complexity 1–2), generated files (EF migrations, `*.Designer.cs`, `*.g.cs`), and DI/configuration glue code.\n\n**Coverage plateau diagnosis** — if coverage has stopped increasing, check for: `[Exclude]` attributes hiding large code sections, tests that execute code but assert nothing (inflated coverage without verification), or integration code that needs external dependencies (databases, file system).\n\n**AI-generated test quality** — coverage delta alone is insufficient. Flag methods where CRAP score is still above threshold after coverage increased (tests may be happy-path only), and methods covered by a single test with no branch variation.\n\n---\n\n## Style\n\n- **Keep risk hotspots prominent and immediately after the summary section** — developers should find the highest-risk methods quickly\n- **Quantify recommendations** — \"adding 3 tests for `ProcessOrder` would cut the CRAP score from 48 to ~6\"\n- **Be direct** — skip preamble, get to the table\n- **Emoji for visual scanning in generated output** (defined in `references/output-format.md`):\n\n | Symbol | Meaning |\n |--------|---------|\n | 🔥 | hotspots |\n | 📋 | gaps |\n | 💡 | recommendations |\n | 📁 | reports |\n | ✅ | passing |\n | ❌ | failing |\n | ⚠️ | warning |\n | 🔴 | HIGH priority |\n | 🟡 | MED priority |\n | 🟢 | LOW priority |\n\n- **Always use Unicode emoji in generated output** — never shortcodes like `:x:` or `:fire:`\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":4883,"content_sha256":"8e7bced5e4deb5e11b008f1d6f8ee69bd5f9a2bb743c9ccceb75f54a7f2790f1"},{"filename":"references/output-format.md","content":"# Output Format\n\nCopy the template below **verbatim** for all fixed elements (headings, table headers, emoji, symbols). Only replace `\u003cplaceholder>` values with actual data. Do not substitute emoji with text equivalents, do not change `·` to `-`, do not change `×` to `x`, and do not drop section emoji prefixes.\n\n```markdown\n# Coverage Analysis - \u003cProjectName>\n\n| Metric | Value |\n|--------|-------|\n| **Date** | \u003cYYYY-MM-DD> |\n| **Line Coverage** | \u003cN>% |\n| **Branch Coverage** | \u003cN>% |\n| **Risk Hotspots** | \u003cN> (CRAP > \u003ccrap_threshold>) |\n| **Tests** | \u003cN> passed · \u003cN> failed |\n\n## Summary\n\n| Metric | Value | Threshold | Status |\n|--------|-------|-----------|--------|\n| **Line Coverage** | \u003cN>% | \u003cline_threshold>% | ✅ / ❌ |\n| **Branch Coverage** | \u003cN>% | \u003cbranch_threshold>% | ✅ / ❌ |\n| **Methods Analyzed** | \u003cN> | — | — |\n| **Risk Hotspots** | \u003cN> | 0 | ✅ / ⚠️ |\n| **Test Result** | \u003cPassed / N tests failed> | — | ✅ / ⚠️ |\n\n> Coverage collected from **\u003cN> of \u003cM> test project(s)**.\n> Outputs saved to: `\u003ccoverageDir>/` (markdown summary + raw Cobertura XML).\n> *If Phase 5 ran:* HTML/CSV reports also at `\u003ccoverageDir>/reports/`.\n\nIf any coverage provider package was added to test projects, include this note after the summary:\n\n> ℹ️ **Coverage provider package updates**\n> - `coverlet.collector` added to `\u003cK>` project(s): `\u003cTestProject1.csproj>`, `\u003cTestProject2.csproj>`\n> - `Microsoft.Testing.Extensions.CodeCoverage` added to `\u003cM>` project(s): `\u003cTestProject3.csproj>`\n>\n> To revert: `git checkout -- \u003cpath-to-each-modified-csproj>`\n\nIf all test projects already had a coverage provider, omit this note.\n\n---\n\n## 🔥 Risk Hotspots (Top \u003cN> by CRAP Score)\n\nMethods flagged as high-risk: complex code with low test coverage that is dangerous to change.\n\n| Rank | Method | Class | File | Complexity | Coverage | CRAP Score |\n|------|--------|-------|------|-----------|---------|-----------|\n| 1 | `\u003cmethod>` | `\u003cclass>` | `\u003cfile>` | \u003cN> | \u003cN>% | **\u003cscore>** |\n| … | … | … | … | … | … | … |\n\n> **CRAP Score** = `Complexity² × (1 − Coverage)³ + Complexity`.\n> Scores above \u003ccrap_threshold> are flagged. A score ≤ 5 is considered safe.\n\n---\n\n## 📋 Coverage Gaps by File\n\nFiles below the line or branch coverage threshold, ordered by uncovered lines descending:\n\n| File | Line Coverage | Branch Coverage | Uncovered Lines | Priority |\n|------|--------------|----------------|----------------|---------|\n| `\u003cfile>` | \u003cN>% | \u003cN>% | \u003cN> | 🔴 HIGH / 🟡 MED / 🟢 LOW |\n| … | … | … | … | … |\n\n---\n\n## 💡 Recommendations\n\n1. **Write tests for the top risk hotspot first** — `\u003cmethod>` in `\u003cclass>` has a CRAP score of \u003cN> (complexity \u003cN>, \u003cN>% coverage). Reducing it to 80% coverage would drop the score to ~\u003cprojected>.\n2. **Focus on `\u003cfile>`** — \u003cN> uncovered lines, below threshold. \u003cBrief reasoning.>\n3. **\u003cUp to 5 actionable items total, ordered by expected risk reduction.>**\n\n---\n\n## 📁 Reports\n\n| Report | Path |\n|--------|------|\n| Markdown summary (this file) | `\u003ccoverageDir>/coverage-analysis.md` |\n| Raw Cobertura XML | `\u003ccoberturaXmlPathsUsedForAnalysis>` |\n| HTML (browsable) | `\u003ccoverageDir>/reports/index.html` *or* `Not generated (optional — request HTML reports to enable)` |\n| Text summary | `\u003ccoverageDir>/reports/Summary.txt` *or* `Not generated` |\n| GitHub markdown | `\u003ccoverageDir>/reports/SummaryGithub.md` *or* `Not generated` |\n| CSV data | `\u003ccoverageDir>/reports/Summary.csv` *or* `Not generated` |\n```\n\nIf ReportGenerator (Phase 5) has not run, mark the HTML/Text/GitHub-markdown/CSV rows as `Not generated (optional — request HTML reports to enable)`. Do not invent paths for files that have not been produced. For **Raw Cobertura XML**, list the actual XML file path(s) used in analysis (for from-scratch runs this is typically under `\u003ccoverageDir>/raw/`; for existing-data runs this may be under `TestResults/` or another user-supplied location).\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":3967,"content_sha256":"f2328f0250002c25276f51373ab3b935b15b41be09c161db02d3e22316ad78c4"}],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"Coverage Analysis","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Purpose","type":"text"}]},{"type":"paragraph","content":[{"text":"Raw coverage percentages answer \"what code was executed?\" — they don't answer what you actually need to know:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"What tests should I write next?","type":"text","marks":[{"type":"strong"}]},{"text":" — ranked by risk and impact","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Which uncovered code is risky vs. trivial?","type":"text","marks":[{"type":"strong"}]},{"text":" — CRAP scores separate the two","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Why has coverage plateaued?","type":"text","marks":[{"type":"strong"}]},{"text":" — identify the files blocking further gains","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Is this code safe to refactor?","type":"text","marks":[{"type":"strong"}]},{"text":" — complex + uncovered = dangerous to change","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"This skill bridges that gap: from a bare .NET solution to a prioritized risk hotspot list, with no manual tool configuration required.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"When to Use","type":"text"}]},{"type":"paragraph","content":[{"text":"Use this skill when the user mentions test coverage, coverage gaps, code risk, CRAP scores, where to add tests, why coverage plateaued, or wants to know which code is safest to refactor — even if they don't explicitly say \"coverage analysis\".","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"When Not to Use","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Targeted single-method CRAP analysis","type":"text","marks":[{"type":"strong"}]},{"text":" — use the ","type":"text"},{"text":"crap-score","type":"text","marks":[{"type":"code_inline"}]},{"text":" skill instead","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Writing or generating tests","type":"text","marks":[{"type":"strong"}]},{"text":" — this skill identifies where tests are needed, not write them","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"General test execution","type":"text","marks":[{"type":"strong"}]},{"text":" unrelated to coverage or CRAP analysis","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Coverage reporting without CRAP context","type":"text","marks":[{"type":"strong"}]},{"text":" — use ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" with coverage collection directly","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Inputs","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Input","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Required","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Default","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Description","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Project/solution path","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"No","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Current directory","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Path to the .NET solution or project","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Line coverage threshold","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"No","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"80%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Minimum acceptable line coverage","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Branch coverage threshold","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"No","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"70%","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Minimum acceptable branch coverage","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"CRAP threshold","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"No","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"30","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Maximum acceptable CRAP score before flagging","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Top N hotspots","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"No","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"10","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Number of risk hotspots to surface","type":"text"}]}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Prerequisites","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":".NET SDK installed (","type":"text"},{"text":"dotnet","type":"text","marks":[{"type":"code_inline"}]},{"text":" on PATH)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"At least one test project referencing the production code (xUnit, NUnit, or MSTest) — only required for the from-scratch path; not needed when the user supplies an existing Cobertura XML","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Optional, only for the from-scratch path:","type":"text","marks":[{"type":"strong"}]},{"text":" internet/NuGet access for ","type":"text"},{"text":"dotnet add package coverlet.collector","type":"text","marks":[{"type":"code_inline"}]},{"text":" (or ","type":"text"},{"text":"Microsoft.Testing.Extensions.CodeCoverage","type":"text","marks":[{"type":"code_inline"}]},{"text":") when a test project has no coverage provider yet. Skip when the user supplies an existing Cobertura XML.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Optional, only for Phase 5:","type":"text","marks":[{"type":"strong"}]},{"text":" internet access for ","type":"text"},{"text":"dotnet tool install","type":"text","marks":[{"type":"code_inline"}]},{"text":" (ReportGenerator). Core CRAP/coverage analysis works from Cobertura XML alone — ReportGenerator only adds HTML/CSV reports as an optional post-summary extra.","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"The skill auto-detects coverage provider state per test project and selects the least-invasive execution strategy:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"unified Microsoft CodeCoverage when all projects use it,","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"unified Coverlet when no project uses Microsoft CodeCoverage,","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"per-project provider execution when the solution is truly mixed.","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"No pre-existing runsettings files or manually installed tools required.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Workflow","type":"text"}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"MANDATORY: deliver the final assistant response with the CRAP/risk-hotspot summary BEFORE any optional work.","type":"text","marks":[{"type":"strong"}]},{"text":" As soon as ","type":"text"},{"text":"Compute-CrapScores.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" and ","type":"text"},{"text":"Extract-MethodCoverage.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" return data, your ","type":"text"},{"text":"next","type":"text","marks":[{"type":"strong"}]},{"text":" assistant response must contain the user-facing analysis (CRAP table, blocking methods, recommendations). Do not run ReportGenerator (Phase 5), do not install global tools, and do not start any heavy parallel work before that response is delivered. The user is judged on the final assistant message, not on side-effect files.","type":"text"}]},{"type":"paragraph","content":[{"text":"If a phase fails, times out, or budget is running low, skip remaining optional work and immediately return a partial summary containing: (1) what was found in the Cobertura XML, (2) any CRAP/risk-hotspot data already extracted, (3) which methods are blocking coverage, and (4) failures encountered.","type":"text"}]}]},{"type":"paragraph","content":[{"text":"If the user provides a path to existing Cobertura XML (or coverage data is already present in ","type":"text"},{"text":"TestResults/","type":"text","marks":[{"type":"code_inline"}]},{"text":"), ","type":"text"},{"text":"skip Phase 2 entirely","type":"text","marks":[{"type":"strong"}]},{"text":" (no test execution) ","type":"text"},{"text":"and skip Phase 5 by default","type":"text","marks":[{"type":"strong"}]},{"text":" (no ReportGenerator install or HTML report) — go directly from Phase 3 (analysis scripts) to Phase 4 (user-facing summary). Only run Phase 5 if the user explicitly asks for HTML/CSV reports. The Risk Hotspots table and CRAP scores are mandatory in every output — they are the skill's core value-add over raw coverage numbers.","type":"text"}]},{"type":"paragraph","content":[{"text":"The workflow runs in five phases. Phases 1–4 are required; Phase 5 (ReportGenerator HTML/CSV reports) is strictly optional and runs ","type":"text"},{"text":"after","type":"text","marks":[{"type":"strong"}]},{"text":" the user-facing summary has been delivered. Do not parallelize Phase 5 with earlier phases — the heavy ","type":"text"},{"text":"dotnet tool install","type":"text","marks":[{"type":"code_inline"}]},{"text":" for ReportGenerator can crash the session before Phase 4 completes.","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Phase 1 — Setup (sequential)","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 1: Locate the solution or project","type":"text"}]},{"type":"paragraph","content":[{"text":"Given the user's path (default: current directory), find the entry point:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$root = \"\u003cuser-provided-path-or-current-directory>\"\n\n# Prefer solution file; fall back to project file\n$sln = Get-ChildItem -Path $root -Filter \"*.sln\" -Recurse -Depth 2 -ErrorAction SilentlyContinue |\n Select-Object -First 1\nif ($sln) {\n Write-Host \"ENTRY_TYPE:Solution\"; Write-Host \"ENTRY:$($sln.FullName)\"\n} else {\n $project = Get-ChildItem -Path $root -Filter \"*.csproj\" -Recurse -Depth 2 -ErrorAction SilentlyContinue |\n Select-Object -First 1\n if ($project) {\n Write-Host \"ENTRY_TYPE:Project\"; Write-Host \"ENTRY:$($project.FullName)\"\n } else {\n Write-Host \"ENTRY_TYPE:NotFound\"\n }\n}\n\n# Test projects: search path first, then git root, then parent\n$searchRoots = @($root)\n$gitRoot = (git -C $root rev-parse --show-toplevel 2>$null)\nif ($gitRoot) { $gitRoot = [System.IO.Path]::GetFullPath($gitRoot) }\nif ($gitRoot -and $gitRoot -ne $root) { $searchRoots += $gitRoot }\n$parentPath = Split-Path $root -Parent\nif ($parentPath -and $parentPath -ne $root -and $parentPath -ne $gitRoot) { $searchRoots += $parentPath }\n\n$testProjects = @()\nforeach ($sr in $searchRoots) {\n # Primary: match by .csproj content (test framework references)\n $testProjects = @(Get-ChildItem -Path $sr -Filter \"*.csproj\" -Recurse -Depth 5 -ErrorAction SilentlyContinue |\n Where-Object { $_.FullName -notmatch '([/\\\\]obj[/\\\\]|[/\\\\]bin[/\\\\])' } |\n Where-Object { (Select-String -Path $_.FullName -Pattern 'Microsoft\\.NET\\.Test\\.Sdk|xunit|nunit|MSTest\\.TestAdapter|\"MSTest\"|MSTest\\.TestFramework|TUnit' -Quiet) })\n if ($testProjects.Count -gt 0) {\n if ($sr -ne $root) { Write-Host \"SEARCHED:$sr\" }\n break\n }\n}\n\n# Fallback: match by file name convention\nif ($testProjects.Count -eq 0) {\n foreach ($sr in $searchRoots) {\n $testProjects = @(Get-ChildItem -Path $sr -Filter \"*.csproj\" -Recurse -Depth 5 -ErrorAction SilentlyContinue |\n Where-Object { $_.Name -match '(?i)(test|spec)' })\n if ($testProjects.Count -gt 0) {\n if ($sr -ne $root) { Write-Host \"SEARCHED:$sr\" }\n break\n }\n }\n}\nWrite-Host \"TEST_PROJECTS:$($testProjects.Count)\"\n$testProjects | ForEach-Object { Write-Host \"TEST_PROJECT:$($_.FullName)\" }\n\n# Resolve the test output root (where coverage-analysis artifacts will be written)\nif ($testProjects.Count -eq 0) {\n if ($gitRoot) {\n $testOutputRoot = $gitRoot\n } else {\n $testOutputRoot = $root\n }\n} elseif ($testProjects.Count -eq 1) {\n $testOutputRoot = $testProjects[0].DirectoryName\n} else {\n # Multiple test projects — find their deepest common parent directory\n $dirs = $testProjects | ForEach-Object { $_.DirectoryName }\n $common = $dirs[0]\n foreach ($d in $dirs[1..($dirs.Count-1)]) {\n $sep = [System.IO.Path]::DirectorySeparatorChar\n while (-not $d.StartsWith(\"$common$sep\", [System.StringComparison]::OrdinalIgnoreCase) -and $d -ne $common) {\n $prevCommon = $common\n $common = Split-Path $common -Parent\n # Terminate if we can no longer move up (at filesystem root or no parent)\n if ([string]::IsNullOrEmpty($common) -or $common -eq $prevCommon) {\n $common = $null\n break\n }\n }\n }\n if ([string]::IsNullOrEmpty($common)) {\n # Fallback when no common parent directory exists (e.g., projects on different drives)\n if ($gitRoot) {\n $testOutputRoot = $gitRoot\n } else {\n $testOutputRoot = $root\n }\n } else {\n $testOutputRoot = $common\n }\n}\nWrite-Host \"TEST_OUTPUT_ROOT:$testOutputRoot\"","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"ENTRY_TYPE:NotFound","type":"text","marks":[{"type":"code_inline"}]},{"text":" and test projects were found → use the test projects directly as entry points (run ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" on each test ","type":"text"},{"text":".csproj","type":"text","marks":[{"type":"code_inline"}]},{"text":").","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"ENTRY_TYPE:NotFound","type":"text","marks":[{"type":"code_inline"}]},{"text":" and no test projects found → stop: ","type":"text"},{"text":"No .sln or test projects found under \u003cpath>. Provide the path to your .NET solution or project.","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"TEST_PROJECTS:0","type":"text","marks":[{"type":"code_inline"}]},{"text":" and ","type":"text"},{"text":"EXISTING_COBERTURA_COUNT","type":"text","marks":[{"type":"code_inline"}]},{"text":" > 0 (Step 2b) → continue with existing Cobertura XML analysis (no ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" run).","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"TEST_PROJECTS:0","type":"text","marks":[{"type":"code_inline"}]},{"text":" and ","type":"text"},{"text":"EXISTING_COBERTURA_COUNT","type":"text","marks":[{"type":"code_inline"}]},{"text":" == 0 → stop: ","type":"text"},{"text":"No test projects found (expected projects with 'Test' or 'Spec' in the name), and no existing Cobertura XML was provided. Add a test project or provide a Cobertura file path.","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 2: Create the output directory","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$coverageDir = Join-Path $testOutputRoot \"TestResults\" \"coverage-analysis\"\nif (Test-Path $coverageDir) { Remove-Item $coverageDir -Recurse -Force }\nNew-Item -ItemType Directory -Path $coverageDir -Force | Out-Null\nWrite-Host \"COVERAGE_DIR:$coverageDir\"","type":"text"}]},{"type":"paragraph","content":[{"text":"This step only manages the ","type":"text"},{"text":"TestResults/coverage-analysis/","type":"text","marks":[{"type":"code_inline"}]},{"text":" subdirectory (skill-owned outputs). It must never delete user-supplied Cobertura files — those live one level up at ","type":"text"},{"text":"TestResults/coverage.cobertura.xml","type":"text","marks":[{"type":"code_inline"}]},{"text":" (or wherever the user pointed). If the user provided a path that ","type":"text"},{"text":"is","type":"text","marks":[{"type":"em"}]},{"text":" ","type":"text"},{"text":"TestResults/coverage-analysis/...","type":"text","marks":[{"type":"code_inline"}]},{"text":", copy the file aside before this step recreates the directory.","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 2b: Discover or accept existing Cobertura XML (required for the existing-data path)","type":"text"}]},{"type":"paragraph","content":[{"text":"If the user supplied a Cobertura XML path explicitly, use it. Otherwise probe well-known locations and any path the user mentioned:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"# 1. Honor a user-supplied path first (highest priority)\n$coberturaFiles = @()\nif ($userSuppliedCoberturaPath -and (Test-Path $userSuppliedCoberturaPath)) {\n $coberturaFiles = @(Get-Item $userSuppliedCoberturaPath)\n}\n\n# 2. Otherwise scan TestResults/ at the repo/test root for any *.cobertura.xml\nif ($coberturaFiles.Count -eq 0) {\n $searchPaths = @(\n (Join-Path $testOutputRoot \"TestResults\"),\n (Join-Path $root \"TestResults\")\n ) | Where-Object { $_ -and (Test-Path $_) } | Select-Object -Unique\n foreach ($sp in $searchPaths) {\n $found = @(Get-ChildItem -Path $sp -Filter \"*.cobertura.xml\" -Recurse -ErrorAction SilentlyContinue |\n Where-Object { $_.FullName -notmatch '[/\\\\]coverage-analysis[/\\\\]raw[/\\\\]' })\n if ($found.Count -gt 0) { $coberturaFiles = $found; break }\n }\n}\n\nWrite-Host \"EXISTING_COBERTURA_COUNT:$($coberturaFiles.Count)\"\n$coberturaFiles | ForEach-Object { Write-Host \"EXISTING_COBERTURA:$($_.FullName)\" }","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"EXISTING_COBERTURA_COUNT","type":"text","marks":[{"type":"code_inline"}]},{"text":" > 0 → ","type":"text"},{"text":"skip Phase 2 entirely","type":"text","marks":[{"type":"strong"}]},{"text":" and pass these paths to the Phase 3 scripts.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"EXISTING_COBERTURA_COUNT","type":"text","marks":[{"type":"code_inline"}]},{"text":" == 0 → run Phase 2 to generate fresh coverage; the file paths to feed Phase 3 will be discovered from ","type":"text"},{"text":"\u003cCOVERAGE_DIR>/raw/","type":"text","marks":[{"type":"code_inline"}]},{"text":" after ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":".","type":"text"}]}]}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 2c: Recommend ignoring ","type":"text"},{"text":"TestResults/","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$pattern = \"**/TestResults/\"\n$gitRoot = (git -C $testOutputRoot rev-parse --show-toplevel 2>$null)\nif ($gitRoot) { $gitRoot = [System.IO.Path]::GetFullPath($gitRoot) }\nif ($gitRoot) {\n $gitignorePath = Join-Path $gitRoot \".gitignore\"\n $alreadyIgnored = $false\n if (Test-Path $gitignorePath) {\n $alreadyIgnored = (Select-String -Path $gitignorePath -Pattern '^\\s*(\\*\\*/)?TestResults/?\\s*

Coverage Analysis Purpose Raw coverage percentages answer "what code was executed?" — they don't answer what you actually need to know: - What tests should I write next? — ranked by risk and impact - Which uncovered code is risky vs. trivial? — CRAP scores separate the two - Why has coverage plateaued? — identify the files blocking further gains - Is this code safe to refactor? — complex + uncovered = dangerous to change This skill bridges that gap: from a bare .NET solution to a prioritized risk hotspot list, with no manual tool configuration required. When to Use Use this skill when the use…

-Quiet)\n }\n if ($alreadyIgnored) {\n Write-Host \"GITIGNORE_RECOMMENDATION:already-present\"\n } else {\n Write-Host \"GITIGNORE_RECOMMENDATION:$pattern\"\n }\n} else {\n Write-Host \"GITIGNORE_RECOMMENDATION:$pattern\"\n}","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Phase 2 — Test execution (skip when Cobertura XML already exists)","type":"text"}]},{"type":"paragraph","content":[{"text":"Run only when no Cobertura XML is present. If the user already has coverage data, skip directly to Phase 3.","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 3: Detect coverage provider and run ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" with coverage collection","type":"text"}]},{"type":"paragraph","content":[{"text":"Before running tests, detect which coverage provider the test projects use. Projects may reference ","type":"text"},{"text":"Microsoft.Testing.Extensions.CodeCoverage","type":"text","marks":[{"type":"code_inline"}]},{"text":" (Microsoft's built-in provider, common on .NET 9+) or ","type":"text"},{"text":"coverlet.collector","type":"text","marks":[{"type":"code_inline"}]},{"text":" (open-source, the default in xUnit templates). The provider determines which ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" arguments to use — both produce Cobertura XML.","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"# Detect coverage provider per test project\n$coverageProvider = \"unknown\" # will be set to \"ms-codecoverage\" or \"coverlet\"\n$msCodeCovProjects = @()\n$coverletProjects = @()\n$neitherProjects = @()\n\nforeach ($tp in $testProjects) {\n $hasMsCodeCov = Select-String -Path $tp.FullName -Pattern 'Microsoft\\.Testing\\.Extensions\\.CodeCoverage' -Quiet\n $hasCoverlet = Select-String -Path $tp.FullName -Pattern 'coverlet\\.collector' -Quiet\n if ($hasMsCodeCov) { $msCodeCovProjects += $tp }\n elseif ($hasCoverlet) { $coverletProjects += $tp }\n else { $neitherProjects += $tp }\n}\n\n# Determine the provider strategy\nif ($msCodeCovProjects.Count -gt 0 -and $coverletProjects.Count -eq 0) {\n $coverageProvider = \"ms-codecoverage\"\n Write-Host \"COVERAGE_PROVIDER:ms-codecoverage (ms:$($msCodeCovProjects.Count), none:$($neitherProjects.Count))\"\n} elseif ($coverletProjects.Count -gt 0 -and $msCodeCovProjects.Count -eq 0) {\n $coverageProvider = \"coverlet\"\n Write-Host \"COVERAGE_PROVIDER:coverlet (coverlet:$($coverletProjects.Count), none:$($neitherProjects.Count))\"\n} elseif ($msCodeCovProjects.Count -gt 0 -and $coverletProjects.Count -gt 0) {\n $coverageProvider = \"mixed-project\"\n Write-Host \"COVERAGE_PROVIDER:mixed-project (ms:$($msCodeCovProjects.Count), coverlet:$($coverletProjects.Count), none:$($neitherProjects.Count))\"\n} else {\n $coverageProvider = \"coverlet\"\n Write-Host \"COVERAGE_PROVIDER:none-detected — defaulting to coverlet\"\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"If any discovered test projects have no provider, add one based on the selected strategy:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"if ($coverageProvider -eq \"ms-codecoverage\" -and $neitherProjects.Count -gt 0) {\n Write-Host \"ADDING_MS_CODECOVERAGE:$($neitherProjects.Count) project(s)\"\n foreach ($tp in $neitherProjects) {\n dotnet add $tp.FullName package Microsoft.Testing.Extensions.CodeCoverage --no-restore\n Write-Host \" ADDED_MS_CODECOVERAGE:$($tp.FullName)\"\n }\n foreach ($tp in $neitherProjects) {\n dotnet restore $tp.FullName --quiet\n }\n}\n\nif (($coverageProvider -eq \"coverlet\" -or $coverageProvider -eq \"mixed-project\") -and $neitherProjects.Count -gt 0) {\n Write-Host \"ADDING_COVERLET:$($neitherProjects.Count) project(s)\"\n foreach ($tp in $neitherProjects) {\n dotnet add $tp.FullName package coverlet.collector --no-restore\n Write-Host \" ADDED:$($tp.FullName)\"\n }\n foreach ($tp in $neitherProjects) {\n dotnet restore $tp.FullName --quiet\n }\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"Log each addition to the console so the developer sees what changed. Document the additions in the final report (see Output Format).","type":"text"}]},{"type":"paragraph","content":[{"text":"Run one ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" per entry point for the selected strategy:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"In ","type":"text"},{"text":"ms-codecoverage","type":"text","marks":[{"type":"code_inline"}]},{"text":" or ","type":"text"},{"text":"coverlet","type":"text","marks":[{"type":"code_inline"}]},{"text":" mode: run a single command for the solution entry (or one per test project if no ","type":"text"},{"text":".sln","type":"text","marks":[{"type":"code_inline"}]},{"text":" was found).","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"In ","type":"text"},{"text":"mixed-project","type":"text","marks":[{"type":"code_inline"}]},{"text":" mode: run one command per test project, using that project's existing provider to avoid dual-provider conflicts.","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"Coverlet","type":"text","marks":[{"type":"strong"}]},{"text":" (","type":"text"},{"text":"coverlet.collector","type":"text","marks":[{"type":"code_inline"}]},{"text":"):","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$rawDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\"\ndotnet test \"\u003cENTRY>\" `\n --collect:\"XPlat Code Coverage\" `\n --results-directory $rawDir `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include=\"[*]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=\"[*.Tests]*,[*.Test]*,[*Tests]*,[*Test]*,[*.Specs]*,[*.Testing]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.SkipAutoProps=true","type":"text"}]},{"type":"paragraph","content":[{"text":"Microsoft CodeCoverage","type":"text","marks":[{"type":"strong"}]},{"text":" (","type":"text"},{"text":"Microsoft.Testing.Extensions.CodeCoverage","type":"text","marks":[{"type":"code_inline"}]},{"text":"):","type":"text"}]},{"type":"paragraph","content":[{"text":"The command syntax depends on the .NET SDK version. In .NET 9, Microsoft.Testing.Platform arguments must be passed after the ","type":"text"},{"text":"--","type":"text","marks":[{"type":"code_inline"}]},{"text":" separator. In .NET 10+, ","type":"text"},{"text":"--coverage","type":"text","marks":[{"type":"code_inline"}]},{"text":" is a top-level ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" flag.","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$rawDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\"\n\n# Detect SDK version for correct argument placement\n$sdkVersion = (dotnet --version 2>$null)\n$major = if ($sdkVersion -match '^(\\d+)\\.') { [int]$Matches[1] } else { 9 }\n\nif ($major -ge 10) {\n # .NET 10+: --coverage is a first-class dotnet test flag\n dotnet test \"\u003cENTRY>\" `\n --results-directory $rawDir `\n --coverage `\n --coverage-output-format cobertura `\n --coverage-output $rawDir\n} else {\n # .NET 9: pass Microsoft.Testing.Platform arguments after the -- separator\n dotnet test \"\u003cENTRY>\" `\n --results-directory $rawDir `\n -- --coverage --coverage-output-format cobertura --coverage-output $rawDir\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"Mixed-project mode","type":"text","marks":[{"type":"strong"}]},{"text":" (","type":"text"},{"text":"Microsoft.Testing.Extensions.CodeCoverage","type":"text","marks":[{"type":"code_inline"}]},{"text":" + ","type":"text"},{"text":"coverlet.collector","type":"text","marks":[{"type":"code_inline"}]},{"text":" in the same solution):","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$rawDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\"\n$sdkVersion = (dotnet --version 2>$null)\n$major = if ($sdkVersion -match '^(\\d+)\\.') { [int]$Matches[1] } else { 9 }\n\nforeach ($tp in $testProjects) {\n $hasMsCodeCov = Select-String -Path $tp.FullName -Pattern 'Microsoft\\.Testing\\.Extensions\\.CodeCoverage' -Quiet\n if ($hasMsCodeCov) {\n if ($major -ge 10) {\n dotnet test $tp.FullName --results-directory $rawDir --coverage --coverage-output-format cobertura --coverage-output $rawDir\n } else {\n dotnet test $tp.FullName --results-directory $rawDir -- --coverage --coverage-output-format cobertura --coverage-output $rawDir\n }\n } else {\n dotnet test $tp.FullName `\n --collect:\"XPlat Code Coverage\" `\n --results-directory $rawDir `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include=\"[*]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=\"[*.Tests]*,[*.Test]*,[*Tests]*,[*Test]*,[*.Specs]*,[*.Testing]*\" `\n -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.SkipAutoProps=true\n }\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"Exit code handling:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"0","type":"text","marks":[{"type":"strong"}]},{"text":" — all tests passed, coverage collected","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"1","type":"text","marks":[{"type":"strong"}]},{"text":" — some tests failed (coverage still collected — proceed with a warning)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Other","type":"text","marks":[{"type":"strong"}]},{"text":" — build failure; stop and report the error","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"After the run, locate coverage files:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$coberturaFiles = Get-ChildItem -Path (Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\") -Filter \"coverage.cobertura.xml\" -Recurse\nWrite-Host \"COBERTURA_COUNT:$($coberturaFiles.Count)\"\n$coberturaFiles | ForEach-Object { Write-Host \"COBERTURA:$($_.FullName)\" }\n$vsCovFiles = Get-ChildItem -Path (Join-Path \"\u003cCOVERAGE_DIR>\" \"raw\") -Filter \"*.coverage\" -Recurse -ErrorAction SilentlyContinue\nif ($vsCovFiles) { Write-Host \"VS_BINARY_COVERAGE:$($vsCovFiles.Count)\" }","type":"text"}]},{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"COBERTURA_COUNT","type":"text","marks":[{"type":"code_inline"}]},{"text":" is 0:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If ","type":"text"},{"text":"VS_BINARY_COVERAGE","type":"text","marks":[{"type":"code_inline"}]},{"text":" > 0: warn the user — ","type":"text"},{"text":"\"Found .coverage files (VS binary format) but no Cobertura XML. These were likely produced by Visual Studio's built-in collector, which outputs a binary format by default. This skill needs Cobertura XML. Re-running with the detected provider configured for Cobertura output.\"","type":"text","marks":[{"type":"em"}]},{"text":" Then re-run the appropriate ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" command above (Coverlet or Microsoft CodeCoverage) with Cobertura format.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If no ","type":"text"},{"text":".coverage","type":"text","marks":[{"type":"code_inline"}]},{"text":" files either: stop and report — ","type":"text"},{"text":"\"Coverage files not generated. Ensure ","type":"text","marks":[{"type":"em"}]},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"},{"type":"em"}]},{"text":" completed successfully and check the build output for errors.\"","type":"text","marks":[{"type":"em"}]}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Phase 3 — Analysis (sequential)","type":"text"}]},{"type":"paragraph","content":[{"text":"Run the two bundled PowerShell scripts. Both are cheap and complete in seconds. ","type":"text"},{"text":"Do not","type":"text","marks":[{"type":"strong"}]},{"text":" install or invoke ReportGenerator here — that belongs in optional Phase 5, after the user-facing summary has been delivered.","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 4: Calculate CRAP scores using the bundled script","type":"text"}]},{"type":"paragraph","content":[{"text":"Run ","type":"text"},{"text":"scripts/Compute-CrapScores.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" (co-located with this SKILL.md). It reads all Cobertura XML files, applies ","type":"text"},{"text":"CRAP(m) = comp² × (1 − cov)³ + comp","type":"text","marks":[{"type":"code_inline"}]},{"text":" per method, and returns the top-N hotspots as JSON.","type":"text"}]},{"type":"paragraph","content":[{"text":"To locate the script: find the directory containing this skill's ","type":"text"},{"text":"SKILL.md","type":"text","marks":[{"type":"code_inline"}]},{"text":" file (the skill loader provides this context), then resolve ","type":"text"},{"text":"scripts/Compute-CrapScores.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" relative to it. If the script path cannot be determined, calculate CRAP scores inline using the formula below.","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"& \"\u003cskill-directory>/scripts/Compute-CrapScores.ps1\" `\n -CoberturaPath @(\u003call COBERTURA file paths as array>) `\n -CrapThreshold \u003ccrap_threshold> `\n -TopN \u003ctop_n>","type":"text"}]},{"type":"paragraph","content":[{"text":"Script outputs: ","type":"text"},{"text":"OVERALL_LINE_COVERAGE:\u003cn>","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"OVERALL_BRANCH_COVERAGE:\u003cn>","type":"text","marks":[{"type":"code_inline"}]},{"text":" (aggregated project-wide rates across all provided Cobertura files), ","type":"text"},{"text":"TOTAL_METHODS:\u003cn>","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"FLAGGED_METHODS:\u003cn>","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"HOTSPOTS:\u003cjson>","type":"text","marks":[{"type":"code_inline"}]},{"text":" (top-N sorted by CrapScore descending). The OVERALL_* values are exactly what the Phase 4 summary needs for the \"Line Coverage\" / \"Branch Coverage\" rows — no separate XML parsing tool call is required.","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 5: Extract per-method coverage gaps","type":"text"}]},{"type":"paragraph","content":[{"text":"Run ","type":"text"},{"text":"scripts/Extract-MethodCoverage.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" to get per-method coverage data for the Coverage Gaps table:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"& \"\u003cskill-directory>/scripts/Extract-MethodCoverage.ps1\" `\n -CoberturaPath @(\u003call COBERTURA file paths as array>) `\n -CoverageThreshold \u003cline_threshold> `\n -BranchThreshold \u003cbranch_threshold> `\n -Filter below-threshold","type":"text"}]},{"type":"paragraph","content":[{"text":"Script outputs: JSON array of methods below the coverage threshold, sorted by coverage ascending. Use this data to populate the Coverage Gaps by File table in the report.","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Phase 4 — User-facing summary (MANDATORY — your next assistant response)","type":"text"}]},{"type":"paragraph","content":[{"text":"As soon as Phase 3 completes, ","type":"text"},{"text":"your immediately next assistant response must contain the user-facing analysis","type":"text","marks":[{"type":"strong"}]},{"text":" — do not interleave any other tool calls before it. This is the response the user (and any judge) sees. Skipping or deferring this in favor of Phase 5 (ReportGenerator) is a hard failure.","type":"text"}]},{"type":"paragraph","content":[{"text":"The response must include, at minimum:","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Overall line and branch coverage — read directly from the ","type":"text"},{"text":"OVERALL_LINE_COVERAGE:","type":"text","marks":[{"type":"code_inline"}]},{"text":" / ","type":"text"},{"text":"OVERALL_BRANCH_COVERAGE:","type":"text","marks":[{"type":"code_inline"}]},{"text":" lines emitted by ","type":"text"},{"text":"Compute-CrapScores.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" (no extra Cobertura parsing required)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"The Risk Hotspots table built from ","type":"text"},{"text":"Compute-CrapScores.ps1","type":"text","marks":[{"type":"code_inline"}]},{"text":" ","type":"text"},{"text":"HOTSPOTS:","type":"text","marks":[{"type":"code_inline"}]},{"text":" output (CRAP scores, complexity, coverage)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Identification of the highest-risk method(s) and what is blocking coverage","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"1–3 prioritized, specific recommendations (which method to test, expected CRAP/coverage impact)","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"Use ","type":"text"},{"text":"references/output-format.md","type":"text","marks":[{"type":"code_inline"}]},{"text":" verbatim for fixed headings, table structures, symbols, and emoji. Use ","type":"text"},{"text":"references/guidelines.md","type":"text","marks":[{"type":"code_inline"}]},{"text":" for prioritization rules and style.","type":"text"}]},{"type":"paragraph","content":[{"text":"If Phase 5 has not yet run when you compose this summary, mark the ","type":"text"},{"text":"## 📁 Reports","type":"text","marks":[{"type":"code_inline"}]},{"text":" section's HTML/Text/CSV/GitHub-markdown rows as ","type":"text"},{"text":"Not generated (optional — request HTML reports to enable)","type":"text","marks":[{"type":"code_inline"}]},{"text":". Only the ","type":"text"},{"text":"coverage-analysis.md","type":"text","marks":[{"type":"code_inline"}]},{"text":" and raw Cobertura paths are guaranteed to exist.","type":"text"}]},{"type":"paragraph","content":[{"text":"Attempt to save the same content to ","type":"text"},{"text":"TestResults/coverage-analysis/coverage-analysis.md","type":"text","marks":[{"type":"code_inline"}]},{"text":" before delivering the response (use the editor's create/edit tool — do not shell out). If the file write fails, still deliver the summary and note the file-write failure explicitly.","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Phase 5 — Optional: ReportGenerator HTML/CSV reports (post-summary)","type":"text"}]},{"type":"paragraph","content":[{"text":"Phase 5 is ","type":"text"},{"text":"strictly optional","type":"text","marks":[{"type":"strong"}]},{"text":" and runs ","type":"text"},{"text":"only after","type":"text","marks":[{"type":"strong"}]},{"text":" Phase 4 has been delivered. Skip Phase 5 entirely when:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"The user supplied existing Cobertura XML and only asked for analysis (the default for the existing-data path).","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"The user is diagnosing a coverage plateau or asking \"what's blocking me?\" — they want the answer, not a static-site report.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"ReportGenerator is not already installed and you have no clear signal the user wants HTML reports.","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"Run Phase 5 only when the user explicitly asks for HTML/CSV reports, or when the project flow requires them (e.g., a CI artifact upload step).","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 6: Verify or install ReportGenerator (only if running Phase 5)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$rgAvailable = $false\n$rgCommand = Get-Command reportgenerator -ErrorAction SilentlyContinue\nif ($rgCommand) {\n $rgAvailable = $true\n Write-Host \"RG_INSTALLED:already-present\"\n} else {\n $rgToolPath = Join-Path \"\u003cCOVERAGE_DIR>\" \".tools\"\n dotnet tool install dotnet-reportgenerator-globaltool --tool-path $rgToolPath\n if ($LASTEXITCODE -eq 0) {\n $env:PATH = \"$rgToolPath$([System.IO.Path]::PathSeparator)$env:PATH\"\n $rgCommand = Get-Command reportgenerator -ErrorAction SilentlyContinue\n if ($rgCommand) {\n $rgAvailable = $true\n Write-Host \"RG_INSTALLED:true (tool-path: $rgToolPath)\"\n } else {\n Write-Host \"RG_INSTALLED:false\"\n Write-Host \"RG_INSTALL_ERROR:reportgenerator-not-available\"\n }\n } else {\n Write-Host \"RG_INSTALLED:false\"\n Write-Host \"RG_INSTALL_ERROR:reportgenerator-not-available\"\n }\n}\nWrite-Host \"RG_AVAILABLE:$rgAvailable\"","type":"text"}]},{"type":"paragraph","content":[{"text":"If installation fails (no internet), keep ","type":"text"},{"text":"RG_AVAILABLE:false","type":"text","marks":[{"type":"code_inline"}]},{"text":", leave the existing user-facing summary as the final output, and note that HTML reports were skipped.","type":"text"}]},{"type":"heading","attrs":{"level":4},"content":[{"text":"Step 7: Generate HTML/CSV reports","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"powershell"},"content":[{"text":"$reportsDir = Join-Path \"\u003cCOVERAGE_DIR>\" \"reports\"\nif ($rgAvailable) {\n reportgenerator `\n -reports:\"\u003csemicolon-separated COBERTURA paths>\" `\n -targetdir:$reportsDir `\n -reporttypes:\"Html;TextSummary;MarkdownSummaryGithub;CsvSummary\" `\n -title:\"Coverage Report\" `\n -tag:\"coverage-analysis-skill\"\n\n Get-Content (Join-Path $reportsDir \"Summary.txt\") -ErrorAction SilentlyContinue\n} else {\n Write-Host \"REPORTGENERATOR_SKIPPED:true\"\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"After Phase 5 completes successfully, you may follow up with a short message pointing the user to the generated HTML report (one paragraph, no need to repeat the summary).","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Validation","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Verify that at least one ","type":"text"},{"text":"coverage.cobertura.xml","type":"text","marks":[{"type":"code_inline"}]},{"text":" file was generated after ","type":"text"},{"text":"dotnet test","type":"text","marks":[{"type":"code_inline"}]},{"text":" (or already exists when the user supplied one)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Confirm the assistant response contained the CRAP/risk-hotspot table — saving the markdown file is secondary","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Confirm ","type":"text"},{"text":"TestResults/coverage-analysis/coverage-analysis.md","type":"text","marks":[{"type":"code_inline"}]},{"text":" was written and contains data","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Spot-check one method's CRAP score: ","type":"text"},{"text":"comp² × (1 − cov)³ + comp","type":"text","marks":[{"type":"code_inline"}]},{"text":" — a method with 100% coverage should have CRAP = complexity","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"If Phase 5 ran, verify ","type":"text"},{"text":"TestResults/coverage-analysis/reports/index.html","type":"text","marks":[{"type":"code_inline"}]},{"text":" exists; otherwise the report file should mark HTML/Text/CSV rows as ","type":"text"},{"text":"Not generated","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Common Pitfalls","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"No Cobertura XML generated","type":"text","marks":[{"type":"strong"}]},{"text":" — the test project may lack a coverage provider. The skill auto-adds one, but if ","type":"text"},{"text":"dotnet add package","type":"text","marks":[{"type":"code_inline"}]},{"text":" fails (offline/proxy), coverage collection silently produces nothing. Check for ","type":"text"},{"text":".coverage","type":"text","marks":[{"type":"code_inline"}]},{"text":" binary files as a fallback indicator.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Test failures (exit code 1)","type":"text","marks":[{"type":"strong"}]},{"text":" — coverage is still collected from passing tests. Do not abort; proceed with partial data and note the failures in the summary.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Premature end before user-facing summary","type":"text","marks":[{"type":"strong"}]},{"text":" — never start Phase 5 (ReportGenerator install/run) before the Phase 4 assistant response is delivered. The heavy ","type":"text"},{"text":"dotnet tool install","type":"text","marks":[{"type":"code_inline"}]},{"text":" can crash the session or exhaust budget, leaving the user with no analysis even though the CRAP scores were already computed.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"ReportGenerator install failure","type":"text","marks":[{"type":"strong"}]},{"text":" — if ","type":"text"},{"text":"dotnet tool install","type":"text","marks":[{"type":"code_inline"}]},{"text":" fails (no internet) during Phase 5, leave the existing Phase 4 summary as the final output and note that HTML reports were skipped. Do not retry or block on the install.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Method name mismatches in Cobertura","type":"text","marks":[{"type":"strong"}]},{"text":" — async methods, lambdas, and local functions may have compiler-generated names. The scripts use the Cobertura method name/signature directly; verify against source if results look unexpected.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Mixed coverage providers","type":"text","marks":[{"type":"strong"}]},{"text":" — when a solution contains both Coverlet and Microsoft CodeCoverage projects, the skill runs per-project to avoid dual-provider conflicts. This is slower but correct.","type":"text"}]}]}]},{"type":"hr","attrs":{"markup":"---"}}]},"metadata":{"date":"2026-06-05","name":"coverage-analysis","author":"@skillopedia","source":{"stars":3225,"repo_name":"skills","origin_url":"https://github.com/dotnet/skills/blob/HEAD/plugins/dotnet-test/skills/coverage-analysis/SKILL.md","repo_owner":"dotnet","body_sha256":"0830d431f9e8d18c2c796e66d390148def8ef4b270c12592d58677a987947f16","cluster_key":"99168869bd6a9835914863795e97e58e820bc657ea35cee20523a96c83cd8067","clean_bundle":{"format":"clean-skill-bundle-v1","source":"dotnet/skills/plugins/dotnet-test/skills/coverage-analysis/SKILL.md","attachments":[{"id":"19ce0bda-df59-5c5a-8504-f472601c0636","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/19ce0bda-df59-5c5a-8504-f472601c0636/attachment.md","path":"references/guidelines.md","size":4883,"sha256":"8e7bced5e4deb5e11b008f1d6f8ee69bd5f9a2bb743c9ccceb75f54a7f2790f1","contentType":"text/markdown; charset=utf-8"},{"id":"4a7c12ae-e093-5369-87c4-f0f323a49736","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/4a7c12ae-e093-5369-87c4-f0f323a49736/attachment.md","path":"references/output-format.md","size":3967,"sha256":"f2328f0250002c25276f51373ab3b935b15b41be09c161db02d3e22316ad78c4","contentType":"text/markdown; charset=utf-8"},{"id":"2c8ccd7d-1c8b-5a4a-834e-b7adc460f9c7","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/2c8ccd7d-1c8b-5a4a-834e-b7adc460f9c7/attachment.ps1","path":"scripts/Compute-CrapScores.ps1","size":6775,"sha256":"5c43c1dedbd464500eab3380cf142176bd288d8652ae0aeba45d7fedf830f526","contentType":"text/plain; charset=utf-8"},{"id":"3cf3e022-a386-5ba1-85f2-5154ae98e413","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/3cf3e022-a386-5ba1-85f2-5154ae98e413/attachment.ps1","path":"scripts/Extract-MethodCoverage.ps1","size":8077,"sha256":"37b3c6377dd5f654f2a0b88ceaeb4c77d8798134cbb0c9584532e7b2835f6f5b","contentType":"text/plain; charset=utf-8"}],"bundle_sha256":"c2807a5120b0d18546f74a44c017d6b8ac126cda613d37981bca7339cedb9213","attachment_count":4,"text_attachments":2,"attachment_storage":"skillopedia-attachments-v1","binary_attachments":2,"excluded_attachments":[]},"cluster_size":1,"skill_md_path":"plugins/dotnet-test/skills/coverage-analysis/SKILL.md","import_metadata":{"date":"2026-06-05","author":"@skillopedia","version":"v1","category":"testing-qa","category_label":"Testing"},"exact_dupes_collapsed_into_this":0},"license":"MIT","version":"v1","category":"testing-qa","import_tag":"clean-skills-v1","description":"Project-wide code coverage and CRAP (Change Risk Anti-Patterns) score analysis for .NET projects. Calculates CRAP scores per method and surfaces risk hotspots — complex code with low coverage that is dangerous to modify. Use to diagnose why coverage is stuck or plateaued, identify what methods block improvement, or get project-wide coverage analysis with risk ranking. USE FOR: coverage stuck, coverage plateau, can't increase coverage, what's blocking coverage, coverage gap, CRAP scores, risk hotspots, where to add tests, coverage analysis, coverage report. DO NOT USE FOR: targeted single-method CRAP analysis (use crap-score), writing tests, running tests without coverage, or troubleshooting test execution (use run-tests).\n"}},"renderedAt":1782980914016}

Coverage Analysis Purpose Raw coverage percentages answer "what code was executed?" — they don't answer what you actually need to know: - What tests should I write next? — ranked by risk and impact - Which uncovered code is risky vs. trivial? — CRAP scores separate the two - Why has coverage plateaued? — identify the files blocking further gains - Is this code safe to refactor? — complex + uncovered = dangerous to change This skill bridges that gap: from a bare .NET solution to a prioritized risk hotspot list, with no manual tool configuration required. When to Use Use this skill when the use…