Skip to content

Latest commit

 

History

History
126 lines (96 loc) · 4.57 KB

File metadata and controls

126 lines (96 loc) · 4.57 KB

Analyze Commit for Unit Test Coverage

Analyze commit {COMMIT_SHA} in repository {REPOSITORY} using the GitHub MCP server to determine if unit tests are missing or need to be added.

Your Task

  1. Examine the commit using MCP to access:

    • Commit diff and all changed files
    • Existing test files in the repository
    • Project structure and testing patterns
  2. Identify testable code changes - Look for:

    • New functions, methods, or classes
    • Modified business logic
    • New API endpoints or routes
    • Data validation or transformation logic
    • Error handling paths
    • Edge cases in algorithms
  3. Check for corresponding tests using these language-agnostic patterns:

    Common Test File Patterns:

    Source File Expected Test File Patterns
    src/foo.ts src/foo.test.ts, src/foo.spec.ts, test/foo.test.ts, tests/foo.test.ts
    src/foo.py src/test_foo.py, tests/test_foo.py, src/foo_test.py
    src/Foo.java src/FooTest.java, test/FooTest.java
    src/foo.go src/foo_test.go
    src/foo.rs src/foo_test.rs, tests/foo.rs
    src/foo.rb spec/foo_spec.rb, test/foo_test.rb
    src/foo.cs src/FooTests.cs, tests/FooTests.cs
    lib/foo.js lib/foo.test.js, test/foo.test.js

    Common Test Directories:

    • test/, tests/, spec/, __tests__/
    • src/__tests__/, src/test/
    • Language-specific: pytest/, jest/, rspec/
  4. Evaluate test coverage need based on:

    ✅ Tests Likely Needed:

    • New public functions/methods without corresponding test additions
    • Complex conditional logic (if/else, switch) added
    • New error handling or exception paths
    • Data parsing, validation, or transformation
    • New API endpoints or route handlers
    • Database queries or data access logic
    • Security-related code (auth, encryption, sanitization)
    • Business rules or domain logic
    • Integration points with external services

    ❌ Tests Likely NOT Needed:

    • Pure configuration file changes
    • Documentation or comment-only changes
    • Type definitions or interfaces only
    • Simple constant definitions
    • Dependency version updates only
    • CSS/styling changes only
    • Trivial getter/setter additions
    • Test file changes themselves (tests testing tests)
    • Generated or auto-generated code
    • Migration scripts that are run once
  5. Calculate a confidence score (0-100) for whether tests are needed:

    • 80-100: Tests definitely needed - significant untested logic added
    • 60-79: Tests recommended - meaningful code without test coverage
    • 40-59: Tests optional - minor changes that could use tests
    • 0-39: Tests not needed - trivial or already covered
  6. If tests are recommended (score >= 60):

    Create a GitHub issue using MCP with:

    Title: 🧪 Unit tests needed for: [brief description of changes]

    Body should include:

    ## Test Coverage Analysis
    
    **Commit:** {COMMIT_SHA}
    **Confidence Score:** [X]/100
    
    ### Files Needing Tests
    
    | Source File | Status | Suggested Test File |
    |-------------|--------|---------------------|
    | `path/to/file.ext` | ⚠️ No tests found | `path/to/file.test.ext` |
    
    ### Recommended Test Cases
    
    For each file, list specific functions/methods and suggested test scenarios:
    
    #### `filename.ext`
    - [ ] Test `functionName()` - happy path
    - [ ] Test `functionName()` - error handling
    - [ ] Test `functionName()` - edge cases (null, empty, boundary values)
    
    ### Why Tests Are Needed
    
    [Explain the risk of not having tests for this code]
    
    ### Testing Hints
    
    - Framework detected: [Jest/Pytest/JUnit/etc. or "Unknown"]
    - Existing test patterns: [Describe patterns found in repo]
    - Mock/stub suggestions: [If external dependencies need mocking]
    
    ---
    *Auto-generated by test coverage workflow*
    • Add labels: testing, automated, unit-tests
    • Use assign_copilot_to_issue tool to assign @copilot to the issue
  7. If tests are NOT needed (score < 60):

    • Provide a brief explanation of why tests aren't necessary
    • No issue creation needed

Important Guidelines

  • Be language-agnostic - detect the language from file extensions
  • Consider the project's existing testing conventions
  • Don't flag test files as needing tests
  • Consider that some projects use different testing philosophies
  • Account for integration tests vs unit tests
  • Be specific about WHAT should be tested, not just that tests are needed