Skip to content

[Testing Layer] Test Coverage & Quality Awareness Service #15

@gloomcheng

Description

@gloomcheng

Problem

Claude Code doesn't know:

  • Which code has tests, which doesn't
  • Test quality (assertions, edge cases, mocks)
  • Test-to-code ratio
  • Which tests are flaky or slow

Developer Pain Points

❌ "I just wrote tests for code that already had tests"
❌ "AI suggested a change that broke untested code"
❌ "No guidance on what tests to write"
❌ "Tests are flaky but no visibility into which ones"

Proposed Solution

Test Coverage Service

```typescript
interface TestCoverageService {
// Parse test files
analyzeTests(projectRoot: string): Promise

// Map tests to source code
getTestsForFile(file: string): Promise<TestFile[]>

// Calculate coverage metrics
getCoverageMetrics(): Promise

// Identify missing tests
findUntested(): Promise<UntestedCode[]>

// Detect test smells
detectTestSmells(): Promise<TestSmell[]>
}
```

Features

  1. Test File Parsing

    • Support Jest, Mocha, Vitest, Playwright
    • Extract test cases and assertions
    • Map describe/it blocks to functions
  2. Coverage Mapping

    • Map test files to source files
    • Track line/function/branch coverage
    • Identify untested code paths
  3. Quality Detection

    • No assertions (empty tests)
    • Only happy path (no edge cases)
    • Missing mocks/spies
    • Slow tests (>1s execution)
  4. MCP Tools

    • `test-analyze`: Analyze test coverage
    • `test-suggest`: Suggest tests for file
    • `test-quality`: Check test quality
    • `test-untested`: Find untested code

Integration with ImplementationValidator

Add test coverage check:
```typescript
if (testCoverage < 80%) {
warnings.push("Low test coverage: " + coverage + "%")
suggestions.push("Add tests for: " + untestedFiles)
}
```

Acceptance Criteria

  • TestCoverageService created
  • Supports Jest, Vitest
  • Maps tests to source files
  • Detects 5+ test smells
  • 4 MCP tools registered
  • Integrated with validation pipeline
  • Tests and documentation

Priority

🔴 Critical - Huge developer pain point

Effort Estimate

3 days

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlayer:analysisAnalysis Layer - static analysis & impactpriority:highHigh priority item

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions