Spaces:
Build error
Build error
| # Test Music Generation API | |
| # Tests the generation endpoint until it works | |
| $Colors = @{ | |
| Red = "Red" | |
| Green = "Green" | |
| Yellow = "Yellow" | |
| Blue = "Cyan" | |
| Cyan = "Cyan" | |
| } | |
| function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue } | |
| function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green } | |
| function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow } | |
| function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red } | |
| Write-Host "`nβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Cyan | |
| Write-Host "β Music Generation API Tester β" -ForegroundColor Cyan | |
| Write-Host "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ`n" -ForegroundColor Cyan | |
| $baseUrl = "http://localhost:8000" | |
| $maxAttempts = 5 | |
| $attempt = 0 | |
| # Test 1: Health endpoint | |
| Write-Info "Test 1: Checking backend health..." | |
| try { | |
| $response = Invoke-WebRequest -Uri "$baseUrl/health" -UseBasicParsing -TimeoutSec 5 | |
| if ($response.StatusCode -eq 200) { | |
| Write-Success "Backend is healthy (Status: $($response.StatusCode))" | |
| Write-Host " Response: $($response.Content)" -ForegroundColor Gray | |
| } else { | |
| Write-Error "Unexpected status: $($response.StatusCode)" | |
| exit 1 | |
| } | |
| } catch { | |
| Write-Error "Backend not responding: $($_.Exception.Message)" | |
| Write-Warning "Make sure backend is running on port 8000" | |
| exit 1 | |
| } | |
| # Test 2: List generations (GET) | |
| Write-Info "`nTest 2: Testing GET /api/v1/generations..." | |
| try { | |
| $response = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations" -UseBasicParsing -TimeoutSec 5 | |
| if ($response.StatusCode -eq 200) { | |
| Write-Success "GET generations works (Status: $($response.StatusCode))" | |
| $data = $response.Content | ConvertFrom-Json | |
| Write-Host " Found $($data.total) generations" -ForegroundColor Gray | |
| } else { | |
| Write-Error "Unexpected status: $($response.StatusCode)" | |
| } | |
| } catch { | |
| $statusCode = $_.Exception.Response.StatusCode.value__ | |
| Write-Error "GET failed with status $statusCode : $($_.Exception.Message)" | |
| if ($statusCode -eq 401) { | |
| Write-Warning "401 Unauthorized - Check CORS and authentication middleware" | |
| } | |
| } | |
| # Test 3: Create generation (POST) | |
| Write-Info "`nTest 3: Testing POST /api/v1/generations..." | |
| $testPrompt = "A calm acoustic guitar melody" | |
| $body = @{ | |
| prompt = $testPrompt | |
| duration = 10 | |
| } | ConvertTo-Json | |
| while ($attempt -lt $maxAttempts) { | |
| $attempt++ | |
| Write-Host "`nAttempt $attempt/$maxAttempts..." -ForegroundColor Yellow | |
| try { | |
| $response = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations" ` | |
| -Method POST ` | |
| -Body $body ` | |
| -ContentType "application/json" ` | |
| -UseBasicParsing ` | |
| -TimeoutSec 10 | |
| if ($response.StatusCode -eq 202) { | |
| Write-Success "β Generation created successfully!" | |
| $data = $response.Content | ConvertFrom-Json | |
| Write-Host " Generation ID: $($data.id)" -ForegroundColor Gray | |
| Write-Host " Status: $($data.status)" -ForegroundColor Gray | |
| Write-Host "`nπ Music generation feature is working!`n" -ForegroundColor Green | |
| exit 0 | |
| } else { | |
| Write-Warning "Unexpected status: $($response.StatusCode)" | |
| Write-Host " Response: $($response.Content)" -ForegroundColor Gray | |
| } | |
| } catch { | |
| $statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { "Unknown" } | |
| $errorMsg = $_.Exception.Message | |
| Write-Error "POST failed: Status $statusCode - $errorMsg" | |
| if ($statusCode -eq 401) { | |
| Write-Warning "401 Unauthorized detected!" | |
| Write-Host " Checking for authentication middleware..." -ForegroundColor Yellow | |
| # Check if there's auth middleware we need to disable | |
| } elseif ($statusCode -eq 500) { | |
| Write-Warning "500 Internal Server Error - Check backend logs" | |
| Write-Host " This might be a database connection issue" -ForegroundColor Yellow | |
| } elseif ($statusCode -eq 0 -or $statusCode -eq "Unknown") { | |
| Write-Warning "Connection error - Backend might not be running" | |
| } | |
| if ($attempt -lt $maxAttempts) { | |
| Write-Host " Waiting 3 seconds before retry..." -ForegroundColor Gray | |
| Start-Sleep -Seconds 3 | |
| } | |
| } | |
| } | |
| Write-Error "`nβ Failed to create generation after $maxAttempts attempts" | |
| Write-Host "`nTroubleshooting steps:" -ForegroundColor Yellow | |
| Write-Host "1. Check backend logs for errors" -ForegroundColor White | |
| Write-Host "2. Verify Docker containers are running: docker ps" -ForegroundColor White | |
| Write-Host "3. Check database connection: python backend/test_db_connection.py" -ForegroundColor White | |
| Write-Host "4. Verify CORS settings in backend/app/main.py" -ForegroundColor White | |
| exit 1 | |