Skip to content

Commit a1a369e

Browse files
committed
feat: add real Langfuse integration tests and update Makefile
- Introduced `test-langfuse-real` target in Makefile for running real Langfuse tests. - Added `run_real_langfuse_tests.sh` script to execute integration tests with live API calls. - Created `test_real_langfuse_integration.py` for comprehensive testing of Langfuse API functionality. - Updated `README.md` to document new testing procedures and commands. - Enhanced `run_docker_tests.sh` to include real Langfuse test scenario. This update improves the testing framework by validating the integration with the actual Langfuse environment.
1 parent dc7e92c commit a1a369e

File tree

6 files changed

+453
-4
lines changed

6 files changed

+453
-4
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: install test build dist sdist bdist_wheel upload upload-test test-release bump clean test-docker test-docker-clean
1+
.PHONY: install test build dist sdist bdist_wheel upload upload-test test-release bump clean test-docker test-docker-clean test-langfuse-real
22

33
install:
44
pip install -r requirements.txt
@@ -39,3 +39,6 @@ test-docker:
3939

4040
test-docker-clean:
4141
docker rmi coaiapy-test || true
42+
43+
test-langfuse-real:
44+
cd tests && ./run_real_langfuse_tests.sh

tests/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ Run all tests:
3535
- **Tests**: All service configurations (AWS, Redis, OpenAI, Langfuse)
3636
- **Purpose**: Comprehensive integration testing
3737

38-
### 4. No .env File
38+
### 4. **Real Langfuse Integration** 🔥
39+
- **File**: `../.env.tests`
40+
- **Tests**: Actual Langfuse API calls with real credentials
41+
- **Purpose**: End-to-end validation with live Langfuse environment
42+
- **Operations Tested**:
43+
- `coaia fuse prompts list` (table and JSON formats)
44+
- `coaia fuse datasets list`
45+
- `coaia fuse traces list`
46+
- Configuration loading and authentication
47+
48+
### 5. No .env File
3949
- **File**: None
4050
- **Tests**: System environment variables only
4151
- **Purpose**: Fallback behavior validation
@@ -91,6 +101,12 @@ docker run --rm \
91101
-v $(pwd):/app/tests:ro \
92102
coaiapy-test
93103

104+
# Test with REAL Langfuse environment
105+
docker run --rm \
106+
-v $(pwd)/../.env.tests:/app/.env:ro \
107+
-v $(pwd):/app/tests:ro \
108+
coaiapy-test python test_real_langfuse_integration.py
109+
94110
# Test without .env file
95111
docker run --rm \
96112
-v $(pwd):/app/tests:ro \
@@ -104,15 +120,30 @@ docker build -f Dockerfile.test -t coaiapy-test ..
104120

105121
## Integration with Main Build System
106122

107-
Add to main `Makefile`:
123+
Available in main `Makefile`:
108124
```make
109125
test-docker:
110126
cd tests && ./run_docker_tests.sh
111127

128+
test-langfuse-real:
129+
cd tests && ./run_real_langfuse_tests.sh
130+
112131
test-docker-clean:
113132
docker rmi coaiapy-test || true
114133
```
115134

135+
### Quick Commands:
136+
```bash
137+
# Run all test scenarios (mock + real)
138+
make test-docker
139+
140+
# Run ONLY real Langfuse tests
141+
make test-langfuse-real
142+
143+
# Clean up Docker images
144+
make test-docker-clean
145+
```
146+
116147
## Expected Output
117148

