Troubleshooting
Relevant source files
The following files were used as context for generating this wiki page:
This document provides guidance for diagnosing and resolving common issues encountered while using the TestGen AI application. It covers problems related to repository cloning, API connectivity, test generation, and test execution for both the client-side and Go backend implementations.
Sources: README.md:213-226
Common Issues Overview
The following table summarizes the most frequent problems and their initial checks.
| Issue | Likely Cause | First Steps |
|---|---|---|
| CORS Errors | Running the frontend locally (localhost) while the backend is not configured for it, or browser security blocking direct API calls. | Ensure the Go backend is running on port 3001 or use the deployed version. |
| Clone Failures | Invalid GitHub URL, private repository, or network issues. | Check the repository URL format and ensure the repository is public. |
| API Errors | Invalid or missing Gemini API key. | Verify the Gemini API key is correctly entered in the Settings tab. |
| Test Execution Failures | The code being tested relies on functions not available in the test runner's mock environment. | Check if the test execution environment covers the necessary use case. |
Sources: README.md:216-222, testgen/CLIENT_BACKEND.md:36-39
Frontend (Client-Side) Troubleshooting
The frontend application, which can run with a client-side backend, has specific error handling and potential issues.
API Connectivity Errors
The client-side backend in backend.ts handles various API errors when communicating with the GitHub and Gemini APIs. The UI in Dashboard.tsx displays these errors as "toast" notifications.
Sources: testgen/src/lib/backend.ts:311-322, testgen/src/pages/Dashboard.tsx:100-107
GitHub API Error Handling
The cloneRepository function in the client-side backend provides specific error messages for common GitHub API issues.
This diagram shows the error handling flow for a GitHub API request.
Sources: testgen/src/lib/backend.ts:311-322
Common frontend error messages and their meanings:
| Error Message | Cause |
|---|---|
CORS error: GitHub API calls are blocked... | The browser is blocking a cross-origin request to api.github.com. This is common on localhost. |
Repository not found. Please check the URL... | The GitHub API returned a 404 error. The repository URL is likely incorrect or the repository is private. |
GitHub API rate limit exceeded. Please try again later. | The GitHub API returned a 403 error. The unauthenticated API limit (60 requests/hour) has been reached. |
Sources: testgen/src/lib/backend.ts:315-321
CORS (Cross-Origin Resource Sharing) Issues
When running the application from localhost, direct calls from the browser to the GitHub API may be blocked by the browser's security policy. This is a primary cause of repository fetching failures in a local development environment. The project includes test pages (test-repo.html, test-simple.html) to help diagnose these connectivity issues directly.
Sources: testgen/CLIENT_BACKEND.md:36-39, testgen/test-repo.html:15-16
The sequence diagram below illustrates how a CORS error occurs.
Go Backend Troubleshooting
The Go backend provides more robust repository handling and centralized API communication. Troubleshooting often involves inspecting its console output.
Sources: README.md:224-229
Debug Mode and Logging
The Go backend does not have a formal "debug mode" but logs significant events to the console, which is essential for debugging. Key logged information includes:
- Repository cloning initiation:
log.Printf("Cloning repository: %s/%s", owner, repo) - Errors during cloning, file reading, or context saving.
- Path and size of the generated context file.
- Final count of processed files for a repository.
- Errors from the Gemini API, including the status code and response body.
Sources: testgen-backend/main.go:343, testgen-backend/main.go:356, testgen-backend/main.go:375-376, testgen-backend/main.go:520
Backend CORS Configuration
The Go backend explicitly allows requests from the default frontend development server (http://localhost:8080). If the frontend is running on a different port, this configuration must be updated.
// file: testgen-backend/main.go:328-332
func cloneRepoHandler(w http.ResponseWriter, r *http.Request) {
// Enable CORS for frontend on port 8080
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080")
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
This configuration is repeated for all API handlers (cloneRepoHandler, getContextHandler, generateTestsHandler).
Sources: testgen-backend/main.go:328-332, testgen-backend/main.go:391-395, testgen-backend/main.go:432-436
Repository Processing Failures
The cloneRepoHandler function follows a multi-step process. Failures can occur at any stage.
This flowchart shows the backend's repository processing logic.
Sources: testgen-backend/main.go:327-388
Gemini API Troubleshooting
Issues with test generation are typically related to the Gemini API key or the content of the request.
API Key and Request Validation
Both the client-side and Go backends validate that an API key and code context are provided before sending a request to Gemini.
- In the frontend, a
toastnotification prompts the user to enter the key. - In the Go backend, it returns an HTTP 400 error.
Sources: testgen/src/pages/Dashboard.tsx:111-118, testgen-backend/main.go:445-455
API Call and Response Parsing
After a request is sent, errors can still occur. The system must handle non-successful HTTP status codes from the Gemini API and parse the JSON content from the response body.
This sequence diagram shows the flow of a test generation request and potential failure points.
A specific challenge is that the Gemini API returns JSON embedded within a larger text response. Both backends include logic to extract the JSON string before parsing. Failure in this step is a common source of errors.
// file: testgen-backend/main.go:551-557
// Extract JSON from the response
jsonStart := strings.Index(generatedText, "{")
jsonEnd := strings.LastIndex(generatedText, "}")
if jsonStart == -1 || jsonEnd == -1 || jsonStart >= jsonEnd {
log.Printf("No valid JSON found in Gemini response: %s", generatedText)
http.Error(w, "No valid JSON found in Gemini response", http.StatusInternalServerError)
return
}
Sources: testgen-backend/main.go:551-557, testgen/src/lib/backend.ts:524-528