Skip to content

Use UUIDs for document IDs in insert_documents method #134

Use UUIDs for document IDs in insert_documents method

Use UUIDs for document IDs in insert_documents method #134

name: Test API Endpoints
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Install Python and dependencies
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install jq and curl
run: sudo apt-get install -y jq curl
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Set up env
run: |
echo "LLM_API_BASE=${{ env.LLM_API_BASE }}" > .env.temp
echo "LLM_API_KEY=${{ secrets.LLM_API_KEY }}" >> .env.temp
echo "LLM_MODEL=${{ env.LLM_MODEL }}" >> .env.temp
echo "LLM_EMBED_MODEL=${{ env.LLM_EMBED_MODEL }}" >> .env.temp
echo "LLM_EMBED_SIZE=${{ env.LLM_EMBED_SIZE }}" >> .env.temp
- name: Run docker compose
uses: hoverkraft-tech/[email protected]
with:
compose-file: ./docker-compose.yml
compose-flags: "--env-file .env.temp"
up-flags: "-d --build"
- name: Wait for services to be ready
run: |
echo "Waiting for services to be ready..."
sleep 60
docker ps
- name: Verify container readiness
run: |
docker ps
# Only check for API and qdrant since MCP services are commented out
for container in api qdrant; do
if ! docker ps | grep -q "$container"; then
echo "ERROR: $container is not running!"
docker compose logs --tail=100 "$container" || echo "Could not get logs for $container"
exit 1
fi
done
echo "All containers are running."
- name: Test /compile endpoint
run: |
echo "Testing /compile endpoint..."
RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/compile \
-H "Content-Type: application/json" \
-d '{
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\");\n}"
}' || echo "CURL_FAILED")
if [ "$RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to connect to API service"
docker ps
docker logs $(docker ps -q --filter name=api)
exit 1
fi
# Check for success in response
if ! echo "$RESPONSE" | jq -e '.success == true' > /dev/null; then
echo "Compilation failed:"
echo "$RESPONSE" | jq || echo "$RESPONSE"
exit 1
fi
echo "Compilation successful!"
echo "$RESPONSE" | jq || echo "$RESPONSE"
- name: Test /compile-and-fix endpoint
run: |
echo "Testing /compile-and-fix endpoint..."
RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/compile-and-fix \
-H "Content-Type: application/json" \
-d '{
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\" // Missing closing parenthesis\n}",
"description": "A simple hello world program",
"max_attempts": 3
}' || echo "CURL_FAILED")
if [ "$RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to connect to API service"
docker ps
docker logs $(docker ps -q --filter name=api)
exit 1
fi
# Check for success in response
if ! echo "$RESPONSE" | jq -e '.success == true' > /dev/null; then
echo "Compilation failed:"
echo "$RESPONSE" | jq || echo "$RESPONSE"
exit 1
fi
echo "Compilation successful!"
echo "$RESPONSE" | jq || echo "$RESPONSE"
- name: Test /generate endpoint
run: |
echo "Testing /generate endpoint..."
# Generate the project
RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/generate \
-H "Content-Type: application/json" \
-d '{
"description": "A simple command-line calculator in Rust",
"requirements": "Should support addition, subtraction, multiplication, and division"
}' || echo "CURL_FAILED")
if [ "$RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to connect to API service"
docker ps
docker logs $(docker ps -q --filter name=api)
exit 1
fi
# Extract project_id from response
PROJECT_ID=$(echo "$RESPONSE" | jq -r '.project_id')
echo "Project ID: $PROJECT_ID"
# Poll for project completion (maximum 10 attempts, 15 seconds apart)
echo "Polling for project completion..."
for i in {1..10}; do
echo "Checking project status (attempt $i)..."
STATUS_RESPONSE=$(curl -s -S -f "http://localhost:8000/project/$PROJECT_ID" || echo "CURL_FAILED")
if [ "$STATUS_RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to get project status"
exit 1
fi
STATUS=$(echo "$STATUS_RESPONSE" | jq -r '.status')
echo "Current status: $STATUS"
if [ "$STATUS" = "completed" ]; then
echo "Project generation successful!"
echo "$STATUS_RESPONSE" | jq
break
elif [ "$STATUS" = "failed" ]; then
echo "Project generation failed:"
echo "$STATUS_RESPONSE" | jq
exit 1
fi
# If still processing, wait and try again
if [ $i -eq 10 ]; then
echo "Project generation taking too long, exiting"
exit 1
fi
echo "Waiting 15 seconds before next check..."
sleep 15
done
# Get a file from the project to verify file access works
echo "Retrieving main.rs file..."
FILE_RESPONSE=$(curl -s -S -f "http://localhost:8000/project/$PROJECT_ID/files/src/main.rs" || echo "CURL_FAILED")
if [ "$FILE_RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to retrieve file"
exit 1
fi
echo "Successfully retrieved file content:"
echo "$FILE_RESPONSE" | head -10
# Test downloading the project
echo "Testing project download..."
DOWNLOAD_RESPONSE=$(curl -s -S -f -o "project-$PROJECT_ID.zip" "http://localhost:8000/project/$PROJECT_ID/download" || echo "CURL_FAILED")
if [ "$DOWNLOAD_RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to download project"
exit 1
fi
# Verify zip file was created
if [ ! -f "project-$PROJECT_ID.zip" ]; then
echo "Project zip file not created"
exit 1
fi
echo "Project download successful!"
ls -la "project-$PROJECT_ID.zip"
- name: Test /generate-sync endpoint
continue-on-error: true # Allow this step to fail without failing the workflow
id: test-generate-sync
run: |
echo "Testing /generate-sync endpoint..."
RESPONSE=$(curl -X POST http://localhost:8000/generate-sync \
-H "Content-Type: application/json" \
-d '{"description": "A command-line calculator in Rust", "requirements": "Should support addition, subtraction, multiplication, and division"}')
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:8000/generate-sync \
-H "Content-Type: application/json" \
-d '{"description": "A command-line calculator in Rust", "requirements": "Should support addition, subtraction, multiplication, and division"}')
echo "HTTP response code: $HTTP_CODE"
if [[ "$HTTP_CODE" == "500" ]] && ([[ "$RESPONSE" == *"Invalid API Key"* ]] || [[ "$RESPONSE" == *"local variable"* ]] || [[ "$RESPONSE" == *"Connection error"* ]]); then
echo "LLM service error detected - this is expected with invalid API keys or connection issues"
echo "status=auth_error" >> $GITHUB_OUTPUT
exit 0
elif [[ "$HTTP_CODE" != "200" ]]; then
echo "Failed to connect to API service with unexpected error"
echo "Response: $RESPONSE"
docker ps
docker logs $(docker ps -q --filter name=api)
echo "status=error" >> $GITHUB_OUTPUT
exit 1
fi
# Save response to file for later use
echo "$RESPONSE" > generate_output.txt
# Check for success in response
if ! echo "$RESPONSE" | jq -e '.success == true' > /dev/null; then
echo "Generation failed:"
echo "status=error" >> $GITHUB_OUTPUT
echo "$RESPONSE" | jq || echo "$RESPONSE"
exit 1
fi
echo "Generate-sync successful! Response contains code files in text format."
echo "status=success" >> $GITHUB_OUTPUT
echo "$RESPONSE" | jq || echo "$RESPONSE"
- name: "Test workflow: /generate-sync → /compile"
run: |
echo "Testing workflow: /generate-sync → /compile..."
# Check if response contains fallback template
if grep -q "FALLBACK TEMPLATE" generate_output.txt; then
echo "WARNING: Testing with fallback template code - LLM generation failed but continuing with tests"
fi
# Get the output from the previous step and remove the build status comment
# GENERATE_OUTPUT=$(cat generate_output.txt | sed '/^# Build/,$d')
# COMPILE_RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/compile \
# -H "Content-Type: application/json" \
# -d "{
# \"code\": $(python3 -c "import json, sys; print(json.dumps(sys.stdin.read()))" < <(echo "$GENERATE_OUTPUT"))
# }" || echo "CURL_FAILED")
# Replace with:
COMPILE_RESPONSE=$(curl -s -S -f -X POST http://localhost:8000/compile \
-H "Content-Type: application/json" \
-d "{
\"code\": $(python3 -c "import json, sys; print(json.dumps(sys.stdin.read()))" < <(echo "$GENERATE_OUTPUT"))
}" || echo "CURL_FAILED")
if [ "$COMPILE_RESPONSE" = "CURL_FAILED" ]; then
echo "Failed to connect to API service"
docker ps
exit 1
fi
# Check for success in response
if ! echo "$COMPILE_RESPONSE" | jq -e '.success == true' > /dev/null; then
echo "Compilation failed:"
echo "$COMPILE_RESPONSE" | jq || echo "$COMPILE_RESPONSE"
exit 1
fi
echo "Workflow test successful! Generated code compiles correctly."
echo "$COMPILE_RESPONSE" | jq || echo "$COMPILE_RESPONSE"