Configuration and Environment
Relevant source files
The following files were used as context for generating this wiki page:
The TestGen AI application is composed of a React frontend and a Go backend, each with its own configuration and environment setup. An alternative client-side "backend" implementation also exists, which runs entirely in the browser and communicates directly with external APIs. This document outlines the configuration for the development environments, server settings, API interactions, and file processing rules that govern the system's behavior.
The project's architecture separates the user interface from the core logic of repository cloning and test generation. The configuration ensures proper communication between these components and with external services like the GitHub API and Google's Gemini AI.
Project Architecture and Environments
The project consists of two primary subdirectories: testgen/ for the frontend and testgen-backend/ for the Go backend. The system can operate in two modes: with the Go backend server or with a client-side implementation that performs backend tasks directly in the browser.
This diagram shows the high-level architecture.
Sources: README.md, CLIENT_BACKEND.md
Frontend Environment
The frontend is a Vite-based React application. Its development environment is configured in vite.config.ts.
Vite Server Configuration
// testgen/vite.config.ts:7-10
export default defineConfig(({ mode }) => ({
server: {
host: "::",
port: 8080,
},
//...
The development server is configured to run on port 8080 and is accessible from any network interface.
Sources: testgen/vite.config.ts:7-10
NPM Scripts
The package.json file defines scripts for managing the frontend development lifecycle.
| Script | Description |
|---|---|
dev | Starts the Vite development server on http://localhost:8080. |
build | Builds the application for production. |
lint | Lints the codebase using ESLint. |
preview | Serves the production build locally for preview. |
Sources: testgen/package.json:6-10
Backend Environment (Go)
The Go backend is a web server that handles repository cloning and test generation requests.
Server Configuration
The server is configured to run on port 3001 and exposes several API endpoints.
// testgen-backend/main.go:671-672
log.Println("Server starting on :3001")
log.Fatal(http.ListenAndServe(":3001", nil))
Sources: testgen-backend/main.go:671-672
Environment Variables
The backend can be configured using environment variables, as described in the project's README.md.
| Variable | Description | Default |
|---|---|---|
GEMINI_API_KEY | Your Google Gemini API key. | (Not specified) |
PORT | The port for the backend server. | 3001 |
FRONTEND_URL | The frontend URL for CORS configuration. | http://localhost:8080 |
Sources: README.md
CORS Configuration
The backend includes Cross-Origin Resource Sharing (CORS) headers to allow requests from the frontend development server running on http://localhost:8080.
// testgen-backend/main.go:359-363
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")
w.Header().Set("Access-Control-Allow-Credentials", "true")
This configuration is applied to all API handlers (/api/clone-repo, /api/context/, /api/generate-tests).
Sources: testgen-backend/main.go:359-363, 469-473, 521-525
API and Service Configuration
The application integrates with the GitHub and Google Gemini APIs. Configuration for these services exists in both the Go backend and the client-side TypeScript implementation.
GitHub API Interaction
The system fetches repository contents using the GitHub API. This process involves parsing a URL, fetching the repository tree, and reading individual files while filtering out irrelevant content.
The following diagram illustrates the repository cloning and file processing logic.
Gemini API Interaction
Test cases are generated by sending the collected code context to the Google Gemini API. The API key is required and is passed in the request.
Test Generation Flow
This sequence diagram shows the process of generating tests.
Gemini Request Configuration
The request to the Gemini API includes generation configuration parameters to control the output.
| Parameter | Value | Purpose |
|---|---|---|
temperature | 0.7 | Controls randomness. |
topK | 40 | Selects from the top K most likely tokens. |
topP | 0.95 | Selects from tokens with a cumulative probability of P. |
maxOutputTokens | 8192 | The maximum number of tokens to generate. |
Sources: testgen-backend/main.go:600-605, testgen/src/lib/backend.ts:491-496
File Filtering and Processing
A crucial configuration aspect is the filtering of repository files to create a concise and relevant context for the AI. Both the Go backend and the client-side implementation use a list of exclusion patterns.
Exclusion Patterns
The following patterns are used to exclude directories and files from processing:
| Pattern | Description |
|---|---|
node_modules, .git | Dependency and version control directories. |
dist, build, coverage | Build output and report directories. |
*.log, *.tmp | Log and temporary files. |
*.min.js, *.min.css | Minified assets. |
package-lock.json, yarn.lock | Lock files. |
.env*, .vscode, .idea | Environment and IDE configuration. |
*.md, LICENSE, README* | Documentation files. |
*config.*, .*rc* | Various configuration files. |
test, tests, spec, docs | Testing and documentation directories. |
assets, images, public | Static asset directories. |
Sources: testgen-backend/main.go:68-80, testgen/src/lib/backend.ts:35-47
File Size and Type Limits
- Backend (Go): Excludes files larger than 1MB. It identifies source files by a list of over 30 extensions and also includes important files like
Dockerfile,Makefile,go.mod, etc.
Sources: testgen-backend/main.go:176-179, 182-199 - Client-Side (TypeScript): Excludes files larger than 50KB and limits the total number of files fetched to 15 to manage performance and API usage in the browser.
Sources: testgen/src/lib/backend.ts:155, 169
Summary
The configuration of the TestGen AI project is defined across its frontend and backend components. Key settings include server ports, CORS policies for development, API keys for external services, and detailed rules for file filtering. The existence of both a Go backend and a client-side TypeScript implementation for core logic provides flexibility but requires consistent configuration, especially for file exclusion patterns and API interactions, to ensure predictable behavior regardless of the deployment model.