118149
```

tests/run_docker_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ declare -a TEST_SCENARIOS=(
5555
"minimal:sample.env.minimal:Basic .env functionality with minimal config"
5656
"langfuse:sample.env.langfuse:Langfuse-specific configuration testing"
5757
"full:sample.env.full:Complete configuration with all services"
58+
"real-langfuse:../.env.tests:Real Langfuse integration testing"
5859
"none::Testing without .env file (environment variables only)"
5960
)
6061

tests/run_real_langfuse_tests.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
# Run real Langfuse integration tests using .env.tests
3+
# This validates the actual .env functionality with live Langfuse API
4+
5+
set -e # Exit on error
6+
7+
# Colors for output
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
BLUE='\033[0;34m'
12+
NC='\033[0m' # No Color
13+
14+
# Script directory
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
17+
18+
echo -e "${BLUE}🔗 CoaiaPy Real Langfuse Integration Tests${NC}"
19+
echo "=================================================="
20+
21+
# Function to print status
22+
print_status() {
23+
echo -e "${BLUE}[INFO]${NC} $1"
24+
}
25+
26+
print_success() {
27+
echo -e "${GREEN}[SUCCESS]${NC} $1"
28+
}
29+
30+
print_error() {
31+
echo -e "${RED}[ERROR]${NC} $1"
32+
}
33+
34+
print_warning() {
35+
echo -e "${YELLOW}[WARNING]${NC} $1"
36+
}
37+
38+
# Check if .env.tests exists
39+
if [[ ! -f "${PROJECT_DIR}/.env.tests" ]]; then
40+
print_error ".env.tests file not found in project root"
41+
print_error "Create .env.tests with your Langfuse test credentials:"
42+
echo "LANGFUSE_SECRET_KEY=sk-lf-your-test-secret-key"
43+
echo "LANGFUSE_PUBLIC_KEY=pk-lf-your-test-public-key"
44+
echo "LANGFUSE_HOST=https://us.cloud.langfuse.com"
45+
exit 1
46+
fi
47+
48+
print_status ".env.tests file found"
49+
50+
# Check if Docker is available
51+
if ! command -v docker &> /dev/null; then
52+
print_error "Docker is not installed or not in PATH"
53+
exit 1
54+
fi
55+
56+
# Build the test image if it doesn't exist
57+
if ! docker image inspect coaiapy-test > /dev/null 2>&1; then
58+
print_status "Building Docker test image..."
59+
if docker build -f "${SCRIPT_DIR}/Dockerfile.test" -t coaiapy-test "${PROJECT_DIR}"; then
60+
print_success "Docker image built successfully"
61+
else
62+
print_error "Failed to build Docker image"
63+
exit 1
64+
fi
65+
else
66+
print_status "Using existing Docker test image"
67+
fi
68+
69+
# Run the real Langfuse integration tests
70+
print_status "Running real Langfuse integration tests..."
71+
print_status "Using .env.tests for actual Langfuse API testing"
72+
73+
# Prepare Docker command
74+
DOCKER_CMD="docker run --rm"
75+
76+
# Mount .env.tests as .env
77+
DOCKER_CMD="$DOCKER_CMD -v ${PROJECT_DIR}/.env.tests:/app/.env:ro"
78+
79+
# Mount the tests directory
80+
DOCKER_CMD="$DOCKER_CMD -v ${SCRIPT_DIR}:/app/tests:ro"
81+
82+
# Set environment variable
83+
DOCKER_CMD="$DOCKER_CMD -e TEST_SCENARIO=real-langfuse"
84+
85+
# Run only the real Langfuse integration tests
86+
DOCKER_CMD="$DOCKER_CMD coaiapy-test python test_real_langfuse_integration.py"
87+
88+
print_status "Executing: $DOCKER_CMD"
89+
90+
if eval "$DOCKER_CMD"; then
91+
print_success "✅ Real Langfuse integration tests PASSED"
92+
echo "=================================================="
93+
print_status "All Langfuse operations validated:"
94+
print_status "• Configuration loading from .env.tests"
95+
print_status "• coaia fuse prompts list (table and JSON)"
96+
print_status "• coaia fuse datasets list"
97+
print_status "• coaia fuse traces list"
98+
echo "=================================================="
99+
exit 0
100+
else
101+
print_error "❌ Real Langfuse integration tests FAILED"
102+
echo "=================================================="
103+
print_error "Possible issues:"
104+
print_error "• Invalid Langfuse credentials in .env.tests"
105+
print_error "• Network connectivity to Langfuse API"
106+
print_error "• API rate limits or service issues"
107+
echo "=================================================="
108+
exit 1
109+
fi

0 commit comments

Comments
 (0)