Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ NetContextServer empowers AI coding assistants like Cursor AI to deeply understa
- 🔍 **Deep Dependency Visualization**: See transitive dependencies with interactive, color-coded graphs
- 🧩 **Smart Grouping**: Visually group related packages for easier navigation
- 📊 **Update Recommendations**: Identify outdated packages and security issues
- 📊 **Test Coverage Analysis**: Deep insights into your test coverage
- 🎯 **Multi-Format Support**: Parse coverage data from Coverlet, LCOV, and Cobertura XML
- 📈 **Detailed Reports**: File-level coverage percentages and uncovered line tracking
- 🔄 **Branch Coverage**: Track method-level branch coverage where available
- 💡 **Smart Recommendations**: Get suggestions for improving test coverage
- ⚡ **Fast & Efficient**: Quick indexing and response times for large codebases

## 🚀 Quick Start
Expand Down Expand Up @@ -78,6 +83,10 @@ Now Cursor AI can understand your codebase! Try asking it questions like:
- "What's the current base directory for file operations?"
- "Help me think through the authentication system design"
- "Document my reasoning about this architectural decision"
- "Analyze test coverage for MyService.cs"
- "Show me uncovered lines in the authentication module"
- "What's the overall test coverage percentage?"
- "Which files have the lowest test coverage?"

## 📚 Documentation

