|
| 1 | +# Analyze Commit for Unit Test Coverage |
| 2 | + |
| 3 | +Analyze commit `{COMMIT_SHA}` in repository `{REPOSITORY}` using the GitHub MCP server to determine if unit tests are missing or need to be added. |
| 4 | + |
| 5 | +## Your Task |
| 6 | + |
| 7 | +1. **Examine the commit** using MCP to access: |
| 8 | + - Commit diff and all changed files |
| 9 | + - Existing test files in the repository |
| 10 | + - Project structure and testing patterns |
| 11 | + |
| 12 | +2. **Identify testable code changes** - Look for: |
| 13 | + - New functions, methods, or classes |
| 14 | + - Modified business logic |
| 15 | + - New API endpoints or routes |
| 16 | + - Data validation or transformation logic |
| 17 | + - Error handling paths |
| 18 | + - Edge cases in algorithms |
| 19 | + |
| 20 | +3. **Check for corresponding tests** using these language-agnostic patterns: |
| 21 | + |
| 22 | + ### Common Test File Patterns: |
| 23 | + | Source File | Expected Test File Patterns | |
| 24 | + |-------------|----------------------------| |
| 25 | + | `src/foo.ts` | `src/foo.test.ts`, `src/foo.spec.ts`, `test/foo.test.ts`, `tests/foo.test.ts` | |
| 26 | + | `src/foo.py` | `src/test_foo.py`, `tests/test_foo.py`, `src/foo_test.py` | |
| 27 | + | `src/Foo.java` | `src/FooTest.java`, `test/FooTest.java` | |
| 28 | + | `src/foo.go` | `src/foo_test.go` | |
| 29 | + | `src/foo.rs` | `src/foo_test.rs`, `tests/foo.rs` | |
| 30 | + | `src/foo.rb` | `spec/foo_spec.rb`, `test/foo_test.rb` | |
| 31 | + | `src/foo.cs` | `src/FooTests.cs`, `tests/FooTests.cs` | |
| 32 | + | `lib/foo.js` | `lib/foo.test.js`, `test/foo.test.js` | |
| 33 | + |
| 34 | + ### Common Test Directories: |
| 35 | + - `test/`, `tests/`, `spec/`, `__tests__/` |
| 36 | + - `src/__tests__/`, `src/test/` |
| 37 | + - Language-specific: `pytest/`, `jest/`, `rspec/` |
| 38 | + |
| 39 | +4. **Evaluate test coverage need** based on: |
| 40 | + |
| 41 | + ### ✅ Tests Likely Needed: |
| 42 | + - New public functions/methods without corresponding test additions |
| 43 | + - Complex conditional logic (if/else, switch) added |
| 44 | + - New error handling or exception paths |
| 45 | + - Data parsing, validation, or transformation |
| 46 | + - New API endpoints or route handlers |
| 47 | + - Database queries or data access logic |
| 48 | + - Security-related code (auth, encryption, sanitization) |
| 49 | + - Business rules or domain logic |
| 50 | + - Integration points with external services |
| 51 | + |
| 52 | + ### ❌ Tests Likely NOT Needed: |
| 53 | + - Pure configuration file changes |
| 54 | + - Documentation or comment-only changes |
| 55 | + - Type definitions or interfaces only |
| 56 | + - Simple constant definitions |
| 57 | + - Dependency version updates only |
| 58 | + - CSS/styling changes only |
| 59 | + - Trivial getter/setter additions |
| 60 | + - Test file changes themselves (tests testing tests) |
| 61 | + - Generated or auto-generated code |
| 62 | + - Migration scripts that are run once |
| 63 | + |
| 64 | +5. **Calculate a confidence score** (0-100) for whether tests are needed: |
| 65 | + - 80-100: Tests definitely needed - significant untested logic added |
| 66 | + - 60-79: Tests recommended - meaningful code without test coverage |
| 67 | + - 40-59: Tests optional - minor changes that could use tests |
| 68 | + - 0-39: Tests not needed - trivial or already covered |
| 69 | + |
| 70 | +6. **If tests are recommended (score >= 60):** |
| 71 | + |
| 72 | + Create a GitHub issue using MCP with: |
| 73 | + |
| 74 | + **Title:** `🧪 Unit tests needed for: [brief description of changes]` |
| 75 | + |
| 76 | + **Body should include:** |
| 77 | + ```markdown |
| 78 | + ## Test Coverage Analysis |
| 79 | + |
| 80 | + **Commit:** {COMMIT_SHA} |
| 81 | + **Confidence Score:** [X]/100 |
| 82 | + |
| 83 | + ### Files Needing Tests |
| 84 | + |
| 85 | + | Source File | Status | Suggested Test File | |
| 86 | + |-------------|--------|---------------------| |
| 87 | + | `path/to/file.ext` | ⚠️ No tests found | `path/to/file.test.ext` | |
| 88 | + |
| 89 | + ### Recommended Test Cases |
| 90 | + |
| 91 | + For each file, list specific functions/methods and suggested test scenarios: |
| 92 | + |
| 93 | + #### `filename.ext` |
| 94 | + - [ ] Test `functionName()` - happy path |
| 95 | + - [ ] Test `functionName()` - error handling |
| 96 | + - [ ] Test `functionName()` - edge cases (null, empty, boundary values) |
| 97 | + |
| 98 | + ### Why Tests Are Needed |
| 99 | + |
| 100 | + [Explain the risk of not having tests for this code] |
| 101 | + |
| 102 | + ### Testing Hints |
| 103 | + |
| 104 | + - Framework detected: [Jest/Pytest/JUnit/etc. or "Unknown"] |
| 105 | + - Existing test patterns: [Describe patterns found in repo] |
| 106 | + - Mock/stub suggestions: [If external dependencies need mocking] |
| 107 | + |
| 108 | + --- |
| 109 | + *Auto-generated by test coverage workflow* |
| 110 | + ``` |
| 111 | + |
| 112 | + - Add labels: `testing`, `automated`, `unit-tests` |
| 113 | + - Use assign_copilot_to_issue tool to assign @copilot to the issue |
| 114 | + |
| 115 | +7. **If tests are NOT needed (score < 60):** |
| 116 | + - Provide a brief explanation of why tests aren't necessary |
| 117 | + - No issue creation needed |
| 118 | + |
| 119 | +## Important Guidelines |
| 120 | + |
| 121 | +- Be language-agnostic - detect the language from file extensions |
| 122 | +- Consider the project's existing testing conventions |
| 123 | +- Don't flag test files as needing tests |
| 124 | +- Consider that some projects use different testing philosophies |
| 125 | +- Account for integration tests vs unit tests |
| 126 | +- Be specific about WHAT should be tested, not just that tests are needed |
0 commit comments