Spaces:
Build error
Build error
| # Test Music Generation End-to-End | |
| # Tests the complete flow from API call to generation | |
| $Colors = @{ | |
| Red = "Red" | |
| Green = "Green" | |
| Yellow = "Yellow" | |
| Blue = "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" | |
| Write-Host "===========================================================" -ForegroundColor Cyan | |
| Write-Host " Music Generation End-to-End Test " -ForegroundColor Cyan | |
| Write-Host "===========================================================" -ForegroundColor Cyan | |
| Write-Host "`n" | |
| $baseUrl = "http://127.0.0.1:8001" | |
| $maxAttempts = 3 | |
| $attempt = 0 | |
| # Test 1: Backend Health | |
| Write-Info "Test 1: Backend Health Check" | |
| try { | |
| $response = Invoke-WebRequest -Uri "$baseUrl/health" -UseBasicParsing -TimeoutSec 5 | |
| if ($response.StatusCode -eq 200) { | |
| Write-Success "Backend is healthy" | |
| } else { | |
| Write-Error "Backend returned status $($response.StatusCode)" | |
| exit 1 | |
| } | |
| } catch { | |
| Write-Error "Backend not responding: $($_.Exception.Message)" | |
| Write-Warning "Make sure backend is running: cd backend; uvicorn app.main:app --reload" | |
| exit 1 | |
| } | |
| # Test 2: Create Generation | |
| Write-Info "`nTest 2: Creating Music Generation" | |
| $testPrompt = "A peaceful piano melody with soft strings" | |
| $body = @{ | |
| prompt = $testPrompt | |
| duration = 10 | |
| } | ConvertTo-Json | |
| while ($attempt -lt $maxAttempts) { | |
| $attempt++ | |
| Write-Host "Attempt $attempt/$maxAttempts..." -ForegroundColor Yellow | |
| try { | |
| $response = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations" ` | |
| -Method POST ` | |
| -Body $body ` | |
| -ContentType "application/json" ` | |
| -UseBasicParsing ` | |
| -TimeoutSec 15 | |
| if ($response.StatusCode -eq 202 -or $response.StatusCode -eq 201 -or $response.StatusCode -eq 200) { | |
| $data = $response.Content | ConvertFrom-Json | |
| Write-Success "Generation created successfully!" | |
| Write-Host " Generation ID: $($data.id)" -ForegroundColor Gray | |
| Write-Host " Status: $($data.status)" -ForegroundColor Gray | |
| Write-Host " Prompt: $testPrompt" -ForegroundColor Gray | |
| # Test 3: Check Generation Status | |
| Write-Info "`nTest 3: Checking Generation Status" | |
| $statusAttempt = 0 | |
| $maxStatusAttempts = 30 | |
| while ($statusAttempt -lt $maxStatusAttempts) { | |
| $statusAttempt++ | |
| Start-Sleep -Seconds 5 | |
| try { | |
| $statusResponse = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations/$($data.id)" -UseBasicParsing -TimeoutSec 5 | |
| $statusData = $statusResponse.Content | ConvertFrom-Json | |
| Write-Host " Current status: $($statusData.status) ($statusAttempt/$maxStatusAttempts)" -ForegroundColor Gray | |
| if ($statusData.status -eq "completed") { | |
| Write-Success "Generation completed!" | |
| if ($statusData.audio_path) { | |
| Write-Host " Audio file: $($statusData.audio_path)" -ForegroundColor Green | |
| } | |
| Write-Host "`nMusic generation feature is working!`n" -ForegroundColor Green | |
| exit 0 | |
| } elseif ($statusData.status -eq "failed") { | |
| Write-Error "Generation failed: $($statusData.error_message)" | |
| exit 1 | |
| } | |
| } catch { | |
| Write-Warning "Could not check status: $($_.Exception.Message)" | |
| } | |
| } | |
| Write-Error "Generation timed out" | |
| exit 1 | |
| } | |
| } catch { | |
| $statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { "Unknown" } | |
| $errorMsg = $_.Exception.Message | |
| Write-Error "Failed: Status $statusCode - $errorMsg" | |
| if ($statusCode -eq 500) { | |
| Write-Warning "500 error usually means:" | |
| Write-Host " * Database connection issue (check Docker)" -ForegroundColor Gray | |
| Write-Host " * ML dependencies not installed" -ForegroundColor Gray | |
| Write-Host " * Check backend logs for details" -ForegroundColor Gray | |
| } | |
| if ($attempt -lt $maxAttempts) { | |
| Write-Host " Retrying in 3 seconds..." -ForegroundColor Gray | |
| Start-Sleep -Seconds 3 | |
| } | |
| } | |
| } | |
| Write-Error "Failed after $maxAttempts attempts" | |
| Write-Host "Troubleshooting:" -ForegroundColor Yellow | |
| Write-Host "1. Check backend is running" -ForegroundColor White | |
| Write-Host "2. Verify ML dependencies" -ForegroundColor White | |
| Write-Host "3. Check Docker containers" -ForegroundColor White | |
| Write-Host "4. Review backend logs for errors" -ForegroundColor White | |
| exit 1 |