OnyxMunk/AudioForge
0
1 2# Test Music Generation End-to-End3# Tests the complete flow from API call to generation4 5$Colors = @{6 Red = "Red"7 Green = "Green"8 Yellow = "Yellow"9 Blue = "Cyan"10}11 12function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue }13function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green }14function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow }15function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red }16 17Write-Host "`n"18Write-Host "===========================================================" -ForegroundColor Cyan19Write-Host " Music Generation End-to-End Test " -ForegroundColor Cyan20Write-Host "===========================================================" -ForegroundColor Cyan21Write-Host "`n"22 23$baseUrl = "http://127.0.0.1:8001"24$maxAttempts = 325$attempt = 026 27# Test 1: Backend Health28Write-Info "Test 1: Backend Health Check"29try {30 $response = Invoke-WebRequest -Uri "$baseUrl/health" -UseBasicParsing -TimeoutSec 531 if ($response.StatusCode -eq 200) {32 Write-Success "Backend is healthy"33 } else {34 Write-Error "Backend returned status $($response.StatusCode)"35 exit 136 }37} catch {38 Write-Error "Backend not responding: $($_.Exception.Message)"39 Write-Warning "Make sure backend is running: cd backend; uvicorn app.main:app --reload"40 exit 141}42 43# Test 2: Create Generation44Write-Info "`nTest 2: Creating Music Generation"45$testPrompt = "A peaceful piano melody with soft strings"46$body = @{47 prompt = $testPrompt48 duration = 1049} | ConvertTo-Json50 51while ($attempt -lt $maxAttempts) {52 $attempt++53 Write-Host "Attempt $attempt/$maxAttempts..." -ForegroundColor Yellow54 55 try {56 $response = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations" `57 -Method POST `58 -Body $body `59 -ContentType "application/json" `60 -UseBasicParsing `61 -TimeoutSec 1562 63 if ($response.StatusCode -eq 202 -or $response.StatusCode -eq 201 -or $response.StatusCode -eq 200) {64 $data = $response.Content | ConvertFrom-Json65 Write-Success "Generation created successfully!"66 Write-Host " Generation ID: $($data.id)" -ForegroundColor Gray67 Write-Host " Status: $($data.status)" -ForegroundColor Gray68 Write-Host " Prompt: $testPrompt" -ForegroundColor Gray69 70 # Test 3: Check Generation Status71 Write-Info "`nTest 3: Checking Generation Status"72 73 $statusAttempt = 074 $maxStatusAttempts = 3075 76 while ($statusAttempt -lt $maxStatusAttempts) {77 $statusAttempt++78 Start-Sleep -Seconds 579 80 try {81 $statusResponse = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations/$($data.id)" -UseBasicParsing -TimeoutSec 582 $statusData = $statusResponse.Content | ConvertFrom-Json83 Write-Host " Current status: $($statusData.status) ($statusAttempt/$maxStatusAttempts)" -ForegroundColor Gray84 85 if ($statusData.status -eq "completed") {86 Write-Success "Generation completed!"87 if ($statusData.audio_path) {88 Write-Host " Audio file: $($statusData.audio_path)" -ForegroundColor Green89 }90 Write-Host "`nMusic generation feature is working!`n" -ForegroundColor Green91 exit 092 } elseif ($statusData.status -eq "failed") {93 Write-Error "Generation failed: $($statusData.error_message)"94 exit 195 }96 } catch {97 Write-Warning "Could not check status: $($_.Exception.Message)"98 }99 }100 Write-Error "Generation timed out"101 exit 1102 }103 } catch {104 $statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { "Unknown" }105 $errorMsg = $_.Exception.Message106 107 108 109 Write-Error "Failed: Status $statusCode - $errorMsg"110 111 if ($statusCode -eq 500) {112 Write-Warning "500 error usually means:"113 Write-Host " * Database connection issue (check Docker)" -ForegroundColor Gray114 Write-Host " * ML dependencies not installed" -ForegroundColor Gray115 Write-Host " * Check backend logs for details" -ForegroundColor Gray116 }117 118 if ($attempt -lt $maxAttempts) {119 Write-Host " Retrying in 3 seconds..." -ForegroundColor Gray120 Start-Sleep -Seconds 3121 }122 }123}124 125Write-Error "Failed after $maxAttempts attempts"126Write-Host "Troubleshooting:" -ForegroundColor Yellow127Write-Host "1. Check backend is running" -ForegroundColor White128Write-Host "2. Verify ML dependencies" -ForegroundColor White129Write-Host "3. Check Docker containers" -ForegroundColor White130Write-Host "4. Review backend logs for errors" -ForegroundColor White131exit 1