|
| 1 | +# Test Cases for GPX Runner Route Generation |
| 2 | + |
| 3 | +## Current Status |
| 4 | + |
| 5 | +The app is deployed at https://gpx-runner.vercel.app |
| 6 | + |
| 7 | +**Working:** |
| 8 | +- ✅ Firebase auth |
| 9 | +- ✅ Route loading from Firestore |
| 10 | +- ✅ Left panel takeover for route suggestion |
| 11 | +- ✅ Distance targeting (±1km) - generates ~5.2km for 5km request |
| 12 | + |
| 13 | +**Known Issues:** |
| 14 | +- ❌ Missing OPENROUTESERVICE_API_KEY in Vercel - causes 500 error |
| 15 | +- ❌ Road-safe fallback not working without API key |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Test Case 1: Basic Route Generation (5km New Path) |
| 20 | + |
| 21 | +**Input:** |
| 22 | +- Start Point: Derived from center of existing routes (Falkenberg area, Sweden) |
| 23 | +- Distance: 5 km |
| 24 | +- Route Type: New paths (avoidFamiliar = true) |
| 25 | +- GPX Files Loaded: 10 routes from user account |
| 26 | + |
| 27 | +**Expected Behavior:** |
| 28 | +- Route follows actual roads/trails (not straight lines) |
| 29 | +- Loop closes within 50m of start |
| 30 | +- Distance: 4.0 - 6.0 km (±1km) |
| 31 | +- Familiarity: 0-20% |
| 32 | +- No long out-and-back segments |
| 33 | + |
| 34 | +**Actual Result (without API key):** |
| 35 | +``` |
| 36 | +Error: Missing OPENROUTESERVICE_API_KEY |
| 37 | +``` |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## Test Case 2: Familiar Route Generation (5km) |
| 42 | + |
| 43 | +**Input:** |
| 44 | +- Start Point: Derived from center of existing routes |
| 45 | +- Distance: 5 km |
| 46 | +- Route Type: Familiar paths (avoidFamiliar = false) |
| 47 | +- GPX Files Loaded: 10 routes |
| 48 | + |
| 49 | +**Expected Behavior:** |
| 50 | +- Route uses user's uploaded GPX tracks as familiarity graph |
| 51 | +- Familiarity: 80-100% |
| 52 | +- Route follows familiar paths where possible |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## API Contract |
| 57 | + |
| 58 | +### Frontend → Backend Request |
| 59 | + |
| 60 | +**Endpoint:** `POST /api/generate-route` |
| 61 | + |
| 62 | +**Request Body:** |
| 63 | +```json |
| 64 | +{ |
| 65 | + "start": { "lat": 56.90, "lng": 12.49 }, |
| 66 | + "targetDistanceKm": 5, |
| 67 | + "toleranceKm": 1, |
| 68 | + "familiarityMode": "new", |
| 69 | + "gpxFiles": [], |
| 70 | + "familiarityTracks": [] |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### Backend → Frontend Response |
| 75 | + |
| 76 | +**Success (200):** |
| 77 | +```json |
| 78 | +{ |
| 79 | + "routes": [ |
| 80 | + { |
| 81 | + "id": "uuid-string", |
| 82 | + "name": "New Loop - 5.2km", |
| 83 | + "coordinates": [[12.491, 56.905], [12.495, 56.908], ...], |
| 84 | + "distance": 5200, |
| 85 | + "elevationGain": 0, |
| 86 | + "startPoint": [12.491, 56.905], |
| 87 | + "isRoundTrip": true, |
| 88 | + "familiarityScore": 5, |
| 89 | + "score": 85.5, |
| 90 | + "debug": { |
| 91 | + "seed": "...", |
| 92 | + "targetMeters": 5000, |
| 93 | + "distancePenalty": 0.04, |
| 94 | + "familiarityPenalty": 0.05 |
| 95 | + } |
| 96 | + } |
| 97 | + ], |
| 98 | + "rejectedCount": 67 |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +**Error (422):** |
| 103 | +```json |
| 104 | +{ |
| 105 | + "error": "Could not find a road/trail loop that matched the requested distance and familiarity." |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## Exact Acceptance Rules |
| 112 | + |
| 113 | +### Required Rules (Must Have) |
| 114 | + |
| 115 | +1. **Loop Closure:** Route must end within 50m of start point |
| 116 | +2. **Road/Trail Only:** Must use OSRM/OpenRouteService routing, NO straight-line fallbacks |
| 117 | +3. **Distance Tolerance:** Target ±1km (e.g., 5km request → 4.0-6.0km acceptable) |
| 118 | +4. **Familiarity - New Mode:** 0-20% overlap with uploaded GPX |
| 119 | +5. **Familiarity - Familiar Mode:** 80-100% overlap with uploaded GPX |
| 120 | + |
| 121 | +### Preferred Rules (Should Have) |
| 122 | + |
| 123 | +6. **Out-and-Back Penalty:** Reject routes with >20% repeated segments |
| 124 | +7. **Loop Shape Score:** Penalize routes that cut through center repeatedly |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Key Files for Debugging |
| 129 | + |
| 130 | +1. **`src/app/page.tsx`** - Frontend: calls `/api/generate-route`, transforms coordinates, renders polyline |
| 131 | +2. **`src/app/api/generate-route/route.ts`** - API endpoint: validates request, calls route generator |
| 132 | +3. **`src/engine/generateRoute.ts`** - Main engine: generates candidates, filters, scores |
| 133 | +4. **`src/engine/candidates.ts`** - Waypoint generation for circular loops |
| 134 | +5. **`src/engine/providers/openRouteService.ts`** - OpenRouteService client |
| 135 | +6. **`src/components/Map.tsx`** - Leaflet map rendering |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## How to Test Manually |
| 140 | + |
| 141 | +1. Go to https://gpx-runner.vercel.app |
| 142 | +2. Login with: mago@osterhult.com / hejapa78 |
| 143 | +3. Click "Suggest Route" button |
| 144 | +4. Select distance (5km) and route type (New/Familiar) |
| 145 | +5. Click "Generate Route" |
| 146 | +6. Check browser console for API response |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## To Add API Key to Vercel |
| 151 | + |
| 152 | +1. Go to Vercel Dashboard → gpx-runner → Settings → Environment Variables |
| 153 | +2. Add: |
| 154 | + - Name: `OPENROUTESERVICE_API_KEY` |
| 155 | + - Value: (your OpenRouteService API key) |
| 156 | +3. Redeploy the app |
0 commit comments