Analyze commit {COMMIT_SHA} in repository {REPOSITORY} using the GitHub MCP server to determine if unit tests are missing or need to be added.
-
Examine the commit using MCP to access:
- Commit diff and all changed files
- Existing test files in the repository
- Project structure and testing patterns
-
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
-
Check for corresponding tests using these language-agnostic patterns:
Source File Expected Test File Patterns src/foo.tssrc/foo.test.ts,src/foo.spec.ts,test/foo.test.ts,tests/foo.test.tssrc/foo.pysrc/test_foo.py,tests/test_foo.py,src/foo_test.pysrc/Foo.javasrc/FooTest.java,test/FooTest.javasrc/foo.gosrc/foo_test.gosrc/foo.rssrc/foo_test.rs,tests/foo.rssrc/foo.rbspec/foo_spec.rb,test/foo_test.rbsrc/foo.cssrc/FooTests.cs,tests/FooTests.cslib/foo.jslib/foo.test.js,test/foo.test.jstest/,tests/,spec/,__tests__/src/__tests__/,src/test/- Language-specific:
pytest/,jest/,rspec/
-
Evaluate test coverage need based on:
- 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
- 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
-
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
-
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
- Add labels:
-
If tests are NOT needed (score < 60):
- Provide a brief explanation of why tests aren't necessary
- No issue creation needed
- 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