Spaces:
Build error
Build error
File size: 5,420 Bytes
09fa60b |
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 |
# 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
|