Spaces:
Running
Running
File size: 6,662 Bytes
0646b18 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# Tools Environment Registry Tests
This directory contains comprehensive tests for the Tools Environment Registry system, including legacy OpenAPI integration, MCP server support, and end-to-end API registry server testing.
## Test Structure
```
tests/
βββ __init__.py # Package initialization
βββ README.md # This file
βββ run_all_tests.py # Main test runner
βββ test_legacy_openapi.py # Legacy OpenAPI service tests
βββ test_mcp_server.py # MCP server integration tests
βββ test_mixed_configuration.py # Mixed config support tests
βββ test_e2e_api_registry.py # End-to-end API registry server tests
```
## Test Suites
### 1. Legacy OpenAPI Integration (`test_legacy_openapi.py`)
Tests the legacy OpenAPI service integration:
- β
Loading and listing applications
- β
Listing APIs with proper OpenAPI transformation
- β
Calling functions with and without parameters
- β
Response parsing and validation
### 2. MCP Server Integration (`test_mcp_server.py`)
Tests the FastMCP server integration:
- β
FastMCP client initialization
- β
Tool loading with parameter flattening
- β
Proper tool prefixing (server_toolname format)
- β
Function calling via SSE-based MCP servers
### 3. Mixed Configuration Support (`test_mixed_configuration.py`)
Tests both legacy and MCP servers in the same configuration:
- β
Loading both service types simultaneously
- β
Proper service isolation and prefixing
- β
Calling functions from both service types
- β
Configuration format validation
### 4. E2E API Registry Server (`test_e2e_api_registry.py`)
End-to-end tests against the actual API registry server:
- β
HTTP endpoint testing (`/applications`, `/apis`, `/functions/call`)
- β
Server lifecycle management
- β
Function calling via REST API
- β
Error handling and validation
## Running Tests
### Run All Tests
```bash
cd ./src/cuga/backend/tools_env/registry/tests
uv run python run_all_tests.py
```
### Run Individual Test Suites
```bash
# Legacy OpenAPI tests
uv run python test_legacy_openapi.py
# MCP server tests
uv run python test_mcp_server.py
# Mixed configuration tests
uv run python test_mixed_configuration.py
# E2E API registry tests
uv run python test_e2e_api_registry.py
```
### Run with Pytest
```bash
# Run all pytest tests
pytest cuga/backend/tools_env/registry/tests/
# Run specific test file
pytest cuga/backend/tools_env/registry/tests/test_legacy_openapi.py
# Run with verbose output
pytest -v cuga/backend/tools_env/registry/tests/
```
## Prerequisites
### For Legacy OpenAPI Tests
- Internet connection (accesses external Digital Sales API)
- No additional setup required
### For MCP Server Tests
- FastMCP example server running on `http://127.0.0.1:8000/sse`
- Start the server:
```bash
cd ./docs/examples/cuga_with_runtime_tools
uv run python fast_mcp_example.py &
```
### For E2E Tests
- API registry server will be started automatically
- Port 8001 should be available
- All dependencies installed via `uv`
## Test Configuration
Tests use temporary configuration files to avoid interfering with the main system:
### Legacy Config Example
```yaml
services:
- digital_sales:
url: https://digitalsales.19pc1vtv090u.us-east.codeengine.appdomain.cloud/openapi.json
description: Digital Sales API for testing
```
### MCP Config Example
```yaml
mcpServers:
digital_sales_mcp:
url: "http://127.0.0.1:8000/sse"
description: FastMCP example server
type: mcp_server
```
### Mixed Config Example
```yaml
# Legacy services
services:
- digital_sales_legacy:
url: https://digitalsales.19pc1vtv090u.us-east.codeengine.appdomain.cloud/openapi.json
description: Legacy Digital Sales API
# MCP servers
mcpServers:
digital_sales_mcp:
url: "http://127.0.0.1:8000/sse"
description: FastMCP example server
type: mcp_server
```
## Expected Results
### Successful Test Run
```
π Registry Test Suite
Running comprehensive tests for the Tools Environment Registry
================================================================================
π§ͺ RUNNING: Legacy OpenAPI Integration
================================================================================
β
Legacy OpenAPI Integration PASSED
================================================================================
π§ͺ RUNNING: MCP Server Integration
================================================================================
β
MCP Server Integration PASSED
================================================================================
π§ͺ RUNNING: Mixed Configuration Support
================================================================================
β
Mixed Configuration Support PASSED
================================================================================
π§ͺ RUNNING: E2E API Registry Server
================================================================================
β
E2E API Registry Server PASSED
================================================================================
π TEST SUMMARY
================================================================================
Total Tests: 4
Passed: 4 β
Failed: 0 β
Total Time: 45.23s
Success Rate: 100.0%
π ALL TESTS PASSED!
```
## Key Features Tested
### Parameter Flattening
- β
`$defs` resolution and removal
- β
Complex nested objects simplified to string arrays
- β
Proper parameter type preservation
- β
Descriptive messages for simplified parameters
### Tool Prefixing
- β
Legacy: `digital_sales_get_my_accounts`
- β
MCP: `digital_sales_mcp_get_my_accounts`
- β
No conflicts between services
### FastMCP Integration
- β
Proper client initialization with config
- β
Tool listing and registration
- β
Function calling with argument handling
- β
Error handling and fallback mechanisms
### API Registry Server
- β
RESTful endpoints for applications and APIs
- β
Function calling via HTTP POST
- β
Proper error responses
- β
Server lifecycle management
## Troubleshooting
### Common Issues
1. **MCP Server Not Running**
```
Error: Failed to connect to MCP server
Solution: Start the FastMCP server first
```
2. **Port Already in Use**
```
Error: Server failed to start (port 8001 in use)
Solution: Kill existing processes on port 8001
```
3. **Network Issues**
```
Error: Failed to fetch OpenAPI spec
Solution: Check internet connection
```
### Debug Mode
Add `--verbose` or set environment variable:
```bash
export DEBUG=1
uv run python run_all_tests.py
```
|