Expand All @@ -95,6 +104,11 @@ Now Cursor AI can understand your codebase! Try asking it questions like:
- 📖 **File Content Access**: Read source files with safety checks and size limits
- 🛡️ **Security**: Built-in safeguards for sensitive files and directory access
- 🎯 **Pattern Management**: Flexible ignore patterns for controlling file access
- 📊 **Coverage Analysis**: Parse and analyze test coverage data
- 📈 **Coverage Reports**: Support for Coverlet JSON, LCOV, and Cobertura XML formats
- 🎯 **Line Coverage**: Track which lines are covered by tests
- 🌳 **Branch Coverage**: Monitor method-level branch coverage
- 💡 **Recommendations**: Get actionable suggestions to improve coverage
- 💭 **Structured Thinking**: Document and validate reasoning about complex operations
- 🧩 **AI-Optimized Reasoning**: Based on [Anthropic's research](https://www.anthropic.com/engineering/claude-think-tool) on improving LLM problem-solving
- 📋 **Task Planning**: Break down complex problems into manageable steps
Expand Down Expand Up @@ -187,6 +201,34 @@ Project: MyProject.csproj
└─ Microsoft.Extensions.DependencyInjection.Abstractions
```

6. **Analyze Test Coverage**:
```bash
# Set your base directory first
dotnet run --project src/NetContextClient/NetContextClient.csproj -- set-base-dir --directory "path/to/your/project"

# Analyze coverage from a Coverlet JSON report
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-analysis --report-path "TestResults/coverage.json"

# Get a coverage summary
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-summary --report-path "TestResults/coverage.json"
```

Example coverage analysis output:
```json
[
{
"filePath": "src/MyProject/Services/UserService.cs",
"coveragePercentage": 85.3,
"uncoveredLines": [42, 43, 88],
"branchCoverage": {
"ValidateUser()": 75.0,
"GetUserById()": 100.0
},
"recommendation": "Consider adding tests for the user validation error paths"
}
]
```

### Search Commands

1. **Text Search**:
Expand Down
51 changes: 51 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,57 @@ dotnet run --project src/NetContextClient/NetContextClient.csproj -- add-ignore-
dotnet run --project src/NetContextClient/NetContextClient.csproj -- get-ignore-patterns
```

## Using Coverage Analysis

NetContextServer includes powerful test coverage analysis capabilities that help you understand and improve your test coverage. Here's how to get started:

### 1. Generate Coverage Reports

First, you'll need to generate a coverage report. NetContextServer supports multiple formats:

**Using Coverlet (recommended):**
```bash
dotnet test --collect:"XPlat Code Coverage"
```
This will generate a coverage report in the `TestResults` directory.

**Using LCOV:**
If you're using LCOV, make sure your test runner is configured to output LCOV format (`.info` files).

**Using Cobertura:**
For Cobertura XML format, configure your test runner to output `.cobertura.xml` files.

### 2. Analyze Coverage

Once you have a coverage report, you can analyze it using NetContextServer:

```bash
# Analyze coverage for detailed per-file information
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-analysis --report-path "TestResults/coverage.json"

# Get a summary of overall coverage
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-summary --report-path "TestResults/coverage.json"
```

### 3. Interpret Results

The coverage analysis provides several key insights:

- **Coverage Percentage**: The percentage of lines covered by tests
- **Uncovered Lines**: Specific line numbers that aren't covered by tests
- **Branch Coverage**: For methods with conditional logic, shows how many branches are covered
- **Recommendations**: Suggestions for improving coverage in specific areas

### 4. Improve Coverage

Use the analysis results to:
1. Identify files with low coverage
2. Focus on uncovered lines in critical code paths
3. Add tests for uncovered branches in complex methods
4. Track coverage trends over time

For more details on coverage analysis commands and options, see the [Tool Reference](tool-reference.md#coverage-analysis-tools).

## Troubleshooting

### Common Issues
Expand Down
57 changes: 56 additions & 1 deletion docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,59 @@ The server provides clear error messages for common scenarios:
- Invalid patterns
- File size limits exceeded
- Restricted file types
- Missing environment variables for semantic search
- Missing environment variables for semantic search

## Coverage Analysis Tools

### `coverage-analysis`

Analyzes test coverage data from various formats and provides detailed insights.

```bash
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-analysis --report-path <path> [--format <format>]
```

**Parameters:**
- `--report-path`: Path to the coverage report file
- `--format` (optional): Coverage report format. Supported values:
- `coverlet-json` (default): Coverlet JSON format
- `lcov`: LCOV format
- `cobertura`: Cobertura XML format

**Output:**
Returns a list of coverage reports for each file, including:
- File path
- Coverage percentage
- List of uncovered lines
- Branch coverage data (where available)
- Recommendations for improving coverage

**Example:**
```bash
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-analysis --report-path "TestResults/coverage.json"
```

### `coverage-summary`

Generates a summary of test coverage across all files.

```bash
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-summary --report-path <path> [--format <format>]
```

**Parameters:**
- `--report-path`: Path to the coverage report file
- `--format` (optional): Coverage report format (same as coverage-analysis)

**Output:**
Returns a summary object containing:
- Total number of files
- Overall coverage percentage
- Total number of uncovered lines
- List of files with coverage below threshold
- List of files with lowest coverage

**Example:**
```bash
dotnet run --project src/NetContextClient/NetContextClient.csproj -- coverage-summary --report-path "TestResults/coverage.json"
```
73 changes: 73 additions & 0 deletions src/NetContextClient/Models/CoverageReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace NetContextClient.Models;

/// <summary>
/// Represents a code coverage report for a single file or class.
/// </summary>
public class CoverageReport
{
/// <summary>
/// Gets or sets the path to the source file, relative to the project root.
/// </summary>
public string FilePath { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the overall coverage percentage for the file (0-100).
/// </summary>
public float CoveragePercentage { get; set; }

/// <summary>
/// Gets or sets the list of line numbers that are not covered by tests.
/// </summary>
public List<int> UncoveredLines { get; set; } = [];

/// <summary>
/// Gets or sets the total number of executable lines in the file.
/// </summary>
public int TotalLines { get; set; }

/// <summary>
/// Gets or sets the branch coverage information, mapping method names to their coverage percentage.
/// </summary>
public Dictionary<string, float> BranchCoverage { get; set; } = [];

/// <summary>
/// Gets or sets the list of test files that provide coverage for this file.
/// </summary>
public List<string> TestFiles { get; set; } = [];

/// <summary>
/// Gets or sets a suggested action to improve coverage, if applicable.
/// </summary>
public string? Recommendation { get; set; }

/// <summary>
/// The type of file being analyzed (Production, Test, Generated, or Unknown)
/// </summary>
public CoverageFileType FileType { get; set; } = CoverageFileType.Unknown;
}

/// <summary>
/// Represents the type of file being analyzed for code coverage
/// </summary>
public enum CoverageFileType
{
/// <summary>
/// Production code file
/// </summary>
Production,

/// <summary>
/// Test code file
/// </summary>
Test,

/// <summary>
/// Generated code file
/// </summary>
Generated,

/// <summary>
/// Unknown file type
/// </summary>
Unknown
}
52 changes: 52 additions & 0 deletions src/NetContextClient/Models/CoverageSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace NetContextClient.Models;

/// <summary>
/// Represents a summary of code coverage across multiple files.
/// </summary>
public class CoverageSummary
{
/// <summary>
/// Gets or sets the overall coverage percentage across all files.
/// </summary>
public float TotalCoveragePercentage { get; set; }

/// <summary>
/// Gets or sets the total number of files analyzed.
/// </summary>
public int TotalFiles { get; set; }

/// <summary>
/// Gets or sets the number of files with coverage below a warning threshold.
/// </summary>
public int FilesWithLowCoverage { get; set; }

/// <summary>
/// Gets or sets the total number of uncovered lines across all files.
/// </summary>
public int TotalUncoveredLines { get; set; }

/// <summary>
/// Gets or sets a list of files with the lowest coverage percentages.
/// </summary>
public List<CoverageReport> LowestCoverageFiles { get; set; } = [];

/// <summary>
/// Number of production files analyzed
/// </summary>
public int ProductionFiles { get; set; }

/// <summary>
/// Number of test files analyzed
/// </summary>
public int TestFiles { get; set; }

/// <summary>
/// Average coverage percentage for production files
/// </summary>
public float ProductionCoveragePercentage { get; set; }

/// <summary>
/// Average coverage percentage for test files
/// </summary>
public float TestCoveragePercentage { get; set; }
}
Loading