|
1 | | -# Test Automation for Coding Agent |
| 1 | +# Test Automation Framework |
2 | 2 |
|
3 | | -This directory contains test automation for the coding agent project, modified per user request to remove GitHub and GitLab mocking. |
| 3 | +This directory contains a comprehensive test automation framework for the coding agent project, including both real API integration tests and mock tests. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
7 | | -The test automation framework provides: |
| 7 | +The test framework provides two modes of operation: |
8 | 8 |
|
9 | | -1. **Mock LLM Client** - Provides configurable LLM responses for testing |
10 | | -2. **Basic MCP Client Mock** - Generic MCP client interface without service-specific data |
11 | | -3. **Unit Tests** - Tests basic functionality without external service dependencies |
12 | | -4. **Integration Tests** - Tests framework components working together |
13 | | -5. **Test Configuration** - Mock-enabled configuration for testing |
| 9 | +1. **Real Integration Tests**: Use actual GitHub and GitLab APIs for comprehensive end-to-end testing |
| 10 | +2. **Mock Tests**: Use mock implementations for rapid development and CI/CD pipelines |
14 | 11 |
|
15 | 12 | ## Test Structure |
16 | 13 |
|
17 | 14 | ``` |
18 | 15 | tests/ |
19 | | -├── __init__.py |
20 | | -├── test_config.yaml # Test configuration with mock providers |
21 | | -├── run_tests.py # Test runner script |
22 | | -├── demo.py # Demo of testing framework |
23 | | -├── mocks/ # Mock implementations |
24 | | -│ ├── __init__.py |
25 | | -│ ├── mock_mcp_client.py # Generic MCP client mock (GitHub/GitLab specifics removed) |
26 | | -│ └── mock_llm_client.py # Mock LLM client with configurable responses |
27 | | -├── unit/ # Unit tests |
28 | | -│ ├── test_github_tasks.py # Basic GitHub-related functionality tests (no API mocking) |
29 | | -│ └── test_gitlab_tasks.py # Basic GitLab-related functionality tests (no API mocking) |
30 | | -└── integration/ # Integration tests |
31 | | - └── test_workflow.py # Basic framework integration tests |
32 | | -``` |
33 | | - |
34 | | -## Key Features Tested |
35 | | - |
36 | | -### LLM Integration |
37 | | -- Mock LLM client with configurable responses |
38 | | -- JSON response parsing and error handling |
39 | | -- Multi-turn conversation simulation |
40 | | -- Error recovery testing |
41 | | - |
42 | | -### Basic GitHub/GitLab Functionality (No Service Mocking) |
43 | | -- URL parsing and basic data structure handling |
44 | | -- Label manipulation |
45 | | -- Prompt formatting |
46 | | -- Basic validation without API calls |
47 | | - |
48 | | -### Framework Integration |
49 | | -- Mock components working together |
50 | | -- Configuration loading |
| 16 | +├── unit/ # Unit tests for individual components |
| 17 | +│ ├── test_github_tasks.py # Real GitHub API integration tests |
| 18 | +│ └── test_gitlab_tasks.py # Real GitLab API integration tests |
| 19 | +├── integration/ # End-to-end workflow tests |
| 20 | +│ └── test_workflow.py # Real GitHub/GitLab workflow tests |
| 21 | +├── mocks/ # Mock implementations |
| 22 | +│ ├── mock_llm_client.py # Mock LLM client |
| 23 | +│ └── mock_mcp_client.py # Mock MCP client (simplified) |
| 24 | +├── real_test_config_github.yaml # GitHub real API test configuration |
| 25 | +├── real_test_config_gitlab.yaml # GitLab real API test configuration |
| 26 | +├── test_config.yaml # Mock test configuration |
| 27 | +├── run_tests.py # Enhanced test runner |
| 28 | +├── demo.py # Interactive demonstration |
| 29 | +└── README.md # This file |
| 30 | +``` |
| 31 | + |
| 32 | +## Real Integration Tests |
| 33 | + |
| 34 | +### Prerequisites |
| 35 | + |
| 36 | +For real integration tests, you need: |
| 37 | + |
| 38 | +#### GitHub Tests |
| 39 | +- GitHub personal access token with appropriate permissions |
| 40 | +- Access to a test repository (default: `notfolder/coding-agent-test`) |
| 41 | +- Environment variable: `GITHUB_TOKEN` |
| 42 | + |
| 43 | +#### GitLab Tests |
| 44 | +- GitLab personal access token with appropriate permissions |
| 45 | +- Access to a test project (default: `coding-agent-test`) |
| 46 | +- Environment variables: `GITLAB_TOKEN`, `GITLAB_API_URL` (optional) |
| 47 | + |
| 48 | +### Test Capabilities |
| 49 | + |
| 50 | +#### GitHub Integration Tests |
| 51 | +- **MCP Server Connection**: Tests GitHub MCP server connectivity and tool availability |
| 52 | +- **Issue Search**: Real GitHub issue search using the search API |
| 53 | +- **Issue Details**: Retrieving issue details, comments, and metadata |
| 54 | +- **Task Processing**: End-to-end GitHub task workflow with real data |
| 55 | +- **Label Management**: Testing label updates and state transitions |
| 56 | +- **Error Handling**: Robust error handling for API failures |
| 57 | + |
| 58 | +#### GitLab Integration Tests |
| 59 | +- **MCP Server Connection**: Tests GitLab MCP server connectivity and tool availability |
| 60 | +- **Issue Listing**: Real GitLab issue listing with filtering |
| 61 | +- **Issue Details**: Retrieving issue details and discussions |
| 62 | +- **Task Processing**: End-to-end GitLab task workflow with real data |
| 63 | +- **Label Management**: Testing label updates and state transitions |
| 64 | +- **Error Handling**: Robust error handling for API failures |
| 65 | + |
| 66 | +### Running Tests |
| 67 | + |
| 68 | +#### All Tests (Auto-detect mode) |
| 69 | +```bash |
| 70 | +# Automatically runs real tests if tokens available, otherwise mock tests |
| 71 | +python3 -m tests.run_tests |
| 72 | +``` |
| 73 | + |
| 74 | +#### Real Integration Tests Only |
| 75 | +```bash |
| 76 | +# Requires GITHUB_TOKEN and/or GITLAB_TOKEN |
| 77 | +python3 -m tests.run_tests --real |
| 78 | +``` |
| 79 | + |
| 80 | +#### Unit Tests Only |
| 81 | +```bash |
| 82 | +python3 -m tests.run_tests --unit |
| 83 | +``` |
| 84 | + |
| 85 | +#### Integration Tests Only |
| 86 | +```bash |
| 87 | +python3 -m tests.run_tests --integration |
| 88 | +``` |
| 89 | + |
| 90 | +#### Mock Tests Only |
| 91 | +```bash |
| 92 | +python3 -m tests.run_tests --mock |
| 93 | +``` |
| 94 | + |
| 95 | +### Environment Setup |
| 96 | + |
| 97 | +#### GitHub Setup |
| 98 | +```bash |
| 99 | +export GITHUB_TOKEN="your_github_token_here" |
| 100 | +# Optional: specify test repository |
| 101 | +export GITHUB_TEST_REPO="owner/repo-name" |
| 102 | +``` |
| 103 | + |
| 104 | +#### GitLab Setup |
| 105 | +```bash |
| 106 | +export GITLAB_TOKEN="your_gitlab_token_here" |
| 107 | +# Optional: specify GitLab instance |
| 108 | +export GITLAB_API_URL="https://gitlab.com/api/v4" |
| 109 | +# Optional: specify test project |
| 110 | +export GITLAB_TEST_PROJECT="project-name" |
| 111 | +``` |
| 112 | + |
| 113 | +## Configuration |
| 114 | + |
| 115 | +### Real Test Configurations |
| 116 | + |
| 117 | +#### GitHub Configuration (`real_test_config_github.yaml`) |
| 118 | +- Configures real GitHub MCP server with authentication |
| 119 | +- Specifies test repository and query parameters |
| 120 | +- Uses mock LLM client to isolate GitHub API testing |
| 121 | + |
| 122 | +#### GitLab Configuration (`real_test_config_gitlab.yaml`) |
| 123 | +- Configures real GitLab MCP server with authentication |
| 124 | +- Specifies test project and query parameters |
| 125 | +- Uses mock LLM client to isolate GitLab API testing |
| 126 | + |
| 127 | +### Test Repository Setup |
| 128 | + |
| 129 | +#### For GitHub |
| 130 | +1. Create a test repository (e.g., `coding-agent-test`) |
| 131 | +2. Create test issues with the `coding agent` label |
| 132 | +3. Ensure your token has permissions for: |
| 133 | + - Reading issues and comments |
| 134 | + - Updating issue labels |
| 135 | + - Creating comments |
| 136 | + |
| 137 | +#### For GitLab |
| 138 | +1. Create a test project (e.g., `coding-agent-test`) |
| 139 | +2. Create test issues with the `coding agent` label |
| 140 | +3. Ensure your token has permissions for: |
| 141 | + - Reading issues and discussions |
| 142 | + - Updating issue labels |
| 143 | + - Creating notes/comments |
| 144 | + |
| 145 | +## Test Features |
| 146 | + |
| 147 | +### Comprehensive Coverage |
| 148 | +- **API Integration**: Tests real API calls and responses |
| 149 | +- **Error Handling**: Tests error scenarios and recovery |
| 150 | +- **Data Validation**: Validates real API response structures |
| 151 | +- **Workflow Testing**: Tests complete task processing workflows |
| 152 | +- **State Management**: Tests label transitions and issue states |
| 153 | + |
| 154 | +### Safety Features |
| 155 | +- **Non-destructive**: Tests are designed to minimize impact on repositories |
| 156 | +- **Graceful Degradation**: Tests skip if API tokens are not available |
| 157 | +- **Isolated Testing**: Uses designated test repositories/projects |
| 158 | +- **Error Recovery**: Robust error handling prevents test failures from affecting repositories |
| 159 | + |
| 160 | +### Performance Considerations |
| 161 | +- **Efficient API Usage**: Minimizes API calls to respect rate limits |
| 162 | +- **Batched Operations**: Groups related operations where possible |
| 163 | +- **Caching**: Caches results where appropriate to reduce API load |
| 164 | + |
| 165 | +## Test Results |
| 166 | + |
| 167 | +Real integration tests provide: |
| 168 | + |
| 169 | +1. **Connectivity Verification**: Confirms MCP servers can connect to APIs |
| 170 | +2. **Tool Availability**: Verifies all required MCP tools are accessible |
| 171 | +3. **Data Integrity**: Validates real API response structures |
| 172 | +4. **Workflow Validation**: Confirms complete task processing workflows |
| 173 | +5. **Error Resilience**: Tests error handling and recovery mechanisms |
| 174 | + |
| 175 | +## Troubleshooting |
| 176 | + |
| 177 | +### Common Issues |
| 178 | + |
| 179 | +#### GitHub Token Issues |
| 180 | +```bash |
| 181 | +# Check token permissions |
| 182 | +curl -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user |
| 183 | +``` |
| 184 | + |
| 185 | +#### GitLab Token Issues |
| 186 | +```bash |
| 187 | +# Check token permissions |
| 188 | +curl -H "Authorization: Bearer $GITLAB_TOKEN" "$GITLAB_API_URL/user" |
| 189 | +``` |
| 190 | + |
| 191 | +#### MCP Server Issues |
| 192 | +- Ensure Node.js packages are installed: `npm install` |
| 193 | +- Check MCP server availability: `npx @notfolder/github-mcp-server --version` |
| 194 | + |
| 195 | +### Test Failures |
| 196 | + |
| 197 | +#### No Issues Found |
| 198 | +- Create test issues in your test repository/project |
| 199 | +- Ensure issues have the correct labels (`coding agent`) |
| 200 | +- Verify repository/project access permissions |
| 201 | + |
| 202 | +#### API Rate Limits |
| 203 | +- Use dedicated test repositories to minimize API usage |
| 204 | +- Implement delays between test runs if needed |
| 205 | +- Use mock tests for frequent testing |
| 206 | + |
| 207 | +#### Permission Errors |
| 208 | +- Verify token has required scopes/permissions |
| 209 | +- Check repository/project access rights |
| 210 | +- Ensure test repository/project exists and is accessible |
| 211 | + |
| 212 | +## Mock Tests |
| 213 | + |
| 214 | +For development and CI/CD environments where API tokens are not available: |
| 215 | + |
| 216 | +```bash |
| 217 | +python3 -m tests.run_tests --mock |
| 218 | +``` |
| 219 | + |
| 220 | +Mock tests provide basic framework validation without external dependencies. |
| 221 | + |
| 222 | +## Interactive Demo |
| 223 | + |
| 224 | +For manual testing and exploration: |
| 225 | + |
| 226 | +```bash |
| 227 | +python3 tests/demo.py |
| 228 | +``` |
| 229 | + |
| 230 | +The demo provides an interactive interface to test various components manually. |
51 | 231 | - Basic workflow validation |
52 | 232 | ## Running Tests |
53 | 233 |
|
|
0 commit comments