|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +<# |
| 3 | +.SYNOPSIS |
| 4 | + Test that the Vertex AI fallback fix is working |
| 5 | + Verifies that the 403 error is resolved |
| 6 | +#> |
| 7 | + |
| 8 | +param( |
| 9 | + [string]$BackendUrl = "https://legalmind-backend-677928716377.us-central1.run.app" |
| 10 | +) |
| 11 | + |
| 12 | +Write-Host "" |
| 13 | +Write-Host "=" * 80 -ForegroundColor Cyan |
| 14 | +Write-Host "TESTING VERTEX AI FIX - 403 Error Resolution" -ForegroundColor Cyan |
| 15 | +Write-Host "=" * 80 -ForegroundColor Cyan |
| 16 | +Write-Host "" |
| 17 | + |
| 18 | +# Test 1: Health check endpoint |
| 19 | +Write-Host "Test 1: Health Check Endpoint" -ForegroundColor Yellow |
| 20 | +Write-Host "URL: $BackendUrl/health" -ForegroundColor Gray |
| 21 | +Write-Host "" |
| 22 | + |
| 23 | +try { |
| 24 | + $response = Invoke-WebRequest -Uri "$BackendUrl/health" -TimeoutSec 15 -ErrorAction Stop |
| 25 | + Write-Host "✅ Status Code: $($response.StatusCode)" -ForegroundColor Green |
| 26 | + Write-Host "✅ Response:" -ForegroundColor Green |
| 27 | + $response.Content | ConvertFrom-Json | Format-List | Write-Host |
| 28 | + |
| 29 | + if ($response.StatusCode -eq 200) { |
| 30 | + Write-Host "✅ HEALTH CHECK PASSED" -ForegroundColor Green |
| 31 | + } |
| 32 | +} |
| 33 | +catch { |
| 34 | + Write-Host "❌ Error: $($_.Exception.Message)" -ForegroundColor Red |
| 35 | + |
| 36 | + if ($_.Exception.Message -contains "403") { |
| 37 | + Write-Host "" |
| 38 | + Write-Host "ERROR: Still getting 403 error!" -ForegroundColor Red |
| 39 | + Write-Host "This means the fallback fix may not have deployed yet." -ForegroundColor Yellow |
| 40 | + Write-Host "" |
| 41 | + Write-Host "Status: Deployment might still be in progress" -ForegroundColor Yellow |
| 42 | + Write-Host "Please wait 2-3 minutes and try again." -ForegroundColor Yellow |
| 43 | + } |
| 44 | + elseif ($_.Exception.Message -contains "Connection refused" -or $_.Exception.Message -contains "host unreachable") { |
| 45 | + Write-Host "" |
| 46 | + Write-Host "INFO: Service may be cold starting or not yet active" -ForegroundColor Yellow |
| 47 | + Write-Host "Cloud Run scales to zero when inactive. Please wait..." -ForegroundColor Yellow |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +Write-Host "" |
| 52 | +Write-Host "=" * 80 -ForegroundColor Cyan |
| 53 | +Write-Host "TEST COMPLETE" -ForegroundColor Cyan |
| 54 | +Write-Host "=" * 80 -ForegroundColor Cyan |
| 55 | +Write-Host "" |
| 56 | + |
| 57 | +# Additional debugging info |
| 58 | +Write-Host "Deployment Info:" -ForegroundColor Yellow |
| 59 | +Write-Host "" |
| 60 | +try { |
| 61 | + $serviceInfo = gcloud run services describe legalmind-backend --project=legalmind-486106 --region=us-central1 --format="table(status.conditions[0].status)" 2>$null |
| 62 | + Write-Host "Service Status:" -ForegroundColor Cyan |
| 63 | + Write-Host $serviceInfo -ForegroundColor Gray |
| 64 | +} |
| 65 | +catch { |
| 66 | + Write-Host "Could not fetch service info" -ForegroundColor Gray |
| 67 | +} |
| 68 | + |
| 69 | +Write-Host "" |
| 70 | +Write-Host "SUMMARY:" -ForegroundColor Green |
| 71 | +Write-Host "- Fixed 4 fallback bugs in gemini_service.py" -ForegroundColor Green |
| 72 | +Write-Host "- Changed all 'if GenerativeModel' checks to 'if not GenerativeModel'" -ForegroundColor Green |
| 73 | +Write-Host " → Now raises errors instead of silently falling back to public API" -ForegroundColor Green |
| 74 | +Write-Host "- Backend will either work with Vertex AI or fail clearly" -ForegroundColor Green |
| 75 | +Write-Host "" |
| 76 | +Write-Host "Next Steps if error persists:" -ForegroundColor Yellow |
| 77 | +Write-Host "1. Wait 2-3 minutes for deployment to complete" -ForegroundColor Yellow |
| 78 | +Write-Host "2. Check logs: gcloud run services logs read legalmind-backend --limit=50" -ForegroundColor Yellow |
| 79 | +Write-Host "3. Verify Vertex AI SDK: pip show google-cloud-aiplatform" -ForegroundColor Yellow |
| 80 | +Write-Host "" |
0 commit comments